diff --git a/centreon/common/aruba/snmp/mode/apusers.pm b/centreon/common/aruba/snmp/mode/apusers.pm index b80f8309e..bb85880f9 100644 --- a/centreon/common/aruba/snmp/mode/apusers.pm +++ b/centreon/common/aruba/snmp/mode/apusers.pm @@ -20,15 +20,21 @@ package centreon::common::aruba::snmp::mode::apusers; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; -my $maps_counters = { - global => { - '000_total' => { set => { +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'essid', type => 1, cb_prefix_output => 'prefix_essid_output', message_multiple => 'All users by ESSID are ok' }, + { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All users by AP are ok' }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'total', set => { key_values => [ { name => 'total' } ], output_template => 'Total Users : %s', perfdatas => [ @@ -37,7 +43,7 @@ my $maps_counters = { ], } }, - '001_total-none' => { set => { + { label => 'total-none', set => { key_values => [ { name => 'total_none' } ], output_template => 'Total Auth None : %s', perfdatas => [ @@ -46,7 +52,7 @@ my $maps_counters = { ], } }, - '002_total-other' => { set => { + { label => 'total-other', set => { key_values => [ { name => 'total_other' } ], output_template => 'Total Auth Other : %s', perfdatas => [ @@ -55,7 +61,7 @@ my $maps_counters = { ], } }, - '003_total-web' => { set => { + { label => 'total-web', set => { key_values => [ { name => 'total_web' } ], output_template => 'Total Auth Web : %s', perfdatas => [ @@ -64,7 +70,7 @@ my $maps_counters = { ], } }, - '004_total-dot1x' => { set => { + { label => 'total-dot1x', set => { key_values => [ { name => 'total_dot1x' } ], output_template => 'Total Auth Dot1x : %s', perfdatas => [ @@ -73,7 +79,7 @@ my $maps_counters = { ], } }, - '005_total-vpn' => { set => { + { label => 'total-vpn', set => { key_values => [ { name => 'total_vpn' } ], output_template => 'Total Auth Vpn : %s', perfdatas => [ @@ -82,7 +88,7 @@ my $maps_counters = { ], } }, - '006_total-mac' => { set => { + { label => 'total-mac', set => { key_values => [ { name => 'total_mac' } ], output_template => 'Total Auth Mac : %s', perfdatas => [ @@ -91,7 +97,7 @@ my $maps_counters = { ], } }, - '007_avg-connection-time' => { set => { + { label => 'avg-connection-time', set => { key_values => [ { name => 'avg_connection_time' } ], output_template => 'Users average connection time : %.3f seconds', perfdatas => [ @@ -100,30 +106,44 @@ my $maps_counters = { ], } }, - }, - total_ap => { - '000_total-ap' => { set => { - key_values => [ { name => 'users' }, { name => 'bssid' } ], - output_template => 'Users : %s', - perfdatas => [ - { label => 'total', value => 'users_absolute', template => '%s', - unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'bssid_absolute' }, - ], - } - }, - }, - total_essid => { - '000_total-essid' => { set => { + ]; + + $self->{maps_counters}->{essid} = [ + { label => 'total-essid', set => { key_values => [ { name => 'users' }, { name => 'essid' } ], - output_template => 'Users : %s', + output_template => 'users : %s', perfdatas => [ - { label => 'total', value => 'users_absolute', template => '%s', + { label => 'essid', value => 'users_absolute', template => '%s', unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'essid_absolute' }, ], } }, - } -}; + ]; + + $self->{maps_counters}->{ap} = [ + { label => 'total-ap', set => { + key_values => [ { name => 'users' }, { name => 'bssid' } ], + output_template => 'users : %s', + perfdatas => [ + { label => 'ap', value => 'users_absolute', template => '%s', + unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'bssid_absolute' }, + ], + } + }, + ]; +} + +sub prefix_essid_output { + my ($self, %options) = @_; + + return "ESSID '" . $options{instance_value}->{essid} . "' "; +} + +sub prefix_ap_output { + my ($self, %options) = @_; + + return "AP '" . $options{instance_value}->{bssid} . "' "; +} sub new { my ($class, %options) = @_; @@ -134,206 +154,13 @@ sub new { $options{options}->add_options(arguments => { "filter-ip-address:s" => { name => 'filter_ip_address' }, - "filter-essid:s" => { name => 'filter_essid' }, + "filter-bssid:s" => { name => 'filter_bssid' }, + "filter-essid:s" => { name => 'filter_essid' }, }); - - foreach my $key (('global', 'total_ap', 'total_essid')) { - 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; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach my $key (('global', 'total_ap', 'total_essid')) { - foreach (keys %{$maps_counters->{$key}}) { - $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); - } - } -} - -sub run_total { - 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(); - } - - 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_ap { - my ($self, %options) = @_; - - my $multiple = 1; - if (scalar(keys %{$self->{ap_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All users by AP are ok'); - } - - foreach my $id (sort keys %{$self->{ap_selected}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits = (); - foreach (sort keys %{$maps_counters->{total_ap}}) { - my $obj = $maps_counters->{total_ap}->{$_}->{obj}; - $obj->set(instance => $id); - - my ($value_check) = $obj->execute(values => $self->{ap_selected}->{$id}); - - 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(extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "AP '$id' $long_msg"); - 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 => "AP '$id' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "AP '$id' $long_msg"); - } - } -} - -sub run_essid { - my ($self, %options) = @_; - - my $multiple = 1; - if (scalar(keys %{$self->{essid_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All users by ESSID are ok'); - } - - foreach my $id (sort keys %{$self->{essid_selected}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits = (); - foreach (sort keys %{$maps_counters->{total_essid}}) { - my $obj = $maps_counters->{total_essid}->{$_}->{obj}; - $obj->set(instance => $id); - - my ($value_check) = $obj->execute(values => $self->{essid_selected}->{$id}); - - 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(extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "ESSID '$id' $long_msg"); - 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 => "ESSID '$id' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "ESSID '$id' $long_msg"); - } - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - $self->manage_selection(); - $self->run_total(); - $self->run_ap(); - $self->run_essid(); - - $self->{output}->display(); - $self->{output}->exit(); -} - my %map_auth_method = ( 0 => 'none', 1 => 'web', 2 => 'mac', 3 => 'vpn', @@ -368,10 +195,10 @@ sub manage_selection { $self->{global} = { total => 0, total_none => 0, total_web => 0, total_mac => 0, total_vpn => 0, total_dot1x => 0, total_kerberos => 0, total_secureId => 0, total_pubcookie => 0, total_xSec => 0, xSecMachine => 0, 'total_via-vpn' => 0, total_other => 0 }; - $self->{ap_selected} = {}; - $self->{essid_selected} = {}; + $self->{ap} = {}; + $self->{essid} = {}; - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ + $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_wlsxSwitchRole }, { oid => $oid_wlsxUserEntry, start => $mapping->{nUserUpTime}->{oid}, end => $mapping->{nUserAuthenticationMethod}->{oid} }, { oid => $mapping2->{nUserApBSSID}->{oid} }, @@ -398,8 +225,8 @@ sub manage_selection { foreach my $oid (keys %{$self->{results}->{$oid_wlsxUserEntry}}) { next if ($oid !~ /^$mapping->{nUserAuthenticationMethod}->{oid}\.(.*)$/); my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_wlsxUserEntry}, instance => $instance); - my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{nUserApBSSID}->{oid}}, instance => $instance); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_wlsxUserEntry}, instance => $instance); + my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{nUserApBSSID}->{oid}}, instance => $instance); # security next if (!defined($result2->{nUserApBSSID})); @@ -408,12 +235,14 @@ sub manage_selection { $map_ap{$bssid}->{ip} !~ /$self->{option_results}->{filter_ip_address}/); next if (defined($self->{option_results}->{filter_essid}) && $self->{option_results}->{filter_essid} ne '' && $map_ap{$bssid}->{essid} !~ /$self->{option_results}->{filter_essid}/); + next if (defined($self->{option_results}->{filter_bssid}) && $self->{option_results}->{filter_bssid} ne '' && + $bssid !~ /$self->{option_results}->{filter_bssid}/); - $self->{ap_selected}->{$bssid} = { users => 0, bssid => $bssid } if (!defined($self->{ap_selected}->{$bssid})); - $self->{ap_selected}->{$bssid}->{users}++; + $self->{ap}->{$bssid} = { users => 0, bssid => $bssid } if (!defined($self->{ap}->{$bssid})); + $self->{ap}->{$bssid}->{users}++; - $self->{essid_selected}->{$map_ap{$bssid}->{essid}} = { users => 0, essid => $map_ap{$bssid}->{essid} } if (!defined($self->{essid_selected}->{$map_ap{$bssid}->{essid}})); - $self->{essid_selected}->{$map_ap{$bssid}->{essid}}->{users}++; + $self->{essid}->{$map_ap{$bssid}->{essid}} = { users => 0, essid => $map_ap{$bssid}->{essid} } if (!defined($self->{essid}->{$map_ap{$bssid}->{essid}})); + $self->{essid}->{$map_ap{$bssid}->{essid}}->{users}++; $self->{global}->{total}++; $self->{global}->{'total_' . $result->{nUserAuthenticationMethod}}++; @@ -439,13 +268,15 @@ Check total users connected. Threshold warning. Can be: 'total', 'total-none', 'total-other', 'total-web', -'total-dot1x', 'total-vpn', 'total-mac', 'avg-connection-time' (seconds). +'total-dot1x', 'total-vpn', 'total-mac', 'avg-connection-time' (seconds), +'total-ap', 'total-essid'. =item B<--critical-*> Threshold critical. Can be: 'total', 'total-none', 'total-other', 'total-web', -'total-dot1x', 'total-vpn', 'total-mac', 'avg-connection-time' (seconds). +'total-dot1x', 'total-vpn', 'total-mac', 'avg-connection-time' (seconds), +'total-ap', 'total-essid'. =item B<--filter-ip-address> @@ -455,6 +286,10 @@ Filter by ip address (regexp can be used). Filter by ESSID (regexp can be used). +=item B<--filter-bssid> + +Filter by BSSID (regexp can be used). + =back =cut diff --git a/network/aerohive/snmp/mode/connectedusers.pm b/network/aerohive/snmp/mode/connectedusers.pm new file mode 100644 index 000000000..e4839dd42 --- /dev/null +++ b/network/aerohive/snmp/mode/connectedusers.pm @@ -0,0 +1,142 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::aerohive::snmp::mode::connectedusers; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'ssid', type => 1, cb_prefix_output => 'prefix_ssid_output', message_multiple => 'All users by SSID are ok' }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'total', set => { + key_values => [ { name => 'total' } ], + output_template => 'Total Users : %s', + perfdatas => [ + { label => 'total', value => 'total_absolute', template => '%s', + unit => 'users', min => 0 }, + ], + } + }, + ]; + $self->{maps_counters}->{ssid} = [ + { label => 'ssid', set => { + key_values => [ { name => 'total' }, { name => 'display' } ], + output_template => 'users : %s', + perfdatas => [ + { label => 'ssid', value => 'total_absolute', template => '%s', + unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_ssid_output { + my ($self, %options) = @_; + + return "SSID '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-ssid:s" => { name => 'filter_ssid' }, + }); + + return $self; +} + +my $oid_ahSSIDNAME = '.1.3.6.1.4.1.26928.1.1.1.2.1.1.1.2'; +my $oid_ahClientSSID = '.1.3.6.1.4.1.26928.1.1.1.2.1.2.1.10'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { total => 0 }; + $self->{ssid} = {}; + + $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_ahSSIDNAME }, + { oid => $oid_ahClientSSID }, + ], + nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}->{ $oid_ahSSIDNAME }}) { + my $ssid = $self->{results}->{ $oid_ahSSIDNAME }->{$oid}; + if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' && + $ssid !~ /$self->{option_results}->{filter_ssid}/) { + $self->{output}->output_add(long_msg => "skipping ssid " . $ssid . " : no matching filter.", debug => 1); + next; + } + $self->{ssid}->{$ssid} = { display => $ssid, total => 0 } if (!defined($self->{ssid}->{$ssid})); + } + + foreach my $oid (keys %{$self->{results}->{ $oid_ahClientSSID }}) { + $self->{global}->{total}++; + my $ssid = $self->{results}->{ $oid_ahClientSSID }->{$oid}; + $self->{ssid}->{$ssid}->{total}++ if (defined($self->{ssid}->{$ssid})); + } + +} + +1; + +__END__ + +=head1 MODE + +Check number of connected users (total and by SSID). + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='ssid$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'total', 'ssid' + +=item B<--critical-*> + +Threshold critical. +Can be: 'total', 'ssid' + +=item B<--filter-ssid> + +Filter by SSID (can be a regexp). + +=back + +=cut diff --git a/network/aerohive/snmp/plugin.pm b/network/aerohive/snmp/plugin.pm new file mode 100644 index 000000000..02a736b20 --- /dev/null +++ b/network/aerohive/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::aerohive::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'connected-users' => 'network::aerohive::snmp::mode::connectedusers', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check aerohive equipment in SNMP + +=cut diff --git a/network/digi/standard/snmp/mode/cpu.pm b/network/digi/standard/snmp/mode/cpu.pm new file mode 100644 index 000000000..777483ee7 --- /dev/null +++ b/network/digi/standard/snmp/mode/cpu.pm @@ -0,0 +1,103 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::digi::standard::snmp::mode::cpu; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_cpuUtil = '.1.3.6.1.4.1.16378.10000.3.1.0'; + + $self->{results} = $self->{snmp}->get_leef(oids => [ $oid_cpuUtil ], + nothing_quit => 1); + + my $cpu = $self->{results}->{$oid_cpuUtil}; + + my $exit = $self->{perfdata}->threshold_check(value => $cpu, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("CPU Usage is %.2f%%", $cpu)); + $self->{output}->perfdata_add(label => "cpu", unit => '%', + value => $cpu, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0, max => 100); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check cpu usage (sarian-monitor.mib). + +=over 8 + +=item B<--warning> + +Threshold warning in percent. + +=item B<--critical> + +Threshold critical in percent. + +=back + +=cut diff --git a/network/digi/standard/snmp/mode/gprs.pm b/network/digi/standard/snmp/mode/gprs.pm new file mode 100644 index 000000000..7add1e7da --- /dev/null +++ b/network/digi/standard/snmp/mode/gprs.pm @@ -0,0 +1,272 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::digi::standard::snmp::mode::gprs; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold_output { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + my $msg; + + $msg = 'Attachement : ' . $self->{result_values}->{attachement}; + $msg .= ', Registration : ' . $self->{result_values}->{registered}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{registered} = $options{new_datas}->{$self->{instance} . '_registered'}; + $self->{result_values}->{attachement} = $options{new_datas}->{$self->{instance} . '_attachement'}; + return 0; +} + +sub custom_tech_threshold_output { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_technology}) && $instance_mode->{option_results}->{critical_technology} ne '' && + eval "$instance_mode->{option_results}->{critical_technology}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_technology}) && $instance_mode->{option_results}->{warning_technology} ne '' && + eval "$instance_mode->{option_results}->{warning_technology}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_tech_output { + my ($self, %options) = @_; + my $msg; + + $msg = 'Technology : ' . $self->{result_values}->{technology}; + return $msg; +} + +sub custom_tech_calc { + my ($self, %options) = @_; + + $self->{result_values}->{technology} = $options{new_datas}->{$self->{instance} . '_technology'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'gprs', type => 0 }, + ]; + $self->{maps_counters}->{gprs} = [ + { label => 'signal', set => { + key_values => [ { name => 'signal' } ], + output_template => 'Signal : %d dBm', + perfdatas => [ + { label => 'signal_strenght', value => 'signal_absolute', template => '%s', + unit => 'dBm' }, + ], + } + }, + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'registered' }, { name => 'attachement' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold_output'), + } + }, + { label => 'technology', threshold => 0, set => { + key_values => [ { name => 'technology' } ], + closure_custom_calc => $self->can('custom_tech_calc'), + closure_custom_output => $self->can('custom_tech_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_tech_threshold_output'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{attachement} eq "notAttached" or %{registered} !~ /registeredHostNetwork|registeredRoaming/' }, + "warning-technology:s" => { name => 'warning_technology', default => '' }, + "critical-technology:s" => { name => 'critical_technology', default => '%{technology} !~ /2G|3G|4G/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status', 'warning_technology', 'critical_technology' )) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +my %map_gprs_registration = ( + 0 => 'notRegisteredNotSearching', + 1 => 'registeredHostNetwork', + 2 => 'notRegisteredSearching', + 3 => 'registrationDenied', + 4 => 'unknown', + 5 => 'registeredRoaming', + 6 => 'unrecognised', +); + +my %map_gprs_attachement = ( + 0 => 'notAtached', + 1 => 'attached', +); + +my %map_gprs_technology = ( + 1 => 'unknown', + 2 => 'GPRS(2G)', + 3 => 'EDGE(2G)', + 4 => 'UMTS(3G)', + 5 => 'HSDPA(3G)', + 6 => 'HSUPA(3G)', + 7 => 'DC-HSPA+(3G)', + 8 => 'LTE(4G)', +); + +my $oid_gprsSignalStrength = '.1.3.6.1.4.1.16378.10000.2.1.0'; +my $oid_gprsRegistered = '.1.3.6.1.4.1.16378.10000.2.2.0'; +my $oid_gprsAttached = '.1.3.6.1.4.1.16378.10000.2.3.0'; +my $oid_gprsNetworkTechnology = '.1.3.6.1.4.1.16378.10000.2.7.0'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{gprs} = {}; + $self->{results} = $options{snmp}->get_leef(oids => [ $oid_gprsSignalStrength, $oid_gprsRegistered, + $oid_gprsAttached, $oid_gprsNetworkTechnology ], + nothing_quit => 1); + + $self->{gprs} = { signal => $self->{results}->{$oid_gprsSignalStrength}, + registered => $map_gprs_registration{$self->{results}->{$oid_gprsRegistered}}, + attachement => $map_gprs_attachement{$self->{results}->{$oid_gprsAttached}}, + technology => $map_gprs_technology{$self->{results}->{$oid_gprsNetworkTechnology}}, + }; + +} + +1; + +__END__ + +=head1 MODE + +Check AP status. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='signal|technology' + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{registered}, %{attachement} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{attachement} eq "attached" and %{registered} !~ /registeredHostNetwork|registeredRoaming/' +Can used special variables like: %{registered}, %{attachement} + +=item B<--warning-technology> + +Set warning threshold for technology. +Use special variables %{technology}. + +=item B<--critical-technology> + +Set critical threshold for technology (Default: '%{technology} !~ /2G|3G|4G/' +Use special variables %{technology}. + +=item B<--warning-signal> + +Threshold warning for signal strength. + +=item B<--critical-signal> + +Threshold critical for signal strength. + +=back + +=cut diff --git a/network/digi/standard/snmp/mode/memory.pm b/network/digi/standard/snmp/mode/memory.pm new file mode 100644 index 000000000..b72e8b78a --- /dev/null +++ b/network/digi/standard/snmp/mode/memory.pm @@ -0,0 +1,111 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::digi::standard::snmp::mode::memory; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_totalMemory = '.1.3.6.1.4.1.16378.10000.3.17.0'; # in Kbytes + my $oid_freeMemory = '.1.3.6.1.4.1.16378.10000.3.18.0'; # in Kbytes + + my $result = $self->{snmp}->get_leef(oids => [$oid_totalMemory, $oid_freeMemory], + nothing_quit => 1); + my $free = $result->{$oid_freeMemory} * 1024; + my $total_size = $result->{$oid_totalMemory} * 1024; + my $used = $total_size - $free; + + my $prct_used = $used * 100 / $total_size; + my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); + my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $used); + + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Ram used %s (%.2f%%), Total: %s", + $used_value . " " . $used_unit, $prct_used, + $total_value . " " . $total_unit)); + + $self->{output}->perfdata_add(label => "used", unit => 'B', + value => $used, + 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), + min => 0, max => $total_size); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check memory usage (sarian-monitor.mib). + +=over 8 + +=item B<--warning> + +Threshold warning in percent. + +=item B<--critical> + +Threshold critical in percent. + +=back + +=cut diff --git a/network/digi/standard/snmp/mode/temperature.pm b/network/digi/standard/snmp/mode/temperature.pm new file mode 100644 index 000000000..b31c8e293 --- /dev/null +++ b/network/digi/standard/snmp/mode/temperature.pm @@ -0,0 +1,124 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and temperatureplication monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.temperatureache.org/licenses/LICENSE-2.0 +# +# Unless required by temperatureplicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::digi::standard::snmp::mode::temperature; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'temperature', type => 0, skipped_code => { -10 => 1 } }, + ]; + $self->{maps_counters}->{temperature} = [ + { label => 'device', set => { + key_values => [ { name => 'device' } ], + output_template => 'Temp Device : %d °C', + perfdatas => [ + { label => 'tempDevice', value => 'device_absolute', template => '%d', + unit => 'C' }, + ], + } + }, + { label => 'processor', set => { + key_values => [ { name => 'processor' } ], + output_template => 'Temp Processor : %d °C', + perfdatas => [ + { label => 'tempProcessor', value => 'processor_absolute', template => '%d', + unit => 'C' }, + ], + } + }, + { label => 'modem', set => { + key_values => [ { name => 'modem' } ], + output_template => 'Temp Modem : %d °C', + perfdatas => [ + { label => 'tempModem', value => 'modem_absolute', template => '%d', + unit => 'C' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +my $oid_temperature = '.1.3.6.1.4.1.16378.10000.3.11.0'; +my $oid_processorTemperature = '.1.3.6.1.4.1.16378.10000.3.12.0'; +my $oid_modemTemperature = '.1.3.6.1.4.1.16378.10000.3.13.0'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + + $self->{temperature} = {}; + $self->{results} = $self->{snmp}->get_leef(oids => [ $oid_temperature, $oid_processorTemperature, $oid_modemTemperature ], + nothing_quit => 1); + + $self->{temperature} = { device => $self->{results}->{$oid_temperature} > -20 ? $self->{results}->{$oid_temperature} : undef, + processor => $self->{results}->{$oid_processorTemperature}, + modem => $self->{results}->{$oid_modemTemperature} }; + +} + +1; + +__END__ + +=head1 MODE + +Check Digi equipment temperature (sarian-monitor.mib) + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='processor|modem' + +=item B<--warning-*> + +Threshold warning. +Can be: 'device', 'modem', 'processor' (C). + +=item B<--critical-*> + +Threshold critical. +Can be: 'device', 'modem', 'processor' (C). + +=back + +=cut diff --git a/network/digi/standard/snmp/plugin.pm b/network/digi/standard/snmp/plugin.pm new file mode 100644 index 000000000..732425486 --- /dev/null +++ b/network/digi/standard/snmp/plugin.pm @@ -0,0 +1,53 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::digi::standard::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'cpu' => 'network::digi::standard::snmp::mode::cpu', + 'memory' => 'network::digi::standard::snmp::mode::memory', + 'temperature' => 'network::digi::standard::snmp::mode::temperature', + 'gprs' => 'network::digi::standard::snmp::mode::gprs', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check DIGI equipement supporting standard sarian-monitor.mib + +=cut diff --git a/network/sonus/sbc/plugin.pm b/network/sonus/sbc/plugin.pm new file mode 100644 index 000000000..c0cc3d9cf --- /dev/null +++ b/network/sonus/sbc/plugin.pm @@ -0,0 +1,59 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::sonus::sbc::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'call-statistics' => 'network::sonus::sbc::snmp::mode::callstats', + 'channels' => 'network::sonus::sbc::snmp::mode::channels', + 'cpu' => 'snmp_standard::mode::cpu', + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'dsp-stats' => 'network::sonus::sbc::snmp::mode::dspstats', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + 'storage' => 'snmp_standard::mode::storage', + 'swap' => 'snmp_standard::mode::swap', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Sonus Session Border Controllers equipment in SNMP. + +=cut diff --git a/network/sonus/sbc/snmp/callstats.pm b/network/sonus/sbc/snmp/callstats.pm new file mode 100644 index 000000000..92c55d54c --- /dev/null +++ b/network/sonus/sbc/snmp/callstats.pm @@ -0,0 +1,173 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::sonus::sbc::snmp::mode::callstats; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'port', type => 1, cb_prefix_output => 'prefix_port_output', message_multiple => 'All calls stats on ports are OK' }, + ]; + + $self->{maps_counters}->{port} = [ + { label => 'current-calls', set => { + key_values => [ { name => 'current' }, { name => 'display' } ], + output_template => 'Current calls : %s', + perfdatas => [ + { label => 'current', value => 'current_absolute', template => '%d', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-per-sec', set => { + key_values => [ { name => 'total', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'total calls: %.2f/s', + perfdatas => [ + { label => 'total', value => 'total_per_second', template => '%.2f', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'connected-per-sec', set => { + key_values => [ { name => 'connected', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'connected calls: %.2f/s', + perfdatas => [ + { label => 'connected', value => 'connected_per_second', template => '%.2f', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'refused-per-sec', set => { + key_values => [ { name => 'refused', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'refused calls: %.2f/s', + perfdatas => [ + { label => 'refused', value => 'refused_per_second', template => '%.2f', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'errored-per-sec', set => { + key_values => [ { name => 'errored', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'errored calls: %.2f/s', + perfdatas => [ + { label => 'errored', value => 'errored_per_second', template => '%.2f', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'blocked-per-sec', set => { + key_values => [ { name => 'blocked', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'blocked calls: %.2f/s', + perfdatas => [ + { label => 'blocked', value => 'blocked_per_second', template => '%.2f', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_dsp_output { + my ($self, %options) = @_; + + return "Port => '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + return $self; +} + +my $mapping = { + uxPTCurrentCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.5' }, + uxPTTotalCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.6' }, + uxPTConnectedCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.7' }, + uxPTRefusedCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.8' }, + uxPTErroredCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.9' }, + uxPTBlockedCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.18' }, +}; + +my $oid_uxPortTable = '.1.3.6.1.4.1.177.15.1.5.1.2.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{cache_name} = "sonus_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + $self->{results} = $options{snmp}->get_table(oid => $oid_uxPortTable, + nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}}) { + next if $oid !~ /^$mapping->{uxPTCurrentCalls}->{oid}\.(.*)$/; + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + $self->{port}->{$instance} = { current => $result->{uxPTCurrentCalls}, + total => $result->{uxPTTotalCalls}, + connected => $result->{uxPTConnectedCalls}, + refused => $result->{uxPTRefusedCalls}, + errored => $result->{uxPTErroredCalls}, + blocked => $result->{uxPTBlockedCalls}, + display => $instance }; + } +} + +1; + +__END__ + +=head1 MODE + +Check Call statistics + +=over 8 + +=item B<--warning-*> + +Warning on counters. Can be ('current-calls', 'total-per-sec', 'connected-per-sec', 'refused-per-sec', 'errored-per-sec', 'blocked-per-sec') + +=item B<--critical-*> + +Critical on counters. Can be ('current-calls', 'total-per-sec', 'connected-per-sec', 'refused-per-sec', 'errored-per-sec', 'blocked-per-sec') + +=back + +=cut diff --git a/network/sonus/sbc/snmp/channels.pm b/network/sonus/sbc/snmp/channels.pm new file mode 100644 index 000000000..5c98a74ab --- /dev/null +++ b/network/sonus/sbc/snmp/channels.pm @@ -0,0 +1,406 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::sonus::sbc::snmp::mode::channels; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_threshold_output { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + my $msg; + + if ($self->{result_values}->{admstatus} eq 'disabled') { + $msg = ' is disabled (admin)'; + } else { + $msg = 'Oper Status : ' . $self->{result_values}->{opstatus}; + } + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{opstatus} = $options{new_datas}->{$self->{instance} . '_opstatus'}; + $self->{result_values}->{admstatus} = $options{new_datas}->{$self->{instance} . '_admstatus'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'channels', type => 1, cb_prefix_output => 'prefix_channels_output', message_multiple => 'All channels are ok' } + ]; + $self->{maps_counters}->{global} = [ + { label => 'total', set => { + key_values => [ { name => 'total' } ], + output_template => 'Total channels : %s', + perfdatas => [ + { label => 'total', value => 'total_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-outofservice', set => { + key_values => [ { name => 'outofservice' } ], + output_template => 'OutOfService : %s', + perfdatas => [ + { label => 'total_outofservice', value => 'outofservice_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-idle', set => { + key_values => [ { name => 'idle' } ], + output_template => 'Idle : %s', + perfdatas => [ + { label => 'total_idle', value => 'idle_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-pending', set => { + key_values => [ { name => 'pending' } ], + output_template => 'Pending : %s', + perfdatas => [ + { label => 'total_pending', value => 'pending_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-waitingforroute', set => { + key_values => [ { name => 'waitingforroute' } ], + output_template => 'WaitingForRoute : %s', + perfdatas => [ + { label => 'total_waitingforroute', value => 'waitingforroute_absolute_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-actionlist', set => { + key_values => [ { name => 'actionlist' } ], + output_template => 'ActionList : %s', + perfdatas => [ + { label => 'total_actionlist', value => 'actionlist_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-waitingfordigits', set => { + key_values => [ { name => 'waitingfordigits' } ], + output_template => 'WaitingForDigits : %s', + perfdatas => [ + { label => 'total_waitingfordigits', value => 'waitingfordigits_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-remotesetup', set => { + key_values => [ { name => 'remotesetup' } ], + output_template => 'RemoteSetup : %s', + perfdatas => [ + { label => 'total_remotesetup', value => 'remotesetup_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-peersetup', set => { + key_values => [ { name => 'peersetup' } ], + output_template => 'PeerSetup : %s', + perfdatas => [ + { label => 'total_peersetup', value => 'peersetup_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-alerting', set => { + key_values => [ { name => 'alerting' } ], + output_template => 'Alerting : %s', + perfdatas => [ + { label => 'total_alerting', value => 'alerting_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-inbandinfo', set => { + key_values => [ { name => 'inbandinfo' } ], + output_template => 'InBandInfo : %s', + perfdatas => [ + { label => 'total_inbandinfo', value => 'inbandinfo_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-connected', set => { + key_values => [ { name => 'connected' } ], + output_template => 'Connected : %s', + perfdatas => [ + { label => 'total_connected', value => 'connected_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-tonegeneration', set => { + key_values => [ { name => 'tonegeneration' } ], + output_template => 'ToneGeneration : %s', + perfdatas => [ + { label => 'total_tonegeneration', value => 'tonegeneration_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-releasing', set => { + key_values => [ { name => 'releasing' } ], + output_template => 'Releasing : %s', + perfdatas => [ + { label => 'total_releasing', value => 'releasing_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-aborting', set => { + key_values => [ { name => 'aborting' } ], + output_template => 'Aborting : %s', + perfdatas => [ + { label => 'total_aborting', value => 'aborting_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-resetting', set => { + key_values => [ { name => 'resetting' } ], + output_template => 'Resetting : %s', + perfdatas => [ + { label => 'total_resetting', value => 'resetting_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-up', set => { + key_values => [ { name => 'up' } ], + output_template => 'Up : %s', + perfdatas => [ + { label => 'total_up', value => 'up_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-down', set => { + key_values => [ { name => 'down' } ], + output_template => 'Down : %s', + perfdatas => [ + { label => 'total_down', value => 'down_absolute', template => '%s', + min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{channels} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + { label => 'seconds', set => { + key_values => [ { name => 'seconds' }, { name => 'display' } ], + output_template => 'lifetime : %s seconds', + perfdatas => [ + { label => 'seconds', value => 'seconds_absolute', template => '%s', + min => 0, unit => 's', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{admstatus} eq "enable" and %{opstatus} !~ /up|idle|connected/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_channels_output { + my ($self, %options) = @_; + + return "Channels '" . $options{instance_value}->{display} . "' "; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +my %map_admin_status = ( + 0 => 'down', + 1 => 'up', +); +my %map_operation_status = ( + 0 => 'outOfService', + 1 => 'idle', + 2 => 'pending', + 3 => 'waitingForRoute', + 4 => 'actionList', + 5 => 'waitingForDigits', + 6 => 'remoteSetUp', + 7 => 'peerSetUp', + 8 => 'alerting', + 9 => 'inBandInfo', + 10 => 'connected', + 11 => 'toneGeneration', + 12 => 'releasing', + 13 => 'aborting', + 14 => 'resetting', + 15 => 'up', + 16 => 'down', +); + +my $mapping = { + uxChAdminState => { oid => '.1.3.6.1.4.1.177.15.1.5.6.1.5', map => \%map_admin_status }, + uxChOperState => { oid => '.1.3.6.1.4.1.177.15.1.5.6.1.6', map => \%map_operation_status }, + uxChInUseSeconds => { oid => '.1.3.6.1.4.1.177.15.1.5.6.1.7' }, +}; + +my $oid_uxChannelStatusEntry = '.1.3.6.1.4.1.177.15.1.5.6.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{channels} = {}; + $self->{global} = { total => 0, outofservice => 0, idle => 0, + pending => 0, waitingforroute => 0, actionlist => 0, + waitingfordigits => 0, remotesetup => 0, peersetup => 0, + alerting => 0, inbandinfo => 0, connected => 0, tonegeneration => 0, + releasing => 0, aborting => 0, resetting => 0, up => 0, down => 0 }; + + $self->{results} = $options{snmp}->get_table(oid => $oid_uxChannelStatusEntry, + nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}}) { + next if($oid !~ /^$mapping->{uxChOperState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + $self->{global}->{total}++; + my $oper_state = lc($result->{uxChOperState}); + + $self->{global}->{$oper_state}++; + $self->{channels}->{$instance} = {display => $instance, + opstatus => $result->{uxChOperState}, + admstatus => $result->{uxChAdminState}, + seconds => $result->{uxChInUseSeconds}}; + } + +} + +1; + +__END__ + +=head1 MODE + +Check Channels on Sonus + +=over 8 + +=item B<--filter-counters> + +Only display some counters (Can be 'channels' or 'global'). + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{display} + +=item B<--critical-status> + +Set critical threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'total', 'total-outofservice', 'total-disassociating', 'total-idle', 'total-pending', 'total-waitingforroute', 'total-actionlist', 'total-waitingfordigits', 'total-remotesetup', 'total-peersetup', 'total-alerting', 'total-inbandinfo', 'total-connected', 'total-tonegeneration', 'total-releasing', 'total-aborting', 'total-resetting', 'total-up', 'total-down', 'seconds' + +=item B<--critical-*> + +Threshold critical. +Can be: 'total', 'total', 'total-outofservice', 'total-disassociating', 'total-idle', 'total-pending', 'total-waitingforroute', 'total-actionlist', 'total-waitingfordigits', 'total-remotesetup', 'total-peersetup', 'total-alerting', 'total-inbandinfo', 'total-connected', 'total-tonegeneration', 'total-releasing', 'total-aborting', 'total-resetting', 'total-up', 'total-down', 'seconds' + +=back + +=cut diff --git a/network/sonus/sbc/snmp/dspstats.pm b/network/sonus/sbc/snmp/dspstats.pm new file mode 100644 index 000000000..e59f37440 --- /dev/null +++ b/network/sonus/sbc/snmp/dspstats.pm @@ -0,0 +1,209 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::sonus::sbc::snmp::mode::dspstats; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_threshold_output { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_state_output { + my ($self, %options) = @_; + + my $msg = sprintf("state is '%s'", $self->{result_values}->{state}); + return $msg; +} + +sub custom_state_calc { + my ($self, %options) = @_; + + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'dsp', type => 1, cb_prefix_output => 'prefix_dsp_output', message_multiple => 'All DSP stats and states are OK' }, + ]; + $self->{maps_counters}->{dsp} = [ + { label => 'state', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'display' } ], + closure_custom_calc => \&custom_state_calc, + closure_custom_output => \&custom_state_output, + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&custom_threshold_output, + } + }, + { label => 'cpu', set => { + key_values => [ { name => 'cpu' }, { name => 'display' } ], + output_template => 'CPU Usage: %s', + perfdatas => [ + { label => 'cpu', value => 'cpu_absolute', template => '%d', + min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'channels', set => { + key_values => [ { name => 'channels' }, { name => 'display' } ], + output_template => 'Active Channels: %s', + perfdatas => [ + { label => 'channels', value => 'channels_absolute', template => '%d', + min => 0, unit => 'channels', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_dsp_output { + my ($self, %options) = @_; + + return "DSP '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{state} eq "down"' }, + }); + return $self; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(); + $instance_mode = $self; +} + +my %map_status = ( + 0 => 'down', + 1 => 'up', +); + +my $mapping = { + uxDSPIsPresent => { oid => '.1.3.6.1.4.1.177.15.1.6.1.3' }, + uxDSPCPUUsage => { oid => '.1.3.6.1.4.1.177.15.1.6.1.4' }, + uxDSPChannelsInUse => { oid => '.1.3.6.1.4.1.177.15.1.6.1.5' }, + uxDSPServiceStatus => { oid => '.1.3.6.1.4.1.177.15.1.6.1.6', map => \%map_status }, +}; + +my $oid_uxDSPResourceTable = '.1.3.6.1.4.1.177.15.1.6.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + + $self->{results} = $options{snmp}->get_table(oid => $oid_uxDSPResourceTable, + nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}}) { + next if($oid !~ /^$mapping->{uxDSPServiceStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + next if ($result->{uxDSPIsPresent} eq '0'); + + $self->{dsp}->{$instance} = { state => $result->{uxDSPServiceStatus}, + cpu => $result->{uxDSPCPUUsage}, + channels => $result->{uxDSPChannelsInUse}, + display => $instance }; + } +} + +1; + +__END__ + +=head1 MODE + +Check Digital Signal Processing statistics + +=over 8 + +=item B<--warning-*> + +Warning on counters. Can be ('cpu', 'channels') + +=item B<--critical-*> + +Warning on counters. Can be ('cpu', 'channels') + +=item B<--warning-status> + +Set warning threshold for status. Use "%{state}" as a special variable. +Useful to be notified when tunnel is up "%{state} eq 'up'" + +=item B<--critical-status> + +Set critical threshold for status. Use "%{state}" as a special variable. +Useful to be notified when tunnel is up "%{state} eq 'up'" + +=back + +=cut diff --git a/os/linux/local/mode/traffic.pm b/os/linux/local/mode/traffic.pm index 908b6c5df..753fd9d32 100644 --- a/os/linux/local/mode/traffic.pm +++ b/os/linux/local/mode/traffic.pm @@ -113,6 +113,7 @@ sub manage_selection { command_options => $self->{option_results}->{command_options}); while ($stdout =~ /^(\S+)(.*?)(\n\n|\n$)/msg) { my ($interface_name, $values) = ($1, $2); + $interface_name =~ s/:$//; my $states = ''; $states .= 'R' if ($values =~ /RUNNING/ms); $states .= 'U' if ($values =~ /UP/ms); @@ -128,8 +129,9 @@ sub manage_selection { next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $interface_name ne $self->{option_results}->{name}); - $values =~ /RX bytes:(\S+).*?TX bytes:(\S+)/msi; - $self->{result}->{$interface_name} = {state => $states, in => $1, out => $2}; + if ($values =~ /RX bytes:(\S+).*?TX bytes:(\S+)/msi || $values =~ /RX packets\s+\d+\s+bytes\s+(\S+).*?TX packets\s+\d+\s+bytes\s+(\S+)/msi) { + $self->{result}->{$interface_name} = {state => $states, in => $1, out => $2}; + } } if (scalar(keys %{$self->{result}}) <= 0) { @@ -373,4 +375,4 @@ Don't display loopback interfaces. =back -=cut \ No newline at end of file +=cut