diff --git a/network/citrix/netscaler/common/mode/connections.pm b/network/citrix/netscaler/common/mode/connections.pm index 888099a3a..91e250130 100644 --- a/network/citrix/netscaler/common/mode/connections.pm +++ b/network/citrix/netscaler/common/mode/connections.pm @@ -24,6 +24,39 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use centreon::plugins::values; + +my $maps_counters = { + global => { + '000_active' => { set => { + key_values => [ { name => 'active' } ], + output_template => 'Active Server TCP connections : %s', + perfdatas => [ + { label => 'active_server', value => 'active_absolute', template => '%s', + unit => 'con', min => 0 }, + ], + } + }, + '001_server' => { set => { + key_values => [ { name => 'server' } ], + output_template => 'Server TCP connections : %s', + perfdatas => [ + { label => 'server', value => 'server_absolute', template => '%s', + unit => 'con', min => 0 }, + ], + } + }, + '002_client' => { set => { + key_values => [ { name => 'client' } ], + output_template => 'Client TCP connections : %s', + perfdatas => [ + { label => 'client', value => 'client_absolute', template => '%s', + unit => 'con', min => 0 }, + ], + } + }, + }, +}; sub new { my ($class, %options) = @_; @@ -33,13 +66,24 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning-server:s" => { name => 'warning_server' }, - "critical-server:s" => { name => 'critical_server' }, - "warning-active:s" => { name => 'warning_active' }, - "critical-active:s" => { name => 'critical_active' }, - "warning-client:s" => { name => 'warning_client' }, - "critical-client:s" => { name => 'critical_client' }, }); + + foreach my $key (('global')) { + foreach (keys %{$maps_counters->{$key}}) { + my ($id, $name) = split /_/; + if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $name . ':s' => { name => 'warning-' . $name }, + 'critical-' . $name . ':s' => { name => 'critical-' . $name }, + }); + } + $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, + perfdata => $self->{perfdata}, + label => $name); + $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); + } + } + return $self; } @@ -47,73 +91,79 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning-server', value => $self->{option_results}->{warning_server})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-server threshold '" . $self->{option_results}->{warning_server} . "'."); - $self->{output}->option_exit(); + foreach my $key (('global')) { + foreach (keys %{$maps_counters->{$key}}) { + $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); + } } - if (($self->{perfdata}->threshold_validate(label => 'critical-server', value => $self->{option_results}->{critical_server})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-server threshold '" . $self->{option_results}->{critical_server} . "'."); - $self->{output}->option_exit(); +} + +sub run_global { + my ($self, %options) = @_; + + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits; + foreach (sort keys %{$maps_counters->{global}}) { + my $obj = $maps_counters->{global}->{$_}->{obj}; + + $obj->set(instance => 'global'); + + my ($value_check) = $obj->execute(values => $self->{global}); + + if ($value_check != 0) { + $long_msg .= $long_msg_append . $obj->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $obj->threshold_check(); + push @exits, $exit2; + + my $output = $obj->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $obj->perfdata(); } - if (($self->{perfdata}->threshold_validate(label => 'warning-active', value => $self->{option_results}->{warning_active})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-active threshold '" . $self->{option_results}->{warning_active} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-active', value => $self->{option_results}->{critical_active})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-active threshold '" . $self->{option_results}->{critical_active} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warning-client', value => $self->{option_results}->{warning_client})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-client threshold '" . $self->{option_results}->{warning_client} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-client', value => $self->{option_results}->{critical_client})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-client threshold '" . $self->{option_results}->{critical_client} . "'."); - $self->{output}->option_exit(); + + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => "$short_msg" + ); + } else { + $self->{output}->output_add(short_msg => "$long_msg"); } } sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + $self->run_global(); + + $self->{output}->display(); + $self->{output}->exit(); +} +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { client => 0, server => 0, active => 0 }; my $oid_tcpCurServerConn = '.1.3.6.1.4.1.5951.4.1.1.46.1.0'; my $oid_tcpCurClientConn = '.1.3.6.1.4.1.5951.4.1.1.46.2.0'; my $oid_tcpActiveServerConn = '.1.3.6.1.4.1.5951.4.1.1.46.8.0'; my $result = $self->{snmp}->get_leef(oids => [$oid_tcpCurServerConn, $oid_tcpCurClientConn, $oid_tcpActiveServerConn ], nothing_quit => 1); - - my $exit_server = $self->{perfdata}->threshold_check(value => $result->{$oid_tcpCurServerConn}, - threshold => [ { label => 'critical-server', exit_litteral => 'critical' }, { label => 'warning-server', exit_litteral => 'warning' } ]); - my $exit_client = $self->{perfdata}->threshold_check(value => $result->{$oid_tcpCurClientConn}, - threshold => [ { label => 'critical-client', exit_litteral => 'critical' }, { label => 'warning-client', exit_litteral => 'warning' } ]); - my $exit_active = $self->{perfdata}->threshold_check(value => $result->{$oid_tcpActiveServerConn}, - threshold => [ { label => 'critical-active', exit_litteral => 'critical' }, { label => 'warning-active', exit_litteral => 'warning' } ]); - my $exit = $self->{output}->get_most_critical(status => [$exit_server, $exit_client, $exit_active]); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Connections: Client=%s Server=%s (activeServer=%s)", - $result->{$oid_tcpCurClientConn}, $result->{$oid_tcpCurServerConn}, $result->{$oid_tcpActiveServerConn})); - - $self->{output}->perfdata_add(label => "client", unit => 'con', - value => $result->{$oid_tcpCurClientConn}, - warning => $self->{option_results}->{warning_client}, - critical => $self->{option_results}->{critical_client}, - min => 0); - $self->{output}->perfdata_add(label => "server", unit => 'con', - value => $result->{$oid_tcpCurServerConn}, - warning => $self->{option_results}->{warning_server}, - critical => $self->{option_results}->{critical_server}, - min => 0); - $self->{output}->perfdata_add(label => "activeServer", unit => 'con', - value => $result->{$oid_tcpActiveServerConn}, - warning => $self->{option_results}->{warning_active}, - critical => $self->{option_results}->{critical_active}, - min => 0); - $self->{output}->display(); - $self->{output}->exit(); + $self->{global}->{client} = $result->{$oid_tcpCurClientConn}; + $self->{global}->{server} = $result->{$oid_tcpCurServerConn}; + $self->{global}->{active} = $result->{$oid_tcpActiveServerConn}; } - + 1; __END__ @@ -124,30 +174,16 @@ Check connections usage (Client, Server, ActiveServer) (NS-ROOT-MIBv2). =over 8 -=item B<--warning-server> +=item B<--warning-*> -Warning on number of server TCP connections +Threshold warning. +Can be: 'server', 'active', 'client'. -=item B<--critical-server> +=item B<--critical-*> -Critical on number of server TCP connections - -=item B<--warning-client> - -Warning on number of client TCP connections - -=item B<--critical-client> - -Critical on number of client TCP connections - -=item B<--warning-active> - -Warning on number of server Active TCP connections - -=item B<--critical-active> - -Critical on number of server Active TCP connections +Threshold critical. +Can be: 'server', 'active', 'client'. =back -=cut +=cut \ No newline at end of file diff --git a/network/juniper/common/screenos/mode/sessions.pm b/network/juniper/common/screenos/mode/sessions.pm index d890eb21e..9ee4e8f73 100644 --- a/network/juniper/common/screenos/mode/sessions.pm +++ b/network/juniper/common/screenos/mode/sessions.pm @@ -87,11 +87,13 @@ sub run { threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $exit_failed = $self->{perfdata}->threshold_check(value => $prct_failed, threshold => [ { label => 'critical-failed', 'exit_litteral' => 'critical' }, { label => 'warning-failed', exit_litteral => 'warning' } ]); - my $exit_code = $self->{output}->get_most_critical(status => [ $exit_failed, $exit_used ]); - $self->{output}->output_add(severity => $exit_code, + $self->{output}->output_add(severity => $exit_used, short_msg => sprintf("%.2f%% of the sessions limit reached (%d of max. %d)", $prct_used, $cp_used, $cp_total)); + $self->{output}->output_add(severity => $exit_failed, + short_msg => sprintf("%.2f%% of failed sessions (%d of max. %d)", + $prct_failed, $cp_failed, $cp_total)); $self->{output}->perfdata_add(label => 'sessions', value => $cp_used,