This commit is contained in:
garnier-quentin 2020-06-23 13:51:44 +02:00
parent e397594631
commit d63c1e898b
4 changed files with 56 additions and 65 deletions

View File

@ -33,33 +33,30 @@ sub set_counters {
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'active', set => { { label => 'active', nlabel => 'connections.server.active.count', set => {
key_values => [ { name => 'active' } ], key_values => [ { name => 'active' } ],
output_template => 'Active Server TCP connections : %s', output_template => 'Active Server TCP connections: %s',
perfdatas => [ perfdatas => [
{ label => 'active_server', value => 'active', template => '%s', { label => 'active_server', template => '%s', unit => 'con', min => 0 }
unit => 'con', min => 0 }, ]
],
} }
}, },
{ label => 'server', set => { { label => 'server', nlabel => 'connections.server.count', set => {
key_values => [ { name => 'server' } ], key_values => [ { name => 'server' } ],
output_template => 'Server TCP connections : %s', output_template => 'Server TCP connections: %s',
perfdatas => [ perfdatas => [
{ label => 'server', value => 'server', template => '%s', { label => 'server', template => '%s', unit => 'con', min => 0 }
unit => 'con', min => 0 }, ]
],
} }
}, },
{ label => 'client', set => { { label => 'client', nlabel => 'connections.client.count', set => {
key_values => [ { name => 'client' } ], key_values => [ { name => 'client' } ],
output_template => 'Client TCP connections : %s', output_template => 'Client TCP connections: %s',
perfdatas => [ perfdatas => [
{ label => 'client', value => 'client', template => '%s', { label => 'client', template => '%s', unit => 'con', min => 0 }
unit => 'con', min => 0 }, ]
],
} }
}, }
]; ];
} }
@ -67,11 +64,10 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ });
});
return $self; return $self;
} }
@ -110,4 +106,4 @@ Can be: 'server', 'active', 'client'.
=back =back
=cut =cut

View File

@ -29,10 +29,10 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'warning:s' => { name => 'warning' }, 'warning:s' => { name => 'warning' },
'critical:s' => { name => 'critical' }, 'critical:s' => { name => 'critical' }
}); });
return $self; return $self;
@ -64,9 +64,11 @@ sub run {
my $used = $result->{$oid_resMemUsage} * $total_size / 100; my $used = $result->{$oid_resMemUsage} * $total_size / 100;
my $free = $total_size - $used; my $free = $total_size - $used;
my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_resMemUsage}, my $exit = $self->{perfdata}->threshold_check(
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); value => $result->{$oid_resMemUsage},
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
);
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size);
my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $used); my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $used);
my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $free); my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $free);
@ -82,7 +84,9 @@ sub run {
); );
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
label => "used", unit => 'B', label => 'used',
nlabel => 'memory.usage.bytes',
unit => 'B',
value => int($used), value => int($used),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1),

View File

@ -27,20 +27,20 @@ use warnings;
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'storage', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All storages are ok' } { name => 'storage', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All storages are ok' }
]; ];
$self->{maps_counters}->{storage} = [ $self->{maps_counters}->{storage} = [
{ label => 'usage', set => { { label => 'usage', set => {
key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ], key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'), closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'), closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'), closure_custom_threshold_check => $self->can('custom_usage_threshold')
} }
}, }
]; ];
} }
@ -112,7 +112,7 @@ sub custom_usage_calc {
sub prefix_volume_output { sub prefix_volume_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Storage '" . $options{instance_value}->{display} . "' "; return "Storage '" . $options{instance_value}->{display} . "' ";
} }
@ -124,7 +124,7 @@ sub new {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
'units:s' => { name => 'units', default => '%' }, 'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' }, 'free' => { name => 'free' }
}); });
return $self; return $self;
@ -156,7 +156,7 @@ sub manage_selection {
$self->{output}->output_add(long_msg => "skipping '" . $result->{sysHealthDiskName} . "': no matching filter.", debug => 1); $self->{output}->output_add(long_msg => "skipping '" . $result->{sysHealthDiskName} . "': no matching filter.", debug => 1);
next; next;
} }
$result->{sysHealthDiskSize} *= 1024 * 1024; $result->{sysHealthDiskSize} *= 1024 * 1024;
$result->{sysHealthDiskUsed} *= 1024 * 1024; $result->{sysHealthDiskUsed} *= 1024 * 1024;
$self->{storage}->{$instance} = { $self->{storage}->{$instance} = {
@ -167,7 +167,7 @@ sub manage_selection {
} }
if (scalar(keys %{$self->{storage}}) <= 0) { if (scalar(keys %{$self->{storage}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No storage found."); $self->{output}->add_option_msg(short_msg => 'No storage found.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
} }

View File

@ -36,59 +36,58 @@ sub set_counters {
$self->{maps_counters}->{vservers} = [ $self->{maps_counters}->{vservers} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'state' } ], key_values => [ { name => 'state' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_threshold_output'), closure_custom_threshold_check => $self->can('custom_threshold_output')
} }
}, },
{ label => 'health', set => { { label => 'health', nlabel => 'vserver.health.percentage', set => {
key_values => [ { name => 'health' }, { name => 'display' } ], key_values => [ { name => 'health' }, { name => 'display' } ],
output_template => 'Health: %.2f %%', output_error_template => 'Health: %s', output_template => 'Health: %.2f %%', output_error_template => 'Health: %s',
perfdatas => [ perfdatas => [
{ label => 'health', template => '%.2f', { label => 'health', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'in-traffic', set => { { label => 'in-traffic', nlabel => 'vserver.traffic.in.bitspersecond', set => {
key_values => [ { name => 'in', per_second => 1 }, { name => 'display' } ], key_values => [ { name => 'in', per_second => 1 }, { name => 'display' } ],
output_template => 'Traffic In: %s %s/s', output_template => 'Traffic In: %s %s/s',
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'traffic_in', template => '%.2f', { label => 'traffic_in', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'out-traffic', set => { { label => 'out-traffic', nlabel => 'vserver.traffic.out.bitspersecond', set => {
key_values => [ { name => 'out', per_second => 1 }, { name => 'display' } ], key_values => [ { name => 'out', per_second => 1 }, { name => 'display' } ],
output_template => 'Traffic Out: %s %s/s', output_template => 'Traffic Out: %s %s/s',
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'traffic_out', template => '%.2f', { label => 'traffic_out', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'clients', set => { { label => 'clients', nlabel => 'vserver.connections.client.count', set => {
key_values => [ { name => 'clients', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'clients', diff => 1 }, { name => 'display' } ],
output_template => 'Total Client Connections : %s', output_template => 'Total Client Connections : %s',
perfdatas => [ perfdatas => [
{ label => 'clients', template => '%s', { label => 'clients', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }, min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'servers', set => { { label => 'servers', nlabel => 'vserver.connections.server.count', set => {
key_values => [ { name => 'servers', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'servers', diff => 1 }, { name => 'display' } ],
output_template => 'Total Server Connections : %s', output_template => 'Total Server Connections : %s',
perfdatas => [ perfdatas => [
{ label => 'servers', template => '%s', { label => 'servers', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }, min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, }
]; ];
} }
@ -138,16 +137,8 @@ sub custom_threshold_output {
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'State : ' . $self->{result_values}->{state};
return $msg; return 'State : ' . $self->{result_values}->{state};
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
return 0;
} }
sub new { sub new {
@ -158,7 +149,7 @@ sub new {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
'filter-type:s' => { name => 'filter_type' }, 'filter-type:s' => { name => 'filter_type' },
'threshold-overload:s@' => { name => 'threshold_overload' }, 'threshold-overload:s@' => { name => 'threshold_overload' }
}); });
return $self; return $self;
@ -226,7 +217,7 @@ sub manage_selection {
oids => [ oids => [
{ oid => $mapping->{vsvrFullName}->{oid} }, { oid => $mapping->{vsvrFullName}->{oid} },
{ oid => $mapping->{vsvrState}->{oid} }, { oid => $mapping->{vsvrState}->{oid} },
{ oid => $mapping->{vsvrEntityType}->{oid} }, { oid => $mapping->{vsvrEntityType}->{oid} }
], ],
return_type => 1, return_type => 1,
nothing_quit => 1 nothing_quit => 1