diff --git a/centreon-plugins/apps/activedirectory/local/mode/dcdiag.pm b/centreon-plugins/apps/activedirectory/local/mode/dcdiag.pm index 44862774e..b46ab7e03 100644 --- a/centreon-plugins/apps/activedirectory/local/mode/dcdiag.pm +++ b/centreon-plugins/apps/activedirectory/local/mode/dcdiag.pm @@ -34,19 +34,19 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "config:s" => { name => 'config' }, - "language:s" => { name => 'language', default => 'en' }, - "dfsr" => { name => 'dfsr' }, - "noeventlog" => { name => 'noeventlog' }, - "nomachineaccount" => { name => 'nomachineaccount' }, - "timeout:s" => { name => 'timeout', default => 30 }, - }); + $options{options}->add_options(arguments => { + 'config:s' => { name => 'config' }, + 'language:s' => { name => 'language', default => 'en' }, + 'dfsr' => { name => 'dfsr' }, + 'noeventlog' => { name => 'noeventlog' }, + 'nomachineaccount' => { name => 'nomachineaccount' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + }); + $self->{os_is2003} = 0; $self->{os_is2008} = 0; $self->{os_is2012} = 0; + $self->{os_is2016} = 0; $self->{msg} = { global => undef, ok => undef, warning => undef, critical => undef }; return $self; @@ -72,12 +72,15 @@ sub check_version { # 5.1, 5.2 => XP/2003 # 6.0, 6.1 => Vista/7/2008 # 6.2, 6.3 => 2012 + # 10.0 => 2016, 2019 if ($ver_major == 5 && ($ver_minor == 1 || $ver_minor == 2)) { $self->{os_is2003} = 1; } elsif ($ver_major == 6 && ($ver_minor == 0 || $ver_minor == 1)) { $self->{os_is2008} = 1; } elsif ($ver_major == 6 && ($ver_minor == 2 || $ver_minor == 3)) { $self->{os_is2012} = 1; + } elsif ($ver_major == 10 && $ver_minor == 0) { + $self->{os_is2016} = 1; } else { $self->{output}->output_add(severity => 'UNKNOWN', short_msg => 'OS version ' . $ver_major . '.' . $ver_minor . ' not managed.'); @@ -136,19 +139,21 @@ sub dcdiag { my $dcdiag_cmd = 'dcdiag /test:services /test:replications /test:advertising /test:fsmocheck /test:ridmanager'; $dcdiag_cmd .= ' /test:machineaccount' if (!defined($self->{option_results}->{nomachineaccount})); $dcdiag_cmd .= ' /test:frssysvol' if ($self->{os_is2003} == 1); - $dcdiag_cmd .= ' /test:sysvolcheck' if ($self->{os_is2008} == 1 || $self->{os_is2012} == 1); + $dcdiag_cmd .= ' /test:sysvolcheck' if ($self->{os_is2008} == 1 || $self->{os_is2012} == 1 || $self->{os_is2016} == 1); if (!defined($self->{option_results}->{noeventlog})) { $dcdiag_cmd .= ' /test:frsevent /test:kccevent' if ($self->{os_is2003} == 1); - $dcdiag_cmd .= ' /test:frsevent /test:kccevent' if (($self->{os_is2008} == 1 || $self->{os_is2012} == 1) && !defined($self->{option_results}->{dfsr})); - $dcdiag_cmd .= ' /test:dfsrevent /test:kccevent' if (($self->{os_is2008} == 1 || $self->{os_is2012} == 1) && defined($self->{option_results}->{dfsr})); + $dcdiag_cmd .= ' /test:frsevent /test:kccevent' if (($self->{os_is2008} == 1 || $self->{os_is2012} == 1 || $self->{os_is2016} == 1) && !defined($self->{option_results}->{dfsr})); + $dcdiag_cmd .= ' /test:dfsrevent /test:kccevent' if (($self->{os_is2008} == 1 || $self->{os_is2012} == 1 || $self->{os_is2016} == 1) && defined($self->{option_results}->{dfsr})); } - my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, - timeout => $self->{option_results}->{timeout}, - command => $dcdiag_cmd, - command_path => undef, - command_options => undef); + my ($stdout) = centreon::plugins::misc::windows_execute( + output => $self->{output}, + timeout => $self->{option_results}->{timeout}, + command => $dcdiag_cmd, + command_path => undef, + command_options => undef + ); my $match = 0; while ($stdout =~ /$self->{msg}->{global}/imsg) { diff --git a/centreon-plugins/apps/activedirectory/local/mode/dfsrbacklog.pm b/centreon-plugins/apps/activedirectory/local/mode/dfsrbacklog.pm index 538c3f094..ff5b94fd4 100644 --- a/centreon-plugins/apps/activedirectory/local/mode/dfsrbacklog.pm +++ b/centreon-plugins/apps/activedirectory/local/mode/dfsrbacklog.pm @@ -49,7 +49,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "sending-member:s" => { name => 'sending_member' }, diff --git a/centreon-plugins/apps/activedirectory/local/mode/netdom.pm b/centreon-plugins/apps/activedirectory/local/mode/netdom.pm index 94afd219d..d08b48314 100644 --- a/centreon-plugins/apps/activedirectory/local/mode/netdom.pm +++ b/centreon-plugins/apps/activedirectory/local/mode/netdom.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "domain:s" => { name => 'domain', }, diff --git a/centreon-plugins/apps/activedirectory/wsman/mode/dcdiag.pm b/centreon-plugins/apps/activedirectory/wsman/mode/dcdiag.pm index e9457cbaf..5af1bc810 100644 --- a/centreon-plugins/apps/activedirectory/wsman/mode/dcdiag.pm +++ b/centreon-plugins/apps/activedirectory/wsman/mode/dcdiag.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "config:s" => { name => 'config', }, diff --git a/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm b/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm index 7ac6b40f2..9c48ad447 100644 --- a/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm +++ b/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm @@ -118,7 +118,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/deployment.pm b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/deployment.pm index bbffa88d5..392d7c74a 100644 --- a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/deployment.pm +++ b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/deployment.pm @@ -206,7 +206,6 @@ sub new { 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 => '%{status} =~ /Warning/i' }, diff --git a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/events.pm b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/events.pm index b98f66f1b..8eb9829bc 100644 --- a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/events.pm +++ b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/events.pm @@ -72,7 +72,6 @@ sub new { 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 => '%{status} =~ /Warning/i' }, diff --git a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/fullscan.pm b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/fullscan.pm index 2c10a709b..84840b556 100644 --- a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/fullscan.pm +++ b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/fullscan.pm @@ -72,7 +72,6 @@ sub new { 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 => '%{status} =~ /Warning/i' }, diff --git a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/logicalnetwork.pm b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/logicalnetwork.pm index 11d5172aa..165143d10 100644 --- a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/logicalnetwork.pm +++ b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/logicalnetwork.pm @@ -96,7 +96,6 @@ sub new { 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 => '%{status} =~ /Warning/i' }, diff --git a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/protection.pm b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/protection.pm index dc6eb87e9..1cc25a87d 100644 --- a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/protection.pm +++ b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/protection.pm @@ -104,7 +104,6 @@ sub new { 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 => '%{status} =~ /Warning/i' }, diff --git a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm index 34f6a3045..44504495a 100644 --- a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm +++ b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm @@ -129,7 +129,6 @@ sub new { 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 => '%{status} =~ /Warning/i' }, diff --git a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm index 25c2d25a4..fa720950f 100644 --- a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm +++ b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm @@ -60,7 +60,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters', default => '' }, diff --git a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm index 2425f62e1..49920a3e4 100644 --- a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm +++ b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm @@ -98,7 +98,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters', default => '' }, diff --git a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm index 9dd7e6b60..761db9bcd 100644 --- a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm +++ b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm @@ -73,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm index ac31aeee5..ed086ee04 100644 --- a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm +++ b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm @@ -92,7 +92,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters', default => '' }, diff --git a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm index 2522c22b8..8a515cc84 100644 --- a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm +++ b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm @@ -105,7 +105,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters', default => '' }, diff --git a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm index c19cf59f0..950a81e73 100644 --- a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm +++ b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm @@ -105,7 +105,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters', default => '' }, diff --git a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm index 041cd431f..b57e79ee3 100644 --- a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm +++ b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm @@ -98,7 +98,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters', default => '' }, diff --git a/centreon-plugins/apps/apache/serverstatus/mode/cpuload.pm b/centreon-plugins/apps/apache/serverstatus/mode/cpuload.pm index 1b0a0b331..f708d5e23 100644 --- a/centreon-plugins/apps/apache/serverstatus/mode/cpuload.pm +++ b/centreon-plugins/apps/apache/serverstatus/mode/cpuload.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/apache/serverstatus/mode/requests.pm b/centreon-plugins/apps/apache/serverstatus/mode/requests.pm index 8fa141e58..de06aace2 100644 --- a/centreon-plugins/apps/apache/serverstatus/mode/requests.pm +++ b/centreon-plugins/apps/apache/serverstatus/mode/requests.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/apache/serverstatus/mode/responsetime.pm b/centreon-plugins/apps/apache/serverstatus/mode/responsetime.pm index a10cdfd20..706452db7 100644 --- a/centreon-plugins/apps/apache/serverstatus/mode/responsetime.pm +++ b/centreon-plugins/apps/apache/serverstatus/mode/responsetime.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/apache/serverstatus/mode/slotstates.pm b/centreon-plugins/apps/apache/serverstatus/mode/slotstates.pm index b7df83972..910d5a770 100644 --- a/centreon-plugins/apps/apache/serverstatus/mode/slotstates.pm +++ b/centreon-plugins/apps/apache/serverstatus/mode/slotstates.pm @@ -199,7 +199,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/apache/serverstatus/mode/workers.pm b/centreon-plugins/apps/apache/serverstatus/mode/workers.pm index f94da1217..7e848c71b 100644 --- a/centreon-plugins/apps/apache/serverstatus/mode/workers.pm +++ b/centreon-plugins/apps/apache/serverstatus/mode/workers.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/apcupsd/local/mode/batterycharge.pm b/centreon-plugins/apps/apcupsd/local/mode/batterycharge.pm index eed6fc14e..a09645d1a 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/batterycharge.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/batterycharge.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/apcupsd/local/mode/batteryvoltage.pm b/centreon-plugins/apps/apcupsd/local/mode/batteryvoltage.pm index 6a1e05c72..8d28621ec 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/batteryvoltage.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/batteryvoltage.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/apcupsd/local/mode/linefrequency.pm b/centreon-plugins/apps/apcupsd/local/mode/linefrequency.pm index 329032a55..294c77af6 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/linefrequency.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/linefrequency.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/apcupsd/local/mode/linevoltage.pm b/centreon-plugins/apps/apcupsd/local/mode/linevoltage.pm index 2d1320a7f..832d48f26 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/linevoltage.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/linevoltage.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/apcupsd/local/mode/loadpercentage.pm b/centreon-plugins/apps/apcupsd/local/mode/loadpercentage.pm index 88e3f468c..66cd4a923 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/loadpercentage.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/loadpercentage.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/apcupsd/local/mode/outputvoltage.pm b/centreon-plugins/apps/apcupsd/local/mode/outputvoltage.pm index d8d11ffab..f17043f8a 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/outputvoltage.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/outputvoltage.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/apcupsd/local/mode/temperature.pm b/centreon-plugins/apps/apcupsd/local/mode/temperature.pm index 02f0d4608..630a5e44c 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/temperature.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/temperature.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/apcupsd/local/mode/timeleft.pm b/centreon-plugins/apps/apcupsd/local/mode/timeleft.pm index d9bef0597..1c767953c 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/timeleft.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/timeleft.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm b/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm index 7087bc164..e57db4735 100644 --- a/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm +++ b/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "host-pattern:s" => { name => 'host_pattern', default => 'all' }, "prettify" => { name => 'prettify' }, diff --git a/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm b/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm index a1bc10600..e9765447c 100644 --- a/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm +++ b/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm @@ -22,7 +22,6 @@ package apps::automation::ansible::tower::custom::towercli; use strict; use warnings; -use DateTime; use JSON::XS; sub new { diff --git a/centreon-plugins/apps/automation/ansible/tower/mode/dashboard.pm b/centreon-plugins/apps/automation/ansible/tower/mode/dashboard.pm index a6d00946a..42c46e075 100644 --- a/centreon-plugins/apps/automation/ansible/tower/mode/dashboard.pm +++ b/centreon-plugins/apps/automation/ansible/tower/mode/dashboard.pm @@ -92,17 +92,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/automation/ansible/tower/mode/discovery.pm b/centreon-plugins/apps/automation/ansible/tower/mode/discovery.pm index 940a7dce9..4a8a8ce37 100644 --- a/centreon-plugins/apps/automation/ansible/tower/mode/discovery.pm +++ b/centreon-plugins/apps/automation/ansible/tower/mode/discovery.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "group" => { name => 'group' }, "inventory" => { name => 'inventory' }, diff --git a/centreon-plugins/apps/automation/ansible/tower/mode/inventorystatistics.pm b/centreon-plugins/apps/automation/ansible/tower/mode/inventorystatistics.pm index 35d2609ee..c173ed29d 100644 --- a/centreon-plugins/apps/automation/ansible/tower/mode/inventorystatistics.pm +++ b/centreon-plugins/apps/automation/ansible/tower/mode/inventorystatistics.pm @@ -140,19 +140,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter-inventory" => { name => 'filter_inventory' }, + 'filter-inventory:s' => { name => 'filter_inventory' }, }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/backup/arcserve/udp/mssql/mode/jobstatus.pm b/centreon-plugins/apps/backup/arcserve/udp/mssql/mode/jobstatus.pm new file mode 100644 index 000000000..23d0630c5 --- /dev/null +++ b/centreon-plugins/apps/backup/arcserve/udp/mssql/mode/jobstatus.pm @@ -0,0 +1,259 @@ +# +# Copyright 2019 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 apps::backup::arcserve::udp::mssql::mode::jobstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + # To exclude some OK + if (defined($self->{instance_mode}->{option_results}->{ok_status}) && $self->{instance_mode}->{option_results}->{ok_status} ne '' && + eval "$self->{instance_mode}->{option_results}->{ok_status}") { + $status = 'ok'; + } elsif (defined($self->{instance_mode}->{option_results}->{critical_status}) && $self->{instance_mode}->{option_results}->{critical_status} ne '' && + eval "$self->{instance_mode}->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($self->{instance_mode}->{option_results}->{warning_status}) && $self->{instance_mode}->{option_results}->{warning_status} ne '' && + eval "$self->{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 = sprintf('status : %s (%s) [type: %s] [remote hostname: %s] [plan name: %s] [end time: %s]', + $self->{result_values}->{status} == 1 ? 'ok' : 'failed', + $self->{result_values}->{status}, + $self->{result_values}->{type}, + $self->{result_values}->{rhostname}, + $self->{result_values}->{plan_name}, + scalar(localtime($self->{result_values}->{end_time})) + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'job', type => 1, cb_prefix_output => 'prefix_job_output', message_multiple => 'All jobs are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'jobs.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'total jobs : %s', + perfdatas => [ + { label => 'total', value => 'total_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{job} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' }, + { name => 'type' }, { name => 'rhostname' }, { name => 'plan_name' }, + { name => 'elapsed_time' }, { name => 'end_time' } ], + closure_custom_calc => \&catalog_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'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-server-name:s' => { name => 'filter_server_name' }, + 'filter-type:s' => { name => 'filter_type' }, + 'filter-end-time:s' => { name => 'filter_end_time', default => 86400 }, + 'ok-status:s' => { name => 'ok_status', default => '%{status} == 1' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} != 1' }, + 'timezone:s' => { name => 'timezone' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => [ + 'ok_status', 'warning_status', 'critical_status'] + ); + + if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { + $ENV{TZ} = $self->{option_results}->{timezone}; + } +} + +sub prefix_job_output { + my ($self, %options) = @_; + + return "job '" . $options{instance_value}->{display} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $query = q{ + SELECT + lj.jobId, + lj.jobStatus, + rhostname, + DATEDIFF(s, '1970-01-01 00:00:00', lj.jobLocalStartTime) as start_time, + DATEDIFF(s, '1970-01-01 00:00:00', lj.jobLocalEndTime) as end_time, + ep.name, + lj.jobType, + lj.jobStatus + FROM as_edge_d2dJobHistory_lastJob lj LEFT OUTER JOIN as_edge_policy ep ON lj.planUUID = ep.uuid, + as_edge_host h + WHERE lj.agentId = h.rhostid + }; + $options{sql}->connect(); + $options{sql}->query(query => $query); + + $self->{global} = { total => 0 }; + $self->{job} = {}; + my ($count, $current_time) = (0, time()); + while ((my $row = $options{sql}->fetchrow_hashref())) { + my $rhostname = defined($row->{rhostname}) && $row->{rhostname} ne '' ? $row->{rhostname} : 'unknown'; + my $plan_name = defined($row->{name}) && $row->{name} ne '' ? $row->{name} : 'unknown'; + if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && + $row->{jobType} !~ /$self->{option_results}->{filter_type}/) { + $self->{output}->output_add(long_msg => "skipping job '" . $row->{jobId} . "': no matching filter type.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_end_time}) && $self->{option_results}->{filter_end_time} =~ /[0-9]+/ && + defined($row->{end_time}) && $row->{end_time} =~ /[0-9]+/ && $row->{end_time} < ($current_time - $self->{option_results}->{filter_end_time})) { + $self->{output}->output_add(long_msg => "skipping job '" . $row->{jobId} . "': end time too old.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_start_time}) && $self->{option_results}->{filter_start_time} =~ /[0-9]+/ && + defined($row->{start_time}) && $row->{start_time} =~ /[0-9]+/ && $row->{start_time} < ($current_time - $self->{option_results}->{filter_start_time})) { + $self->{output}->output_add(long_msg => "skipping job '" . $row->{jobId} . "': start time too old.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_server_name}) && $self->{option_results}->{filter_server_name} ne '' && + $row->{rhostname} !~ /$self->{option_results}->{filter_server_name}/) { + $self->{output}->output_add(long_msg => "skipping job '" . $row->{jobId} . "': no matching filter type.", debug => 1); + next; + } + + my $elapsed_time = defined($row->{start_time}) ? $current_time - $row->{start_time} : -1; + $self->{job}->{$row->{jobId}} = { + display => $row->{jobId}, + elapsed_time => $elapsed_time, + status => $row->{jobStatus}, + type => $row->{jobType}, + rhostname => $rhostname, + plan_name => $plan_name, + end_time => $row->{end_time}, + }; + + $self->{global}->{total}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check job status. + +=over 8 + +=item B<--filter-server-name> + +Filter job server name (can be a regexp). + +=item B<--filter-type> + +Filter job type (can be a regexp). + +=item B<--filter-start-time> + +Filter job with start time greater than current time less value in seconds. + +=item B<--filter-end-time> + +Filter job with end time greater than current time less value in seconds (Default: 86400). + +=item B<--timezone> + +Timezone of mssql server (If not set, we use current server execution timezone). + +=item B<--ok-status> + +Set ok threshold for status (Default: '%{status} == 1') +Can used special variables like: %{display}, %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} == 1') +Can used special variables like: %{display}, %{status}, %{type} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} != 1'). +Can used special variables like: %{display}, %{status}, %{type} + +=item B<--warning-total> + +Set warning threshold for total jobs. + +=item B<--critical-total> + +Set critical threshold for total jobs. + +=back + +=cut diff --git a/centreon-plugins/apps/backup/netbackup/local/mode/dedupstatus.pm b/centreon-plugins/apps/backup/netbackup/local/mode/dedupstatus.pm index 503590718..4a09d9c8b 100644 --- a/centreon-plugins/apps/backup/netbackup/local/mode/dedupstatus.pm +++ b/centreon-plugins/apps/backup/netbackup/local/mode/dedupstatus.pm @@ -85,7 +85,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/backup/netbackup/local/mode/drivecleaning.pm b/centreon-plugins/apps/backup/netbackup/local/mode/drivecleaning.pm index 3289c27d6..0055948a0 100644 --- a/centreon-plugins/apps/backup/netbackup/local/mode/drivecleaning.pm +++ b/centreon-plugins/apps/backup/netbackup/local/mode/drivecleaning.pm @@ -51,7 +51,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm b/centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm index 102cf7b97..e475b0e94 100644 --- a/centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm +++ b/centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/backup/netbackup/local/mode/jobstatus.pm b/centreon-plugins/apps/backup/netbackup/local/mode/jobstatus.pm index f07bdd3ae..5f0156daa 100644 --- a/centreon-plugins/apps/backup/netbackup/local/mode/jobstatus.pm +++ b/centreon-plugins/apps/backup/netbackup/local/mode/jobstatus.pm @@ -203,30 +203,29 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'bpdbjobs' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-report -most_columns' }, - "exec-only" => { name => 'exec_only' }, - "filter-policy-name:s" => { name => 'filter_policy_name' }, - "filter-type:s" => { name => 'filter_type' }, - "filter-end-time:s" => { name => 'filter_end_time', default => 86400 }, - "filter-start-time:s" => { name => 'filter_start_time' }, - "ok-status:s" => { name => 'ok_status', default => '%{status} == 0' }, - "warning-status:s" => { name => 'warning_status', default => '%{status} == 1' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} > 1' }, - "warning-long:s" => { name => 'warning_long' }, - "critical-long:s" => { name => 'critical_long' }, - "warning-frozen:s" => { name => 'warning_frozen' }, - "critical-frozen:s" => { name => 'critical_frozen', default => '%{state} =~ /active|queue/ && %{kb} == 0' }, + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'bpdbjobs' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-report -most_columns' }, + 'exec-only' => { name => 'exec_only' }, + 'filter-policy-name:s' => { name => 'filter_policy_name' }, + 'filter-type:s' => { name => 'filter_type' }, + 'filter-end-time:s' => { name => 'filter_end_time', default => 86400 }, + 'filter-start-time:s' => { name => 'filter_start_time' }, + 'ok-status:s' => { name => 'ok_status', default => '%{status} == 0' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} == 1' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} > 1' }, + 'warning-long:s' => { name => 'warning_long' }, + 'critical-long:s' => { name => 'critical_long' }, + 'warning-frozen:s' => { name => 'warning_frozen' }, + 'critical-frozen:s' => { name => 'critical_frozen', default => '%{state} =~ /active|queue/ && %{kb} == 0' }, }); return $self; @@ -311,7 +310,7 @@ sub manage_selection { ($values[0], $values[1], $values[2], $values[3], $values[4], $values[5], $values[8], $values[10], $values[14], $values[33]); $job_pname = defined($job_pname) && $job_pname ne '' ? $job_pname : 'unknown'; - $job_status = defined($job_status) && $job_status =~ /[0-9]/ ? $job_status : undef; + $job_status = defined($job_status) && $job_status =~ /[0-9]/ ? $job_status : -1; if (defined($self->{option_results}->{filter_policy_name}) && $self->{option_results}->{filter_policy_name} ne '' && $job_pname !~ /$self->{option_results}->{filter_policy_name}/) { $self->{output}->output_add(long_msg => "skipping job '" . $job_pname . "/" . $job_id . "': no matching filter.", debug => 1); diff --git a/centreon-plugins/apps/backup/netbackup/local/mode/listpolicies.pm b/centreon-plugins/apps/backup/netbackup/local/mode/listpolicies.pm index 345b49c44..18d2aaa29 100644 --- a/centreon-plugins/apps/backup/netbackup/local/mode/listpolicies.pm +++ b/centreon-plugins/apps/backup/netbackup/local/mode/listpolicies.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/backup/netbackup/local/mode/tapeusage.pm b/centreon-plugins/apps/backup/netbackup/local/mode/tapeusage.pm index fe881099d..be77f1e0e 100644 --- a/centreon-plugins/apps/backup/netbackup/local/mode/tapeusage.pm +++ b/centreon-plugins/apps/backup/netbackup/local/mode/tapeusage.pm @@ -110,7 +110,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, diff --git a/centreon-plugins/apps/backup/quadstor/local/mode/listvtl.pm b/centreon-plugins/apps/backup/quadstor/local/mode/listvtl.pm index 47623972f..01113fa73 100644 --- a/centreon-plugins/apps/backup/quadstor/local/mode/listvtl.pm +++ b/centreon-plugins/apps/backup/quadstor/local/mode/listvtl.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/backup/quadstor/local/mode/vtldiskusage.pm b/centreon-plugins/apps/backup/quadstor/local/mode/vtldiskusage.pm index 930a0a6fa..f1c564c3a 100644 --- a/centreon-plugins/apps/backup/quadstor/local/mode/vtldiskusage.pm +++ b/centreon-plugins/apps/backup/quadstor/local/mode/vtldiskusage.pm @@ -141,7 +141,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/backup/quadstor/local/mode/vtljobstatus.pm b/centreon-plugins/apps/backup/quadstor/local/mode/vtljobstatus.pm index 6afa2a83f..29f3645ed 100644 --- a/centreon-plugins/apps/backup/quadstor/local/mode/vtljobstatus.pm +++ b/centreon-plugins/apps/backup/quadstor/local/mode/vtljobstatus.pm @@ -148,7 +148,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm b/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm index 7a3f5d755..5178a4398 100644 --- a/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm +++ b/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm @@ -154,7 +154,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/backup/tsm/local/mode/actlog.pm b/centreon-plugins/apps/backup/tsm/local/mode/actlog.pm index b3245cfb6..ba103572a 100644 --- a/centreon-plugins/apps/backup/tsm/local/mode/actlog.pm +++ b/centreon-plugins/apps/backup/tsm/local/mode/actlog.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-time:s" => { name => 'filter_time', default => '1' }, diff --git a/centreon-plugins/apps/backup/tsm/local/mode/drives.pm b/centreon-plugins/apps/backup/tsm/local/mode/drives.pm index 3b98bdf39..f7de5ce73 100644 --- a/centreon-plugins/apps/backup/tsm/local/mode/drives.pm +++ b/centreon-plugins/apps/backup/tsm/local/mode/drives.pm @@ -111,7 +111,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/backup/tsm/local/mode/nodes.pm b/centreon-plugins/apps/backup/tsm/local/mode/nodes.pm index 02cc062b7..f26a4d41e 100644 --- a/centreon-plugins/apps/backup/tsm/local/mode/nodes.pm +++ b/centreon-plugins/apps/backup/tsm/local/mode/nodes.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/backup/tsm/local/mode/sessions.pm b/centreon-plugins/apps/backup/tsm/local/mode/sessions.pm index 4ceb1791b..2bff8216d 100644 --- a/centreon-plugins/apps/backup/tsm/local/mode/sessions.pm +++ b/centreon-plugins/apps/backup/tsm/local/mode/sessions.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-clientname:s" => { name => 'filter_clientname' }, diff --git a/centreon-plugins/apps/backup/tsm/local/mode/volumes.pm b/centreon-plugins/apps/backup/tsm/local/mode/volumes.pm index 34d31bef0..bfaaaa89d 100644 --- a/centreon-plugins/apps/backup/tsm/local/mode/volumes.pm +++ b/centreon-plugins/apps/backup/tsm/local/mode/volumes.pm @@ -116,7 +116,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-volume:s" => { name => 'filter_volume' }, diff --git a/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm b/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm index fde18d23d..e8e40fc05 100644 --- a/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm +++ b/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm @@ -138,7 +138,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 50 }, diff --git a/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm b/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm index 86620f8e3..3eb9c2c24 100644 --- a/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm +++ b/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 50 }, diff --git a/centreon-plugins/apps/bind9/web/mode/memoryusage.pm b/centreon-plugins/apps/bind9/web/mode/memoryusage.pm index eda534b51..7a672f496 100644 --- a/centreon-plugins/apps/bind9/web/mode/memoryusage.pm +++ b/centreon-plugins/apps/bind9/web/mode/memoryusage.pm @@ -93,7 +93,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/bind9/web/mode/serverusage.pm b/centreon-plugins/apps/bind9/web/mode/serverusage.pm index 9f996c75d..f7ff9e0ff 100644 --- a/centreon-plugins/apps/bind9/web/mode/serverusage.pm +++ b/centreon-plugins/apps/bind9/web/mode/serverusage.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/bind9/web/mode/zoneusage.pm b/centreon-plugins/apps/bind9/web/mode/zoneusage.pm index be327882f..ecc8cef06 100644 --- a/centreon-plugins/apps/bind9/web/mode/zoneusage.pm +++ b/centreon-plugins/apps/bind9/web/mode/zoneusage.pm @@ -82,7 +82,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/apps/biztalk/sql/mode/rlocationdisabled.pm b/centreon-plugins/apps/biztalk/sql/mode/rlocationdisabled.pm index e0c383c77..4ebad573a 100644 --- a/centreon-plugins/apps/biztalk/sql/mode/rlocationdisabled.pm +++ b/centreon-plugins/apps/biztalk/sql/mode/rlocationdisabled.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/apps/bluemind/mode/incoming.pm b/centreon-plugins/apps/bluemind/mode/incoming.pm index 3a59faae7..7d6b4a0f2 100644 --- a/centreon-plugins/apps/bluemind/mode/incoming.pm +++ b/centreon-plugins/apps/bluemind/mode/incoming.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '8086'}, diff --git a/centreon-plugins/apps/centreon/local/mode/bamservice.pm b/centreon-plugins/apps/centreon/local/mode/bamservice.pm index 8eb982913..3e380707e 100644 --- a/centreon-plugins/apps/centreon/local/mode/bamservice.pm +++ b/centreon-plugins/apps/centreon/local/mode/bamservice.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "centreon-config:s" => { name => 'centreon_config', default => '/etc/centreon/centreon-config.pm' }, "bam-id:s" => { name => 'bam_id', }, @@ -84,7 +83,7 @@ sub run { value => $current_level, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 0, + min => 0, max => 100, ); $self->{output}->display(); diff --git a/centreon-plugins/apps/centreon/local/mode/brokerstats.pm b/centreon-plugins/apps/centreon/local/mode/brokerstats.pm index 0a8f2ee80..852220a6d 100644 --- a/centreon-plugins/apps/centreon/local/mode/brokerstats.pm +++ b/centreon-plugins/apps/centreon/local/mode/brokerstats.pm @@ -103,7 +103,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "broker-stats-file:s@" => { name => 'broker_stats_file' }, diff --git a/centreon-plugins/apps/centreon/local/mode/centreonpluginsversion.pm b/centreon-plugins/apps/centreon/local/mode/centreonpluginsversion.pm index bf0a11dc1..fccfea264 100644 --- a/centreon-plugins/apps/centreon/local/mode/centreonpluginsversion.pm +++ b/centreon-plugins/apps/centreon/local/mode/centreonpluginsversion.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/apps/centreon/local/mode/downtimetrap.pm b/centreon-plugins/apps/centreon/local/mode/downtimetrap.pm index a2f82c392..9f5081178 100644 --- a/centreon-plugins/apps/centreon/local/mode/downtimetrap.pm +++ b/centreon-plugins/apps/centreon/local/mode/downtimetrap.pm @@ -55,7 +55,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "oid-trap:s" => { name => 'oid_trap', default => '.1.3.6.1.4.1.50000.1.1' }, diff --git a/centreon-plugins/apps/centreon/local/mode/dummy.pm b/centreon-plugins/apps/centreon/local/mode/dummy.pm index e26bb0448..6f8fd7a29 100644 --- a/centreon-plugins/apps/centreon/local/mode/dummy.pm +++ b/centreon-plugins/apps/centreon/local/mode/dummy.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "status:s" => { name => 'status' }, diff --git a/centreon-plugins/apps/centreon/local/mode/metaservice.pm b/centreon-plugins/apps/centreon/local/mode/metaservice.pm index 1a1dcd13a..ee6fed1d6 100644 --- a/centreon-plugins/apps/centreon/local/mode/metaservice.pm +++ b/centreon-plugins/apps/centreon/local/mode/metaservice.pm @@ -36,7 +36,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "centreon-config:s" => { name => 'centreon_config', default => '/etc/centreon/centreon-config.pm' }, diff --git a/centreon-plugins/apps/centreon/local/mode/notsodummy.pm b/centreon-plugins/apps/centreon/local/mode/notsodummy.pm new file mode 100644 index 000000000..585fcac0c --- /dev/null +++ b/centreon-plugins/apps/centreon/local/mode/notsodummy.pm @@ -0,0 +1,183 @@ +# +# Copyright 2019 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 apps::centreon::local::mode::notsodummy; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; +use Digest::MD5 qw(md5_hex); + +my %errors_service = (0 => 'OK', 1 => 'WARNING', 2 => 'CRITICAL', 3 => 'UNKNOWN'); +my %errors_host = (0 => 'UP', 1 => 'DOWN'); +my %errors_hash = ('UP' => 'OK', 'DOWN' => 'CRITICAL'); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "status-sequence:s" => { name => 'status_sequence' }, + "host" => { name => 'host' }, + "restart-sequence" => { name => 'restart_sequence' }, + "show-sequence" => { name => 'show_sequence' }, + "output:s" => { name => 'output' }, + }); + + $self->{cache} = centreon::plugins::statefile->new(%options); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (!defined($self->{option_results}->{status_sequence}) || $self->{option_results}->{status_sequence} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --status option."); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{output}) || $self->{option_results}->{output} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --output option."); + $self->{output}->option_exit(); + } + + foreach my $status (split(',', $self->{option_results}->{status_sequence})) { + if (!defined($self->{option_results}->{host}) && $status !~ /^[0-3]$/ && $status !~ /ok|warning|critical|unknown/i) { + $self->{output}->add_option_msg(short_msg => "Status should be in '0,1,2,3' or 'ok,warning,critical,unknown' (case isensitive)."); + $self->{output}->option_exit(); + } + if (defined($self->{option_results}->{host}) && $status !~ /^[0-1]$/ && $status !~ /up|down/i) { + $self->{output}->add_option_msg(short_msg => "Status should be in '0,1' or 'up,down' (case isensitive)."); + $self->{output}->option_exit(); + } + push @{$self->{status_sequence}}, $status; + } + + $self->{cache}->check_options(option_results => $self->{option_results}); +} + +sub get_next_status { + my ($self, %options) = @_; + + my $index; + my $has_cache_file = $options{statefile}->read(statefile => 'centreon_notsodummy_' . + md5_hex(@{$self->{status_sequence}}) . '_' . md5_hex($self->{option_results}->{output})); + + if ($has_cache_file == 0 || $self->{option_results}->{restart_sequence}) { + $index = 0; + my $datas = { last_timestamp => time(), status_sequence => $self->{status_sequence}, status_sequence_index => $index }; + $options{statefile}->write(data => $datas); + } else { + $index = $options{statefile}->get(name => 'status_sequence_index'); + $index = ($index < scalar(@{$self->{status_sequence}} - 1)) ? $index + 1 : 0; + my $datas = { last_timestamp => time(), status_sequence => $self->{status_sequence}, status_sequence_index => $index }; + $options{statefile}->write(data => $datas); + } + + return $self->{status_sequence}[$index], $index; +} + +sub get_sequence_output { + my ($self, %options) = @_; + + my @sequence_output; + + my $i = 0; + foreach my $status (split(',', $self->{option_results}->{status_sequence})) { + $status = $errors_service{$status} if ($status =~ /^[0-3]$/ && !defined($self->{option_results}->{host})); + $status = $errors_host{$status} if ($status =~ /^[0-1]$/ && defined($self->{option_results}->{host})); + + push @sequence_output, uc($status) if ($i == $options{index}); + push @sequence_output, lc($status) if ($i != $options{index}); + $i++ + } + + return join(',', @sequence_output); +} + +sub run { + my ($self, %options) = @_; + + my ($status, $index) = $self->get_next_status(statefile => $self->{cache}); + my $status_label = $status; + if (defined($self->{option_results}->{host})) { + $status_label = $errors_host{$status} if ($status =~ /^[0-1]$/); + $status = $errors_host{$status} if ($status =~ /^[0-1]$/); + $status = $errors_hash{uc($status)}; + } else { + $status_label = $errors_service{$status} if ($status =~ /^[0-3]$/); + $status = $errors_service{$status} if ($status =~ /^[0-3]$/); + } + my $output = $self->{option_results}->{output}; + $output .= ' [' . $self->get_sequence_output(index => $index) . ']' if ($self->{option_results}->{show_sequence}); + + $self->{output}->output_add( + severity => $status, + short_msg => uc($status_label) . ': ' . $output + ); + $self->{output}->perfdata_add( + nlabel => 'sequence.index.position', value => ++$index, + min => 1, max => scalar(@{$self->{status_sequence}}) + ); + $self->{output}->display(nolabel => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Do a not-so-dummy check. + +=over 8 + +=item B<--status-sequence> + +Comma separated sequence of statuses +from which the mode should pick is +return code from. +(Example: --status-sequence='ok,critical,ok,ok' or --status-sequence='up,up,down' --host) +(Should be numeric value between 0 and 3, or string in ok, warning, critical, unknown, up, down). + +=item B<--host> + +Host statuses. + +=item B<--restart-sequence> + +Restart the sequence from the beginning (ie. reset the sequence). + +=item B<--show-sequence> + +Show the sequence is the output. + +=item B<--output> + +Output to be returned. + +=back + +=cut diff --git a/centreon-plugins/apps/centreon/local/mode/retentionbroker.pm b/centreon-plugins/apps/centreon/local/mode/retentionbroker.pm index da23f13d5..1ae0d6968 100644 --- a/centreon-plugins/apps/centreon/local/mode/retentionbroker.pm +++ b/centreon-plugins/apps/centreon/local/mode/retentionbroker.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "broker-config:s@" => { name => 'broker_config' }, diff --git a/centreon-plugins/apps/centreon/local/plugin.pm b/centreon-plugins/apps/centreon/local/plugin.pm index 98e0ecd43..8c14ffc71 100644 --- a/centreon-plugins/apps/centreon/local/plugin.pm +++ b/centreon-plugins/apps/centreon/local/plugin.pm @@ -37,6 +37,7 @@ sub new { 'downtime-trap' => 'apps::centreon::local::mode::downtimetrap', 'dummy' => 'apps::centreon::local::mode::dummy', 'metaservice' => 'apps::centreon::local::mode::metaservice', + 'not-so-dummy' => 'apps::centreon::local::mode::notsodummy', 'retention-broker' => 'apps::centreon::local::mode::retentionbroker', ); diff --git a/centreon-plugins/apps/centreon/map/jmx/mode/brokerstats.pm b/centreon-plugins/apps/centreon/map/jmx/mode/brokerstats.pm index e3f5995c8..20827f960 100644 --- a/centreon-plugins/apps/centreon/map/jmx/mode/brokerstats.pm +++ b/centreon-plugins/apps/centreon/map/jmx/mode/brokerstats.pm @@ -89,7 +89,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters', default => '' }, diff --git a/centreon-plugins/apps/centreon/map/jmx/mode/enginestats.pm b/centreon-plugins/apps/centreon/map/jmx/mode/enginestats.pm index 1f209f4f9..1dac9d883 100644 --- a/centreon-plugins/apps/centreon/map/jmx/mode/enginestats.pm +++ b/centreon-plugins/apps/centreon/map/jmx/mode/enginestats.pm @@ -80,7 +80,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters', default => '' }, diff --git a/centreon-plugins/apps/centreon/map/jmx/mode/events.pm b/centreon-plugins/apps/centreon/map/jmx/mode/events.pm index 7c5e2f274..21ba0e3b0 100644 --- a/centreon-plugins/apps/centreon/map/jmx/mode/events.pm +++ b/centreon-plugins/apps/centreon/map/jmx/mode/events.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters', default => '' }, diff --git a/centreon-plugins/apps/centreon/map/jmx/mode/openviews.pm b/centreon-plugins/apps/centreon/map/jmx/mode/openviews.pm index f6f0e6459..8bca1a70d 100644 --- a/centreon-plugins/apps/centreon/map/jmx/mode/openviews.pm +++ b/centreon-plugins/apps/centreon/map/jmx/mode/openviews.pm @@ -49,7 +49,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/centreon/map/jmx/mode/sessions.pm b/centreon-plugins/apps/centreon/map/jmx/mode/sessions.pm index 74fc5eb12..68d42a53e 100644 --- a/centreon-plugins/apps/centreon/map/jmx/mode/sessions.pm +++ b/centreon-plugins/apps/centreon/map/jmx/mode/sessions.pm @@ -58,7 +58,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters', default => '' }, diff --git a/centreon-plugins/apps/centreon/map/jmx/mode/syncstats.pm b/centreon-plugins/apps/centreon/map/jmx/mode/syncstats.pm index 41c922d8a..4892da1c9 100644 --- a/centreon-plugins/apps/centreon/map/jmx/mode/syncstats.pm +++ b/centreon-plugins/apps/centreon/map/jmx/mode/syncstats.pm @@ -158,7 +158,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; } diff --git a/centreon-plugins/apps/centreon/map4/jmx/mode/elements.pm b/centreon-plugins/apps/centreon/map4/jmx/mode/elements.pm index ef5adc299..5d5182cb5 100644 --- a/centreon-plugins/apps/centreon/map4/jmx/mode/elements.pm +++ b/centreon-plugins/apps/centreon/map4/jmx/mode/elements.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/centreon/map4/jmx/mode/eventqueue.pm b/centreon-plugins/apps/centreon/map4/jmx/mode/eventqueue.pm index 81d92264a..b1ecb5993 100644 --- a/centreon-plugins/apps/centreon/map4/jmx/mode/eventqueue.pm +++ b/centreon-plugins/apps/centreon/map4/jmx/mode/eventqueue.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/centreon/map4/jmx/mode/eventstatistics.pm b/centreon-plugins/apps/centreon/map4/jmx/mode/eventstatistics.pm index 2909b7cca..645fed25d 100644 --- a/centreon-plugins/apps/centreon/map4/jmx/mode/eventstatistics.pm +++ b/centreon-plugins/apps/centreon/map4/jmx/mode/eventstatistics.pm @@ -38,7 +38,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-global:s" => { name => 'warning_global', }, diff --git a/centreon-plugins/apps/centreon/map4/jmx/mode/gates.pm b/centreon-plugins/apps/centreon/map4/jmx/mode/gates.pm index 74392ed0e..514fe3169 100644 --- a/centreon-plugins/apps/centreon/map4/jmx/mode/gates.pm +++ b/centreon-plugins/apps/centreon/map4/jmx/mode/gates.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/centreon/map4/jmx/mode/sessions.pm b/centreon-plugins/apps/centreon/map4/jmx/mode/sessions.pm index c0321efc0..07af552d8 100644 --- a/centreon-plugins/apps/centreon/map4/jmx/mode/sessions.pm +++ b/centreon-plugins/apps/centreon/map4/jmx/mode/sessions.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/centreon/restapi/custom/api.pm b/centreon-plugins/apps/centreon/restapi/custom/api.pm new file mode 100644 index 000000000..4cda2bd5d --- /dev/null +++ b/centreon-plugins/apps/centreon/restapi/custom/api.pm @@ -0,0 +1,285 @@ +# +# Copyright 2019 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 apps::centreon::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use centreon::plugins::statefile; +use JSON::XS; +use Digest::MD5 qw(md5_hex); + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port' }, + "proto:s" => { name => 'proto' }, + "api-username:s" => { name => 'api_username' }, + "api-password:s" => { name => 'api_password' }, + "api-path:s" => { name => 'api_path' }, + "timeout:s" => { name => 'timeout' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + $self->{cache} = centreon::plugins::statefile->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'http'; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 80; + $self->{api_username} = (defined($self->{option_results}->{api_username})) ? + $self->{option_results}->{api_username} : undef; + $self->{api_password} = (defined($self->{option_results}->{api_password})) ? + $self->{option_results}->{api_password} : undef; + $self->{api_path} = (defined($self->{option_results}->{api_path})) ? + $self->{option_results}->{api_path} : '/centreon/api/index.php'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_username}) || $self->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_password}) || $self->{api_password} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option."); + $self->{output}->option_exit(); + } + + $self->{cache}->check_options(option_results => $self->{option_results}); + + return 0; +} + +sub get_connection_infos { + my ($self, %options) = @_; + + return $self->{hostname} . '_' . $self->{http}->get_port(); +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + if (defined($self->{auth_token})) { + $self->{http}->add_header(key => 'Centreon-Auth-Token', value => $self->{auth_token}); + $self->{http}->add_header(key => 'Content-Type', value => 'application/json'); + } + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub get_auth_token { + my ($self, %options) = @_; + + my $has_cache_file = $options{statefile}->read(statefile => 'centreon_api_' . md5_hex($self->{hostname}) . + '_' . md5_hex($self->{api_username})); + my $expires_on = $options{statefile}->get(name => 'expires_on'); + my $auth_token = $options{statefile}->get(name => 'auth_token'); + + if ($has_cache_file == 0 || !defined($auth_token) || (($expires_on - time()) < 10)) { + my $post_param = [ 'username=' . $self->{api_username}, 'password=' . $self->{api_password} ]; + + $self->settings(); + + my $content = $self->{http}->request( + method => 'POST', + url_path => '/centreon/api/index.php?action=authenticate', + post_param => $post_param + ); + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); + $self->{output}->option_exit(); + } + if (!defined($decoded->{authToken})) { + $self->{output}->add_option_msg(short_msg => "Cannot get token"); + $self->{output}->option_exit(); + } + + $auth_token = $decoded->{authToken}; + my $datas = { last_timestamp => time(), auth_token => $decoded->{authToken}, expires_on => time() + 3600 }; + $options{statefile}->write(data => $datas); + } + + return $auth_token; +} + +sub request_api { + my ($self, %options) = @_; + + if (!defined($self->{auth_token})) { + $self->{auth_token} = $self->get_auth_token(statefile => $self->{cache}); + } + + $self->settings(); + + my $encoded_form_post; + eval { + $encoded_form_post = JSON::XS->new->utf8->encode($options{query_form_post}); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot encode json request"); + $self->{output}->option_exit(); + } + + my $content = $self->{http}->request( + method => $options{method}, + url_path => $options{url_path}, + query_form_post => $encoded_form_post, + critical_status => '', warning_status => '', unknown_status => '' + ); + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); + $self->{output}->option_exit(); + } + + return ($decoded, JSON::XS->new->utf8->pretty->encode($decoded)); +} + +sub submit_result { + my ($self, %options) = @_; + + my ($response, $raw) = $self->request_api( + method => 'POST', + url_path => $self->{api_path} . '?action=submit&object=centreon_submit_results', + query_form_post => $options{post_data} + ); + + return ($response, $raw); +} + +1; + +__END__ + +=head1 NAME + +Centreon REST API + +=head1 SYNOPSIS + +Centreon Rest API custom mode + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +Centreon hostname. + +=item B<--port> + +Port used (Default: 80) + +=item B<--proto> + +Specify https if needed (Default: 'http') + +=item B<--api-username> + +Centreon username. + +=item B<--api-password> + +Centreon password. + +=item B<--api-path> + +API base url path (Default: '/centreon/api/index.php'). + +=item B<--timeout> + +Set HTTP timeout in seconds (Default: '10'). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/centreon/restapi/mode/submitresult.pm b/centreon-plugins/apps/centreon/restapi/mode/submitresult.pm new file mode 100644 index 000000000..74e718029 --- /dev/null +++ b/centreon-plugins/apps/centreon/restapi/mode/submitresult.pm @@ -0,0 +1,156 @@ +# +# Copyright 2019 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 apps::centreon::restapi::mode::submitresult; + +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, cb_prefix_output => 'prefix_output', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'results-202', nlabel => 'results.202.count', set => { + key_values => [ { name => '202' } ], + output_template => '202: %d', + perfdatas => [ + { value => '202_absolute', template => '%d', min => 0 }, + ], + } + }, + { label => 'results-400', nlabel => 'results.400.count', set => { + key_values => [ { name => '400' } ], + output_template => '400: %d', + perfdatas => [ + { value => '400_absolute', template => '%d', min => 0 }, + ], + } + }, + { label => 'results-404', nlabel => 'results.404.count', set => { + key_values => [ { name => '404' } ], + output_template => '404: %d', + perfdatas => [ + { value => '404_absolute', template => '%d', min => 0 }, + ], + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Results "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "host:s@" => { name => 'host' }, + "service:s@" => { name => 'service' }, + "status:s@" => { name => 'status' }, + "output:s@" => { name => 'output' }, + "perfdata:s@" => { name => 'perfdata' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $post_data; + my $i = 0; + foreach (@{$self->{option_results}->{host}}) { + my %result; + $result{updatetime} = time(); + $result{host} = $_; + $result{service} = ${$self->{option_results}->{service}}[$i] if (defined(${$self->{option_results}->{service}}[$i])); + $result{status} = ${$self->{option_results}->{status}}[$i]; + $result{output} = ${$self->{option_results}->{output}}[$i]; + $result{perfdata} = ${$self->{option_results}->{perfdata}}[$i] if (defined(${$self->{option_results}->{perfdata}}[$i])); + push @{$post_data->{results}}, \%result; + $i++; + } + + my ($response, $raw) = $options{custom}->submit_result(post_data => $post_data); + + $self->{global} = { 202 => 0, 400 => 0, 404 => 0 }; + foreach my $result (@{$response->{results}}) { + $self->{global}->{$result->{code}}++; + } + + $self->{output}->output_add(long_msg => $raw); +} + +1; + +__END__ + +=head1 MODE + +Submit one or several results to the API. + +Examples: +perl centreon_plugins --plugin=apps::centreon::restapi::plugin --mode=submit-result --hostname=10.30.2.245 +--api-username=admin --api-password=centreon --host='MyHost' --service='TheService' --status=2 --output='Hi!' +--perfdata='france=3,brazil=0' --verbose + +=over 8 + +=item B<--host> + +Hostname (Mandatory). + +=item B<--service> + +Service description (If result's for a service). + +=item B<--status> + +Status in 0, 1, 2, 3 or ok, warning, critical, unknown for services, +or in 0, 1 or up, down for hosts (Mandatory). + +=item B<--output> + +Short output (Mandatory). + +=item B<--perfdata> + +Comma separated list of perfdata (Optionnal). + +=back + +=cut + diff --git a/centreon-plugins/apps/centreon/restapi/plugin.pm b/centreon-plugins/apps/centreon/restapi/plugin.pm new file mode 100644 index 000000000..3fa99e74a --- /dev/null +++ b/centreon-plugins/apps/centreon/restapi/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2019 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 apps::centreon::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'submit-result' => 'apps::centreon::restapi::mode::submitresult', + ); + + $self->{custom_modes}{api} = 'apps::centreon::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Interacts with Centreon RestAPI. + +=cut diff --git a/centreon-plugins/apps/centreon/sql/mode/countnotifications.pm b/centreon-plugins/apps/centreon/sql/mode/countnotifications.pm index 6e7b1f068..ee25b6df5 100644 --- a/centreon-plugins/apps/centreon/sql/mode/countnotifications.pm +++ b/centreon-plugins/apps/centreon/sql/mode/countnotifications.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/apps/centreon/sql/mode/countproblems.pm b/centreon-plugins/apps/centreon/sql/mode/countproblems.pm index a4378222a..bca184e7b 100644 --- a/centreon-plugins/apps/centreon/sql/mode/countproblems.pm +++ b/centreon-plugins/apps/centreon/sql/mode/countproblems.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/apps/centreon/sql/mode/countservices.pm b/centreon-plugins/apps/centreon/sql/mode/countservices.pm index f6ff2df86..2913a2483 100644 --- a/centreon-plugins/apps/centreon/sql/mode/countservices.pm +++ b/centreon-plugins/apps/centreon/sql/mode/countservices.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-poller:s" => { name => 'filter_poller' }, diff --git a/centreon-plugins/apps/centreon/sql/mode/dsmqueue.pm b/centreon-plugins/apps/centreon/sql/mode/dsmqueue.pm index b9d024b04..cbaeaf806 100644 --- a/centreon-plugins/apps/centreon/sql/mode/dsmqueue.pm +++ b/centreon-plugins/apps/centreon/sql/mode/dsmqueue.pm @@ -75,7 +75,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-host-queue:s" => { name => 'filter_host_queue' }, diff --git a/centreon-plugins/apps/centreon/sql/mode/multiservices.pm b/centreon-plugins/apps/centreon/sql/mode/multiservices.pm index cd6291f1f..2e1c70498 100644 --- a/centreon-plugins/apps/centreon/sql/mode/multiservices.pm +++ b/centreon-plugins/apps/centreon/sql/mode/multiservices.pm @@ -282,7 +282,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "config-file:s" => { name => 'config_file' }, diff --git a/centreon-plugins/apps/centreon/sql/mode/partitioning.pm b/centreon-plugins/apps/centreon/sql/mode/partitioning.pm index 468509483..98a303a65 100644 --- a/centreon-plugins/apps/centreon/sql/mode/partitioning.pm +++ b/centreon-plugins/apps/centreon/sql/mode/partitioning.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "tablename:s@" => { name => 'tablename' }, diff --git a/centreon-plugins/apps/centreon/sql/mode/pollerdelay.pm b/centreon-plugins/apps/centreon/sql/mode/pollerdelay.pm index 9329be835..2670bfa9a 100644 --- a/centreon-plugins/apps/centreon/sql/mode/pollerdelay.pm +++ b/centreon-plugins/apps/centreon/sql/mode/pollerdelay.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm b/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm index cf4b31178..a7d07e39a 100644 --- a/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm +++ b/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm @@ -129,9 +129,13 @@ sub custom_metric_threshold { my $label_warn = ($self->{result_values}->{type} eq 'unique') ? 'warning-metric' : 'warning-global-'.$self->{result_values}->{instance}; my $label_crit = ($self->{result_values}->{type} eq 'unique') ? 'critical-metric' : 'critical-global-'.$self->{result_values}->{instance}; - my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{perfdata_value}, - threshold => [ { label => $label_crit, exit_litteral => 'critical' }, - { label => $label_warn, exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check( + value => $self->{result_values}->{perfdata_value}, + threshold => [ + { label => $label_crit, exit_litteral => 'critical' }, + { label => $label_warn, exit_litteral => 'warning' } + ] + ); return $exit; } @@ -169,12 +173,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "config-file:s" => { name => 'config_file' }, - "json-data:s" => { name => 'json_data' }, - }); + $options{options}->add_options(arguments => { + 'config-file:s' => { name => 'config_file' }, + 'json-data:s' => { name => 'json_data' }, + 'database:s' => { name => 'database' }, + }); + return $self; } @@ -206,6 +210,10 @@ sub check_options { $config_data->{formatting}->{custom_message_metric} = "All metrics are OK" if (!exists($config_data->{formatting}->{custom_message_metric})); $config_data->{formatting}->{cannonical_separator} = "#" if (!exists($config_data->{formatting}->{cannonical_separator})); $config_data->{formatting}->{change_bytes} = 0 if (!exists($config_data->{formatting}->{change_bytes})); + + $self->{option_results}->{database} = + (defined($self->{option_results}->{database}) && $self->{option_results}->{database} ne '') ? + $self->{option_results}->{database} . '.' : 'centreon_storage.'; } sub parse_json_config { @@ -235,7 +243,6 @@ sub parse_json_config { sub manage_selection { my ($self, %options) = @_; - # $options{sql} = sqlmode object $self->{sql} = $options{sql}; $self->{sql}->connect(); $self->{metrics} = {}; @@ -254,7 +261,7 @@ sub manage_selection { }; foreach my $id (keys %{$config_data->{selection}}) { my $query = "SELECT index_data.host_name, index_data.service_description, metrics.metric_name, metrics.current_value, metrics.unit_name, metrics.min, metrics.max "; - $query .= "FROM centreon_storage.index_data, centreon_storage.metrics WHERE index_data.id = metrics.index_id "; + $query .= "FROM $self->{option_results}->{database}index_data, $self->{option_results}->{database}metrics WHERE index_data.id = metrics.index_id "; $query .= "AND index_data.service_description = '" . $config_data->{selection}->{$id}->{service_name} . "'"; $query .= "AND index_data.host_name = '" . $config_data->{selection}->{$id}->{host_name} . "'" ; $query .= "AND metrics.metric_name = '" . $config_data->{selection}->{$id}->{metric_name} . "'"; @@ -275,7 +282,7 @@ sub manage_selection { name => 'metric', type => 1, message_separator => $config_data->{formatting}->{message_separator}, message_multiple => $config_data->{formatting}->{custom_message_metric}, }; my $query = "SELECT index_data.host_name, index_data.service_description, metrics.metric_name, metrics.current_value, metrics.unit_name, metrics.min, metrics.max "; - $query .= "FROM centreon_storage.index_data, centreon_storage.metrics WHERE index_data.id = metrics.index_id "; + $query .= "FROM $self->{option_results}->{database}index_data, $self->{option_results}->{database}metrics WHERE index_data.id = metrics.index_id "; $query .= "AND index_data.service_description LIKE '" . $config_data->{filters}->{service} . "'" if (defined($config_data->{filters}->{service}) && ($config_data->{filters}->{service} ne '')); $query .= "AND index_data.host_name LIKE '" . $config_data->{filters}->{host} . "'" if (defined($config_data->{filters}->{host}) && ($config_data->{filters}->{host} ne '')); $query .= "AND metrics.metric_name LIKE '" . $config_data->{filters}->{metric} . "'" if (defined($config_data->{filters}->{metric}) && ($config_data->{filters}->{metric} ne '')); @@ -326,24 +333,28 @@ sub manage_selection { value => (defined($self->{option_results}->{'critical-global'})) ? $self->{option_results}->{'critical-global'} : $config_data->{virtualcurve}->{$vcurve}->{critical}); } - $self->{global}->{$vcurve} = {display => $vcurve, - type => 'global', - unit => $self->{vmetrics}->{$vcurve}->{unit}, - value => $self->{vmetrics}->{$vcurve}->{aggregated_value}, - min => $self->{vmetrics}->{$vcurve}->{min}, - max => $self->{vmetrics}->{$vcurve}->{max} }; - } + $self->{global}->{$vcurve} = { + display => $vcurve, + type => 'global', + unit => $self->{vmetrics}->{$vcurve}->{unit}, + value => $self->{vmetrics}->{$vcurve}->{aggregated_value}, + min => $self->{vmetrics}->{$vcurve}->{min}, + max => $self->{vmetrics}->{$vcurve}->{max} + }; + } - $self->{metric}->{$metric} = {display => $self->{metrics}->{$metric}->{display_name}, - type => 'unique', - unit => $self->{metrics}->{$metric}->{unit}, - value => $self->{metrics}->{$metric}->{current}, - min => $self->{metrics}->{$metric}->{min}, - max => $self->{metrics}->{$metric}->{max} } if ($self->{metrics}->{$metric}->{display} == 1); + $self->{metric}->{$metric} = { + display => $self->{metrics}->{$metric}->{display_name}, + type => 'unique', + unit => $self->{metrics}->{$metric}->{unit}, + value => $self->{metrics}->{$metric}->{current}, + min => $self->{metrics}->{$metric}->{min}, + max => $self->{metrics}->{$metric}->{max} + } if ($self->{metrics}->{$metric}->{display} == 1); } if (scalar(keys %{$self->{metric}}) <= 0 && scalar(keys %{$self->{vmetrics}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No metrics returned - are your selection/filters correct ?"); + $self->{output}->add_option_msg(short_msg => 'No metrics returned - are your selection/filters correct ?'); $self->{output}->option_exit(); } } @@ -360,6 +371,10 @@ e.g: aggregate multiple metrics (min,max,avg,sum) or custom operation =over 8 +=item B<--database> + +Specify the database (default: 'centreon_storage') + =item B<--config-file> Specify the full path to a json config file diff --git a/centreon-plugins/apps/checkmyws/mode/status.pm b/centreon-plugins/apps/checkmyws/mode/status.pm index eb2d057d5..560d0b41d 100644 --- a/centreon-plugins/apps/checkmyws/mode/status.pm +++ b/centreon-plugins/apps/checkmyws/mode/status.pm @@ -41,7 +41,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname', default => 'api.checkmy.ws'}, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/cisco/cms/restapi/mode/alarms.pm b/centreon-plugins/apps/cisco/cms/restapi/mode/alarms.pm index 4df8ad8a0..41182bf31 100644 --- a/centreon-plugins/apps/cisco/cms/restapi/mode/alarms.pm +++ b/centreon-plugins/apps/cisco/cms/restapi/mode/alarms.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-type:s" => { name => 'filter_type' }, diff --git a/centreon-plugins/apps/cisco/cms/restapi/mode/calls.pm b/centreon-plugins/apps/cisco/cms/restapi/mode/calls.pm index 004dfc5cd..d93c621a1 100644 --- a/centreon-plugins/apps/cisco/cms/restapi/mode/calls.pm +++ b/centreon-plugins/apps/cisco/cms/restapi/mode/calls.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters' }, diff --git a/centreon-plugins/apps/cisco/cms/restapi/mode/databasestatus.pm b/centreon-plugins/apps/cisco/cms/restapi/mode/databasestatus.pm index a1ba37ddb..f226e37e6 100644 --- a/centreon-plugins/apps/cisco/cms/restapi/mode/databasestatus.pm +++ b/centreon-plugins/apps/cisco/cms/restapi/mode/databasestatus.pm @@ -75,7 +75,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/apps/cisco/cms/restapi/mode/licenses.pm b/centreon-plugins/apps/cisco/cms/restapi/mode/licenses.pm index 3c8323d6e..01c014fac 100644 --- a/centreon-plugins/apps/cisco/cms/restapi/mode/licenses.pm +++ b/centreon-plugins/apps/cisco/cms/restapi/mode/licenses.pm @@ -78,7 +78,6 @@ sub new { 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 => '%{status} eq "activated" && %{expiry_days} < 60' }, diff --git a/centreon-plugins/apps/cisco/cms/restapi/mode/systemstatus.pm b/centreon-plugins/apps/cisco/cms/restapi/mode/systemstatus.pm index 8249e0969..6c177f6eb 100644 --- a/centreon-plugins/apps/cisco/cms/restapi/mode/systemstatus.pm +++ b/centreon-plugins/apps/cisco/cms/restapi/mode/systemstatus.pm @@ -142,7 +142,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters' }, diff --git a/centreon-plugins/apps/cisco/ise/restapi/mode/session.pm b/centreon-plugins/apps/cisco/ise/restapi/mode/session.pm index 0fdcd838e..29074ef63 100644 --- a/centreon-plugins/apps/cisco/ise/restapi/mode/session.pm +++ b/centreon-plugins/apps/cisco/ise/restapi/mode/session.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters' }, diff --git a/centreon-plugins/apps/citrix/local/mode/folder.pm b/centreon-plugins/apps/citrix/local/mode/folder.pm index af3b6ae34..d74fa6e4f 100644 --- a/centreon-plugins/apps/citrix/local/mode/folder.pm +++ b/centreon-plugins/apps/citrix/local/mode/folder.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/citrix/local/mode/license.pm b/centreon-plugins/apps/citrix/local/mode/license.pm index 021b43ebd..ebee962a9 100644 --- a/centreon-plugins/apps/citrix/local/mode/license.pm +++ b/centreon-plugins/apps/citrix/local/mode/license.pm @@ -20,80 +20,96 @@ package apps::citrix::local::mode::license; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Win32::OLE; +sub custom_license_output { + my ($self, %options) = @_; + + my $msg = sprintf("Licenses Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)", + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute}); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'usage', nlabel => 'licenses.usage.count', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_license_output'), + perfdatas => [ + { label => 'mem_used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 }, + ], + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'licenses.free.count', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_license_output'), + perfdatas => [ + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', cast_int => 1 }, + ], + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'licenses.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Licenses Used : %.2f %%', + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + $options{options}->add_options(arguments => { + }); + 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 { +sub manage_selection { my ($self, %options) = @_; - $self->{output}->output_add(severity => 'Ok', - short_msg => "All licenses are ok"); - my $wmi = Win32::OLE->GetObject('winmgmts:root\CitrixLicensing'); if (!defined($wmi)) { - $self->{output}->add_option_msg(short_msg => "Cant create server object:" . Win32::OLE->LastError()); + $self->{output}->add_option_msg(short_msg => 'Cant create server object:' . Win32::OLE->LastError()); $self->{output}->option_exit(); } - my $count = 0; - my $inUseCount = 0; - my $percentUsed = 100; - + $self->{global} = { total => 0, used => 0 }; my $query = "Select InUseCount,Count from Citrix_GT_License_Pool"; my $resultset = $wmi->ExecQuery($query); foreach my $obj (in $resultset) { - $inUseCount = $obj->{InUseCount}; - $count = $obj->{Count}; - $percentUsed = ($inUseCount / $count) * 100; - - my $exit = $self->{perfdata}->threshold_check(value => $percentUsed, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => $percentUsed . "% licenses are used (" . $inUseCount . "/" . $count . ")"); - $self->{output}->perfdata_add(label => 'licenses_used', - value => $inUseCount, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $count), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $count), - min => 0, max => $count); + $self->{global}->{used} += $obj->{InUseCount}; + $self->{global}->{total} += $obj->{Count}; } - if ($count == 0) { - $self->{output}->output_add(severity => 'Unknown', - short_msg => "Can't get licenses count"); + if ($self->{global}->{total} == 0) { + $self->{output}->add_option_msg(short_msg => 'Cant get licenses count'); + $self->{output}->option_exit(); } - - $self->{output}->display(); - $self->{output}->exit(); + + $self->{global}->{prct_used} = $self->{global}->{used} * 100 / $self->{global}->{total}; + $self->{global}->{prct_free} = 100 - $self->{global}->{prct_used}; + $self->{global}->{free} = $self->{global}->{total} - $self->{global}->{used}; } 1; @@ -106,13 +122,10 @@ Check Citrix licenses. =over 8 -=item B<--warning> +=item B<--warning-*> B<--critical-*> -Threshold warning of licenses used in percent. - -=item B<--critical> - -Threshold critical of licenses used in percent. +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). =back diff --git a/centreon-plugins/apps/citrix/local/mode/session.pm b/centreon-plugins/apps/citrix/local/mode/session.pm index 24ac787d4..967a400f2 100644 --- a/centreon-plugins/apps/citrix/local/mode/session.pm +++ b/centreon-plugins/apps/citrix/local/mode/session.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/citrix/local/mode/zone.pm b/centreon-plugins/apps/citrix/local/mode/zone.pm index 382f729b4..468440bfa 100644 --- a/centreon-plugins/apps/citrix/local/mode/zone.pm +++ b/centreon-plugins/apps/citrix/local/mode/zone.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/cluster/mscs/local/mode/listnodes.pm b/centreon-plugins/apps/cluster/mscs/local/mode/listnodes.pm index 28b6fc21b..1059442a6 100644 --- a/centreon-plugins/apps/cluster/mscs/local/mode/listnodes.pm +++ b/centreon-plugins/apps/cluster/mscs/local/mode/listnodes.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/cluster/mscs/local/mode/listresources.pm b/centreon-plugins/apps/cluster/mscs/local/mode/listresources.pm index 1503cbdbf..f20b3d186 100644 --- a/centreon-plugins/apps/cluster/mscs/local/mode/listresources.pm +++ b/centreon-plugins/apps/cluster/mscs/local/mode/listresources.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/cluster/mscs/local/mode/networkstatus.pm b/centreon-plugins/apps/cluster/mscs/local/mode/networkstatus.pm index 7236f2c80..0158d38d9 100644 --- a/centreon-plugins/apps/cluster/mscs/local/mode/networkstatus.pm +++ b/centreon-plugins/apps/cluster/mscs/local/mode/networkstatus.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/cluster/mscs/local/mode/nodestatus.pm b/centreon-plugins/apps/cluster/mscs/local/mode/nodestatus.pm index c3daff01e..6aa538d5a 100644 --- a/centreon-plugins/apps/cluster/mscs/local/mode/nodestatus.pm +++ b/centreon-plugins/apps/cluster/mscs/local/mode/nodestatus.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/cluster/mscs/local/mode/resourcegroupstatus.pm b/centreon-plugins/apps/cluster/mscs/local/mode/resourcegroupstatus.pm index dbcdcedd1..52c8fb253 100644 --- a/centreon-plugins/apps/cluster/mscs/local/mode/resourcegroupstatus.pm +++ b/centreon-plugins/apps/cluster/mscs/local/mode/resourcegroupstatus.pm @@ -124,7 +124,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/cluster/mscs/local/mode/resourcestatus.pm b/centreon-plugins/apps/cluster/mscs/local/mode/resourcestatus.pm index ea3563aa5..5e5f44801 100644 --- a/centreon-plugins/apps/cluster/mscs/local/mode/resourcestatus.pm +++ b/centreon-plugins/apps/cluster/mscs/local/mode/resourcestatus.pm @@ -73,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/elasticsearch/restapi/mode/cluster.pm b/centreon-plugins/apps/elasticsearch/restapi/mode/cluster.pm deleted file mode 100644 index ba0ac0c11..000000000 --- a/centreon-plugins/apps/elasticsearch/restapi/mode/cluster.pm +++ /dev/null @@ -1,167 +0,0 @@ -# -# Copyright 2019 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 apps::elasticsearch::restapi::mode::cluster; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); - -sub custom_status_output { - my ($self, %options) = @_; - my $msg = "Cluster '" . $self->{result_values}->{display} . "' Status : " . $self->{result_values}->{status}; - - return $msg; -} - -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; - $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 }, - ]; - - $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'status' }, { 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 => \&catalog_status_threshold, - } - }, - { label => 'active-primary-shards', set => { - key_values => [ { name => 'active_primary_shards' } ], - output_template => 'Active Primary Shards : %s', - perfdatas => [ - { label => 'active_primary_shards', value => 'active_primary_shards_absolute', template => '%s', - min => 0 }, - ], - } - }, - { label => 'active-shards', set => { - key_values => [ { name => 'active_shards' } ], - output_template => 'Active Shards : %s', - perfdatas => [ - { label => 'active_shards', value => 'active_shards_absolute', template => '%s', - min => 0 }, - ], - } - }, - { label => 'unassigned-shards', set => { - key_values => [ { name => 'unassigned_shards' } ], - output_template => 'Unassigned Shards : %s', - perfdatas => [ - { label => 'unassigned_shards', value => 'unassigned_shards_absolute', template => '%s', - min => 0 }, - ], - } - }, - ]; -} - -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 => - { - "elastic-path:s" => { name => 'elastic_path', default => '/_cluster/health' }, - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /yellow/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /red/i' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - -sub manage_selection { - my ($self, %options) = @_; - - my $result = $options{custom}->get(path => $self->{option_results}->{elastic_path}); - $self->{global} = { - display => $result->{cluster_name}, - status => $result->{status}, - active_primary_shards => $result->{active_primary_shards}, - active_shards => $result->{active_shards}, - unassigned_shards => $result->{unassigned_shards}, - }; -} - -1; - -__END__ - -=head1 MODE - -Check Elasticsearch cluster. - -=over 8 - -=item B<--elastic-path> - -Set path to get Elasticsearch information (Default: '/_cluster/health') - -=item B<--filter-counters> - -Only display some counters (regexp can be used). -Example: --filter-counters='^status$' - -=item B<--warning-*> - -Threshold warning. -Can be: 'active-primary-shards', 'active-shards', 'unassigned-shards'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'active-primary-shards', 'active-shards', 'unassigned-shards'. - -=item B<--warning-status> - -Set warning threshold for status (Default: '%{status} =~ /yellow/i') -Can used special variables like: %{status}. - -=item B<--critical-status> - -Set critical threshold for status (Default: '%{status} =~ /red/i'). -Can used special variables like: %{status}. - -=back - -=cut diff --git a/centreon-plugins/apps/elasticsearch/restapi/mode/nodes.pm b/centreon-plugins/apps/elasticsearch/restapi/mode/nodes.pm deleted file mode 100644 index 4e3ff668f..000000000 --- a/centreon-plugins/apps/elasticsearch/restapi/mode/nodes.pm +++ /dev/null @@ -1,144 +0,0 @@ -# -# Copyright 2019 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 apps::elasticsearch::restapi::mode::nodes; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'nodes', type => 0, cb_prefix_output => 'prefix_output' }, - ]; - - $self->{maps_counters}->{nodes} = [ - { label => 'total', set => { - key_values => [ { name => 'total' } ], - output_template => 'Total : %s', - perfdatas => [ - { label => 'total', value => 'total_absolute', template => '%s', - min => 0 }, - ], - } - }, - { label => 'masteronly', set => { - key_values => [ { name => 'master_only' } ], - output_template => 'Master Only : %s', - perfdatas => [ - { label => 'master_only', value => 'master_only_absolute', template => '%s', - min => 0 }, - ], - } - }, - { label => 'dataonly', set => { - key_values => [ { name => 'data_only' } ], - output_template => 'Data Only : %s', - perfdatas => [ - { label => 'data_only', value => 'data_only_absolute', template => '%s', - min => 0 }, - ], - } - }, - { label => 'masterdata', set => { - key_values => [ { name => 'master_data' } ], - output_template => 'Master Data : %s', - perfdatas => [ - { label => 'master_data', value => 'master_data_absolute', template => '%s', - min => 0 }, - ], - } - }, - { label => 'client', set => { - key_values => [ { name => 'client' } ], - output_template => 'Client : %s', - perfdatas => [ - { label => 'client', value => 'client_absolute', template => '%s', - min => 0 }, - ], - } - }, - ]; -} - -sub prefix_output { - my ($self, %options) = @_; - - return "Nodes "; -} - -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 => - { - "elastic-path:s" => { name => 'elastic_path', default => '/_cluster/stats' }, - }); - - return $self; -} - -sub manage_selection { - my ($self, %options) = @_; - - my $result = $options{custom}->get(path => $self->{option_results}->{elastic_path}); - $self->{nodes} = { - %{$result->{nodes}->{count}} - }; -} - -1; - -__END__ - -=head1 MODE - -Check Elasticsearch nodes. - -=over 8 - -=item B<--elastic-path> - -Set path to get Elasticsearch information (Default: '/_cluster/stats') - -=item B<--filter-counters> - -Only display some counters (regexp can be used). -Example: --filter-counters='^total$' - -=item B<--warning-*> - -Threshold warning. -Can be: 'total', 'masteronly', 'dataonly', 'masterdata', 'client'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'total', 'masteronly', 'dataonly', 'masterdata', 'client'. - -=back - -=cut diff --git a/centreon-plugins/apps/exchange/2010/local/mode/activesyncmailbox.pm b/centreon-plugins/apps/exchange/2010/local/mode/activesyncmailbox.pm index 08c8b6e11..917b91f7a 100644 --- a/centreon-plugins/apps/exchange/2010/local/mode/activesyncmailbox.pm +++ b/centreon-plugins/apps/exchange/2010/local/mode/activesyncmailbox.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote-host:s" => { name => 'remote_host', }, diff --git a/centreon-plugins/apps/exchange/2010/local/mode/databases.pm b/centreon-plugins/apps/exchange/2010/local/mode/databases.pm index 7988c2531..5c96611ff 100644 --- a/centreon-plugins/apps/exchange/2010/local/mode/databases.pm +++ b/centreon-plugins/apps/exchange/2010/local/mode/databases.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote-host:s" => { name => 'remote_host', }, diff --git a/centreon-plugins/apps/exchange/2010/local/mode/imapmailbox.pm b/centreon-plugins/apps/exchange/2010/local/mode/imapmailbox.pm index 1f4e85bfe..513fc4dfc 100644 --- a/centreon-plugins/apps/exchange/2010/local/mode/imapmailbox.pm +++ b/centreon-plugins/apps/exchange/2010/local/mode/imapmailbox.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote-host:s" => { name => 'remote_host', }, "remote-user:s" => { name => 'remote_user', }, diff --git a/centreon-plugins/apps/exchange/2010/local/mode/listdatabases.pm b/centreon-plugins/apps/exchange/2010/local/mode/listdatabases.pm index 42d902969..677da5801 100644 --- a/centreon-plugins/apps/exchange/2010/local/mode/listdatabases.pm +++ b/centreon-plugins/apps/exchange/2010/local/mode/listdatabases.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote-host:s" => { name => 'remote_host', }, diff --git a/centreon-plugins/apps/exchange/2010/local/mode/mapimailbox.pm b/centreon-plugins/apps/exchange/2010/local/mode/mapimailbox.pm index c4e7b6263..72ead2ab1 100644 --- a/centreon-plugins/apps/exchange/2010/local/mode/mapimailbox.pm +++ b/centreon-plugins/apps/exchange/2010/local/mode/mapimailbox.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote-host:s" => { name => 'remote_host', }, diff --git a/centreon-plugins/apps/exchange/2010/local/mode/outlookwebservices.pm b/centreon-plugins/apps/exchange/2010/local/mode/outlookwebservices.pm index f82d3b663..323e6ce5c 100644 --- a/centreon-plugins/apps/exchange/2010/local/mode/outlookwebservices.pm +++ b/centreon-plugins/apps/exchange/2010/local/mode/outlookwebservices.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote-host:s" => { name => 'remote_host', }, "remote-user:s" => { name => 'remote_user', }, diff --git a/centreon-plugins/apps/exchange/2010/local/mode/owamailbox.pm b/centreon-plugins/apps/exchange/2010/local/mode/owamailbox.pm index 9cacfd45b..dd9f272e7 100644 --- a/centreon-plugins/apps/exchange/2010/local/mode/owamailbox.pm +++ b/centreon-plugins/apps/exchange/2010/local/mode/owamailbox.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote-host:s" => { name => 'remote_host', }, diff --git a/centreon-plugins/apps/exchange/2010/local/mode/queues.pm b/centreon-plugins/apps/exchange/2010/local/mode/queues.pm index 5a8ddbceb..1eaecca47 100644 --- a/centreon-plugins/apps/exchange/2010/local/mode/queues.pm +++ b/centreon-plugins/apps/exchange/2010/local/mode/queues.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote-host:s" => { name => 'remote_host', }, diff --git a/centreon-plugins/apps/exchange/2010/local/mode/replicationhealth.pm b/centreon-plugins/apps/exchange/2010/local/mode/replicationhealth.pm index 0c8b41a98..d1186bd2b 100644 --- a/centreon-plugins/apps/exchange/2010/local/mode/replicationhealth.pm +++ b/centreon-plugins/apps/exchange/2010/local/mode/replicationhealth.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote-host:s" => { name => 'remote_host', }, diff --git a/centreon-plugins/apps/exchange/2010/local/mode/services.pm b/centreon-plugins/apps/exchange/2010/local/mode/services.pm index 0a17b8d75..f412e7dae 100644 --- a/centreon-plugins/apps/exchange/2010/local/mode/services.pm +++ b/centreon-plugins/apps/exchange/2010/local/mode/services.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote-host:s" => { name => 'remote_host', }, diff --git a/centreon-plugins/apps/github/mode/commits.pm b/centreon-plugins/apps/github/mode/commits.pm index 86b0a4ad8..152262747 100644 --- a/centreon-plugins/apps/github/mode/commits.pm +++ b/centreon-plugins/apps/github/mode/commits.pm @@ -34,7 +34,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname', default => 'api.github.com' }, "port:s" => { name => 'port', default => '443'}, diff --git a/centreon-plugins/apps/github/mode/issues.pm b/centreon-plugins/apps/github/mode/issues.pm index 92b36e784..19fe8ebdc 100644 --- a/centreon-plugins/apps/github/mode/issues.pm +++ b/centreon-plugins/apps/github/mode/issues.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname', default => 'api.github.com' }, "port:s" => { name => 'port', default => '443'}, diff --git a/centreon-plugins/apps/github/mode/pullrequests.pm b/centreon-plugins/apps/github/mode/pullrequests.pm index ca4b3cd15..cdb3b5f27 100644 --- a/centreon-plugins/apps/github/mode/pullrequests.pm +++ b/centreon-plugins/apps/github/mode/pullrequests.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname', default => 'api.github.com' }, "port:s" => { name => 'port', default => '443' }, diff --git a/centreon-plugins/apps/github/mode/stats.pm b/centreon-plugins/apps/github/mode/stats.pm index 203e249b0..4119036ef 100644 --- a/centreon-plugins/apps/github/mode/stats.pm +++ b/centreon-plugins/apps/github/mode/stats.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname', default => 'api.github.com' }, "port:s" => { name => 'port', default => '443'}, diff --git a/centreon-plugins/apps/github/mode/status.pm b/centreon-plugins/apps/github/mode/status.pm index 96ab886f5..9463babb7 100644 --- a/centreon-plugins/apps/github/mode/status.pm +++ b/centreon-plugins/apps/github/mode/status.pm @@ -40,7 +40,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname', default => 'status.github.com' }, "port:s" => { name => 'port', default => '443'}, diff --git a/centreon-plugins/apps/haproxy/snmp/mode/backendusage.pm b/centreon-plugins/apps/haproxy/snmp/mode/backendusage.pm index e753d5c8b..889c84c7e 100644 --- a/centreon-plugins/apps/haproxy/snmp/mode/backendusage.pm +++ b/centreon-plugins/apps/haproxy/snmp/mode/backendusage.pm @@ -113,7 +113,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'filter-name:s' => { name => 'filter_name' }, 'warning-status:s' => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/apps/haproxy/snmp/mode/frontendusage.pm b/centreon-plugins/apps/haproxy/snmp/mode/frontendusage.pm index bcb16c251..88790cf68 100644 --- a/centreon-plugins/apps/haproxy/snmp/mode/frontendusage.pm +++ b/centreon-plugins/apps/haproxy/snmp/mode/frontendusage.pm @@ -104,7 +104,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/apps/hddtemp/local/mode/temperature.pm b/centreon-plugins/apps/hddtemp/local/mode/temperature.pm index 411b19858..7da90839d 100644 --- a/centreon-plugins/apps/hddtemp/local/mode/temperature.pm +++ b/centreon-plugins/apps/hddtemp/local/mode/temperature.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/hddtemp/remote/mode/listdrives.pm b/centreon-plugins/apps/hddtemp/remote/mode/listdrives.pm index 2ee6308c3..124c21f5c 100644 --- a/centreon-plugins/apps/hddtemp/remote/mode/listdrives.pm +++ b/centreon-plugins/apps/hddtemp/remote/mode/listdrives.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/hddtemp/remote/mode/temperature.pm b/centreon-plugins/apps/hddtemp/remote/mode/temperature.pm index e55df715a..28dad81d8 100644 --- a/centreon-plugins/apps/hddtemp/remote/mode/temperature.pm +++ b/centreon-plugins/apps/hddtemp/remote/mode/temperature.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '7634' }, diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/listnodevms.pm b/centreon-plugins/apps/hyperv/2012/local/mode/listnodevms.pm index f2f7e111e..b20a29fc2 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/listnodevms.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/listnodevms.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 50 }, diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/nodeintegrationservice.pm b/centreon-plugins/apps/hyperv/2012/local/mode/nodeintegrationservice.pm index e376346bc..35ec358b5 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/nodeintegrationservice.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/nodeintegrationservice.pm @@ -123,7 +123,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 50 }, diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/nodereplication.pm b/centreon-plugins/apps/hyperv/2012/local/mode/nodereplication.pm index d1a2b73a8..1fd3bbacc 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/nodereplication.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/nodereplication.pm @@ -73,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 50 }, diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/nodesnapshot.pm b/centreon-plugins/apps/hyperv/2012/local/mode/nodesnapshot.pm index 226565fa9..f86e6a295 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/nodesnapshot.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/nodesnapshot.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 50 }, diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/nodevmstatus.pm b/centreon-plugins/apps/hyperv/2012/local/mode/nodevmstatus.pm index a4652d4cf..fa96f3b39 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/nodevmstatus.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/nodevmstatus.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 50 }, diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm index 958b884b1..2f4aac170 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm @@ -142,7 +142,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "scvmm-hostname:s" => { name => 'scvmm_hostname' }, diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmsnapshot.pm b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmsnapshot.pm index a7d61ac09..82fd58439 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmsnapshot.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmsnapshot.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "scvmm-hostname:s" => { name => 'scvmm_hostname' }, diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmvmstatus.pm b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmvmstatus.pm index 7cda0ecf3..9ab2b7a0d 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmvmstatus.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmvmstatus.pm @@ -73,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "scvmm-hostname:s" => { name => 'scvmm_hostname' }, diff --git a/centreon-plugins/apps/iis/local/mode/applicationpoolstate.pm b/centreon-plugins/apps/iis/local/mode/applicationpoolstate.pm index c4caf35bf..1ff4dc052 100644 --- a/centreon-plugins/apps/iis/local/mode/applicationpoolstate.pm +++ b/centreon-plugins/apps/iis/local/mode/applicationpoolstate.pm @@ -39,7 +39,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning" => { name => 'warning', }, diff --git a/centreon-plugins/apps/iis/local/mode/listapplicationpools.pm b/centreon-plugins/apps/iis/local/mode/listapplicationpools.pm index a30c87d31..ec923a7d8 100644 --- a/centreon-plugins/apps/iis/local/mode/listapplicationpools.pm +++ b/centreon-plugins/apps/iis/local/mode/listapplicationpools.pm @@ -39,7 +39,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s" => { name => 'name' }, diff --git a/centreon-plugins/apps/iis/local/mode/listsites.pm b/centreon-plugins/apps/iis/local/mode/listsites.pm index 1f18df5bb..4399c5ad0 100644 --- a/centreon-plugins/apps/iis/local/mode/listsites.pm +++ b/centreon-plugins/apps/iis/local/mode/listsites.pm @@ -39,7 +39,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s" => { name => 'name' }, diff --git a/centreon-plugins/apps/iis/local/mode/webservicestatistics.pm b/centreon-plugins/apps/iis/local/mode/webservicestatistics.pm index fde285b10..28a86402e 100644 --- a/centreon-plugins/apps/iis/local/mode/webservicestatistics.pm +++ b/centreon-plugins/apps/iis/local/mode/webservicestatistics.pm @@ -46,7 +46,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; foreach my $name (keys %$counters) { $options{options}->add_options(arguments => { diff --git a/centreon-plugins/apps/iis/wsman/mode/applicationpoolstate.pm b/centreon-plugins/apps/iis/wsman/mode/applicationpoolstate.pm index 76965e73f..60e3f5ca6 100644 --- a/centreon-plugins/apps/iis/wsman/mode/applicationpoolstate.pm +++ b/centreon-plugins/apps/iis/wsman/mode/applicationpoolstate.pm @@ -37,7 +37,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning" => { name => 'warning', }, diff --git a/centreon-plugins/apps/iis/wsman/mode/listapplicationpools.pm b/centreon-plugins/apps/iis/wsman/mode/listapplicationpools.pm index 9adddf152..406190f62 100644 --- a/centreon-plugins/apps/iis/wsman/mode/listapplicationpools.pm +++ b/centreon-plugins/apps/iis/wsman/mode/listapplicationpools.pm @@ -37,7 +37,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s" => { name => 'name' }, diff --git a/centreon-plugins/apps/inin/ig/snmp/mode/spanusage.pm b/centreon-plugins/apps/inin/ig/snmp/mode/spanusage.pm index b97f75758..14345b4f7 100644 --- a/centreon-plugins/apps/inin/ig/snmp/mode/spanusage.pm +++ b/centreon-plugins/apps/inin/ig/snmp/mode/spanusage.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/inin/ig/snmp/mode/stats.pm b/centreon-plugins/apps/inin/ig/snmp/mode/stats.pm index 1bd0fb77f..11ccc3cba 100644 --- a/centreon-plugins/apps/inin/ig/snmp/mode/stats.pm +++ b/centreon-plugins/apps/inin/ig/snmp/mode/stats.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/inin/mediaserver/snmp/mode/audioengineusage.pm b/centreon-plugins/apps/inin/mediaserver/snmp/mode/audioengineusage.pm index e98a4ebd6..787f1a280 100644 --- a/centreon-plugins/apps/inin/mediaserver/snmp/mode/audioengineusage.pm +++ b/centreon-plugins/apps/inin/mediaserver/snmp/mode/audioengineusage.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-location:s" => { name => 'filter_location' }, diff --git a/centreon-plugins/apps/inin/mediaserver/snmp/mode/cmdsrvusage.pm b/centreon-plugins/apps/inin/mediaserver/snmp/mode/cmdsrvusage.pm index c5ccb271b..84671e3eb 100644 --- a/centreon-plugins/apps/inin/mediaserver/snmp/mode/cmdsrvusage.pm +++ b/centreon-plugins/apps/inin/mediaserver/snmp/mode/cmdsrvusage.pm @@ -149,7 +149,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-client:s" => { name => 'filter_client' }, diff --git a/centreon-plugins/apps/inin/mediaserver/snmp/mode/component.pm b/centreon-plugins/apps/inin/mediaserver/snmp/mode/component.pm index 7dd341294..a23a80734 100644 --- a/centreon-plugins/apps/inin/mediaserver/snmp/mode/component.pm +++ b/centreon-plugins/apps/inin/mediaserver/snmp/mode/component.pm @@ -53,7 +53,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/inin/mediaserver/snmp/mode/diskusage.pm b/centreon-plugins/apps/inin/mediaserver/snmp/mode/diskusage.pm index 645dd44e6..921d9228b 100644 --- a/centreon-plugins/apps/inin/mediaserver/snmp/mode/diskusage.pm +++ b/centreon-plugins/apps/inin/mediaserver/snmp/mode/diskusage.pm @@ -124,7 +124,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, diff --git a/centreon-plugins/apps/inin/mediaserver/snmp/mode/memoryusage.pm b/centreon-plugins/apps/inin/mediaserver/snmp/mode/memoryusage.pm index 45b6d46d5..c1984bc96 100644 --- a/centreon-plugins/apps/inin/mediaserver/snmp/mode/memoryusage.pm +++ b/centreon-plugins/apps/inin/mediaserver/snmp/mode/memoryusage.pm @@ -51,7 +51,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/java/awa/jmx/mode/agent.pm b/centreon-plugins/apps/java/awa/jmx/mode/agent.pm index 4d2307e95..4a6be2fe6 100644 --- a/centreon-plugins/apps/java/awa/jmx/mode/agent.pm +++ b/centreon-plugins/apps/java/awa/jmx/mode/agent.pm @@ -70,7 +70,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/java/awa/jmx/mode/listagents.pm b/centreon-plugins/apps/java/awa/jmx/mode/listagents.pm index 8c50a6b9d..b00c26dd7 100644 --- a/centreon-plugins/apps/java/awa/jmx/mode/listagents.pm +++ b/centreon-plugins/apps/java/awa/jmx/mode/listagents.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/java/awa/jmx/mode/listqueues.pm b/centreon-plugins/apps/java/awa/jmx/mode/listqueues.pm index 9a145d775..cb1ca97b7 100644 --- a/centreon-plugins/apps/java/awa/jmx/mode/listqueues.pm +++ b/centreon-plugins/apps/java/awa/jmx/mode/listqueues.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/java/awa/jmx/mode/listservers.pm b/centreon-plugins/apps/java/awa/jmx/mode/listservers.pm index 453082646..162b1c58f 100644 --- a/centreon-plugins/apps/java/awa/jmx/mode/listservers.pm +++ b/centreon-plugins/apps/java/awa/jmx/mode/listservers.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/java/awa/jmx/mode/queue.pm b/centreon-plugins/apps/java/awa/jmx/mode/queue.pm index 79ed174f6..63e70f542 100644 --- a/centreon-plugins/apps/java/awa/jmx/mode/queue.pm +++ b/centreon-plugins/apps/java/awa/jmx/mode/queue.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/java/awa/jmx/mode/server.pm b/centreon-plugins/apps/java/awa/jmx/mode/server.pm index 9ba0fdefa..0a99aa400 100644 --- a/centreon-plugins/apps/java/awa/jmx/mode/server.pm +++ b/centreon-plugins/apps/java/awa/jmx/mode/server.pm @@ -67,7 +67,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/java/hibernate/jmx/mode/stats.pm b/centreon-plugins/apps/java/hibernate/jmx/mode/stats.pm index 7545fe8bc..0d77bb437 100644 --- a/centreon-plugins/apps/java/hibernate/jmx/mode/stats.pm +++ b/centreon-plugins/apps/java/hibernate/jmx/mode/stats.pm @@ -88,7 +88,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/java/jboss/jmx/mode/datasourceusage.pm b/centreon-plugins/apps/java/jboss/jmx/mode/datasourceusage.pm index d02567162..fc102bdc8 100644 --- a/centreon-plugins/apps/java/jboss/jmx/mode/datasourceusage.pm +++ b/centreon-plugins/apps/java/jboss/jmx/mode/datasourceusage.pm @@ -84,7 +84,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/java/jboss/jmx/mode/listdatasources.pm b/centreon-plugins/apps/java/jboss/jmx/mode/listdatasources.pm index e4ce66a88..1264dcb84 100644 --- a/centreon-plugins/apps/java/jboss/jmx/mode/listdatasources.pm +++ b/centreon-plugins/apps/java/jboss/jmx/mode/listdatasources.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/java/kafka/jmx/mode/globalstats.pm b/centreon-plugins/apps/java/kafka/jmx/mode/globalstats.pm index db8fa3a67..36f507911 100644 --- a/centreon-plugins/apps/java/kafka/jmx/mode/globalstats.pm +++ b/centreon-plugins/apps/java/kafka/jmx/mode/globalstats.pm @@ -120,7 +120,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/java/peoplesoft/jmx/mode/queuelength.pm b/centreon-plugins/apps/java/peoplesoft/jmx/mode/queuelength.pm index 551758343..6a311d04c 100644 --- a/centreon-plugins/apps/java/peoplesoft/jmx/mode/queuelength.pm +++ b/centreon-plugins/apps/java/peoplesoft/jmx/mode/queuelength.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/apps/java/peoplesoft/jmx/mode/sessions.pm b/centreon-plugins/apps/java/peoplesoft/jmx/mode/sessions.pm index e9f7b73d4..b138be54b 100644 --- a/centreon-plugins/apps/java/peoplesoft/jmx/mode/sessions.pm +++ b/centreon-plugins/apps/java/peoplesoft/jmx/mode/sessions.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/apps/java/solr/jmx/mode/cacheusage.pm b/centreon-plugins/apps/java/solr/jmx/mode/cacheusage.pm index 14226c5fc..18f4bf6ab 100644 --- a/centreon-plugins/apps/java/solr/jmx/mode/cacheusage.pm +++ b/centreon-plugins/apps/java/solr/jmx/mode/cacheusage.pm @@ -78,7 +78,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/java/solr/jmx/mode/requesthandlerusage.pm b/centreon-plugins/apps/java/solr/jmx/mode/requesthandlerusage.pm index b6ecdc522..6c616f694 100644 --- a/centreon-plugins/apps/java/solr/jmx/mode/requesthandlerusage.pm +++ b/centreon-plugins/apps/java/solr/jmx/mode/requesthandlerusage.pm @@ -78,7 +78,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name', default => '(/select|/update)$' }, diff --git a/centreon-plugins/apps/java/weblogic/jmx/mode/workmanager.pm b/centreon-plugins/apps/java/weblogic/jmx/mode/workmanager.pm index dbba485b1..810fd3acb 100644 --- a/centreon-plugins/apps/java/weblogic/jmx/mode/workmanager.pm +++ b/centreon-plugins/apps/java/weblogic/jmx/mode/workmanager.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-application:s" => { name => 'filter_application' }, "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/java/zookeeper/jmx/mode/stats.pm b/centreon-plugins/apps/java/zookeeper/jmx/mode/stats.pm index d1c7ccb79..6e682816a 100644 --- a/centreon-plugins/apps/java/zookeeper/jmx/mode/stats.pm +++ b/centreon-plugins/apps/java/zookeeper/jmx/mode/stats.pm @@ -96,7 +96,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/jenkins/mode/jobstate.pm b/centreon-plugins/apps/jenkins/mode/jobstate.pm index 3ba01e1b9..a8c2a3e95 100644 --- a/centreon-plugins/apps/jenkins/mode/jobstate.pm +++ b/centreon-plugins/apps/jenkins/mode/jobstate.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port' }, diff --git a/centreon-plugins/apps/jive/sql/mode/etljobstatus.pm b/centreon-plugins/apps/jive/sql/mode/etljobstatus.pm index 2cd759c39..4c524db20 100644 --- a/centreon-plugins/apps/jive/sql/mode/etljobstatus.pm +++ b/centreon-plugins/apps/jive/sql/mode/etljobstatus.pm @@ -37,7 +37,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "retention:s" => { name => 'retention', default => 1 }, diff --git a/centreon-plugins/apps/jmeter/mode/scenario.pm b/centreon-plugins/apps/jmeter/mode/scenario.pm index 74e69f8e7..05295d0a7 100644 --- a/centreon-plugins/apps/jmeter/mode/scenario.pm +++ b/centreon-plugins/apps/jmeter/mode/scenario.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote" => { name => 'remote' }, diff --git a/centreon-plugins/apps/kayako/api/mode/listdepartment.pm b/centreon-plugins/apps/kayako/api/mode/listdepartment.pm index a3d98c6c2..3e7046b4b 100644 --- a/centreon-plugins/apps/kayako/api/mode/listdepartment.pm +++ b/centreon-plugins/apps/kayako/api/mode/listdepartment.pm @@ -35,7 +35,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port' }, diff --git a/centreon-plugins/apps/kayako/api/mode/listpriority.pm b/centreon-plugins/apps/kayako/api/mode/listpriority.pm index aa4a6e146..471e24d70 100644 --- a/centreon-plugins/apps/kayako/api/mode/listpriority.pm +++ b/centreon-plugins/apps/kayako/api/mode/listpriority.pm @@ -35,7 +35,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port' }, diff --git a/centreon-plugins/apps/kayako/api/mode/liststaff.pm b/centreon-plugins/apps/kayako/api/mode/liststaff.pm index ba73c2302..3278370eb 100644 --- a/centreon-plugins/apps/kayako/api/mode/liststaff.pm +++ b/centreon-plugins/apps/kayako/api/mode/liststaff.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port' }, diff --git a/centreon-plugins/apps/kayako/api/mode/liststatus.pm b/centreon-plugins/apps/kayako/api/mode/liststatus.pm index 500afa70a..041d3f34a 100644 --- a/centreon-plugins/apps/kayako/api/mode/liststatus.pm +++ b/centreon-plugins/apps/kayako/api/mode/liststatus.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port' }, diff --git a/centreon-plugins/apps/kayako/api/mode/ticketcount.pm b/centreon-plugins/apps/kayako/api/mode/ticketcount.pm index 832e8075f..4dd2039df 100644 --- a/centreon-plugins/apps/kayako/api/mode/ticketcount.pm +++ b/centreon-plugins/apps/kayako/api/mode/ticketcount.pm @@ -44,7 +44,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port' }, diff --git a/centreon-plugins/apps/kayako/sql/mode/listdepartment.pm b/centreon-plugins/apps/kayako/sql/mode/listdepartment.pm index b8795b50d..50c85a197 100644 --- a/centreon-plugins/apps/kayako/sql/mode/listdepartment.pm +++ b/centreon-plugins/apps/kayako/sql/mode/listdepartment.pm @@ -29,7 +29,6 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; return $self; } diff --git a/centreon-plugins/apps/kayako/sql/mode/listpriority.pm b/centreon-plugins/apps/kayako/sql/mode/listpriority.pm index 6a75c91ca..141f5a1c8 100644 --- a/centreon-plugins/apps/kayako/sql/mode/listpriority.pm +++ b/centreon-plugins/apps/kayako/sql/mode/listpriority.pm @@ -29,7 +29,6 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; return $self; } diff --git a/centreon-plugins/apps/kayako/sql/mode/liststaff.pm b/centreon-plugins/apps/kayako/sql/mode/liststaff.pm index a5659a514..2602fa05f 100644 --- a/centreon-plugins/apps/kayako/sql/mode/liststaff.pm +++ b/centreon-plugins/apps/kayako/sql/mode/liststaff.pm @@ -29,7 +29,6 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; return $self; } diff --git a/centreon-plugins/apps/kayako/sql/mode/liststatus.pm b/centreon-plugins/apps/kayako/sql/mode/liststatus.pm index 098823f2b..0c67adcc6 100644 --- a/centreon-plugins/apps/kayako/sql/mode/liststatus.pm +++ b/centreon-plugins/apps/kayako/sql/mode/liststatus.pm @@ -29,7 +29,6 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; return $self; } diff --git a/centreon-plugins/apps/kayako/sql/mode/ticketcount.pm b/centreon-plugins/apps/kayako/sql/mode/ticketcount.pm index 732b29f6b..920b05253 100644 --- a/centreon-plugins/apps/kayako/sql/mode/ticketcount.pm +++ b/centreon-plugins/apps/kayako/sql/mode/ticketcount.pm @@ -40,7 +40,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, diff --git a/centreon-plugins/apps/keepalived/snmp/mode/vrrpstatus.pm b/centreon-plugins/apps/keepalived/snmp/mode/vrrpstatus.pm index f275ba7e8..7b515a7a8 100644 --- a/centreon-plugins/apps/keepalived/snmp/mode/vrrpstatus.pm +++ b/centreon-plugins/apps/keepalived/snmp/mode/vrrpstatus.pm @@ -80,7 +80,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/activeusers.pm b/centreon-plugins/apps/kingdee/eas/mode/activeusers.pm index 62fb4d26c..6762110f2 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/activeusers.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/activeusers.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkactiveusers.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/classloading.pm b/centreon-plugins/apps/kingdee/eas/mode/classloading.pm index 9a9089bfa..fbef2484f 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/classloading.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/classloading.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkclassloading.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/datasource.pm b/centreon-plugins/apps/kingdee/eas/mode/datasource.pm index 47ce30e8d..0de95d316 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/datasource.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/datasource.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkdatasources.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/easlicense.pm b/centreon-plugins/apps/kingdee/eas/mode/easlicense.pm index 0638bb947..8b99f2a04 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/easlicense.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/easlicense.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkeaslicense.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/httphandler.pm b/centreon-plugins/apps/kingdee/eas/mode/httphandler.pm index 67622d5be..d04e3959f 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/httphandler.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/httphandler.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new( package => __PACKAGE__, %options ); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options( arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkhttphandler.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/ibmjvmgc.pm b/centreon-plugins/apps/kingdee/eas/mode/ibmjvmgc.pm index b95ef4acf..937e3db2c 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/ibmjvmgc.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/ibmjvmgc.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkgc_j9gen.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/javaruntime.pm b/centreon-plugins/apps/kingdee/eas/mode/javaruntime.pm index a5053dd25..e02439e65 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/javaruntime.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/javaruntime.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkjavaruntime.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/memory.pm b/centreon-plugins/apps/kingdee/eas/mode/memory.pm index fcaeccb74..1638f8495 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/memory.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/memory.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new( package => __PACKAGE__, %options ); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options( arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkmemory.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/muxhandler.pm b/centreon-plugins/apps/kingdee/eas/mode/muxhandler.pm index e81aa84e1..7159135d6 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/muxhandler.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/muxhandler.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new( package => __PACKAGE__, %options ); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options( arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkmuxhandler.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/oraclejvmgc.pm b/centreon-plugins/apps/kingdee/eas/mode/oraclejvmgc.pm index af77580bc..d580b6b37 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/oraclejvmgc.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/oraclejvmgc.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkgc_ps.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/oracleksqltemptable.pm b/centreon-plugins/apps/kingdee/eas/mode/oracleksqltemptable.pm index 140e74aa2..e9bb70c45 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/oracleksqltemptable.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/oracleksqltemptable.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkoraclevt.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/oraclerecyclebin.pm b/centreon-plugins/apps/kingdee/eas/mode/oraclerecyclebin.pm index a6e50d09d..8d807851a 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/oraclerecyclebin.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/oraclerecyclebin.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkoraclerecyclebin.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/oracleredolog.pm b/centreon-plugins/apps/kingdee/eas/mode/oracleredolog.pm index 1b5aefc7f..b95a56451 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/oracleredolog.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/oracleredolog.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkoracleredolog.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/oraclesession.pm b/centreon-plugins/apps/kingdee/eas/mode/oraclesession.pm index 98cd0fafe..ba6eba1fb 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/oraclesession.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/oraclesession.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkoraclesession.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/oracletable.pm b/centreon-plugins/apps/kingdee/eas/mode/oracletable.pm index b4876b8e9..579481b8e 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/oracletable.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/oracletable.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkoracletable.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/oracleversion.pm b/centreon-plugins/apps/kingdee/eas/mode/oracleversion.pm index 61d3ae4b3..b4171dc64 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/oracleversion.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/oracleversion.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkoracleversion.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/ormrpc.pm b/centreon-plugins/apps/kingdee/eas/mode/ormrpc.pm index 4270b79e3..a6e6135d5 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/ormrpc.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/ormrpc.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new( package => __PACKAGE__, %options ); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options( arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkrpc.jsp" }, diff --git a/centreon-plugins/apps/kingdee/eas/mode/transaction.pm b/centreon-plugins/apps/kingdee/eas/mode/transaction.pm index 953654f86..94c475d34 100644 --- a/centreon-plugins/apps/kingdee/eas/mode/transaction.pm +++ b/centreon-plugins/apps/kingdee/eas/mode/transaction.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checktransaction.jsp" }, diff --git a/centreon-plugins/apps/lmsensors/snmp/mode/sensors.pm b/centreon-plugins/apps/lmsensors/snmp/mode/sensors.pm index c796274ea..808ddc170 100644 --- a/centreon-plugins/apps/lmsensors/snmp/mode/sensors.pm +++ b/centreon-plugins/apps/lmsensors/snmp/mode/sensors.pm @@ -53,7 +53,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/lotus/snmp/mode/mailstate.pm b/centreon-plugins/apps/lotus/snmp/mode/mailstate.pm index 91cc91d86..5613c2edc 100644 --- a/centreon-plugins/apps/lotus/snmp/mode/mailstate.pm +++ b/centreon-plugins/apps/lotus/snmp/mode/mailstate.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-waiting:s" => { name => 'warning_waiting', }, diff --git a/centreon-plugins/apps/lotus/snmp/mode/mailtime.pm b/centreon-plugins/apps/lotus/snmp/mode/mailtime.pm index 7b28d66cf..124414301 100644 --- a/centreon-plugins/apps/lotus/snmp/mode/mailtime.pm +++ b/centreon-plugins/apps/lotus/snmp/mode/mailtime.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/lotus/snmp/mode/serveravailability.pm b/centreon-plugins/apps/lotus/snmp/mode/serveravailability.pm index 689d0a0b2..8c50760dd 100644 --- a/centreon-plugins/apps/lotus/snmp/mode/serveravailability.pm +++ b/centreon-plugins/apps/lotus/snmp/mode/serveravailability.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/lotus/snmp/mode/servertransactions.pm b/centreon-plugins/apps/lotus/snmp/mode/servertransactions.pm index 4a5dc5d4e..523dbc596 100644 --- a/centreon-plugins/apps/lotus/snmp/mode/servertransactions.pm +++ b/centreon-plugins/apps/lotus/snmp/mode/servertransactions.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/lotus/snmp/mode/usersessions.pm b/centreon-plugins/apps/lotus/snmp/mode/usersessions.pm index 522638c9c..a9ca8bec6 100644 --- a/centreon-plugins/apps/lotus/snmp/mode/usersessions.pm +++ b/centreon-plugins/apps/lotus/snmp/mode/usersessions.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/lync/2013/mssql/mode/lyncusers.pm b/centreon-plugins/apps/lync/2013/mssql/mode/lyncusers.pm index efc2b4ea3..e3ddafa02 100644 --- a/centreon-plugins/apps/lync/2013/mssql/mode/lyncusers.pm +++ b/centreon-plugins/apps/lync/2013/mssql/mode/lyncusers.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/monitoring/openmetrics/mode/scrapemetrics.pm b/centreon-plugins/apps/monitoring/openmetrics/mode/scrapemetrics.pm new file mode 100644 index 000000000..2c529bbcb --- /dev/null +++ b/centreon-plugins/apps/monitoring/openmetrics/mode/scrapemetrics.pm @@ -0,0 +1,198 @@ +# +# Copyright 2019 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 apps::monitoring::openmetrics::mode::scrapemetrics; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::common::monitoring::openmetrics::scrape; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-metrics:s' => { name => 'filter_metrics' }, + "warning:s" => { name => 'warning', default => '' }, + "critical:s" => { name => 'critical', default => '' }, + 'instance:s' => { name => 'instance' }, + 'subinstance:s' => { name => 'subinstance' }, + 'filter-instance:s' => { name => 'filter_instance' }, + 'filter-subinstance:s' => { name => 'filter_subinstance' }, + 'new-perfdata' => { name => 'new_perfdata' }, + }); + + 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) = @_; + + $self->{metrics} = centreon::common::monitoring::openmetrics::scrape::parse(%options); + + my @exits; + my $short_msg = 'All metrics are ok'; + + my $nometrics = 1; + + foreach my $metric (keys %{$self->{metrics}}) { + next if (defined($self->{option_results}->{filter_metrics}) && $self->{option_results}->{filter_metrics} ne '' && + $metric !~ /$self->{option_results}->{filter_metrics}/); + + foreach my $data (@{$self->{metrics}->{$metric}->{data}}) { + next if (defined($self->{option_results}->{instance}) && + !defined($data->{dimensions}->{$self->{option_results}->{instance}}) || + defined($self->{option_results}->{filter_instance}) && $self->{option_results}->{filter_instance} ne '' && + $data->{dimensions}->{$self->{option_results}->{instance}} !~ /$self->{option_results}->{filter_instance}/); + next if (defined($self->{option_results}->{subinstance}) && + !defined($data->{dimensions}->{$self->{option_results}->{subinstance}}) || + defined($self->{option_results}->{filter_subinstance}) && $self->{option_results}->{filter_subinstance} ne '' && + $data->{dimensions}->{$self->{option_results}->{subinstance}} !~ /$self->{option_results}->{filter_subinstance}/); + $nometrics = 0; + my $label = $metric; + $label =~ s/_/./g if (defined($self->{option_results}->{new_perfdata})); + $label = $data->{dimensions}->{$self->{option_results}->{instance}} . '#' . $label + if (defined($self->{option_results}->{instance}) && + defined($data->{dimensions}->{$self->{option_results}->{instance}}) && + !defined($self->{option_results}->{subinstance})); + $label = $data->{dimensions}->{$self->{option_results}->{instance}} . '~' . + $data->{dimensions}->{$self->{option_results}->{subinstance}} . '#' . $label + if (defined($self->{option_results}->{instance}) && + defined($data->{dimensions}->{$self->{option_results}->{instance}}) && + defined($self->{option_results}->{subinstance}) && + defined($data->{dimensions}->{$self->{option_results}->{subinstance}})); + $label =~ s/'//g; + + push @exits, $self->{perfdata}->threshold_check( + value => $data->{value}, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, + { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->perfdata_add( + label => $label, + value => $data->{value}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); + + $self->{output}->output_add(long_msg => sprintf("Metric '%s' value is '%s' [Help: \"%s\"] [Type: '%s'] [Dimensions: \"%s\"]", + $metric, $data->{value}, + (defined($self->{metrics}->{$metric}->{help})) ? $self->{metrics}->{$metric}->{help} : '-', + (defined($self->{metrics}->{$metric}->{type})) ? $self->{metrics}->{$metric}->{type} : '-', + $data->{dimensions_string})); + } + } + + if ($nometrics == 1) { + $self->{output}->add_option_msg(short_msg => "No metrics found."); + $self->{output}->option_exit(); + } + + my $exit = $self->{output}->get_most_critical(status => \@exits); + $short_msg = 'Some metrics are not ok' if ($exit !~ /OK/i); + $self->{output}->output_add(severity => $exit, short_msg => $short_msg); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Scrape metrics. + +Examples: + +# perl centreon_plugins.pl --plugin=apps::monitoring::openmetrics::plugin --mode=scrape-metrics +--custommode=web --hostname=10.2.3.4 --port=9100 --verbose --filter-metrics='node_network_up' +--critical='0:0' --instance='device' --new-perfdata + +# perl centreon_plugins.pl --plugin=apps::monitoring::openmetrics::plugin --mode=scrape-metrics +--custommode=web --hostname=10.2.3.4 --port=9100 --verbose --filter-metrics='node_cpu_seconds_total' +--instance='cpu' --subinstance='mode' --filter-subinstance='idle' + +# perl centreon_plugins.pl --plugin=apps::monitoring::openmetrics::plugin --mode=scrape-metrics +--custommode=file --command-options='/tmp/metrics' --filter-metrics='cpu' --verbose + +# perl centreon_plugins.pl --plugin=apps::monitoring::openmetrics::plugin --mode=scrape-metrics +--custommode=file --hostname=10.2.3.4 --ssh-option='-l=centreon-engine' --ssh-option='-p=52' +--command-options='/my/app/path/metrics' --verbose + +=over 8 + +=item B<--filter-metrics> + +Only parse some metrics (regexp can be used). +Example: --filter-metrics='^status$' + +=item B<--warning> + +Set warning threshold. + +=item B<--critical> + +Set critical threshold. + +=item B<--instance> + +Set the label from dimensions to get the instance value from. + +=item B<--filter-instance> + +Only display some instances. +Example: --filter-instance='0' + +=item B<--subinstance> + +Set the label from dimensions to get the subinstance value from. + +=item B<--filter-subinstance> + +Only display some subinstances. +Example: --filter-subinstance='idle' + +=item B<--new-perfdata> + +Replace the underscore symbol by a point in perfdata. + +=back + +=cut diff --git a/centreon-plugins/apps/monitoring/openmetrics/plugin.pm b/centreon-plugins/apps/monitoring/openmetrics/plugin.pm new file mode 100644 index 000000000..9209ee89d --- /dev/null +++ b/centreon-plugins/apps/monitoring/openmetrics/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2019 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 apps::monitoring::openmetrics::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'scrape-metrics' => 'apps::monitoring::openmetrics::mode::scrapemetrics', + ); + $self->{custom_modes}{web} = 'centreon::common::monitoring::openmetrics::custom::web'; + $self->{custom_modes}{file} = 'centreon::common::monitoring::openmetrics::custom::file'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Scrapes metrics from openmetric endpoints. + +=cut diff --git a/centreon-plugins/apps/monitoring/quanta/restapi/custom/api.pm b/centreon-plugins/apps/monitoring/quanta/restapi/custom/api.pm new file mode 100644 index 000000000..7255b6ee8 --- /dev/null +++ b/centreon-plugins/apps/monitoring/quanta/restapi/custom/api.pm @@ -0,0 +1,202 @@ +# +# Copyright 2019 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 apps::monitoring::quanta::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use DateTime; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + "hostname:s" => { name => 'hostname' }, + "url-path:s" => { name => 'url_path' }, + "port:s" => { name => 'port' }, + "proto:s" => { name => 'proto' }, + "api-token:s" => { name => 'api_token' }, + "timeout:s" => { name => 'timeout' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : 'app.quanta.io'; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/api'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + $self->{api_token} = (defined($self->{option_results}->{api_token})) ? $self->{option_results}->{api_token} : ''; + + if (!defined($self->{api_token}) || $self->{api_token} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-token option."); + $self->{output}->option_exit(); + } + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{url_path} = $self->{url_path}; + $self->{option_results}->{warning_status} = ''; + $self->{option_results}->{critical_status} = ''; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub get_api_token { + my ($self, %options) = @_; + + return $self->{api_token}; +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings; + + $self->{output}->output_add(long_msg => "Query URL: '" . $self->{proto} . "://" . $self->{hostname} . + $self->{url_path} . $options{url_path} . "'", debug => 1); + + my $content = $self->{http}->request(url_path => $self->{url_path} . $options{url_path}); + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); + $self->{output}->option_exit(); + } + if (defined($decoded->{error})) { + $self->{output}->add_option_msg(short_msg => "API returned error '" . $decoded->{error} . "'"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +1; + +__END__ + +=head1 NAME + +Quanta Rest API + +=head1 SYNOPSIS + +Quanta Rest API custom mode + +=head1 REST API OPTIONS + +Quanta Rest API + +=over 8 + +=item B<--hostname> + +Quanta API hostname (Default: 'api.quanta.io') + +=item B<--port> + +API port (Default: 443) + +=item B<--proto> + +Specify https if needed (Default: 'https') + +=item B<--url-path> + +API URL path (Default: '/api') + +=item B<--api-token> + +API token. + +=item B<--timeout> + +Set HTTP timeout. + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/monitoring/quanta/restapi/mode/webscenariosavailability.pm b/centreon-plugins/apps/monitoring/quanta/restapi/mode/webscenariosavailability.pm new file mode 100644 index 000000000..8d50ba526 --- /dev/null +++ b/centreon-plugins/apps/monitoring/quanta/restapi/mode/webscenariosavailability.pm @@ -0,0 +1,137 @@ +# +# Copyright 2019 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 apps::monitoring::quanta::restapi::mode::webscenariosavailability; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 1, cb_prefix_output => 'prefix_output' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-response-time', nlabel => 'total.response.time.seconds', set => { + key_values => [ { name => 'response_time' }, { name => 'display' } ], + output_template => 'Total Response Time: %.3fs', + perfdatas => [ + { value => 'response_time_absolute', template => '%.3f', + min => 0, unit => 's', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'availability', nlabel => 'availability.percentage', set => { + key_values => [ { name => 'availability' }, { name => 'display' } ], + output_template => 'Availability: %.2f%%', + perfdatas => [ + { value => 'availability_absolute', template => '%s', + min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'step-response-time', nlabel => 'step.response.time.seconds', set => { + key_values => [ { name => 'avg_step_response_time' }, { name => 'display' } ], + output_template => 'Step Average Response Time: %.3fs', + perfdatas => [ + { value => 'avg_step_response_time_absolute', template => '%.3f', + min => 0, unit => 's', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Scenario '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "scenario-id:s" => { name => 'scenario_id' }, + "timeframe:s" => { name => 'timeframe', default => 900 }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{scenario_id}) || $self->{option_results}->{scenario_id} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --scenario-id option."); + $self->{output}->option_exit(); + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = {}; + + my $from = DateTime->now->subtract(seconds => $self->{option_results}->{timeframe}); + my $to = DateTime->now; + my $from_epoch = $from->epoch; + my $to_epoch = $to->epoch; + my $url = '/partners/report/' . $options{custom}->get_api_token . + '?scenario=' . $self->{option_results}->{scenario_id} . + '&from=' . $from_epoch . '&to=' . $to_epoch; + + my $results = $options{custom}->request_api(url_path => $url); + + $self->{global}->{$results->{site}->{id}}->{display} = $results->{site}->{scenario}; + $self->{global}->{$results->{site}->{id}}->{availability} = $results->{site}->{availability} * 100; + $self->{global}->{$results->{site}->{id}}->{avg_step_response_time} = $results->{site}->{avg_step_response_time}; + foreach my $response (@{$results->{site}->{scenario_response_times}}) { + $self->{global}->{$results->{site}->{id}}->{response_time} += $response->{value}; + } + $self->{global}->{$results->{site}->{id}}->{response_time} /= scalar(@{$results->{site}->{scenario_response_times}}) + if (scalar(@{$results->{site}->{scenario_response_times}}) > 0); +} + +1; + +__END__ + +=head1 MODE + +Check web scenario availability metrics. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Can be: 'total-response-time', 'availability', +'step-response-time'. + +=back + +=cut diff --git a/centreon-plugins/apps/elasticsearch/restapi/plugin.pm b/centreon-plugins/apps/monitoring/quanta/restapi/plugin.pm similarity index 70% rename from centreon-plugins/apps/elasticsearch/restapi/plugin.pm rename to centreon-plugins/apps/monitoring/quanta/restapi/plugin.pm index df152c9ce..552647b33 100644 --- a/centreon-plugins/apps/elasticsearch/restapi/plugin.pm +++ b/centreon-plugins/apps/monitoring/quanta/restapi/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package apps::elasticsearch::restapi::plugin; +package apps::monitoring::quanta::restapi::plugin; use strict; use warnings; @@ -31,20 +31,25 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cluster' => 'apps::elasticsearch::restapi::mode::cluster', - 'indices' => 'apps::elasticsearch::restapi::mode::indices', - 'nodes' => 'apps::elasticsearch::restapi::mode::nodes', - ); - $self->{custom_modes}{api} = 'apps::elasticsearch::restapi::custom::api'; + 'web-scenarios-availability' => 'apps::monitoring::quanta::restapi::mode::webscenariosavailability', + ); + + $self->{custom_modes}{api} = 'apps::monitoring::quanta::restapi::custom::api'; return $self; } +sub init { + my ( $self, %options ) = @_; + + $self->SUPER::init(%options); +} + 1; __END__ =head1 PLUGIN DESCRIPTION -Check elasticsearch through HTTP/REST API. +Check Quanta.io application probes results. =cut diff --git a/centreon-plugins/apps/monitoring/scom/restapi/custom/api.pm b/centreon-plugins/apps/monitoring/scom/restapi/custom/api.pm new file mode 100644 index 000000000..89189fbee --- /dev/null +++ b/centreon-plugins/apps/monitoring/scom/restapi/custom/api.pm @@ -0,0 +1,291 @@ +# +# Copyright 2019 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 apps::monitoring::scom::restapi::custom::api; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::http; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'api-version' => { name => 'api_version' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'basic' => { name => 'basic' }, + 'ntlmv2' => { name => 'ntlmv2' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout' }, + 'unknown-http-status:s' => { name => 'unknown_http_status' }, + 'warning-http-status:s' => { name => 'warning_http_status' }, + 'critical-http-status:s' => { name => 'critical_http_status' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MODE OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{api_version} = (defined($self->{option_results}->{api_version})) ? $self->{option_results}->{api_version} : 2016; + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 80; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'http'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + $self->{username} = $self->{option_results}->{username}; + $self->{password} = $self->{option_results}->{password}; + $self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300' ; + $self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : ''; + $self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : ''; + $self->{basic} = $self->{option_results}->{basic}; + $self->{ntlmv2} = $self->{option_results}->{ntlmv2}; + + if (!defined($self->{api_version}) || $self->{api_version} !~ /(2012|2016|1801)/) { + $self->{output}->add_option_msg(short_msg => 'Need to specify valid --api-version.'); + $self->{output}->option_exit(); + } + $self->{api_version} = $1; + + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); + $self->{output}->option_exit(); + } + return 0; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub get_port { + my ($self, %options) = @_; + + return $self->{port}; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{timeout} = $self->{timeout}; + + if (defined($self->{username}) && $self->{username} ne '') { + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1 if (defined($self->{basic})); + $self->{option_results}->{ntlmv2} = 1 if (defined($self->{ntlmv2})); + $self->{option_results}->{username} = $self->{username}; + $self->{option_results}->{password} = $self->{password}; + } +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub get_method { + my ($self, %options) = @_; + + my $api = 2016; + $api = 1801 if ($self->{api_version} == 1801); + return $self->can($options{method} . '_' . $api); +} + +my $map_severity = { + 0 => 'information', 1 => 'warning', 2 => 'critical' +}; +my $map_resolution_state = { + 0 => 'new', 255 => 'closed', 254 => 'resolved', + 250 => 'scheduled', 247 => 'awaiting_evidence', + 248 => 'assigned_to_engineering', + 249 => 'acknowledge', +}; + +sub get_alerts_2016 { + my ($self, %options) = @_; + + $self->settings(); + my ($status, $response) = $self->{http}->request( + url_path => '/api/alerts', + credentials => 1, + header => [ + 'Accept-Type: application/json; charset=utf-8', + 'Content-Type: application/json; charset=utf-8', + ], + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status}, + ); + + my $entries; + eval { + $entries = JSON::XS->new->utf8->decode($response); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); + $self->{output}->option_exit(); + } + + my $results = {}; + foreach (@$entries) { + $results->{$_->{alertGenerated}->{id}} = { + host => $_->{alertGenerated}->{monitoringObjectDisplayName}, + monitoringobjectdisplayname => $_->{alertGenerated}->{monitoringObjectDisplayName}, + resolutionstate => $map_resolution_state->{$_->{alertGenerated}->{resolutionState}}, + name => $_->{alertGenerated}->{name}, + severity => $map_severity->{$_->{alertGenerated}->{severity}}, + timeraised => $_->{alertGenerated}->{timeRaised}, + description => $_->{alertGenerated}->{description}, + }; + } + + return $results; +} + +sub get_alerts_1801 { + my ($self, %options) = @_; + + $self->{output}->add_option_msg(short_msg => "method 'get_alerts_1801' unsupported"); + $self->{output}->option_exit(); +} + +sub get_alerts { + my ($self, %options) = @_; + + my $func = $self->get_method(method => 'get_alerts'); + return $func->($self, %options); +} + +1; + +__END__ + +=head1 NAME + +SCOM Rest API + +=head1 CUSTOM MODE OPTIONS + +SCOM Rest API + +=over 8 + +=item B<--api-version> + +Set SCOM API version (default: 2016). +Could be: 2012, 2016 or 1801. + +=item B<--hostname> + +Remote hostname or IP address. + +=item B<--port> + +Port used (Default: 80) + +=item B<--proto> + +Specify https if needed (Default: 'http') + +=item B<--username> + +Specify username for authentication + +=item B<--password> + +Specify password for authentication + +=item B<--basic> + +Specify this option if you access webpage over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your webserver. + +Specify this option if you access webpage over hidden basic authentication or you'll get a '404 NOT FOUND' error. + +(Use with --credentials) + +=item B<--ntlmv2> + +Specify this option if you access webpage over ntlmv2 authentication (Use with --credentials and --port options) + +=item B<--timeout> + +Set timeout in seconds (Default: 10). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/monitoring/scom/restapi/mode/alerts.pm b/centreon-plugins/apps/monitoring/scom/restapi/mode/alerts.pm new file mode 100644 index 000000000..d7f697bec --- /dev/null +++ b/centreon-plugins/apps/monitoring/scom/restapi/mode/alerts.pm @@ -0,0 +1,190 @@ +# +# Copyright 2018 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 apps::monitoring::scom::restapi::mode::alerts; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::statefile; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("alert [severity: %s] [host: %s] [name: %s] %s", $self->{result_values}->{severity}, + $self->{result_values}->{host}, $self->{result_values}->{name}, $self->{result_values}->{timeraised}); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, + { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { nlabel => 'alerts.problems.current.count', min => 0 }, + group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] + } + ]; + + $self->{maps_counters}->{global} = []; + foreach ('new', 'closed', 'resolved', 'scheduled', 'awaiting_evidence', 'assigned_to_engineering', 'acknowledge') { + my $label = $_; + $label =~ s/_/-/g; + push @{$self->{maps_counters}->{global}}, { + label => $label, nlabel => 'alerts.resolution.' . $_ . '.count', display_ok => 0, set => { + key_values => [ { name => $_ } ], + output_template => $_ . ': %s', + perfdatas => [ + { value => $_ . '_absolute', template => '%s', min => 0 }, + ], + } + }; + } + + $self->{maps_counters}->{alarm} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'host' }, { name => 'name' }, + { name => 'severity' }, { name => 'timeraised' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Resolution state '; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-host:s' => { name => 'filter_host' }, + 'warning-status:s' => { name => 'warning_status', default => '%{severity} =~ /warning/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{severity} =~ /critical/i' }, + 'memory' => { name => 'memory' }, + }); + + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->check_options(%options); + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { + 'new' => 0, 'closed' => 0, 'resolved' => 0, 'scheduled' => 0, 'awaiting_evidence' => 0, 'assigned_to_engineering' => 0, 'acknowledge' => 0, + }; + $self->{alarms}->{global} = { alarm => {} }; + my $results = $options{custom}->get_alerts(); + + my $alerts_mem; + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->read(statefile => "cache_scom_" . $options{custom}->get_hostname() . '_' . $options{custom}->get_port(). '_' . $self->{mode}); + $alerts_mem = $self->{statefile_cache}->get(name => 'alerts'); + } + + foreach my $alert_id (keys %$results) { + if (defined($self->{option_results}->{memory})) { + if (defined($alerts_mem) && defined($alerts_mem->{$alert_id})) { + $alerts_mem->{$alert_id} = 1; + next; + } + $alerts_mem->{$alert_id} = 1; + } + + if (defined($self->{option_results}->{filter_host}) && $self->{option_results}->{filter_host} ne '' && + $results->{$alert_id}->{monitoringobjectdisplayname} !~ /$self->{option_results}->{filter_host}/) { + $self->{output}->output_add(long_msg => "skipping '" . $results->{$alert_id}->{monitoringobjectdisplayname} . "': no matching filter.", debug => 1); + next; + } + + $self->{global}->{$results->{$alert_id}->{resolutionstate}}++; + $self->{alarms}->{global}->{alarm}->{$alert_id} = { %{$results->{$alert_id}} }; + } + + if (defined($alerts_mem)) { + foreach (keys %$alerts_mem) { + if (!defined($results->{$_})) { + delete $alerts_mem->{$_}; + } + } + } + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->write(data => { alerts => $alerts_mem }); + } +} + +1; + +__END__ + +=head1 MODE + +Check alerts. + +=over 8 + +=item B<--filter-host> + +Filter by host name (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{severity} =~ /warning/i') +Can used special variables like: %{severity}, %{host}, %{name}, %{timeraised} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{severity} =~ /critical/i'). +Can used special variables like: %{severity}, %{host}, %{name}, %{timeraised} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'new', 'closed', 'resolved', 'scheduled', 'awaiting-evidence', 'assigned-to-engineering', 'acknowledge'. + +=item B<--memory> + +Only check new alarms. + +=back + +=cut diff --git a/centreon-plugins/apps/monitoring/scom/restapi/plugin.pm b/centreon-plugins/apps/monitoring/scom/restapi/plugin.pm new file mode 100644 index 000000000..c69418059 --- /dev/null +++ b/centreon-plugins/apps/monitoring/scom/restapi/plugin.pm @@ -0,0 +1,51 @@ +# +# Copyright 2019 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 apps::monitoring::scom::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'alerts' => 'apps::monitoring::scom::restapi::mode::alerts', + ); + + $self->{custom_modes}{api} = 'apps::monitoring::scom::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check SCOM with Rest API. +Compatible SCOM 2012 and 2016 with api: https://gallery.technet.microsoft.com/System-Center-Operations-5d88527c +Not compatible SCOM 1801 (soon) + +=cut diff --git a/centreon-plugins/apps/mq/rabbitmq/restapi/custom/api.pm b/centreon-plugins/apps/mq/rabbitmq/restapi/custom/api.pm new file mode 100644 index 000000000..bc039050c --- /dev/null +++ b/centreon-plugins/apps/mq/rabbitmq/restapi/custom/api.pm @@ -0,0 +1,221 @@ +# +# Copyright 2019 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 apps::mq::rabbitmq::restapi::custom::api; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::http; +use URI::Encode; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MODE OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 15672; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'http'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + $self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef; + $self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef; + + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); + $self->{output}->option_exit(); + } + return 0; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub get_port { + my ($self, %options) = @_; + + return $self->{port}; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{timeout} = $self->{timeout}; + + if (defined($self->{username}) && $self->{username} ne '') { + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{username}; + $self->{option_results}->{password} = $self->{password}; + } +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub request { + my ($self, %options) = @_; + + $self->settings(); + + $self->{output}->output_add(long_msg => "URL: '" . $self->{proto} . '://' . $self->{hostname} . ':' . $self->{port} . $options{url_path} . "'", debug => 1); + $self->{output}->output_add(long_msg => "Parameters: '" . join(', ', @{$options{post_param}}) . "'", debug => 1) if (defined($options{post_param})); + + my $content = $self->{http}->request( + %options, + unknown_status => '%{http_code} < 200 or %{http_code} >= 300', + critical_status => '', + ); + + if (!defined($content) || $content eq '') { + $self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); + $self->{output}->option_exit(); + } + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->output_add(long_msg => $content, debug => 1); + $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +sub query { + my ($self, %options) = @_; + + return $self->request(url_path => $options{url_path}); +} + +1; + +__END__ + +=head1 NAME + +RabbitMQ Rest API + +=head1 CUSTOM MODE OPTIONS + +RabbitMQ Rest API + +=over 8 + +=item B<--hostname> + +Remote hostname or IP address. + +=item B<--port> + +Port used (Default: 15672) + +=item B<--proto> + +Specify https if needed (Default: 'http') + +=item B<--username> + +Specify username for authentication + +=item B<--password> + +Specify password for authentication + +=item B<--timeout> + +Set timeout in seconds (Default: 10). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/mq/rabbitmq/restapi/mode/listnodes.pm b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/listnodes.pm new file mode 100644 index 000000000..f4af0b960 --- /dev/null +++ b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/listnodes.pm @@ -0,0 +1,102 @@ +# +# Copyright 2019 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 apps::mq::rabbitmq::restapi::mode::listnodes; + +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; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->query(url_path => '/api/nodes/?columns=name'); + $self->{node} = {}; + foreach (@$result) { + $self->{node}->{$_->{name}} = { + name => $_->{name}, + status => $_->{running} ? 'running' : 'notrunning', + }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (sort keys %{$self->{node}}) { + $self->{output}->output_add(long_msg => sprintf( + "[name = %s][status = %s]", + $self->{node}->{$_}->{name}, $self->{node}->{$_}->{status}) + ); + } + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List nodes:' + ); + + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (values %{$self->{node}}) { + $self->{output}->add_disco_entry(%$_); + } +} + +1; + +__END__ + +=head1 MODE + +List nodes. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/apps/mq/rabbitmq/restapi/mode/listqueues.pm b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/listqueues.pm new file mode 100644 index 000000000..be9ee6fe6 --- /dev/null +++ b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/listqueues.pm @@ -0,0 +1,103 @@ +# +# Copyright 2019 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 apps::mq::rabbitmq::restapi::mode::listqueues; + +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; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->query(url_path => '/api/queues/?columns=vhost,name,state'); + $self->{queue} = {}; + foreach (@$result) { + $self->{queue}->{$_->{vhost} . ':' . $_->{name}} = { + vhost => $_->{vhost}, + name => $_->{name}, + state => $_->{state}, + }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (sort keys %{$self->{queue}}) { + $self->{output}->output_add(long_msg => sprintf( + "[name = %s][vhost = %s][state = %s]", + $self->{queue}->{$_}->{name}, $self->{queue}->{$_}->{vhost}, $self->{queue}->{$_}->{state}) + ); + } + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List queues:' + ); + + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'vhost', 'state']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (values %{$self->{queue}}) { + $self->{output}->add_disco_entry(%$_); + } +} + +1; + +__END__ + +=head1 MODE + +List queues. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/apps/mq/rabbitmq/restapi/mode/listvhosts.pm b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/listvhosts.pm new file mode 100644 index 000000000..55dbb6702 --- /dev/null +++ b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/listvhosts.pm @@ -0,0 +1,105 @@ +# +# Copyright 2019 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 apps::mq::rabbitmq::restapi::mode::listvhosts; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use URI::Encode; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $uri = URI::Encode->new({encode_reserved => 1}); + my $result = $options{custom}->query(url_path => '/api/vhosts/?columns=name'); + $self->{vhost} = {}; + foreach (@$result) { + my $result_alive = $options{custom}->query(url_path => '/api/aliveness-test/' . $uri->encode($_->{name})); + $self->{vhost}->{$_->{name}} = { + name => $_->{name}, + status => $result_alive->{status} + }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (sort keys %{$self->{vhost}}) { + $self->{output}->output_add(long_msg => sprintf( + "[name = %s][status = %s]", + $self->{vhost}->{$_}->{name}, $self->{vhost}->{$_}->{status}) + ); + } + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List vhosts:' + ); + + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (values %{$self->{vhost}}) { + $self->{output}->add_disco_entry(%$_); + } +} + +1; + +__END__ + +=head1 MODE + +List vhosts. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/apps/mq/rabbitmq/restapi/mode/nodeusage.pm b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/nodeusage.pm new file mode 100644 index 000000000..da4f78357 --- /dev/null +++ b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/nodeusage.pm @@ -0,0 +1,161 @@ +# +# Copyright 2019 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 apps::mq::rabbitmq::restapi::mode::nodeusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = "status: '" . $self->{result_values}->{status} . "'"; + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All nodes are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{node} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'read', nlabel => 'node.io.read.usage.bytespersecond', set => { + key_values => [ { name => 'io_read_bytes', diff => 1 }, { name => 'display' } ], + output_template => 'read i/o : %s %s/s', + per_second => 1, output_change_bytes => 1, + perfdatas => [ + { value => 'io_read_bytes_per_second', template => '%d', + unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'write', nlabel => 'node.io.write.usage.bytespersecond', set => { + key_values => [ { name => 'io_write_bytes', diff => 1 }, { name => 'display' } ], + output_template => 'write i/o : %s %s/s', + per_second => 1, output_change_bytes => 1, + perfdatas => [ + { value => 'io_write_bytes_per_second', template => '%d', + unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_node_output { + my ($self, %options) = @_; + + return "Node '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} ne "running"' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->query(url_path => '/api/nodes/?columns=name,running,io_write_bytes,io_read_bytes'); + + $self->{node} = {}; + foreach (@$result) { + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' + && $_->{name} !~ /$self->{option_results}->{filter_name}/); + + $self->{node}->{$_->{name}} = { + display => $_->{name}, + io_write_bytes => $_->{io_write_bytes}, + io_read_bytes => $_->{io_read_bytes}, + status => $_->{running} ? 'running' : 'notrunning', + }; + } + + if (scalar(keys %{$self->{node}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No node found'); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "rabbitmq_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check node usage. + +=over 8 + +=item B<--filter-name> + +Filter node name (Can use regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} ne "running"'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'read', 'write'. + +=back + +=cut diff --git a/centreon-plugins/apps/mq/rabbitmq/restapi/mode/queueusage.pm b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/queueusage.pm new file mode 100644 index 000000000..9d323d383 --- /dev/null +++ b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/queueusage.pm @@ -0,0 +1,160 @@ +# +# Copyright 2019 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 apps::mq::rabbitmq::restapi::mode::queueusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = "state: '" . $self->{result_values}->{state} . "'"; + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'queue', type => 1, cb_prefix_output => 'prefix_queue_output', message_multiple => 'All queues are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{queue} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'queue-msg', nlabel => 'queue.messages.count', set => { + key_values => [ { name => 'queue_messages' }, { name => 'display' } ], + output_template => 'current queue messages : %s', + perfdatas => [ + { label => 'queue_msg', value => 'queue_messages_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'queue-msg-ready', nlabel => 'queue.messages.ready.count', set => { + key_values => [ { name => 'queue_messages_ready' }, { name => 'display' } ], + output_template => 'current queue messages ready : %s', + perfdatas => [ + { label => 'queue_msg_ready', value => 'queue_messages_ready_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_queue_output { + my ($self, %options) = @_; + + return "Queue '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} ne "running"' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->query(url_path => '/api/queues/?columns=vhost,name,state,messages,messages_ready'); + + $self->{queue} = {}; + foreach (@$result) { + my $name = $_->{vhost} . ':' . $_->{name}; + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' + && $_->{name} !~ /$self->{option_results}->{filter_name}/); + + $self->{queue}->{$name} = { + display => $name, + queue_messages_ready => $_->{messages_ready}, + queue_messages => $_->{messages}, + state => $_->{state}, + }; + } + + if (scalar(keys %{$self->{queue}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No queue found'); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "rabbitmq_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check queue usage. + +=over 8 + +=item B<--filter-name> + +Filter queue name (Can use regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{state}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{state} ne "running"'). +Can used special variables like: %{state}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'queue-msg', 'queue-msg-ready'. + +=back + +=cut diff --git a/centreon-plugins/apps/mq/rabbitmq/restapi/mode/systemusage.pm b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/systemusage.pm new file mode 100644 index 000000000..692ccaa22 --- /dev/null +++ b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/systemusage.pm @@ -0,0 +1,131 @@ +# +# Copyright 2019 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 apps::mq::rabbitmq::restapi::mode::systemusage; + +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 => 'global', type => 0, skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'queue-msg', nlabel => 'system.queue.messages.count', set => { + key_values => [ { name => 'queue_messages' } ], + output_template => 'current queue messages : %s', + perfdatas => [ + { label => 'queue_msg', value => 'queue_messages_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'queue-msg-ready', nlabel => 'system.queue.messages.ready.count', set => { + key_values => [ { name => 'queue_messages_ready' } ], + output_template => 'current queue messages ready : %s', + perfdatas => [ + { label => 'queue_msg_ready', value => 'queue_messages_ready_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'db-event-queue', nlabel => 'system.db.event.queue.count', set => { + key_values => [ { name => 'db_event_queue' } ], + output_template => 'db event queue : %s', + perfdatas => [ + { label => 'db_event_queue', value => 'db_event_queue_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'disk-read-iops', nlabel => 'system.disk.read.usage.iops', set => { + key_values => [ { name => 'disk_reads', diff => 1 } ], + per_second => 1, + output_template => 'disk reads iops : %s', + perfdatas => [ + { label => 'disk_reads', value => 'disk_reads_per_second', template => '%d', + unit => 'iops', min => 0, }, + ], + } + }, + { label => 'disk-write-iops', nlabel => 'system.disk.write.usage.iops', set => { + key_values => [ { name => 'disk_writes', diff => 1 } ], + per_second => 1, + output_template => 'disk writes iops : %s', + perfdatas => [ + { label => 'disk_writes', value => 'disk_writes_per_second', template => '%d', + unit => 'iops', min => 0, }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->query(url_path => '/api/overview'); + $self->{global} = { + disk_reads => $result->{message_stats}->{disk_reads}, + disk_writes => $result->{message_stats}->{disk_writes}, + queue_messages_ready => $result->{queue_totals}->{messages_ready}, + queue_messages => $result->{queue_totals}->{messages}, + db_event_queue => $result->{statistics_db_event_queue}, + }; + + $self->{cache_name} = "rabbitmq_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check global system statistics + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'disk-read-iops', 'disk-write-iops', +'queue-msg-ready', 'queue-msg', 'db-event-queue'. + +=back + +=cut diff --git a/centreon-plugins/apps/mq/rabbitmq/restapi/mode/vhostusage.pm b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/vhostusage.pm new file mode 100644 index 000000000..09e9eb809 --- /dev/null +++ b/centreon-plugins/apps/mq/rabbitmq/restapi/mode/vhostusage.pm @@ -0,0 +1,159 @@ +# +# Copyright 2019 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 apps::mq::rabbitmq::restapi::mode::vhostusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use URI::Encode; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status: ' . $self->{result_values}->{status}; + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vhost', type => 1, cb_prefix_output => 'prefix_vhost_output', message_multiple => 'All vhosts are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{vhost} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'queue-msg', nlabel => 'vhost.queue.messages.count', set => { + key_values => [ { name => 'queue_messages' }, { name => 'display' } ], + output_template => 'current queue messages : %s', + perfdatas => [ + { label => 'queue_msg', value => 'queue_messages_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'queue-msg-ready', nlabel => 'vhost.queue.messages.ready.count', set => { + key_values => [ { name => 'queue_messages_ready' }, { name => 'display' } ], + output_template => 'current queue messages ready : %s', + perfdatas => [ + { label => 'queue_msg_ready', value => 'queue_messages_ready_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_vhost_output { + my ($self, %options) = @_; + + return "Vhost '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} ne "ok"' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->query(url_path => '/api/vhosts'); + + my $uri = URI::Encode->new({encode_reserved => 1}); + $self->{vhost} = {}; + foreach (@$result) { + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' + && $_->{name} !~ /$self->{option_results}->{filter_name}/); + + my $result_alive = $options{custom}->query(url_path => '/api/aliveness-test/' . $uri->encode($_->{name})); + + $self->{vhost}->{$_->{name}} = { + display => $_->{name}, + queue_messages_ready => $_->{messages_ready}, + queue_messages => $_->{messages}, + status => $result_alive->{status} + }; + } + + if (scalar(keys %{$self->{vhost}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No vhost found'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check vhost usage. + +=over 8 + +=item B<--filter-name> + +Filter vhost name (Can use regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} ne "ok"'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'queue-msg-ready', 'queue-msg'. + +=back + +=cut diff --git a/centreon-plugins/apps/mq/rabbitmq/restapi/plugin.pm b/centreon-plugins/apps/mq/rabbitmq/restapi/plugin.pm new file mode 100644 index 000000000..b2a1fdfe6 --- /dev/null +++ b/centreon-plugins/apps/mq/rabbitmq/restapi/plugin.pm @@ -0,0 +1,55 @@ +# +# Copyright 2019 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 apps::mq::rabbitmq::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'list-nodes' => 'apps::mq::rabbitmq::restapi::mode::listnodes', + 'list-queues' => 'apps::mq::rabbitmq::restapi::mode::listqueues', + 'list-vhosts' => 'apps::mq::rabbitmq::restapi::mode::listvhosts', + 'node-usage' => 'apps::mq::rabbitmq::restapi::mode::nodeusage', + 'queue-usage' => 'apps::mq::rabbitmq::restapi::mode::queueusage', + 'system-usage' => 'apps::mq::rabbitmq::restapi::mode::systemusage', + 'vhost-usage' => 'apps::mq::rabbitmq::restapi::mode::vhostusage', + ); + + $self->{custom_modes}{api} = 'apps::mq::rabbitmq::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check RabbitMQ with Rest API. + +=cut diff --git a/centreon-plugins/apps/nginx/serverstatus/mode/connections.pm b/centreon-plugins/apps/nginx/serverstatus/mode/connections.pm index beadcc04a..21d95e81a 100644 --- a/centreon-plugins/apps/nginx/serverstatus/mode/connections.pm +++ b/centreon-plugins/apps/nginx/serverstatus/mode/connections.pm @@ -38,7 +38,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/nginx/serverstatus/mode/requests.pm b/centreon-plugins/apps/nginx/serverstatus/mode/requests.pm index 4c9216097..6490c56c1 100644 --- a/centreon-plugins/apps/nginx/serverstatus/mode/requests.pm +++ b/centreon-plugins/apps/nginx/serverstatus/mode/requests.pm @@ -38,7 +38,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/nginx/serverstatus/mode/responsetime.pm b/centreon-plugins/apps/nginx/serverstatus/mode/responsetime.pm index 027d840dc..3ee1c1d91 100644 --- a/centreon-plugins/apps/nginx/serverstatus/mode/responsetime.pm +++ b/centreon-plugins/apps/nginx/serverstatus/mode/responsetime.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/nsclient/restapi/mode/query.pm b/centreon-plugins/apps/nsclient/restapi/mode/query.pm index 1061bd88a..f07cb5e14 100644 --- a/centreon-plugins/apps/nsclient/restapi/mode/query.pm +++ b/centreon-plugins/apps/nsclient/restapi/mode/query.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => 8443 }, diff --git a/centreon-plugins/apps/openldap/ldap/mode/systemusage.pm b/centreon-plugins/apps/openldap/ldap/mode/systemusage.pm index 42c907829..e876c1456 100644 --- a/centreon-plugins/apps/openldap/ldap/mode/systemusage.pm +++ b/centreon-plugins/apps/openldap/ldap/mode/systemusage.pm @@ -102,7 +102,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'hostname:s' => { name => 'hostname' }, 'search-base:s' => { name => 'search_base', default => 'cn=monitor' }, diff --git a/centreon-plugins/apps/openvpn/omi/mode/serverusage.pm b/centreon-plugins/apps/openvpn/omi/mode/serverusage.pm index b7041c849..189d63511 100644 --- a/centreon-plugins/apps/openvpn/omi/mode/serverusage.pm +++ b/centreon-plugins/apps/openvpn/omi/mode/serverusage.pm @@ -70,7 +70,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/openweathermap/restapi/mode/cityweather.pm b/centreon-plugins/apps/openweathermap/restapi/mode/cityweather.pm index 6398f1118..b302d12b2 100644 --- a/centreon-plugins/apps/openweathermap/restapi/mode/cityweather.pm +++ b/centreon-plugins/apps/openweathermap/restapi/mode/cityweather.pm @@ -106,7 +106,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "city-name:s" => { name => 'city_name' }, "warning-weather:s" => { name => 'warning_weather', default => '' }, diff --git a/centreon-plugins/apps/pacemaker/local/mode/clustat.pm b/centreon-plugins/apps/pacemaker/local/mode/clustat.pm index 2b4075c65..f35f74cdf 100644 --- a/centreon-plugins/apps/pacemaker/local/mode/clustat.pm +++ b/centreon-plugins/apps/pacemaker/local/mode/clustat.pm @@ -96,7 +96,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/pacemaker/local/mode/constraints.pm b/centreon-plugins/apps/pacemaker/local/mode/constraints.pm index 7d4c6456f..59115b1a3 100644 --- a/centreon-plugins/apps/pacemaker/local/mode/constraints.pm +++ b/centreon-plugins/apps/pacemaker/local/mode/constraints.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/pacemaker/local/mode/crm.pm b/centreon-plugins/apps/pacemaker/local/mode/crm.pm index bcdacd1e3..b209e17e6 100644 --- a/centreon-plugins/apps/pacemaker/local/mode/crm.pm +++ b/centreon-plugins/apps/pacemaker/local/mode/crm.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/pfsense/snmp/mode/listpfinterfaces.pm b/centreon-plugins/apps/pfsense/snmp/mode/listpfinterfaces.pm index e9bb63b60..9f1dd1870 100644 --- a/centreon-plugins/apps/pfsense/snmp/mode/listpfinterfaces.pm +++ b/centreon-plugins/apps/pfsense/snmp/mode/listpfinterfaces.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/pfsense/snmp/mode/packetstats.pm b/centreon-plugins/apps/pfsense/snmp/mode/packetstats.pm index 9f8b00c32..c117b0ecf 100644 --- a/centreon-plugins/apps/pfsense/snmp/mode/packetstats.pm +++ b/centreon-plugins/apps/pfsense/snmp/mode/packetstats.pm @@ -102,7 +102,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/pfsense/snmp/mode/pfinterfaces.pm b/centreon-plugins/apps/pfsense/snmp/mode/pfinterfaces.pm index c9a5a85a3..b9a55ba29 100644 --- a/centreon-plugins/apps/pfsense/snmp/mode/pfinterfaces.pm +++ b/centreon-plugins/apps/pfsense/snmp/mode/pfinterfaces.pm @@ -88,7 +88,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/pfsense/snmp/mode/runtime.pm b/centreon-plugins/apps/pfsense/snmp/mode/runtime.pm index b6e0882ab..ae60e5269 100644 --- a/centreon-plugins/apps/pfsense/snmp/mode/runtime.pm +++ b/centreon-plugins/apps/pfsense/snmp/mode/runtime.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/apps/php/apc/web/mode/filecache.pm b/centreon-plugins/apps/php/apc/web/mode/filecache.pm index 015881d0a..74064c87c 100644 --- a/centreon-plugins/apps/php/apc/web/mode/filecache.pm +++ b/centreon-plugins/apps/php/apc/web/mode/filecache.pm @@ -199,7 +199,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/php/apc/web/mode/memory.pm b/centreon-plugins/apps/php/apc/web/mode/memory.pm index dd262bf88..19b2ea917 100644 --- a/centreon-plugins/apps/php/apc/web/mode/memory.pm +++ b/centreon-plugins/apps/php/apc/web/mode/memory.pm @@ -95,7 +95,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/php/fpm/web/mode/usage.pm b/centreon-plugins/apps/php/fpm/web/mode/usage.pm index 93bccd9fc..9e9a738b2 100644 --- a/centreon-plugins/apps/php/fpm/web/mode/usage.pm +++ b/centreon-plugins/apps/php/fpm/web/mode/usage.pm @@ -139,7 +139,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/pineapp/securemail/snmp/mode/system.pm b/centreon-plugins/apps/pineapp/securemail/snmp/mode/system.pm new file mode 100644 index 000000000..f138fd331 --- /dev/null +++ b/centreon-plugins/apps/pineapp/securemail/snmp/mode/system.pm @@ -0,0 +1,275 @@ +# +# Copyright 2019 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 apps::pineapp::securemail::snmp::mode::system; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status is ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_storage_status_output { + my ($self, %options) = @_; + + my $msg = 'Storage status is ' . $self->{result_values}->{status}; + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global_load', type => 0, cb_prefix_output => 'prefix_load_output', skipped_code => { -10 => 1 } }, + { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, + { name => 'service', type => 1, cb_prefix_output => 'prefix_service_output', message_multiple => 'All services are ok' }, + ]; + + $self->{maps_counters}->{global_load} = []; + foreach ('1', '5', '15') { + push @{$self->{maps_counters}->{global_load}}, { + label => 'load-' . $_ . 'm', nlabel => 'system.load.' . $_ . 'm.count', set => { + key_values => [ { name => 'cpuload' . $_ . 'minavg' } ], + output_template => '%s (' . $_ . 'm)', + perfdatas => [ + { value => 'cpuload' . $_ . 'minavg_absolute', template => '%s', min => 0 }, + ], + } + }; + } + + $self->{maps_counters}->{global} = [ + { label => 'storage-status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_storage_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'messages-queue-inbound', nlabel => 'system.messages.queue.inbound.count', display_ok => 0, set => { + key_values => [ { name => 'mailsysteminboundqueue' } ], + output_template => 'messages inbound queue: %s', + perfdatas => [ + { value => 'mailsysteminboundqueue_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'messages-queue-outbound', nlabel => 'system.messages.queue.outbound.count', display_ok => 0, set => { + key_values => [ { name => 'mailsystemoutboundqueue' } ], + output_template => 'messages outbound queue: %s', + perfdatas => [ + { value => 'mailsystemoutboundqueue_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'messages-priority-high', nlabel => 'system.messages.priority.high.count', display_ok => 0, set => { + key_values => [ { name => 'mailQueueHigh' } ], + output_template => 'messages high priority: %s', + perfdatas => [ + { value => 'mailQueueHigh_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'messages-priority-normal', nlabel => 'system.messages.priority.normal.count', display_ok => 0, set => { + key_values => [ { name => 'mailQueueNormal' } ], + output_template => 'messages normal priority: %s', + perfdatas => [ + { value => 'mailQueueNormal_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'messages-priority-low', nlabel => 'system.messages.priority.low.count', display_ok => 0, set => { + key_values => [ { name => 'mailQueueLow' } ], + output_template => 'messages low priority: %s', + perfdatas => [ + { value => 'mailQueueLow_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'messages-queue-total', nlabel => 'system.messages.queue.total.count', display_ok => 0, set => { + key_values => [ { name => 'mailQueueTotal' } ], + output_template => 'messages queue total: %s', + perfdatas => [ + { value => 'mailQueueTotal_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{service} = [ + { label => 'service-status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_load_output { + my ($self, %options) = @_; + + return 'Load average: '; +} + +sub prefix_service_output { + my ($self, %options) = @_; + + return "Service '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-service-status:s' => { name => 'unknown_service_status', default => '' }, + 'warning-service-status:s' => { name => 'warning_service_status', default => '' }, + 'critical-service-status:s' => { name => 'critical_service_status', default => '%{status} !~ /running/i' }, + 'unknown-storage-status:s' => { name => 'unknown_storage_status', default => '' }, + 'warning-storage-status:s' => { name => 'warning_storage_status', default => '' }, + 'critical-storage-status:s' => { name => 'critical_storage_status', default => '%{status} !~ /ok/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros( + macros => [ + 'unknown_service_status', 'warning_service_status', 'critical_service_status', + 'unknown_storage_status', 'warning_storage_status', 'critical_storage_status', + ] + ); +} + +my $map_sc_status = { 0 => 'stopped', 1 => 'running' }; + +my $mapping = { + cpuload1minavg => { oid => '.1.3.6.1.4.1.19801.1.1.3.1' }, + cpuload5minavg => { oid => '.1.3.6.1.4.1.19801.1.1.3.2' }, + cpuload15minavg => { oid => '.1.3.6.1.4.1.19801.1.1.3.3' }, + storage => { oid => '.1.3.6.1.4.1.19801.1.4' }, + smtpservicestatus => { oid => '.1.3.6.1.4.1.19801.2.1.1', map => $map_sc_status }, + pop3servicestatus => { oid => '.1.3.6.1.4.1.19801.2.1.2', map => $map_sc_status }, + imap4servicestatus => { oid => '.1.3.6.1.4.1.19801.2.1.3', map => $map_sc_status }, + mailsysteminboundqueue => { oid => '.1.3.6.1.4.1.19801.2.1.10.1' }, + mailsystemoutboundqueue => { oid => '.1.3.6.1.4.1.19801.2.1.10.2' }, + mailQueueHigh => { oid => '.1.3.6.1.4.1.19801.2.1.10.3.1' }, + mailQueueNormal => { oid => '.1.3.6.1.4.1.19801.2.1.10.3.2' }, + mailQueueLow => { oid => '.1.3.6.1.4.1.19801.2.1.10.3.3' }, + mailQueueTotal => { oid => '.1.3.6.1.4.1.19801.2.1.10.3.4' }, + antivirusservicestatus => { oid => '.1.3.6.1.4.1.19801.2.5.1', map => $map_sc_status }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ], nothing_quit => 1 + ); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + $self->{service} = { + smtp => { status => $result->{smtpservicestatus}, display => 'smtp' }, + pop3 => { status => $result->{pop3servicestatus}, display => 'pop3' }, + imap4 => { status => $result->{imap4servicestatus}, display => 'imap4' }, + antivirus => { status => $result->{antivirusservicestatus}, display => 'antivirus' }, + }; + + $self->{global_load} = { %$result }; + $self->{global} = { + status => $result->{storage}, + mailsysteminboundqueue => $result->{mailsysteminboundqueue}, + mailsystemoutboundqueue => $result->{mailsystemoutboundqueue}, + mailQueueHigh => $result->{mailQueueHigh}, + mailQueueNormal => $result->{mailQueueNormal}, + mailQueueLow => $result->{mailQueueLow}, + mailQueueTotal => $result->{mailQueueTotal}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check system usage. + +=over 8 + +=item B<--unknown-service-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--warning-service-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-service-status> + +Set critical threshold for status (Default: '%{status} !~ /running/i'). +Can used special variables like: %{status}, %{display} + +=item B<--unknown-storage-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--warning-storage-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--critical-storage-status> + +Set critical threshold for status (Default: '%{status} !~ /ok/i'). +Can used special variables like: %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'load-1m', 'load-5m', 'load-15m', +'messages-priority-high', 'messages-priority-medium', 'messages-priority-low', +'messages-queue-inbound', 'messages-queue-outbound', +'messages-queue-total'. + +=back + +=cut + diff --git a/centreon-plugins/apps/pineapp/securemail/snmp/plugin.pm b/centreon-plugins/apps/pineapp/securemail/snmp/plugin.pm new file mode 100644 index 000000000..ea1a5ce2c --- /dev/null +++ b/centreon-plugins/apps/pineapp/securemail/snmp/plugin.pm @@ -0,0 +1,48 @@ +# +# Copyright 2019 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 apps::pineapp::securemail::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}} = ( + 'system' => 'apps::pineapp::securemail::snmp::mode::system', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check PineApp SecureMail in SNMP. + +=cut diff --git a/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm b/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm index 340e240e9..ab20d044e 100644 --- a/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm +++ b/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm @@ -28,11 +28,11 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = "AS:'" . $self->{result_values}->{as} . "' "; + my $msg = "AS:'" . $self->{result_values}->{as} . "'"; $msg .= " Local: '" . $self->{result_values}->{local} . "'"; $msg .= " Remote: '" . $self->{result_values}->{remote} . "'"; $msg .= " Peer State: '" . $self->{result_values}->{peerstate} . "'"; - $msg .= " Admin State : '" . $self->{result_values}->{adminstate} . "'"; + $msg .= " Admin State: '" . $self->{result_values}->{adminstate} . "'"; return $msg; } @@ -54,7 +54,8 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'peers', type => 1, cb_prefix_output => 'prefix_peers_output', message_multiple => 'All BGP peers are ok' }, + { name => 'peers', type => 1, cb_prefix_output => 'prefix_peers_output', + message_multiple => 'All BGP peers are ok' }, ]; $self->{maps_counters}->{peers} = [ { label => 'status', threshold => 0, set => { @@ -66,7 +67,7 @@ sub set_counters { closure_custom_threshold_check => \&catalog_status_threshold, } }, - { label => 'updates', set => { + { label => 'updates', nlabel => 'bgppeer.update.seconds', set => { key_values => [ { name => 'seconds' }, { name => 'display' } ], output_template => 'Last update : %ss', perfdatas => [ @@ -81,7 +82,7 @@ sub set_counters { sub prefix_peers_output { my ($self, %options) = @_; - return "Peer: '" . $options{instance_value}->{display} . "' "; + return "Peer '" . $options{instance_value}->{display} . "' "; } sub new { @@ -89,14 +90,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-peer:s" => { name => 'filter_peer' }, - "filter-as:s" => { name => 'filter_as' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - }); + $options{options}->add_options(arguments => { + "filter-peer:s" => { name => 'filter_peer' }, + "filter-as:s" => { name => 'filter_as' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', + default => '%{adminstate} =~ /start/ && %{peerstate} !~ /established/' }, + }); return $self; } @@ -144,30 +144,45 @@ sub manage_selection { foreach my $oid (keys %{$result}) { next if ($oid !~ /^$mapping->{bgpPeerState}->{oid}\.(.*)$/); my $instance = $1; - my $mapped_value = $options{snmp}->map_instance(mapping => $mapping, results => $result, instance => $instance); + my $mapped_value = $options{snmp}->map_instance( + mapping => $mapping, + results => $result, + instance => $instance + ); my $local_addr = $mapped_value->{bgpPeerLocalAddr} . ':' . $mapped_value->{bgpPeerLocalPort}; my $remote_addr = $mapped_value->{bgpPeerRemoteAddr} . ':' . $mapped_value->{bgpPeerRemotePort}; if (defined($self->{option_results}->{filter_peer}) && $self->{option_results}->{filter_peer} ne '' && $instance !~ /$self->{option_results}->{filter_peer}/) { - $self->{output}->output_add(long_msg => "skipping peer '" . $instance . "': no matching filter.", debug => 1); + $self->{output}->output_add( + long_msg => "skipping peer '" . $instance . "': no matching filter.", + debug => 1 + ); next; } if (defined($self->{option_results}->{filter_as}) && $self->{option_results}->{filter_as} ne '' && $instance !~ /$self->{option_results}->{filter_as}/) { - $self->{output}->output_add(long_msg => "skipping AS '" . $mapped_value->{bgpPeerRemoteAs} . "': no matching filter.", debug => 1); + $self->{output}->output_add( + long_msg => "skipping AS '" . $mapped_value->{bgpPeerRemoteAs} . "': no matching filter.", + debug => 1 + ); next; } - $self->{peers}->{$instance} = { adminstate => $mapped_value->{bgpPeerAdminStatus}, local => $local_addr, - peerstate => $mapped_value->{bgpPeerState}, remote => $remote_addr, - seconds => $mapped_value->{bgpPeerInUpdateElpasedTime}, as => $mapped_value->{bgpPeerRemoteAs}, - display => $instance }; + $self->{peers}->{$instance} = { + adminstate => $mapped_value->{bgpPeerAdminStatus}, + local => $local_addr, + peerstate => $mapped_value->{bgpPeerState}, + remote => $remote_addr, + seconds => $mapped_value->{bgpPeerInUpdateElpasedTime}, + as => $mapped_value->{bgpPeerRemoteAs}, + display => $instance + }; } if (scalar(keys %{$self->{peers}}) <= 0) { - $self->{output}->add_option_msg(short_msg => 'No peers detected, check your filter ? '); + $self->{output}->add_option_msg(short_msg => 'No peers found'); $self->{output}->option_exit(); } } @@ -178,7 +193,7 @@ __END__ =head1 MODE -Check BGP basic infos (BGP4-MIB.mib and rfc4273) +Check BGP peer state (BGP4-MIB.mib and rfc4273) =over 8 @@ -200,12 +215,17 @@ Critical threshold on last update (seconds) =item B<--warning-status> -Specify admin and peer state that trigger a warning. Can use %{adminstate} and %{peerstate} -e.g --warning-status "%{adminstate} =~ /stop" +Specify admin and peer state that trigger a warning. +Can use special variables like %{adminstate}, %{peerstate}, +%{local}, %{remote}, %{as}, %{display} +(Default: '') =item B<--critical-status> -Specify admin and peer state that trigger a critical. Can use %{adminstate} and %{peerstate} +Specify admin and peer state that trigger a critical. +Can use special variables like %{adminstate}, %{peerstate}, +%{local}, %{remote}, %{as}, %{display} +(Default: '%{adminstate} =~ /start/ && %{peerstate} !~ /established/') =back diff --git a/centreon-plugins/apps/protocols/dhcp/mode/connection.pm b/centreon-plugins/apps/protocols/dhcp/mode/connection.pm index 8c278dfc1..30c84eef9 100644 --- a/centreon-plugins/apps/protocols/dhcp/mode/connection.pm +++ b/centreon-plugins/apps/protocols/dhcp/mode/connection.pm @@ -35,7 +35,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "serverip:s@" => { name => 'serverip' }, diff --git a/centreon-plugins/apps/protocols/dns/mode/request.pm b/centreon-plugins/apps/protocols/dns/mode/request.pm index 87b1bd2b8..8e737afb6 100644 --- a/centreon-plugins/apps/protocols/dns/mode/request.pm +++ b/centreon-plugins/apps/protocols/dns/mode/request.pm @@ -34,7 +34,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "nameservers:s@" => { name => 'nameservers' }, diff --git a/centreon-plugins/apps/protocols/ftp/mode/commands.pm b/centreon-plugins/apps/protocols/ftp/mode/commands.pm index f6f851508..0ee70df7d 100644 --- a/centreon-plugins/apps/protocols/ftp/mode/commands.pm +++ b/centreon-plugins/apps/protocols/ftp/mode/commands.pm @@ -46,7 +46,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/ftp/mode/date.pm b/centreon-plugins/apps/protocols/ftp/mode/date.pm index 30b455b1c..f0b2fe0da 100644 --- a/centreon-plugins/apps/protocols/ftp/mode/date.pm +++ b/centreon-plugins/apps/protocols/ftp/mode/date.pm @@ -38,7 +38,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/ftp/mode/filescount.pm b/centreon-plugins/apps/protocols/ftp/mode/filescount.pm index 05e1048e9..d9daf34a0 100644 --- a/centreon-plugins/apps/protocols/ftp/mode/filescount.pm +++ b/centreon-plugins/apps/protocols/ftp/mode/filescount.pm @@ -37,7 +37,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/ftp/mode/login.pm b/centreon-plugins/apps/protocols/ftp/mode/login.pm index 6c9895b88..66dda17f1 100644 --- a/centreon-plugins/apps/protocols/ftp/mode/login.pm +++ b/centreon-plugins/apps/protocols/ftp/mode/login.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm b/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm index 91a0f7431..9504883a6 100644 --- a/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/expectedcontent.pm @@ -107,7 +107,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.2'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm b/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm index 4322b69ec..c86c626e1 100644 --- a/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm @@ -34,7 +34,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.2'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "vhost:s" => { name => 'vhost' }, diff --git a/centreon-plugins/apps/protocols/http/mode/response.pm b/centreon-plugins/apps/protocols/http/mode/response.pm index 8d7b8fb03..7575925a2 100644 --- a/centreon-plugins/apps/protocols/http/mode/response.pm +++ b/centreon-plugins/apps/protocols/http/mode/response.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm index 0faf14460..17ce2a675 100644 --- a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm @@ -33,42 +33,41 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.2'; $options{options}->add_options(arguments => { - "service-soap:s" => { name => 'service_soap' }, - "data:s" => { name => 'data' }, - "lookup:s@" => { name => 'lookup' }, - "hostname:s" => { name => 'hostname' }, - "vhost:s" => { name => 'vhost' }, - "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto' }, - "urlpath:s" => { name => 'url_path' }, - "credentials" => { name => 'credentials' }, - "basic" => { name => 'basic' }, - "ntlmv2" => { name => 'ntlmv2' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "header:s@" => { name => 'header' }, - "timeout:s" => { name => 'timeout', default => 10 }, - "cert-file:s" => { name => 'cert_file' }, - "key-file:s" => { name => 'key_file' }, - "cacert-file:s" => { name => 'cacert_file' }, - "cert-pwd:s" => { name => 'cert_pwd' }, - "cert-pkcs12" => { name => 'cert_pkcs12' }, - "unknown-status:s" => { name => 'unknown_status' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status' }, - "warning-numeric:s" => { name => 'warning_numeric' }, - "critical-numeric:s" => { name => 'critical_numeric' }, - "warning-string:s" => { name => 'warning_string' }, - "critical-string:s" => { name => 'critical_string' }, - "warning-time:s" => { name => 'warning_time' }, - "critical-time:s" => { name => 'critical_time' }, - "threshold-value:s" => { name => 'threshold_value', default => 'count' }, - "format-ok:s" => { name => 'format_ok', default => '%{count} element(s) found' }, - "format-warning:s" => { name => 'format_warning', default => '%{count} element(s) found' }, - "format-critical:s" => { name => 'format_critical', default => '%{count} element(s) found' }, - "values-separator:s" => { name => 'values_separator', default => ', ' }, + 'service-soap:s' => { name => 'service_soap' }, + 'data:s' => { name => 'data' }, + 'lookup:s@' => { name => 'lookup' }, + 'hostname:s' => { name => 'hostname' }, + 'vhost:s' => { name => 'vhost' }, + 'port:s' => { name => 'port', }, + 'proto:s' => { name => 'proto' }, + 'urlpath:s' => { name => 'url_path' }, + 'credentials' => { name => 'credentials' }, + 'basic' => { name => 'basic' }, + 'ntlmv2' => { name => 'ntlmv2' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'header:s@' => { name => 'header' }, + 'timeout:s' => { name => 'timeout', default => 10 }, + 'cert-file:s' => { name => 'cert_file' }, + 'key-file:s' => { name => 'key_file' }, + 'cacert-file:s' => { name => 'cacert_file' }, + 'cert-pwd:s' => { name => 'cert_pwd' }, + 'cert-pkcs12' => { name => 'cert_pkcs12' }, + 'unknown-status:s' => { name => 'unknown_status' }, + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status' }, + 'warning-numeric:s' => { name => 'warning_numeric' }, + 'critical-numeric:s' => { name => 'critical_numeric' }, + 'warning-string:s' => { name => 'warning_string' }, + 'critical-string:s' => { name => 'critical_string' }, + 'warning-time:s' => { name => 'warning_time' }, + 'critical-time:s' => { name => 'critical_time' }, + 'threshold-value:s' => { name => 'threshold_value', default => 'count' }, + 'format-ok:s' => { name => 'format_ok', default => '%{count} element(s) found' }, + 'format-warning:s' => { name => 'format_warning', default => '%{count} element(s) found' }, + 'format-critical:s' => { name => 'format_critical', default => '%{count} element(s) found' }, + 'values-separator:s' => { name => 'values_separator', default => ', ' }, }); $self->{count} = 0; $self->{count_ok} = 0; @@ -217,11 +216,13 @@ sub lookup { $self->{'count_' . $exit}++; } - $self->{output}->perfdata_add(label => 'count', - value => $self->{count}, - warning => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-numeric') : undef, - critical => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef, - min => 0); + $self->{output}->perfdata_add( + label => 'count', + value => $self->{count}, + warning => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-numeric') : undef, + critical => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef, + min => 0 + ); my $count = 0; foreach my $value (@{$self->{values}}) { @@ -233,10 +234,12 @@ sub lookup { push @{$self->{'values_' . $exit}}, $value; $self->{'count_' . $exit}++ } - $self->{output}->perfdata_add(label => 'element_' . $count, - value => $value, - warning => $self->{option_results}->{threshold_value} eq 'values' ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-numeric') : undef, - critical => $self->{option_results}->{threshold_value} eq 'values' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef); + $self->{output}->perfdata_add( + label => 'element_' . $count, + value => $value, + warning => $self->{option_results}->{threshold_value} eq 'values' ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-numeric') : undef, + critical => $self->{option_results}->{threshold_value} eq 'values' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef + ); } else { if (defined($self->{option_results}->{critical_string}) && $self->{option_results}->{critical_string} ne '' && $value =~ /$self->{option_results}->{critical_string}/) { @@ -263,7 +266,10 @@ sub run { my $timeelapsed = tv_interval ($timing0, [gettimeofday]); $self->{output}->output_add(long_msg => $self->{soap_response}, debug => 1); - if (!defined($self->{option_results}->{lookup}) || scalar(@{$self->{option_results}->{lookup}}) == 0) { + if (!defined($self->{option_results}->{lookup}) || + scalar(@{$self->{option_results}->{lookup}}) == 0 || + $self->{option_results}->{lookup}->[0] eq '' + ) { $self->{output}->output_add(severity => 'OK', short_msg => "SOAP request success"); } else { @@ -278,11 +284,13 @@ sub run { } else { $self->{output}->output_add(long_msg => sprintf("Response time %.3fs", $timeelapsed)); } - $self->{output}->perfdata_add(label => "time", unit => 's', - value => sprintf('%.3f', $timeelapsed), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-time'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-time'), - min => 0); + $self->{output}->perfdata_add( + label => "time", unit => 's', + value => sprintf('%.3f', $timeelapsed), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-time'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-time'), + min => 0 + ); $self->{output}->display(); $self->{output}->exit(); diff --git a/centreon-plugins/apps/protocols/imap/mode/login.pm b/centreon-plugins/apps/protocols/imap/mode/login.pm index 7d60912f6..54caa9385 100644 --- a/centreon-plugins/apps/protocols/imap/mode/login.pm +++ b/centreon-plugins/apps/protocols/imap/mode/login.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/imap/mode/searchmessage.pm b/centreon-plugins/apps/protocols/imap/mode/searchmessage.pm index 0641cf440..d324368a0 100644 --- a/centreon-plugins/apps/protocols/imap/mode/searchmessage.pm +++ b/centreon-plugins/apps/protocols/imap/mode/searchmessage.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/jmx/mode/listattributes.pm b/centreon-plugins/apps/protocols/jmx/mode/listattributes.pm index 23c09740d..0715612a2 100644 --- a/centreon-plugins/apps/protocols/jmx/mode/listattributes.pm +++ b/centreon-plugins/apps/protocols/jmx/mode/listattributes.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "max-depth:s" => { name => 'max_depth', default => 6 }, diff --git a/centreon-plugins/apps/protocols/jmx/mode/numericvalue.pm b/centreon-plugins/apps/protocols/jmx/mode/numericvalue.pm index dc5d82b96..2efcf083c 100644 --- a/centreon-plugins/apps/protocols/jmx/mode/numericvalue.pm +++ b/centreon-plugins/apps/protocols/jmx/mode/numericvalue.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "mbean-pattern:s" => { name => 'mbean_pattern' }, diff --git a/centreon-plugins/apps/protocols/ldap/mode/login.pm b/centreon-plugins/apps/protocols/ldap/mode/login.pm index 74c7d3eff..c1eb3561b 100644 --- a/centreon-plugins/apps/protocols/ldap/mode/login.pm +++ b/centreon-plugins/apps/protocols/ldap/mode/login.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'hostname:s' => { name => 'hostname' }, 'ldap-connect-options:s@' => { name => 'ldap_connect_options' }, diff --git a/centreon-plugins/apps/protocols/ldap/mode/search.pm b/centreon-plugins/apps/protocols/ldap/mode/search.pm index 5a8bad0e1..d3c6ad614 100644 --- a/centreon-plugins/apps/protocols/ldap/mode/search.pm +++ b/centreon-plugins/apps/protocols/ldap/mode/search.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'hostname:s' => { name => 'hostname' }, 'search-base:s' => { name => 'search_base' }, diff --git a/centreon-plugins/apps/protocols/modbus/mode/numericvalue.pm b/centreon-plugins/apps/protocols/modbus/mode/numericvalue.pm index f3d3ac8aa..17a34d0d4 100644 --- a/centreon-plugins/apps/protocols/modbus/mode/numericvalue.pm +++ b/centreon-plugins/apps/protocols/modbus/mode/numericvalue.pm @@ -165,7 +165,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "config:s" => { name => 'config' }, diff --git a/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm b/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm index ff1ef4475..e66500807 100644 --- a/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm +++ b/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm @@ -28,6 +28,8 @@ use centreon::plugins::http; use URI::Encode; use JSON::XS; +my %errors_num = (0 => 'OK', 1 => 'WARNING', 2 => 'CRITICAL', 3 => 'UNKNOWN'); + sub new { my ($class, %options) = @_; my $self = {}; @@ -52,6 +54,7 @@ sub new { "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "legacy-password:s" => { name => 'legacy_password' }, + "new-api" => { name => 'new_api' }, "timeout:s" => { name => 'timeout' }, }); } @@ -96,8 +99,6 @@ sub check_options { $self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef; $self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef; $self->{legacy_password} = (defined($self->{option_results}->{legacy_password})) ? $self->{option_results}->{legacy_password} : undef; - $self->{credentials} = (defined($self->{option_results}->{credentials})) ? 1 : undef; - $self->{basic} = (defined($self->{option_results}->{basic})) ? 1 : undef; if (!defined($self->{hostname}) || $self->{hostname} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); @@ -117,6 +118,13 @@ sub build_options_for_httplib { $self->{option_results}->{warning_status} = ''; $self->{option_results}->{critical_status} = ''; $self->{option_results}->{unknown_status} = '%{http_code} < 200 or %{http_code} >= 300'; + + if (defined($self->{username})) { + $self->{option_results}->{username} = $self->{username}; + $self->{option_results}->{password} = $self->{password}; + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + } } sub settings { @@ -129,79 +137,50 @@ sub settings { $self->{http}->set_options(%{$self->{option_results}}); } -# Two kind of outputs. -# 1- -# { -# "header": { -# "source_id": "" -# }, -# "payload": [{ -# "command": "check_centreon_plugins", -# "lines": [{ -# "message": "OK: Reboot Pending : False | 'value1'=10;;;; 'value2'=10;;;;\r\nlong1\r\nlong2" -# }], -# "result": "OK" -# }] -# } -# 2- Can be also "int_value". -# { -# "header": { -# "source_id": "" -# }, -# "payload": [{ -# "command": "check_drivesize", -# "lines": [{ -# "message": "OK All 1 drive(s) are ok", -# "perf": [{ -# "alias": "C", -# "float_value": { -# "critical": 44.690621566027403, -# "maximum": 49.656246185302734, -# "minimum": 0.00000000000000000, -# "unit": "GB", -# "value": 21.684593200683594, -# "warning": 39.724996947683394 -# } -# }, -# { -# "alias": "C", -# "float_value": { -# "critical": 90.000000000000000, -# "maximum": 100.00000000000000, -# "minimum": 0.00000000000000000, -# "unit": "%", -# "value": 44.000000000000000, -# "warning": 80.000000000000000 -# } -# } -# ] -# }], -# "result": "OK" -# }] -# } - sub output_perf { my ($self, %options) = @_; + my $result = 'UNKNOWN'; + $result = $errors_num{$options{result}} if ($options{result} =~ /[0-3]/); + $result = $options{result}if ($options{result} =~ /\w+/); + my %result = ( - code => $options{result}, + code => $result, message => $options{data}->{message} ); - foreach (@{$options{data}->{perf}}) { - my $perf = defined($_->{float_value}) ? $_->{float_value} : $_->{int_value}; - my $printf_format = '%d'; - $printf_format = '%.3f' if (defined($_->{float_value})); - - push @{$result{perf}}, { - label => $_->{alias}, - unit => $perf->{unit}, - value => sprintf($printf_format, $perf->{value}), - warning => defined($perf->{warning}) ? sprintf($printf_format, $perf->{warning}) : undef, - critical => defined($perf->{critical}) ? sprintf($printf_format, $perf->{critical}) : undef, - min => defined($perf->{minimum}) ? sprintf($printf_format, $perf->{minimum}) : undef, - max => defined($perf->{maximum}) ? sprintf($printf_format, $perf->{maximum}) : undef, - }; + if (defined($self->{option_results}->{new_api})) { + foreach (keys %{$options{data}->{perf}}) { + my $printf_format = '%d'; + ($options{data}->{perf}->{$_}->{value} =~ /\.(\d\d\d)/); + $printf_format = '%.3f' if ($options{data}->{perf}->{$_}->{value} =~ /\.(\d\d\d)/ && $1 !~ /000/); + + push @{$result{perf}}, { + label => $_, + unit => $options{data}->{perf}->{$_}->{unit}, + value => sprintf($printf_format, $options{data}->{perf}->{$_}->{value}), + warning => defined($options{data}->{perf}->{$_}->{warning}) ? sprintf($printf_format, $options{data}->{perf}->{$_}->{warning}) : undef, + critical => defined($options{data}->{perf}->{$_}->{critical}) ? sprintf($printf_format, $options{data}->{perf}->{$_}->{critical}) : undef, + min => defined($options{data}->{perf}->{$_}->{minimum}) ? sprintf($printf_format, $options{data}->{perf}->{$_}->{minimum}) : undef, + max => defined($options{data}->{perf}->{$_}->{maximum}) ? sprintf($printf_format, $options{data}->{perf}->{$_}->{maximum}) : undef, + }; + } + } else { + foreach (@{$options{data}->{perf}}) { + my $perf = defined($_->{float_value}) ? $_->{float_value} : $_->{int_value}; + my $printf_format = '%d'; + $printf_format = '%.3f' if (defined($_->{float_value})); + + push @{$result{perf}}, { + label => $_->{alias}, + unit => $perf->{unit}, + value => sprintf($printf_format, $perf->{value}), + warning => defined($perf->{warning}) ? sprintf($printf_format, $perf->{warning}) : undef, + critical => defined($perf->{critical}) ? sprintf($printf_format, $perf->{critical}) : undef, + min => defined($perf->{minimum}) ? sprintf($printf_format, $perf->{minimum}) : undef, + max => defined($perf->{maximum}) ? sprintf($printf_format, $perf->{maximum}) : undef, + }; + } } return \%result; } @@ -230,7 +209,12 @@ sub format_result { $self->{output}->option_exit(); } - my $entry = $decoded->{payload}->[0]; + my $entry; + if (defined($self->{option_results}->{new_api})) { + $entry = $decoded; + } else { + $entry = $decoded->{payload}->[0]; + } $entry->{lines}->[0]->{message} =~ s/\r//msg; if (defined($entry->{lines}->[0]->{perf})) { return $self->output_perf(result => $entry->{result}, data => $entry->{lines}->[0]); @@ -244,6 +228,7 @@ sub request { $self->settings(); + my $url = ''; my $uri = URI::Encode->new({encode_reserved => 1}); my ($encoded_args, $append) = ('', ''); if (defined($options{arg})) { @@ -253,7 +238,12 @@ sub request { } } - my ($content) = $self->{http}->request(url_path => '/query/' . $options{command} . '?' . $encoded_args); + if (defined($self->{option_results}->{new_api})) { + $url = '/api/v1/queries/' . $options{command} . '/commands/execute?' . $encoded_args + } else { + $url = '/query/' . $options{command} . '?' . $encoded_args + } + my ($content) = $self->{http}->request(url_path => $url); if (!defined($content) || $content eq '') { $self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); $self->{output}->option_exit(); @@ -291,30 +281,22 @@ Port used (Default: 8443) Specify https if needed (Default: 'https') -=item B<--credentials> - -Specify this option if you access webpage with authentication - =item B<--username> -Specify username for authentication (Mandatory if --credentials is specified) +Specify username for authentication (If basic authentication) =item B<--password> -Specify password for authentication (Mandatory if --credentials is specified) - -=item B<--basic> - -Specify this option if you access webpage over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your webserver. - -Specify this option if you access webpage over hidden basic authentication or you'll get a '404 NOT FOUND' error. - -(Use with --credentials) +Specify password for authentication (If basic authentication) =item B<--legacy-password> Specify password for old authentication system. +=item B<--new-api> + +Use new RestAPI (> 5.2.33). + =item B<--timeout> Set timeout in seconds (Default: 10). diff --git a/centreon-plugins/apps/protocols/nrpe/mode/query.pm b/centreon-plugins/apps/protocols/nrpe/mode/query.pm index fa862d99d..5fa8ea078 100644 --- a/centreon-plugins/apps/protocols/nrpe/mode/query.pm +++ b/centreon-plugins/apps/protocols/nrpe/mode/query.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "command:s" => { name => 'command' }, "arg:s@" => { name => 'arg' }, diff --git a/centreon-plugins/apps/protocols/ntp/mode/offset.pm b/centreon-plugins/apps/protocols/ntp/mode/offset.pm index e1e32151b..5bbb9903b 100644 --- a/centreon-plugins/apps/protocols/ntp/mode/offset.pm +++ b/centreon-plugins/apps/protocols/ntp/mode/offset.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "ntp-host:s" => { name => 'ntp_host' }, diff --git a/centreon-plugins/apps/protocols/ntp/mode/responsetime.pm b/centreon-plugins/apps/protocols/ntp/mode/responsetime.pm index af38c5e4e..d306c5fe3 100644 --- a/centreon-plugins/apps/protocols/ntp/mode/responsetime.pm +++ b/centreon-plugins/apps/protocols/ntp/mode/responsetime.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/ospf/snmp/mode/neighbor.pm b/centreon-plugins/apps/protocols/ospf/snmp/mode/neighbor.pm index 42a12c912..2f68663a3 100644 --- a/centreon-plugins/apps/protocols/ospf/snmp/mode/neighbor.pm +++ b/centreon-plugins/apps/protocols/ospf/snmp/mode/neighbor.pm @@ -102,7 +102,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/apps/protocols/radius/mode/login.pm b/centreon-plugins/apps/protocols/radius/mode/login.pm index 645e8663c..c9bb47282 100644 --- a/centreon-plugins/apps/protocols/radius/mode/login.pm +++ b/centreon-plugins/apps/protocols/radius/mode/login.pm @@ -78,7 +78,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/smtp/mode/login.pm b/centreon-plugins/apps/protocols/smtp/mode/login.pm index 34fa417de..eeb25ae83 100644 --- a/centreon-plugins/apps/protocols/smtp/mode/login.pm +++ b/centreon-plugins/apps/protocols/smtp/mode/login.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/smtp/mode/message.pm b/centreon-plugins/apps/protocols/smtp/mode/message.pm index db8e520a1..b9cf74491 100644 --- a/centreon-plugins/apps/protocols/smtp/mode/message.pm +++ b/centreon-plugins/apps/protocols/smtp/mode/message.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm b/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm index 95fad6ac8..c5cac08f1 100644 --- a/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm +++ b/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm @@ -78,7 +78,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout' }, "packets:s" => { name => 'packets' }, diff --git a/centreon-plugins/apps/protocols/ssh/mode/login.pm b/centreon-plugins/apps/protocols/ssh/mode/login.pm index b0a6bb86e..1de5f825f 100644 --- a/centreon-plugins/apps/protocols/ssh/mode/login.pm +++ b/centreon-plugins/apps/protocols/ssh/mode/login.pm @@ -73,7 +73,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/apps/protocols/tcp/mode/responsetime.pm b/centreon-plugins/apps/protocols/tcp/mode/responsetime.pm index a55a7cadc..26a0f993a 100644 --- a/centreon-plugins/apps/protocols/tcp/mode/responsetime.pm +++ b/centreon-plugins/apps/protocols/tcp/mode/responsetime.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/telnet/mode/scenario.pm b/centreon-plugins/apps/protocols/telnet/mode/scenario.pm index 966faa363..ca1c75a3f 100644 --- a/centreon-plugins/apps/protocols/telnet/mode/scenario.pm +++ b/centreon-plugins/apps/protocols/telnet/mode/scenario.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "scenario:s" => { name => 'scenario' }, "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/apps/protocols/tftp/mode/commands.pm b/centreon-plugins/apps/protocols/tftp/mode/commands.pm index c2618a0d5..034576e62 100644 --- a/centreon-plugins/apps/protocols/tftp/mode/commands.pm +++ b/centreon-plugins/apps/protocols/tftp/mode/commands.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => 69 }, diff --git a/centreon-plugins/apps/protocols/udp/mode/connection.pm b/centreon-plugins/apps/protocols/udp/mode/connection.pm index 75299020f..84d41d873 100644 --- a/centreon-plugins/apps/protocols/udp/mode/connection.pm +++ b/centreon-plugins/apps/protocols/udp/mode/connection.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/x509/mode/certificate.pm b/centreon-plugins/apps/protocols/x509/mode/certificate.pm index 09b5ab04f..ea8f0f07e 100644 --- a/centreon-plugins/apps/protocols/x509/mode/certificate.pm +++ b/centreon-plugins/apps/protocols/x509/mode/certificate.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/protocols/x509/mode/validity.pm b/centreon-plugins/apps/protocols/x509/mode/validity.pm index e45e5f01c..d4b88772d 100644 --- a/centreon-plugins/apps/protocols/x509/mode/validity.pm +++ b/centreon-plugins/apps/protocols/x509/mode/validity.pm @@ -34,7 +34,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.4'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/apps/proxmox/ve/restapi/custom/api.pm b/centreon-plugins/apps/proxmox/ve/restapi/custom/api.pm index 055452e4c..273533390 100644 --- a/centreon-plugins/apps/proxmox/ve/restapi/custom/api.pm +++ b/centreon-plugins/apps/proxmox/ve/restapi/custom/api.pm @@ -45,15 +45,14 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port'}, - "proto:s" => { name => 'proto' }, - "api-username:s" => { name => 'api_username' }, - "api-password:s" => { name => 'api_password' }, - "realm:s" => { name => 'realm' }, - "timeout:s" => { name => 'timeout' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "reload-cache-time:s" => { name => 'reload_cache_time', default => 7200 }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port'}, + 'proto:s' => { name => 'proto' }, + 'api-username:s' => { name => 'api_username' }, + 'api-password:s' => { name => 'api_password' }, + 'realm:s' => { name => 'realm' }, + 'timeout:s' => { name => 'timeout' }, + 'reload-cache-time:s' => { name => 'reload_cache_time', default => 7200 }, }); } @@ -96,7 +95,6 @@ sub check_options { $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 8006; $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; - $self->{ssl_opt} = (defined($self->{option_results}->{ssl_opt})) ? $self->{option_results}->{ssl_opt} : undef; $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : undef; $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : undef; $self->{realm} = (defined($self->{option_results}->{realm})) ? $self->{option_results}->{realm} : 'pam'; @@ -137,11 +135,10 @@ sub build_options_for_httplib { $self->{option_results}->{hostname} = $self->{hostname}; $self->{option_results}->{port} = $self->{port}; $self->{option_results}->{proto} = $self->{proto}; - $self->{option_results}->{ssl_opt} = $self->{ssl_opt}; $self->{option_results}->{timeout} = $self->{timeout}; $self->{option_results}->{warning_status} = ''; $self->{option_results}->{critical_status} = ''; - $self->{option_results}->{unknown_status} = ''; + $self->{option_results}->{unknown_status} = '%{http_code} < 200 or %{http_code} >= 300'; } sub settings { diff --git a/centreon-plugins/apps/proxmox/ve/restapi/mode/listnodes.pm b/centreon-plugins/apps/proxmox/ve/restapi/mode/listnodes.pm index 7ea6e1348..7b57a7f2c 100644 --- a/centreon-plugins/apps/proxmox/ve/restapi/mode/listnodes.pm +++ b/centreon-plugins/apps/proxmox/ve/restapi/mode/listnodes.pm @@ -30,10 +30,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); + return $self; } diff --git a/centreon-plugins/apps/proxmox/ve/restapi/mode/liststorages.pm b/centreon-plugins/apps/proxmox/ve/restapi/mode/liststorages.pm index 515044c63..b4bf391e5 100644 --- a/centreon-plugins/apps/proxmox/ve/restapi/mode/liststorages.pm +++ b/centreon-plugins/apps/proxmox/ve/restapi/mode/liststorages.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/proxmox/ve/restapi/mode/listvms.pm b/centreon-plugins/apps/proxmox/ve/restapi/mode/listvms.pm index 5df2bd240..cef3d7456 100644 --- a/centreon-plugins/apps/proxmox/ve/restapi/mode/listvms.pm +++ b/centreon-plugins/apps/proxmox/ve/restapi/mode/listvms.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/proxmox/ve/restapi/mode/nodeusage.pm b/centreon-plugins/apps/proxmox/ve/restapi/mode/nodeusage.pm index 7c07ed031..3ac512ecf 100644 --- a/centreon-plugins/apps/proxmox/ve/restapi/mode/nodeusage.pm +++ b/centreon-plugins/apps/proxmox/ve/restapi/mode/nodeusage.pm @@ -254,16 +254,14 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "node-id:s" => { name => 'node_id' }, - "node-name:s" => { name => 'node_name' }, - "filter-name:s" => { name => 'filter_name' }, - "use-name" => { name => 'use_name' }, - "warning-node-status:s" => { name => 'warning_node_status', default => '' }, - "critical-node-status:s" => { name => 'critical_node_status', default => '' }, - }); + $options{options}->add_options(arguments => { + 'node-id:s' => { name => 'node_id' }, + 'node-name:s' => { name => 'node_name' }, + 'filter-name:s' => { name => 'filter_name' }, + 'use-name' => { name => 'use_name' }, + 'warning-node-status:s' => { name => 'warning_node_status', default => '' }, + 'critical-node-status:s' => { name => 'critical_node_status', default => '' }, + }); $self->{statefile_cache_nodes} = centreon::plugins::statefile->new(%options); return $self; diff --git a/centreon-plugins/apps/proxmox/ve/restapi/mode/storageusage.pm b/centreon-plugins/apps/proxmox/ve/restapi/mode/storageusage.pm index b8fdf7a4c..37a0ca502 100644 --- a/centreon-plugins/apps/proxmox/ve/restapi/mode/storageusage.pm +++ b/centreon-plugins/apps/proxmox/ve/restapi/mode/storageusage.pm @@ -123,7 +123,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "storage-id:s" => { name => 'storage_id' }, diff --git a/centreon-plugins/apps/proxmox/ve/restapi/mode/version.pm b/centreon-plugins/apps/proxmox/ve/restapi/mode/version.pm index 88d024ddd..750f30a81 100644 --- a/centreon-plugins/apps/proxmox/ve/restapi/mode/version.pm +++ b/centreon-plugins/apps/proxmox/ve/restapi/mode/version.pm @@ -30,10 +30,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); + return $self; } diff --git a/centreon-plugins/apps/proxmox/ve/restapi/mode/vmusage.pm b/centreon-plugins/apps/proxmox/ve/restapi/mode/vmusage.pm index 1568d748d..d5c6ed61e 100644 --- a/centreon-plugins/apps/proxmox/ve/restapi/mode/vmusage.pm +++ b/centreon-plugins/apps/proxmox/ve/restapi/mode/vmusage.pm @@ -242,18 +242,16 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "vm-id:s" => { name => 'vm_id' }, - "vm-name:s" => { name => 'vm_name' }, - "filter-name:s" => { name => 'filter_name' }, - "use-name" => { name => 'use_name' }, - "warning-vm-status:s" => { name => 'warning_vm_status', default => '' }, - "critical-vm-status:s" => { name => 'critical_vm_status', default => '' }, - }); - $self->{statefile_cache_vms} = centreon::plugins::statefile->new(%options); - return $self; + $options{options}->add_options(arguments => { + 'vm-id:s' => { name => 'vm_id' }, + 'vm-name:s' => { name => 'vm_name' }, + 'filter-name:s' => { name => 'filter_name' }, + 'use-name' => { name => 'use_name' }, + 'warning-vm-status:s' => { name => 'warning_vm_status', default => '' }, + 'critical-vm-status:s' => { name => 'critical_vm_status', default => '' }, + }); + $self->{statefile_cache_vms} = centreon::plugins::statefile->new(%options); + return $self; } sub check_options { diff --git a/centreon-plugins/apps/pvx/restapi/mode/httphits.pm b/centreon-plugins/apps/pvx/restapi/mode/httphits.pm index 56d687d61..f73bbe97c 100644 --- a/centreon-plugins/apps/pvx/restapi/mode/httphits.pm +++ b/centreon-plugins/apps/pvx/restapi/mode/httphits.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s" => { name => 'instance', default => 'layer' }, diff --git a/centreon-plugins/apps/pvx/restapi/mode/networkconnection.pm b/centreon-plugins/apps/pvx/restapi/mode/networkconnection.pm index 4989b4f20..fb891267c 100644 --- a/centreon-plugins/apps/pvx/restapi/mode/networkconnection.pm +++ b/centreon-plugins/apps/pvx/restapi/mode/networkconnection.pm @@ -83,7 +83,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s" => { name => 'instance', default => 'layer' }, diff --git a/centreon-plugins/apps/pvx/restapi/mode/networktraffic.pm b/centreon-plugins/apps/pvx/restapi/mode/networktraffic.pm index aec394da6..83fc52ae7 100644 --- a/centreon-plugins/apps/pvx/restapi/mode/networktraffic.pm +++ b/centreon-plugins/apps/pvx/restapi/mode/networktraffic.pm @@ -117,7 +117,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s" => { name => 'instance', default => 'layer' }, diff --git a/centreon-plugins/apps/pvx/restapi/mode/networkuserexperience.pm b/centreon-plugins/apps/pvx/restapi/mode/networkuserexperience.pm index ca1e6a75c..303d0855f 100644 --- a/centreon-plugins/apps/pvx/restapi/mode/networkuserexperience.pm +++ b/centreon-plugins/apps/pvx/restapi/mode/networkuserexperience.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s" => { name => 'instance', default => 'layer' }, diff --git a/centreon-plugins/apps/redis/cli/mode/clients.pm b/centreon-plugins/apps/redis/cli/mode/clients.pm index 777ce20c1..53c24de25 100644 --- a/centreon-plugins/apps/redis/cli/mode/clients.pm +++ b/centreon-plugins/apps/redis/cli/mode/clients.pm @@ -73,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { diff --git a/centreon-plugins/apps/redis/cli/mode/commands.pm b/centreon-plugins/apps/redis/cli/mode/commands.pm index 5e29b3759..238ab86fe 100644 --- a/centreon-plugins/apps/redis/cli/mode/commands.pm +++ b/centreon-plugins/apps/redis/cli/mode/commands.pm @@ -64,7 +64,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { diff --git a/centreon-plugins/apps/redis/cli/mode/connections.pm b/centreon-plugins/apps/redis/cli/mode/connections.pm index 76f6d3d9e..0ebf3f48d 100644 --- a/centreon-plugins/apps/redis/cli/mode/connections.pm +++ b/centreon-plugins/apps/redis/cli/mode/connections.pm @@ -92,7 +92,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { diff --git a/centreon-plugins/apps/redis/cli/mode/cpu.pm b/centreon-plugins/apps/redis/cli/mode/cpu.pm index c0a829dfc..c748f5fe8 100644 --- a/centreon-plugins/apps/redis/cli/mode/cpu.pm +++ b/centreon-plugins/apps/redis/cli/mode/cpu.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { diff --git a/centreon-plugins/apps/redis/cli/mode/memory.pm b/centreon-plugins/apps/redis/cli/mode/memory.pm index 5c7f2a472..74683a491 100644 --- a/centreon-plugins/apps/redis/cli/mode/memory.pm +++ b/centreon-plugins/apps/redis/cli/mode/memory.pm @@ -203,7 +203,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/apps/redis/cli/mode/persistence.pm b/centreon-plugins/apps/redis/cli/mode/persistence.pm index a50c853a5..70de76840 100644 --- a/centreon-plugins/apps/redis/cli/mode/persistence.pm +++ b/centreon-plugins/apps/redis/cli/mode/persistence.pm @@ -106,7 +106,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { diff --git a/centreon-plugins/apps/redis/cli/mode/replication.pm b/centreon-plugins/apps/redis/cli/mode/replication.pm index 5013d9a2c..e8a4e65bb 100644 --- a/centreon-plugins/apps/redis/cli/mode/replication.pm +++ b/centreon-plugins/apps/redis/cli/mode/replication.pm @@ -127,7 +127,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { diff --git a/centreon-plugins/apps/redis/restapi/mode/clusterstats.pm b/centreon-plugins/apps/redis/restapi/mode/clusterstats.pm index e1eb4be5c..8b2a971de 100644 --- a/centreon-plugins/apps/redis/restapi/mode/clusterstats.pm +++ b/centreon-plugins/apps/redis/restapi/mode/clusterstats.pm @@ -221,7 +221,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, diff --git a/centreon-plugins/apps/redis/restapi/mode/databasesstats.pm b/centreon-plugins/apps/redis/restapi/mode/databasesstats.pm index e8b835e93..e2cfca959 100644 --- a/centreon-plugins/apps/redis/restapi/mode/databasesstats.pm +++ b/centreon-plugins/apps/redis/restapi/mode/databasesstats.pm @@ -413,7 +413,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-database:s" => { name => 'filter_database' }, diff --git a/centreon-plugins/apps/redis/restapi/mode/listdatabases.pm b/centreon-plugins/apps/redis/restapi/mode/listdatabases.pm index c2c322e1a..c73e72db9 100644 --- a/centreon-plugins/apps/redis/restapi/mode/listdatabases.pm +++ b/centreon-plugins/apps/redis/restapi/mode/listdatabases.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/redis/restapi/mode/listnodes.pm b/centreon-plugins/apps/redis/restapi/mode/listnodes.pm index 71c3c0945..855f65504 100644 --- a/centreon-plugins/apps/redis/restapi/mode/listnodes.pm +++ b/centreon-plugins/apps/redis/restapi/mode/listnodes.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/redis/restapi/mode/listshards.pm b/centreon-plugins/apps/redis/restapi/mode/listshards.pm index fc42f88d9..985216a78 100644 --- a/centreon-plugins/apps/redis/restapi/mode/listshards.pm +++ b/centreon-plugins/apps/redis/restapi/mode/listshards.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/redis/restapi/mode/nodesstats.pm b/centreon-plugins/apps/redis/restapi/mode/nodesstats.pm index 68b88d6b0..4d4d6e79c 100644 --- a/centreon-plugins/apps/redis/restapi/mode/nodesstats.pm +++ b/centreon-plugins/apps/redis/restapi/mode/nodesstats.pm @@ -271,7 +271,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-node:s" => { name => 'filter_node' }, diff --git a/centreon-plugins/apps/redis/restapi/mode/shardsstats.pm b/centreon-plugins/apps/redis/restapi/mode/shardsstats.pm index dd31867c8..37882a256 100644 --- a/centreon-plugins/apps/redis/restapi/mode/shardsstats.pm +++ b/centreon-plugins/apps/redis/restapi/mode/shardsstats.pm @@ -296,7 +296,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-shard:s" => { name => 'filter_shard' }, diff --git a/centreon-plugins/apps/rrdcached/mode/stats.pm b/centreon-plugins/apps/rrdcached/mode/stats.pm index dbc5d9fb6..573804224 100644 --- a/centreon-plugins/apps/rrdcached/mode/stats.pm +++ b/centreon-plugins/apps/rrdcached/mode/stats.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "host:s" => { name => 'host', default => '127.0.0.1' }, diff --git a/centreon-plugins/apps/rudder/restapi/mode/discovery.pm b/centreon-plugins/apps/rudder/restapi/mode/discovery.pm index e5450abb9..d2cc47f55 100644 --- a/centreon-plugins/apps/rudder/restapi/mode/discovery.pm +++ b/centreon-plugins/apps/rudder/restapi/mode/discovery.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "prettify" => { name => 'prettify' }, }); diff --git a/centreon-plugins/apps/rudder/restapi/mode/globalcompliance.pm b/centreon-plugins/apps/rudder/restapi/mode/globalcompliance.pm index 7b788440f..d886141f7 100644 --- a/centreon-plugins/apps/rudder/restapi/mode/globalcompliance.pm +++ b/centreon-plugins/apps/rudder/restapi/mode/globalcompliance.pm @@ -95,7 +95,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/apps/rudder/restapi/mode/listnodes.pm b/centreon-plugins/apps/rudder/restapi/mode/listnodes.pm index 5954f5c36..e62337877 100644 --- a/centreon-plugins/apps/rudder/restapi/mode/listnodes.pm +++ b/centreon-plugins/apps/rudder/restapi/mode/listnodes.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/apps/rudder/restapi/mode/listrules.pm b/centreon-plugins/apps/rudder/restapi/mode/listrules.pm index c11137650..345f3e3ee 100644 --- a/centreon-plugins/apps/rudder/restapi/mode/listrules.pm +++ b/centreon-plugins/apps/rudder/restapi/mode/listrules.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/apps/rudder/restapi/mode/nodecompliance.pm b/centreon-plugins/apps/rudder/restapi/mode/nodecompliance.pm index cf670fcad..a0d25497d 100644 --- a/centreon-plugins/apps/rudder/restapi/mode/nodecompliance.pm +++ b/centreon-plugins/apps/rudder/restapi/mode/nodecompliance.pm @@ -102,7 +102,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/apps/rudder/restapi/mode/nodesoverallcompliance.pm b/centreon-plugins/apps/rudder/restapi/mode/nodesoverallcompliance.pm index d9e469c40..fbb946cdf 100644 --- a/centreon-plugins/apps/rudder/restapi/mode/nodesoverallcompliance.pm +++ b/centreon-plugins/apps/rudder/restapi/mode/nodesoverallcompliance.pm @@ -136,7 +136,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, }); diff --git a/centreon-plugins/apps/rudder/restapi/mode/rulecompliance.pm b/centreon-plugins/apps/rudder/restapi/mode/rulecompliance.pm index 6b575ad23..773e8ab58 100644 --- a/centreon-plugins/apps/rudder/restapi/mode/rulecompliance.pm +++ b/centreon-plugins/apps/rudder/restapi/mode/rulecompliance.pm @@ -102,7 +102,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/apps/rudder/restapi/mode/statistics.pm b/centreon-plugins/apps/rudder/restapi/mode/statistics.pm index 8ebd50aaf..f49e88210 100644 --- a/centreon-plugins/apps/rudder/restapi/mode/statistics.pm +++ b/centreon-plugins/apps/rudder/restapi/mode/statistics.pm @@ -95,7 +95,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/sahipro/restapi/mode/scenario.pm b/centreon-plugins/apps/sahipro/restapi/mode/scenario.pm index bbc754eab..58c6ca037 100644 --- a/centreon-plugins/apps/sahipro/restapi/mode/scenario.pm +++ b/centreon-plugins/apps/sahipro/restapi/mode/scenario.pm @@ -136,7 +136,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "sahi-hostname:s" => { name => 'sahi_hostname' }, "sahi-port:s" => { name => 'sahi_port', default => 9999 }, diff --git a/centreon-plugins/apps/sccm/local/mode/databasereplicationstatus.pm b/centreon-plugins/apps/sccm/local/mode/databasereplicationstatus.pm index 7867c1714..f3bef9bfc 100644 --- a/centreon-plugins/apps/sccm/local/mode/databasereplicationstatus.pm +++ b/centreon-plugins/apps/sccm/local/mode/databasereplicationstatus.pm @@ -144,19 +144,18 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "timeout:s" => { name => 'timeout', default => 30 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "warning-link-status:s" => { name => 'warning_link_status', default => '' }, - "critical-link-status:s" => { name => 'critical_link_status', default => '' }, - "warning-site-status:s" => { name => 'warning_site_status', default => '' }, - "critical-site-status:s" => { name => 'critical_site_status', default => '' }, - "timezone:s" => { name => 'timezone', default => 'UTC' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'warning-link-status:s' => { name => 'warning_link_status', default => '' }, + 'critical-link-status:s' => { name => 'critical_link_status', default => '' }, + 'warning-site-status:s' => { name => 'warning_site_status', default => '' }, + 'critical-site-status:s' => { name => 'critical_site_status', default => '' }, + 'timezone:s' => { name => 'timezone', default => 'UTC' }, }); return $self; @@ -178,11 +177,13 @@ sub manage_selection { ); $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { $self->{output}->output_add(severity => 'OK', short_msg => $stdout); @@ -200,7 +201,7 @@ sub manage_selection { } if (!defined($decoded->{LinkStatus})) { - $self->{output}->add_option_msg(short_msg => "No database replication"); + $self->{output}->add_option_msg(short_msg => 'No database replication'); $self->{output}->option_exit(); } $self->{global}->{LinkStatus} = $map_link_status{$decoded->{LinkStatus}}; diff --git a/centreon-plugins/apps/sccm/local/mode/sitestatus.pm b/centreon-plugins/apps/sccm/local/mode/sitestatus.pm index 81595c65b..6b7020d73 100644 --- a/centreon-plugins/apps/sccm/local/mode/sitestatus.pm +++ b/centreon-plugins/apps/sccm/local/mode/sitestatus.pm @@ -110,16 +110,15 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "timeout:s" => { name => 'timeout', default => 30 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, }); return $self; @@ -140,11 +139,13 @@ sub manage_selection { ); $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { $self->{output}->output_add(severity => 'OK', short_msg => $stdout); @@ -161,7 +162,7 @@ sub manage_selection { $self->{output}->option_exit(); } - if (ref($decoded) eq "ARRAY") { + if (ref($decoded) eq "ARRAY") { foreach my $site (@{$decoded}) { $self->{sites}->{$site->{SiteCode}} = { display => $site->{SiteCode}, @@ -172,7 +173,7 @@ sub manage_selection { SecondarySiteCMUpdateStatus => $site->{SecondarySiteCMUpdateStatus}, }; } - } else { + } else { $self->{sites}->{$decoded->{SiteCode}} = { display => $decoded->{SiteCode}, SiteName => $decoded->{SiteName}, diff --git a/centreon-plugins/apps/selenium/mode/scenario.pm b/centreon-plugins/apps/selenium/mode/scenario.pm index 48372e1b7..2160bf0e8 100644 --- a/centreon-plugins/apps/selenium/mode/scenario.pm +++ b/centreon-plugins/apps/selenium/mode/scenario.pm @@ -36,7 +36,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "selenium-hostname:s" => { name => 'selenium_hostname', default => 'localhost' }, diff --git a/centreon-plugins/apps/selenium/mode/scenariokatalon.pm b/centreon-plugins/apps/selenium/mode/scenariokatalon.pm index 400617cf8..2716fd3e0 100644 --- a/centreon-plugins/apps/selenium/mode/scenariokatalon.pm +++ b/centreon-plugins/apps/selenium/mode/scenariokatalon.pm @@ -181,7 +181,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "selenium-hostname:s" => { name => 'selenium_hostname', default => 'localhost' }, diff --git a/centreon-plugins/apps/slack/restapi/mode/countchannels.pm b/centreon-plugins/apps/slack/restapi/mode/countchannels.pm index 988adfa7c..2e7da4514 100644 --- a/centreon-plugins/apps/slack/restapi/mode/countchannels.pm +++ b/centreon-plugins/apps/slack/restapi/mode/countchannels.pm @@ -107,7 +107,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-channel:s" => { name => 'filter_channel' }, }); diff --git a/centreon-plugins/apps/slack/restapi/mode/countmembers.pm b/centreon-plugins/apps/slack/restapi/mode/countmembers.pm index 49333cc05..12dddcb45 100644 --- a/centreon-plugins/apps/slack/restapi/mode/countmembers.pm +++ b/centreon-plugins/apps/slack/restapi/mode/countmembers.pm @@ -83,7 +83,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/squid/snmp/mode/cacheusage.pm b/centreon-plugins/apps/squid/snmp/mode/cacheusage.pm index d2a435361..04ef89421 100644 --- a/centreon-plugins/apps/squid/snmp/mode/cacheusage.pm +++ b/centreon-plugins/apps/squid/snmp/mode/cacheusage.pm @@ -78,7 +78,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/squid/snmp/mode/protocolstats.pm b/centreon-plugins/apps/squid/snmp/mode/protocolstats.pm index 5a88020a2..37f3a8733 100644 --- a/centreon-plugins/apps/squid/snmp/mode/protocolstats.pm +++ b/centreon-plugins/apps/squid/snmp/mode/protocolstats.pm @@ -169,7 +169,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/tomcat/jmx/mode/connectorusage.pm b/centreon-plugins/apps/tomcat/jmx/mode/connectorusage.pm index 0d458f56f..b16d354c4 100644 --- a/centreon-plugins/apps/tomcat/jmx/mode/connectorusage.pm +++ b/centreon-plugins/apps/tomcat/jmx/mode/connectorusage.pm @@ -164,7 +164,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/apps/tomcat/jmx/mode/datasourceusage.pm b/centreon-plugins/apps/tomcat/jmx/mode/datasourceusage.pm index 46b355ac4..34461aef6 100644 --- a/centreon-plugins/apps/tomcat/jmx/mode/datasourceusage.pm +++ b/centreon-plugins/apps/tomcat/jmx/mode/datasourceusage.pm @@ -134,7 +134,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/apps/tomcat/jmx/mode/listdatasources.pm b/centreon-plugins/apps/tomcat/jmx/mode/listdatasources.pm index 7156abf45..d62e41e31 100644 --- a/centreon-plugins/apps/tomcat/jmx/mode/listdatasources.pm +++ b/centreon-plugins/apps/tomcat/jmx/mode/listdatasources.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-host:s" => { name => 'filter_host' }, diff --git a/centreon-plugins/apps/tomcat/jmx/mode/listwebapps.pm b/centreon-plugins/apps/tomcat/jmx/mode/listwebapps.pm index 3f3cf530c..83a194987 100644 --- a/centreon-plugins/apps/tomcat/jmx/mode/listwebapps.pm +++ b/centreon-plugins/apps/tomcat/jmx/mode/listwebapps.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-host:s" => { name => 'filter_host' }, diff --git a/centreon-plugins/apps/tomcat/jmx/mode/webappssessions.pm b/centreon-plugins/apps/tomcat/jmx/mode/webappssessions.pm index 790180e6a..3a30aa2ae 100644 --- a/centreon-plugins/apps/tomcat/jmx/mode/webappssessions.pm +++ b/centreon-plugins/apps/tomcat/jmx/mode/webappssessions.pm @@ -133,7 +133,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/apps/tomcat/web/mode/applications.pm b/centreon-plugins/apps/tomcat/web/mode/applications.pm index 8ede76459..eb9a3ef84 100644 --- a/centreon-plugins/apps/tomcat/web/mode/applications.pm +++ b/centreon-plugins/apps/tomcat/web/mode/applications.pm @@ -20,123 +20,123 @@ package apps::tomcat::web::mode::applications; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); + use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); use centreon::plugins::http; +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'state: ' . $self->{result_values}->{state}; + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'application', type => 1, cb_prefix_output => 'prefix_application_output', message_multiple => 'All applications are ok' } + ]; + + $self->{maps_counters}->{application} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'contextpath' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'sessions-active', nlabel => 'application.sessions.active.count', set => { + key_values => [ { name => 'sessions' }, { name => 'display' } ], + output_template => 'active sessions: %s', + perfdatas => [ + { value => 'sessions_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_application_output { + my ($self, %options) = @_; + + return "Application '" . $options{instance_value}->{display} . "' "; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto' }, - "credentials" => { name => 'credentials' }, - "basic" => { name => 'basic' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, - "urlpath:s" => { name => 'url_path', default => '/manager/text/list' }, - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - "filter-path:s" => { name => 'filter_path', }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port', default => '8080' }, + 'proto:s' => { name => 'proto' }, + 'credentials' => { name => 'credentials' }, + 'basic' => { name => 'basic' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout' }, + 'urlpath:s' => { name => 'url_path', default => '/manager/text/list' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-path:s' => { name => 'filter_path', }, + 'unknown-http-status:s' => { name => 'unknown_http_status', default => '%{http_code} < 200 or %{http_code} >= 300' }, + 'warning-http-status:s' => { name => 'warning_http_status' }, + 'critical-http-status:s' => { name => 'critical_http_status' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{state} ne "running"' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} eq "stopped"' }, }); - $self->{result} = {}; $self->{http} = centreon::plugins::http->new(%options); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); $self->{http}->set_options(%{$self->{option_results}}); + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); } sub manage_selection { my ($self, %options) = @_; - my $webcontent = $self->{http}->request(); + my $webcontent = $self->{http}->request( + unknown_status => $self->{option_results}->{unknown_http_status}, + warning_status => $self->{option_results}->{warning_http_status}, + critical_status => $self->{option_results}->{critical_http_status}, + ); + $self->{application} = {}; while ($webcontent =~ /^(.*?):(.*?):(.*?):(.*)/mg) { my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4); next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' && $contextpath !~ /$self->{option_results}->{filter_path}/); + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $context !~ /$self->{option_results}->{filter_name}/); - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) - && $context !~ /$self->{option_results}->{name}/i); - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $context !~ /$self->{option_results}->{name}/); - next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $context ne $self->{option_results}->{name}); - - $self->{result}->{$context} = {state => $state, - sessions => $sessions, - contextpath => $contextpath}; + $self->{application}->{$context} = { + display => $context, + state => $state, + sessions => $sessions, + contextpath => $contextpath + }; } - if (scalar(keys %{$self->{result}}) <= 0) { - if (defined($self->{option_results}->{name})) { - $self->{output}->add_option_msg(short_msg => "No contexts found for name '" . $self->{option_results}->{name} . "'."); - } else { - $self->{output}->add_option_msg(short_msg => "No contexts found."); - } + if (scalar(keys %{$self->{application}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No application found."); $self->{output}->option_exit(); } } -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - - if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All Contexts are ok.'); - }; - - - foreach my $name (sort(keys %{$self->{result}})) { - my $exit = 'OK'; - my $staterc = '0'; - - if ($self->{result}->{$name}->{state} eq 'stopped') { - $exit = 'CRITICAL'; - $staterc = '1'; - } elsif ($self->{result}->{$name}->{state} ne 'running') { - $exit = 'UNKNOWN'; - $staterc = '2'; - }; - - $self->{output}->output_add(long_msg => sprintf("Context '%s' : %s", $name, - $self->{result}->{$name}->{state})); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Context '%s' : %s", $name, - $self->{result}->{$name}->{state})); - } - - my $extra_label; - $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})); - $self->{output}->perfdata_add( - label => 'status', - instances => $extra_label, - value => sprintf("%.1f", $staterc), - min => 0 - ); - }; - - $self->{output}->display(); - $self->{output}->exit(); -}; - 1; __END__ @@ -189,23 +189,47 @@ Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list') Tomcat 6: '/manager/list' Tomcat 7: '/manager/text/list' -=item B<--name> +=item B<--fitler-name> -Set the Context name (empty means 'check all contexts') - -=item B<--regexp> - -Allows to use regexp to filter contexts (with option --name). - -=item B<--regexp-isensitive> - -Allows to use regexp non case-sensitive (with --regexp). +Filter context name (regexp can be used) =item B<--filter-path> Filter Context Path (regexp can be used). Can be for example: '/STORAGE/context/test1'. +=item B<--unknown-http-status> + +Threshold unknown for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300') + +=item B<--warning-http-status> + +Threshold warning for http response code + +=item B<--critical-http-status> + +Threshold critical for http response code + +=item B<--unknown-status> + +Set unknown threshold for status (Default: '%{state} ne "running"'). +Can used special variables like: %{state}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{state}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{state} eq "stopped"'). +Can used special variables like: %{state}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'sessions-active'. + =back =cut diff --git a/centreon-plugins/apps/tomcat/web/mode/traffic.pm b/centreon-plugins/apps/tomcat/web/mode/connectors.pm similarity index 58% rename from centreon-plugins/apps/tomcat/web/mode/traffic.pm rename to centreon-plugins/apps/tomcat/web/mode/connectors.pm index edeadefc8..6ae720e64 100644 --- a/centreon-plugins/apps/tomcat/web/mode/traffic.pm +++ b/centreon-plugins/apps/tomcat/web/mode/connectors.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package apps::tomcat::web::mode::traffic; +package apps::tomcat::web::mode::connectors; use base qw(centreon::plugins::templates::counter); @@ -29,69 +29,6 @@ use Digest::MD5 qw(md5_hex); use XML::XPath; use URI::Escape; -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'connector', type => 1, cb_prefix_output => 'prefix_connector_output', message_multiple => 'All connector traffics are ok' }, - ]; - - $self->{maps_counters}->{connector} = [ - { label => 'in', set => { - key_values => [ { name => 'in', diff => 1 }, { name => 'display' } ], - per_second => 1, - closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, - closure_custom_output => $self->can('custom_traffic_output'), - closure_custom_perfdata => $self->can('custom_traffic_perfdata'), - closure_custom_threshold_check => $self->can('custom_traffic_threshold'), - } - }, - { label => 'out', set => { - key_values => [ { name => 'out', diff => 1 }, { name => 'display' } ], - per_second => 1, - closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, - closure_custom_output => $self->can('custom_traffic_output'), - closure_custom_perfdata => $self->can('custom_traffic_perfdata'), - closure_custom_threshold_check => $self->can('custom_traffic_threshold'), - } - }, - ]; -} - -sub custom_traffic_perfdata { - my ($self, %options) = @_; - - my ($warning, $critical); - if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { - $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1); - $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1); - } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { - $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}); - $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}); - } - - $self->{output}->perfdata_add( - label => 'traffic_' . $self->{result_values}->{label}, unit => 'b/s', - instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, - value => sprintf("%.2f", $self->{result_values}->{traffic}), - warning => $warning, - critical => $critical, - min => 0, max => $self->{result_values}->{speed} - ); -} - -sub custom_traffic_threshold { - my ($self, %options) = @_; - - my $exit = 'ok'; - if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { - $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); - } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { - $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); - } - return $exit; -} - sub custom_traffic_output { my ($self, %options) = @_; @@ -118,10 +55,116 @@ sub custom_traffic_calc { if (defined($self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}}) && $self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}} =~ /[0-9]/) { $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic} * 100 / ($self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000); $self->{result_values}->{speed} = $self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000; + } elsif (defined($options{extra_options}->{type}) && $options{extra_options}->{type} eq 'prct') { + return -10; } return 0; } +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'connector', type => 1, cb_prefix_output => 'prefix_connector_output', message_multiple => 'All connectors are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{connector} = [ + { label => 'threads-current', nlabel => 'connector.threads.current.count', set => { + key_values => [ { name => 'currentThreadCount' }, { name => 'maxThreads' }, { name => 'display' } ], + output_template => 'Threads Current : %s', + perfdatas => [ + { label => 'threads_current', value => 'currentThreadCount_absolute', template => '%.2f', min => 0, max => 'maxThreads_absolute', + label_extra_instance => 1 }, + ], + } + }, + { label => 'threads-busy', nlabel => 'connector.threads.busy.count', set => { + key_values => [ { name => 'currentThreadsBusy' }, { name => 'maxThreads' }, { name => 'display' } ], + output_template => 'Threads Busy : %s', + perfdatas => [ + { label => 'threads_busy', value => 'currentThreadsBusy_absolute', template => '%.2f', min => 0, max => 'maxThreads_absolute', + label_extra_instance => 1 }, + ], + } + }, + { label => 'traffic-in', nlabel => 'connector.traffic.in.bitspersecond', set => { + key_values => [ { name => 'in', diff => 1 }, { name => 'display' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, + closure_custom_output => $self->can('custom_traffic_output'), + threshold_use => 'traffic', + perfdatas => [ + { label => 'traffic_in', value => 'traffic', template => '%.2f', min => 0, max => 'speed', + unit => 'b/s', label_extra_instance => 1 }, + ], + } + }, + { label => 'traffic-in-prct', display_ok => 0, nlabel => 'connector.traffic.in.percent', set => { + key_values => [ { name => 'in', diff => 1 }, { name => 'display' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in', type => 'prct' }, + output_template => 'Traffic In Used : %.2f %%', + output_use => 'traffic_prct', threshold_use => 'traffic_prct', + perfdatas => [ + { label => 'traffic_in_prct', value => 'traffic_prct', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1 }, + ], + } + }, + { label => 'traffic-out', nlabel => 'connector.traffic.out.bitspersecond', set => { + key_values => [ { name => 'out', diff => 1 }, { name => 'display' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, + closure_custom_output => $self->can('custom_traffic_output'), + threshold_use => 'traffic', + perfdatas => [ + { label => 'traffic_out', value => 'traffic', template => '%.2f', min => 0, max => 'speed', + unit => 'b/s', label_extra_instance => 1 }, + ], + } + }, + { label => 'traffic-out-prct', display_ok => 0, nlabel => 'connector.traffic.out.percent', set => { + key_values => [ { name => 'out', diff => 1 }, { name => 'display' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out', type => 'prct' }, + output_template => 'Traffic Out Used : %.2f %%', + output_use => 'traffic_prct', threshold_use => 'traffic_prct', + perfdatas => [ + { label => 'traffic_out_prct', value => 'traffic_prct', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1 }, + ], + } + }, + { label => 'requests-processingtime-total', nlabel => 'connector.requests.processingtime.total.milliseconds', set => { + key_values => [ { name => 'requestInfo_processingTime', diff => 1 }, { name => 'display' } ], + output_template => 'Requests Total Processing Time : %s ms', + perfdatas => [ + { label => 'requests_processingtime_total', value => 'requestInfo_processingTime_absolute', template => '%s', min => 0, + unit => 'ms', label_extra_instance => 1 }, + ], + } + }, + { label => 'requests-errors', nlabel => 'connector.requests.errors.count', set => { + key_values => [ { name => 'requestInfo_errorCount', diff => 1 }, { name => 'display' } ], + output_template => 'Requests Errors : %s', + perfdatas => [ + { label => 'requests_errors', value => 'requestInfo_errorCount_absolute', template => '%s', min => 0, + label_extra_instance => 1 }, + ], + } + }, + { label => 'requests-total', nlabel => 'connector.requests.total.count', set => { + key_values => [ { name => 'requestInfo_requestCount', diff => 1 }, { name => 'display' } ], + output_template => 'Requests Total : %s', + perfdatas => [ + { label => 'requests_total', value => 'requestInfo_requestCount_absolute', template => '%s', min => 0, + label_extra_instance => 1 }, + ], + } + }, + ]; +} + sub prefix_connector_output { my ($self, %options) = @_; @@ -133,21 +176,19 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto' }, - "credentials" => { name => 'credentials' }, - "basic" => { name => 'basic' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, - "urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' }, - "filter-name:s" => { name => 'filter_name' }, - "speed-in:s" => { name => 'speed_in' }, - "speed-out:s" => { name => 'speed_out' }, - "units-traffic:s" => { name => 'units_traffic', default => '%' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port', default => '8080' }, + 'proto:s' => { name => 'proto' }, + 'credentials' => { name => 'credentials' }, + 'basic' => { name => 'basic' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout' }, + 'urlpath:s' => { name => 'url_path', default => '/manager/status?XML=true' }, + 'filter-name:s' => { name => 'filter_name' }, + 'speed-in:s' => { name => 'speed_in' }, + 'speed-out:s' => { name => 'speed_out' }, }); $self->{http} = centreon::plugins::http->new(%options); @@ -162,13 +203,20 @@ sub check_options { if (!defined($self->{hostname})) { $self->{hostname} = 'me'; } - + $self->{http}->set_options(%{$self->{option_results}}); } my %xpath_to_check = ( - in => '/status/connector/requestInfo/@bytesReceived', - out => '/status/connector/requestInfo/@bytesSent', + requestInfo_maxTime => '/status/connector/requestInfo/@maxTime', + requestInfo_processingTime => '/status/connector/requestInfo/@processingTime', + requestInfo_requestCount => '/status/connector/requestInfo/@requestCount', + requestInfo_errorCount => '/status/connector/requestInfo/@errorCount', + maxThreads => '/status/connector/threadInfo/@maxThreads', + currentThreadCount => '/status/connector/threadInfo/@currentThreadCount', + currentThreadsBusy => '/status/connector/threadInfo/@currentThreadsBusy', + in => '/status/connector/requestInfo/@bytesReceived', + out => '/status/connector/requestInfo/@bytesSent', ); sub manage_selection { @@ -234,21 +282,17 @@ sub manage_selection { next; } - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) - && $connector_name !~ /$self->{option_results}->{name}/i); - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $connector_name !~ /$self->{option_results}->{name}/); - next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $connector_name ne $self->{option_results}->{name}); - $self->{connector}->{$connector_name} = { display => $connector_name } if (!defined($self->{connector}->{$connector_name})); my $value = $node->string_value(); if ($value =~ /^"?([0-9.]+)"?$/) { - $self->{connector}->{$connector_name}->{$label} = $1 * 8; + $self->{connector}->{$connector_name}->{$label} = $1; + if ($label =~ /^in|out/) { + $self->{connector}->{$connector_name}->{$label} *= 8; + } } } } - + if (scalar(keys %{$self->{connector}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No information found."); $self->{output}->option_exit(); @@ -265,7 +309,7 @@ __END__ =head1 MODE -Check Tomcat Application Servers Traffic for each Connector +Check Tomcat Application Servers Connectors =over 8 @@ -311,21 +355,15 @@ Path to the Tomcat Manager XML (Default: '/manager/status?XML=true') =item B<--filter-name> -Filter by context name (can be a regexp). +Filter by connector name (can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'in', 'out'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'in', 'out'. - -=item B<--units-traffic> - -Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). +Thresholds. +Can be: 'traffic-in' (b), 'traffic-in-prct' (%), +'traffic-out' (b), 'traffic-out-prct' (%), +'threads-current', 'threads-busy', 'requests-processingtime-total' (ms), +'requests-errors', 'requests-total'. =item B<--speed-in> diff --git a/centreon-plugins/apps/tomcat/web/mode/listapplication.pm b/centreon-plugins/apps/tomcat/web/mode/listapplication.pm index 3b4396cbe..49f457c27 100644 --- a/centreon-plugins/apps/tomcat/web/mode/listapplication.pm +++ b/centreon-plugins/apps/tomcat/web/mode/listapplication.pm @@ -30,20 +30,19 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto' }, - "credentials" => { name => 'credentials' }, - "basic" => { name => 'basic' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, - "urlpath:s" => { name => 'url_path', default => '/manager/text/list' }, - "filter-name:s" => { name => 'filter_name', }, - "filter-state:s" => { name => 'filter_state', }, - "filter-path:s" => { name => 'filter_path', }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port', default => '8080' }, + 'proto:s' => { name => 'proto' }, + 'credentials' => { name => 'credentials' }, + 'basic' => { name => 'basic' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout' }, + 'urlpath:s' => { name => 'url_path', default => '/manager/text/list' }, + 'filter-name:s' => { name => 'filter_name', }, + 'filter-state:s' => { name => 'filter_state', }, + 'filter-path:s' => { name => 'filter_path', }, }); $self->{result} = {}; @@ -111,9 +110,10 @@ sub disco_show { $self->manage_selection(); foreach my $name (sort(keys %{$self->{result}})) { - $self->{output}->add_disco_entry(name => $name, - state => $self->{result}->{$name}->{state} - ); + $self->{output}->add_disco_entry( + name => $name, + state => $self->{result}->{$name}->{state} + ); } } diff --git a/centreon-plugins/apps/tomcat/web/mode/memory.pm b/centreon-plugins/apps/tomcat/web/mode/memory.pm index 297651586..af024a67f 100644 --- a/centreon-plugins/apps/tomcat/web/mode/memory.pm +++ b/centreon-plugins/apps/tomcat/web/mode/memory.pm @@ -20,49 +20,86 @@ package apps::tomcat::web::mode::memory; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); + use strict; use warnings; use centreon::plugins::http; use XML::XPath; +sub custom_memory_output { + my ($self, %options) = @_; + + my $msg = sprintf("Memory Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)", + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute}); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'usage', nlabel => 'memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_memory_output'), + perfdatas => [ + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 }, + ], + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_memory_output'), + perfdatas => [ + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 }, + ], + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Memory Used : %.2f %%', + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto' }, - "credentials" => { name => 'credentials' }, - "basic" => { name => 'basic' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, - "urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port', default => '8080' }, + 'proto:s' => { name => 'proto' }, + 'credentials' => { name => 'credentials' }, + 'basic' => { name => 'basic' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout' }, + 'urlpath:s' => { name => 'url_path', default => '/manager/status?XML=true' }, }); - $self->{result} = {}; $self->{http} = centreon::plugins::http->new(%options); 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(); - } + $self->SUPER::check_options(%options); $self->{http}->set_options(%{$self->{option_results}}); } @@ -73,11 +110,10 @@ my %xpath_to_check = ( memTotal => '/status/jvm/memory/@total', ); -sub run { +sub manage_selection { my ($self, %options) = @_; my $webcontent = $self->{http}->request(); - my $port = $self->{option_results}->{port}; #EXAMPLE 1: # @@ -117,56 +153,32 @@ sub run { # # - #GET XML DATA - my $xpath = XML::XPath->new( xml => $webcontent ); - my %xpath_check_results; + my $result = {}; + my $xpath = XML::XPath->new(xml => $webcontent); + foreach my $xpath_check (keys %xpath_to_check) { + my $nodeset = $xpath->find($xpath_to_check{$xpath_check}); - foreach my $xpath_check ( keys %xpath_to_check ) { - my $singlepath = $xpath_to_check{$xpath_check}; - $singlepath =~ s{\$port}{$port}; - my $nodeset = $xpath->find($singlepath); - - foreach my $node ($nodeset->get_nodelist) { + foreach my $node ($nodeset->get_nodelist()) { my $value = $node->string_value(); - if ( $value =~ /^"?([0-9.]+)"?$/ ) { - $self->{result}->{$xpath_check} = $1; - } else { - $self->{result}->{$xpath_check} = "not_numeric"; - }; + if ($value =~ /^"?([0-9.]+)"?$/) { + $result->{$xpath_check} = $1; + } }; }; - my $memTotal = $self->{result}->{memTotal}; - my $memFree = $self->{result}->{memFree}; - my $memMax = $self->{result}->{memMax}; - my $memUsed = $memTotal - $memFree; - my $memUsed_prct = $memUsed * 100 / $memTotal; - - if (!defined($memTotal) || !defined($memFree) || !defined($memUsed) || !defined($memUsed_prct)) { - $self->{output}->add_option_msg(short_msg => "Some informations missing."); + if (!defined($result->{memTotal}) || !defined($result->{memFree})) { + $self->{output}->add_option_msg(short_msg => "some informations missing."); $self->{output}->option_exit(); } - my $exit = $self->{perfdata}->threshold_check(value => $memUsed_prct, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - my ($memTotal_value, $memTotal_unit) = $self->{perfdata}->change_bytes(value => $memTotal); - my ($memFree_value, $memFree_unit) = $self->{perfdata}->change_bytes(value => $memFree); - my ($memMax_value, $memMax_unit) = $self->{perfdata}->change_bytes(value => $memMax); - my ($memUsed_value, $memUsed_unit) = $self->{perfdata}->change_bytes(value => $memUsed); - - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Memory used %s (%.2f%%)", - $memUsed_value . " " . $memUsed_unit, $memUsed_prct)); - - $self->{output}->perfdata_add(label => "used", unit => 'B', - value => $memUsed, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $memTotal), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $memTotal), - min => 0, max => $memTotal); - - $self->{output}->display(); - $self->{output}->exit(); + my $total = $result->{memTotal}; + $self->{global} = { + total => $total, + free => $result->{memFree}, + used => $total - $result->{memFree}, + prct_free => $result->{memFree} * 100 / $total, + prct_used => ($result->{memTotal} - $result->{memFree}) * 100 / $total, + }; }; 1; @@ -219,13 +231,10 @@ Threshold for HTTP timeout Path to the Tomcat Manager XML (Default: '/manager/status?XML=true') -=item B<--warning> +=item B<--warning-*> B<--critical-*> -Threshold warning in percent. - -=item B<--critical> - -Threshold critical in percent. +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). =back diff --git a/centreon-plugins/apps/tomcat/web/mode/requestinfo.pm b/centreon-plugins/apps/tomcat/web/mode/requestinfo.pm deleted file mode 100644 index 01e66073d..000000000 --- a/centreon-plugins/apps/tomcat/web/mode/requestinfo.pm +++ /dev/null @@ -1,421 +0,0 @@ -# -# Copyright 2019 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 apps::tomcat::web::mode::requestinfo; - -use base qw(centreon::plugins::mode); -use strict; -use warnings; -use centreon::plugins::http; -use centreon::plugins::statefile; -use Digest::MD5 qw(md5_hex); -use XML::XPath; -use URI::Escape; - -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 => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto' }, - "credentials" => { name => 'credentials' }, - "basic" => { name => 'basic' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, - "urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' }, - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - "warning-maxtime:s" => { name => 'warning_maxtime' }, - "critical-maxtime:s" => { name => 'critical_maxtime' }, - "warning-processingtime:s" => { name => 'warning_processingtime' }, - "critical-processingtime:s" => { name => 'critical_processingtime' }, - "warning-requestcount:s" => { name => 'warning_requestcount' }, - "critical-requestcount:s" => { name => 'critical_requestcount' }, - "warning-errorcount:s" => { name => 'warning_errorcount' }, - "critical-errorcount:s" => { name => 'critical_errorcount' }, - }); - - $self->{result} = {}; - $self->{hostname} = undef; - $self->{statefile_value} = centreon::plugins::statefile->new(%options); - $self->{http} = centreon::plugins::http->new(%options); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - #MaxTime - if (($self->{perfdata}->threshold_validate(label => 'warning-maxtime', value => $self->{option_results}->{warning_maxtime})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-maxtime' threshold '" . $self->{option_results}->{warning_maxtime} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-maxtime', value => $self->{option_results}->{critical_maxtime})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-maxtime' threshold '" . $self->{option_results}->{critical_maxtime} . "'."); - $self->{output}->option_exit(); - } - #processingTime - if (($self->{perfdata}->threshold_validate(label => 'warning-processingtime', value => $self->{option_results}->{warning_processingtime})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-processingtime' threshold '" . $self->{option_results}->{warning_processingtime} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-processingtime', value => $self->{option_results}->{critical_processingtime})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-processingtime' threshold '" . $self->{option_results}->{critical_processingtime} . "'."); - $self->{output}->option_exit(); - } - #requestCount - if (($self->{perfdata}->threshold_validate(label => 'warning-requestcount', value => $self->{option_results}->{warning_requestcount})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-requestcount' threshold '" . $self->{option_results}->{warning_requestcount} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-requestcount', value => $self->{option_results}->{critical_requestcount})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-requestcount' threshold '" . $self->{option_results}->{critical_requestcount} . "'."); - $self->{output}->option_exit(); - } - #errorCount - if (($self->{perfdata}->threshold_validate(label => 'warning-errorcount', value => $self->{option_results}->{warning_errorcount})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-errorcount' threshold '" . $self->{option_results}->{warning_errorcount} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-errorcount', value => $self->{option_results}->{critical_errorcount})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-errorcount' threshold '" . $self->{option_results}->{critical_errorcount} . "'."); - $self->{output}->option_exit(); - } - - $self->{statefile_value}->check_options(%options); - $self->{hostname} = $self->{option_results}->{hostname}; - if (!defined($self->{hostname})) { - $self->{hostname} = 'me'; - } - - $self->{http}->set_options(%{$self->{option_results}}); -} - -my %xpath_to_check = ( - requestInfo_maxTime => '/status/connector/requestInfo/@maxTime', # - requestInfo_processingTime => '/status/connector/requestInfo/@processingTime', #to last - requestInfo_requestCount => '/status/connector/requestInfo/@requestCount', #to last - requestInfo_errorCount => '/status/connector/requestInfo/@errorCount', #to last -); - -sub manage_selection { - my ($self, %options) = @_; - - my $webcontent = $self->{http}->request(); - my $port = $self->{option_results}->{port}; - - #EXAMPLE 1: - # - # - # - # - # - # - # - # - # - # - # - # - # - - #EXAMPLE 2: - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - - #GET XML DATA - my $xpath = XML::XPath->new( xml => $webcontent ); - my %xpath_check_results; - - foreach my $xpath_check ( keys %xpath_to_check ) { - my $singlepath = $xpath_to_check{$xpath_check}; - $singlepath =~ s{\$port}{$port}; - my $nodeset = $xpath->find($singlepath); - - foreach my $node ($nodeset->get_nodelist) { - my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name"); - $connector_name =~ s/^["'\s]+//; - $connector_name =~ s/["'\s]+$//; - $connector_name = uri_unescape($connector_name); - - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) - && $connector_name !~ /$self->{option_results}->{name}/i); - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $connector_name !~ /$self->{option_results}->{name}/); - next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $connector_name ne $self->{option_results}->{name}); - - my $value = $node->string_value(); - if ( $value =~ /^"?([0-9.]+)"?$/ ) { - $self->{result}->{$connector_name}{$xpath_check} = $1; - } else { - $self->{result}->{$connector_name}{$xpath_check} = "not_numeric"; - }; - }; - - if (scalar(keys %{$self->{result}}) <= 0) { - if (defined($self->{option_results}->{name})) { - $self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'."); - } else { - $self->{output}->add_option_msg(short_msg => "No information found."); - } - $self->{output}->option_exit(); - }; - }; -}; - -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - - my $new_datas = {}; - $self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all'))); - $new_datas->{last_timestamp} = time(); - my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); - - if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All requestInfo Data are ok.'); - } - - foreach my $name (sort(keys %{$self->{result}})) { - $new_datas->{'requestInfo_processingTime_' . $name} = $self->{result}->{$name}->{requestInfo_processingTime}; - $new_datas->{'requestInfo_requestCount_' . $name} = $self->{result}->{$name}->{requestInfo_requestCount}; - $new_datas->{'requestInfo_errorCount_' . $name} = $self->{result}->{$name}->{requestInfo_errorCount}; - - my $requestInfo_processingTime = $self->{statefile_value}->get(name => 'requestInfo_processingTime_' . $name); - my $requestInfo_requestCount = $self->{statefile_value}->get(name => 'requestInfo_requestCount_' . $name); - my $requestInfo_errorCount = $self->{statefile_value}->get(name => 'requestInfo_errorCount_' . $name); - - if (!defined($old_timestamp) || !defined($requestInfo_processingTime) || !defined($requestInfo_requestCount) || !defined($requestInfo_errorCount)) { - next; - } - if ($new_datas->{'requestInfo_processingTime_' . $name} < $requestInfo_processingTime) { - # We set 0. Has reboot. - $requestInfo_processingTime = 0; - } - if ($new_datas->{'requestInfo_requestCount_' . $name} < $requestInfo_requestCount) { - # We set 0. Has reboot. - $requestInfo_requestCount = 0; - } - if ($new_datas->{'requestInfo_errorCount_' . $name} < $requestInfo_errorCount) { - # We set 0. Has reboot. - $requestInfo_errorCount = 0; - } - - my $time_delta = $new_datas->{last_timestamp} - $old_timestamp; - if ($time_delta <= 0) { - # At least one second. two fast calls ;) - $time_delta = 1; - } - - my $requestInfo_maxTime = $self->{result}->{$name}->{requestInfo_maxTime}; - - my $requestInfo_processingTime_absolute_per_sec = ($new_datas->{'requestInfo_processingTime_' . $name} - $requestInfo_processingTime) / $time_delta; - my $requestInfo_requestCount_absolute_per_sec = ($new_datas->{'requestInfo_requestCount_' . $name} - $requestInfo_requestCount) / $time_delta; - my $requestInfo_errorCount_absolute_per_sec = ($new_datas->{'requestInfo_errorCount_' . $name} - $requestInfo_errorCount) / $time_delta; - - my $exit1 = $self->{perfdata}->threshold_check(value => $requestInfo_maxTime, threshold => [ { label => 'critical-maxtime', 'exit_litteral' => 'critical' }, { label => 'warning-maxtime', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $requestInfo_processingTime_absolute_per_sec, threshold => [ { label => 'critical-processingtime', 'exit_litteral' => 'critical' }, { label => 'warning-processingtime', exit_litteral => 'warning' } ]); - my $exit3 = $self->{perfdata}->threshold_check(value => $requestInfo_requestCount_absolute_per_sec, threshold => [ { label => 'critical-requestcount', 'exit_litteral' => 'critical' }, { label => 'warning-requestcount', exit_litteral => 'warning' } ]); - my $exit4 = $self->{perfdata}->threshold_check(value => $requestInfo_errorCount_absolute_per_sec, threshold => [ { label => 'critical-errorcount', 'exit_litteral' => 'critical' }, { label => 'warning-errorcount', exit_litteral => 'warning' } ]); - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4 ]); - - $self->{output}->output_add(long_msg => sprintf("Connector '%s' maxTime : %s, processingTime : %.3f, requestCount : %.2f, errorCount : %.2f", $name, $requestInfo_maxTime, $requestInfo_processingTime_absolute_per_sec, $requestInfo_requestCount_absolute_per_sec, $requestInfo_errorCount_absolute_per_sec)); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Connector '%s' maxTime : %s, processingTime : %.3f, requestCount : %.2f, errorCount : %.2f", $name, - $requestInfo_maxTime, - $requestInfo_processingTime_absolute_per_sec, - $requestInfo_requestCount_absolute_per_sec, - $requestInfo_errorCount_absolute_per_sec)); - } - - my $extra_label; - $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})); - $self->{output}->perfdata_add( - label => 'maxTime', - instances => $extra_label, - value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_maxTime}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0 - ); - - $self->{output}->perfdata_add( - label => 'processingTime', - instances => $extra_label, - value => sprintf("%.3f", $requestInfo_processingTime_absolute_per_sec), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0 - ); - $self->{output}->perfdata_add( - label => 'requestCount', - instances => $extra_label, - value => sprintf("%.2f", $requestInfo_requestCount_absolute_per_sec), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0 - ); - $self->{output}->perfdata_add( - label => 'errorCount', - instances => $extra_label, - value => sprintf("%.2f", $requestInfo_errorCount_absolute_per_sec), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0 - ); - }; - - $self->{statefile_value}->write(data => $new_datas); - if (!defined($old_timestamp)) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); - } - - $self->{output}->display(); - $self->{output}->exit(); -}; - -1; - -__END__ - -=head1 MODE - -Check Tomcat Application Servers Requestinfo Threadsinformation for each Connector - -=over 8 - -=item B<--hostname> - -IP Address or FQDN of the Tomcat Application Server - -=item B<--port> - -Port used by Tomcat - -=item B<--proto> - -Protocol used http or https - -=item B<--credentials> - -Specify this option if you access server-status page with authentication - -=item B<--username> - -Specify username for authentication (Mandatory if --credentials is specified) - -=item B<--password> - -Specify password for authentication (Mandatory if --credentials is specified) - -=item B<--basic> - -Specify this option if you access server-status page over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your webserver. - -Specify this option if you access server-status page over hidden basic authentication or you'll get a '404 NOT FOUND' error. - -(Use with --credentials) - -=item B<--timeout> - -Threshold for HTTP timeout - -=item B<--urlpath> - -Path to the Tomcat Manager XML (Default: '/manager/status?XML=true') - -=item B<--name> - -Set the filter name (empty means 'check all contexts') - -=item B<--regexp> - -Allows to use regexp to filter (with option --name). - -=item B<--regexp-isensitive> - -Allows to use regexp non case-sensitive (with --regexp). - -=item B<--warning-maxtime> - -Threshold warning for maxTime - -=item B<--critical-maxtime> - -Threshold critical for maxTime - -=item B<--warning-processingtime> - -Threshold warning for ProcessingTime - -=item B<--critical-processingtime> - -Threshold critical for ProcessingTime - -=item B<--warning-requestcount> - -Threshold warning for requestCount - -=item B<--critical-requestcount> - -Threshold critical for requestCount - -=item B<--warning-errorcount> - -Threshold warning for errorCount - -=item B<--critical-errorcount> - -Threshold critical for errorCount - -=back - -=cut diff --git a/centreon-plugins/apps/tomcat/web/mode/sessions.pm b/centreon-plugins/apps/tomcat/web/mode/sessions.pm deleted file mode 100644 index 61bc891a2..000000000 --- a/centreon-plugins/apps/tomcat/web/mode/sessions.pm +++ /dev/null @@ -1,227 +0,0 @@ -# -# Copyright 2019 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 apps::tomcat::web::mode::sessions; - -use base qw(centreon::plugins::mode); -use strict; -use warnings; -use centreon::plugins::http; - -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 => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto' }, - "credentials" => { name => 'credentials' }, - "basic" => { name => 'basic' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, - "urlpath:s" => { name => 'url_path', default => '/manager/text/list' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - "filter-state:s" => { name => 'filter_state' }, - "filter-path:s" => { name => 'filter_path', }, - }); - - $self->{result} = {}; - $self->{http} = centreon::plugins::http->new(%options); - 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(); - } - $self->{http}->set_options(%{$self->{option_results}}); -} - -sub manage_selection { - my ($self, %options) = @_; - - my $webcontent = $self->{http}->request(); - - while ($webcontent =~ /(.*):(.*):(\d+):(.*)/g) { - my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4); - - next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' && - $state !~ /$self->{option_results}->{filter_state}/); - next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' && - $contextpath !~ /$self->{option_results}->{filter_path}/); - - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) - && $context !~ /$self->{option_results}->{name}/i); - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $context !~ /$self->{option_results}->{name}/); - next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $context ne $self->{option_results}->{name}); - - $self->{result}->{$context} = {state => $state, sessions => $sessions, contextpath => $contextpath}; - } - - if (scalar(keys %{$self->{result}}) <= 0) { - if (defined($self->{option_results}->{name})) { - $self->{output}->add_option_msg(short_msg => "No session information found for name '" . $self->{option_results}->{name} . "'."); - } else { - $self->{output}->add_option_msg(short_msg => "No session information found."); - } - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - - if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All Sessions are ok.'); - }; - - foreach my $name (sort(keys %{$self->{result}})) { - my $exit = $self->{perfdata}->threshold_check(value => $self->{result}->{$name}->{sessions}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->output_add(long_msg => sprintf("Context '%s' sessions : %s", $name, - $self->{result}->{$name}->{sessions})); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Context '%s' sessions : %s", $name, - $self->{result}->{$name}->{sessions})); - } - - my $extra_label; - $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})); - $self->{output}->perfdata_add( - label => 'sessions', - instances => $extra_label, - value => sprintf("%.2f", $self->{result}->{$name}->{sessions}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0 - ); - }; - - $self->{output}->display(); - $self->{output}->exit(); -}; - -1; - -__END__ - -=head1 MODE - -Check Tomcat Application Servers Number of Sessions for each Context - -=over 8 - -=item B<--hostname> - -IP Address or FQDN of the Tomcat Application Server - -=item B<--port> - -Port used by Tomcat - -=item B<--proto> - -Protocol used http or https - -=item B<--credentials> - -Specify this option if you access server-status page with authentication - -=item B<--username> - -Specify username for authentication (Mandatory if --credentials is specified) - -=item B<--password> - -Specify password for authentication (Mandatory if --credentials is specified) - -=item B<--basic> - -Specify this option if you access server-status page over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your webserver. - -Specify this option if you access server-status page over hidden basic authentication or you'll get a '404 NOT FOUND' error. - -(Use with --credentials) - -=item B<--timeout> - -Threshold for HTTP timeout - -=item B<--urlpath> - -Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list') -Tomcat 6: '/manager/list' -Tomcat 7: '/manager/text/list' - -=item B<--warning> - -Warning Threshold for Number of Sessions - -=item B<--critical> - -Critical Threshold for Number of Sessions - -=item B<--name> - -Set the Context name (empty means 'check all contexts') - -=item B<--regexp> - -Allows to use regexp to filter contexts (with option --name). - -=item B<--regexp-isensitive> - -Allows to use regexp non case-sensitive (with --regexp). - -=item B<--filter-state> - -Filter state (regexp can be used). -Can be for example: 'running' or 'stopped'. - -=item B<--filter-path> - -Filter Context Path (regexp can be used). -Can be for example: '/STORAGE/context/test1'. - -=back - -=cut diff --git a/centreon-plugins/apps/tomcat/web/mode/threads.pm b/centreon-plugins/apps/tomcat/web/mode/threads.pm deleted file mode 100644 index 9385d23a4..000000000 --- a/centreon-plugins/apps/tomcat/web/mode/threads.pm +++ /dev/null @@ -1,286 +0,0 @@ -# -# Copyright 2019 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 apps::tomcat::web::mode::threads; - -use base qw(centreon::plugins::mode); -use strict; -use warnings; -use centreon::plugins::http; -use XML::XPath; -use URI::Escape; - -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 => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto' }, - "credentials" => { name => 'credentials' }, - "basic" => { name => 'basic' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, - "urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - }); - - $self->{result} = {}; - $self->{hostname} = undef; - $self->{http} = centreon::plugins::http->new(%options); - 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(); - } - - $self->{http}->set_options(%{$self->{option_results}}); -} - -my %xpath_to_check = ( - maxThreads => '/status/connector/threadInfo/@maxThreads', - currentThreadCount => '/status/connector/threadInfo/@currentThreadCount', - currentThreadsBusy => '/status/connector/threadInfo/@currentThreadsBusy', -); - -sub manage_selection { - my ($self, %options) = @_; - - my $webcontent = $self->{http}->request(); - my $port = $self->{option_results}->{port}; - - #EXAMPLE 1: - # - # - # - # - # - # - # - # - # - # - # - # - # - - #EXAMPLE 2: - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - - #GET XML DATA - my $xpath = XML::XPath->new( xml => $webcontent ); - my %xpath_check_results; - - foreach my $xpath_check ( keys %xpath_to_check ) { - my $singlepath = $xpath_to_check{$xpath_check}; - $singlepath =~ s{\$port}{$port}; - my $nodeset = $xpath->find($singlepath); - - foreach my $node ($nodeset->get_nodelist) { - my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name"); - $connector_name =~ s/^["'\s]+//; - $connector_name =~ s/["'\s]+$//; - $connector_name = uri_unescape($connector_name); - - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) - && $connector_name !~ /$self->{option_results}->{name}/i); - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $connector_name !~ /$self->{option_results}->{name}/); - next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $connector_name ne $self->{option_results}->{name}); - - my $value = $node->string_value(); - if ( $value =~ /^"?([0-9.]+)"?$/ ) { - $self->{result}->{$connector_name}{$xpath_check} = $1; - } else { - $self->{result}->{$connector_name}{$xpath_check} = "not_numeric"; - }; - }; - - if (scalar(keys %{$self->{result}}) <= 0) { - if (defined($self->{option_results}->{name})) { - $self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'."); - } else { - $self->{output}->add_option_msg(short_msg => "No information found."); - } - $self->{output}->option_exit(); - }; - }; -}; - -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - - if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All Threads are ok.'); - }; - - foreach my $name (sort(keys %{$self->{result}})) { - my $exit = $self->{perfdata}->threshold_check(value => $self->{result}->{$name}->{currentThreadsBusy}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->output_add(long_msg => sprintf("Thread '%s' currentThreadsBusy : %s", $name, - $self->{result}->{$name}->{currentThreadsBusy})); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Thread '%s' currentThreadsBusy : %s", $name, - $self->{result}->{$name}->{currentThreadsBusy})); - } - - my $extra_label; - $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})); - $self->{output}->perfdata_add( - label => 'currentThreadsBusy', - instances => $extra_label, - value => $self->{result}->{$name}->{currentThreadsBusy}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, - max => $self->{result}->{$name}->{maxThreads} - ); - - $self->{output}->perfdata_add( - label => 'currentThreadCount', - instances => $extra_label, - value => $self->{result}->{$name}->{currentThreadCount}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, - max => $self->{result}->{$name}->{maxThreads} - ); - }; - - $self->{output}->display(); - $self->{output}->exit(); -}; - -1; - -__END__ - -=head1 MODE - -Check Tomcat Application Servers Threads for each Connector - -=over 8 - -=item B<--hostname> - -IP Address or FQDN of the Tomcat Application Server - -=item B<--port> - -Port used by Tomcat - -=item B<--proto> - -Protocol used http or https - -=item B<--credentials> - -Specify this option if you access server-status page with authentication - -=item B<--username> - -Specify username for authentication (Mandatory if --credentials is specified) - -=item B<--password> - -Specify password for authentication (Mandatory if --credentials is specified) - -=item B<--basic> - -Specify this option if you access server-status page over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your webserver. - -Specify this option if you access server-status page over hidden basic authentication or you'll get a '404 NOT FOUND' error. - -(Use with --credentials) - -=item B<--timeout> - -Threshold for HTTP timeout - -=item B<--urlpath> - -Path to the Tomcat Manager XML (Default: '/manager/status?XML=true') - -=item B<--warning> - -Warning Threshold for Number of Threads - -=item B<--critical> - -Critical Threshold for Number of Threads - -=item B<--name> - -Set the filter name (empty means 'check all contexts') - -=item B<--regexp> - -Allows to use regexp to filter (with option --name). - -=item B<--regexp-isensitive> - -Allows to use regexp non case-sensitive (with --regexp). - -=back - -=cut diff --git a/centreon-plugins/apps/tomcat/web/plugin.pm b/centreon-plugins/apps/tomcat/web/plugin.pm index 2a26e7591..f2c48808b 100644 --- a/centreon-plugins/apps/tomcat/web/plugin.pm +++ b/centreon-plugins/apps/tomcat/web/plugin.pm @@ -31,14 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'applications' => 'apps::tomcat::web::mode::applications', - 'list-application' => 'apps::tomcat::web::mode::listapplication', - 'sessions' => 'apps::tomcat::web::mode::sessions', - 'threads' => 'apps::tomcat::web::mode::threads', - 'requestinfo' => 'apps::tomcat::web::mode::requestinfo', - 'memory' => 'apps::tomcat::web::mode::memory', - 'traffic' => 'apps::tomcat::web::mode::traffic', - ); + 'applications' => 'apps::tomcat::web::mode::applications', + 'connectors' => 'apps::tomcat::web::mode::connectors', + 'list-application' => 'apps::tomcat::web::mode::listapplication', + 'memory' => 'apps::tomcat::web::mode::memory', + ); return $self; } diff --git a/centreon-plugins/apps/toshiba/storemate/sql/mode/maintenanceplan.pm b/centreon-plugins/apps/toshiba/storemate/sql/mode/maintenanceplan.pm index e11d0a72f..167bb1f1b 100644 --- a/centreon-plugins/apps/toshiba/storemate/sql/mode/maintenanceplan.pm +++ b/centreon-plugins/apps/toshiba/storemate/sql/mode/maintenanceplan.pm @@ -73,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "database:s" => { name => 'database', default => 'Framework' }, diff --git a/centreon-plugins/apps/toshiba/storemate/sql/mode/posstatus.pm b/centreon-plugins/apps/toshiba/storemate/sql/mode/posstatus.pm index 90f8b0ba7..a190e9610 100644 --- a/centreon-plugins/apps/toshiba/storemate/sql/mode/posstatus.pm +++ b/centreon-plugins/apps/toshiba/storemate/sql/mode/posstatus.pm @@ -221,7 +221,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "database:s" => { name => 'database', default => 'Framework' }, diff --git a/centreon-plugins/apps/varnish/local/mode/stats.pm b/centreon-plugins/apps/varnish/local/mode/stats.pm index 3add27c66..c238aa5c8 100644 --- a/centreon-plugins/apps/varnish/local/mode/stats.pm +++ b/centreon-plugins/apps/varnish/local/mode/stats.pm @@ -214,7 +214,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'hostname:s' => { name => 'hostname' }, 'remote' => { name => 'remote' }, diff --git a/centreon-plugins/apps/video/openheadend/snmp/mode/nodeusage.pm b/centreon-plugins/apps/video/openheadend/snmp/mode/nodeusage.pm index bce79115f..b0f987574 100644 --- a/centreon-plugins/apps/video/openheadend/snmp/mode/nodeusage.pm +++ b/centreon-plugins/apps/video/openheadend/snmp/mode/nodeusage.pm @@ -75,7 +75,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/video/openheadend/snmp/mode/operationstatus.pm b/centreon-plugins/apps/video/openheadend/snmp/mode/operationstatus.pm index f7a0cc5aa..2c74e38f7 100644 --- a/centreon-plugins/apps/video/openheadend/snmp/mode/operationstatus.pm +++ b/centreon-plugins/apps/video/openheadend/snmp/mode/operationstatus.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-id:s" => { name => 'filter_id' }, diff --git a/centreon-plugins/apps/video/zixi/restapi/mode/broadcasterinputusage.pm b/centreon-plugins/apps/video/zixi/restapi/mode/broadcasterinputusage.pm index c522df103..e80a73055 100644 --- a/centreon-plugins/apps/video/zixi/restapi/mode/broadcasterinputusage.pm +++ b/centreon-plugins/apps/video/zixi/restapi/mode/broadcasterinputusage.pm @@ -88,7 +88,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-source:s" => { name => 'filter_source' }, diff --git a/centreon-plugins/apps/video/zixi/restapi/mode/broadcasterlicenseusage.pm b/centreon-plugins/apps/video/zixi/restapi/mode/broadcasterlicenseusage.pm index 90e712a01..2b1ccd170 100644 --- a/centreon-plugins/apps/video/zixi/restapi/mode/broadcasterlicenseusage.pm +++ b/centreon-plugins/apps/video/zixi/restapi/mode/broadcasterlicenseusage.pm @@ -160,7 +160,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/video/zixi/restapi/mode/broadcasteroutputusage.pm b/centreon-plugins/apps/video/zixi/restapi/mode/broadcasteroutputusage.pm index 63ba95f3c..a62523211 100644 --- a/centreon-plugins/apps/video/zixi/restapi/mode/broadcasteroutputusage.pm +++ b/centreon-plugins/apps/video/zixi/restapi/mode/broadcasteroutputusage.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/video/zixi/restapi/mode/broadcastersystemusage.pm b/centreon-plugins/apps/video/zixi/restapi/mode/broadcastersystemusage.pm index 4846abb4f..6c62009bc 100644 --- a/centreon-plugins/apps/video/zixi/restapi/mode/broadcastersystemusage.pm +++ b/centreon-plugins/apps/video/zixi/restapi/mode/broadcastersystemusage.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/video/zixi/restapi/mode/feederinputusage.pm b/centreon-plugins/apps/video/zixi/restapi/mode/feederinputusage.pm index 8b90e7a8d..597232828 100644 --- a/centreon-plugins/apps/video/zixi/restapi/mode/feederinputusage.pm +++ b/centreon-plugins/apps/video/zixi/restapi/mode/feederinputusage.pm @@ -78,7 +78,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/video/zixi/restapi/mode/feederoutputusage.pm b/centreon-plugins/apps/video/zixi/restapi/mode/feederoutputusage.pm index 822c89d5e..218b5b6d7 100644 --- a/centreon-plugins/apps/video/zixi/restapi/mode/feederoutputusage.pm +++ b/centreon-plugins/apps/video/zixi/restapi/mode/feederoutputusage.pm @@ -79,7 +79,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/virtualization/ovirt/mode/cpuhost.pm b/centreon-plugins/apps/virtualization/ovirt/mode/cpuhost.pm index 197aeb9ed..65a400168 100644 --- a/centreon-plugins/apps/virtualization/ovirt/mode/cpuhost.pm +++ b/centreon-plugins/apps/virtualization/ovirt/mode/cpuhost.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-id:s" => { name => 'filter_id' }, diff --git a/centreon-plugins/apps/virtualization/ovirt/mode/listclusters.pm b/centreon-plugins/apps/virtualization/ovirt/mode/listclusters.pm index e32179221..2f2240dd0 100644 --- a/centreon-plugins/apps/virtualization/ovirt/mode/listclusters.pm +++ b/centreon-plugins/apps/virtualization/ovirt/mode/listclusters.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/apps/virtualization/ovirt/mode/listdatacenters.pm b/centreon-plugins/apps/virtualization/ovirt/mode/listdatacenters.pm index 9348bac38..d77c4e785 100644 --- a/centreon-plugins/apps/virtualization/ovirt/mode/listdatacenters.pm +++ b/centreon-plugins/apps/virtualization/ovirt/mode/listdatacenters.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/apps/virtualization/ovirt/mode/listhosts.pm b/centreon-plugins/apps/virtualization/ovirt/mode/listhosts.pm index c29b64892..df50b047d 100644 --- a/centreon-plugins/apps/virtualization/ovirt/mode/listhosts.pm +++ b/centreon-plugins/apps/virtualization/ovirt/mode/listhosts.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/apps/vmware/connector/mode/alarmdatacenter.pm b/centreon-plugins/apps/vmware/connector/mode/alarmdatacenter.pm index 06c3011d9..90e87a8df 100644 --- a/centreon-plugins/apps/vmware/connector/mode/alarmdatacenter.pm +++ b/centreon-plugins/apps/vmware/connector/mode/alarmdatacenter.pm @@ -198,7 +198,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "datacenter:s" => { name => 'datacenter' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/alarmhost.pm b/centreon-plugins/apps/vmware/connector/mode/alarmhost.pm index 6c0491fca..a99d8c48b 100644 --- a/centreon-plugins/apps/vmware/connector/mode/alarmhost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/alarmhost.pm @@ -197,7 +197,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm b/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm index b396acab2..787e9e7bd 100644 --- a/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm @@ -128,7 +128,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm b/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm index 8ba9a1834..902f2cecc 100644 --- a/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm @@ -127,7 +127,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/cpuvm.pm b/centreon-plugins/apps/vmware/connector/mode/cpuvm.pm index 112722537..6e01f5228 100644 --- a/centreon-plugins/apps/vmware/connector/mode/cpuvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/cpuvm.pm @@ -148,7 +148,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vm-hostname:s" => { name => 'vm_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/datastorecountvm.pm b/centreon-plugins/apps/vmware/connector/mode/datastorecountvm.pm index 64f9fb60f..f494d8daa 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastorecountvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastorecountvm.pm @@ -129,7 +129,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "datastore-name:s" => { name => 'datastore_name' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/datastorehost.pm b/centreon-plugins/apps/vmware/connector/mode/datastorehost.pm index 7b681ee45..30fec30c9 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastorehost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastorehost.pm @@ -109,7 +109,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/datastoreio.pm b/centreon-plugins/apps/vmware/connector/mode/datastoreio.pm index 4d933a139..1c18b1f3b 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastoreio.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastoreio.pm @@ -114,7 +114,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "datastore-name:s" => { name => 'datastore_name' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/datastoreiops.pm b/centreon-plugins/apps/vmware/connector/mode/datastoreiops.pm index 189435553..b6132c940 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastoreiops.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastoreiops.pm @@ -131,7 +131,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "datastore-name:s" => { name => 'datastore_name' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/datastoresnapshot.pm b/centreon-plugins/apps/vmware/connector/mode/datastoresnapshot.pm index f9ffad0b4..2994f135f 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastoresnapshot.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastoresnapshot.pm @@ -112,7 +112,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "datastore-name:s" => { name => 'datastore_name' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm b/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm index adc75e5c0..0446950b1 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm @@ -189,7 +189,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "datastore-name:s" => { name => 'datastore_name' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/datastorevm.pm b/centreon-plugins/apps/vmware/connector/mode/datastorevm.pm index 48f3e30bf..236d63450 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastorevm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastorevm.pm @@ -134,7 +134,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vm-hostname:s" => { name => 'vm_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/devicevm.pm b/centreon-plugins/apps/vmware/connector/mode/devicevm.pm index 15f7ef15b..a9e6928d9 100644 --- a/centreon-plugins/apps/vmware/connector/mode/devicevm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/devicevm.pm @@ -106,7 +106,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vm-hostname:s" => { name => 'vm_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/discovery.pm b/centreon-plugins/apps/vmware/connector/mode/discovery.pm index d61e4b7e4..d23a01f53 100644 --- a/centreon-plugins/apps/vmware/connector/mode/discovery.pm +++ b/centreon-plugins/apps/vmware/connector/mode/discovery.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-type:s" => { name => 'resource_type' }, "prettify" => { name => 'prettify' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/getmap.pm b/centreon-plugins/apps/vmware/connector/mode/getmap.pm index 0542bd203..ef9b0dba2 100644 --- a/centreon-plugins/apps/vmware/connector/mode/getmap.pm +++ b/centreon-plugins/apps/vmware/connector/mode/getmap.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/healthhost.pm b/centreon-plugins/apps/vmware/connector/mode/healthhost.pm index 3a1258136..d9cdab2dc 100644 --- a/centreon-plugins/apps/vmware/connector/mode/healthhost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/healthhost.pm @@ -164,7 +164,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/limitvm.pm b/centreon-plugins/apps/vmware/connector/mode/limitvm.pm index dce27d214..834ce6a92 100644 --- a/centreon-plugins/apps/vmware/connector/mode/limitvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/limitvm.pm @@ -133,7 +133,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vm-hostname:s" => { name => 'vm_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/listclusters.pm b/centreon-plugins/apps/vmware/connector/mode/listclusters.pm index 43f9ed958..08db18431 100644 --- a/centreon-plugins/apps/vmware/connector/mode/listclusters.pm +++ b/centreon-plugins/apps/vmware/connector/mode/listclusters.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "cluster:s" => { name => 'cluster' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/listdatacenters.pm b/centreon-plugins/apps/vmware/connector/mode/listdatacenters.pm index 292f22bda..ef3a58b5e 100644 --- a/centreon-plugins/apps/vmware/connector/mode/listdatacenters.pm +++ b/centreon-plugins/apps/vmware/connector/mode/listdatacenters.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "datacenter:s" => { name => 'datacenter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/listdatastores.pm b/centreon-plugins/apps/vmware/connector/mode/listdatastores.pm index c56548938..16d12a35f 100644 --- a/centreon-plugins/apps/vmware/connector/mode/listdatastores.pm +++ b/centreon-plugins/apps/vmware/connector/mode/listdatastores.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "datastore-name:s" => { name => 'datastore_name' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/listnichost.pm b/centreon-plugins/apps/vmware/connector/mode/listnichost.pm index d6e5c7fad..eff53592c 100644 --- a/centreon-plugins/apps/vmware/connector/mode/listnichost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/listnichost.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/maintenancehost.pm b/centreon-plugins/apps/vmware/connector/mode/maintenancehost.pm index cd0754868..8e2ccacbb 100644 --- a/centreon-plugins/apps/vmware/connector/mode/maintenancehost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/maintenancehost.pm @@ -92,7 +92,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm b/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm index 86f55708b..16cead2bc 100644 --- a/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm @@ -185,7 +185,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm b/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm index 7e420228f..f776ba3aa 100644 --- a/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm @@ -250,7 +250,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vm-hostname:s" => { name => 'vm_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/nethost.pm b/centreon-plugins/apps/vmware/connector/mode/nethost.pm index d3ba0e983..1201d38cc 100644 --- a/centreon-plugins/apps/vmware/connector/mode/nethost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/nethost.pm @@ -256,7 +256,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "nic-name:s" => { name => 'nic_name' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/servicehost.pm b/centreon-plugins/apps/vmware/connector/mode/servicehost.pm index 98e5750cf..ea52ee142 100644 --- a/centreon-plugins/apps/vmware/connector/mode/servicehost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/servicehost.pm @@ -116,7 +116,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/snapshotvm.pm b/centreon-plugins/apps/vmware/connector/mode/snapshotvm.pm index 460058990..fdb031c95 100644 --- a/centreon-plugins/apps/vmware/connector/mode/snapshotvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/snapshotvm.pm @@ -31,27 +31,29 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "vm-hostname:s" => { name => 'vm_hostname' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "scope-cluster:s" => { name => 'scope_cluster' }, - "scope-host:s" => { name => 'scope_host' }, - "filter-description:s" => { name => 'filter_description' }, - "filter-os:s" => { name => 'filter_os' }, - "filter-uuid:s" => { name => 'filter_uuid' }, - "display-description" => { name => 'display_description' }, - "check-consolidation" => { name => 'check_consolidation' }, - "nopoweredon-skip" => { name => 'nopoweredon_skip' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' }, + 'vm-hostname:s' => { name => 'vm_hostname' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' }, + 'scope-host:s' => { name => 'scope_host' }, + 'filter-description:s' => { name => 'filter_description' }, + 'filter-os:s' => { name => 'filter_os' }, + 'filter-uuid:s' => { name => 'filter_uuid' }, + 'display-description' => { name => 'display_description' }, + 'check-consolidation' => { name => 'check_consolidation' }, + 'nopoweredon-skip' => { name => 'nopoweredon_skip' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'disconnect-status:s' => { name => 'disconnect_status', default => 'unknown' }, + 'unit:s' => { name => 'unit', default => 's' }, }); return $self; } +my $unitdiv = { s => ['seconds', 1], w => ['weeks', 604800], d => ['days', 86400], h => ['hours', 3600], m => ['minutes', 60] }; + sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); @@ -69,6 +71,10 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong disconnect-status option '" . $self->{option_results}->{disconnect_status} . "'."); $self->{output}->option_exit(); } + + if ($self->{option_results}->{unit} eq '' || !defined($unitdiv->{$self->{option_results}->{unit}})) { + $self->{option_results}->{unit} = 's'; + } } sub run { @@ -120,7 +126,7 @@ sub run { my $diff_time = time() - $create_time; my $days = int($diff_time / 60 / 60 / 24); - my $exit = $self->{perfdata}->threshold_check(value => $diff_time, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check(value => ($diff_time / $unitdiv->{$self->{option_results}->{unit}}->[1]), threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $prefix_msg = "'$vm_name'"; if (defined($self->{display_description}) && defined($response->{data}->{$vm_id}->{'config.annotation'}) && @@ -151,19 +157,35 @@ sub run { min => 0 ); if (scalar(keys %{$vm_errors{warning}}) > 0) { - $self->{output}->output_add(severity => 'WARNING', - short_msg => sprintf('Snapshots for VM older than %d days: [%s]', ($self->{option_results}->{warning} / 86400), - join('] [', sort keys %{$vm_errors{warning}}))); + $self->{output}->output_add( + severity => 'WARNING', + short_msg => sprintf( + 'Snapshots for VM older than %d %s: [%s]', + $self->{option_results}->{warning}, + $unitdiv->{$self->{option_results}->{unit}}->[0], + join('] [', sort keys %{$vm_errors{warning}}) + ) + ); } if (scalar(keys %{$vm_errors{critical}}) > 0) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf('Snapshots for VM older than %d days: [%s]', ($self->{option_results}->{critical} / 86400), - join('] [', sort keys %{$vm_errors{critical}}))); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => sprintf( + 'Snapshots for VM older than %d %s: [%s]', + $self->{option_results}->{critical}, + $unitdiv->{$self->{option_results}->{unit}}->[0], + join('] [', sort keys %{$vm_errors{critical}}) + ) + ); } if (scalar(keys %vm_consolidate) > 0) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf('VMs need consolidation: [%s]', - join('] [', sort keys %vm_consolidate))); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => sprintf( + 'VMs need consolidation: [%s]', + join('] [', sort keys %vm_consolidate) + ) + ); } $self->{output}->display(); @@ -225,13 +247,18 @@ Status if VM disconnected (default: 'unknown'). Skip check if VM is not poweredOn. +=item B<--unit> + +Select the unit for performance data and thresholds. May be 's' for seconds, 'm' for minutes, +'h' for hours, 'd' for days, 'w' for weeks. Default is seconds + =item B<--warning> -Threshold warning in seconds. +Warning threshold for snapshot's age. =item B<--critical> -Threshold critical in seconds. +Critical threshold for snapshot's age. =back diff --git a/centreon-plugins/apps/vmware/connector/mode/statconnectors.pm b/centreon-plugins/apps/vmware/connector/mode/statconnectors.pm index dc3f57d7a..13cb11a75 100644 --- a/centreon-plugins/apps/vmware/connector/mode/statconnectors.pm +++ b/centreon-plugins/apps/vmware/connector/mode/statconnectors.pm @@ -70,7 +70,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/vmware/connector/mode/statuscluster.pm b/centreon-plugins/apps/vmware/connector/mode/statuscluster.pm new file mode 100644 index 000000000..5cad04e7d --- /dev/null +++ b/centreon-plugins/apps/vmware/connector/mode/statuscluster.pm @@ -0,0 +1,147 @@ +# +# Copyright 2019 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 apps::vmware::connector::mode::statuscluster; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status is ' . $self->{result_values}->{overall_status}; + if ($self->{result_values}->{vsan_status} ne '') { + $msg .= ' [vsan status: ' . $self->{result_values}->{vsan_status} . ']'; + } + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cluster', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok' }, + ]; + + $self->{maps_counters}->{cluster} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'overall_status' }, { name => 'vsan_status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_cluster_output { + my ($self, %options) = @_; + + return "Cluster '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'cluster-name:s' => { name => 'cluster_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{overall_status} =~ /gray/i || %{vsan_status} =~ /gray/i' }, + 'warning-status:s' => { name => 'warning_status', default => '%{overall_status} =~ /yellow/i || %{vsan_status} =~ /yellow/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{overall_status} =~ /red/i || %{vsan_status} =~ /red/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cluster} = {}; + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'statuscluster' + ); + + foreach my $cluster_id (keys %{$response->{data}}) { + my $cluster_name = $response->{data}->{$cluster_id}->{name}; + $self->{cluster}->{$cluster_name} = { + display => $cluster_name, + overall_status => $response->{data}->{$cluster_id}->{overall_status}, + vsan_status => defined($response->{data}->{$cluster_id}->{vsan_cluster_status}) ? $response->{data}->{$cluster_id}->{vsan_cluster_status} : '', + }; + } +} + +1; + +__END__ + +=head1 MODE + +Check cluster status (also vsan status). + +=over 8 + +=item B<--cluster-name> + +cluster to check. +If not set, we check all clusters. + +=item B<--filter> + +Cluster name is a regexp. + +=item B<--scope-datacenter> + +Search in following datacenter(s) (can be a regexp). + +=item B<--unknown-status> + +Set warning threshold for status (Default: '%{overall_status} =~ /gray/i || %{vsan_status} =~ /gray/i'). +Can used special variables like: %{overall_status}, %{vsan_status} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{overall_status} =~ /yellow/i || %{vsan_status} =~ /yellow/i'). +Can used special variables like: %{overall_status}, %{vsan_status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{overall_status} =~ /red/i || %{vsan_status} =~ /red/i'). +Can used special variables like: %{overall_status}, %{vsan_status} + +=back + +=cut diff --git a/centreon-plugins/apps/vmware/connector/mode/statushost.pm b/centreon-plugins/apps/vmware/connector/mode/statushost.pm index f891665d4..b744bedec 100644 --- a/centreon-plugins/apps/vmware/connector/mode/statushost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/statushost.pm @@ -92,7 +92,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/statusvm.pm b/centreon-plugins/apps/vmware/connector/mode/statusvm.pm index bce83bdc2..d2790b389 100644 --- a/centreon-plugins/apps/vmware/connector/mode/statusvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/statusvm.pm @@ -98,7 +98,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vm-hostname:s" => { name => 'vm_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/swaphost.pm b/centreon-plugins/apps/vmware/connector/mode/swaphost.pm index 5f7f1c95d..2382795c2 100644 --- a/centreon-plugins/apps/vmware/connector/mode/swaphost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/swaphost.pm @@ -90,7 +90,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/swapvm.pm b/centreon-plugins/apps/vmware/connector/mode/swapvm.pm index 9a715ecae..5b35037b1 100644 --- a/centreon-plugins/apps/vmware/connector/mode/swapvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/swapvm.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vm-hostname:s" => { name => 'vm_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/thinprovisioningvm.pm b/centreon-plugins/apps/vmware/connector/mode/thinprovisioningvm.pm index 3013a083a..498b8ba62 100644 --- a/centreon-plugins/apps/vmware/connector/mode/thinprovisioningvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/thinprovisioningvm.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vm-hostname:s" => { name => 'vm_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/timehost.pm b/centreon-plugins/apps/vmware/connector/mode/timehost.pm index 4aa4852f5..243d858b2 100644 --- a/centreon-plugins/apps/vmware/connector/mode/timehost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/timehost.pm @@ -88,7 +88,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/toolsvm.pm b/centreon-plugins/apps/vmware/connector/mode/toolsvm.pm index 35293769a..3cdca0c1f 100644 --- a/centreon-plugins/apps/vmware/connector/mode/toolsvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/toolsvm.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vm-hostname:s" => { name => 'vm_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/uptimehost.pm b/centreon-plugins/apps/vmware/connector/mode/uptimehost.pm index afaedfbf1..f5defedfe 100644 --- a/centreon-plugins/apps/vmware/connector/mode/uptimehost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/uptimehost.pm @@ -88,7 +88,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/vmoperationcluster.pm b/centreon-plugins/apps/vmware/connector/mode/vmoperationcluster.pm index 05e620968..94f12b18d 100644 --- a/centreon-plugins/apps/vmware/connector/mode/vmoperationcluster.pm +++ b/centreon-plugins/apps/vmware/connector/mode/vmoperationcluster.pm @@ -75,7 +75,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "cluster:s" => { name => 'cluster' }, "filter" => { name => 'filter' }, diff --git a/centreon-plugins/apps/vmware/connector/mode/vsanclusterusage.pm b/centreon-plugins/apps/vmware/connector/mode/vsanclusterusage.pm new file mode 100644 index 000000000..21346f952 --- /dev/null +++ b/centreon-plugins/apps/vmware/connector/mode/vsanclusterusage.pm @@ -0,0 +1,183 @@ +# +# Copyright 2019 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 apps::vmware::connector::mode::vsanclusterusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cluster', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok' }, + ]; + + $self->{maps_counters}->{cluster} = [ + { label => 'backend-read-usage', nlabel => 'cluster.vsan.backend.read.usage.iops', set => { + key_values => [ { name => 'iopsRead' } ], + output_template => 'read IOPS: %s', + perfdatas => [ + { value => 'iopsRead_absolute', template => '%s', unit => 'iops', min => 0 }, + ], + } + }, + { label => 'backend-write-usage', nlabel => 'cluster.vsan.backend.write.usage.iops', set => { + key_values => [ { name => 'iopsWrite' } ], + output_template => 'write IOPS: %s', + perfdatas => [ + { value => 'iopsWrite_absolute', template => '%s', unit => 'iops', min => 0 }, + ], + } + }, + { label => 'backend-congestions', nlabel => 'cluster.vsan.backend.congestions.count', set => { + key_values => [ { name => 'congestion' } ], + output_template => 'congestions: %s', + perfdatas => [ + { value => 'congestion_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'backend-outstanding-io', nlabel => 'cluster.vsan.backend.outstanding.io.count', set => { + key_values => [ { name => 'oio' } ], + output_template => 'outstanding IO: %s', + perfdatas => [ + { value => 'oio_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'backend-throughput-read', nlabel => 'cluster.vsan.backend.throughput.read.bytespersecond', display_ok => 0, set => { + key_values => [ { name => 'throughputRead' } ], + output_template => 'read throughput: %s %s/s', + output_change_bytes => 1, + perfdatas => [ + { value => 'throughputRead_absolute', template => '%s', unit => 'B/s', min => 0 }, + ], + } + }, + { label => 'backend-throughput-write', nlabel => 'cluster.vsan.backend.throughput.write.bytespersecond', display_ok => 0, set => { + key_values => [ { name => 'throughputWrite' } ], + output_template => 'write throughput: %s %s/s', + output_change_bytes => 1, + perfdatas => [ + { value => 'throughputWrite_absolute', template => '%s', unit => 'B/s', min => 0 }, + ], + } + }, + { label => 'backend-latency-read', nlabel => 'cluster.vsan.backend.latency.read.milliseconds', display_ok => 0, set => { + key_values => [ { name => 'latencyAvgRead' } ], + output_template => 'read latency: %s ms', + perfdatas => [ + { value => 'latencyAvgRead_absolute', template => '%s', unit => 'ms', min => 0 }, + ], + } + }, + { label => 'backend-latency-write', nlabel => 'cluster.vsan.backend.latency.write.milliseconds', display_ok => 0, set => { + key_values => [ { name => 'latencyAvgWrite' } ], + output_template => 'write latency: %s ms', + perfdatas => [ + { value => 'latencyAvgWrite_absolute', template => '%s', unit => 'ms', min => 0 }, + ], + } + }, + ]; +} + +sub prefix_cluster_output { + my ($self, %options) = @_; + + return "Cluster '" . $options{instance_value}->{display} . "' vsan backend "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'cluster-name:s' => { name => 'cluster_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cluster} = {}; + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'vsanclusterusage' + ); + + foreach my $cluster_id (keys %{$response->{data}}) { + my $cluster_name = $response->{data}->{$cluster_id}->{name}; + $self->{cluster}->{$cluster_name} = { + display => $cluster_name, + %{$response->{data}->{$cluster_id}->{cluster_domcompmgr}}, + }; + } +} + +1; + +__END__ + +=head1 MODE + +Check Vsan cluster usage + +=over 8 + +=item B<--cluster-name> + +cluster to check. +If not set, we check all clusters. + +=item B<--filter> + +Cluster name is a regexp. + +=item B<--scope-datacenter> + +Search in following datacenter(s) (can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'backend-write-usage', 'backend-read-usage', +'backend-outstanding-io', 'backend-congestions', +'backend-throughput-read', 'backend-throughput-write' +. + +=back + +=cut diff --git a/centreon-plugins/apps/vmware/connector/plugin.pm b/centreon-plugins/apps/vmware/connector/plugin.pm index 00265e891..64c4634fd 100644 --- a/centreon-plugins/apps/vmware/connector/plugin.pm +++ b/centreon-plugins/apps/vmware/connector/plugin.pm @@ -59,6 +59,7 @@ sub new { 'service-host' => 'apps::vmware::connector::mode::servicehost', 'snapshot-vm' => 'apps::vmware::connector::mode::snapshotvm', 'stat-connectors' => 'apps::vmware::connector::mode::statconnectors', + 'status-cluster' => 'apps::vmware::connector::mode::statuscluster', 'status-host' => 'apps::vmware::connector::mode::statushost', 'status-vm' => 'apps::vmware::connector::mode::statusvm', 'swap-host' => 'apps::vmware::connector::mode::swaphost', @@ -68,6 +69,7 @@ sub new { 'tools-vm' => 'apps::vmware::connector::mode::toolsvm', 'uptime-host' => 'apps::vmware::connector::mode::uptimehost', 'vmoperation-cluster' => 'apps::vmware::connector::mode::vmoperationcluster', + 'vsan-cluster-usage' => 'apps::vmware::connector::mode::vsanclusterusage', ); $self->{custom_modes}{connector} = 'apps::vmware::connector::custom::connector'; diff --git a/centreon-plugins/apps/vmware/vcsa/restapi/custom/api.pm b/centreon-plugins/apps/vmware/vcsa/restapi/custom/api.pm new file mode 100644 index 000000000..38641a749 --- /dev/null +++ b/centreon-plugins/apps/vmware/vcsa/restapi/custom/api.pm @@ -0,0 +1,267 @@ +# +# Copyright 2019 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 apps::vmware::vcsa::restapi::custom::api; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::http; +use centreon::plugins::statefile; +use JSON::XS; +use Digest::MD5 qw(md5_hex); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port'}, + 'proto:s' => { name => 'proto' }, + 'api-username:s' => { name => 'api_username' }, + 'api-password:s' => { name => 'api_password' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + }); + } + + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + $self->{cache} = centreon::plugins::statefile->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30; + $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : undef; + $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : undef; + + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_username}) || $self->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_password}) || $self->{api_password} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option."); + $self->{output}->option_exit(); + } + + $self->{cache}->check_options(option_results => $self->{option_results}); + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{timeout} = $self->{timeout}; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Content-Type', value => 'application/json;charset=UTF-8'); + $self->{http}->add_header(key => 'Accept', value => 'application/json;charset=UTF-8'); + if (defined($self->{session_id})) { + $self->{http}->add_header(key => 'vmware-api-session-id', value => $self->{session_id}); + } else { + $self->{http}->add_header(key => 'vmware-api-session-id', value => 'null'); + } + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub json_decode { + my ($self, %options) = @_; + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($options{content}); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +sub clean_session_id { + my ($self, %options) = @_; + + my $datas = { last_timestamp => time() }; + $options{statefile}->write(data => $datas); + $self->{session_id} = undef; +} + +sub authenticate { + my ($self, %options) = @_; + + my $has_cache_file = $options{statefile}->read(statefile => 'vcsa_api_' . md5_hex($self->{option_results}->{hostname}) . '_' . md5_hex($self->{option_results}->{api_username})); + my $session_id = $options{statefile}->get(name => 'session_id'); + + if ($has_cache_file == 0 || !defined($session_id)) { + my $content = $self->{http}->request( + method => 'POST', + url_path => '/rest/com/vmware/cis/session', + credentials => 1, basic => 1, + username => $self->{api_username}, + password => $self->{api_password}, + warning_status => '', unknown_status => '', critical_status => '', + curl_backend_options => { header => ['Content-Length: 0'] }, + ); + if ($self->{http}->get_code() != 200) { + $self->{output}->add_option_msg(short_msg => "Login error [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); + $self->{output}->option_exit(); + } + + my $decoded = $self->json_decode(content => $content); + + if (defined($decoded) && defined($decoded->{value})) { + $session_id = $decoded->{value}; + } else { + $self->{output}->add_option_msg(short_msg => "Error retrieving session_id"); + $self->{output}->option_exit(); + } + + my $datas = { last_timestamp => time(), session_id => $session_id }; + $options{statefile}->write(data => $datas); + } + + $self->{session_id} = $session_id; +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + if (!defined($self->{session_id})) { + $self->authenticate(statefile => $self->{cache}); + } + my $content = $self->{http}->request(%options, + warning_status => '', unknown_status => '', critical_status => '' + ); + + # Maybe there is an issue with the session_id. So we retry. + if ($self->{http}->get_code() != 200) { + $self->clean_session_id(); + $self->authenticate(statefile => $self->{cache}); + $content = $self->{http}->request(%options, + warning_status => '', unknown_status => '', critical_status => '' + ); + } + + my $decoded = $self->json_decode(content => $content); + if (!defined($decoded)) { + $self->{output}->add_option_msg(short_msg => "Error while retrieving data (add --debug option for detailed message)"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +1; + +__END__ + +=head1 NAME + +VCSA Rest API + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +Set hostname or IP of vsca. + +=item B<--port> + +Set port (Default: '443'). + +=item B<--proto> + +Specify https if needed (Default: 'https'). + +=item B<--api-username> + +Set username. + +=item B<--api-password> + +Set password. + +=item B<--timeout> + +Threshold for HTTP timeout (Default: '30'). + +=back + +=cut diff --git a/centreon-plugins/apps/vmware/vcsa/restapi/mode/health.pm b/centreon-plugins/apps/vmware/vcsa/restapi/mode/health.pm new file mode 100644 index 000000000..67bcfa52d --- /dev/null +++ b/centreon-plugins/apps/vmware/vcsa/restapi/mode/health.pm @@ -0,0 +1,138 @@ +# +# Copyright 2019 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 apps::vmware::vcsa::restapi::mode::health; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg .= 'health is ' . $self->{result_values}->{health}; + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'service', type => 1, cb_prefix_output => 'prefix_service_output', message_multiple => 'All services are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{service} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'health' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_service_output { + my ($self, %options) = @_; + + return "Service '" . $options{instance_value}->{display} ."' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => { + 'filter-service:s' => { name => 'filter_service' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{health} !~ /green/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => [ + 'warning_status', 'critical_status', 'unknown_status', + ]); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $endpoint = '/rest/appliance/health/'; + my @services = ('applmgmt', 'database-storage', 'load', 'mem', 'software-packages', 'storage', 'swap', 'system'); + $self->{service} = {}; + foreach (@services) { + if (defined($self->{option_results}->{filter_service}) && $self->{option_results}->{filter_service} ne '' && + $_ !~ /$self->{option_results}->{filter_service}/) { + $self->{output}->output_add(long_msg => "skipping '" . $_ . "': no matching filter.", debug => 1); + next; + } + + my $result = $options{custom}->request_api(url_path => $endpoint . $_); + $self->{service}->{$_} = { + display => $_, + health => $result->{value}, + }; + } +} + +1; + +__END__ + +=head1 MODE + +Check service health. + +=over 8 + +=item B<--filter-service> + +Filter service (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{health}, %{display} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{health}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{health} !~ /green/'). +Can used special variables like: %{health}, %{display} + +=back + +=cut diff --git a/centreon-plugins/apps/vmware/vcsa/restapi/plugin.pm b/centreon-plugins/apps/vmware/vcsa/restapi/plugin.pm new file mode 100644 index 000000000..373a74410 --- /dev/null +++ b/centreon-plugins/apps/vmware/vcsa/restapi/plugin.pm @@ -0,0 +1,54 @@ +# +# Copyright 2019 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 apps::vmware::vcsa::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'health' => 'apps::vmware::vcsa::restapi::mode::health', + ); + + $self->{custom_modes}{api} = 'apps::vmware::vcsa::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check vCenter Server Appliance (VCSA) through HTTP/REST API. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/apps/vmware/wsman/mode/hardware.pm b/centreon-plugins/apps/vmware/wsman/mode/hardware.pm index 40694ac35..9c2b77063 100644 --- a/centreon-plugins/apps/vmware/wsman/mode/hardware.pm +++ b/centreon-plugins/apps/vmware/wsman/mode/hardware.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm b/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm index af5642fa8..ed7508dbd 100644 --- a/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm +++ b/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm @@ -194,9 +194,13 @@ sub request_api { warning_status => '', unknown_status => '', critical_status => '%{http_code} < 200 or %{http_code} >= 300' ); - # Some content may be strangely returned, for example : "[{\"Category\":\"provider\",\"Count\":1}]" + # Some content may be strangely returned, for example : + # 3CX < 16.0.2.910 : "[{\"Category\":\"provider\",\"Count\":1}]" + # 3CX >= 16.0.2.910 : {"tcxUpdate":"[{\"Category\":\"provider\",\"Count\":5},{\"Category\":\"sp150\",\"Count\":1}]","perPage":"[]"} if (defined($options{eval_content}) && $options{eval_content} == 1) { - $content = eval "$content"; + if (my $evcontent = eval "$content") { + $content = $evcontent; + } } my $decoded; @@ -249,6 +253,13 @@ sub internal_update_checker { my ($self, %options) = @_; my $status = $self->request_api(method => 'GET', url_path =>'/api/UpdateChecker/GetFromParams', eval_content => 1); + if (ref($status) eq 'HASH') { + $status = $status->{tcxUpdate}; + if (ref($status) ne 'ARRAY') { + # See above note about strange content + $status = JSON::XS->new->utf8->decode($status); + } + } return $status; } diff --git a/centreon-plugins/apps/voip/3cx/restapi/mode/system.pm b/centreon-plugins/apps/voip/3cx/restapi/mode/system.pm index 31a6b7803..7b69c8d3b 100644 --- a/centreon-plugins/apps/voip/3cx/restapi/mode/system.pm +++ b/centreon-plugins/apps/voip/3cx/restapi/mode/system.pm @@ -29,15 +29,19 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = 'health : ' . $self->{result_values}->{health}; + my $msg = ''; + if ($self->{result_values}->{service} !~ /^Has[A-Z]/) { + $msg .= 'error '; + } + $msg .= ': ' . $self->{result_values}->{error}; return $msg; } sub custom_status_calc { my ($self, %options) = @_; - $self->{result_values}->{health} = $options{new_datas}->{$self->{instance} . '_health'}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{error} = $options{new_datas}->{$self->{instance} . '_error'}; + $self->{result_values}->{service} = $options{new_datas}->{$self->{instance} . '_service'}; return 0; } @@ -72,7 +76,7 @@ sub set_counters { $self->{maps_counters}->{service} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'health' }, { name => 'display' } ], + key_values => [ { name => 'error' }, { name => 'service' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, @@ -85,7 +89,7 @@ sub set_counters { sub prefix_service_output { my ($self, %options) = @_; - return "Service '" . $options{instance_value}->{display} . "' "; + return "3CX '" . $options{instance_value}->{service} ."' "; } sub new { @@ -97,7 +101,7 @@ sub new { $options{options}->add_options(arguments => { "unknown-status:s" => { name => 'unknown_status', default => '' }, "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{health} =~ /false/' }, + "critical-status:s" => { name => 'critical_status', default => '%{error} =~ /true/' }, }); return $self; @@ -123,27 +127,27 @@ sub manage_selection { foreach my $item (keys %$single) { # As of 3CX 15.5 / 16, we have Firewall, Phones, Trunks $self->{service}->{$item} = { - display => $item, - health => $single->{$item} ? 'true' : 'false', + service => $item, + error => $single->{$item} ? 'false' : 'true', }; } # As per 3CX support, $single->{Trunks} does not trigger if TrunksRegistered != TrunksTotal, # but only if "trunk is unsupported", so let's workaround $self->{service}->{HasUnregisteredTrunks} = { - display => 'HasUnregisteredTrunks', - health => ($system->{TrunksRegistered} < $system->{TrunksTotal}) ? 'false' : 'true', + service => 'HasUnregisteredTrunks', + error => ($system->{TrunksRegistered} < $system->{TrunksTotal}) ? 'true' : 'false', }; $self->{service}->{HasNotRunningServices} = { - display => 'HasNotRunningServices', - health => $system->{HasNotRunningServices} ? 'false' : 'true', + service => 'HasNotRunningServices', + error => $system->{HasNotRunningServices} ? 'true' : 'false', }; $self->{service}->{HasUnregisteredSystemExtensions} = { - display => 'HasUnregisteredSystemExtensions', - health => $system->{HasUnregisteredSystemExtensions} ? 'false' : 'true', + service => 'HasUnregisteredSystemExtensions', + error => $system->{HasUnregisteredSystemExtensions} ? 'true' : 'false', }; $self->{service}->{HasUpdatesAvailable} = { - display => 'HasUpdatesAvailable', - health => scalar(@$update) ? 'false' : 'true', + service => 'HasUpdatesAvailable', + error => scalar(@$update) ? 'true' : 'false', }; $self->{global} = { @@ -165,17 +169,17 @@ Check system health =item B<--unknown-status> Set unknown threshold for status. -Can used special variables like: %{health}, %{display} +Can used special variables like: %{error}, %{service} =item B<--warning-status> Set warning threshold for status. -Can used special variables like: %{health}, %{display} +Can used special variables like: %{error}, %{service} =item B<--critical-status> -Set critical threshold for status (Default: '%{health} =~ /false/'). -Can used special variables like: %{health}, %{display} +Set critical threshold for status (Default: '%{error} =~ /false/'). +Can used special variables like: %{error}, %{service} =item B<--warning-*> B<--critical-*> diff --git a/centreon-plugins/apps/voip/asterisk/ami/custom/api.pm b/centreon-plugins/apps/voip/asterisk/ami/custom/api.pm index f2db73c4d..c7c80949e 100644 --- a/centreon-plugins/apps/voip/asterisk/ami/custom/api.pm +++ b/centreon-plugins/apps/voip/asterisk/ami/custom/api.pm @@ -124,7 +124,11 @@ sub read_ami_protocol_end { if ($options{response} eq 'Follows') { return 1 if ($options{message} =~ /^--END COMMAND--/ms); } else { - return 1 if ($options{message} =~ /^Message: (.*)(\r\n)/ms); + if ($options{message} =~ /^Message:\s+Command\s+output\s+follows/i) { + return 1 if ($options{message} =~ /\n\n/ms); + } elsif ($options{message} =~ /^Message: (.*)(\n)/ms) { + return 1; + } } } @@ -135,13 +139,20 @@ sub read_ami_protocol { my ($self, %options) = @_; my $select = IO::Select->new($self->{cnx_ami}); - # Two types of message: + # Three types of message: # Response: Error # Message: Authentication failed # # Response: Follows # ... # --END COMMAND-- + # + # Response: Success + # Message: Command output follows + # output: xxxx + # output: xxxx + # ... + # my ($response, $read_msg); my $message = ''; @@ -152,8 +163,9 @@ sub read_ami_protocol { } my $status = $self->{cnx_ami}->recv($read_msg, 4096); + $read_msg =~ s/\r//msg; if (!defined($response)) { - next if ($read_msg !~ /^Response: (.*?)(?:\r\n|\n)(.*)/ms); + next if ($read_msg !~ /^Response: (.*?)(?:\n)(.*)/ms); ($response, $message) = ($1, $2); } else { $message .= $read_msg; @@ -161,8 +173,8 @@ sub read_ami_protocol { last if ($self->read_ami_protocol_end(response => $response, message => $message)); } - - $message =~ s/\r//msg; + + $message =~ s/^Output:\s+//mig; if ($response !~ /Success|Follows/) { $message =~ s/\n+$//msg; $message =~ s/\n/ -- /msg; diff --git a/centreon-plugins/apps/voip/asterisk/ami/mode/channelusage.pm b/centreon-plugins/apps/voip/asterisk/ami/mode/channelusage.pm index 3e5a0c2ff..b32c7f158 100644 --- a/centreon-plugins/apps/voip/asterisk/ami/mode/channelusage.pm +++ b/centreon-plugins/apps/voip/asterisk/ami/mode/channelusage.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/voip/asterisk/ami/mode/dahdistatus.pm b/centreon-plugins/apps/voip/asterisk/ami/mode/dahdistatus.pm index 0b24195cf..c3c0963e2 100644 --- a/centreon-plugins/apps/voip/asterisk/ami/mode/dahdistatus.pm +++ b/centreon-plugins/apps/voip/asterisk/ami/mode/dahdistatus.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-description:s" => { name => 'filter_description' }, diff --git a/centreon-plugins/apps/voip/asterisk/ami/mode/sippeersusage.pm b/centreon-plugins/apps/voip/asterisk/ami/mode/sippeersusage.pm index 957ab6b2d..0cebbbf44 100644 --- a/centreon-plugins/apps/voip/asterisk/ami/mode/sippeersusage.pm +++ b/centreon-plugins/apps/voip/asterisk/ami/mode/sippeersusage.pm @@ -108,7 +108,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/apps/voip/asterisk/snmp/mode/channelusage.pm b/centreon-plugins/apps/voip/asterisk/snmp/mode/channelusage.pm index 86a7e2013..735b7e9a6 100644 --- a/centreon-plugins/apps/voip/asterisk/snmp/mode/channelusage.pm +++ b/centreon-plugins/apps/voip/asterisk/snmp/mode/channelusage.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/apps/voip/cisco/meetingplace/mode/audiolicenses.pm b/centreon-plugins/apps/voip/cisco/meetingplace/mode/audiolicenses.pm index 1a0aa4125..46386e75e 100644 --- a/centreon-plugins/apps/voip/cisco/meetingplace/mode/audiolicenses.pm +++ b/centreon-plugins/apps/voip/cisco/meetingplace/mode/audiolicenses.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '60' }, diff --git a/centreon-plugins/apps/voip/cisco/meetingplace/mode/audioports.pm b/centreon-plugins/apps/voip/cisco/meetingplace/mode/audioports.pm index c9a8d1e25..b7780184a 100644 --- a/centreon-plugins/apps/voip/cisco/meetingplace/mode/audioports.pm +++ b/centreon-plugins/apps/voip/cisco/meetingplace/mode/audioports.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '60' }, diff --git a/centreon-plugins/apps/voip/cisco/meetingplace/mode/videolicenses.pm b/centreon-plugins/apps/voip/cisco/meetingplace/mode/videolicenses.pm index 4ce445cbc..c568177f9 100644 --- a/centreon-plugins/apps/voip/cisco/meetingplace/mode/videolicenses.pm +++ b/centreon-plugins/apps/voip/cisco/meetingplace/mode/videolicenses.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '60' }, diff --git a/centreon-plugins/apps/voip/cisco/meetingplace/mode/videoports.pm b/centreon-plugins/apps/voip/cisco/meetingplace/mode/videoports.pm index 1768cda3b..aa8426693 100644 --- a/centreon-plugins/apps/voip/cisco/meetingplace/mode/videoports.pm +++ b/centreon-plugins/apps/voip/cisco/meetingplace/mode/videoports.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '60' }, diff --git a/centreon-plugins/apps/vtom/restapi/mode/jobstatus.pm b/centreon-plugins/apps/vtom/restapi/mode/jobstatus.pm index 07ba12d80..0d1667c11 100644 --- a/centreon-plugins/apps/vtom/restapi/mode/jobstatus.pm +++ b/centreon-plugins/apps/vtom/restapi/mode/jobstatus.pm @@ -157,7 +157,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-application:s" => { name => 'filter_application' }, diff --git a/centreon-plugins/apps/wazuh/restapi/custom/api.pm b/centreon-plugins/apps/wazuh/restapi/custom/api.pm new file mode 100644 index 000000000..a0fd99efb --- /dev/null +++ b/centreon-plugins/apps/wazuh/restapi/custom/api.pm @@ -0,0 +1,222 @@ +# +# Copyright 2019 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 apps::wazuh::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'hostname:s@' => { name => 'hostname' }, + 'username:s@' => { name => 'username' }, + 'password:s@' => { name => 'password' }, + 'timeout:s@' => { name => 'timeout' }, + 'port:s@' => { name => 'port' }, + 'proto:s@' => { name => 'proto' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; + +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? shift(@{$self->{option_results}->{hostname}}) : undef; + $self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : ''; + $self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : ''; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : 10; + $self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : 55000; + $self->{proto} = (defined($self->{option_results}->{proto})) ? shift(@{$self->{option_results}->{proto}}) : 'https'; + + if (!defined($self->{hostname})) { + $self->{output}->add_option_msg(short_msg => 'Need to specify hostname option.'); + $self->{output}->option_exit(); + } + + if (!defined($self->{hostname}) || + scalar(@{$self->{option_results}->{hostname}}) == 0) { + return 0; + } + return 1; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub get_port { + my ($self, %options) = @_; + + return $self->{port}; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{username}; + $self->{option_results}->{password} = $self->{password}; + + if (!defined($self->{option_results}->{ssl_opt})) { + $self->{option_results}->{ssl_opt} = ['SSL_verify_mode => SSL_VERIFY_NONE']; + } + if (!defined($self->{option_results}->{curl_opt})) { + $self->{option_results}->{curl_opt} = ['CURLOPT_SSL_VERIFYPEER => 0', 'CURLOPT_SSL_VERIFYHOST => 0']; + } +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub request { + my ($self, %options) = @_; + + $self->settings(); + my $content = $self->{http}->request( + url_path => $options{path}, + unknown_status => '', warning_status => '', critical_status => '', + ); + + if ($self->{http}->get_code() != 200) { + $self->{output}->add_option_msg(short_msg => 'Connection issue : ' . $self->{http}->get_message() . ' (' . $self->{http}->get_code() . ')'); + $self->{output}->option_exit(); + } + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => 'Cannot decode json response'); + $self->{output}->option_exit(); + } + if ($decoded->{error} != 0) { + $self->{output}->add_option_msg(short_msg => "api error $decoded->{error}: " . $decoded->{message}); + $self->{output}->option_exit(); + } + + return $decoded; +} + +1; + +__END__ + +=head1 NAME + +Wazuh REST API + +=head1 SYNOPSIS + +Wazuh Rest API custom mode + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +Wazuh hostname. + +=item B<--username> + +Wazuh username. + +=item B<--password> + +Wazuh password. + +=item B<--timeout> + +Set HTTP timeout in seconds (Default: '10'). + +=item B<--proto> + +Set protocol (default: 'https') + +=item B<--port> + +Set HTTP port (default: 55000) + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/wazuh/restapi/mode/agents.pm b/centreon-plugins/apps/wazuh/restapi/mode/agents.pm new file mode 100644 index 000000000..6e27c6bbe --- /dev/null +++ b/centreon-plugins/apps/wazuh/restapi/mode/agents.pm @@ -0,0 +1,165 @@ +# +# Copyright 2019 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 apps::wazuh::restapi::mode::agents; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf('status: %s [node name: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{node_name} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, + { name => 'agent', type => 1, cb_prefix_output => 'prefix_agent_output', message_multiple => 'All agents are ok' } + ]; + + $self->{maps_counters}->{global} = []; + foreach ('active', 'pending', 'neverconnected', 'disconnected') { + push @{$self->{maps_counters}->{global}}, { + label => $_, nlabel => 'agents.' . $_ . '.count', display_ok => 0, set => { + key_values => [ { name => $_ } ], + output_template => $_ . ': %s', + perfdatas => [ + { value => $_ . '_absolute', template => '%s', min => 0 }, + ], + } + }; + } + + $self->{maps_counters}->{agent} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' }, { name => 'node_name' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "Total agents "; +} + +sub prefix_agent_output { + my ($self, %options) = @_; + + return "Agent '" . $options{instance_value}->{display} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { active => 0, pending => 0, neverconnected => 0, disconnected => 0 }; + $self->{agent} = {}; + my $result = $options{custom}->request(path => '/agents?select=name,status,node_name'); + foreach (@{$result->{data}->{items}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping agent '" . $_->{name} . "': no matching filter.", debug => 1); + next; + } + + my $status = lc($_->{status}); + $self->{agent}->{$_->{id}} = { + display => $_->{name}, + node_name => $_->{node_name}, + status => $status, + }; + + $self->{global}->{$status}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check wazuh agents. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^status$' + +=item B<--filter-name> + +Filter agent name (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{node_name}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: ''). +Can used special variables like: %{status}, %{node_name}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'active', 'pending', 'neverconnected', 'disconnected'. + +=back + +=cut diff --git a/centreon-plugins/apps/wazuh/restapi/mode/manager.pm b/centreon-plugins/apps/wazuh/restapi/mode/manager.pm new file mode 100644 index 000000000..f0d4b6f38 --- /dev/null +++ b/centreon-plugins/apps/wazuh/restapi/mode/manager.pm @@ -0,0 +1,211 @@ +# +# Copyright 2019 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 apps::wazuh::restapi::mode::manager; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf('status: %s', + $self->{result_values}->{status}, + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, + { name => 'process', type => 1, cb_prefix_output => 'prefix_process_output', message_multiple => 'All manager processes are ok' }, + { name => 'log', type => 1, cb_prefix_output => 'prefix_log_output', message_multiple => 'All manager logs are ok' } + ]; + + $self->{maps_counters}->{global} = []; + foreach ('stopped', 'running') { + push @{$self->{maps_counters}->{global}}, { + label => 'processes-' . $_, nlabel => 'manager.processes.' . $_ . '.count', display_ok => 0, set => { + key_values => [ { name => $_ } ], + output_template => $_ . ': %s', + perfdatas => [ + { value => $_ . '_absolute', template => '%s', min => 0 }, + ], + } + }; + } + + $self->{maps_counters}->{process} = [ + { label => 'process-status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; + + $self->{maps_counters}->{log} = []; + foreach ('error', 'critical', 'warning') { + push @{$self->{maps_counters}->{log}}, { + label => 'log-' . $_, nlabel => 'manager.log.' . $_ . '.count', set => { + key_values => [ { name => $_, diff => 1 } ], + output_template => $_ . ': %s', + perfdatas => [ + { value => $_ . '_absolute', template => '%s', min => 0 }, + ], + } + }; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, , statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-process:s' => { name => 'filter_process' }, + 'filter-log:s' => { name => 'filter_log' }, + 'warning-process-status:s' => { name => 'warning_process_status', default => '' }, + 'critical-process-status:s' => { name => 'critical_process_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_process_status', 'critical_process_status']); +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "Total processes "; +} + +sub prefix_process_output { + my ($self, %options) = @_; + + return "Process '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_log_output { + my ($self, %options) = @_; + + return "Log '" . $options{instance_value}->{display} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { running => 0, stopped => 0 }; + $self->{process} = {}; + my $result = $options{custom}->request(path => '/manager/status'); + foreach (keys %{$result->{data}}) { + if (defined($self->{option_results}->{filter_process}) && $self->{option_results}->{filter_process} ne '' && + $_ !~ /$self->{option_results}->{filter_process}/) { + $self->{output}->output_add(long_msg => "skipping process '" . $_ . "': no matching filter.", debug => 1); + next; + } + + my $status = lc($result->{data}->{$_}); + $self->{process}->{$_} = { + display => $_, + status => $status, + }; + + $self->{global}->{$status}++; + } + + $self->{log} = {}; + $result = $options{custom}->request(path => '/manager/logs/summary?'); + foreach (keys %{$result->{data}}) { + if (defined($self->{option_results}->{filter_log}) && $self->{option_results}->{filter_log} ne '' && + $_ !~ /$self->{option_results}->{filter_log}/) { + $self->{output}->output_add(long_msg => "skipping log '" . $_ . "': no matching filter.", debug => 1); + next; + } + + $self->{log}->{$_} = { + display => $_, + error => $result->{data}->{$_}->{error}, + warning => $result->{data}->{$_}->{warning}, + critical => $result->{data}->{$_}->{critical}, + }; + } + + $self->{cache_name} = 'wazuh_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_log}) ? md5_hex($self->{option_results}->{filter_log}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check wazuh manager processes and logs. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^status$' + +=item B<--filter-process> + +Filter process name (can be a regexp). + +=item B<--filter-log> + +Filter log name (can be a regexp). + +=item B<--warning-process-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-process-status> + +Set critical threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'processes-running', 'processes-stopped', +'log-error', 'log-critical', 'log-warning'. + +=back + +=cut diff --git a/centreon-plugins/apps/wazuh/restapi/plugin.pm b/centreon-plugins/apps/wazuh/restapi/plugin.pm new file mode 100644 index 000000000..a3c5228c6 --- /dev/null +++ b/centreon-plugins/apps/wazuh/restapi/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2019 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 apps::wazuh::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'agents' => 'apps::wazuh::restapi::mode::agents', + 'manager' => 'apps::wazuh::restapi::mode::manager', + ); + + $self->{custom_modes}{api} = 'apps::wazuh::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Wazuh through HTTP/REST API. + +=cut diff --git a/centreon-plugins/apps/wsus/local/mode/computersstatus.pm b/centreon-plugins/apps/wsus/local/mode/computersstatus.pm index 74b3933aa..9020d27d6 100644 --- a/centreon-plugins/apps/wsus/local/mode/computersstatus.pm +++ b/centreon-plugins/apps/wsus/local/mode/computersstatus.pm @@ -94,7 +94,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 30 }, "command:s" => { name => 'command', default => 'powershell.exe' }, diff --git a/centreon-plugins/apps/wsus/local/mode/serverstatistics.pm b/centreon-plugins/apps/wsus/local/mode/serverstatistics.pm index 11954f076..4e16c20c7 100644 --- a/centreon-plugins/apps/wsus/local/mode/serverstatistics.pm +++ b/centreon-plugins/apps/wsus/local/mode/serverstatistics.pm @@ -115,7 +115,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 30 }, "command:s" => { name => 'command', default => 'powershell.exe' }, diff --git a/centreon-plugins/apps/wsus/local/mode/synchronisationstatus.pm b/centreon-plugins/apps/wsus/local/mode/synchronisationstatus.pm index 4e2925fc0..abac0d56a 100644 --- a/centreon-plugins/apps/wsus/local/mode/synchronisationstatus.pm +++ b/centreon-plugins/apps/wsus/local/mode/synchronisationstatus.pm @@ -205,7 +205,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 30 }, "command:s" => { name => 'command', default => 'powershell.exe' }, @@ -348,15 +347,10 @@ Can used special variables like: %{status}. Set critical threshold for current synchronisation status (Default: '%{status} !~ /Succeeded/'). Can used special variables like: %{status}. -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Warning thresholds. -Can be: 'progress' (%), 'duration' (s). - -=item B<--critical-*> - -Critical thresholds. -Can be: 'progress' (%), 'duration' (s). +Thresholds. +Can be: 'last-synchronisation-duration' (s), 'synchronisation-progress' (%). =item B<--filter-counters> diff --git a/centreon-plugins/apps/wsus/local/mode/updatesstatus.pm b/centreon-plugins/apps/wsus/local/mode/updatesstatus.pm index b765e57aa..ce0a14374 100644 --- a/centreon-plugins/apps/wsus/local/mode/updatesstatus.pm +++ b/centreon-plugins/apps/wsus/local/mode/updatesstatus.pm @@ -94,7 +94,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 30 }, "command:s" => { name => 'command', default => 'powershell.exe' }, diff --git a/centreon-plugins/apps/zoom/restapi/custom/api.pm b/centreon-plugins/apps/zoom/restapi/custom/api.pm new file mode 100644 index 000000000..f6d813d4f --- /dev/null +++ b/centreon-plugins/apps/zoom/restapi/custom/api.pm @@ -0,0 +1,239 @@ +# +# Copyright 2019 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 apps::zoom::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use centreon::plugins::statefile; +use DateTime; +use Digest::MD5 qw(md5_hex); +use JSON::XS; +use JSON::WebToken; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + "hostname:s" => { name => 'hostname' }, + "url-path:s" => { name => 'url_path' }, + "port:s" => { name => 'port' }, + "proto:s" => { name => 'proto' }, + "api-key:s" => { name => 'api_key' }, + "api-secret:s" => { name => 'api_secret' }, + "timeout:s" => { name => 'timeout' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + $self->{cache} = centreon::plugins::statefile->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : 'api.zoom.us'; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/v2'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + $self->{api_key} = (defined($self->{option_results}->{api_key})) ? $self->{option_results}->{api_key} : ''; + $self->{api_secret} = (defined($self->{option_results}->{api_secret})) ? $self->{option_results}->{api_secret} : ''; + + if (!defined($self->{api_key}) || $self->{api_key} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-key option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_secret}) || $self->{api_secret} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-secret option."); + $self->{output}->option_exit(); + } + + $self->{cache}->check_options(option_results => $self->{option_results}); + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{url_path} = $self->{url_path}; + $self->{option_results}->{warning_status} = ''; + $self->{option_results}->{critical_status} = ''; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + if (defined($self->{jwt_token})) { + $self->{http}->add_header(key => 'Authorization', value => 'Bearer ' . $self->{jwt_token}); + } + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub get_jwt_token { + my ($self, %options) = @_; + + my $has_cache_file = $options{statefile}->read(statefile => 'zoom_api_' . md5_hex($self->{api_key})); + my $expires_on = $options{statefile}->get(name => 'expires_on'); + my $jwt_token = $options{statefile}->get(name => 'jwt_token'); + + if ($has_cache_file == 0 || !defined($jwt_token) || (($expires_on - time()) < 10)) { + my $exp = time() + 3600; + + $jwt_token = JSON::WebToken->encode({ + alg => "HS256", + typ => "JWT", + iss => $self->{api_key}, + exp => $exp, + }, $self->{api_secret}, 'HS256'); + + my $datas = { last_timestamp => time(), jwt_token => $jwt_token, expires_on => $exp }; + $options{statefile}->write(data => $datas); + } + + return $jwt_token; +} + +sub request_api { + my ($self, %options) = @_; + + if (!defined($self->{jwt_token})) { + $self->{jwt_token} = $self->get_jwt_token(statefile => $self->{cache}); + } + + $self->settings; + + $self->{output}->output_add(long_msg => "Query URL: '" . $self->{proto} . "://" . $self->{hostname} . + $self->{url_path} . $options{url_path} . "'", debug => 1); + + my $content = $self->{http}->request(url_path => $self->{url_path} . $options{url_path}); + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +1; + +__END__ + +=head1 NAME + +Zoom Rest API + +=head1 SYNOPSIS + +Zoom Rest API custom mode + +=head1 REST API OPTIONS + +Zoom Rest API + +=over 8 + +=item B<--hostname> + +Zoom API hostname (Default: 'api.zoom.us') + +=item B<--port> + +API port (Default: 443) + +=item B<--proto> + +Specify https if needed (Default: 'https') + +=item B<--url-path> + +API URL path (Default: '/v2') + +=item B<--api-key> + +JWT app API key. + +=item B<--api-secret> + +JWT app API secret. + +=item B<--timeout> + +Set HTTP timeout. + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/zoom/restapi/mode/listusers.pm b/centreon-plugins/apps/zoom/restapi/mode/listusers.pm new file mode 100644 index 000000000..e84af031c --- /dev/null +++ b/centreon-plugins/apps/zoom/restapi/mode/listusers.pm @@ -0,0 +1,121 @@ +# +# Copyright 2019 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 apps::zoom::restapi::mode::listusers; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + my @users; + + my $page = 1; + while (my $results = $options{custom}->request_api(url_path => '/users?page_size=30&page_number=' . $page)) { + push @users, @{$results->{users}}; + ($results->{page_number} < $results->{page_count}) ? $page++ : last; + } + + foreach my $user (@users) { + $self->{users}->{$user->{id}} = { + first_name => $user->{first_name}, + last_name => $user->{last_name}, + email => $user->{email}, + status => $user->{status}, + id => $user->{id}, + } + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $user (sort keys %{$self->{users}}) { + $self->{output}->output_add( + long_msg => sprintf("[id = %s] [first_name = %s] [last_name = %s] [email = %s] [status = %s]", + $self->{users}->{$user}->{id}, + $self->{users}->{$user}->{first_name}, + $self->{users}->{$user}->{last_name}, + $self->{users}->{$user}->{email}, + $self->{users}->{$user}->{status}) + ); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List users:' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['id', 'first_name', 'last_name', 'email', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $user (sort keys %{$self->{users}}) { + $self->{output}->add_disco_entry( + id => $self->{users}->{$user}->{id}, + first_name => $self->{users}->{$user}->{first_name}, + last_name => $self->{users}->{$user}->{last_name}, + email => $self->{users}->{$user}->{email}, + status => $self->{users}->{$user}->{status}, + ); + } +} + +1; + +__END__ + +=head1 MODE + +List users. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/apps/zoom/restapi/plugin.pm b/centreon-plugins/apps/zoom/restapi/plugin.pm new file mode 100644 index 000000000..0ff793adb --- /dev/null +++ b/centreon-plugins/apps/zoom/restapi/plugin.pm @@ -0,0 +1,55 @@ +# +# Copyright 2019 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 apps::zoom::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'list-users' => 'apps::zoom::restapi::mode::listusers', + ); + + $self->{custom_modes}{api} = 'apps::zoom::restapi::custom::api'; + return $self; +} + +sub init { + my ( $self, %options ) = @_; + + $self->SUPER::init(%options); +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Zoom. + +=cut diff --git a/centreon-plugins/centreon/common/adic/tape/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/adic/tape/snmp/mode/hardware.pm index 8c9f8fa56..c9cbea756 100644 --- a/centreon-plugins/centreon/common/adic/tape/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/adic/tape/snmp/mode/hardware.pm @@ -83,7 +83,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelinterference.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelinterference.pm index 4b76973df..1da7ca945 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelinterference.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelinterference.pm @@ -64,7 +64,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'filter-name:s' => { name => 'filter_name' }, 'filter-channel:s' => { name => 'filter_channel' }, diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelnoise.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelnoise.pm index 71fc8a0bb..bf5314fb9 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelnoise.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelnoise.pm @@ -55,7 +55,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'filter-name:s' => { name => 'filter_name' }, 'filter-channel:s' => { name => 'filter_channel' }, diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm index 45fdd6908..deb51d754 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm @@ -120,7 +120,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/apusers.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/apusers.pm index e1ec5044a..9d5f6be6b 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/apusers.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/apusers.pm @@ -168,7 +168,6 @@ sub new { 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' }, 'filter-ap:s' => { name => 'filter_ap' }, diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/cpu.pm index ad67d4a7d..1d26382e4 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/hardware.pm index 99d49e221..fe68e7b52 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/hardware.pm @@ -55,7 +55,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/memory.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/memory.pm index 9d0d67e88..ec568a281 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/apconnections.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/apconnections.pm index 3544adb43..77b3800bd 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/apconnections.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/apconnections.pm @@ -89,7 +89,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-ip-address:s" => { name => 'filter_ip_address' }, "filter-bssid:s" => { name => 'filter_bssid' }, @@ -210,7 +209,7 @@ __END__ =head1 MODE -Check AP connections. +Check AP connections (Deprecated). =over 8 diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/apssidstatistics.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/apssidstatistics.pm new file mode 100644 index 000000000..87a738ad5 --- /dev/null +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/apssidstatistics.pm @@ -0,0 +1,263 @@ +# +# Copyright 2019 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 centreon::common::aruba::snmp::mode::apssidstatistics; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ap', type => 3, cb_prefix_output => 'prefix_output_ap', cb_long_output => 'long_output', + message_multiple => 'All AP BSSID are ok', indent_long_output => ' ', + group => [ + { name => 'global', type => 0 }, + { name => 'essid', display_long => 1, cb_prefix_output => 'prefix_output_essid', + message_multiple => 'All ESSID are ok', type => 1 }, + { name => 'bssid', display_long => 1, cb_prefix_output => 'prefix_output_bssid', + message_multiple => 'All BSSID are ok', type => 1 }, + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'stations-associated', nlabel => 'stations.associated.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'Stations Associated: %d', + perfdatas => [ + { value => 'total_absolute', template => '%d', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{essid} = [ + { label => 'essid-stations-associated', nlabel => 'essid.stations.associated.count', set => { + key_values => [ { name => 'wlanAPEssidNumAssociatedStations' }, { name => 'wlanAPESSID' } ], + output_template => 'Associated Stations: %d', + perfdatas => [ + { value => 'wlanAPEssidNumAssociatedStations_absolute', template => '%d', + label_extra_instance => 1 }, + ], + } + }, + ]; + + $self->{maps_counters}->{bssid} = [ + { label => 'bssid-stations-associated', nlabel => 'bssid.stations.associated.count', set => { + key_values => [ { name => 'wlanAPBssidNumAssociatedStations' }, { name => 'wlanAPBSSID' }, + { name => 'wlanAPESSID' } ], + output_template => 'Associated Stations: %d', + perfdatas => [ + { value => 'wlanAPBssidNumAssociatedStations_absolute', template => '%d', + label_extra_instance => 1 }, + ], + } + }, + { label => 'channel-noise', nlabel => 'bssid.channel.noise.count', set => { + key_values => [ { name => 'apChannelNoise' }, { name => 'wlanAPBSSID' }, + { name => 'wlanAPESSID' } ], + output_template => 'Channel Noise: %d', + perfdatas => [ + { value => 'apChannelNoise_absolute', template => '%d', + label_extra_instance => 1 }, + ], + } + }, + { label => 'signal-noise-ratio', nlabel => 'bssid.signal.noise.ratio.count', set => { + key_values => [ { name => 'apSignalToNoiseRatio' }, { name => 'wlanAPBSSID' }, + { name => 'wlanAPESSID' } ], + output_template => 'Signal To Noise Ratio: %d', + perfdatas => [ + { value => 'apSignalToNoiseRatio_absolute', template => '%d', + label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_output_ap { + my ($self, %options) = @_; + + return "AP '" . $options{instance_value}->{wlanAPName} . "' [Mac: " . $options{instance_value}->{wlanAPMacAddress} . "] "; +} + +sub prefix_output_essid { + my ($self, %options) = @_; + + return "ESSID '" . $options{instance_value}->{wlanAPESSID} . "' "; +} + +sub prefix_output_bssid { + my ($self, %options) = @_; + + return "BSSID '" . $options{instance_value}->{wlanAPBSSID} . "' [ESSID: " . + $options{instance_value}->{wlanAPESSID} . "][Protocol: " . $options{instance_value}->{wlanAPBssidPhyType} . "] "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking AP '" . $options{instance_value}->{wlanAPName} . "' [Mac: " . $options{instance_value}->{wlanAPMacAddress} . "] "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-ap:s" => { name => 'filter_ap' }, + "filter-essid:s" => { name => 'filter_essid' }, + "filter-protocol:s" => { name => 'filter_protocol' }, + "filter-bssid:s" => { name => 'filter_bssid' }, + }); + + return $self; +} + +my %map_type = ( + 1 => '802.11a', 2 => '802.11b', 3 => '802.11g', + 4 => '802.11ag', 5 => 'wired' +); + +my $oid_wlsxSwitchAccessPointTable = '.1.3.6.1.4.1.14823.2.2.1.1.3.3.1'; + +my $mapping_switch = { + apChannelNoise => { oid => '.1.3.6.1.4.1.14823.2.2.1.1.3.3.1.13' }, + apSignalToNoiseRatio => { oid => '.1.3.6.1.4.1.14823.2.2.1.1.3.3.1.14' }, +}; + +my $oid_wlsxWlanAPBssidTable = '.1.3.6.1.4.1.14823.2.2.1.5.2.1.7.1'; + +my $mapping_wlan = { + wlanAPESSID => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.7.1.2' }, + wlanAPBssidPhyType => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.7.1.5', map => \%map_type }, + wlanAPBssidUpTime => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.7.1.9' }, + wlanAPBssidInactiveTime => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.7.1.10' }, + wlanAPBssidNumAssociatedStations => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.7.1.12' }, +}; + +my $oid_wlanAPName = '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.3'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_wlsxSwitchAccessPointTable, + start => $mapping_switch->{apChannelNoise}->{oid}, + end => $mapping_switch->{apSignalToNoiseRatio}->{oid} }, + { oid => $oid_wlsxWlanAPBssidTable, + start => $mapping_wlan->{wlanAPESSID}->{oid}, + end => $mapping_wlan->{wlanAPBssidNumAssociatedStations}->{oid} }, + { oid => $oid_wlanAPName }, + ], + nothing_quit => 1 + ); + + $self->{ap} = {}; + + foreach my $oid (keys %{$snmp_result->{$oid_wlsxWlanAPBssidTable}}) { + next if ($oid !~ /^$mapping_wlan->{wlanAPESSID}->{oid}\.(.*)/); + my $instance = $1; + + my $result = $options{snmp}->map_instance( + mapping => $mapping_wlan, + results => $snmp_result->{$oid_wlsxWlanAPBssidTable}, + instance => $instance + ); + + my @digits = split /\./, $instance; + $result->{wlanAPMacAddress} = join(':', unpack("(A2)*", unpack('H*', pack('C*', @digits[0..5])))); + $result->{wlanAPBSSID} = join(':', unpack("(A2)*", unpack('H*', pack('C*', @digits[7..12])))); + $result->{wlanAPName} = $snmp_result->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . join('.', @digits[0..5])}; + $result->{apChannelNoise} = $snmp_result->{$oid_wlsxSwitchAccessPointTable}->{$mapping_switch->{apChannelNoise}->{oid} . '.' . join('.', @digits[7..12])}; + $result->{apSignalToNoiseRatio} = $snmp_result->{$oid_wlsxSwitchAccessPointTable}->{$mapping_switch->{apSignalToNoiseRatio}->{oid} . '.' . join('.', @digits[7..12])}; + + if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' && + $result->{wlanAPName} !~ /$self->{option_results}->{filter_ap}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{wlanAPName} . "': no matching filter name.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_essid}) && $self->{option_results}->{filter_essid} ne '' && + $result->{wlanAPESSID} !~ /$self->{option_results}->{filter_essid}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{wlanAPESSID} . "': no matching filter essid.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_bssid}) && $self->{option_results}->{filter_bssid} ne '' && + $result->{wlanAPBSSID} !~ /$self->{option_results}->{filter_bssid}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{wlanAPESSID} . "': no matching filter bssid.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_protocol}) && $self->{option_results}->{filter_protocol} ne '' && + $result->{wlanAPBssidPhyType} !~ /$self->{option_results}->{filter_protocol}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{wlanAPBssidPhyType} . "': no matching filter protocol.", debug => 1); + next; + } + + $self->{ap}->{$result->{wlanAPName}}->{global}->{total} += $result->{wlanAPBssidNumAssociatedStations}; + $self->{ap}->{$result->{wlanAPName}}->{wlanAPName} = $result->{wlanAPName}; + $self->{ap}->{$result->{wlanAPName}}->{wlanAPMacAddress} = $result->{wlanAPMacAddress}; + $self->{ap}->{$result->{wlanAPName}}->{essid}->{$result->{wlanAPESSID}}->{wlanAPEssidNumAssociatedStations} += $result->{wlanAPBssidNumAssociatedStations}; + $self->{ap}->{$result->{wlanAPName}}->{essid}->{$result->{wlanAPESSID}}->{wlanAPESSID} = $result->{wlanAPESSID}; + $self->{ap}->{$result->{wlanAPName}}->{bssid}->{$result->{wlanAPBSSID}} = { %{$result} }; + } + + if (scalar(keys %{$self->{ap}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No AP found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check AP ESSID and BSSID statistics (WLSX-WLAN-MIB, WLSX-SWITCH-MIB). + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'stations-associated' (ESSID and BSSID), +'channel-noise', 'signal-noise-ratio' (BSSID). + +=item B<--critical-*> + +Threshold critical. +Can be: 'stations-associated' (ESSID and BSSID), +'channel-noise', 'signal-noise-ratio' (BSSID). + +=item B<--filter-*> + +Filter by 'ap', 'essid', 'protocol', 'bssid' (regexp can be used). + +=back + +=cut diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/apstatus.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/apstatus.pm new file mode 100644 index 000000000..7aa3beb41 --- /dev/null +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/apstatus.pm @@ -0,0 +1,273 @@ +# +# Copyright 2019 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 centreon::common::aruba::snmp::mode::apstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("Status is '%s' [Ip: %s][Group: %s][Location: %s]", + $self->{result_values}->{status}, + $self->{result_values}->{ip}, + $self->{result_values}->{group}, + $self->{result_values}->{location}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_wlanAPName'}; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_wlanAPStatus'}; + $self->{result_values}->{ip} = $options{new_datas}->{$self->{instance} . '_wlanAPIpAddress'}; + $self->{result_values}->{group} = $options{new_datas}->{$self->{instance} . '_wlanAPGroupName'}; + $self->{result_values}->{location} = $options{new_datas}->{$self->{instance} . '_wlanAPLocation'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_init => 'skip_global' }, + { name => 'ap', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All AP status are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'connected-current', nlabel => 'accesspoints.connected.current.count', set => { + key_values => [ { name => 'connected' } ], + output_template => 'Total connected AP: %d', + perfdatas => [ + { value => 'connected_absolute', template => '%d', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{ap} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'wlanAPName' }, { name => 'wlanAPIpAddress' }, { name => 'wlanAPGroupName' }, + { name => 'wlanAPLocation' }, { name => 'wlanAPStatus' } ], + 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 => \&catalog_status_threshold, + } + }, + { label => 'uptime', nlabel => 'accesspoint.uptime.seconds', set => { + key_values => [ { name => 'wlanAPUpTime' }, { name => 'wlanAPName' } ], + output_template => 'Uptime: %ss', + perfdatas => [ + { value => 'wlanAPUpTime_absolute', template => '%s', + unit => 's', label_extra_instance => 1, instance_use => 'wlanAPName_absolute' }, + ], + } + }, + { label => 'controller-bootstrap', nlabel => 'accesspoint.controller.bootstrap.count', set => { + key_values => [ { name => 'wlanAPNumBootstraps' }, { name => 'wlanAPName' } ], + output_template => 'Controller Bootstrap Count: %d', + perfdatas => [ + { value => 'wlanAPNumBootstraps_absolute', template => '%d', + label_extra_instance => 1, instance_use => 'wlanAPName_absolute' }, + ], + } + }, + { label => 'reboot', nlabel => 'accesspoint.reboot.count', set => { + key_values => [ { name => 'wlanAPNumReboots' }, { name => 'wlanAPName' } ], + output_template => 'Reboot Count: %d', + perfdatas => [ + { value => 'wlanAPNumReboots_absolute', template => '%d', + label_extra_instance => 1, instance_use => 'wlanAPName_absolute' }, + ], + } + }, + ]; +} + +sub skip_global { + my ($self, %options) = @_; + + scalar(keys %{$self->{ap}}) > 1 ? return(0) : return(1); +} + +sub prefix_output { + my ($self, %options) = @_; + + return "AP '" . $options{instance_value}->{wlanAPName} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-ip:s" => { name => 'filter_ip' }, + "filter-name:s" => { name => 'filter_name' }, + "filter-group:s" => { name => 'filter_group' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /up/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +my %map_status = ( + 1 => 'up', 2 => 'down' +); + +my $oid_wlsxWlanAPTable = '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1'; + +my $mapping_info = { + wlanAPIpAddress => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.2' }, + wlanAPName => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.3' }, + wlanAPGroupName=> { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.4' }, +}; +my $mapping_stat = { + wlanAPUpTime => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.12' }, + wlanAPLocation => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.14' }, + wlanAPStatus => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.20', map => \%map_status }, + wlanAPNumBootstraps => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.21' }, + wlanAPNumReboots => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.22' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global}->{connected} = 0; + $self->{ap} = {}; + + my $snmp_info = $options{snmp}->get_table( + oid => $oid_wlsxWlanAPTable, + start => $mapping_info->{wlanAPIpAddress}->{oid}, + end => $mapping_info->{wlanAPGroupName}->{oid}, + nothing_quit => 1 + ); + + foreach my $oid (keys %{$snmp_info}) { + next if ($oid !~ /^$mapping_info->{wlanAPIpAddress}->{oid}\.(.*)/); + my $instance = $1; + + my $result = $options{snmp}->map_instance( + mapping => $mapping_info, + results => $snmp_info, + instance => $instance + ); + + if (defined($self->{option_results}->{filter_ip}) && $self->{option_results}->{filter_ip} ne '' && + $result->{wlanAPIpAddress} !~ /$self->{option_results}->{filter_ip}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{wlanAPIpAddress} . "': no matching filter ip.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{wlanAPName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{wlanAPName} . "': no matching filter name.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' && + $result->{wlanAPGroupName} !~ /$self->{option_results}->{filter_group}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{wlanAPGroupName} . "': no matching filter group.", debug => 1); + next; + } + + $self->{ap}->{$instance} = { %{$result} }; + } + + if (scalar(keys %{$self->{ap}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No AP found."); + $self->{output}->option_exit(); + } + + $options{snmp}->load( + oids => [ + $mapping_stat->{wlanAPUpTime}->{oid}, + $mapping_stat->{wlanAPLocation}->{oid}, + $mapping_stat->{wlanAPStatus}->{oid}, + $mapping_stat->{wlanAPNumBootstraps}->{oid}, + $mapping_stat->{wlanAPNumReboots}->{oid}, + ], + instances => [ keys %{$self->{ap}} ], + instance_regexp => '^(.*)$' + ); + + my $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping_stat->{wlanAPUpTime}->{oid}\.(.*)/); + my $instance = $1; + + my $result = $options{snmp}->map_instance( + mapping => $mapping_stat, + results => $snmp_result, + instance => $instance + ); + + $self->{ap}->{$instance} = { %{$self->{ap}->{$instance}}, %{$result}, wlanAPUpTime => $result->{wlanAPUpTime} / 100 }; + $self->{global}->{connected}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check AP status (WLSX-WLAN-MIB). + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'connected-current' (global), 'uptime', +'controller-bootstrap', 'reboot', 'status' (per AP). +'status' can use special variables like: %{name}, +%{status}, %{ip}, %{group}, %{location} (Default: '') + +=item B<--critical-*> + +Threshold critical. +Can be: 'connected-current' (global), 'uptime', +'controller-bootstrap', 'reboot', 'status' (per AP). +'status' can use special variables like: %{name}, +%{status}, %{ip}, %{group}, %{location} (Default: '%{status} !~ /up/i') + +=item B<--filter-*> + +Filter by 'ip', 'name', 'group' (regexp can be used). + +=back + +=cut diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm index d01eaa6c0..3e19df873 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm @@ -150,13 +150,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-ip-address:s" => { name => 'filter_ip_address' }, - "filter-bssid:s" => { name => 'filter_bssid' }, - "filter-essid:s" => { name => 'filter_essid' }, - }); + $options{options}->add_options(arguments => { + "filter-ip-address:s" => { name => 'filter_ip_address' }, + "filter-bssid:s" => { name => 'filter_bssid' }, + "filter-essid:s" => { name => 'filter_essid' }, + }); return $self; } @@ -177,11 +175,11 @@ my %map_role = ( 3 => 'standbymaster', ); my $mapping = { - nUserUpTime => { oid => '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1.5' }, - nUserAuthenticationMethod => { oid => '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1.6', map => \%map_auth_method }, + nUserUpTime => { oid => '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1.5' }, + nUserAuthenticationMethod => { oid => '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1.6', map => \%map_auth_method }, }; my $mapping2 = { - nUserApBSSID => { oid => '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1.11' }, + nUserApBSSID => { oid => '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1.11' }, }; my $oid_wlsxUserEntry = '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1'; @@ -265,7 +263,7 @@ __END__ =head1 MODE -Check total users connected. +Check total users connected (Deprecated). =over 8 diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/components/fan.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/components/fan.pm index 3bcaf2f07..c69793b19 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/components/fan.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/components/fan.pm @@ -28,7 +28,6 @@ my %map_fan_status = ( 2 => 'inactive', ); -# In MIB 'aruba-systemext' my $mapping = { sysExtFanStatus => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.17.1.2', map => \%map_fan_status }, }; @@ -50,20 +49,28 @@ sub check { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_wlsxSysExtFanEntry}})) { next if ($oid !~ /^$mapping->{sysExtFanStatus}->{oid}\.(.*)$/); my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_wlsxSysExtFanEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance( + mapping => $mapping, + results => $self->{results}->{$oid_wlsxSysExtFanEntry}, + instance => $instance + ); next if ($self->check_filter(section => 'fan', instance => $instance)); $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is %s [instance: %s].", - $instance, $result->{sysExtFanStatus}, - $instance - )); + $self->{output}->output_add( + long_msg => sprintf("Fan '%s' status is %s [instance: %s].", + $instance, $result->{sysExtFanStatus}, + $instance + )); my $exit = $self->get_severity(section => 'fan', value => $result->{sysExtFanStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Fan '%s' status is %s", - $instance, $result->{sysExtFanStatus})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Fan '%s' status is %s", + $instance, + $result->{sysExtFanStatus} + )); } } } diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/components/module.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/components/module.pm index af117adda..12eaf3faa 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/components/module.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/components/module.pm @@ -47,7 +47,6 @@ my %map_module_status = ( 2 => 'inactive', ); -# In MIB 'aruba-systemext' my $mapping = { sysExtCardType => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.16.1.2', map => \%map_card_type }, sysExtCardStatus => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.16.1.12', map => \%map_module_status }, @@ -70,20 +69,29 @@ sub check { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_wlsxSysExtCardEntry}})) { next if ($oid !~ /^$mapping->{sysExtCardStatus}->{oid}\.(.*)$/); my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_wlsxSysExtCardEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance( + mapping => $mapping, + results => $self->{results}->{$oid_wlsxSysExtCardEntry}, + instance => $instance + ); next if ($self->check_filter(section => 'module', instance => $instance)); $self->{components}->{module}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Module '%s/%s' status is %s [instance: %s].", - $result->{sysExtCardType}, $instance, $result->{sysExtCardStatus}, - $instance - )); + $self->{output}->output_add( + long_msg => sprintf("Module '%s/%s' status is %s [instance: %s].", + $result->{sysExtCardType}, $instance, $result->{sysExtCardStatus}, + $instance + )); my $exit = $self->get_severity(section => 'module', value => $result->{sysExtCardStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Module '%s/%s' status is %s", - $result->{sysExtCardType}, $instance, $result->{sysExtCardStatus})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Module '%s/%s' status is %s", + $result->{sysExtCardType}, + $instance, + $result->{sysExtCardStatus}) + ); } } } diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/components/psu.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/components/psu.pm index 521b396b3..eadf46117 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/components/psu.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/components/psu.pm @@ -28,7 +28,6 @@ my %map_psu_status = ( 2 => 'inactive', ); -# In MIB 'aruba-systemext' my $mapping = { sysExtPowerSupplyStatus => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.18.1.2', map => \%map_psu_status }, }; @@ -50,20 +49,27 @@ sub check { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_wlsxSysExtPowerSupplyEntry}})) { next if ($oid !~ /^$mapping->{sysExtPowerSupplyStatus}->{oid}\.(.*)$/); my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_wlsxSysExtPowerSupplyEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance( + mapping => $mapping, + results => $self->{results}->{$oid_wlsxSysExtPowerSupplyEntry}, + instance => $instance + ); next if ($self->check_filter(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s [instance: %s].", - $instance, $result->{sysExtPowerSupplyStatus}, - $instance - )); + $self->{output}->output_add( + long_msg => sprintf("Power supply '%s' status is %s [instance: %s].", + $instance, $result->{sysExtPowerSupplyStatus}, + $instance + )); my $exit = $self->get_severity(section => 'psu', value => $result->{sysExtPowerSupplyStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Power supply '%s' status is %s", - $instance, $result->{sysExtPowerSupplyStatus})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Power supply '%s' status is %s", + $instance, $result->{sysExtPowerSupplyStatus} + )); } } } diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/controllerstatus.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/controllerstatus.pm new file mode 100644 index 000000000..24922f0ae --- /dev/null +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/controllerstatus.pm @@ -0,0 +1,219 @@ +# +# Copyright 2019 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 centreon::common::aruba::snmp::mode::controllerstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("Status is '%s', Role is '%s' [Ip: %s][Version: %s][Location: %s]", + $self->{result_values}->{status}, + $self->{result_values}->{role}, + $self->{result_values}->{ip}, + $self->{result_values}->{version}, + $self->{result_values}->{location}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchName'}; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchStatus'}; + $self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchRole'}; + $self->{result_values}->{ip} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchIPAddress'}; + $self->{result_values}->{version} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchSWVersion'}; + $self->{result_values}->{location} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchLocation'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_init => 'skip_global' }, + { name => 'controllers', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All controllers status are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'connected-current', nlabel => 'controllers.connected.current.count', set => { + key_values => [ { name => 'current' } ], + output_template => 'Total controllers: %d', + perfdatas => [ + { value => 'current_absolute', template => '%d', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{controllers} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'sysExtSwitchIPAddress' }, { name => 'sysExtSwitchName' }, + { name => 'sysExtSwitchLocation' }, { name => 'sysExtSwitchSWVersion' }, + { name => 'sysExtSwitchRole' }, { name => 'sysExtSwitchStatus' } ], + 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 => \&catalog_status_threshold, + } + }, + ]; +} + +sub skip_global { + my ($self, %options) = @_; + + scalar(keys %{$self->{controllers}}) > 1 ? return(0) : return(1); +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Controller '" . $options{instance_value}->{sysExtSwitchName} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + "filter-ip:s" => { name => 'filter_ip' }, + "filter-location:s" => { name => 'filter_location' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /active/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +my %map_status = ( + 1 => 'active', 2 => 'inactive' +); +my %map_role = ( + 1 => 'master', 2 => 'local', 3 => 'backupmaster' +); + +my $oid_wlsxSysExtSwitchListTable = '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1'; + +my $mapping = { + sysExtSwitchRole => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1.2', map => \%map_role }, + sysExtSwitchLocation=> { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1.3' }, + sysExtSwitchSWVersion => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1.4' }, + sysExtSwitchStatus => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1.5', map => \%map_status }, + sysExtSwitchName => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1.6' }, +}; +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_wlsxSysExtSwitchListTable, + start => $mapping->{sysExtSwitchRole}->{oid}, + end => $mapping->{sysExtSwitchName}->{oid}, + nothing_quit => 1 + ); + + $self->{global}->{current} = 0; + $self->{controllers} = {}; + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{sysExtSwitchRole}->{oid}\.(.*)/); + my $instance = $1; + + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance + ); + $result->{sysExtSwitchIPAddress} = $instance; + + if (defined($self->{option_results}->{filter_ip}) && $self->{option_results}->{filter_ip} ne '' && + $result->{sysExtSwitchIPAddress} !~ /$self->{option_results}->{filter_ip}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{sysExtSwitchIPAddress} . "': no matching filter ip.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{sysExtSwitchName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{sysExtSwitchName} . "': no matching filter name.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_location}) && $self->{option_results}->{filter_location} ne '' && + $result->{sysExtSwitchLocation} !~ /$self->{option_results}->{filter_location}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{sysExtSwitchLocation} . "': no matching filter location.", debug => 1); + next; + } + + $self->{controllers}->{$result->{sysExtSwitchName}} = { %{$result} }; + $self->{global}->{current}++; + } + + if (scalar(keys %{$self->{controllers}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No controller found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check controller status (WLSX-SYSTEMEXT-MIB). +(Works only on master controller). + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'connected-current' (global), 'status' (per controller). +'status' can use special variables like: %{name}, +%{status}, %{ip}, %{role}, %{location} (Default: '') + +=item B<--critical-*> + +Threshold critical. +Can be: 'connected-current' (global), 'status' (per controller). +'status' can use special variables like: %{name}, +%{status}, %{ip}, %{role}, %{location} (Default: '%{status} !~ /active/i') + +=item B<--filter-*> + +Filter by 'ip', 'name', 'location' (regexp can be used). + +=back + +=cut diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/cpu.pm index f707ac281..c6b25d2e2 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/cpu.pm @@ -20,79 +20,84 @@ package centreon::common::aruba::snmp::mode::cpu; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cpu', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All CPUs utilization are ok' }, + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'utilization', nlabel => 'cpu.utilization.percentage', set => { + key_values => [ { name => 'sysExtProcessorLoad' }, { name => 'sysExtProcessorDescr' } ], + output_template => 'Utilization %.2f%%', + perfdatas => [ + { label => 'utilization', value => 'sysExtProcessorLoad_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'sysExtProcessorDescr_absolute' }, + ], + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "CPU '" . $options{instance_value}->{sysExtProcessorDescr} . "' "; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + + $options{options}->add_options(arguments => {}); return $self; } -sub check_options { +my $oid_wlsxSysExtProcessorEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.13.1'; + +my $mapping = { + sysExtProcessorDescr => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.13.1.2' }, + sysExtProcessorLoad => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.13.1.3' }, +}; + +sub manage_selection { 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) = @_; - $self->{snmp} = $options{snmp}; - - my $oid_wlsxSysExtProcessorEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.13.1'; - my $oid_sysExtProcessorDescr = '.1.3.6.1.4.1.14823.2.2.1.2.1.13.1.2'; - my $oid_sysExtProcessorLoad = '.1.3.6.1.4.1.14823.2.2.1.2.1.13.1.3'; - my $result = $self->{snmp}->get_table(oid => $oid_wlsxSysExtProcessorEntry, nothing_quit => 1); - $self->{output}->output_add(severity => 'OK', - short_msg => 'All CPUs are ok.'); + my $snmp_result = $options{snmp}->get_table( + oid => $oid_wlsxSysExtProcessorEntry, + start => $mapping->{sysExtProcessorDescr}->{oid}, + end => $mapping->{sysExtProcessorLoad}->{oid}, + nothing_quit => 1 + ); - foreach my $oid (keys %$result) { - next if ($oid !~ /^$oid_sysExtProcessorLoad/); - $oid =~ /\.([0-9]+)$/; + $self->{cpu} = {}; + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{sysExtProcessorDescr}->{oid}\.(.*)/); my $instance = $1; - my $load = $result->{$oid}; - my $descr = $result->{$oid_sysExtProcessorDescr . '.' . $instance}; - my $exit = $self->{perfdata}->threshold_check(value => $load, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->output_add(long_msg => sprintf("CPU '%s': %.2f%% (1min)", $descr, - $load)); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("CPU '%s': %.2f%% (1min)", $descr, - $load)); - } - - $self->{output}->perfdata_add(label => "cpu_" . $instance, unit => '%', - value => $load, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance + ); + + $self->{cpu}->{$instance} = { %{$result} }; + } + + if (scalar(keys %{$self->{cpu}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "Cannot find CPU informations"); + $self->{output}->option_exit(); } - - $self->{output}->display(); - $self->{output}->exit(); } 1; @@ -101,15 +106,15 @@ __END__ =head1 MODE -Check cpu usage (over the last minute) (aruba-systemext). +Check CPU usage (over the last minute) (WLSX-SYSTEMEXT-MIB). =over 8 -=item B<--warning> +=item B<--warning-utilization> Threshold warning in percent. -=item B<--critical> +=item B<--critical-utilization> Threshold critical in percent. diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/discovery.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/discovery.pm new file mode 100644 index 000000000..779db97f4 --- /dev/null +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/discovery.pm @@ -0,0 +1,136 @@ +# +# Copyright 2019 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 centreon::common::aruba::snmp::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my %map_status = ( + 1 => 'up', 2 => 'down' +); + +my $oid_wlsxWlanAPTable = '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1'; + +my $mapping = { + wlanAPIpAddress => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.2' }, + wlanAPName => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.3' }, + wlanAPGroupName=> { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.4' }, + wlanAPUpTime => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.12' }, + wlanAPLocation => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.14' }, + wlanAPStatus => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.20', map => \%map_status }, + wlanAPNumBootstraps => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.21' }, + wlanAPNumReboots => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.22' }, +}; + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_wlsxWlanAPTable, + start => $mapping->{wlanAPIpAddress}->{oid}, + end => $mapping->{wlanAPNumReboots}->{oid}, + nothing_quit => 1 + ); + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{wlanAPIpAddress}->{oid}\.(.*)/); + my $instance = $1; + + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance + ); + + my %ap; + $ap{name} = $result->{wlanAPName}; + $ap{ip} = $result->{wlanAPIpAddress}; + $ap{group} = $result->{wlanAPGroupName}; + $ap{location} = $result->{wlanAPLocation}; + $ap{status} = $result->{wlanAPStatus}; + + push @disco_data, \%ap; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Resources discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/hardware.pm index 15ad1fa61..a8dc54337 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/hardware.pm @@ -63,10 +63,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => {}); return $self; } @@ -77,7 +74,7 @@ __END__ =head1 MODE -Check hardware (modules, fans, power supplies). +Check hardware (modules, fans, power supplies) (WLSX-SYSTEMEXT-MIB). =over 8 diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/license.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/license.pm new file mode 100644 index 000000000..a31e1fcf0 --- /dev/null +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/license.pm @@ -0,0 +1,180 @@ +# +# Copyright 2019 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 centreon::common::aruba::snmp::mode::license; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use Time::Local; + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("Status is '%s', Expires in '%s' [%s]", + $self->{result_values}->{flag}, + $self->{result_values}->{expires_human}, + $self->{result_values}->{expires_date}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{key} = $options{new_datas}->{$self->{instance} . '_sysExtLicenseKey'}; + $self->{result_values}->{flag} = $options{new_datas}->{$self->{instance} . '_sysExtLicenseFlags'}; + $self->{result_values}->{service} = $options{new_datas}->{$self->{instance} . '_sysExtLicenseService'}; + $self->{result_values}->{expires} = $options{new_datas}->{$self->{instance} . '_sysExtLicenseExpires'}; + $self->{result_values}->{expires_date} = $options{new_datas}->{$self->{instance} . '_sysExtLicenseExpires'}; + $self->{result_values}->{expires_human} = 'Never'; + + if ($self->{result_values}->{expires} !~ /Never/) { + my ($year, $mon, $mday, $hour, $min, $sec) = split(/[\s\-:]+/, $self->{result_values}->{expires}); + $self->{result_values}->{expires} = timelocal($sec, $min, $hour, $mday, $mon - 1, $year) - time(); + $self->{result_values}->{expires_human} = centreon::plugins::misc::change_seconds(value => $self->{result_values}->{expires}); + $self->{result_values}->{expires_human} = $self->{result_values}->{expires} = 0 if ($self->{result_values}->{expires} < 0); + } + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'license', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All licenses status are ok' }, + ]; + + $self->{maps_counters}->{license} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'sysExtLicenseKey' }, { name => 'sysExtLicenseFlags' }, + { name => 'sysExtLicenseService' }, { name => 'sysExtLicenseExpires' } ], + 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 => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "License '" . $options{instance_value}->{sysExtLicenseService} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', + default => '%{flag} !~ /enabled/i || (%{expires} ne "Never" && %{expires} < 86400)' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +my %map_flags = ( + 'E' => 'enabled', 'A' => 'auto-generated', 'R' => 'reboot-required' +); + +my $oid_wlsxSysExtSwitchLicenseTable = '.1.3.6.1.4.1.14823.2.2.1.2.1.20.1'; + +my $mapping = { + sysExtLicenseKey => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.20.1.2' }, + sysExtLicenseInstalled => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.20.1.3' }, + sysExtLicenseExpires => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.20.1.4' }, + sysExtLicenseFlags => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.20.1.5', map => \%map_flags }, + sysExtLicenseService => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.20.1.6' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_wlsxSysExtSwitchLicenseTable, + start => $mapping->{sysExtLicenseKey}->{oid}, + end => $mapping->{sysExtLicenseService}->{oid}, + nothing_quit => 1 + ); + + foreach my $oid (keys %{$snmp_result}) { + $snmp_result->{$oid} = centreon::plugins::misc::trim($snmp_result->{$oid}); + } + + $self->{license} = {}; + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{sysExtLicenseKey}->{oid}\.(.*)/); + my $instance = $1; + + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance + ); + + $self->{license}->{$result->{sysExtLicenseService}} = { %{$result} }; + } + + if (scalar(keys %{$self->{license}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No license found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check license (WLSX-SYSTEMEXT-MIB). + +=over 8 + +=item B<--warning-status> + +Threshold warning. +Can use special variables like:%{key}, +%{service}, %{flag}, %{expires} (Default: '') + +=item B<--critical-status> + +Threshold critical. +Can use special variables like: %{key}, +%{service}, %{flag}, %{expires} (Default: '%{flag} !~ /enabled/i || (%{expires} ne "Never" && %{expires} < 86400)') + +=back + +=cut diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/memory.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/memory.pm index 99a779277..b1847db7e 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/memory.pm @@ -20,103 +20,131 @@ package centreon::common::aruba::snmp::mode::memory; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub custom_usage_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + instances => $self->{instance}, + label => 'usage', nlabel => 'memory.usage.bytes', + unit => 'B', + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check( + value => $self->{result_values}->{prct_used}, + threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_sysExtMemorySize'} * 1024; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_sysExtMemoryUsed'} * 1024; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'memory', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All memory pools are ok' }, + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'usage', set => { + key_values => [ { name => 'sysExtMemoryUsed' }, { name => 'sysExtMemorySize' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Memory '" . $options{instance_value}->{display} . "' "; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => {}); return $self; } -sub check_options { +my $oid_wlsxSysExtMemoryEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1'; + +my $mapping = { + sysExtMemorySize => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1.2' }, # in KB + sysExtMemoryUsed => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1.3' }, # in KB +}; + +sub manage_selection { 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} . "'."); + my $snmp_result = $options{snmp}->get_table( + oid => $oid_wlsxSysExtMemoryEntry, + start => $mapping->{sysExtMemorySize}->{oid}, + end => $mapping->{sysExtMemoryUsed}->{oid}, + nothing_quit => 1 + ); + + $self->{memory} = {}; + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{sysExtMemorySize}->{oid}\.(.*)/); + my $instance = $1; + + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance + ); + + $self->{memory}->{$instance} = { %{$result}, display => $instance }; + } + + if (scalar(keys %{$self->{memory}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "Cannot find memory informations"); $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) = @_; - $self->{snmp} = $options{snmp}; - - my $oid_wlsxSysExtMemoryEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1'; - my $oid_sysExtMemoryUsed = '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1.3'; # in KB - my $oid_sysExtMemoryFree = '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1.4'; # in KB - my $result = $self->{snmp}->get_table(oid => $oid_wlsxSysExtMemoryEntry, nothing_quit => 1); - my $mode = 0; - - if (scalar(keys %$result) > 3) { - # Not Only Control Processor memory - $mode = 1; - $self->{output}->output_add(severity => 'OK', - short_msg => 'All pool memories are ok.'); - } - - foreach my $oid (keys %$result) { - next if ($oid !~ /^$oid_sysExtMemoryFree/); - $oid =~ /\.([0-9]+)$/; - - my $memory_name = ($mode == 1) ? $1 : 'Control Processor'; - my $memory_used = $result->{$oid_sysExtMemoryUsed . '.' . $1} * 1024; - my $memory_free =$result->{$oid_sysExtMemoryFree . '.' . $1} * 1024; - - my $total_size = $memory_used + $memory_free; - my $prct_used = $memory_used * 100 / $total_size; - my $prct_free = 100 - $prct_used; - - 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 => $memory_used); - my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $memory_free); - - $self->{output}->output_add(long_msg => sprintf("Memory '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $memory_name, - $total_value . " " . $total_unit, - $used_value . " " . $used_unit, $prct_used, - $free_value . " " . $free_unit, $prct_free)); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || $mode == 0) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Memory '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $memory_name, - $total_value . " " . $total_unit, - $used_value . " " . $used_unit, $prct_used, - $free_value . " " . $free_unit, $prct_free)); - } - - if ($mode == 1) { - $self->{output}->perfdata_add(label => "used_" . $memory_name, unit => 'B', - value => $memory_used, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size), - min => 0, max => $total_size); - } else { - $self->{output}->perfdata_add(label => "used", unit => 'B', - value => $memory_used, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size), - min => 0, max => $total_size); - } - } - - $self->{output}->display(); - $self->{output}->exit(); } 1; @@ -125,15 +153,15 @@ __END__ =head1 MODE -Check memory usage (aruba-systemext). +Check memory usage (WLSX-SYSTEMEXT-MIB). =over 8 -=item B<--warning> +=item B<--warning-usage> Threshold warning in percent. -=item B<--critical> +=item B<--critical-usage> Threshold critical in percent. diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/storage.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/storage.pm index 086d1b40a..6d3f315cf 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/storage.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/storage.pm @@ -20,119 +20,152 @@ package centreon::common::aruba::snmp::mode::storage; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my %map_storage_type = ( - 1 => 'ram', - 2 => 'flashMemory' -); +sub custom_usage_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + instances => $self->{instance}, + label => 'usage', nlabel => 'storage.usage.bytes', + unit => 'B', + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check( + value => $self->{result_values}->{prct_used}, + threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_sysExtStorageSize'} * 1024 * 1024; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_sysExtStorageUsed'} * 1024 * 1024; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'storage', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All storages are ok' }, + ]; + + $self->{maps_counters}->{storage} = [ + { label => 'usage', set => { + key_values => [ { name => 'sysExtStorageUsed' }, { name => 'sysExtStorageSize' }, + { name => 'sysExtStorageName' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Storage '" . $options{instance_value}->{sysExtStorageName} . "' "; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "filter-name:s" => { name => 'filter_name' }, - "filter-type:s" => { name => 'filter_type' }, - }); + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + "filter-type:s" => { name => 'filter_type' }, + }); return $self; } + +my $oid_wlsxSysExtStorageEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1'; -sub check_options { +my %map_storage_type = ( + 1 => 'ram', 2 => 'flashMemory' +); + +my $mapping = { + sysExtStorageType => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.2', map => \%map_storage_type }, + sysExtStorageSize => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.3' }, # MB + sysExtStorageUsed => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.4' }, # MB + sysExtStorageName => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.5' }, +}; + +sub manage_selection { 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) = @_; - $self->{snmp} = $options{snmp}; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_wlsxSysExtStorageEntry, + start => $mapping->{sysExtStorageType}->{oid}, + end => $mapping->{sysExtStorageName}->{oid}, + nothing_quit => 1 + ); - my $oid_wlsxSysExtStorageEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1'; - my $oid_sysExtStorageType = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.2'; - my $oid_sysExtStorageName = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.5'; - my $oid_sysExtStorageSize = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.3'; # MB - my $oid_sysExtStorageUsed = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.4'; # MB + $self->{storage} = {}; - my $storage_num = 0; - my $result = $self->{snmp}->get_table(oid => $oid_wlsxSysExtStorageEntry, nothing_quit => 1); - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All storages are ok.'); - - foreach my $oid (keys %$result) { - next if ($oid !~ /^$oid_sysExtStorageSize/); - $oid =~ /\.([0-9]+)$/; + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{sysExtStorageType}->{oid}\.(.*)/); + my $instance = $1; - my $name = $result->{$oid_sysExtStorageName . '.' . $1}; - my $type = $result->{$oid_sysExtStorageType . '.' . $1};; - my $total_used = $result->{$oid_sysExtStorageUsed . '.' . $1} * 1024 * 1024; - my $total_size = $result->{$oid_sysExtStorageSize . '.' . $1} * 1024 * 1024; + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance + ); if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $name !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => sprintf("Skipping storage '%s'.", $name)); + $result->{sysExtStorageName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => sprintf("Skipping storage '%s'.", $result->{sysExtStorageName}), debug => 1); next; } if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && - $map_storage_type{$type} !~ /$self->{option_results}->{filter_type}/i) { - $self->{output}->output_add(long_msg => sprintf("Skipping storage '%s'.", $name)); + $result->{sysExtStorageType} !~ /$self->{option_results}->{filter_type}/i) { + $self->{output}->output_add(long_msg => sprintf("Skipping storage '%s'.", $result->{sysExtStorageType}), debug => 1); next; } - $storage_num++; - my $total_free = $total_size - $total_used; - my $prct_used = $total_used * 100 / $total_size; - my $prct_free = 100 - $prct_used; - - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $total_size); - my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $total_used); - my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $total_free); - - $self->{output}->output_add(long_msg => sprintf("Storage '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name, - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $prct_used, - $total_free_value . " " . $total_free_unit, $prct_free)); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Storage '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name, - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $prct_used, - $total_free_value . " " . $total_free_unit, $prct_free)); - } - - $self->{output}->perfdata_add(label => 'used_' . $name, unit => 'B', - value => $total_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->{storage}->{$result->{sysExtStorageName}} = { %{$result} }; } - - if ($storage_num == 0) { - $self->{output}->add_option_msg(short_msg => "No storage information found (maybe your filters)"); + + if (scalar(keys %{$self->{storage}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No storage found"); $self->{output}->option_exit(); } - - $self->{output}->display(); - $self->{output}->exit(); } 1; @@ -141,15 +174,15 @@ __END__ =head1 MODE -Check storage device usage (aruba-systemext). +Check storage device usage (WLSX-SYSTEMEXT-MIB). =over 8 -=item B<--warning> +=item B<--warning-usage> Threshold warning in percent. -=item B<--critical> +=item B<--critical-usage> Threshold critical in percent. diff --git a/centreon-plugins/centreon/common/avaya/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/avaya/snmp/mode/cpu.pm index 6be4b2111..7e044d02e 100644 --- a/centreon-plugins/centreon/common/avaya/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/avaya/snmp/mode/cpu.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/avaya/snmp/mode/memory.pm b/centreon-plugins/centreon/common/avaya/snmp/mode/memory.pm index acf7cd249..2f2c466f3 100644 --- a/centreon-plugins/centreon/common/avaya/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/avaya/snmp/mode/memory.pm @@ -105,7 +105,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/bluearc/snmp/mode/clusterstatus.pm b/centreon-plugins/centreon/common/bluearc/snmp/mode/clusterstatus.pm index d048178b8..dbc06e813 100644 --- a/centreon-plugins/centreon/common/bluearc/snmp/mode/clusterstatus.pm +++ b/centreon-plugins/centreon/common/bluearc/snmp/mode/clusterstatus.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/centreon/common/bluearc/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/bluearc/snmp/mode/hardware.pm index 6227a2de1..66e3422ed 100644 --- a/centreon-plugins/centreon/common/bluearc/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/bluearc/snmp/mode/hardware.pm @@ -96,7 +96,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/bluearc/snmp/mode/volumeusage.pm b/centreon-plugins/centreon/common/bluearc/snmp/mode/volumeusage.pm index d0c7553e9..fa5d74a24 100644 --- a/centreon-plugins/centreon/common/bluearc/snmp/mode/volumeusage.pm +++ b/centreon-plugins/centreon/common/bluearc/snmp/mode/volumeusage.pm @@ -139,7 +139,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /needsChecking/i' }, diff --git a/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/cpu.pm index 547243c82..5726dacfb 100644 --- a/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/cpu.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/hardware.pm index e2c35678f..829a4edcb 100644 --- a/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/hardware.pm @@ -70,7 +70,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/memory.pm b/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/memory.pm index 625cd60d0..60f3b94d1 100644 --- a/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/broadcom/fastpath/snmp/mode/memory.pm @@ -93,7 +93,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/broadcom/megaraid/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/broadcom/megaraid/snmp/mode/hardware.pm index bf382cd7b..e81201d90 100644 --- a/centreon-plugins/centreon/common/broadcom/megaraid/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/broadcom/megaraid/snmp/mode/hardware.pm @@ -82,7 +82,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/cpu.pm index fc630974e..08926e208 100644 --- a/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/cpu.pm @@ -58,7 +58,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/hardware.pm index e9e853260..9c37d38ab 100644 --- a/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/hardware.pm @@ -63,7 +63,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/keysexpire.pm b/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/keysexpire.pm deleted file mode 100644 index 8c774331c..000000000 --- a/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/keysexpire.pm +++ /dev/null @@ -1,118 +0,0 @@ -# -# Copyright 2019 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 centreon::common::cisco::ironport::snmp::mode::keysexpire; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'keys', type => 1, cb_prefix_output => 'prefix_keys_output', message_multiple => 'All keys are ok' } - ]; - - $self->{maps_counters}->{keys} = [ - { label => 'seconds', set => { - key_values => [ { name => 'seconds' }, { name => 'msg' }, { name => 'display' } ], - output_template => '%s remaining before expiration', - output_use => 'msg_absolute', - closure_custom_perfdata => sub { return 0; }, - } - }, - ]; -} - -sub prefix_keys_output { - my ($self, %options) = @_; - - return "Key '" . $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 => { - }); - - return $self; -} - -my $mapping = { - keyDescription => { oid => '.1.3.6.1.4.1.15497.1.1.1.12.1.2' }, - keyIsPerpetual => { oid => '.1.3.6.1.4.1.15497.1.1.1.12.1.3' }, - keySecondsUntilExpire => { oid => '.1.3.6.1.4.1.15497.1.1.1.12.1.4' }, -}; -my $oid_keyExpirationEntry = '.1.3.6.1.4.1.15497.1.1.1.12.1'; - -sub manage_selection { - my ($self, %options) = @_; - - $self->{keys} = {}; - my $snmp_result = $options{snmp}->get_table(oid => $oid_keyExpirationEntry, - nothing_quit => 1); - - foreach my $oid (keys %{$snmp_result}) { - next if ($oid !~ /^$mapping->{keySecondsUntilExpire}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - next if ($result->{keyIsPerpetual} == 1); - - $self->{keys}->{$instance} = { - display => $result->{keyDescription}, - seconds => $result->{keySecondsUntilExpire}, - msg => centreon::plugins::misc::change_seconds(value => $result->{keySecondsUntilExpire}), - }; - } - - if (scalar(keys %{$self->{keys}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No key found."); - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check number of seconds remaining before the expiration of keys. - -=over 8 - -=item B<--warning-seconds> - -Threshold warning in seconds. - -=item B<--critical-seconds> - -Threshold critical in seconds. - -=back - -=cut - diff --git a/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/mailusage.pm b/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/mailusage.pm new file mode 100644 index 000000000..32ed1e314 --- /dev/null +++ b/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/mailusage.pm @@ -0,0 +1,277 @@ +# +# Copyright 2019 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 centreon::common::cisco::ironport::snmp::mode::mailusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'queue status: ' . $self->{result_values}->{queue_status} . ' [resource conservation: ' . $self->{result_values}->{resource_conservation} . ']'; + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'keys', type => 1, cb_prefix_output => 'prefix_keys_output', message_multiple => 'All keys are ok' }, + { name => 'updates', type => 1, cb_prefix_output => 'prefix_updates_output', message_multiple => 'All service updates are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'queue_status' }, { name => 'resource_conservation' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'messages-workqueue', nlabel => 'system.queue.messages.workqueue.count', display_ok => 0, set => { + key_values => [ { name => 'msgs_in_work_queue' } ], + output_template => 'messages in work queue: %s', + perfdatas => [ + { value => 'msgs_in_work_queue_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'dns-requests-outstanding', nlabel => 'system.dns.requests.outstanding.count', display_ok => 0, set => { + key_values => [ { name => 'outstandingDNSRequests' } ], + output_template => 'dns requests with no reply: %s', + perfdatas => [ + { value => 'outstandingDNSRequests_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'dns-requests-pending', nlabel => 'system.dns.requests.pending.count', display_ok => 0, set => { + key_values => [ { name => 'pendingDNSRequests' } ], + output_template => 'dns requests pending: %s', + perfdatas => [ + { value => 'pendingDNSRequests_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'fd-opened', nlabel => 'system.fd.opened.count', display_ok => 0, set => { + key_values => [ { name => 'openFilesOrSockets' } ], + output_template => 'fd opened: %s', + perfdatas => [ + { value => 'openFilesOrSockets_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'threads-mail', nlabel => 'system.threads.mail.count', display_ok => 0, set => { + key_values => [ { name => 'mailTransferThreads' } ], + output_template => 'threads mail: %s', + perfdatas => [ + { value => 'mailTransferThreads_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{updates} = [ + { label => 'update-failures', nlabel => 'service.update.failures.count', set => { + key_values => [ { name => 'updateFailures', diff => 1 }, { name => 'updateServiceName' } ], + output_template => 'update failures: %s', + perfdatas => [ + { value => 'updateFailures_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'updateServiceName_absolute' }, + ], + } + }, + ]; + + $self->{maps_counters}->{keys} = [ + { label => 'time-expiration', nlabel => 'key.time.expiration.seconds', set => { + key_values => [ { name => 'seconds' }, { name => 'msg' }, { name => 'display' } ], + output_template => '%s remaining before expiration', + output_use => 'msg_absolute', + perfdatas => [ + { value => 'seconds_absolute', template => '%s', + unit => 's', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_keys_output { + my ($self, %options) = @_; + + return "Key '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_updates_output { + my ($self, %options) = @_; + + return "Service '" . $options{instance_value}->{updateServiceName} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{resource_conservation} =~ /memoryShortage|queueSpaceShortage/i || %{queue_status} =~ /queueSpaceShortage/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{resource_conservation} =~ /queueFull/i || %{queue_status} =~ /queueFull/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +my $mapping = { + keyDescription => { oid => '.1.3.6.1.4.1.15497.1.1.1.12.1.2' }, + keyIsPerpetual => { oid => '.1.3.6.1.4.1.15497.1.1.1.12.1.3' }, + keySecondsUntilExpire => { oid => '.1.3.6.1.4.1.15497.1.1.1.12.1.4' }, +}; +my $oid_keyExpirationEntry = '.1.3.6.1.4.1.15497.1.1.1.12.1'; + +my $mapping2 = { + updateServiceName => { oid => '.1.3.6.1.4.1.15497.1.1.1.13.1.2' }, + updateFailures => { oid => '.1.3.6.1.4.1.15497.1.1.1.13.1.4' }, +}; +my $oid_updateEntry = '.1.3.6.1.4.1.15497.1.1.1.13.1'; + +my $map_conservation_reason = { + 1 => 'noResourceConservation', + 2 => 'memoryShortage', + 3 => 'queueSpaceShortage', + 4 => 'queueFull' +}; +my $map_queue_status = { + 1 => 'queueSpaceAvailable', + 2 => 'queueSpaceShortage', + 3 => 'queueFull', +}; + +my $mapping3 = { + queueAvailabilityStatus => { oid => '.1.3.6.1.4.1.15497.1.1.1.5', map => $map_queue_status }, + resourceConservationReason => { oid => '.1.3.6.1.4.1.15497.1.1.1.6', map => $map_conservation_reason }, + workQueueMessages => { oid => '.1.3.6.1.4.1.15497.1.1.1.11' }, + outstandingDNSRequests => { oid => '.1.3.6.1.4.1.15497.1.1.1.15' }, + pendingDNSRequests => { oid => '.1.3.6.1.4.1.15497.1.1.1.16' }, + openFilesOrSockets => { oid => '.1.3.6.1.4.1.15497.1.1.1.19' }, + mailTransferThreads => { oid => '.1.3.6.1.4.1.15497.1.1.1.20' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result2 = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping3)) ], nothing_quit => 1 + ); + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_keyExpirationEntry }, + { oid => $oid_updateEntry }, + ], + ); + + $self->{updates} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_updateEntry}}) { + next if ($oid !~ /^$mapping2->{updateServiceName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_updateEntry}, instance => $instance); + + $self->{updates}->{$instance} = { %$result }; + } + + $self->{keys} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_keyExpirationEntry}}) { + next if ($oid !~ /^$mapping->{keySecondsUntilExpire}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_keyExpirationEntry}, instance => $instance); + next if ($result->{keyIsPerpetual} == 1); + + $self->{keys}->{$instance} = { + display => $result->{keyDescription}, + seconds => $result->{keySecondsUntilExpire}, + msg => centreon::plugins::misc::change_seconds(value => $result->{keySecondsUntilExpire}), + }; + } + + my $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result2, instance => 0); + $self->{global} = { + queue_status => $result->{queueAvailabilityStatus}, + resource_conservation => $result->{resourceConservationReason}, + msgs_in_work_queue => $result->{workQueueMessages}, + outstandingDNSRequests => $result->{outstandingDNSRequests}, + pendingDNSRequests => $result->{pendingDNSRequests}, + openFilesOrSockets => $result->{openFilesOrSockets}, + mailTransferThreads => $result->{mailTransferThreads}, + }; + + $self->{cache_name} = "cisco_ironport_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check email security usage. + +=over 8 + +=item B<--unknown-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{queue_status}, %{resource_conservation} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{resource_conservation} =~ /memoryShortage|queueSpaceShortage/i || %{queue_status} =~ /queueSpaceShortage/i'). +Can used special variables like: %{queue_status}, %{resource_conservation} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{resource_conservation} =~ /queueFull/i || %{queue_status} =~ /queueFull/i'). +Can used special variables like: %{queue_status}, %{resource_conservation} + +=item B<--warning-*> B<--critical-*> + +Warning threshold. +Can be: 'messages-workqueue', 'dns-requests-outstanding', +'dns-requests-pending', 'fd-opened', 'threads-mail', +'update-failures', 'time-expiration'. + +=back + +=cut + diff --git a/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/memory.pm b/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/memory.pm index 62448af7a..1ae2b07d2 100644 --- a/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { 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', }, diff --git a/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/proxyusage.pm b/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/proxyusage.pm index 4ed2080b9..fdf7585df 100644 --- a/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/proxyusage.pm +++ b/centreon-plugins/centreon/common/cisco/ironport/snmp/mode/proxyusage.pm @@ -163,7 +163,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/cisco/ironport/xmlapi/mode/systemusage.pm b/centreon-plugins/centreon/common/cisco/ironport/xmlapi/mode/systemusage.pm index 1a3b8f825..7b8a23261 100644 --- a/centreon-plugins/centreon/common/cisco/ironport/xmlapi/mode/systemusage.pm +++ b/centreon-plugins/centreon/common/cisco/ironport/xmlapi/mode/systemusage.pm @@ -170,7 +170,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'hostname:s' => { name => 'hostname' }, 'port:s' => { name => 'port', }, @@ -181,7 +180,7 @@ sub new { 'timeout:s' => { name => 'timeout' }, 'unknown-http-status:s' => { name => 'unknown_http_status' }, 'warning-http-status:s' => { name => 'warning_http_status' }, - 'critical-http-status:s' => { name => 'critical_http__status' }, + 'critical-http-status:s' => { name => 'critical_http_status' }, 'warning-system-status:s' => { name => 'warning_system_status', default => '' }, 'critical-system-status:s' => { name => 'critical_system_status', default => '%{system_status} !~ /online/i' }, }); diff --git a/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/cpu.pm index d0c44a44c..153e7ab70 100644 --- a/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '' }, diff --git a/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/environment.pm b/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/environment.pm index 66c24a837..034b4df83 100644 --- a/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/environment.pm +++ b/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/environment.pm @@ -67,7 +67,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/configuration.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/configuration.pm index 6f31ec552..780df2d16 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/configuration.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/configuration.pm @@ -83,7 +83,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/cpu.pm index 0ac880512..2364fdd4d 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/cpu.pm @@ -111,7 +111,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'check-order:s' => { name => 'check_order', default => 'process,old_sys,system_ext' }, }); diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm index a137e5f45..c97f6ba1a 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm @@ -137,7 +137,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/hsrp.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/hsrp.pm index 0928f6b7e..16203624b 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/hsrp.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/hsrp.pm @@ -47,11 +47,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "role:s" => { name => 'role', default => 'primary' }, - }); + $options{options}->add_options(arguments => { + 'role:s' => { name => 'role', default => 'primary' }, + 'filter-vrid:s' => { name => 'filter_vrid' }, + }); + return $self; } @@ -73,18 +73,26 @@ sub run { my $oid_cHsrpGrpStandbyState = ".1.3.6.1.4.1.9.9.106.1.2.1.1.15"; # HSRP Oper Status my $oid_cHsrpGrpEntryRowStatus = ".1.3.6.1.4.1.9.9.106.1.2.1.1.17"; # HSRP Admin Status - my $results = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_cHsrpGrpStandbyState }, - { oid => $oid_cHsrpGrpEntryRowStatus }, - ], - nothing_quit => 1); + my $results = $self->{snmp}->get_multiple_table(oids => + [ + { oid => $oid_cHsrpGrpStandbyState }, + { oid => $oid_cHsrpGrpEntryRowStatus }, + ], + nothing_quit => 1 + ); $self->{output}->output_add(severity => 'OK', short_msg => sprintf("Router is in its expected state : '%s'", $self->{option_results}->{role})); foreach my $oid (keys %{$results->{$oid_cHsrpGrpStandbyState}}) { $oid =~ /(\d+\.\d+)$/; my $vrid = $1; - + + if (defined($self->{option_results}->{filter_vrid}) && $self->{option_results}->{filter_vrid} ne '' && + $vrid !~ /$self->{option_results}->{filter_vrid}/) { + $self->{output}->output_add(long_msg => "skipping vrid '" . $vrid . "': no matching filter.", debug => 1); + next; + } + my $operState = $results->{$oid_cHsrpGrpEntryRowStatus}->{$oid_cHsrpGrpEntryRowStatus . "." . $vrid}; my $adminState = $results->{$oid_cHsrpGrpStandbyState}->{$oid}; @@ -121,6 +129,10 @@ Check Cisco HSRP (CISCO-HSRP-MIB). Trigger a critical if not in the expected sta =over 8 +=item B<--filter-vrid> + +Filter VRID (can be a regexp). + =item B<--role> If role is 'primary', an error if HSRPs are 'standby' states. diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/interfaces.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/interfaces.pm index 7c4c5dd8f..91d97c5c4 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/interfaces.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/interfaces.pm @@ -25,6 +25,67 @@ use base qw(snmp_standard::mode::interfaces); use strict; use warnings; +sub custom_status_output { + my ($self, %options) = @_; + my $msg = 'Status : ' . $self->{result_values}->{opstatus} . ' (admin: ' . $self->{result_values}->{admstatus} . ')'; + if (defined($self->{instance_mode}->{option_results}->{add_duplex_status})) { + $msg .= ' (duplex: ' . $self->{result_values}->{duplexstatus} . ')'; + } + if (defined($self->{instance_mode}->{option_results}->{add_err_disable})) { + $msg .= ' (error disable: ' . $self->{result_values}->{errdisable} . ')'; + } + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->SUPER::custom_status_calc(%options); + $self->{result_values}->{errdisable} = $options{new_datas}->{$self->{instance} . '_errdisable'}; + return 0; +} + +sub set_key_values_status { + my ($self, %options) = @_; + + return [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'duplexstatus' }, { name => 'errdisable' }, { name => 'display' } ]; +} + +sub set_oids_status { + my ($self, %options) = @_; + + $self->SUPER::set_oids_status(%options); + $self->{oid_cErrDisableIfStatusCause} = '.1.3.6.1.4.1.9.9.548.1.3.1.1.2'; + $self->{oid_cErrDisableIfStatusCause_mapping} = { + 1 => 'udld', 2 => 'bpduGuard', 3 => 'channelMisconfig', + 4 => 'pagpFlap', 5 => 'dtpFlap', 6 => 'linkFlap', + 7 => 'l2ptGuard', 8 => 'dot1xSecurityViolation', + 9 => 'portSecurityViolation', 10 => 'gbicInvalid', + 11 => 'dhcpRateLimit', 12 => 'unicastFlood', + 13 => 'vmps', 14 => 'stormControl', 15 => 'inlinePower', + 16 => 'arpInspection', 17 => 'portLoopback', + 18 => 'packetBuffer', 19 => 'macLimit', 20 => 'linkMonitorFailure', + 21 => 'oamRemoteFailure', 22 => 'dot1adIncompEtype', 23 => 'dot1adIncompTunnel', + 24 => 'sfpConfigMismatch', 25 => 'communityLimit', 26 => 'invalidPolicy', + 27 => 'lsGroup', 28 => 'ekey', 29 => 'portModeFailure', + 30 => 'pppoeIaRateLimit', 31 => 'oamRemoteCriticalEvent', + 32 => 'oamRemoteDyingGasp', 33 => 'oamRemoteLinkFault', + 34 => 'mvrp', 35 => 'tranceiverIncomp', 36 => 'other', + 37 => 'portReinitLimitReached', 38 => 'adminRxBBCreditPerfBufIncomp', + 39 => 'ficonNotEnabled', 40 => 'adminModeIncomp', 41 => 'adminSpeedIncomp', + 42 => 'adminRxBBCreditIncomp', 43 => 'adminRxBufSizeIncomp', + 44 => 'eppFailure', 45 => 'osmEPortUp', 46 => 'osmNonEPortUp', + 47 => 'udldUniDir', 48 => 'udldTxRxLoop', 49 => 'udldNeighbourMismatch', + 50 => 'udldEmptyEcho', 51 => 'udldAggrasiveModeLinkFailed', + 52 => 'excessivePortInterrupts', 53 => 'channelErrDisabled', + 54 => 'hwProgFailed', 55 => 'internalHandshakeFailed', + 56 => 'stpInconsistencyOnVpcPeerLink', 57 => 'stpPortStateFailure', + 58 => 'ipConflict', 59 => 'multipleMSapIdsRcvd', + 60 => 'oneHundredPdusWithoutAck', 61 => 'ipQosCompatCheckFailure', + }; +} + sub set_oids_errors { my ($self, %options) = @_; @@ -56,7 +117,11 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + + $options{options}->add_options(arguments => { + 'add-err-disable' => { name => 'add_err_disable' }, + }); + return $self; } @@ -74,6 +139,15 @@ sub load_errors { ); } +sub load_status { + my ($self, %options) = @_; + + $self->SUPER::load_status(%options); + if (defined($self->{option_results}->{add_err_disable})) { + $self->{snmp_errdisable_result} = $self->{snmp}->get_table(oid => $self->{oid_cErrDisableIfStatusCause}); + } +} + sub add_result_errors { my ($self, %options) = @_; @@ -84,6 +158,31 @@ sub add_result_errors { $self->{int}->{$options{instance}}->{incrc} = $self->{results}->{$self->{oid_ifInCrc} . '.' . $options{instance}}; } +sub add_result_status { + my ($self, %options) = @_; + + $self->SUPER::add_result_status(%options); + + $self->{int}->{$options{instance}}->{errdisable} = ''; + if (defined($self->{option_results}->{add_err_disable})) { + my $append = ''; + # ifIndex.vlanIndex (if physical interface, vlanIndex = 0) + foreach (keys %{$self->{snmp_errdisable_result}}) { + next if (! /^$self->{oid_cErrDisableIfStatusCause}\.$options{instance}\.(.*)/); + if ($1 == 0) { + $self->{int}->{$options{instance}}->{errdisable} = $self->{oid_cErrDisableIfStatusCause_mapping}->{ $self->{snmp_errdisable_result}->{$_} }; + last; + } + + $self->{int}->{$options{instance}}->{errdisable} .= $append . 'vlan' . $1 . ':' . $self->{oid_cErrDisableIfStatusCause_mapping}->{ $self->{snmp_errdisable_result}->{$_} }; + $append = ','; + } + } + + $self->{int}->{$options{instance}}->{errdisable} = '-' + if ($self->{int}->{$options{instance}}->{errdisable} eq ''); +} + 1; __END__ @@ -106,6 +205,10 @@ Check interface status. Check duplex status (with --warning-status and --critical-status). +=item B<--add-err-disable> + +Check error disable (with --warning-status and --critical-status). + =item B<--add-traffic> Check interface traffic. @@ -129,24 +232,16 @@ Check interface data volume between two checks (not supposed to be graphed, usef =item B<--warning-status> Set warning threshold for status. -Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{errdisable}, %{display} =item B<--critical-status> Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). -Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{errdisable}, %{display} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', -'in-traffic', 'out-traffic', 'in-crc', 'in-error', 'in-discard', 'out-error', 'out-discard', -'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), -'speed' (b/s). - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', 'in-traffic', 'out-traffic', 'in-crc', 'in-error', 'in-discard', 'out-error', 'out-discard', 'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsectunnel.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsectunnel.pm index 284f57958..92c64a82b 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsectunnel.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsectunnel.pm @@ -222,7 +222,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-sa:s" => { name => 'filter_sa' }, diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsla.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsla.pm index 0951d9a8b..c33d8e159 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsla.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsla.pm @@ -800,7 +800,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-tag:s" => { name => 'filter_tag', default => '.*' }, diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm index db8381a4b..254757dbe 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm @@ -121,7 +121,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'filter-pool:s' => { name => 'filter_pool' }, 'check-order:s' => { name => 'check_order', default => 'enhanced_pool,pool,process,system_ext' }, @@ -226,11 +225,12 @@ sub check_memory_enhanced_pool { oids => $oids, return_type => 1 ); - + + my $physical_array = {}; foreach my $oid (keys %{$snmp_result}) { - next if ($oid !~ /^$mapping_enh_memory_pool->{cempMemPoolName}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping_enh_memory_pool, results => $snmp_result, instance => $instance); + next if ($oid !~ /^$mapping_enh_memory_pool->{cempMemPoolName}->{oid}\.(.*?)\.(.*)$/); + my ($physical_index, $mem_index) = ($1, $2); + my $result = $self->{snmp}->map_instance(mapping => $mapping_enh_memory_pool, results => $snmp_result, instance => $physical_index . '.' . $mem_index); $self->{checked_memory} = 1; if (defined($self->{option_results}->{filter_pool}) && $self->{option_results}->{filter_pool} ne '' && @@ -241,13 +241,36 @@ sub check_memory_enhanced_pool { my $used = defined($result->{cempMemPoolHCUsed}) ? $result->{cempMemPoolHCUsed} : $result->{cempMemPoolUsed}; my $free = defined($result->{cempMemPoolHCFree}) ? $result->{cempMemPoolHCFree} : $result->{cempMemPoolFree}; - $self->{memory}->{$instance} = { + if ($used + $free <= 0) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{cempMemPoolName} . "': no total.", debug => 1); + next; + } + + $physical_array->{$physical_index} = 1; + $self->{memory}->{$physical_index . '.' . $mem_index} = { display => $result->{cempMemPoolName}, total => $used + $free, used => $used, prct_used => -1, + physical_index => $physical_index, }; } + + if (scalar(keys %$physical_array) > 0) { + my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7'; + $self->{snmp}->load( + oids => [$oid_entPhysicalName], + instances => [keys %$physical_array], + instance_regexp => '^(.*)$' + ); + $snmp_result = $self->{snmp}->get_leef(); + foreach (keys %{$self->{memory}}) { + if (defined($snmp_result->{ $oid_entPhysicalName . '.' . $self->{memory}->{$_}->{physical_index} })) { + $self->{memory}->{$_}->{display} = + $snmp_result->{ $oid_entPhysicalName . '.' . $self->{memory}->{$_}->{physical_index} } . '_' . $self->{memory}->{$_}->{display}; + } + } + } } my $mapping_memory_process = { diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memoryflash.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memoryflash.pm index adc1690da..4b6af277d 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memoryflash.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memoryflash.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm index aa2d85318..a13d20ed2 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm @@ -179,7 +179,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-source:s" => { name => 'filter_source' }, "oid-filter:s" => { name => 'oid_filter', default => 'ifname' }, diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm index 3cd17db54..745a64f4f 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm @@ -206,7 +206,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/stack.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/stack.pm index 55573d40d..35a35bc8f 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/stack.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/stack.pm @@ -24,7 +24,14 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_stack_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("Stack status is '%s'", $self->{result_values}->{stack_status}); + return $msg; +} sub custom_status_output { my ($self, %options) = @_; @@ -33,15 +40,6 @@ sub custom_status_output { return $msg; } -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; - $self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'}; - $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; - return 0; -} - sub prefix_global_output { my ($self, %options) = @_; @@ -58,10 +56,22 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ + { name => 'stack', type => 0 }, { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, { name => 'members', type => 1, cb_prefix_output => 'prefix_status_output', message_multiple => 'All stack members status are ok' }, ]; - + + $self->{maps_counters}->{stack} = [ + { label => 'stack-status', threshold => 0, set => { + key_values => [ { name => 'stack_status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_stack_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + } + ]; + $self->{maps_counters}->{global} = [ { label => 'waiting', set => { key_values => [ { name => 'waiting' } ], @@ -167,7 +177,7 @@ sub set_counters { $self->{maps_counters}->{members} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'id' }, { name => 'role' }, { name => 'state' } ], - closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, closure_custom_threshold_check => \&catalog_status_threshold, @@ -181,12 +191,12 @@ sub new { 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} !~ /ready/ && %{state} !~ /provisioned/' }, - }); + $options{options}->add_options(arguments => { + 'warning-stack-status:s' => { name => 'warning_stack_status', default => '' }, + 'critical-stack-status:s' => { name => 'critical_stack_status', default => '%{stack_status} =~ /notredundant/' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} !~ /ready/ && %{state} !~ /provisioned/' }, + }); return $self; } @@ -195,7 +205,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(macros => ['warning_status', 'critical_status']); + $self->change_macros(macros => ['warning_stack_status', 'critical_stack_status', 'warning_status', 'critical_status']); } my %map_role = ( @@ -228,28 +238,31 @@ my $oid_cswRingRedundant = '.1.3.6.1.4.1.9.9.500.1.1.3.0'; sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{global} = { waiting => 0, progressing => 0, added => 0, ready => 0, sdmMismatch => 0, + $self->{global} = { + waiting => 0, progressing => 0, added => 0, ready => 0, sdmMismatch => 0, verMismatch => 0, featureMismatch => 0, newMasterInit => 0, provisioned => 0, - invalid => 0, removed => 0 }; + invalid => 0, removed => 0 + }; $self->{members} = {}; - my $redundant = $self->{snmp}->get_leef(oids => [ $oid_cswRingRedundant ], nothing_quit => 1); + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_cswRingRedundant ], nothing_quit => 1); + $self->{stack} = { + stack_status => ($snmp_result->{$oid_cswRingRedundant} != 1) ? 'notredundant' : 'redundant', + }; - if ($redundant->{$oid_cswRingRedundant} != 1) { - $self->{output}->add_option_msg(short_msg => "Stack ring is not redundant"); - $self->{output}->option_exit(); - } + $snmp_result = $options{snmp}->get_table( + oid => $oid_cswSwitchInfoEntry, + start => $mapping->{cswSwitchRole}->{oid}, + end => $mapping->{cswSwitchState}->{oid}, + nothing_quit => 1 + ); - $self->{results} = $options{snmp}->get_table(oid => $oid_cswSwitchInfoEntry, - nothing_quit => 1); - - foreach my $oid (keys %{$self->{results}}) { + foreach my $oid (keys %$snmp_result) { next if($oid !~ /^$mapping->{cswSwitchRole}->{oid}\.(.*)$/); my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); # .1001, .2001 the instance. my $id = int(($instance - 1) / 1000); @@ -260,11 +273,6 @@ sub manage_selection { }; $self->{global}->{$result->{cswSwitchState}}++; } - - if (scalar(keys %{$self->{members}}) <= 0) { - $self->{output}->add_option_msg(short_msg => 'No stack members found'); - $self->{output}->option_exit(); - } } 1; @@ -277,26 +285,30 @@ Check Cisco Stack (CISCO-STACKWISE-MIB). =over 8 -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Set warning threshold on members count for each states. +Set thresholds on members count for each states. (Can be: 'waiting', 'progressing', 'added', 'ready', 'sdm-mismatch', 'version-mismatch', 'feature-mismatch', 'new-master-init', 'provisioned', 'invalid', 'removed') -=item B<--critical-*> +=item B<--warning-stack-status> -Set warning threshold on members count for each states. -(Can be: 'waiting', 'progressing', 'added', 'ready', 'sdm-mismatch', 'version-mismatch', -'feature-mismatch', 'new-master-init', 'provisioned', 'invalid', 'removed') +Set warning threshold for stack status (Default: ''). +Can used special variables like: %{stack_status} + +=item B<--critical-stack-status> + +Set critical threshold for stack status (Default: '%{stack_status} =~ /notredundant/'). +Can used special variables like: %{stack_status} =item B<--warning-status> -Set warning threshold for status (Default: ''). +Set warning threshold for members status (Default: ''). Can used special variables like: %{id}, %{role}, %{state} =item B<--critical-status> -Set critical threshold for status (Default: '%{state} !~ /ready/ && %{state} !~ /provisioned/'). +Set critical threshold for member status (Default: '%{state} !~ /ready/ && %{state} !~ /provisioned/'). Can used special variables like: %{id}, %{role}, %{state} Role can be: 'master', 'member', 'notMember', 'standby'. diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/voicecall.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/voicecall.pm new file mode 100644 index 000000000..28c0cdf36 --- /dev/null +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/voicecall.pm @@ -0,0 +1,168 @@ +# +# Copyright 2019 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 centreon::common::cisco::standard::snmp::mode::voicecall; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'gavg', type => 0, cb_prefix_output => 'prefix_gavg_output', message_separator => ' ', skipped_code => { -10 => 1 } }, + { name => 'ctype', type => 1, cb_prefix_output => 'prefix_ctype_output', message_multiple => 'All connection types are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{gavg} = [ + { label => 'active-1m-average', nlabel => 'calls.active.1m.average.count', set => { + key_values => [ { name => 'active_1m_average' } ], + output_template => '%.2f (1m)', + perfdatas => [ + { value => 'active_1m_average_absolute', template => '%.2f', min => 0 }, + ], + } + }, + { label => 'active-5m-average', nlabel => 'calls.active.5m.average.count', set => { + key_values => [ { name => 'active_5m_average' } ], + output_template => '%.2f (5m)', + perfdatas => [ + { value => 'active_5m_average_absolute', template => '%.2f', min => 0 }, + ], + } + }, + { label => 'active-15m-average', nlabel => 'calls.active.15m.average.count', set => { + key_values => [ { name => 'active_15m_average' } ], + output_template => '%.2f (15m)', + perfdatas => [ + { value => 'active_15m_average_absolute', template => '%.2f', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{ctype} = [ + { label => 'connection-calls-active', nlabel => 'connection.calls.active.count', set => { + key_values => [ { name => 'active_calls' }, { name => 'display' } ], + output_template => 'active calls %s', + perfdatas => [ + { value => 'active_calls_absolute', template => '%s', + min => 0, label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_gavg_output { + my ($self, %options) = @_; + + return 'Calls active '; +} + +sub prefix_ctype_output { + my ($self, %options) = @_; + + return "Connection type '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my %map_con_type = ( + 1 => 'h323', 2 => 'sip', 3 => 'mgcp', + 4 => 'sccp', 5 => 'multicast', + 6 => 'cacontrol', 7 => 'telephony', + ); + my $oid_cvCallVolConnActiveConnection = '.1.3.6.1.4.1.9.9.63.1.3.8.1.1.2'; + my $oid_cvActiveCallStatsAvgVal_min = '.1.3.6.1.4.1.9.9.63.1.4.3.3.1.4.2'; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_cvCallVolConnActiveConnection }, + { oid => $oid_cvActiveCallStatsAvgVal_min } + ], + nothing_quit => 1 + ); + + $self->{ctype} = {}; + foreach (keys %{$snmp_result->{ $oid_cvCallVolConnActiveConnection }}) { + /\.(\d+)$/; + $self->{ctype}->{$map_con_type{$1}} = { + display => $map_con_type{$1}, + active_calls => $snmp_result->{ $oid_cvCallVolConnActiveConnection }->{$_}, + }; + } + + my %definitions_avg = ( + 'active_1m_average' => [1, 1, 1, 0, 0], + 'active_5m_average' => [1, 5, 5, 0, 0], + 'active_15m_average' => [1, 15, 15, 0, 0], + ); + foreach my $oid (keys %{$snmp_result->{ $oid_cvActiveCallStatsAvgVal_min }}) { + $oid =~ /\.(\d+)$/; + my $interval = $1; + foreach (values %definitions_avg) { + if ($interval >= $_->[0] && $interval <= $_->[1]) { + $_->[3]++; + $_->[4] += $snmp_result->{ $oid_cvActiveCallStatsAvgVal_min }->{$oid}; + } + } + } + + $self->{gavg} = {}; + foreach (keys %definitions_avg) { + next if ($definitions_avg{$_}->[2] != $definitions_avg{$_}->[3]); + $self->{gavg}->{$_} = $definitions_avg{$_}->[4] / $definitions_avg{$_}->[2]; + } +} + +1; + +__END__ + +=head1 MODE + +Check call traffic statistics (CISCO-VOICE-DIAL-CONTROL-MIB) + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'active-1m-average', 'active-5m-average', 'active-15m-average', +'connection-calls-active'. + +=back + +=cut diff --git a/centreon-plugins/centreon/common/cps/ups/snmp/mode/batterystatus.pm b/centreon-plugins/centreon/common/cps/ups/snmp/mode/batterystatus.pm new file mode 100644 index 000000000..07b28ebba --- /dev/null +++ b/centreon-plugins/centreon/common/cps/ups/snmp/mode/batterystatus.pm @@ -0,0 +1,166 @@ +# +# Copyright 2019 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 centreon::common::cps::ups::snmp::mode::batterystatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf('battery status is %s', $self->{result_values}->{status}); +} + +sub custom_load_output { + my ($self, %options) = @_; + + return sprintf("charge remaining: %s%% (%s minutes remaining)", + $self->{result_values}->{charge_remain_absolute}, + $self->{result_values}->{minute_remain_absolute} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'charge-remaining', nlabel => 'battery.charge.remaining.percent', set => { + key_values => [ { name => 'charge_remain' }, { name => 'minute_remain' } ], + closure_custom_output => $self->can('custom_load_output'), + perfdatas => [ + { value => 'charge_remain_absolute', template => '%s', min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'voltage', nlabel => 'battery.voltage.volt', display_ok => 0, set => { + key_values => [ { name => 'voltage', no_value => 0 } ], + output_template => 'voltage: %s V', + perfdatas => [ + { value => 'voltage_absolute', template => '%s', unit => 'V' }, + ], + } + }, + { label => 'temperature', nlabel => 'battery.temperature.celsius', display_ok => 0, set => { + key_values => [ { name => 'temperature', no_value => 0 } ], + output_template => 'temperature: %s C', + perfdatas => [ + { value => 'temperature_absolute', template => '%s', unit => 'C' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown|notPresent/i' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /low/i' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +my $map_status = { 1 => 'unknown', 2 => 'normal', 3 => 'low', 4 => 'notPresent' }; + +my $mapping = { + upsBaseBatteryStatus => { oid => '.1.3.6.1.4.1.3808.1.1.1.2.1.1', map => $map_status }, + upsAdvanceBatteryCapacity => { oid => '.1.3.6.1.4.1.3808.1.1.1.2.2.1' }, + upsAdvanceBatteryVoltage => { oid => '.1.3.6.1.4.1.3808.1.1.1.2.2.2' }, # in dV + upsAdvanceBatteryTemperature => { oid => '.1.3.6.1.4.1.3808.1.1.1.2.2.3' }, # in degrees Centigrade + upsAdvanceBatteryRunTimeRemaining => { oid => '.1.3.6.1.4.1.3808.1.1.1.2.2.4' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_upsBattery = '.1.3.6.1.4.1.3808.1.1.1.2'; + my $snmp_result = $options{snmp}->get_table(oid => $oid_upsBattery, nothing_quit => 1); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + + $self->{global} = { + voltage => (defined($result->{upsAdvanceBatteryVoltage}) && $result->{upsAdvanceBatteryVoltage} =~ /\d/) ? $result->{upsAdvanceBatteryVoltage} * 0.1 : 0, + temperature => $result->{upsAdvanceBatteryTemperature}, + minute_remain => (defined($result->{upsAdvanceBatteryRunTimeRemaining}) && $result->{upsAdvanceBatteryRunTimeRemaining} =~ /\d/) ? ($result->{upsAdvanceBatteryRunTimeRemaining} / 100 / 60) : 'unknown', + charge_remain => (defined($result->{upsAdvanceBatteryCapacity}) && $result->{upsAdvanceBatteryCapacity} =~ /\d/) ? $result->{upsAdvanceBatteryCapacity} : undef, + status => $result->{upsBaseBatteryStatus}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check battery status and charge remaining. + +=over 8 + +=item B<--unknown-status> + +Set warning threshold for status (Default: '%{status} =~ /unknown|notPresent/i'). +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /low/i'). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'charge-remaining' (%), 'voltage' (V), 'temperature' (C). + +=back + +=cut diff --git a/centreon-plugins/centreon/common/cps/ups/snmp/mode/inputlines.pm b/centreon-plugins/centreon/common/cps/ups/snmp/mode/inputlines.pm new file mode 100644 index 000000000..6494446a8 --- /dev/null +++ b/centreon-plugins/centreon/common/cps/ups/snmp/mode/inputlines.pm @@ -0,0 +1,154 @@ +# +# Copyright 2019 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 centreon::common::cps::ups::snmp::mode::inputlines; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf("status is '%s'", $self->{result_values}->{status}); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ilines', type => 0, cb_prefix_output => 'prefix_ilines_output', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{ilines} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'voltage', nlabel => 'lines.input.voltage.volt', set => { + key_values => [ { name => 'voltage' } ], + output_template => 'Voltage : %.2f V', + perfdatas => [ + { value => 'voltage_absolute', template => '%.2f', unit => 'V' }, + ], + } + }, + { label => 'frequence', nlabel => 'lines.input.frequence.hertz', set => { + key_values => [ { name => 'frequence' } ], + output_template => 'Frequence : %.2f Hz', + perfdatas => [ + { value => 'frequence_absolute', template => '%.2f', min => 0, unit => 'Hz' }, + ], + } + }, + ]; +} + +sub prefix_ilines_output { + my ($self, %options) = @_; + + return 'Input '; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /normal/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +my $map_status = { + 1 => 'normal', 2 => 'overVoltage', + 3 => 'underVoltage', 4 => 'frequencyFailure', 5 => 'blackout', +}; + +my $mapping = { + upsAdvanceInputLineVoltage => { oid => '.1.3.6.1.4.1.3808.1.1.1.3.2.1' }, # in dV + upsAdvanceInputFrequency => { oid => '.1.3.6.1.4.1.3808.1.1.1.3.2.4' }, # in dHz + upsAdvanceInputStatus => { oid => '.1.3.6.1.4.1.3808.1.1.1.3.2.6', map => $map_status }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_upsAdvanceInput = '.1.3.6.1.4.1.3808.1.1.1.3.2'; + my $snmp_result = $options{snmp}->get_table(oid => $oid_upsAdvanceInput, nothing_quit => 1); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + + $self->{ilines} = { + frequence => (defined($result->{upsAdvanceInputFrequency}) && $result->{upsAdvanceInputFrequency} =~ /\d/) ? $result->{upsAdvanceInputFrequency} * 0.1 : undef, + voltage => (defined($result->{upsAdvanceInputLineVoltage}) && $result->{upsAdvanceInputLineVoltage} =~ /\d/) ? $result->{upsAdvanceInputLineVoltage} * 0.1 : undef, + status => $result->{upsAdvanceInputStatus}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check INPUT lines metrics. + +=over 8 + +=item B<--unknown-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /normal/'). +Can used special variables like: %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'voltage', 'frequence'. + +=back + +=cut diff --git a/centreon-plugins/centreon/common/cps/ups/snmp/mode/outputlines.pm b/centreon-plugins/centreon/common/cps/ups/snmp/mode/outputlines.pm new file mode 100644 index 000000000..7efe70d9a --- /dev/null +++ b/centreon-plugins/centreon/common/cps/ups/snmp/mode/outputlines.pm @@ -0,0 +1,188 @@ +# +# Copyright 2019 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 centreon::common::cps::ups::snmp::mode::outputlines; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf("status is '%s'", $self->{result_values}->{status}); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'olines', type => 0, cb_prefix_output => 'prefix_olines_output', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{olines} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'load', nlabel => 'lines.output.load.percentage', set => { + key_values => [ { name => 'load' } ], + output_template => 'Load : %.2f %%', + perfdatas => [ + { value => 'load_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'current', nlabel => 'lines.output.current.ampere', set => { + key_values => [ { name => 'current' } ], + output_template => 'Current : %.2f A', + perfdatas => [ + { value => 'current_absolute', template => '%.2f', min => 0, unit => 'A' }, + ], + } + }, + { label => 'voltage', nlabel => 'lines.output.voltage.volt', set => { + key_values => [ { name => 'voltage' } ], + output_template => 'Voltage : %.2f V', + perfdatas => [ + { value => 'voltage_absolute', template => '%.2f', unit => 'V' }, + ], + } + }, + { label => 'power', nlabel => 'lines.output.power.watt', set => { + key_values => [ { name => 'power' } ], + output_template => 'Power : %.2f W', + perfdatas => [ + { value => 'power_absolute', template => '%.2f', min => 0, unit => 'W' }, + ], + } + }, + { label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => { + key_values => [ { name => 'frequence' } ], + output_template => 'Frequence : %.2f Hz', + perfdatas => [ + { value => 'frequence_absolute', template => '%.2f', min => 0, unit => 'Hz' }, + ], + } + }, + ]; +} + +sub prefix_olines_output { + my ($self, %options) = @_; + + return 'Output '; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /rebooting|onBattery|onBypass/i' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +my $map_status = { + 1 => 'unknown', 2 => 'onLine', + 3 => 'onBattery', 4 => 'onBoost', + 5 => 'onSleep', 6 => 'off', + 7 => 'rebooting', 8 => 'onECO', + 9 => 'onBypass', 10 => 'onBuck', + 11 => 'onOverload', +}; + +my $mapping = { + upsBaseOutputStatus => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.1.1', map => $map_status }, + upsAdvanceOutputVoltage => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.2.1' }, # in dV + upsAdvanceOutputFrequency => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.2.2' }, # in dHz + upsAdvanceOutputLoad => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.2.3' }, # in % + upsAdvanceOutputCurrent => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.2.4' }, # in dA + upsAdvanceOutputPower => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.2.5' }, # in W +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_upsOutput = '.1.3.6.1.4.1.3808.1.1.1.4'; + my $snmp_result = $options{snmp}->get_table(oid => $oid_upsOutput, nothing_quit => 1); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + + $self->{olines} = { + frequence => (defined($result->{upsAdvanceOutputFrequency}) && $result->{upsAdvanceOutputFrequency} =~ /\d/) ? $result->{upsAdvanceOutputFrequency} * 0.1 : undef, + voltage => (defined($result->{upsAdvanceOutputVoltage}) && $result->{upsAdvanceOutputVoltage} =~ /\d/) ? $result->{upsAdvanceOutputVoltage} * 0.1 : undef, + current => (defined($result->{upsAdvanceOutputCurrent}) && $result->{upsAdvanceOutputCurrent} =~ /\d/) ? $result->{upsAdvanceOutputCurrent} * 0.1 : undef, + load => (defined($result->{upsAdvanceOutputLoad}) && $result->{upsAdvanceOutputLoad} =~ /\d/) ? $result->{upsAdvanceOutputLoad} : undef, + power => (defined($result->{upsAdvanceOutputPower}) && $result->{upsAdvanceOutputPower} =~ /\d/) ? $result->{upsAdvanceOutputPower} : undef, + status => $result->{upsBaseOutputStatus}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check output lines metrics. + +=over 8 + +=item B<--unknown-status> + +Set warning threshold for status (Default: '%{status} =~ /unknown/i'). +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /rebooting|onBattery|onBypass/i'). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'load', 'voltage', 'current', 'power', 'frequence'. + +=back + +=cut diff --git a/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/cpu.pm index b83b9122b..ead478151 100644 --- a/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '' }, diff --git a/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/environment.pm b/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/environment.pm index ac6238651..cefaffefb 100644 --- a/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/environment.pm +++ b/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/environment.pm @@ -70,7 +70,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/memory.pm b/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/memory.pm index fbc141836..a28f1e362 100644 --- a/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/dell/fastpath/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/centreon/common/dell/powerconnect3000/mode/globalstatus.pm b/centreon-plugins/centreon/common/dell/powerconnect3000/mode/globalstatus.pm index e0bd06f70..ad43d5b83 100644 --- a/centreon-plugins/centreon/common/dell/powerconnect3000/mode/globalstatus.pm +++ b/centreon-plugins/centreon/common/dell/powerconnect3000/mode/globalstatus.pm @@ -36,7 +36,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/cache.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/cache.pm index 80cef6b29..645c2d77c 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/cache.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/cache.pm @@ -52,7 +52,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "cache-command:s" => { name => 'cache_command', default => 'getcache' }, diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/controller.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/controller.pm index 641854ec2..8e847a028 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/controller.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/controller.pm @@ -94,7 +94,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/disk.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/disk.pm index 074a448c8..9f61b0fe1 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/disk.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/disk.pm @@ -167,7 +167,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-raidgroupid:s" => { name => 'filter_raidgroupid', }, "filter-disk:s" => { name => 'filter_disk', }, diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/faults.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/faults.pm index ab8cc644c..e6f49590e 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/faults.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/faults.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/hbastate.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/hbastate.pm index 2a584f4b5..62da38275 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/hbastate.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/hbastate.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-server:s" => { name => 'filter_server' }, diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/listluns.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/listluns.pm index a0b5d9c5f..5405131a6 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/listluns.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/listluns.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-lunnumber:s" => { name => 'filter_lunnumber', }, diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/portstate.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/portstate.pm index 43fddf6f4..db6c42872 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/portstate.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/portstate.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/sp.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/sp.pm index ec0aa9928..7698ae49a 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/sp.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/sp.pm @@ -89,7 +89,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "getcrus-options:s" => { name => 'getcrus_options', default => '-all' }, diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/spinfo.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/spinfo.pm index 8cadcb480..f9ad3fded 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/spinfo.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/spinfo.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/force10/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/force10/snmp/mode/cpu.pm index 224199af3..fb9c6c04a 100644 --- a/centreon-plugins/centreon/common/force10/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/force10/snmp/mode/cpu.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm index 129ae6453..774272a10 100644 --- a/centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm @@ -69,7 +69,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/force10/snmp/mode/memory.pm b/centreon-plugins/centreon/common/force10/snmp/mode/memory.pm index a13cdcf7f..bd96ce940 100644 --- a/centreon-plugins/centreon/common/force10/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/force10/snmp/mode/memory.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/apusage.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/apusage.pm index 16725dd75..206ceebe4 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/apusage.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/apusage.pm @@ -120,7 +120,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "unknown-status:s" => { name => 'unknown_status', default => '' }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/clusterstatus.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/clusterstatus.pm index 3fb5a7bf9..bb2c7cb09 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/clusterstatus.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/clusterstatus.pm @@ -24,52 +24,20 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); - -sub custom_status_threshold { - my ($self, %options) = @_; - my $status = 'ok'; - my $message; - - eval { - local $SIG{__WARN__} = sub { $message = $_[0]; }; - local $SIG{__DIE__} = sub { $message = $_[0]; }; - - if (defined($self->{instance_mode}->{option_results}->{critical_status}) && $self->{instance_mode}->{option_results}->{critical_status} ne '' && - eval "$self->{instance_mode}->{option_results}->{critical_status}") { - $status = 'critical'; - } elsif (defined($self->{instance_mode}->{option_results}->{warning_status}) && $self->{instance_mode}->{option_results}->{warning_status} ne '' && - eval "$self->{instance_mode}->{option_results}->{warning_status}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("status is '%s' [Hostname: %s] [Role: %s]", + my $msg = sprintf("status is '%s' [Hostname: %s] [Role: %s] [Checksum: %s]", $self->{result_values}->{sync_status}, $self->{result_values}->{hostname}, - $self->{result_values}->{role}); + $self->{result_values}->{role}, + $self->{result_values}->{checksum}, + ); return $msg; } -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{serial} = $options{new_datas}->{$self->{instance} . '_serial'}; - $self->{result_values}->{hostname} = $options{new_datas}->{$self->{instance} . '_hostname'}; - $self->{result_values}->{sync_status} = $options{new_datas}->{$self->{instance} . '_sync_status'}; - $self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'}; - return 0; -} - sub prefix_status_output { my ($self, %options) = @_; @@ -117,14 +85,22 @@ sub set_counters { ], } }, + { label => 'total-checksums', display_ok => 0, set => { + key_values => [ { name => 'total_checksums' } ], + output_template => 'Total Checksums: %d', + perfdatas => [ + { label => 'total_checksums', value => 'total_checksums_absolute', template => '%d', min => 0 }, + ], + } + }, ]; $self->{maps_counters}->{nodes} = [ { label => 'node', threshold => 0, set => { - key_values => [ { name => 'serial' }, { name => 'hostname' }, { name => 'sync_status' }, { name => 'role' } ], - closure_custom_calc => $self->can('custom_status_calc'), + key_values => [ { name => 'serial' }, { name => 'hostname' }, { name => 'sync_status' }, { name => 'role' }, { name => 'checksum' } ], + closure_custom_calc => \&catalog_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'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, ]; @@ -135,13 +111,11 @@ sub new { 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 => '%{sync_status} =~ /not synchronized/' }, - "one-node-status:s" => { name => 'one_node_status' }, # not used, use --opt-exit instead - }); + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{sync_status} =~ /not synchronized/' }, + 'one-node-status:s' => { name => 'one_node_status' }, # not used, use --opt-exit instead + }); return $self; } @@ -164,10 +138,11 @@ my %map_sync_status = ( ); my $mapping = { - fgHaStatsSerial => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.2' }, - fgHaStatsHostname => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.11' }, - fgHaStatsSyncStatus => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.12', map => \%map_sync_status }, - fgHaStatsMasterSerial => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.16' }, + fgHaStatsSerial => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.2' }, + fgHaStatsHostname => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.11' }, + fgHaStatsSyncStatus => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.12', map => \%map_sync_status }, + fgHaStatsGlobalChecksum => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.15' }, + fgHaStatsMasterSerial => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.16' }, }; my $oid_fgHaStatsEntry = '.1.3.6.1.4.1.12356.101.13.2.1.1'; @@ -188,28 +163,33 @@ sub manage_selection { $self->{output}->output_add(short_msg => "HA mode: " . $map_ha_mode{$mode->{$oid_fgHaSystemMode}}); - $self->{results} = $options{snmp}->get_table(oid => $oid_fgHaStatsEntry, - nothing_quit => 1); + $self->{results} = $options{snmp}->get_table( + oid => $oid_fgHaStatsEntry, + nothing_quit => 1 + ); $self->{global} = { synchronized => 0, not_synchronized => 0, total_nodes => 0 }; - + my $checksums = {}; foreach my $oid (keys %{$self->{results}}) { next if ($oid !~ /^$mapping->{fgHaStatsSerial}->{oid}\.(.*)$/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + $checksums->{$result->{fgHaStatsGlobalChecksum}} = 1; $self->{nodes}->{$instance} = { serial => $result->{fgHaStatsSerial}, hostname => $result->{fgHaStatsHostname}, sync_status => $result->{fgHaStatsSyncStatus}, role => ($result->{fgHaStatsMasterSerial} eq '' || $result->{fgHaStatsMasterSerial} =~ /$result->{fgHaStatsSerial}/) ? "master" : "slave", + checksum => $result->{fgHaStatsGlobalChecksum}, }; $result->{fgHaStatsSyncStatus} =~ s/ /_/; $self->{global}->{$result->{fgHaStatsSyncStatus}}++; $self->{global}->{total_nodes}++; } + $self->{global}->{total_checksums} = scalar(keys %$checksums); if (scalar(keys %{$self->{nodes}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No cluster nodes found'); $self->{output}->option_exit(); @@ -226,15 +206,11 @@ Check cluster status (FORTINET-FORTIGATE-MIB). =over 8 -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Set warning thresholds. -Can be: 'total-nodes', 'synchronized', 'not-synchronized'. - -=item B<--critical-*> - -Set critical thresholds. -Can be: 'total-nodes', 'synchronized', 'not-synchronized'. +Set thresholds. +Can be: 'total-nodes', 'synchronized', 'not-synchronized', +'total-checksums'. =item B<--warning-status> @@ -249,4 +225,3 @@ Can used special variables like: %{serial}, %{hostname}, %{sync_status}, %{role} =back =cut - diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/cpu.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/cpu.pm index 5b5aeca29..6057c9e14 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/cpu.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/cpu.pm @@ -42,7 +42,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/disk.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/disk.pm index b8a045989..5762b7e06 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/disk.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/disk.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/hardware.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/hardware.pm index 16fa3cbd4..8a1946526 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/hardware.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/hardware.pm @@ -20,93 +20,179 @@ package centreon::common::fortinet::fortigate::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^sensors$'; + $self->{regexp_threshold_numeric_check_section_option} = '^sensors$'; + + $self->{cb_hook1} = 'get_system_information'; + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + sensors => [ + ['on', 'CRITICAL'], + ['off', 'OK'], + ], + }; + + $self->{components_path} = 'centreon::common::fortinet::fortigate::mode::components'; + $self->{components_module} = ['sensors']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, + no_absent => 1, no_load_components => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub get_system_information { + my ($self, %options) = @_; + + my $oid_sysDescr = '.1.3.6.1.2.1.1.1.0'; + my $oid_fgSysVersion = '.1.3.6.1.4.1.12356.101.4.1.1.0'; + + my $result = $options{snmp}->get_leef(oids => [$oid_sysDescr, $oid_fgSysVersion]);#, nothing_quit => 1); + $self->{output}->output_add( + long_msg => sprintf( + '[System: %s] [Firmware: %s]', + $result->{$oid_sysDescr}, + defined($result->{$oid_fgSysVersion}) ? $result->{$oid_fgSysVersion} : 'unknown' + ) + ); +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +1; + +=head1 MODE + +Check hardware. +It's deprecated. Work only for 'FortiGate-5000 Series Chassis'. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'sensors'. + +=item B<--add-name-instance> + +Add literal description for instance value (used in filter, and threshold options). + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=sensors,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='sensors,WARNING,off' + +=item B<--warning> + +Set warning threshold for 'sensors' (syntax: type,regexp,threshold) +Example: --warning='sensors,.*,30' + +=item B<--critical> + +Set critical threshold for 'sensors' (syntax: type,regexp,threshold) +Example: --critical='sensors,.*,50' + + +=back + +=cut + +package centreon::common::fortinet::fortigate::mode::components::sensors; use strict; use warnings; -use centreon::plugins::misc; my %alarm_map = ( 0 => 'off', 1 => 'on', ); +my $mapping = { + fgHwSensorEntName => { oid => '.1.3.6.1.4.1.12356.101.4.3.2.1.2' }, + fgHwSensorEntValue => { oid => '.1.3.6.1.4.1.12356.101.4.3.2.1.3' }, + fgHwSensorEntAlarmStatus => { oid => '.1.3.6.1.4.1.12356.101.4.3.2.1.4', map => \%alarm_map }, +}; +my $oid_fgHwSensorEntry = '.1.3.6.1.4.1.12356.101.4.3.2.1'; -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 => - { - }); +sub load { + my ($self) = @_; - return $self; + push @{$self->{request}}, { oid => $oid_fgHwSensorEntry }; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} +sub check { + my ($self) = @_; -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $oid_sysDescr = '.1.3.6.1.2.1.1.1.0'; - my $oid_fgSysVersion = '.1.3.6.1.4.1.12356.101.4.1.1.0'; - my $oid_fgHwSensorCount = '.1.3.6.1.4.1.12356.101.4.3.1.0'; - my $result = $self->{snmp}->get_leef(oids => [$oid_sysDescr, $oid_fgSysVersion, $oid_fgHwSensorCount], nothing_quit => 1); - - $self->{output}->output_add(long_msg => sprintf("[System: %s] [Firmware: %s]", $result->{$oid_sysDescr}, - defined($result->{$oid_fgSysVersion}) ? $result->{$oid_fgSysVersion} : 'unknown')); - if (!defined($result->{$oid_fgHwSensorCount}) || $result->{$oid_fgHwSensorCount} == 0) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "No hardware sensors available."); - $self->{output}->display(); - $self->{output}->exit(); - } - - $self->{output}->output_add(severity => 'OK', - short_msg => "All sensors are ok."); - - my $oid_fgHwSensorEntry = '.1.3.6.1.4.1.12356.101.4.3.2.1'; - my $oid_fgHwSensorEntAlarmStatus = '.1.3.6.1.4.1.12356.101.4.3.2.1.4'; - my $oid_fgHwSensorEntName = '.1.3.6.1.4.1.12356.101.4.3.2.1.2'; - my $oid_fgHwSensorEntValue = '.1.3.6.1.4.1.12356.101.4.3.2.1.3'; - $result = $self->{snmp}->get_table(oid => $oid_fgHwSensorEntry); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_fgHwSensorEntName\.(\d+)/); - my $index = $1; - my $name = centreon::plugins::misc::trim($result->{$oid_fgHwSensorEntName . '.' . $index}); - my $value = $result->{$oid_fgHwSensorEntValue . '.' . $index}; - my $alarm_status = centreon::plugins::misc::trim($result->{$oid_fgHwSensorEntAlarmStatus . '.' . $index}); - - $self->{output}->output_add(long_msg => sprintf("Sensor %s alarm status is %s [value: %s]", - $name, $alarm_map{$alarm_status}, $value)); - if ($alarm_map{$alarm_status} eq 'on') { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Sensor %s alarm status is %s [value: %s]", - $name, $alarm_map{$alarm_status}, $value)); + $self->{output}->output_add(long_msg => "Checking sensors"); + $self->{components}->{sensors} = {name => 'sensors', total => 0, skip => 0}; + return if ($self->check_filter(section => 'sensors')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fgHwSensorEntry}})) { + next if ($oid !~ /^$mapping->{fgHwSensorEntAlarmStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fgHwSensorEntry}, instance => $instance); + my $name = centreon::plugins::misc::trim($result->{fgHwSensorEntName}); + + next if ($self->check_filter(section => 'sensors', instance => $instance, name => $name)); + + $self->{components}->{sensors}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("sensor '%s' status is '%s' [instance = %s] [value = %s]", + $name, $result->{fgHwSensorEntAlarmStatus}, $instance, + defined($result->{fgHwSensorEntValue}) ? $result->{fgHwSensorEntValue} : '-')); + + my $exit = $self->get_severity(section => 'sensors', name => $name, value => $result->{fgHwSensorEntAlarmStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sensor '%s' status is '%s'", $name, $result->{fgHwSensorEntAlarmStatus})); } + + next if (!defined($result->{fgHwSensorEntValue})); + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'sensors', instance => $instance, name => $name, value => $result->{fgHwSensorEntValue}); + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Sensor '%s' measure is %s", $name, $result->{fgHwSensorEntValue})); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.sensors.measure', + instances => $name, + value => $result->{fgHwSensorEntValue}, + warning => $warn, + critical => $crit, + ); } - - $self->{output}->display(); - $self->{output}->exit(); } 1; - -__END__ - -=head1 MODE - -Check fortigate hardware sensors (FORTINET-FORTIGATE-MIB). -It's deprecated. Work only for 'FortiGate-5000 Series Chassis'. - -=over 8 - -=back - -=cut \ No newline at end of file diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/ipsstats.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/ipsstats.pm index 70dfccbe5..f921aa3a8 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/ipsstats.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/ipsstats.pm @@ -129,7 +129,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/listvirtualdomains.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/listvirtualdomains.pm index 70841ebff..2de3c373e 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/listvirtualdomains.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/listvirtualdomains.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s" => { name => 'name' }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/memory.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/memory.pm index 332668f95..9f979a21c 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/memory.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/memory.pm @@ -40,7 +40,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/sessions.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/sessions.pm index e795b0514..3b6234167 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/sessions.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/sessions.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/signatures.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/signatures.pm index 75f9a2963..6999f7692 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/signatures.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/signatures.pm @@ -31,7 +31,9 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'av', type => 0, cb_prefix_output => 'prefix_av_output' }, + { name => 'avet', type => 0, cb_prefix_output => 'prefix_avet_output' }, { name => 'ips', type => 0, cb_prefix_output => 'prefix_ips_output' }, + { name => 'ipset', type => 0, cb_prefix_output => 'prefix_ipset_output' }, ]; $self->{maps_counters}->{av} = [ @@ -46,6 +48,18 @@ sub set_counters { } }, ]; + $self->{maps_counters}->{avet} = [ + { label => 'avet', set => { + key_values => [ { name => 'human' }, { name => 'value' } ], + threshold_use => 'value_absolute', + output_template => "last refresh is: '%s'", + perfdatas => [ + { label => 'avet_update', value => 'value_absolute', + template => '%d', min => 0, unit => 's' }, + ], + } + }, + ]; $self->{maps_counters}->{ips} = [ { label => 'ips', set => { key_values => [ { name => 'human' }, { name => 'value' } ], @@ -58,18 +72,42 @@ sub set_counters { } }, ]; + $self->{maps_counters}->{ipset} = [ + { label => 'ipset', set => { + key_values => [ { name => 'human' }, { name => 'value' } ], + threshold_use => 'value_absolute', + output_template => "last refresh is: '%s'", + perfdatas => [ + { label => 'ipset_update', value => 'value_absolute', + template => '%d', min => 0, unit => 's' }, + ], + } + }, + ]; } sub prefix_av_output { my ($self, %options) = @_; - return "AV Signature "; + return 'AV Signature '; +} + +sub prefix_avet_output { + my ($self, %options) = @_; + + return 'AV Extended Signature '; } sub prefix_ips_output { my ($self, %options) = @_; - return "IPS Signature "; + return 'IPS Signature '; +} + +sub prefix_ipset_output { + my ($self, %options) = @_; + + return 'IPS Extended Signature '; } sub new { @@ -77,10 +115,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); return $self; } @@ -98,24 +134,39 @@ sub manage_selection { my $oid_fgSysVersionAv = '.1.3.6.1.4.1.12356.101.4.2.1.0'; my $oid_fgSysVersionIps = '.1.3.6.1.4.1.12356.101.4.2.2.0'; + my $oid_fgSysVersionAvEt = '.1.3.6.1.4.1.12356.101.4.2.3.0'; + my $oid_fgSysVersionIpsEt = '.1.3.6.1.4.1.12356.101.4.2.4.0'; - my $result = $self->{snmp}->get_leef(oids => [$oid_fgSysVersionAv, $oid_fgSysVersionIps], nothing_quit => 1); + my $result = $self->{snmp}->get_leef(oids => [$oid_fgSysVersionAv, $oid_fgSysVersionIps, $oid_fgSysVersionAvEt, $oid_fgSysVersionIpsEt], nothing_quit => 1); my $av_epoch = $self->get_epoch_from_signature(date => $result->{$oid_fgSysVersionAv}); my $ips_epoch = $self->get_epoch_from_signature(date => $result->{$oid_fgSysVersionIps}); + my $avet_epoch = $self->get_epoch_from_signature(date => $result->{$oid_fgSysVersionAvEt}); + my $ipset_epoch = $self->get_epoch_from_signature(date => $result->{$oid_fgSysVersionIpsEt}); my $now = time(); my $av_diff = $now - $av_epoch; my $ips_diff = $now - $ips_epoch; + my $avet_diff = $now - $avet_epoch; + my $ipset_diff = $now - $ipset_epoch; - $self->{av} = { human => centreon::plugins::misc::change_seconds(value => $av_diff, start => 'h'), - value => $av_diff }; - - $self->{ips} = { human => centreon::plugins::misc::change_seconds(value => $ips_diff, start => 'h'), - value => $ips_diff }; - - + $self->{av} = { + human => centreon::plugins::misc::change_seconds(value => $av_diff, start => 'h'), + value => $av_diff + }; + $self->{ips} = { + human => centreon::plugins::misc::change_seconds(value => $ips_diff, start => 'h'), + value => $ips_diff + }; + $self->{avet} = { + human => centreon::plugins::misc::change_seconds(value => $avet_diff, start => 'h'), + value => $avet_diff + }; + $self->{ipset} = { + human => centreon::plugins::misc::change_seconds(value => $ipset_diff, start => 'h'), + value => $ipset_diff + }; } 1; @@ -133,15 +184,10 @@ Check last update/refresh of av and ips signatures Only display some counters (regexp can be used). Example: --filter-counters='^av$' -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning (in seconds). -Can be: 'av', 'ips' - -=item B<--critical-*> - -Threshold critical (in seconds). -Can be: 'av', 'ips' +Thresholds (in seconds). +Can be: 'av', 'ips', 'avet', ipset'. =back diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomcpu.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomcpu.pm index b664cde2f..0d7db91a2 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomcpu.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomcpu.pm @@ -55,7 +55,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdommemory.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdommemory.pm index 89d03ad6c..fca5363ec 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdommemory.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdommemory.pm @@ -55,7 +55,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomsession.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomsession.pm index b3d9acfa2..67a37b834 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomsession.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomsession.pm @@ -64,7 +64,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomstate.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomstate.pm index 7f9b775d9..c1b02a10c 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomstate.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomstate.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomusage.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomusage.pm index adaa4a70d..20cd5e3e1 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomusage.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vdomusage.pm @@ -117,7 +117,6 @@ sub new { 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 => '%{state} eq "disabled"' }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/virus.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/virus.pm index 8e13ab77d..85b5696e2 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/virus.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/virus.pm @@ -36,7 +36,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-virus-detected:s" => { name => 'warning_virus_detected' }, diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vpn.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vpn.pm index 1b2f0c0b7..4930aae62 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vpn.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vpn.pm @@ -128,7 +128,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-vpn:s" => { name => 'filter_vpn' }, diff --git a/centreon-plugins/centreon/common/h3c/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/h3c/snmp/mode/cpu.pm index d10c70663..238416238 100644 --- a/centreon-plugins/centreon/common/h3c/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/h3c/snmp/mode/cpu.pm @@ -57,7 +57,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, "display-entity-name" => { name => 'display_entity_name' }, diff --git a/centreon-plugins/centreon/common/h3c/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/h3c/snmp/mode/hardware.pm index e0545eb69..b0732b210 100644 --- a/centreon-plugins/centreon/common/h3c/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/h3c/snmp/mode/hardware.pm @@ -159,7 +159,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, diff --git a/centreon-plugins/centreon/common/h3c/snmp/mode/memory.pm b/centreon-plugins/centreon/common/h3c/snmp/mode/memory.pm index c605ff525..ac0199b95 100644 --- a/centreon-plugins/centreon/common/h3c/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/h3c/snmp/mode/memory.pm @@ -121,7 +121,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, "display-entity-name" => { name => 'display_entity_name' }, diff --git a/centreon-plugins/centreon/common/ibm/tapelibrary/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/ibm/tapelibrary/snmp/mode/hardware.pm index 7cbd60b28..c436ba720 100644 --- a/centreon-plugins/centreon/common/ibm/tapelibrary/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/ibm/tapelibrary/snmp/mode/hardware.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/ingrian/snmp/mode/connections.pm b/centreon-plugins/centreon/common/ingrian/snmp/mode/connections.pm index a32a33e09..f14ecba5e 100644 --- a/centreon-plugins/centreon/common/ingrian/snmp/mode/connections.pm +++ b/centreon-plugins/centreon/common/ingrian/snmp/mode/connections.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/ingrian/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/ingrian/snmp/mode/cpu.pm index 8d27f23a6..5cb297c38 100644 --- a/centreon-plugins/centreon/common/ingrian/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/ingrian/snmp/mode/cpu.pm @@ -73,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/ingrian/snmp/mode/disk.pm b/centreon-plugins/centreon/common/ingrian/snmp/mode/disk.pm index 38a3af3b1..6a5123bf8 100644 --- a/centreon-plugins/centreon/common/ingrian/snmp/mode/disk.pm +++ b/centreon-plugins/centreon/common/ingrian/snmp/mode/disk.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/ingrian/snmp/mode/memory.pm b/centreon-plugins/centreon/common/ingrian/snmp/mode/memory.pm index 696eb164f..cc8c2d4d8 100644 --- a/centreon-plugins/centreon/common/ingrian/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/ingrian/snmp/mode/memory.pm @@ -92,7 +92,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/ingrian/snmp/mode/requeststats.pm b/centreon-plugins/centreon/common/ingrian/snmp/mode/requeststats.pm index 7441785b5..eac696a6b 100644 --- a/centreon-plugins/centreon/common/ingrian/snmp/mode/requeststats.pm +++ b/centreon-plugins/centreon/common/ingrian/snmp/mode/requeststats.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/centreon/common/jvm/mode/classcount.pm b/centreon-plugins/centreon/common/jvm/mode/classcount.pm index 1352cc5da..30a991be0 100644 --- a/centreon-plugins/centreon/common/jvm/mode/classcount.pm +++ b/centreon-plugins/centreon/common/jvm/mode/classcount.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/jvm/mode/cpuload.pm b/centreon-plugins/centreon/common/jvm/mode/cpuload.pm index 59f116e52..6af470812 100644 --- a/centreon-plugins/centreon/common/jvm/mode/cpuload.pm +++ b/centreon-plugins/centreon/common/jvm/mode/cpuload.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-system:s" => { name => 'warning_system' }, diff --git a/centreon-plugins/centreon/common/jvm/mode/fdusage.pm b/centreon-plugins/centreon/common/jvm/mode/fdusage.pm index de191a8e4..c30c93794 100644 --- a/centreon-plugins/centreon/common/jvm/mode/fdusage.pm +++ b/centreon-plugins/centreon/common/jvm/mode/fdusage.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/centreon/common/jvm/mode/gcusage.pm b/centreon-plugins/centreon/common/jvm/mode/gcusage.pm index 483d32841..0cbdac2a4 100644 --- a/centreon-plugins/centreon/common/jvm/mode/gcusage.pm +++ b/centreon-plugins/centreon/common/jvm/mode/gcusage.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/centreon/common/jvm/mode/loadaverage.pm b/centreon-plugins/centreon/common/jvm/mode/loadaverage.pm index 3c7d5c76b..515ce497f 100644 --- a/centreon-plugins/centreon/common/jvm/mode/loadaverage.pm +++ b/centreon-plugins/centreon/common/jvm/mode/loadaverage.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/centreon/common/jvm/mode/memory.pm b/centreon-plugins/centreon/common/jvm/mode/memory.pm index 5b5591cce..9f134a23e 100644 --- a/centreon-plugins/centreon/common/jvm/mode/memory.pm +++ b/centreon-plugins/centreon/common/jvm/mode/memory.pm @@ -127,7 +127,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, }); diff --git a/centreon-plugins/centreon/common/jvm/mode/memorydetailed.pm b/centreon-plugins/centreon/common/jvm/mode/memorydetailed.pm index a97977c25..0d9a35416 100644 --- a/centreon-plugins/centreon/common/jvm/mode/memorydetailed.pm +++ b/centreon-plugins/centreon/common/jvm/mode/memorydetailed.pm @@ -174,7 +174,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, }); diff --git a/centreon-plugins/centreon/common/jvm/mode/threads.pm b/centreon-plugins/centreon/common/jvm/mode/threads.pm index 8d157c944..740c70bf1 100644 --- a/centreon-plugins/centreon/common/jvm/mode/threads.pm +++ b/centreon-plugins/centreon/common/jvm/mode/threads.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/appsharingqoe.pm b/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/appsharingqoe.pm index e77b97b68..1326ec441 100644 --- a/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/appsharingqoe.pm +++ b/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/appsharingqoe.pm @@ -80,7 +80,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeframe:s" => { name => 'timeframe', default => '900' }, diff --git a/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/audioqoe.pm b/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/audioqoe.pm index 2ad8ddbb5..a8d9cd3b5 100644 --- a/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/audioqoe.pm +++ b/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/audioqoe.pm @@ -122,7 +122,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeframe:s" => { name => 'timeframe', default => '900' }, diff --git a/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/poorcalls.pm b/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/poorcalls.pm index 0bba2a080..46704cc40 100644 --- a/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/poorcalls.pm +++ b/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/poorcalls.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "lookback:s" => { name => 'lookback', default => '65' }, # not used diff --git a/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/sessionstypes.pm b/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/sessionstypes.pm index e730777c4..06ccdb6ce 100644 --- a/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/sessionstypes.pm +++ b/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/sessionstypes.pm @@ -104,7 +104,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "lookback:s" => { name => 'lookback', default => '5' }, # not used diff --git a/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/videoqoe.pm b/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/videoqoe.pm index e28519266..ced1a2bbd 100644 --- a/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/videoqoe.pm +++ b/centreon-plugins/centreon/common/microsoft/skype/mssql/mode/videoqoe.pm @@ -87,7 +87,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeframe:s" => { name => 'timeframe', default => '900' }, diff --git a/centreon-plugins/centreon/common/monitoring/openmetrics/custom/file.pm b/centreon-plugins/centreon/common/monitoring/openmetrics/custom/file.pm new file mode 100644 index 000000000..b78ca7a7e --- /dev/null +++ b/centreon-plugins/centreon/common/monitoring/openmetrics/custom/file.pm @@ -0,0 +1,170 @@ +# +# Copyright 2019 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 centreon::common::monitoring::openmetrics::custom::file; + +use strict; +use warnings; +use centreon::plugins::misc; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + "hostname:s" => { name => 'hostname' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 10 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'cat' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'FILE OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + + return $self; + +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + $self->{option_results}->{remote} = 1; + } + + return 0; +} + +sub scrape { + my ($self, %options) = @_; + + return centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + ); +} + +1; + +__END__ + +=head1 NAME + +Openmetrics file + +=head1 SYNOPSIS + +Openmetrics file custom mode + +=head1 FILE OPTIONS + +=over 8 + +=item B<--hostname> + +Endpoint hostname (If remote). + +=item B<--ssh-option> + +Specify multiple options like the user (Example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (Default: none) + +=item B<--ssh-command> + +Specify ssh command (Default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'cat'). + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options). + +=item B<--timeout> + +Set SSH timeout (Default: 10). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/centreon/common/monitoring/openmetrics/custom/web.pm b/centreon-plugins/centreon/common/monitoring/openmetrics/custom/web.pm new file mode 100644 index 000000000..792a23ab4 --- /dev/null +++ b/centreon-plugins/centreon/common/monitoring/openmetrics/custom/web.pm @@ -0,0 +1,189 @@ +# +# Copyright 2019 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 centreon::common::monitoring::openmetrics::custom::web; + +use strict; +use warnings; +use centreon::plugins::http; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'hostname:s@' => { name => 'hostname' }, + 'port:s@' => { name => 'port' }, + 'proto:s@' => { name => 'proto' }, + 'urlpath:s@' => { name => 'url_path' }, + 'username:s@' => { name => 'username' }, + 'password:s@' => { name => 'password' }, + 'timeout:s@' => { name => 'timeout' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'WEB OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; + +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? shift(@{$self->{option_results}->{hostname}}) : undef; + $self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : 80; + $self->{proto} = (defined($self->{option_results}->{proto})) ? shift(@{$self->{option_results}->{proto}}) : 'http'; + $self->{url_path} = (defined($self->{option_results}->{url_path})) ? shift(@{$self->{option_results}->{url_path}}) : '/metrics'; + $self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : ''; + $self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : ''; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : 10; + + if (!defined($self->{hostname})) { + $self->{output}->add_option_msg(short_msg => "Need to specify hostname option."); + $self->{output}->option_exit(); + } + + if (!defined($self->{hostname}) || + scalar(@{$self->{option_results}->{hostname}}) == 0) { + return 0; + } + return 1; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{url_path} = $self->{url_path}; + $self->{option_results}->{timeout} = $self->{timeout}; + + if (defined($self->{username}) && $self->{username} ne '') { + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{username}; + $self->{option_results}->{password} = $self->{password}; + } +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub scrape { + my ($self, %options) = @_; + + $self->settings(); + + return $self->{http}->request(critical_status => '', warning_status => ''); +} + +1; + +__END__ + +=head1 NAME + +Openmetrics web + +=head1 SYNOPSIS + +Openmetrics web custom mode + +=head1 WEB OPTIONS + +=over 8 + +=item B<--hostname> + +Endpoint hostname. + +=item B<--port> + +Port used (Default: 80) + +=item B<--proto> + +Specify https if needed (Default: 'http') + +=item B<--urlpath> + +URL to scrape metrics from (Default: '/metrics'). + +=item B<--username> + +Endpoint username. + +=item B<--password> + +Endpoint password. + +=item B<--timeout> + +Set HTTP timeout (Default: 10). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/centreon/common/monitoring/openmetrics/scrape.pm b/centreon-plugins/centreon/common/monitoring/openmetrics/scrape.pm new file mode 100644 index 000000000..4c4f3324c --- /dev/null +++ b/centreon-plugins/centreon/common/monitoring/openmetrics/scrape.pm @@ -0,0 +1,65 @@ +# +# Copyright 2019 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 centreon::common::monitoring::openmetrics::scrape; + +use strict; +use warnings; +use centreon::plugins::misc; + +sub parse { + my (%options) = @_; + + my $result; + my $response = $options{custom}->scrape; + + foreach my $line (split /\n/, $response) { + $result->{metrics}->{$1}->{type} = $2 if ($line =~ /^#\sTYPE\s(\w+)\s(.*)$/); + $result->{metrics}->{$1}->{help} = $2 if ($line =~ /^#\sHELP\s(\w+)\s(.*)$/); + + next if ($line !~ /^[\d\/\s]*([\w.]+)(.*)?\s([\d.+-e]+)$/); + my ($metric, $dimensions, $value) = ($1, $2, $3); + + $dimensions =~ s/[{}]//g; + $dimensions =~ s/"/'/g; + my %dimensions = map { (split /=/) } split /,/, $dimensions; + + push @{$result->{metrics}->{$metric}->{data}}, { + value => centreon::plugins::misc::expand_exponential(value => $value), + dimensions => \%dimensions, + dimensions_string => $dimensions }; + } + + return $result->{metrics}; +} + +1; + +__END__ + +=head1 MODE + +Scrape metrics. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/board.pm b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/board.pm new file mode 100644 index 000000000..c12fcafa7 --- /dev/null +++ b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/board.pm @@ -0,0 +1,70 @@ +# +# Copyright 2019 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 centreon::common::polycom::endpoint::snmp::mode::components::board; + +use strict; +use warnings; +use centreon::common::polycom::endpoint::snmp::mode::components::resources qw($map_status); + +my $mapping = { + hardwareUcBoardStatus => { oid => '.1.3.6.1.4.1.13885.101.1.3.12.1', map => $map_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping->{hardwareUcBoardStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking boards"); + $self->{components}->{board} = {name => 'board', total => 0, skip => 0}; + return if ($self->check_filter(section => 'board')); + + return if (!defined($self->{results}->{ $mapping->{hardwareUcBoardStatus}->{oid} }) || + scalar(keys %{$self->{results}->{ $mapping->{hardwareUcBoardStatus}->{oid} }}) <= 0); + + my $instance = '0'; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{hardwareUcBoardStatus}->{oid} }, instance => $instance); + + return if ($self->check_filter(section => 'board', instance => $instance)); + $self->{components}->{board}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + 'overall boards status is %s [instance: %s]', + $result->{hardwareUcBoardStatus}, $instance + ) + ); + my $exit = $self->get_severity(section => 'board', label => 'default', value => $result->{hardwareUcBoardStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => + sprintf('Overall boards status is %s', $result->{hardwareUcBoardStatus} + ) + ); + } +} + +1; diff --git a/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/camera.pm b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/camera.pm new file mode 100644 index 000000000..ac586b444 --- /dev/null +++ b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/camera.pm @@ -0,0 +1,77 @@ +# +# Copyright 2019 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 centreon::common::polycom::endpoint::snmp::mode::components::camera; + +use strict; +use warnings; +use centreon::common::polycom::endpoint::snmp::mode::components::resources qw($map_status); + +my $mapping = { + hardwareCameraCamerasName => { oid => '.1.3.6.1.4.1.13885.101.1.3.6.2.1.2' }, + hardwareCameraCamerasStatus => { oid => '.1.3.6.1.4.1.13885.101.1.3.6.2.1.3', map => $map_status }, +}; +my $oid_hardwareCameraCamerasEntry = '.1.3.6.1.4.1.13885.101.1.3.6.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_hardwareCameraCamerasEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking cameras"); + $self->{components}->{camera} = {name => 'cameras', total => 0, skip => 0}; + return if ($self->check_filter(section => 'camera')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hardwareCameraCamerasEntry}})) { + next if ($oid !~ /^$mapping->{hardwareCameraCamerasStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hardwareCameraCamerasEntry}, instance => $instance); + + next if ($self->check_filter(section => 'camera', instance => $instance)); + $self->{components}->{camera}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "camera '%s' status is '%s' [instance = %s]", + $result->{hardwareCameraCamerasName}, + $result->{hardwareCameraCamerasStatus}, + $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'camera', instance => $instance, value => $result->{hardwareCameraCamerasStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Camera '%s' status is '%s'", + $result->{hardwareCameraCamerasName}, + $result->{hardwareCameraCamerasStatus} + ) + ); + } + } +} + +1; diff --git a/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/global.pm b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/global.pm new file mode 100644 index 000000000..c987e2f16 --- /dev/null +++ b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/global.pm @@ -0,0 +1,70 @@ +# +# Copyright 2019 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 centreon::common::polycom::endpoint::snmp::mode::components::global; + +use strict; +use warnings; +use centreon::common::polycom::endpoint::snmp::mode::components::resources qw($map_status); + +my $mapping = { + hardwareOverallStatus => { oid => '.1.3.6.1.4.1.13885.101.1.3.1', map => $map_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping->{hardwareOverallStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking global"); + $self->{components}->{global} = {name => 'global', total => 0, skip => 0}; + return if ($self->check_filter(section => 'global')); + + return if (!defined($self->{results}->{ $mapping->{hardwareOverallStatus}->{oid} }) || + scalar(keys %{$self->{results}->{ $mapping->{hardwareOverallStatus}->{oid} }}) <= 0); + + my $instance = '0'; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{hardwareOverallStatus}->{oid} }, instance => $instance); + + return if ($self->check_filter(section => 'global', instance => $instance)); + $self->{components}->{global}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + 'overall global status is %s [instance: %s]', + $result->{hardwareOverallStatus}, $instance + ) + ); + my $exit = $self->get_severity(section => 'global', label => 'default', value => $result->{hardwareOverallStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => + sprintf('Overall global status is %s', $result->{hardwareOverallStatus} + ) + ); + } +} + +1; diff --git a/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/microphone.pm b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/microphone.pm new file mode 100644 index 000000000..fa0bf0bd7 --- /dev/null +++ b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/microphone.pm @@ -0,0 +1,77 @@ +# +# Copyright 2019 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 centreon::common::polycom::endpoint::snmp::mode::components::microphone; + +use strict; +use warnings; +use centreon::common::polycom::endpoint::snmp::mode::components::resources qw($map_status); + +my $mapping = { + hardwareMicrophoneMicrophonesName => { oid => '.1.3.6.1.4.1.13885.101.1.3.5.2.1.2' }, + hardwareMicrophoneMicrophonesStatus => { oid => '.1.3.6.1.4.1.13885.101.1.3.5.2.1.3', map => $map_status }, +}; +my $oid_hardwareMicrophoneMicrophonesEntry = '.1.3.6.1.4.1.13885.101.1.3.5.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_hardwareMicrophoneMicrophonesEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking microphones"); + $self->{components}->{microphone} = {name => 'microphones', total => 0, skip => 0}; + return if ($self->check_filter(section => 'microphone')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hardwareMicrophoneMicrophonesEntry}})) { + next if ($oid !~ /^$mapping->{hardwareMicrophoneMicrophonesStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hardwareMicrophoneMicrophonesEntry}, instance => $instance); + + next if ($self->check_filter(section => 'microphone', instance => $instance)); + $self->{components}->{microphone}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "microphone '%s' status is '%s' [instance = %s]", + $result->{hardwareMicrophoneMicrophonesName}, + $result->{hardwareMicrophoneMicrophonesStatus}, + $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'microphone', instance => $instance, value => $result->{hardwareMicrophoneMicrophonesStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Microphone '%s' status is '%s'", + $result->{hardwareMicrophoneMicrophonesName}, + $result->{hardwareMicrophoneMicrophonesStatus} + ) + ); + } + } +} + +1; diff --git a/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/nic.pm b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/nic.pm new file mode 100644 index 000000000..992230c8b --- /dev/null +++ b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/nic.pm @@ -0,0 +1,77 @@ +# +# Copyright 2019 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 centreon::common::polycom::endpoint::snmp::mode::components::nic; + +use strict; +use warnings; +use centreon::common::polycom::endpoint::snmp::mode::components::resources qw($map_status); + +my $mapping = { + hardwareNICNICsName => { oid => '.1.3.6.1.4.1.13885.101.1.3.10.2.1.2' }, + hardwareNICNICsStatus => { oid => '.1.3.6.1.4.1.13885.101.1.3.10.2.1.6', map => $map_status }, +}; +my $oid_hardwareNICNICsEntry = '.1.3.6.1.4.1.13885.101.1.3.10.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_hardwareNICNICsEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking nics"); + $self->{components}->{nic} = {name => 'nics', total => 0, skip => 0}; + return if ($self->check_filter(section => 'nic')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hardwareNICNICsEntry}})) { + next if ($oid !~ /^$mapping->{hardwareNICNICsStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hardwareNICNICsEntry}, instance => $instance); + + next if ($self->check_filter(section => 'nic', instance => $instance)); + $self->{components}->{nic}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "nic '%s' status is '%s' [instance = %s]", + $result->{hardwareNICNICsName}, + $result->{hardwareNICNICsStatus}, + $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'nic', instance => $instance, value => $result->{hardwareNICNICsStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Nic '%s' status is '%s'", + $result->{hardwareNICNICsName}, + $result->{hardwareNICNICsStatus} + ) + ); + } + } +} + +1; diff --git a/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/ptc.pm b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/ptc.pm new file mode 100644 index 000000000..b767c1b84 --- /dev/null +++ b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/ptc.pm @@ -0,0 +1,70 @@ +# +# Copyright 2019 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 centreon::common::polycom::endpoint::snmp::mode::components::ptc; + +use strict; +use warnings; +use centreon::common::polycom::endpoint::snmp::mode::components::resources qw($map_status); + +my $mapping = { + hardwarePTCStatus => { oid => '.1.3.6.1.4.1.13885.101.1.3.11.1', map => $map_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping->{hardwarePTCStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking polycom touch control"); + $self->{components}->{ptc} = {name => 'ptc', total => 0, skip => 0}; + return if ($self->check_filter(section => 'ptc')); + + return if (!defined($self->{results}->{ $mapping->{hardwarePTCStatus}->{oid} }) || + scalar(keys %{$self->{results}->{ $mapping->{hardwarePTCStatus}->{oid} }}) <= 0); + + my $instance = '0'; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{hardwarePTCStatus}->{oid} }, instance => $instance); + + return if ($self->check_filter(section => 'ptc', instance => $instance)); + $self->{components}->{ptc}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + 'overall polycom touch control status is %s [instance: %s]', + $result->{hardwarePTCStatus}, $instance + ) + ); + my $exit = $self->get_severity(section => 'ptc', label => 'default', value => $result->{hardwarePTCStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => + sprintf('Overall polycom touch control status is %s', $result->{hardwarePTCStatus} + ) + ); + } +} + +1; diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/resources.pm b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/resources.pm similarity index 50% rename from centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/resources.pm rename to centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/resources.pm index 2b4aea7aa..8f23bd6a1 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/resources.pm +++ b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/components/resources.pm @@ -18,46 +18,19 @@ # limitations under the License. # -package hardware::server::sun::mgmt_cards::components::showenvironment::resources; +package centreon::common::polycom::endpoint::snmp::mode::components::resources; use strict; use warnings; use Exporter; -our $thresholds; +our $map_status; our @ISA = qw(Exporter); -our @EXPORT_OK = qw($thresholds); +our @EXPORT_OK = qw($map_status); -$thresholds = { - temperature => [ - ['^(?!(OK)$)', 'CRITICAL'], - ['^OK$', 'OK'], - ], - si => [ - ['^(?!(OFF)$)', 'CRITICAL'], - ['^OFF$', 'OK'], - ], - disk => [ - ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], - ['^OK|NOT PRESENT$', 'OK'], - ], - fan => [ - ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], - ['^OK|NOT PRESENT$', 'OK'], - ], - voltage => [ - ['^(?!(OK)$)', 'CRITICAL'], - ['^OK$', 'OK'], - ], - psu => [ - ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], - ['^OK|NOT PRESENT$', 'OK'], - ], - sensors => [ - ['^(?!(OK)$)', 'CRITICAL'], - ['^OK$', 'OK'], - ], +$map_status = { + 1 => 'disabled', 2 => 'ok', 3 => 'failed', }; -1; \ No newline at end of file +1; diff --git a/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/hardware.pm new file mode 100644 index 000000000..1828c302d --- /dev/null +++ b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/hardware.pm @@ -0,0 +1,97 @@ +# +# Copyright 2019 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 centreon::common::polycom::endpoint::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(?:global|microphone|camera|nic|ptc|board)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['ok', 'OK'], + ['disabled', 'OK'], + ['failed', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'centreon::common::polycom::endpoint::snmp::mode::components'; + $self->{components_module} = ['global', 'microphone', 'camera', 'nic', 'ptc', 'board']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1, no_absent => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'global', 'microphone', 'camera', 'nic', 'ptc', 'board'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=camera) +Can also exclude specific instance: --filter=camera,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='camera,WARNING,disabled' + +=back + +=cut diff --git a/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/videoconferencing.pm b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/videoconferencing.pm new file mode 100644 index 000000000..3545038cc --- /dev/null +++ b/centreon-plugins/centreon/common/polycom/endpoint/snmp/mode/videoconferencing.pm @@ -0,0 +1,84 @@ +# +# Copyright 2019 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 centreon::common::polycom::endpoint::snmp::mode::videoconferencing; + +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 }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'conferences-active', nlabel => 'videoconferencing.conferences.active.count', set => { + key_values => [ { name => 'NumberActiveConferences' } ], + output_template => 'Current Conferences : %s', + perfdatas => [ + { label => 'conferences_active', value => 'NumberActiveConferences_absolute', template => '%d', min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_conferenceNumberActiveConferences = '.1.3.6.1.4.1.13885.101.1.5.1.0'; + my $results = $options{snmp}->get_leef(oids => [$oid_conferenceNumberActiveConferences], nothing_quit => 1); + + $self->{global} = { NumberActiveConferences => $results->{$oid_conferenceNumberActiveConferences} }; +} + +1; + +__END__ + +=head1 MODE + +Check video conferencing usage. + +=over 8 + +=item B<--warning-conferences-active> + +Threshold warning. + +=item B<--critical-conferences-active> + +Threshold critical. + +=back + +=cut diff --git a/centreon-plugins/centreon/common/protocols/jmx/custom/jolokia.pm b/centreon-plugins/centreon/common/protocols/jmx/custom/jolokia.pm index 2774e8c89..91a252302 100644 --- a/centreon-plugins/centreon/common/protocols/jmx/custom/jolokia.pm +++ b/centreon-plugins/centreon/common/protocols/jmx/custom/jolokia.pm @@ -177,7 +177,11 @@ sub check_error { my ($self, %options) = @_; # 500-599 an error. 400 is an attribute not present - if ($options{response}->status() >= 500 || $options{response}->status() == 401 || $options{response}->status() == 408) { + my $status = $options{response}->status(); + if ($status >= 500 || + $status == 401 || + $status == 403 || + $status == 408) { $self->{output}->add_option_msg(short_msg => "protocol issue: " . $options{response}->error_text()); $self->{output}->option_exit(); } diff --git a/centreon-plugins/centreon/common/protocols/sql/mode/connectiontime.pm b/centreon-plugins/centreon/common/protocols/sql/mode/connectiontime.pm index c16758939..218b215d2 100644 --- a/centreon-plugins/centreon/common/protocols/sql/mode/connectiontime.pm +++ b/centreon-plugins/centreon/common/protocols/sql/mode/connectiontime.pm @@ -32,7 +32,6 @@ sub new { 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', }, diff --git a/centreon-plugins/centreon/common/protocols/sql/mode/sql.pm b/centreon-plugins/centreon/common/protocols/sql/mode/sql.pm index 1a562124c..8be2bdaed 100644 --- a/centreon-plugins/centreon/common/protocols/sql/mode/sql.pm +++ b/centreon-plugins/centreon/common/protocols/sql/mode/sql.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "sql-statement:s" => { name => 'sql_statement', }, "format:s" => { name => 'format', default => 'SQL statement result : %i.'}, diff --git a/centreon-plugins/centreon/common/protocols/sql/mode/sqlstring.pm b/centreon-plugins/centreon/common/protocols/sql/mode/sqlstring.pm index d673a2414..2044c08ad 100644 --- a/centreon-plugins/centreon/common/protocols/sql/mode/sqlstring.pm +++ b/centreon-plugins/centreon/common/protocols/sql/mode/sqlstring.pm @@ -105,7 +105,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "sql-statement:s" => { name => 'sql_statement' }, "key-column:s" => { name => 'key_column' }, diff --git a/centreon-plugins/centreon/common/radlan/mode/components/fan.pm b/centreon-plugins/centreon/common/radlan/mode/components/fan.pm new file mode 100644 index 000000000..c91449654 --- /dev/null +++ b/centreon-plugins/centreon/common/radlan/mode/components/fan.pm @@ -0,0 +1,74 @@ +# +# Copyright 2019 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 centreon::common::radlan::mode::components::fan; + +use strict; +use warnings; + +my %map_states = ( + 1 => 'normal', + 2 => 'warning', + 3 => 'critical', + 4 => 'shutdown', + 5 => 'notPresent', + 6 => 'notFunctioning', +); + +my $mapping = { + rlEnvMonFanStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.1.1.2' }, + rlEnvMonFanState => { oid => '.1.3.6.1.4.1.89.83.1.1.1.3', map => \%map_states }, +}; +my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.89.83.1.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_rlEnvMonFanStatusEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking fans'); + $self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'fan')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonFanStatusEntry}})) { + next if ($oid !~ /^$mapping->{rlEnvMonFanState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonFanStatusEntry}, instance => $instance); + + next if ($self->check_filter(section => 'fan', instance => $instance, name => $result->{rlEnvMonFanStatusDescr})); + next if ($result->{rlEnvMonFanState} eq 'notPresent' && + $self->absent_problem(section => 'fan', instance => $instance, name => $result->{rlEnvMonFanStatusDescr})); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fan '%s' state is %s [instance: %s]", + $result->{rlEnvMonFanStatusDescr}, $result->{rlEnvMonFanState}, $instance)); + my $exit = $self->get_severity(section => 'fan', value => $result->{rlEnvMonFanState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' state is %s.", $result->{rlEnvMonFanStatusDescr}, $result->{rlEnvMonFanState})); + } + } +} + +1; diff --git a/centreon-plugins/centreon/common/radlan/mode/components/psu.pm b/centreon-plugins/centreon/common/radlan/mode/components/psu.pm new file mode 100644 index 000000000..0e72fbdc5 --- /dev/null +++ b/centreon-plugins/centreon/common/radlan/mode/components/psu.pm @@ -0,0 +1,74 @@ +# +# Copyright 2019 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 centreon::common::radlan::mode::components::psu; + +use strict; +use warnings; + +my %map_states = ( + 1 => 'normal', + 2 => 'warning', + 3 => 'critical', + 4 => 'shutdown', + 5 => 'notPresent', + 6 => 'notFunctioning', +); + +my $mapping = { + rlEnvMonSupplyStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.2.1' }, + rlEnvMonSupplyState => { oid => '.1.3.6.1.4.1.89.83.1.2.1.3', map => \%map_states }, +}; +my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.89.83.1.2.1.2'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_rlEnvMonSupplyStatusEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking power supplies'); + $self->{components}->{psu} = { name => 'psus', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'psu')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) { + next if ($oid !~ /^$mapping->{rlEnvMonSupplyState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}, instance => $instance); + + next if ($self->check_filter(section => 'psu', instance => $instance, name => $result->{rlEnvMonSupplyStatusDescr})); + next if ($result->{rlEnvMonSupplyState} eq 'notPresent' && + $self->absent_problem(section => 'psu', instance => $instance, name => $result->{rlEnvMonSupplyStatusDescr})); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("power supply '%s' state is %s [instance: %s]", + $result->{rlEnvMonSupplyStatusDescr}, $result->{rlEnvMonSupplyState}, $instance)); + my $exit = $self->get_severity(section => 'psu', value => $result->{rlEnvMonSupplyState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' state is %s.", $result->{rlEnvMonSupplyStatusDescr}, $result->{rlEnvMonSupplyState})); + } + } +} + +1; diff --git a/centreon-plugins/centreon/common/radlan/mode/cpu.pm b/centreon-plugins/centreon/common/radlan/mode/cpu.pm index 698975bc2..626673a0d 100644 --- a/centreon-plugins/centreon/common/radlan/mode/cpu.pm +++ b/centreon-plugins/centreon/common/radlan/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '' }, diff --git a/centreon-plugins/centreon/common/radlan/mode/environment.pm b/centreon-plugins/centreon/common/radlan/mode/environment.pm index c4c9e98a9..ca5762645 100644 --- a/centreon-plugins/centreon/common/radlan/mode/environment.pm +++ b/centreon-plugins/centreon/common/radlan/mode/environment.pm @@ -20,257 +20,57 @@ package centreon::common::radlan::mode::environment; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.89.83.1.1.1'; -my $oid_rlEnvMonFanStatusDescr = '.1.3.6.1.4.1.89.83.1.1.1.2'; -my $oid_rlEnvMonFanState = '.1.3.6.1.4.1.89.83.1.1.1.3'; -my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.89.83.1.2.1'; -my $oid_rlEnvMonSupplyStatusDescr = '.1.3.6.1.4.1.89.83.1.2.1.2'; -my $oid_rlEnvMonSupplyState = '.1.3.6.1.4.1.89.83.1.2.1.3'; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^fan|psu$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['shutdown', 'WARNING'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['notFunctioning', 'CRITICAL'], + ['notPresent', 'OK'], + ['normal', 'OK'], + ], + }; + + $self->{components_path} = 'centreon::common::radlan::mode::components'; + $self->{components_module} = ['fan', 'psu']; +} -my $thresholds = { - psu => [ - ['shutdown', 'WARNING'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['notFunctioning', 'CRITICAL'], - ['notPresent', 'OK'], - ['normal', 'OK'], - ], - fan => [ - ['shutdown', 'WARNING'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['notFunctioning', 'CRITICAL'], - ['notPresent', 'OK'], - ['normal', 'OK'], - ], -}; +sub snmp_execute { + my ($self, %options) = @_; -my %map_states = ( - 1 => 'normal', - 2 => 'warning', - 3 => 'critical', - 4 => 'shutdown', - 5 => 'notPresent', - 6 => 'notFunctioning', -); + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "absent-problem:s" => { name => 'absent' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => {}); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - # There is a bug with get_leef and snmpv1. - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_rlEnvMonFanStatusEntry }, - { oid => $oid_rlEnvMonSupplyStatusEntry }, - ]); - - if ($self->{option_results}->{component} eq 'all') { - $self->check_fan(); - $self->check_psu(); - } elsif ($self->{option_results}->{component} eq 'fan') { - $self->check_fan(); - } elsif ($self->{option_results}->{component} eq 'psu') { - $self->check_psu(); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub absent_problem { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{absent}) && - $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Component '%s' instance '%s' is not present", - $options{section}, $options{instance})); - } - - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)")); - $self->{components}->{$options{section}}->{skip}++; - return 1; -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - -sub check_fan { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking fans"); - $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fan')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonFanStatusEntry}})) { - next if ($oid !~ /^$oid_rlEnvMonFanStatusDescr\.(.*)/); - my $instance = $self->{results}->{$oid_rlEnvMonFanStatusEntry}->{$oid}; - my $fan_state = $self->{results}->{$oid_rlEnvMonFanStatusEntry}->{$oid_rlEnvMonFanState . '.' . $1}; - - next if ($self->check_exclude(section => 'fan', instance => $instance)); - next if ($map_states{$fan_state} eq 'notPresent' && - $self->absent_problem(section => 'fan', instance => $instance)); - - $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan '%s' state is %s.", - $instance, $map_states{$fan_state})); - my $exit = $self->get_severity(section => 'fan', value => $map_states{$fan_state}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Fan '%s' state is %s.", $instance, $map_states{$fan_state})); - } - } -} - -sub check_psu { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking power supplies"); - $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) { - next if ($oid !~ /^$oid_rlEnvMonSupplyStatusDescr\.(.*)/); - my $instance = $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}->{$oid}; - my $psu_state = $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}->{$oid_rlEnvMonSupplyState . '.' . $1}; - - next if ($self->check_exclude(section => 'psu', instance => $instance)); - next if ($map_states{$psu_state} eq 'notPresent' && - $self->absent_problem(section => 'psu', instance => $instance)); - - $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Power supply '%s' state is %s.", - $instance, $map_states{$psu_state})); - my $exit = $self->get_severity(section => 'psu', value => $map_states{$psu_state}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Power supply '%s' state is %s.", $instance, $map_states{$psu_state})); - } - } -} - 1; __END__ =head1 MODE -Check environment (RADLAN-HWENVIROMENT) (Fans, Power Supplies). +Check environment (RADLAN-HWENVIROMENT). =over 8 @@ -279,10 +79,10 @@ Check environment (RADLAN-HWENVIROMENT) (Fans, Power Supplies). Which component to check (Default: 'all'). Can be: 'psu', 'fan'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=psu) -Can also exclude specific instance: --exclude='fan#fan2_unit1#' +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=fan,1 =item B<--absent-problem> diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwoptimization.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwoptimization.pm index dca33d757..b276f9fbd 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwoptimization.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwoptimization.pm @@ -88,7 +88,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '0.1'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwpassthrough.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwpassthrough.pm index f75625dba..6d1852253 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwpassthrough.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwpassthrough.pm @@ -84,7 +84,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '0.1'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/connections.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/connections.pm index d380b764f..63a58527d 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/connections.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/connections.pm @@ -103,7 +103,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; $options{options}->add_options(arguments => { }); return $self; diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/diskutilization.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/diskutilization.pm index d25e5da2d..a48ef1bb1 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/diskutilization.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/diskutilization.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '0.1'; $options{options}->add_options(arguments =>{ }); return $self; diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/loadaverage.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/loadaverage.pm index 6d8819a49..acd5f4a7e 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/loadaverage.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/loadaverage.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; $options{options}->add_options(arguments =>{ }); return $self; diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/status.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/status.pm index 91e01dac6..9eb7bfaed 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/status.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/status.pm @@ -81,7 +81,6 @@ sub new { 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 => '%{health} !~ /Healthy/ || %{status} !~ /running/' }, diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/temperature.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/temperature.pm index abbd060e7..844cec1e1 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/temperature.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/temperature.pm @@ -51,7 +51,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; $options{options}->add_options(arguments =>{ }); return $self; diff --git a/centreon-plugins/centreon/common/smcli/mode/healthstatus.pm b/centreon-plugins/centreon/common/smcli/mode/healthstatus.pm index 344b8a48e..e35573398 100644 --- a/centreon-plugins/centreon/common/smcli/mode/healthstatus.pm +++ b/centreon-plugins/centreon/common/smcli/mode/healthstatus.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "storage-command:s" => { name => 'storage_command', }, }); diff --git a/centreon-plugins/centreon/common/sun/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/sun/snmp/mode/hardware.pm index e2ee85901..09b946e47 100644 --- a/centreon-plugins/centreon/common/sun/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/sun/snmp/mode/hardware.pm @@ -63,7 +63,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/common/violin/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/violin/snmp/mode/hardware.pm index d4cae4777..b1cf88628 100644 --- a/centreon-plugins/centreon/common/violin/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/violin/snmp/mode/hardware.pm @@ -96,7 +96,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/centreon/plugins/alternative/Getopt.pm b/centreon-plugins/centreon/plugins/alternative/Getopt.pm index 3253010ea..f31603bf5 100644 --- a/centreon-plugins/centreon/plugins/alternative/Getopt.pm +++ b/centreon-plugins/centreon/plugins/alternative/Getopt.pm @@ -55,7 +55,7 @@ sub get_assigned_value { sub GetOptions { my (%opts) = @_; - + my $search_str = ',' . join(',', keys %opts) . ','; my $num_args = scalar(@ARGV); for (my $i = 0; $i < $num_args;) { diff --git a/centreon-plugins/centreon/plugins/backend/http/curl.pm b/centreon-plugins/centreon/plugins/backend/http/curl.pm index 215395cae..768ce915b 100644 --- a/centreon-plugins/centreon/plugins/backend/http/curl.pm +++ b/centreon-plugins/centreon/plugins/backend/http/curl.pm @@ -131,7 +131,7 @@ sub cb_debug { if ($type == $uservar->{constant_cb}->(name => 'CURLINFO_SSL_DATA_IN')) { $msg = sprintf("=> Recv SSL data: %s", $data); } - + $uservar->{output}->output_add(long_msg => $msg, debug => 1); return 0; } @@ -313,9 +313,9 @@ sub request { $content_type_forced = 1; } } - + $self->set_method(%options, content_type_forced => $content_type_forced, headers => $headers); - + if (scalar(@$headers) > 0) { $self->{curl_easy}->pushopt($self->{constant_cb}->(name => 'CURLOPT_HTTPHEADER'), $headers); } @@ -341,7 +341,7 @@ sub request { $self->{output}->add_option_msg(short_msg => 'curl perform error : ' . $@); $self->{output}->option_exit(); } - + $self->{response_code} = $self->{curl_easy}->getinfo($self->{constant_cb}->(name => 'CURLINFO_RESPONSE_CODE')); # Check response diff --git a/centreon-plugins/centreon/plugins/backend/http/lwp.pm b/centreon-plugins/centreon/plugins/backend/http/lwp.pm index fc2a4447b..6b2111bcb 100644 --- a/centreon-plugins/centreon/plugins/backend/http/lwp.pm +++ b/centreon-plugins/centreon/plugins/backend/http/lwp.pm @@ -41,6 +41,7 @@ sub new { $self->{output} = $options{output}; $self->{ua} = undef; + $self->{debug_handlers} = 0; return $self; } @@ -125,7 +126,8 @@ sub request { } } - if ($self->{output}->is_debug()) { + if ($self->{output}->is_debug() && $self->{debug_handlers} == 0) { + $self->{debug_handlers} = 1; $self->{ua}->add_handler("request_send", sub { my ($response, $ua, $handler) = @_; @@ -245,7 +247,6 @@ sub request { $self->{response}->www_authenticate =~ /(\S+)/); } - $self->{output}->output_add(long_msg => $self->{response}->content, debug => 1); $self->{output}->output_add(severity => $status, short_msg => $short_msg); $self->{output}->display(); diff --git a/centreon-plugins/centreon/plugins/dbi.pm b/centreon-plugins/centreon/plugins/dbi.pm index 690aa318b..ac10b3c8c 100644 --- a/centreon-plugins/centreon/plugins/dbi.pm +++ b/centreon-plugins/centreon/plugins/dbi.pm @@ -52,7 +52,7 @@ sub new { 'password:s@' => { name => 'password' }, 'connect-options:s@' => { name => 'connect_options' }, 'sql-errors-exit:s' => { name => 'sql_errors_exit', default => 'unknown' }, - 'timeout:i' => { name => 'timeout' }, + 'timeout:s' => { name => 'timeout' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'DBI OPTIONS', once => 1); @@ -92,7 +92,7 @@ sub class_handle_ALRM { sub handle_ALRM { my $self = shift; - + $self->disconnect(); $self->{output}->output_add(severity => $self->{sql_errors_exit}, short_msg => 'Timeout'); @@ -204,6 +204,7 @@ sub disconnect { if (defined($self->{instance})) { $self->{statement_handle} = undef; $self->{instance}->disconnect(); + $self->{instance} = undef; } } @@ -211,6 +212,8 @@ sub connect { my ($self, %options) = @_; my $dontquit = (defined($options{dontquit}) && $options{dontquit} == 1) ? 1 : 0; + return if (defined($self->{instance})); + # Set ENV if (defined($self->{env})) { foreach (keys %{$self->{env}}) { diff --git a/centreon-plugins/centreon/plugins/http.pm b/centreon-plugins/centreon/plugins/http.pm index ad0f86f1b..8ad028aea 100644 --- a/centreon-plugins/centreon/plugins/http.pm +++ b/centreon-plugins/centreon/plugins/http.pm @@ -30,10 +30,10 @@ sub new { if (!defined($options{noptions}) || $options{noptions} != 1) { $options{options}->add_options(arguments => { - "http-peer-addr:s" => { name => 'http_peer_addr' }, - "proxyurl:s" => { name => 'proxyurl' }, - "proxypac:s" => { name => 'proxypac' }, - "http-backend:s" => { name => 'http_backend', default => 'lwp' }, + 'http-peer-addr:s' => { name => 'http_peer_addr' }, + 'proxyurl:s' => { name => 'proxyurl' }, + 'proxypac:s' => { name => 'proxypac' }, + 'http-backend:s' => { name => 'http_backend', default => 'lwp' }, }); $options{options}->add_help(package => __PACKAGE__, sections => 'HTTP GLOBAL OPTIONS'); } @@ -87,6 +87,13 @@ sub check_options { $self->{output}->option_exit(); } + if (defined($options{request}->{curl_backend_options}) && + $self->{http_backend} eq 'curl') { + foreach (keys %{$options{request}->{curl_backend_options}}) { + $options{request}->{$_} = $options{request}->{curl_backend_options}->{$_}; + } + } + if (($options{request}->{proto} ne 'http') && ($options{request}->{proto} ne 'https')) { $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); $self->{output}->option_exit(); diff --git a/centreon-plugins/centreon/plugins/mode.pm b/centreon-plugins/centreon/plugins/mode.pm index 739f6b8a8..545d76cc9 100644 --- a/centreon-plugins/centreon/plugins/mode.pm +++ b/centreon-plugins/centreon/plugins/mode.pm @@ -36,7 +36,7 @@ sub new { $self->{output}->use_new_perfdata(value => 1) if (defined($options{force_new_perfdata}) && $options{force_new_perfdata} == 1); $self->{mode} = $options{mode}; - $self->{version} = undef; + $self->{version} = '1.0'; return $self; } diff --git a/centreon-plugins/centreon/plugins/multi.pm b/centreon-plugins/centreon/plugins/multi.pm new file mode 100644 index 000000000..a63ad96ad --- /dev/null +++ b/centreon-plugins/centreon/plugins/multi.pm @@ -0,0 +1,121 @@ +# +# Copyright 2019 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 centreon::plugins::multi; + +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; + + $options{options}->add_options(arguments => { + 'modes-exec:s' => { name => 'modes_exec' }, + 'option-mode:s@' => { name => 'option_mode' }, + }); + $self->{options} = $options{options}; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (!defined($self->{option_results}->{modes_exec})) { + $self->{output}->add_option_msg(short_msg => "Need to specify --modes-exec option."); + $self->{output}->option_exit(); + } + $self->{options_mode_extra} = {}; + if (defined($self->{option_results}->{option_mode})) { + foreach (@{$self->{option_results}->{option_mode}}) { + next if (! /^(.+?),(.*)$/); + $self->{options_mode_extra}->{$1} = [] if (!defined($self->{options_mode_extra}->{$1})); + push @{$self->{options_mode_extra}->{$1}}, $2; + } + } + + $self->{modes} = $options{modes}; +} + +sub run { + my ($self, %options) = @_; + + $self->{output}->parameter(attr => 'nodisplay', value => 1); + $self->{output}->parameter(attr => 'noexit_die', value => 1); + $self->{output}->use_new_perfdata(value => 1); + + my @modes = split /,/, $self->{option_results}->{modes_exec}; + foreach (@modes) { + next if (!defined($self->{modes}->{$_})); + eval { + centreon::plugins::misc::mymodule_load( + output => $self->{output}, + module => $self->{modes}->{$_}, + error_msg => "Cannot load module --mode $_" + ); + @ARGV = (@{$self->{options_mode_extra}->{$_}}) if (defined($self->{options_mode_extra}->{$_})); + $self->{output}->mode(name => $_); + + my $mode = $self->{modes}->{$_}->new(options => $self->{options}, output => $self->{output}, mode => $_); + $self->{options}->parse_options(); + my $option_results = $self->{options}->get_options(); + $mode->check_options(option_results => $option_results, %options); + $mode->run(%options); + }; + if ($@) { + $self->{output}->output_add(long_msg => 'eval result mode ' . $_ . ': ' . $@, debug => 1); + } + } + + $self->{output}->parameter(attr => 'nodisplay', value => 0); + $self->{output}->parameter(attr => 'noexit_die', value => 0); + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check multiple modes at once. You cannot set specific thresholds or filter options for modes. + +=over 8 + +=item B<--modes-exec> + +Which modes to select (separated by coma). +Example for linux: --modes-exec=cpu,memory,storage,interfaces + +=item B<--option-mode> + +Set options for a specifi mode (can be multiple). +Example interfaces and storage snmp: +--option-mode='interfaces,--statefile-dir=/tmp' --option-mode='interfaces,--add-traffic' --option-mode='storage,--statefile-dir=/tmp' + +=back + +=cut diff --git a/centreon-plugins/centreon/plugins/output.pm b/centreon-plugins/centreon/plugins/output.pm index 2795d08da..1ef936100 100644 --- a/centreon-plugins/centreon/plugins/output.pm +++ b/centreon-plugins/centreon/plugins/output.pm @@ -58,6 +58,9 @@ sub new { %{$self->{option_results}} = (); $self->{option_msg} = []; + + $self->{nodisplay} = 0; + $self->{noexit_die} = 0; $self->{is_output_xml} = 0; $self->{is_output_json} = 0; @@ -185,7 +188,7 @@ sub output_add { sub perfdata_add { my ($self, %options) = @_; my $perfdata = { - label => '', value => '', unit => '', warning => '', critical => '', min => '', max => '' + label => '', value => '', unit => '', warning => '', critical => '', min => '', max => '', mode => $self->{mode}, }; foreach (keys %options) { next if (!defined($options{$_})); @@ -376,6 +379,12 @@ sub output_xml { sub output_openmetrics { my ($self, %options) = @_; + centreon::plugins::misc::mymodule_load( + output => $self->{output}, module => 'Time::HiRes', + error_msg => "Cannot load module 'Time::HiRes'." + ); + + my $time_ms = int(Time::HiRes::time() * 1000); $self->change_perfdata(); foreach my $perf (@{$self->{perfdatas}}) { next if (defined($self->{option_results}->{filter_perfdata}) && @@ -388,7 +397,7 @@ sub output_openmetrics { if ($label =~ /^(.*?)#(.*)$/) { ($perf->{instance}, $label) = ($1, $2); } - my ($bucket, $append) = ('{plugin="' . $self->{plugin} . '",mode="' . $self->{mode} . '"', ''); + my ($bucket, $append) = ('{plugin="' . $self->{plugin} . '",mode="' . $perf->{mode} . '"', ''); foreach ('unit', 'warning', 'critical', 'min', 'max', 'instance') { if (defined($perf->{$_}) && $perf->{$_} ne '') { $bucket .= ',' . $_ . '="' . $perf->{$_} . '"'; @@ -396,7 +405,7 @@ sub output_openmetrics { } $bucket .= '}'; - print $label . $bucket . ' ' . $perf->{value} . "\n"; + print $label . $bucket . ' ' . $perf->{value} . ' ' . $time_ms . "\n"; } } @@ -448,6 +457,7 @@ sub output_txt { my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; + return if ($self->{nodisplay} == 1); if (defined($self->{global_short_concat_outputs}->{UNQUALIFIED_YET})) { $self->output_add(severity => uc($options{exit_litteral}), short_msg => $self->{global_short_concat_outputs}->{UNQUALIFIED_YET}); } @@ -485,6 +495,7 @@ sub display { my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; $force_long_output = 1 if (defined($self->{option_results}->{debug})); + return if ($self->{nodisplay} == 1); if (defined($self->{option_results}->{output_file})) { if (!open (STDOUT, '>', $self->{option_results}->{output_file})) { $self->output_add(severity => 'UNKNOWN', @@ -573,8 +584,10 @@ sub option_exit { sub exit { my ($self, %options) = @_; - # $options{exit_litteral} = exit + if ($self->{noexit_die} == 1) { + die 'exit'; + } if (defined($options{exit_litteral})) { exit $self->{errors}->{uc($options{exit_litteral})}; } @@ -770,6 +783,15 @@ sub to_utf8 { return centreon::plugins::misc::trim(Encode::decode('UTF-8', $value, $self->{perlqq})); } +sub parameter { + my ($self, %options) = @_; + + if (defined($options{attr})) { + $self->{$options{attr}} = $options{value}; + } + return $self->{$options{attr}}; +} + sub add_disco_entry { my ($self, %options) = @_; diff --git a/centreon-plugins/centreon/plugins/script.pm b/centreon-plugins/centreon/plugins/script.pm index a38689806..d0e224edc 100644 --- a/centreon-plugins/centreon/plugins/script.pm +++ b/centreon-plugins/centreon/plugins/script.pm @@ -28,7 +28,7 @@ use FindBin; use Pod::Usage; use Pod::Find qw(pod_where); -my %handlers = (DIE => {}); +my %handlers = (DIE => {}, ALRM => {}); my $global_version = '(dev)'; my $alternative_fatpacker = 0; @@ -45,18 +45,18 @@ sub new { # Avoid to destroy because it keeps a ref on the object. # A problem if we execute it multiple times in the same perl execution # Use prepare_destroy - $self->set_signal_handlers; + $self->set_signal_handlers(); return $self; } sub prepare_destroy { my ($self) = @_; - delete $handlers{DIE}->{$self}; + %handlers = undef; } sub set_signal_handlers { - my $self = shift; + my ($self) = @_; $SIG{__DIE__} = \&class_handle_DIE; $handlers{DIE}->{$self} = sub { $self->handle_DIE($_[0]) }; @@ -70,6 +70,12 @@ sub class_handle_DIE { } } +sub class_handle_ALRM { + foreach (keys %{$handlers{ALRM}}) { + &{$handlers{ALRM}->{$_}}(); + } +} + sub handle_DIE { my ($self, $msg) = @_; @@ -78,6 +84,13 @@ sub handle_DIE { $self->{output}->die_exit(); } +sub handle_ALRM { + my ($self) = @_; + + $self->{output}->add_option_msg(short_msg => 'script global timeout'); + $self->{output}->option_exit(); +} + sub get_global_version { return $global_version; } @@ -85,9 +98,7 @@ sub get_global_version { sub get_plugin { my ($self) = @_; - ###### # Need to load global 'Output' and 'Options' - ###### if ($alternative_fatpacker == 0) { require centreon::plugins::options; $self->{options} = centreon::plugins::options->new(); @@ -105,20 +116,28 @@ sub get_plugin { 'ignore-warn-msg' => { name => 'ignore_warn_msg' }, 'version' => { name => 'version' }, 'runas:s' => { name => 'runas' }, + 'global-timeout:s' => { name => 'global_timeout' }, 'environment:s%' => { name => 'environment' }, 'convert-args:s' => { name => 'convert_args' }, }); $self->{options}->parse_options(); - $self->{plugin} = $self->{options}->get_option(argument => 'plugin' ); - $self->{list_plugin} = $self->{options}->get_option(argument => 'list_plugin' ); - $self->{help} = $self->{options}->get_option(argument => 'help' ); - $self->{version} = $self->{options}->get_option(argument => 'version' ); - $self->{runas} = $self->{options}->get_option(argument => 'runas' ); - $self->{environment} = $self->{options}->get_option(argument => 'environment' ); - $self->{ignore_warn_msg} = $self->{options}->get_option(argument => 'ignore_warn_msg' ); - $self->{convert_args} = $self->{options}->get_option(argument => 'convert_args' ); + $self->{plugin} = $self->{options}->get_option(argument => 'plugin'); + $self->{list_plugin} = $self->{options}->get_option(argument => 'list_plugin'); + $self->{help} = $self->{options}->get_option(argument => 'help'); + $self->{version} = $self->{options}->get_option(argument => 'version'); + $self->{runas} = $self->{options}->get_option(argument => 'runas'); + $self->{environment} = $self->{options}->get_option(argument => 'environment'); + $self->{ignore_warn_msg} = $self->{options}->get_option(argument => 'ignore_warn_msg'); + $self->{convert_args} = $self->{options}->get_option(argument => 'convert_args'); + + my $global_timeout = $self->{options}->get_option(argument => 'global_timeout'); + if (defined($global_timeout) && $global_timeout =~ /(\d+)/) { + $SIG{ALRM} = \&class_handle_ALRM; + $handlers{ALRM}->{$self} = sub { $self->handle_ALRM() }; + alarm($1); + } $self->{output}->plugin(name => $self->{plugin}); $self->{output}->check_options(option_results => $self->{options}->get_options()); @@ -224,15 +243,17 @@ sub check_plugin_option { sub display_list_plugin { my ($self) = @_; $self->{plugins_result} = {}; - + if ($alternative_fatpacker == 1) { my $integrated_plugins = $self->fatpacker_find_plugin(); - foreach my $key (@$integrated_plugins) { + foreach my $key (sort @$integrated_plugins) { # Need to load it to get the description - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $key, - error_msg => 'Cannot load module --plugin.'); - + centreon::plugins::misc::mymodule_load( + output => $self->{output}, module => $key, + error_msg => 'Cannot load module --plugin.' + ); + my $name = $key; $name =~ s/\.pm//g; $name =~ s/\//::/g; @@ -254,7 +275,7 @@ sub display_list_plugin { # Search file 'plugin.pm' $self->check_directory($FindBin::Bin); - foreach my $key (keys %{$self->{plugins_result}}) { + foreach my $key (sort keys %{$self->{plugins_result}}) { my $name = $key; $name =~ s/^$FindBin::Bin\/(.*)\.pm/$1/; $name =~ s/\//::/g; @@ -354,8 +375,10 @@ sub run { centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{plugin}, error_msg => 'Cannot load module --plugin.'); my $plugin = $self->{plugin}->new(options => $self->{options}, output => $self->{output}); - $plugin->init(help => $self->{help}, - version => $self->{version}); + $plugin->init( + help => $self->{help}, + version => $self->{version} + ); $plugin->run(); } @@ -399,6 +422,10 @@ Perl warn messages are ignored (not displayed). Run the script as a different user (prefer to use directly the good user). +=item B<--global-timeout> + +Set script timeout. + =item B<--environment> Set environment variables for the script (prefer to set it before running it for better performance). diff --git a/centreon-plugins/centreon/plugins/script_custom.pm b/centreon-plugins/centreon/plugins/script_custom.pm index 5ea3251b4..8e0034c10 100644 --- a/centreon-plugins/centreon/plugins/script_custom.pm +++ b/centreon-plugins/centreon/plugins/script_custom.pm @@ -28,9 +28,6 @@ sub new { my ($class, %options) = @_; my $self = {}; bless $self, $class; - # $options{package} = parent package caller - # $options{options} = options object - # $options{output} = output object $self->{options} = $options{options}; $self->{output} = $options{output}; @@ -78,9 +75,9 @@ sub load_custom_mode { sub init { my ($self, %options) = @_; - # $options{version} = string version - # $options{help} = string help + # add meta mode + $self->{modes}->{multi} = 'centreon::plugins::multi'; if (defined($options{help}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) { $self->{options}->display_help(); $self->{output}->option_exit(); @@ -153,7 +150,11 @@ sub init { $self->{custommode_current}->set_options(option_results => $self->{option_results}); push @{$self->{custommode_stored}}, $self->{custommode_current}; } - $self->{mode}->check_options(option_results => $self->{option_results}, default => $self->{default}); + $self->{mode}->check_options( + option_results => $self->{option_results}, + default => $self->{default}, + modes => $self->{modes} # for meta mode multi + ); } sub load_password_mgr { @@ -197,7 +198,6 @@ sub run { sub is_mode { my ($self, %options) = @_; - # $options->{mode} = mode if (!defined($self->{modes}{$options{mode}})) { $self->{output}->add_option_msg(short_msg => "mode '" . $options{mode} . "' doesn't exist (use --list-mode option to show available modes)."); $self->{output}->option_exit(); @@ -207,7 +207,6 @@ sub is_mode { sub is_custommode { my ($self, %options) = @_; - # $options->{custommode} = mode if (!defined($self->{custom_modes}{$options{custommode}})) { $self->{output}->add_option_msg(short_msg => "mode '" . $options{custommode} . "' doesn't exist (use --list-custommode option to show available modes)."); $self->{output}->option_exit(); @@ -224,9 +223,13 @@ sub list_mode { my $self = shift; $self->{options}->display_help(); - $self->{output}->add_option_msg(long_msg => "Modes Available:"); + $self->{output}->add_option_msg(long_msg => 'Modes Meta:'); + $self->{output}->add_option_msg(long_msg => ' multi'); + $self->{output}->add_option_msg(long_msg => ''); + $self->{output}->add_option_msg(long_msg => 'Modes Available:'); foreach (sort keys %{$self->{modes}}) { - $self->{output}->add_option_msg(long_msg => " " . $_); + next if ($_ eq 'multi'); + $self->{output}->add_option_msg(long_msg => ' ' . $_); } $self->{output}->option_exit(nolabel => 1); } diff --git a/centreon-plugins/centreon/plugins/script_simple.pm b/centreon-plugins/centreon/plugins/script_simple.pm index 569d03e4a..ca141f7e5 100644 --- a/centreon-plugins/centreon/plugins/script_simple.pm +++ b/centreon-plugins/centreon/plugins/script_simple.pm @@ -27,9 +27,6 @@ sub new { my ($class, %options) = @_; my $self = {}; bless $self, $class; - # $options{package} = parent package caller - # $options{options} = options object - # $options{output} = output object $self->{options} = $options{options}; $self->{output} = $options{output}; @@ -62,9 +59,9 @@ sub new { sub init { my ($self, %options) = @_; - # $options{version} = string version - # $options{help} = string help + # add meta mode + $self->{modes}->{multi} = 'centreon::plugins::multi'; if (defined($options{help}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) { $self->{options}->display_help(); $self->{output}->option_exit(); @@ -119,7 +116,11 @@ sub init { $self->{option_results} = $self->{options}->get_options(); $self->{pass_mgr}->manage_options(option_results => $self->{option_results}) if (defined($self->{pass_mgr})); - $self->{mode}->check_options(option_results => $self->{option_results}, default => $self->{default}); + $self->{mode}->check_options( + option_results => $self->{option_results}, + default => $self->{default}, + modes => $self->{modes} # for meta mode multi + ); } sub load_password_mgr { @@ -171,9 +172,13 @@ sub list_mode { my $self = shift; $self->{options}->display_help(); - $self->{output}->add_option_msg(long_msg => "Modes Available:"); + $self->{output}->add_option_msg(long_msg => 'Modes Meta:'); + $self->{output}->add_option_msg(long_msg => ' multi'); + $self->{output}->add_option_msg(long_msg => ''); + $self->{output}->add_option_msg(long_msg => 'Modes Available:'); foreach (sort keys %{$self->{modes}}) { - $self->{output}->add_option_msg(long_msg => " " . $_); + next if ($_ eq 'multi'); + $self->{output}->add_option_msg(long_msg => ' ' . $_); } $self->{output}->option_exit(nolabel => 1); } diff --git a/centreon-plugins/centreon/plugins/script_snmp.pm b/centreon-plugins/centreon/plugins/script_snmp.pm index fc7378dd9..783e62e5e 100644 --- a/centreon-plugins/centreon/plugins/script_snmp.pm +++ b/centreon-plugins/centreon/plugins/script_snmp.pm @@ -29,9 +29,6 @@ sub new { my ($class, %options) = @_; my $self = {}; bless $self, $class; - # $options{package} = parent package caller - # $options{options} = options object - # $options{output} = output object $self->{options} = $options{options}; $self->{output} = $options{output}; @@ -46,7 +43,7 @@ sub new { } ); $self->{version} = '1.0'; - %{$self->{modes}} = (); + $self->{modes} = {}; $self->{default} = undef; $self->{options}->parse_options(); @@ -65,9 +62,9 @@ sub new { sub init { my ($self, %options) = @_; - # $options{version} = string version - # $options{help} = string help + # add meta mode + $self->{modes}->{multi} = 'centreon::plugins::multi'; if (defined($options{help}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) { $self->{options}->display_help(); $self->{output}->option_exit(); @@ -126,7 +123,12 @@ sub init { $self->{pass_mgr}->manage_options(option_results => $self->{option_results}) if (defined($self->{pass_mgr})); $self->{snmp}->check_options(option_results => $self->{option_results}); - $self->{mode}->check_options(option_results => $self->{option_results}, default => $self->{default}, snmp => $self->{snmp}); + $self->{mode}->check_options( + option_results => $self->{option_results}, + default => $self->{default}, + snmp => $self->{snmp}, + modes => $self->{modes} # for meta mode multi + ); } sub load_password_mgr { @@ -162,8 +164,7 @@ sub run { sub is_mode { my ($self, %options) = @_; - - # $options->{mode} = mode + if (!defined($self->{modes}{$options{mode}})) { $self->{output}->add_option_msg(short_msg => "mode '" . $options{mode} . "' doesn't exist (use --list-mode option to show available modes)."); $self->{output}->option_exit(); @@ -172,17 +173,21 @@ sub is_mode { sub version { my ($self) = @_; - $self->{output}->add_option_msg(short_msg => "Plugin Version: " . $self->{version}); + $self->{output}->add_option_msg(short_msg => 'Plugin Version: ' . $self->{version}); $self->{output}->option_exit(nolabel => 1); } sub list_mode { my ($self) = @_; $self->{options}->display_help(); - - $self->{output}->add_option_msg(long_msg => "Modes Available:"); + + $self->{output}->add_option_msg(long_msg => 'Modes Meta:'); + $self->{output}->add_option_msg(long_msg => ' multi'); + $self->{output}->add_option_msg(long_msg => ''); + $self->{output}->add_option_msg(long_msg => 'Modes Available:'); foreach (sort keys %{$self->{modes}}) { - $self->{output}->add_option_msg(long_msg => " " . $_); + next if ($_ eq 'multi'); + $self->{output}->add_option_msg(long_msg => ' ' . $_); } $self->{output}->option_exit(nolabel => 1); } diff --git a/centreon-plugins/centreon/plugins/script_sql.pm b/centreon-plugins/centreon/plugins/script_sql.pm index 4f782f927..f97d0812d 100644 --- a/centreon-plugins/centreon/plugins/script_sql.pm +++ b/centreon-plugins/centreon/plugins/script_sql.pm @@ -28,9 +28,6 @@ sub new { my ($class, %options) = @_; my $self = {}; bless $self, $class; - # $options{package} = parent package caller - # $options{options} = options object - # $options{output} = output object $self->{options} = $options{options}; $self->{output} = $options{output}; @@ -70,9 +67,9 @@ sub new { sub init { my ($self, %options) = @_; - # $options{version} = string version - # $options{help} = string help + # add meta mode + $self->{modes}->{multi} = 'centreon::plugins::multi'; if (defined($options{help}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) { $self->{options}->display_help(); $self->{output}->option_exit(); @@ -149,7 +146,11 @@ sub init { $self->{sqlmode_current}->set_options(option_results => $self->{option_results}); push @{$self->{sqlmode_stored}}, $self->{sqlmode_current}; } - $self->{mode}->check_options(option_results => $self->{option_results}, default => $self->{default}); + $self->{mode}->check_options( + option_results => $self->{option_results}, + default => $self->{default}, + modes => $self->{modes} # for meta mode multi + ); } sub load_password_mgr { @@ -221,9 +222,13 @@ sub list_mode { my $self = shift; $self->{options}->display_help(); - $self->{output}->add_option_msg(long_msg => "Modes Available:"); + $self->{output}->add_option_msg(long_msg => 'Modes Meta:'); + $self->{output}->add_option_msg(long_msg => ' multi'); + $self->{output}->add_option_msg(long_msg => ''); + $self->{output}->add_option_msg(long_msg => 'Modes Available:'); foreach (sort keys %{$self->{modes}}) { - $self->{output}->add_option_msg(long_msg => " " . $_); + next if ($_ eq 'multi'); + $self->{output}->add_option_msg(long_msg => ' ' . $_); } $self->{output}->option_exit(nolabel => 1); } diff --git a/centreon-plugins/centreon/plugins/script_wsman.pm b/centreon-plugins/centreon/plugins/script_wsman.pm index 493429677..2c9b62159 100644 --- a/centreon-plugins/centreon/plugins/script_wsman.pm +++ b/centreon-plugins/centreon/plugins/script_wsman.pm @@ -29,9 +29,6 @@ sub new { my ($class, %options) = @_; my $self = {}; bless $self, $class; - # $options{package} = parent package caller - # $options{options} = options object - # $options{output} = output object $self->{options} = $options{options}; $self->{output} = $options{output}; @@ -64,9 +61,9 @@ sub new { sub init { my ($self, %options) = @_; - # $options{version} = string version - # $options{help} = string help + # add meta mode + $self->{modes}->{multi} = 'centreon::plugins::multi'; if (defined($options{help}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) { $self->{options}->display_help(); $self->{output}->option_exit(); @@ -121,7 +118,11 @@ sub init { $self->{pass_mgr}->manage_options(option_results => $self->{option_results}) if (defined($self->{pass_mgr})); $self->{wsman}->check_options(option_results => $self->{option_results}); - $self->{mode}->check_options(option_results => $self->{option_results}, default => $self->{default}); + $self->{mode}->check_options( + option_results => $self->{option_results}, + default => $self->{default}, + modes => $self->{modes} # for meta mode multi + ); } sub load_password_mgr { @@ -175,9 +176,13 @@ sub list_mode { my $self = shift; $self->{options}->display_help(); - $self->{output}->add_option_msg(long_msg => "Modes Available:"); + $self->{output}->add_option_msg(long_msg => 'Modes Meta:'); + $self->{output}->add_option_msg(long_msg => ' multi'); + $self->{output}->add_option_msg(long_msg => ''); + $self->{output}->add_option_msg(long_msg => 'Modes Available:'); foreach (sort keys %{$self->{modes}}) { - $self->{output}->add_option_msg(long_msg => " " . $_); + next if ($_ eq 'multi'); + $self->{output}->add_option_msg(long_msg => ' ' . $_); } $self->{output}->option_exit(nolabel => 1); } diff --git a/centreon-plugins/centreon/plugins/statefile.pm b/centreon-plugins/centreon/plugins/statefile.pm index e93d28c57..012eb0418 100644 --- a/centreon-plugins/centreon/plugins/statefile.pm +++ b/centreon-plugins/centreon/plugins/statefile.pm @@ -34,17 +34,17 @@ sub new { bless $self, $class; if (defined($options{options})) { - $options{options}->add_options(arguments => - { - "memcached:s" => { name => 'memcached' }, - "redis-server:s" => { name => 'redis_server' }, - 'redis-attribute:s%' => { name => 'redis_attribute' }, - "memexpiration:s" => { name => 'memexpiration', default => 86400 }, - "statefile-dir:s" => { name => 'statefile_dir', default => $default_dir }, - "statefile-suffix:s" => { name => 'statefile_suffix', default => '' }, - "statefile-concat-cwd" => { name => 'statefile_concat_cwd' }, - "statefile-storable" => { name => 'statefile_storable' }, - }); + $options{options}->add_options(arguments => { + 'memcached:s' => { name => 'memcached' }, + 'redis-server:s' => { name => 'redis_server' }, + 'redis-attribute:s%' => { name => 'redis_attribute' }, + 'redis-db:s' => { name => 'redis_db' }, + 'memexpiration:s' => { name => 'memexpiration', default => 86400 }, + 'statefile-dir:s' => { name => 'statefile_dir', default => $default_dir }, + 'statefile-suffix:s' => { name => 'statefile_suffix', default => '' }, + 'statefile-concat-cwd' => { name => 'statefile_concat_cwd' }, + 'statefile-storable' => { name => 'statefile_storable' }, + }); $options{options}->add_help(package => __PACKAGE__, sections => 'RETENTION OPTIONS', once => 1); } @@ -76,7 +76,7 @@ sub check_options { $self->{redis_attributes} = ''; if (defined($options{option_results}->{redis_attribute})) { foreach (keys %{$options{option_results}->{redis_attribute}}) { - $self->{redis_attributes} .= "$_ => " . $options{option_results}->{redis_attribute}->{$_} . ", "; + $self->{redis_attributes} .= "$_ => " . $options{option_results}->{redis_attribute}->{$_} . ', '; } } @@ -85,6 +85,12 @@ sub check_options { eval { $self->{redis_cnx} = Redis->new(server => $options{option_results}->{redis_server}, eval $self->{redis_attributes}); + if (defined($self->{redis_cnx}) && + defined($options{option_results}->{redis_db}) && + $options{option_results}->{redis_db} ne '' + ) { + $self->{redis_cnx}->select($options{option_results}->{redis_db}); + } }; } @@ -147,7 +153,7 @@ sub read { return 0; } - if (! -e $self->{statefile_dir} . "/" . $self->{statefile}) { + if (! -e $self->{statefile_dir} . '/' . $self->{statefile}) { if (! -w $self->{statefile_dir} || ! -x $self->{statefile_dir}) { $self->error(1); $self->{output}->add_option_msg(short_msg => "Cannot write statefile '" . $self->{statefile_dir} . "/" . $self->{statefile} . "'. Need write/exec permissions on directory."); @@ -156,20 +162,20 @@ sub read { } } return 0; - } elsif (! -w $self->{statefile_dir} . "/" . $self->{statefile}) { + } elsif (! -w $self->{statefile_dir} . '/' . $self->{statefile}) { $self->error(1); $self->{output}->add_option_msg(short_msg => "Cannot write statefile '" . $self->{statefile_dir} . "/" . $self->{statefile} . "'. Need write permissions on file."); if ($self->{no_quit} == 0) { $self->{output}->option_exit(); } return 1; - } elsif (! -s $self->{statefile_dir} . "/" . $self->{statefile}) { + } elsif (! -s $self->{statefile_dir} . '/' . $self->{statefile}) { # Empty file. Not a problem. Maybe plugin not manage not values return 0; } if ($self->{storable} == 1) { - open FILE, $self->{statefile_dir} . "/" . $self->{statefile}; + open FILE, $self->{statefile_dir} . '/' . $self->{statefile}; eval { $self->{datas} = Storable::fd_retrieve(*FILE); }; @@ -180,7 +186,7 @@ sub read { } close FILE; } else { - unless (my $return = do $self->{statefile_dir} . "/" . $self->{statefile}) { + unless (my $return = do $self->{statefile_dir} . '/' . $self->{statefile}) { # File is corrupted surely. We'll reset it return 0; #if ($@) { @@ -221,21 +227,21 @@ sub write { my ($self, %options) = @_; if ($self->{memcached_ok} == 1) { - Memcached::libmemcached::memcached_set($self->{memcached}, $self->{statefile_dir} . "/" . $self->{statefile}, - Data::Dumper->Dump([$options{data}], ["datas"]), $self->{memexpiration}); + Memcached::libmemcached::memcached_set($self->{memcached}, $self->{statefile_dir} . '/' . $self->{statefile}, + Data::Dumper->Dump([$options{data}], ['datas']), $self->{memexpiration}); if (defined($self->{memcached}->errstr) && $self->{memcached}->errstr =~ /^SUCCESS$/i) { return ; } } if (defined($self->{redis_cnx})) { - return if (defined($self->{redis_cnx}->set($self->{statefile_dir} . "/" . $self->{statefile}, Data::Dumper->Dump([$options{data}], ["datas"]), + return if (defined($self->{redis_cnx}->set($self->{statefile_dir} . '/' . $self->{statefile}, Data::Dumper->Dump([$options{data}], ['datas']), 'EX', $self->{memexpiration}))); } - open FILE, ">", $self->{statefile_dir} . "/" . $self->{statefile}; + open FILE, '>', $self->{statefile_dir} . '/' . $self->{statefile}; if ($self->{storable} == 1) { Storable::store_fd($options{data}, *FILE); } else { - print FILE Data::Dumper->Dump([$options{data}], ["datas"]); + print FILE Data::Dumper->Dump([$options{data}], ['datas']); } close FILE; } @@ -268,6 +274,10 @@ Redis server to use (only one server). Set Redis Options (--redis-attribute="cnx_timeout=5"). +=item B<--redis-db> + +Set Redis database index. + =item B<--memexpiration> Time to keep data in seconds (Default: 86400). diff --git a/centreon-plugins/centreon/plugins/templates/catalog_functions.pm b/centreon-plugins/centreon/plugins/templates/catalog_functions.pm index 9e0cf76ab..7c3815744 100644 --- a/centreon-plugins/centreon/plugins/templates/catalog_functions.pm +++ b/centreon-plugins/centreon/plugins/templates/catalog_functions.pm @@ -38,17 +38,17 @@ sub catalog_status_threshold { my $label = $self->{label}; $label =~ s/-/_/g; - if (defined($self->{instance_mode}->{option_results}->{ok_status}) && $self->{instance_mode}->{option_results}->{ok_status} ne '' && - eval "$self->{instance_mode}->{option_results}->{ok_status}") { + if (defined($self->{instance_mode}->{option_results}->{'ok_' . $label}) && $self->{instance_mode}->{option_results}->{'ok_' . $label} ne '' && + eval "$self->{instance_mode}->{option_results}->{'ok_' . $label}") { $status = 'ok'; } elsif (defined($self->{instance_mode}->{option_results}->{'critical_' . $label}) && $self->{instance_mode}->{option_results}->{'critical_' . $label} ne '' && eval "$self->{instance_mode}->{option_results}->{'critical_' . $label}") { $status = 'critical'; } elsif (defined($self->{instance_mode}->{option_results}->{'warning_' . $label}) && $self->{instance_mode}->{option_results}->{'warning_' . $label} ne '' && - eval "$self->{instance_mode}->{option_results}->{'warning_' . $label}") { + eval "$self->{instance_mode}->{option_results}->{'warning_' . $label}") { $status = 'warning'; } elsif (defined($self->{instance_mode}->{option_results}->{'unknown_' . $label}) && $self->{instance_mode}->{option_results}->{'unknown_' . $label} ne '' && - eval "$self->{instance_mode}->{option_results}->{'unknown_' . $label}") { + eval "$self->{instance_mode}->{option_results}->{'unknown_' . $label}") { $status = 'unknown'; } }; @@ -63,7 +63,7 @@ sub catalog_status_calc { my ($self, %options) = @_; foreach (keys %{$options{new_datas}}) { - if (/^$self->{instance}_(.*)/) { + if (/^\Q$self->{instance}\E_(.*)/) { $self->{result_values}->{$1} = $options{new_datas}->{$_}; } } diff --git a/centreon-plugins/centreon/plugins/templates/counter.pm b/centreon-plugins/centreon/plugins/templates/counter.pm index d6bbd2113..1098c3306 100644 --- a/centreon-plugins/centreon/plugins/templates/counter.pm +++ b/centreon-plugins/centreon/plugins/templates/counter.pm @@ -174,13 +174,18 @@ sub check_options { $self->SUPER::init(%options); if (defined($self->{option_results}->{list_counters})) { - my $list_counter = "Counter list:"; + my $list_counter = 'counter list:'; + my $th_counter = ''; foreach my $key (keys %{$self->{maps_counters}}) { foreach (@{$self->{maps_counters}->{$key}}) { + my $label = $_->{label}; + $label =~ s/-//g; $list_counter .= " " . $_->{label}; + $th_counter .= " --warning-$_->{label}='\$_SERVICEWARNING" . uc($label) . "\$' --critical-$_->{label}='\$_SERVICECRITICAL" . uc($label) . "\$'"; } } $self->{output}->output_add(short_msg => $list_counter); + $self->{output}->output_add(long_msg => 'configuration: ' . $th_counter); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); $self->{output}->exit(); } @@ -445,6 +450,7 @@ sub run_multiple_instances { my ($self, %options) = @_; return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1); + my $use_new_perfdata = $self->{output}->use_new_perfdata(); my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? $options{multiple_parent} : 0; my $indent_long_output = defined($options{indent_long_output}) ? $options{indent_long_output} : ''; my $no_message_multiple = 1; @@ -469,7 +475,7 @@ sub run_multiple_instances { $_->{label} !~ /$self->{option_results}->{filter_counters}/); my $instance = $id; - if ($multiple_parent == 1 && $multiple == 1) { + if ($use_new_perfdata || ($multiple_parent == 1 && $multiple == 1)) { $instance = $options{instance_parent} . ($self->{output}->get_instance_perfdata_separator()) . $id; } elsif ($multiple_parent == 1 && $multiple == 0) { $instance = $options{instance_parent}; diff --git a/centreon-plugins/centreon/plugins/values.pm b/centreon-plugins/centreon/plugins/values.pm index ecb947677..b509edf40 100644 --- a/centreon-plugins/centreon/plugins/values.pm +++ b/centreon-plugins/centreon/plugins/values.pm @@ -113,7 +113,7 @@ sub threshold_check { my $warn = defined($self->{threshold_warn}) ? $self->{threshold_warn} : 'warning-' . $self->{thlabel}; my $crit = defined($self->{threshold_crit}) ? $self->{threshold_crit} : 'critical-' . $self->{thlabel}; - my $first = ${${$self->{key_values}}[0]}{name}; + my $first = defined($self->{key_values}->[0]) ? $self->{key_values}->[0]->{name} : ''; my $value; if (!defined($self->{threshold_use})) { diff --git a/centreon-plugins/changelog b/centreon-plugins/changelog index a6b1bf094..343ae9203 100644 --- a/centreon-plugins/changelog +++ b/centreon-plugins/changelog @@ -1,25 +1,39 @@ -2019-XX-XX Quentin Garnier +2019-07-04 Quentin Garnier + * Plugin added: RabbitMQ Rest API + * Plugin added: VMware VeloCloud Rest API + * Plugin added: InfluxDB + * Plugin added: MongoDB + * Plugin added: Aruba Instant SNMP * Plugin added: Cisco ACI APIC Rest API * Plugin added: OpenLDAP * Plugin added: SCCM * Plugin added: Cisco ESA XML API - * Plugin added: MongoDB + * Plugin added: Protocol NRPE * Plugin added: Ovirt Rest API * Plugin added: Keepalived SNMP * Plugin added: Openweathermap Rest API * Plugin added: 3CX Rest API * Plugin added: Atto FiberBridge SNMP * Plugin added: Buffalo TeraStation SNMP + * Plugin added: PDU Schleifenbauer Gateway SNMP + * Plugin added: Ansible Tower + * Plugin added: Dell ME4 Rest API + * Plugin added: Avaya AES SNMP + * Plugin added: Arcseve UDP MSSQL * Mode added: [oracle] 'librarycacheusage' * Mode added: [oracle] 'dictionarycacheusage' * Mode added: [oracle] 'redologusage' * Enhancement: [haproxy/snmp] manage oss mib (#1475) * Enhancement: [oracle] Fix segfault with last DBD::Oracle + * Break: [elasticsearch] plugin refactoring * Break: [pdu/apc] modes refactoring * Break: [pdu/eaton] modes refactoring * Break: [apps/lmsensors] modes refactoring * Break: [cisco/standard] 'cpu', 'memory' refactoring * Break: [3par/ssh] modes refactoring + * Break: [mysql] 'threads-connected' refactoring + * Break: [snmp_standard] 'swap' refactoring + * Fix: Ctrl+F "Fix" on commits page 2019-04-12 Quentin Garnier * Plugin added: Google Cloud Platform Compute Engine API diff --git a/centreon-plugins/cloud/aws/billing/mode/estimatedcharges.pm b/centreon-plugins/cloud/aws/billing/mode/estimatedcharges.pm index 3ce776ee1..19f81b26e 100644 --- a/centreon-plugins/cloud/aws/billing/mode/estimatedcharges.pm +++ b/centreon-plugins/cloud/aws/billing/mode/estimatedcharges.pm @@ -28,23 +28,24 @@ use warnings; sub prefix_charges_output { my ($self, %options) = @_; - return "Service '" . $self->{option_results}->{service} . "' "; + return "Service '" . $options{instance_value}->{display} . "' "; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'estimatedcharges', type => 0, cb_prefix_output => 'prefix_charges_output' }, + { name => 'services', type => 1, cb_prefix_output => 'prefix_charges_output', + message_multiple => 'All services estimated charges are ok' }, ]; - $self->{maps_counters}->{estimatedcharges} = [ - { label => 'billing', set => { + $self->{maps_counters}->{services} = [ + { label => 'billing', nlabel => 'billing.estimatedcharges.usd', set => { key_values => [ { name => 'estimated_charges' }, { name => 'display' } ], - output_template => 'estimated charges: %.2f USD', + output_template => 'Estimated Charges: %.2f USD', perfdatas => [ - { label => 'billing', value => 'estimated_charges_absolute', template => '%.2f', - unit => 'USD' }, + { value => 'estimated_charges_absolute', template => '%.2f', unit => 'USD', + label_extra_instance => 1 }, ], } }, @@ -53,15 +54,13 @@ sub set_counters { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "service:s" => { name => 'service' }, - "currency:s" => { name => 'currency', default => 'USD' }, - }); + $options{options}->add_options(arguments => { + "service:s@" => { name => 'service' }, + "currency:s" => { name => 'currency', default => 'USD' }, + }); return $self; } @@ -87,20 +86,25 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - my $metric_results = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, - namespace => 'AWS/Billing', - dimensions => [ { Name => 'ServiceName', Value => $self->{option_results}->{service} }, { Name => 'Currency', Value => $self->{option_results}->{currency} } ], - metrics => ['EstimatedCharges'], - statistics => ['Maximum'], - timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, - ); + foreach my $service (@{$self->{option_results}->{service}}) { + my $metric_results = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/Billing', + dimensions => [ + { Name => 'ServiceName', Value => $service }, + { Name => 'Currency', Value => $self->{option_results}->{currency} } + ], + metrics => ['EstimatedCharges'], + statistics => ['Maximum'], + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); - $self->{estimatedcharges}->{estimated_charges} = $metric_results->{'EstimatedCharges'}->{'maximum'} if defined($metric_results->{'EstimatedCharges'}->{'maximum'}); - $self->{estimatedcharges}->{display} = $self->{option_results}->{service}; + $self->{services}->{$service}->{estimated_charges} = $metric_results->{'EstimatedCharges'}->{'maximum'} if defined($metric_results->{'EstimatedCharges'}->{'maximum'}); + $self->{services}->{$service}->{display} = $service; + } - if (scalar(keys %{$self->{estimatedcharges}}) <= 0) { + if (scalar(keys %{$self->{services}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No value.'); $self->{output}->option_exit(); } @@ -124,7 +128,7 @@ See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/billing-metr =item B<--service> -Set the Amazon service (Required). +Set the Amazon service (Required) (Can be multiple). =item B<--warning-billing> diff --git a/centreon-plugins/cloud/aws/billing/mode/listservices.pm b/centreon-plugins/cloud/aws/billing/mode/listservices.pm index 1696f580c..80f1a6bcd 100644 --- a/centreon-plugins/cloud/aws/billing/mode/listservices.pm +++ b/centreon-plugins/cloud/aws/billing/mode/listservices.pm @@ -30,10 +30,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => {}); return $self; } @@ -48,8 +45,10 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{dimensions} = $options{custom}->cloudwatch_list_metrics(region => $self->{aws_region}, - namespace => 'AWS/Billing'); + $self->{dimensions} = $options{custom}->cloudwatch_list_metrics( + region => $self->{aws_region}, + namespace => 'AWS/Billing' + ); } sub run { diff --git a/centreon-plugins/cloud/aws/cloudfront/mode/errors.pm b/centreon-plugins/cloud/aws/cloudfront/mode/errors.pm index 088900016..67fe260af 100644 --- a/centreon-plugins/cloud/aws/cloudfront/mode/errors.pm +++ b/centreon-plugins/cloud/aws/cloudfront/mode/errors.pm @@ -25,33 +25,68 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my %metrics_mapping = ( + 'TotalErrorRate' => { + 'output' => 'Total Error Rate', + 'label' => 'errorrate-total', + 'nlabel' => 'cloudfront.errorrate.total.percentage', + }, + '4xxErrorRate' => { + 'output' => '4xx Error Rate', + 'label' => 'errorrate-4xx', + 'nlabel' => 'cloudfront.errorrate.4xx.percentage', + }, + '5xxErrorRate' => { + 'output' => '5xx Error Rate', + 'label' => 'errorrate-5xx', + 'nlabel' => 'cloudfront.errorrate.5xx.percentage', + }, +); + sub prefix_metric_output { my ($self, %options) = @_; - return "Instance '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; + return "Instance '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking Instance '" . $options{instance_value}->{display} . "' "; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All errors metrics are ok", skipped_code => { -10 => 1 } }, + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All instances metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - foreach my $statistic ('minimum', 'maximum', 'average', 'sum') { - foreach my $metric ('TotalErrorRate', '4xxErrorRate', '5xxErrorRate') { - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' } ], - output_template => $metric . ': %.2f %%', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%.2f', min => 0, max => 100, unit => '%', - label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; } } @@ -60,12 +95,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "id:s@" => { name => 'id' }, - "filter-metric:s" => { name => 'filter_metric' }, - }); + $options{options}->add_options(arguments => { + "id:s@" => { name => 'id' }, + "filter-metric:s" => { name => 'filter_metric' }, + }); return $self; } @@ -98,7 +131,7 @@ sub check_options { } } - foreach my $metric ('TotalErrorRate', '4xxErrorRate', '5xxErrorRate') { + foreach my $metric (keys %metrics_mapping) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); @@ -125,15 +158,14 @@ sub manage_selection { foreach my $statistic (@{$self->{aws_statistics}}) { next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance; - $self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic); - $self->{metric}->{$instance . "_" . lc($statistic)}->{timeframe} = $self->{aws_timeframe}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } - if (scalar(keys %{$self->{metric}}) <= 0) { + if (scalar(keys %{$self->{metrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); $self->{output}->option_exit(); } @@ -149,9 +181,10 @@ Check CloudFront instances errors. Example: perl centreon_plugins.pl --plugin=cloud::aws::cloudfront::plugin --custommode=paws --mode=errors --region='eu-west-1' ---id='E8T734E1AF1L4' --statistic='sum' --critical-totalerrorsrate-sum='10' --verbose +--id='E8T734E1AF1L4' --statistic='average' --critical-totalerrorsrate='10' --verbose -See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cf-metricscollected.html' for more informations. +See 'https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/monitoring-using-cloudwatch.html' +for more informations. Default statistic: 'average' / Valid statistic: 'average'. @@ -166,15 +199,15 @@ Set the instance id (Required) (Can be multiple). Filter metrics (Can be: 'TotalErrorRate', '4xxErrorRate', '5xxErrorRate') (Can be a regexp). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-*> -Thresholds warning ($metric$ can be: 'totalerrorrate', '4xxerrorrate', '5xxerrorrate', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning (Can be: 'errorrate-total', +'errorrate-4xx', 'errorrate-5xx'). -=item B<--critical-$metric$-$statistic$> +=item B<--critical-*> -Thresholds critical ($metric$ can be: 'totalerrorrate', '4xxerrorrate', '5xxerrorrate', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds critical (Can be: 'errorrate-total', +'errorrate-4xx', 'errorrate-5xx'). =back diff --git a/centreon-plugins/cloud/aws/cloudfront/mode/requests.pm b/centreon-plugins/cloud/aws/cloudfront/mode/requests.pm index b6c6d9a8d..937cdafeb 100644 --- a/centreon-plugins/cloud/aws/cloudfront/mode/requests.pm +++ b/centreon-plugins/cloud/aws/cloudfront/mode/requests.pm @@ -25,45 +25,71 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my %metrics_mapping = ( + 'Requests' => { + 'output' => 'Requests', + 'label' => 'requests', + 'nlabel' => { + 'absolute' => 'cloudfront.requests.count', + 'per_second' => 'cloudfront.requests.persecond', + }, + }, +); + sub prefix_metric_output { my ($self, %options) = @_; - return "Instance '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; + return "Instance '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking Instance '" . $options{instance_value}->{display} . "' "; } sub custom_metric_calc { my ($self, %options) = @_; $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; - $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric} . '_' . $options{extra_options}->{stat}}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}}; $self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe}; - $self->{result_values}->{stat} = $options{extra_options}->{stat}; $self->{result_values}->{metric} = $options{extra_options}->{metric}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; } sub custom_metric_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, - threshold => [ { label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'critical' }, - { label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check( + value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, + threshold => [ { label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ]); return $exit; } sub custom_metric_perfdata { my ($self, %options) = @_; - my $extra_label = ''; - $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add(label => lc($self->{result_values}->{metric}) . "_" . lc($self->{result_values}->{stat}) . $extra_label, - unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'requests/s' : 'requests', - value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - ); + $self->{output}->perfdata_add( + instances => $self->{instance}, + label => $metrics_mapping{$self->{result_values}->{metric}}->{label}, + nlabel => defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{per_second} : + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{absolute}, + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'requests/s' : 'requests', + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $self->{result_values}->{value_per_sec} : + $self->{result_values}->{value}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + ); } sub custom_metric_output { @@ -72,10 +98,10 @@ sub custom_metric_output { if (defined($self->{instance_mode}->{option_results}->{per_sec})) { my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}); - $msg = $self->{result_values}->{metric} . ": " . $value . "requests/s"; + $msg = $metrics_mapping{$self->{result_values}->{metric}}->{output} . ": " . $value . " requests/s"; } else { my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}); - $msg = $self->{result_values}->{metric} . ": " . $value . "requests"; + $msg = $metrics_mapping{$self->{result_values}->{metric}}->{output} . ": " . $value . " requests"; } return $msg; } @@ -84,31 +110,36 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All requests metrics are ok", skipped_code => { -10 => 1 } }, + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All instances metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - foreach my $statistic ('minimum', 'maximum', 'average', 'sum') { - foreach my $metric ('Requests') { - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' }, { name => 'timeframe' } ], - closure_custom_calc => $self->can('custom_metric_calc'), - closure_custom_calc_extra_options => { metric => $metric, stat => $statistic }, - closure_custom_output => $self->can('custom_metric_output'), - closure_custom_perfdata => $self->can('custom_metric_perfdata'), - closure_custom_threshold_check => $self->can('custom_metric_threshold'), - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + set => { + key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_metric_calc'), + closure_custom_calc_extra_options => { metric => $metric }, + closure_custom_output => $self->can('custom_metric_output'), + closure_custom_perfdata => $self->can('custom_metric_perfdata'), + closure_custom_threshold_check => $self->can('custom_metric_threshold'), + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; } } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "id:s@" => { name => 'id' }, "per-sec" => { name => 'per_sec' }, @@ -165,17 +196,20 @@ sub manage_selection { foreach my $metric (@{$self->{aws_metrics}}) { foreach my $statistic (@{$self->{aws_statistics}}) { - next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && + !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance; - $self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic); - $self->{metric}->{$instance . "_" . lc($statistic)}->{timeframe} = $self->{aws_timeframe}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{timeframe} = $self->{aws_timeframe}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } - if (scalar(keys %{$self->{metric}}) <= 0) { + if (scalar(keys %{$self->{metrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); $self->{output}->option_exit(); } @@ -191,9 +225,10 @@ Check CloudFront instances requests. Example: perl centreon_plugins.pl --plugin=cloud::aws::cloudfront::plugin --custommode=paws --mode=requests --region='eu-west-1' ---id='E8T734E1AF1L4' --statistic='sum' --critical-requests-sum='10' --verbose +--id='E8T734E1AF1L4' --statistic='sum' --critical-requests='10' --verbose -See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cf-metricscollected.html' for more informations. +See 'https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/monitoring-using-cloudwatch.html' +for more informations. Default statistic: 'sum' / Valid statistic: 'sum'. @@ -203,15 +238,17 @@ Default statistic: 'sum' / Valid statistic: 'sum'. Set the instance id (Required) (Can be multiple). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-requests> -Thresholds warning ($metric$ can be: 'requests', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning. -=item B<--critical-$metric$-$statistic$> +=item B<--critical-requests> -Thresholds critical ($metric$ can be: 'requests', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds critical. + +=item B<--per-sec> + +Change the data to be unit/sec. =back diff --git a/centreon-plugins/cloud/aws/cloudfront/mode/throughput.pm b/centreon-plugins/cloud/aws/cloudfront/mode/throughput.pm index 1f4725127..617695d22 100644 --- a/centreon-plugins/cloud/aws/cloudfront/mode/throughput.pm +++ b/centreon-plugins/cloud/aws/cloudfront/mode/throughput.pm @@ -25,45 +25,79 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my %metrics_mapping = ( + 'BytesDownloaded' => { + 'output' => 'Bytes Downloaded', + 'label' => 'bytes-downloaded', + 'nlabel' => { + 'absolute' => 'cloudfront.bytes.downloaded.bytes', + 'per_second' => 'cloudfront.bytes.downloaded.persecond', + }, + }, + 'BytesUploaded' => { + 'output' => 'Bytes Uploaded', + 'label' => 'bytes-uploaded', + 'nlabel' => { + 'absolute' => 'cloudfront.bytes.uploaded.bytes', + 'per_second' => 'cloudfront.bytes.uploaded.persecond', + }, + }, +); + sub prefix_metric_output { my ($self, %options) = @_; - return "Instance '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; + return "Instance '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking Instance '" . $options{instance_value}->{display} . "' "; } sub custom_metric_calc { my ($self, %options) = @_; $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; - $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric} . '_' . $options{extra_options}->{stat}}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}}; $self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe}; - $self->{result_values}->{stat} = $options{extra_options}->{stat}; $self->{result_values}->{metric} = $options{extra_options}->{metric}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; } sub custom_metric_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, - threshold => [ { label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'critical' }, - { label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check( + value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, + threshold => [ { label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ]); return $exit; } sub custom_metric_perfdata { my ($self, %options) = @_; - my $extra_label = ''; - $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add(label => lc($self->{result_values}->{metric}) . "_" . lc($self->{result_values}->{stat}) . $extra_label, - unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B', - value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - ); + $self->{output}->perfdata_add( + instances => $self->{instance}, + label => $metrics_mapping{$self->{result_values}->{metric}}->{label}, + nlabel => defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{per_second} : + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{absolute}, + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B', + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $self->{result_values}->{value_per_sec} : + $self->{result_values}->{value}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + ); } sub custom_metric_output { @@ -72,10 +106,10 @@ sub custom_metric_output { if (defined($self->{instance_mode}->{option_results}->{per_sec})) { my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}); - $msg = $self->{result_values}->{metric} . ": " . $value . $unit . "/s"; + $msg = $metrics_mapping{$self->{result_values}->{metric}}->{output} . ": " . $value . $unit . "/s"; } else { my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}); - $msg = $self->{result_values}->{metric} . ": " . $value . $unit; + $msg = $metrics_mapping{$self->{result_values}->{metric}}->{output} . ": " . $value . $unit; } return $msg; } @@ -84,31 +118,36 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All throughput metrics are ok", skipped_code => { -10 => 1 } }, + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All instances metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - foreach my $statistic ('minimum', 'maximum', 'average', 'sum') { - foreach my $metric ('BytesDownloaded', 'BytesUploaded') { - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' }, { name => 'timeframe' } ], - closure_custom_calc => $self->can('custom_metric_calc'), - closure_custom_calc_extra_options => { metric => $metric, stat => $statistic }, - closure_custom_output => $self->can('custom_metric_output'), - closure_custom_perfdata => $self->can('custom_metric_perfdata'), - closure_custom_threshold_check => $self->can('custom_metric_threshold'), - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + set => { + key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_metric_calc'), + closure_custom_calc_extra_options => { metric => $metric }, + closure_custom_output => $self->can('custom_metric_output'), + closure_custom_perfdata => $self->can('custom_metric_perfdata'), + closure_custom_threshold_check => $self->can('custom_metric_threshold'), + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; } } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "id:s@" => { name => 'id' }, "filter-metric:s" => { name => 'filter_metric' }, @@ -146,7 +185,7 @@ sub check_options { } } - foreach my $metric ('BytesDownloaded', 'BytesUploaded') { + foreach my $metric (keys %metrics_mapping) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); @@ -171,17 +210,20 @@ sub manage_selection { foreach my $metric (@{$self->{aws_metrics}}) { foreach my $statistic (@{$self->{aws_statistics}}) { - next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && + !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance; - $self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic); - $self->{metric}->{$instance . "_" . lc($statistic)}->{timeframe} = $self->{aws_timeframe}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{timeframe} = $self->{aws_timeframe}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } - if (scalar(keys %{$self->{metric}}) <= 0) { + if (scalar(keys %{$self->{metrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); $self->{output}->option_exit(); } @@ -197,9 +239,10 @@ Check CloudFront instances throughput. Example: perl centreon_plugins.pl --plugin=cloud::aws::cloudfront::plugin --custommode=paws --mode=throughput --region='eu-west-1' ---id='E8T734E1AF1L4' --statistic='sum' --critical-bytesdownloaded-sum='10' --verbose +--id='E8T734E1AF1L4' --statistic='sum' --critical-bytes-downloaded='10' --verbose -See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cf-metricscollected.html' for more informations. +See 'https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/monitoring-using-cloudwatch.html' +for more informations. Default statistic: 'sum' / Valid statistic: 'sum'. @@ -214,15 +257,17 @@ Set the instance id (Required) (Can be multiple). Filter metrics (Can be: 'BytesDownloaded', 'BytesUploaded') (Can be a regexp). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-*> -Thresholds warning ($metric$ can be: 'bytesdownloaded', 'bytesuploaded', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning (Can be: 'bytes-downloaded', 'bytes-uploaded'). -=item B<--critical-$metric$-$statistic$> +=item B<--critical-*> -Thresholds critical ($metric$ can be: 'bytesdownloaded', 'bytesuploaded', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds critical (Can be: 'bytes-downloaded', 'bytes-uploaded') + +=item B<--per-sec> + +Change the data to be unit/sec. =back diff --git a/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm b/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm index 1a37729ab..8c696cc49 100644 --- a/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm +++ b/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "service:s@" => { name => 'service' }, "prettify" => { name => 'prettify' }, diff --git a/centreon-plugins/cloud/aws/cloudwatch/mode/getalarms.pm b/centreon-plugins/cloud/aws/cloudwatch/mode/getalarms.pm index d00bed52c..548960439 100644 --- a/centreon-plugins/cloud/aws/cloudwatch/mode/getalarms.pm +++ b/centreon-plugins/cloud/aws/cloudwatch/mode/getalarms.pm @@ -75,7 +75,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-alarm-name:s" => { name => 'filter_alarm_name' }, diff --git a/centreon-plugins/cloud/aws/cloudwatch/mode/getmetrics.pm b/centreon-plugins/cloud/aws/cloudwatch/mode/getmetrics.pm index 95a2cdc7f..62b144aec 100644 --- a/centreon-plugins/cloud/aws/cloudwatch/mode/getmetrics.pm +++ b/centreon-plugins/cloud/aws/cloudwatch/mode/getmetrics.pm @@ -87,7 +87,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "namespace:s" => { name => 'namespace' }, diff --git a/centreon-plugins/cloud/aws/cloudwatch/mode/listmetrics.pm b/centreon-plugins/cloud/aws/cloudwatch/mode/listmetrics.pm index 1a0e7ed1e..d499d46d1 100644 --- a/centreon-plugins/cloud/aws/cloudwatch/mode/listmetrics.pm +++ b/centreon-plugins/cloud/aws/cloudwatch/mode/listmetrics.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "namespace:s" => { name => 'namespace' }, diff --git a/centreon-plugins/cloud/aws/custom/awscli.pm b/centreon-plugins/cloud/aws/custom/awscli.pm index c86e59b4f..231628e41 100644 --- a/centreon-plugins/cloud/aws/custom/awscli.pm +++ b/centreon-plugins/cloud/aws/custom/awscli.pm @@ -348,6 +348,7 @@ sub ec2_list_resources { InstanceType => $instance->{InstanceType}, State => $instance->{State}->{Name}, Tags => join(",", @instance_tags), + KeyName => $instance->{KeyName}, }; } diff --git a/centreon-plugins/cloud/aws/ec2/mode/asgstatus.pm b/centreon-plugins/cloud/aws/ec2/mode/asgstatus.pm index 6a2b29e13..606fca438 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/asgstatus.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/asgstatus.pm @@ -112,7 +112,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "region:s" => { name => 'region' }, diff --git a/centreon-plugins/cloud/aws/ec2/mode/cpu.pm b/centreon-plugins/cloud/aws/ec2/mode/cpu.pm index 7d5acb459..bbf8887be 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/cpu.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/cpu.pm @@ -76,13 +76,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "type:s" => { name => 'type' }, - "name:s@" => { name => 'name' }, - "filter-metric:s" => { name => 'filter_metric' }, - }); + $options{options}->add_options(arguments => { + "type:s" => { name => 'type' }, + "name:s@" => { name => 'name' }, + "filter-metric:s" => { name => 'filter_metric' }, + }); return $self; } diff --git a/centreon-plugins/cloud/aws/ec2/mode/diskio.pm b/centreon-plugins/cloud/aws/ec2/mode/diskio.pm index d4f9cc715..96f49622c 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/diskio.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/diskio.pm @@ -153,7 +153,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "type:s" => { name => 'type' }, "name:s@" => { name => 'name' }, diff --git a/centreon-plugins/cloud/aws/ec2/mode/instancesstatus.pm b/centreon-plugins/cloud/aws/ec2/mode/instancesstatus.pm index e25d4bb7d..53452cef7 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/instancesstatus.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/instancesstatus.pm @@ -118,7 +118,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "region:s" => { name => 'region' }, diff --git a/centreon-plugins/cloud/aws/ec2/mode/instancestypes.pm b/centreon-plugins/cloud/aws/ec2/mode/instancestypes.pm index 8850ac46e..f2cc2242a 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/instancestypes.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/instancestypes.pm @@ -100,7 +100,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "region:s" => { name => 'region' }, diff --git a/centreon-plugins/cloud/aws/ec2/mode/listasg.pm b/centreon-plugins/cloud/aws/ec2/mode/listasg.pm index 23e76b5a5..42a63d4d2 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/listasg.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/listasg.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/cloud/aws/ec2/mode/listinstances.pm b/centreon-plugins/cloud/aws/ec2/mode/listinstances.pm index 83b211ae5..c7fe49d95 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/listinstances.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/listinstances.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); @@ -54,8 +53,8 @@ sub run { $self->manage_selection(%options); foreach (@{$self->{instances}}) { next if ($_->{Type} !~ m/instance/); - $self->{output}->output_add(long_msg => sprintf("[Id = %s][AvailabilityZone = %s][InstanceType = %s][State = %s][Tags = %s]", - $_->{Name}, $_->{AvailabilityZone}, $_->{InstanceType}, $_->{State}, $_->{Tags})); + $self->{output}->output_add(long_msg => sprintf("[Id = %s][AvailabilityZone = %s][InstanceType = %s][State = %s][Tags = %s][KeyName = %s]", + $_->{Name}, $_->{AvailabilityZone}, $_->{InstanceType}, $_->{State}, $_->{Tags}, $_->{KeyName})); } $self->{output}->output_add(severity => 'OK', @@ -67,7 +66,7 @@ sub run { sub disco_format { my ($self, %options) = @_; - $self->{output}->add_disco_format(elements => ['id', 'availabilityzone', 'instancetype', 'state', 'tags']); + $self->{output}->add_disco_format(elements => ['id', 'availabilityzone', 'instancetype', 'state', 'tags', 'keyname']); } sub disco_show { @@ -82,6 +81,7 @@ sub disco_show { instancetype => $_->{InstanceType}, state => $_->{State}, tags => $_->{Tags}, + keyname => $_->{KeyName}, ); } } diff --git a/centreon-plugins/cloud/aws/ec2/mode/network.pm b/centreon-plugins/cloud/aws/ec2/mode/network.pm index 137be8a6f..f346d8627 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/network.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/network.pm @@ -153,7 +153,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "type:s" => { name => 'type' }, "name:s@" => { name => 'name' }, diff --git a/centreon-plugins/cloud/aws/ec2/mode/status.pm b/centreon-plugins/cloud/aws/ec2/mode/status.pm index 519799225..a8d663da4 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/status.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/status.pm @@ -106,7 +106,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "type:s" => { name => 'type' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/commandsmemcached.pm b/centreon-plugins/cloud/aws/elasticache/mode/commandsmemcached.pm index ed2874035..19370f7c8 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/commandsmemcached.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/commandsmemcached.pm @@ -111,7 +111,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, "node-id:s" => { name => 'node_id' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/commandsredis.pm b/centreon-plugins/cloud/aws/elasticache/mode/commandsredis.pm index db911534d..9d6e35eb5 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/commandsredis.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/commandsredis.pm @@ -112,7 +112,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, "node-id:s" => { name => 'node_id' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/connections.pm b/centreon-plugins/cloud/aws/elasticache/mode/connections.pm index cd5e25952..2aeedfbe7 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/connections.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/connections.pm @@ -123,7 +123,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, "node-id:s" => { name => 'node_id' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/cpu.pm b/centreon-plugins/cloud/aws/elasticache/mode/cpu.pm index ca87bb0fb..d8454cef8 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/cpu.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/cpu.pm @@ -64,7 +64,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "region:s" => { name => 'region' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/evictions.pm b/centreon-plugins/cloud/aws/elasticache/mode/evictions.pm index 5ad1059a2..1de1af613 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/evictions.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/evictions.pm @@ -111,7 +111,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, "node-id:s" => { name => 'node_id' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/items.pm b/centreon-plugins/cloud/aws/elasticache/mode/items.pm index f0b462826..27b5182b4 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/items.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/items.pm @@ -123,7 +123,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, "node-id:s" => { name => 'node_id' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/network.pm b/centreon-plugins/cloud/aws/elasticache/mode/network.pm index dfd419388..1c4405754 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/network.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/network.pm @@ -113,7 +113,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, "node-id:s" => { name => 'node_id' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/replication.pm b/centreon-plugins/cloud/aws/elasticache/mode/replication.pm index 6044271f1..a714703e4 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/replication.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/replication.pm @@ -125,7 +125,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, "node-id:s" => { name => 'node_id' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/requestsmemcached.pm b/centreon-plugins/cloud/aws/elasticache/mode/requestsmemcached.pm index 69c3f70dc..c892530e6 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/requestsmemcached.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/requestsmemcached.pm @@ -112,7 +112,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, "node-id:s" => { name => 'node_id' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/requestsredis.pm b/centreon-plugins/cloud/aws/elasticache/mode/requestsredis.pm index 8cc576b86..4c2353fe5 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/requestsredis.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/requestsredis.pm @@ -111,7 +111,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, "node-id:s" => { name => 'node_id' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/usagememcached.pm b/centreon-plugins/cloud/aws/elasticache/mode/usagememcached.pm index e703df574..44115b4e4 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/usagememcached.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/usagememcached.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, diff --git a/centreon-plugins/cloud/aws/elasticache/mode/usageredis.pm b/centreon-plugins/cloud/aws/elasticache/mode/usageredis.pm index 83fe22ab3..934135382 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/usageredis.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/usageredis.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, diff --git a/centreon-plugins/cloud/aws/elb/mode/httpcodes.pm b/centreon-plugins/cloud/aws/elb/mode/httpcodes.pm index 1f70efa96..7e6c91a46 100644 --- a/centreon-plugins/cloud/aws/elb/mode/httpcodes.pm +++ b/centreon-plugins/cloud/aws/elb/mode/httpcodes.pm @@ -25,6 +25,44 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my %metrics_mapping = ( + 'HTTPCode_Backend_2XX' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'HTTP 2XXs', + 'label' => 'httpcode-backend-2xx', + 'nlabel' => 'elb.httpcode.backend.2xx.count', + }, + 'HTTPCode_Backend_3XX' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'HTTP 3XXs', + 'label' => 'httpcode-backend-3xx', + 'nlabel' => 'elb.httpcode.backend.3xx.count', + }, + 'HTTPCode_Backend_4XX' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'HTTP 4XXs', + 'label' => 'httpcode-backend-4xx', + 'nlabel' => 'elb.httpcode.backend.4xx.count', + }, + 'HTTPCode_Backend_5XX' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'HTTP 5XXs', + 'label' => 'httpcode-backend-5xx', + 'nlabel' => 'elb.httpcode.backend.5xx.count', + }, + 'HTTPCode_ELB_4XX' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'ELB HTTP 4XXs', + 'label' => 'httpcode-elb-4xx', + 'nlabel' => 'elb.httpcode.elb.4xx.count', + }, + 'HTTPCode_ELB_5XX' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'ELB HTTP 5XXs', + 'label' => 'httpcode-elb-5xx', + 'nlabel' => 'elb.httpcode.elb.5xx.count', + }, + 'BackendConnectionErrors' => { + 'output' => 'Backend Connection Errors', + 'label' => 'backendconnectionerrors', + 'nlabel' => 'elb.backendconnectionerrors.count', + }, +); + my %map_type = ( "loadbalancer" => "LoadBalancerName", "availabilityzone" => "AvailabilityZone", @@ -38,58 +76,66 @@ sub prefix_metric_output { $availability_zone = "[$options{instance_value}->{availability_zone}] "; } - return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone . $options{instance_value}->{stat} . " "; + return ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking " . ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All http codes metrics are ok", skipped_code => { -10 => 1 } }, + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - foreach my $statistic ('minimum', 'maximum', 'average', 'sum') { - foreach my $metric ('HTTPCode_Backend_2XX', 'HTTPCode_Backend_3XX', 'HTTPCode_Backend_4XX', 'HTTPCode_Backend_5XX', 'HTTPCode_ELB_4XX', 'HTTPCode_ELB_5XX') { - next if ($statistic =~ /minimum|maximum|average/); # Minimum, Maximum, and Average all return 1. - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'type' }, { name => 'stat' } ], - output_template => $metric . ': %d', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%d', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - foreach my $metric ('BackendConnectionErrors') { - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'type' }, { name => 'stat' } ], - output_template => $metric . ': %d', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%d', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; } } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "type:s" => { name => 'type' }, - "name:s@" => { name => 'name' }, - "availability-zone:s" => { name => 'availability_zone' }, - "filter-metric:s" => { name => 'filter_metric' }, - }); + $options{options}->add_options(arguments => { + "type:s" => { name => 'type' }, + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + }); return $self; } @@ -137,8 +183,7 @@ sub check_options { } } - foreach my $metric ('HTTPCode_Backend_2XX', 'HTTPCode_Backend_3XX', 'HTTPCode_Backend_4XX', 'HTTPCode_Backend_5XX', - 'HTTPCode_ELB_4XX', 'HTTPCode_ELB_5XX', 'BackendConnectionErrors') { + foreach my $metric (keys %metrics_mapping) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); @@ -169,16 +214,15 @@ sub manage_selection { foreach my $statistic (@{$self->{aws_statistics}}) { next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance; - $self->{metric}->{$instance . "_" . lc($statistic)}->{type} = $self->{option_results}->{type}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic); - $self->{metric}->{$instance . "_" . lc($statistic)}->{availability_zone} = $self->{option_results}->{availability_zone}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } - - if (scalar(keys %{$self->{metric}}) <= 0) { + + if (scalar(keys %{$self->{metrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); $self->{output}->option_exit(); } @@ -194,9 +238,9 @@ Check ELB http codes. Example: perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=http-codes --region='eu-west-1' ---type='loadbalancer' --name='elb-www-fr' --critical-httpcode-backend-4xx-sum='10' --verbose +--type='loadbalancer' --name='elb-www-fr' --critical-httpcode-backend-4xx='10' --verbose -See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/elb-metricscollected.html' for more informations. +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. Default statistic: 'sum' / Most usefull statistics: 'sum'. @@ -220,19 +264,17 @@ Filter metrics (Can be: 'HTTPCode_Backend_2XX', 'HTTPCode_Backend_3XX', 'HTTPCod 'HTTPCode_Backend_5XX', 'HTTPCode_ELB_4XX', 'HTTPCode_ELB_5XX', 'BackendConnectionErrors') (Can be a regexp). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-*> -Thresholds warning ($metric$ can be: 'httpcode_backend_2xx', 'httpcode_backend_3xx', -'httpcode_backend_4xx', 'httpcode_backend_5xx', 'httpcode_elb_4xx', -'httpcode_elb_5xx', 'backendconnectionerrors', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning (Can be: 'httpcode-backend-2xx', 'httpcode-backend-3xx', +'httpcode-backend-4xx', 'httpcode-backend-5xx', 'httpcode-elb-4xx', +'httpcode-elb-5xx', 'backendconnectionerrors') -=item B<--critical-$metric$-$statistic$> +=item B<--critical-*> -Thresholds critical ($metric$ can be: 'httpcode_backend_2xx', 'httpcode_backend_3xx', -'httpcode_backend_4xx', 'httpcode_backend_5xx', 'httpcode_elb_4xx', -'httpcode_elb_5xx', 'backendconnectionerrors', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds critical (Can be: 'httpcode-backend-2xx', 'httpcode-backend-3xx', +'httpcode-backend-4xx', 'httpcode-backend-5xx', 'httpcode-elb-4xx', +'httpcode-elb-5xx', 'backendconnectionerrors') =back diff --git a/centreon-plugins/cloud/aws/elb/mode/performances.pm b/centreon-plugins/cloud/aws/elb/mode/performances.pm index 4b2c18e34..1ba00b2b6 100644 --- a/centreon-plugins/cloud/aws/elb/mode/performances.pm +++ b/centreon-plugins/cloud/aws/elb/mode/performances.pm @@ -25,6 +25,19 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my %metrics_mapping = ( + 'RequestCount' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Requests', + 'label' => 'requestcount', + 'nlabel' => 'elb.requestcount.count', + }, + 'Latency' => { # Minimum is typically not useful + 'output' => 'Latency', + 'label' => 'latency', + 'nlabel' => 'elb.latency.seconds', + }, +); + my %map_type = ( "loadbalancer" => "LoadBalancerName", "availabilityzone" => "AvailabilityZone", @@ -38,60 +51,67 @@ sub prefix_metric_output { $availability_zone = "[$options{instance_value}->{availability_zone}] "; } - return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone . $options{instance_value}->{stat} . " "; + return ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking " . ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All performances metrics are ok", skipped_code => { -10 => 1 } }, + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - foreach my $statistic ('minimum', 'maximum', 'average', 'sum') { - foreach my $metric ('RequestCount') { - next if ($statistic =~ /minimum|maximum|average/); # Minimum, Maximum, and Average all return 1. - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'type' }, { name => 'stat' } ], - output_template => $metric . ': %d requests', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%d', unit => 'requests', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - foreach my $metric ('Latency') { - next if ($statistic =~ /minimum|sum/); # Minimum is typically not useful - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'type' }, { name => 'stat' } ], - output_template => $metric . ': %.2f sec', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%.2f', unit => 's', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; } } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "type:s" => { name => 'type' }, - "name:s@" => { name => 'name' }, - "availability-zone:s" => { name => 'availability_zone' }, - "filter-metric:s" => { name => 'filter_metric' }, - "statistic:s@" => { name => 'statistic' }, - }); + $options{options}->add_options(arguments => { + "type:s" => { name => 'type' }, + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + "statistic:s@" => { name => 'statistic' }, + }); return $self; } @@ -138,7 +158,7 @@ sub check_options { } } - foreach my $metric ('RequestCount', 'Latency') { + foreach my $metric (keys %metrics_mapping) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); @@ -169,16 +189,15 @@ sub manage_selection { foreach my $statistic (@{$self->{aws_statistics}}) { next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance; - $self->{metric}->{$instance . "_" . lc($statistic)}->{type} = $self->{option_results}->{type}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic); - $self->{metric}->{$instance . "_" . lc($statistic)}->{availability_zone} = $self->{option_results}->{availability_zone}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } - if (scalar(keys %{$self->{metric}}) <= 0) { + if (scalar(keys %{$self->{metrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); $self->{output}->option_exit(); } @@ -194,9 +213,9 @@ Check ELB performances. Example: perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=performances --region='eu-west-1' ---type='loadbalancer' --name='elb-www-fr' --critical-requestcount-sum='10' --verbose +--type='loadbalancer' --name='elb-www-fr' --critical-requestcount='10' --verbose -See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/elb-metricscollected.html' for more informations. +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. Default statistic: 'sum', 'average' / Most usefull statistics: RequestCount: 'sum', Latency: 'average'. @@ -219,15 +238,13 @@ Add Availability Zone dimension (only with --type='loadbalancer'). Filter metrics (Can be: 'RequestCount', 'Latency') (Can be a regexp). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-*> -Thresholds warning ($metric$ can be: 'requestcount', 'latency', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning (Can be: 'requestcount', 'latency'). -=item B<--critical-$metric$-$statistic$> +=item B<--critical-*> -Thresholds critical ($metric$ can be: 'requestcount', 'latency', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds critical (Can be: 'requestcount', 'latency'). =back diff --git a/centreon-plugins/cloud/aws/elb/mode/queues.pm b/centreon-plugins/cloud/aws/elb/mode/queues.pm index 0a4e0db36..a2c94ba65 100644 --- a/centreon-plugins/cloud/aws/elb/mode/queues.pm +++ b/centreon-plugins/cloud/aws/elb/mode/queues.pm @@ -25,6 +25,19 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my %metrics_mapping = ( + 'SpilloverCount' => { # Average, Minimum, and Maximum are reported per load balancer node and are not typically useful. + 'output' => 'Spillover Count', + 'label' => 'spillovercount', + 'nlabel' => 'elb.spillovercount.count', + }, + 'SurgeQueueLength' => { # Sum is not useful. + 'output' => 'Surge Queue Length', + 'label' => 'surgequeuelength', + 'nlabel' => 'elb.surgequeuelength.count', + }, +); + my %map_type = ( "loadbalancer" => "LoadBalancerName", "availabilityzone" => "AvailabilityZone", @@ -38,60 +51,67 @@ sub prefix_metric_output { $availability_zone = "[$options{instance_value}->{availability_zone}] "; } - return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone . $options{instance_value}->{stat} . " "; + return ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking " . ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All queues metrics are ok", skipped_code => { -10 => 1 } }, + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - foreach my $statistic ('minimum', 'maximum', 'average', 'sum') { - foreach my $metric ('SpilloverCount') { - next if ($statistic =~ /minimum|maximum|average/); # Average, Minimum, and Maximum are reported per load balancer node and are not typically useful. - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'type' }, { name => 'stat' } ], - output_template => $metric . ': %d', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%d', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - foreach my $metric ('SurgeQueueLength') { - next if ($statistic =~ /sum/); # Sum is not useful. - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'type' }, { name => 'stat' } ], - output_template => $metric . ': %d', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%d', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; } } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "type:s" => { name => 'type' }, - "name:s@" => { name => 'name' }, - "availability-zone:s" => { name => 'availability_zone' }, - "filter-metric:s" => { name => 'filter_metric' }, - "statistic:s@" => { name => 'statistic' }, - }); + $options{options}->add_options(arguments => { + "type:s" => { name => 'type' }, + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + "statistic:s@" => { name => 'statistic' }, + }); return $self; } @@ -139,7 +159,7 @@ sub check_options { } } - foreach my $metric ('SpilloverCount', 'SurgeQueueLength') { + foreach my $metric (keys %metrics_mapping) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); @@ -170,16 +190,15 @@ sub manage_selection { foreach my $statistic (@{$self->{aws_statistics}}) { next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance; - $self->{metric}->{$instance . "_" . lc($statistic)}->{type} = $self->{option_results}->{type}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic); - $self->{metric}->{$instance . "_" . lc($statistic)}->{availability_zone} = $self->{option_results}->{availability_zone}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } - if (scalar(keys %{$self->{metric}}) <= 0) { + if (scalar(keys %{$self->{metrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); $self->{output}->option_exit(); } @@ -197,7 +216,7 @@ Example: perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=queues --region='eu-west-1' --type='loadbalancer' --name='elb-www-fr' --critical-spillovercount-sum='10' --verbose -See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/elb-metricscollected.html' for more informations. +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. Default statistic: 'sum', 'maximum' / Most usefull statistics: SpilloverCount: 'sum', SurgeQueueLength: 'maximum'. diff --git a/centreon-plugins/cloud/aws/elb/mode/targetshealth.pm b/centreon-plugins/cloud/aws/elb/mode/targetshealth.pm index e6297c55e..517e174a7 100644 --- a/centreon-plugins/cloud/aws/elb/mode/targetshealth.pm +++ b/centreon-plugins/cloud/aws/elb/mode/targetshealth.pm @@ -25,6 +25,19 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my %metrics_mapping = ( + 'HealthyHostCount' => { + 'output' => 'Healthy Hosts', + 'label' => 'healthyhostcount', + 'nlabel' => 'elb.healthyhostcount.count', + }, + 'UnHealthyHostCount' => { + 'output' => 'Unhealthy Hosts', + 'label' => 'unhealthyhostcount', + 'nlabel' => 'elb.unhealthyhostcount.count', + }, +); + my %map_type = ( "loadbalancer" => "LoadBalancerName", "availabilityzone" => "AvailabilityZone", @@ -38,46 +51,67 @@ sub prefix_metric_output { $availability_zone = "[$options{instance_value}->{availability_zone}] "; } - return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone . $options{instance_value}->{stat} . " "; + return ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking " . ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' " . $availability_zone; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All health metrics are ok", skipped_code => { -10 => 1 } }, + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - foreach my $statistic ('minimum', 'maximum', 'average', 'sum') { - foreach my $metric ('HealthyHostCount', 'UnHealthyHostCount') { - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'type' }, { name => 'stat' } ], - output_template => $metric . ': %d', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%d', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; } } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "type:s" => { name => 'type' }, - "name:s@" => { name => 'name' }, - "availability-zone:s" => { name => 'availability_zone' }, - "filter-metric:s" => { name => 'filter_metric' }, - "statistic:s@" => { name => 'statistic' }, - }); + $options{options}->add_options(arguments => { + "type:s" => { name => 'type' }, + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + "statistic:s@" => { name => 'statistic' }, + }); return $self; } @@ -125,7 +159,7 @@ sub check_options { } } - foreach my $metric ('HealthyHostCount', 'UnHealthyHostCount') { + foreach my $metric (keys %metrics_mapping) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); @@ -156,16 +190,15 @@ sub manage_selection { foreach my $statistic (@{$self->{aws_statistics}}) { next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance; - $self->{metric}->{$instance . "_" . lc($statistic)}->{type} = $self->{option_results}->{type}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic); - $self->{metric}->{$instance . "_" . lc($statistic)}->{availability_zone} = $self->{option_results}->{availability_zone}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } - if (scalar(keys %{$self->{metric}}) <= 0) { + if (scalar(keys %{$self->{metrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); $self->{output}->option_exit(); } @@ -181,9 +214,9 @@ Check ELB instances health. Example: perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=instancehealth --region='eu-west-1' ---type='loadbalancer' --name='elb-www-fr' --critical-healthyhostcount-average='10' --verbose +--type='loadbalancer' --name='elb-www-fr' --critical-healthyhostcount='10' --verbose -See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/elb-metricscollected.html' for more informations. +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. Default statistic: 'average' / Most usefull statistics: 'average', 'minimum', 'maximum'. @@ -206,15 +239,13 @@ Add Availability Zone dimension (only with --type='loadbalancer'). Filter metrics (Can be: 'HealthyHostCount', 'UnHealthyHostCount') (Can be a regexp). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-*> -Thresholds warning ($metric$ can be: 'healthyhostcount', 'unhealthyhostcount', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning (Can be: 'healthyhostcount', 'unhealthyhostcount'). -=item B<--critical-$metric$-$statistic$> +=item B<--critical-*> -Thresholds critical ($metric$ can be: 'healthyhostcount', 'unhealthyhostcount', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds critical (Can be: 'healthyhostcount', 'unhealthyhostcount'). =back diff --git a/centreon-plugins/cloud/aws/lambda/mode/invocations.pm b/centreon-plugins/cloud/aws/lambda/mode/invocations.pm index 27e650215..cb7c71fe6 100644 --- a/centreon-plugins/cloud/aws/lambda/mode/invocations.pm +++ b/centreon-plugins/cloud/aws/lambda/mode/invocations.pm @@ -25,60 +25,95 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my %metrics_mapping = ( + 'Duration' => { + 'output' => 'Duration', + 'label' => 'duration', + 'nlabel' => 'lambda.function.duration.milliseconds', + }, + 'Invocations' => { + 'output' => 'Invocations', + 'label' => 'invocations', + 'nlabel' => 'lambda.function.invocations.count', + }, + 'Errors' => { + 'output' => 'Errors', + 'label' => 'errors', + 'nlabel' => 'lambda.function.errors.count', + }, + 'DeadLetterErrors' => { + 'output' => 'Dead Letter Errors', + 'label' => 'deadlettererrors', + 'nlabel' => 'lambda.function.deadlettererrors.count', + }, + 'Throttles' => { + 'output' => 'Throttles', + 'label' => 'throttles', + 'nlabel' => 'lambda.function.throttles.count', + }, + 'IteratorAge' => { + 'output' => 'Iterator Age', + 'label' => 'iteratorage', + 'nlabel' => 'lambda.function.iteratorage.milliseconds', + } +); + sub prefix_metric_output { my ($self, %options) = @_; - return "Function '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; + return "Function '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking Function '" . $options{instance_value}->{display} . "' "; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All invocations metrics are ok", skipped_code => { -10 => 1 } }, + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All functions metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - foreach my $statistic ('minimum', 'maximum', 'average', 'sum') { - foreach my $metric ('Invocations', 'Errors', 'Dead Letter Error', 'Throttles') { - next if ($statistic =~ /minimum|maximum|average/); - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' } ], - output_template => $metric . ': %.2f', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%.2f', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - foreach my $metric ('Duration') { - next if ($statistic =~ /sum/); - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' } ], - output_template => $metric . ': %.2f ms', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%.2f', unit => 'ms', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; } } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "name:s@" => { name => 'name' }, - "filter-metric:s" => { name => 'filter_metric' }, - }); + $options{options}->add_options(arguments => { + "name:s@" => { name => 'name' }, + "filter-metric:s" => { name => 'filter_metric' }, + }); return $self; } @@ -111,7 +146,7 @@ sub check_options { } } - foreach my $metric ('Invocations', 'Errors', 'Throttles', 'Duration') { + foreach my $metric (keys %metrics_mapping) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); @@ -138,14 +173,14 @@ sub manage_selection { foreach my $statistic (@{$self->{aws_statistics}}) { next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance; - $self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic); - $self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } - if (scalar(keys %{$self->{metric}}) <= 0) { + if (scalar(keys %{$self->{metrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); $self->{output}->option_exit(); } @@ -161,9 +196,9 @@ Check Lambda invocations metrics. Example: perl centreon_plugins.pl --plugin=cloud::aws::lambda::plugin --custommode=paws --mode=invocations --region='eu-west-1' ---name='myFunction' --filter-metric='Duration' --statistic='average' --critical-duration-average='10' --verbose +--name='myFunction' --filter-metric='Duration' --statistic='average' --critical-duration='10' --verbose -See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/lam-metricscollected.html' for more informations. +See 'https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions-metrics.html' for more informations. Default statistic: 'sum', 'average'. @@ -175,18 +210,19 @@ Set the function name (Required) (Can be multiple). =item B<--filter-metric> -Filter metrics (Can be: 'Invocations', 'Errors', 'Throttles', 'Duration') +Filter metrics (Can be: 'Duration', 'Invocations', 'Errors', +'DeadLetterErrors', 'Throttles', 'IteratorAge') (Can be a regexp). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-*> -Thresholds warning ($metric$ can be: 'invocations', 'errors', 'throttles', 'duration', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning (Can be: 'invocations', 'errors', +'throttles', 'duration', 'deadlettererrors', 'iteratorage'). -=item B<--critical-$metric$-$statistic$> +=item B<--critical-*> -Thresholds critical ($metric$ can be: 'invocations', 'errors', 'throttles', 'duration', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds critical (Can be: 'invocations', 'errors', +'throttles', 'duration', 'deadlettererrors', 'iteratorage'). =back diff --git a/centreon-plugins/cloud/aws/rds/mode/connections.pm b/centreon-plugins/cloud/aws/rds/mode/connections.pm index 0a4daa2cc..4957b4fe5 100644 --- a/centreon-plugins/cloud/aws/rds/mode/connections.pm +++ b/centreon-plugins/cloud/aws/rds/mode/connections.pm @@ -64,7 +64,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "type:s" => { name => 'type' }, diff --git a/centreon-plugins/cloud/aws/rds/mode/cpu.pm b/centreon-plugins/cloud/aws/rds/mode/cpu.pm index e44656214..2622fa7ac 100644 --- a/centreon-plugins/cloud/aws/rds/mode/cpu.pm +++ b/centreon-plugins/cloud/aws/rds/mode/cpu.pm @@ -76,7 +76,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "type:s" => { name => 'type' }, diff --git a/centreon-plugins/cloud/aws/rds/mode/diskio.pm b/centreon-plugins/cloud/aws/rds/mode/diskio.pm index 913009450..af5eb5915 100644 --- a/centreon-plugins/cloud/aws/rds/mode/diskio.pm +++ b/centreon-plugins/cloud/aws/rds/mode/diskio.pm @@ -101,7 +101,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "type:s" => { name => 'type' }, diff --git a/centreon-plugins/cloud/aws/rds/mode/instancestatus.pm b/centreon-plugins/cloud/aws/rds/mode/instancestatus.pm index b11c63dc7..6b429f0a0 100644 --- a/centreon-plugins/cloud/aws/rds/mode/instancestatus.pm +++ b/centreon-plugins/cloud/aws/rds/mode/instancestatus.pm @@ -118,7 +118,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-instanceid:s" => { name => 'filter_instanceid' }, diff --git a/centreon-plugins/cloud/aws/rds/mode/listclusters.pm b/centreon-plugins/cloud/aws/rds/mode/listclusters.pm index 634be2f58..345eaf8db 100644 --- a/centreon-plugins/cloud/aws/rds/mode/listclusters.pm +++ b/centreon-plugins/cloud/aws/rds/mode/listclusters.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/cloud/aws/rds/mode/listinstances.pm b/centreon-plugins/cloud/aws/rds/mode/listinstances.pm index 94a297634..62a8e1223 100644 --- a/centreon-plugins/cloud/aws/rds/mode/listinstances.pm +++ b/centreon-plugins/cloud/aws/rds/mode/listinstances.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/cloud/aws/rds/mode/network.pm b/centreon-plugins/cloud/aws/rds/mode/network.pm index c08d8d603..b56e2544c 100644 --- a/centreon-plugins/cloud/aws/rds/mode/network.pm +++ b/centreon-plugins/cloud/aws/rds/mode/network.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "type:s" => { name => 'type' }, diff --git a/centreon-plugins/cloud/aws/rds/mode/queries.pm b/centreon-plugins/cloud/aws/rds/mode/queries.pm index ceb61f590..493b0e7a7 100644 --- a/centreon-plugins/cloud/aws/rds/mode/queries.pm +++ b/centreon-plugins/cloud/aws/rds/mode/queries.pm @@ -76,7 +76,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "type:s" => { name => 'type' }, diff --git a/centreon-plugins/cloud/aws/rds/mode/transactions.pm b/centreon-plugins/cloud/aws/rds/mode/transactions.pm index b7472bd54..8517dcdd1 100644 --- a/centreon-plugins/cloud/aws/rds/mode/transactions.pm +++ b/centreon-plugins/cloud/aws/rds/mode/transactions.pm @@ -76,7 +76,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "type:s" => { name => 'type' }, diff --git a/centreon-plugins/cloud/aws/rds/mode/volume.pm b/centreon-plugins/cloud/aws/rds/mode/volume.pm index ec49ac64c..bd6d58c4b 100644 --- a/centreon-plugins/cloud/aws/rds/mode/volume.pm +++ b/centreon-plugins/cloud/aws/rds/mode/volume.pm @@ -125,7 +125,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "type:s" => { name => 'type', default => 'cluster' }, "name:s@" => { name => 'name' }, diff --git a/centreon-plugins/cloud/aws/s3/mode/bucketsize.pm b/centreon-plugins/cloud/aws/s3/mode/bucketsize.pm index 511c3e840..1f5a3fb3d 100644 --- a/centreon-plugins/cloud/aws/s3/mode/bucketsize.pm +++ b/centreon-plugins/cloud/aws/s3/mode/bucketsize.pm @@ -62,7 +62,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, diff --git a/centreon-plugins/cloud/aws/s3/mode/objects.pm b/centreon-plugins/cloud/aws/s3/mode/objects.pm index c971ee90d..648e96a10 100644 --- a/centreon-plugins/cloud/aws/s3/mode/objects.pm +++ b/centreon-plugins/cloud/aws/s3/mode/objects.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, diff --git a/centreon-plugins/cloud/aws/s3/mode/requests.pm b/centreon-plugins/cloud/aws/s3/mode/requests.pm index 458c4d765..7b1371c0a 100644 --- a/centreon-plugins/cloud/aws/s3/mode/requests.pm +++ b/centreon-plugins/cloud/aws/s3/mode/requests.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s@" => { name => 'name' }, diff --git a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm index 94eace662..c4c00fbb5 100644 --- a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm +++ b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm @@ -81,7 +81,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/diskio.pm b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/diskio.pm index 0a1f54b36..e19efc3d4 100644 --- a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/diskio.pm +++ b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/diskio.pm @@ -158,7 +158,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/listresources.pm b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/listresources.pm index f2036eb20..5597f6637 100644 --- a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/listresources.pm +++ b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/listresources.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/network.pm b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/network.pm index e5b4710f1..00e6bb355 100644 --- a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/network.pm +++ b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/network.pm @@ -117,7 +117,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/vmsizes.pm b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/vmsizes.pm index df9722a3a..58dd2120a 100644 --- a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/vmsizes.pm +++ b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/vmsizes.pm @@ -120,7 +120,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/vmsstate.pm b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/vmsstate.pm index a9fb2c4aa..5ad6deb18 100644 --- a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/vmsstate.pm +++ b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/vmsstate.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/custom/api.pm b/centreon-plugins/cloud/azure/custom/api.pm index c1710fd45..77bfcbe50 100644 --- a/centreon-plugins/cloud/azure/custom/api.pm +++ b/centreon-plugins/cloud/azure/custom/api.pm @@ -95,7 +95,7 @@ sub check_options { if (defined($self->{option_results}->{aggregation})) { foreach my $aggregation (@{$self->{option_results}->{aggregation}}) { - if ($aggregation !~ /average|maximum|minimum|total/i) { + if ($aggregation !~ /average|maximum|minimum|total|count/i) { $self->{output}->add_option_msg(short_msg => "Aggregation '" . $aggregation . "' is not handled"); $self->{output}->option_exit(); } @@ -280,9 +280,11 @@ sub azure_get_metrics_set_url { my $encoded_aggregations = $uri->encode(join(',', @{$options{aggregations}})); my $encoded_timespan = $uri->encode($options{start_time} . '/' . $options{end_time}); - my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourceGroups/" . $options{resource_group} . - "/providers/" . $options{resource_namespace} . "/" . $options{resource_type} . "/" . $options{resource} . '/providers/microsoft.insights/metrics' . - "?api-version=" . $self->{api_version} . "&metricnames=" . $encoded_metrics . "&aggregation=" . $encoded_aggregations . "×pan=" . $encoded_timespan; + my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourceGroups/" . + $options{resource_group} . "/providers/" . $options{resource_namespace} . "/" . $options{resource_type} . + "/" . $options{resource} . "/providers/microsoft.insights/metrics?api-version=" . $self->{api_version} . + "&metricnames=" . $encoded_metrics . "&aggregation=" . $encoded_aggregations . + "×pan=" . $encoded_timespan . "&interval=" . $options{interval}; return $url; } @@ -609,6 +611,8 @@ To connect to the Azure Rest API, you must register an application. Follow the 'How-to guide' in https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal +The application needs the 'Monitoring Reader' role (See https://docs.microsoft.com/en-us/azure/azure-monitor/platform/roles-permissions-security#monitoring-reader). + This custom mode is using the 'OAuth 2.0 Client Credentials Grant Flow' For futher informations, visit https://docs.microsoft.com/en-us/azure/active-directory/develop/v1-oauth2-client-creds-grant-flow diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasesize.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasesize.pm index c2591f618..1bf16335b 100644 --- a/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasesize.pm +++ b/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasesize.pm @@ -64,7 +64,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasestatus.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasestatus.pm index 1531898db..7f0a569f1 100644 --- a/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasestatus.pm +++ b/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasestatus.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/listdatabases.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/listdatabases.pm index 2c99eb97f..b931fa570 100644 --- a/centreon-plugins/cloud/azure/database/sqldatabase/mode/listdatabases.pm +++ b/centreon-plugins/cloud/azure/database/sqldatabase/mode/listdatabases.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/database/sqlserver/mode/listservers.pm b/centreon-plugins/cloud/azure/database/sqlserver/mode/listservers.pm index f7dd62e2f..0f88aa9be 100644 --- a/centreon-plugins/cloud/azure/database/sqlserver/mode/listservers.pm +++ b/centreon-plugins/cloud/azure/database/sqlserver/mode/listservers.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/database/sqlserver/mode/serverstatus.pm b/centreon-plugins/cloud/azure/database/sqlserver/mode/serverstatus.pm index b28a34411..c6eb1ab89 100644 --- a/centreon-plugins/cloud/azure/database/sqlserver/mode/serverstatus.pm +++ b/centreon-plugins/cloud/azure/database/sqlserver/mode/serverstatus.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/management/monitor/mode/discovery.pm b/centreon-plugins/cloud/azure/management/monitor/mode/discovery.pm index 7a2a0d5fa..fb2106a81 100644 --- a/centreon-plugins/cloud/azure/management/monitor/mode/discovery.pm +++ b/centreon-plugins/cloud/azure/management/monitor/mode/discovery.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "namespace:s" => { name => 'namespace' }, "type:s" => { name => 'type' }, diff --git a/centreon-plugins/cloud/azure/management/monitor/mode/getmetrics.pm b/centreon-plugins/cloud/azure/management/monitor/mode/getmetrics.pm index 2a77be569..3ae3d7bf6 100644 --- a/centreon-plugins/cloud/azure/management/monitor/mode/getmetrics.pm +++ b/centreon-plugins/cloud/azure/management/monitor/mode/getmetrics.pm @@ -29,27 +29,30 @@ use Data::Dumper; sub custom_metric_perfdata { my ($self, %options) = @_; - $self->{output}->perfdata_add(label => $self->{result_values}->{perf_label}, - value => $self->{result_values}->{value}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-metric'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-metric'), - ); + $self->{output}->perfdata_add( + label => $self->{result_values}->{perf_label}, + value => $self->{result_values}->{value}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-metric'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-metric'), + ); } sub custom_metric_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{value}, - threshold => [ { label => 'critical-metric', exit_litteral => 'critical' }, - { label => 'warning-metric', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check( + value => $self->{result_values}->{value}, + threshold => [ { label => 'critical-metric', exit_litteral => 'critical' }, + { label => 'warning-metric', exit_litteral => 'warning' } ]); return $exit; } sub custom_metric_output { my ($self, %options) = @_; - my $msg = "Metric '" . $self->{result_values}->{label} . "' of resource '" . $self->{result_values}->{display} . "' value is " . $self->{result_values}->{value}; + my $msg = "Metric '" . $self->{result_values}->{name} . "' of resource '" . $self->{result_values}->{display} . + "' and aggregation '" . $self->{result_values}->{aggregation} . "' value is " . $self->{result_values}->{value}; return $msg; } @@ -57,6 +60,7 @@ sub custom_metric_calc { my ($self, %options) = @_; $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_value'}; + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; $self->{result_values}->{label} = $options{new_datas}->{$self->{instance} . '_label'}; $self->{result_values}->{aggregation} = $options{new_datas}->{$self->{instance} . '_aggregation'}; $self->{result_values}->{perf_label} = $options{new_datas}->{$self->{instance} . '_perf_label'}; @@ -68,12 +72,12 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'metrics', type => 0 }, + { name => 'metrics', type => 1, message_multiple => 'All metrics are ok' }, ]; $self->{maps_counters}->{metrics} = [ { label => 'metric', set => { - key_values => [ { name => 'value' }, { name => 'label' }, { name => 'aggregation' }, + key_values => [ { name => 'value' }, { name => 'name' }, { name => 'label' }, { name => 'aggregation' }, { name => 'perf_label' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_metric_calc'), closure_custom_output => $self->can('custom_metric_output'), @@ -89,15 +93,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "resource:s" => { name => 'resource' }, - "resource-group:s" => { name => 'resource_group' }, - "resource-type:s" => { name => 'resource_type' }, - "resource-namespace:s" => { name => 'resource_namespace' }, - "metric:s@" => { name => 'metric' }, - }); + $options{options}->add_options(arguments => { + "resource:s" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "resource-type:s" => { name => 'resource_type' }, + "resource-namespace:s" => { name => 'resource_namespace' }, + "metric:s@" => { name => 'metric' }, + }); return $self; } @@ -107,7 +109,7 @@ sub check_options { $self->SUPER::check_options(%options); if (!defined($self->{option_results}->{resource})) { - $self->{output}->add_option_msg(short_msg => "Need to specify either --resource with --resource-group and --resource-type options or --resource ."); + $self->{output}->add_option_msg(short_msg => "Need to specify either --resource with --resource-group, --resource-type and --resource-namespace options or --resource ."); $self->{output}->option_exit(); } @@ -165,8 +167,9 @@ sub manage_selection { foreach my $aggregation (('minimum', 'maximum', 'average', 'total')) { next if (!defined($results->{$label}->{$aggregation})); - $self->{metrics} = { + $self->{metrics}->{$label . '_' . $aggregation} = { display => $self->{az_resource}, + name => $results->{$label}->{name}, label => $label, aggregation => $aggregation, value => $results->{$label}->{$aggregation}, @@ -215,7 +218,7 @@ Set resource type (Required if resource's name is used). =item B<--metric> -Set monitor metrics (Required). +Set monitor metrics (Required) (Can be multiple). =item B<--warning-metric> diff --git a/centreon-plugins/cloud/azure/management/recovery/mode/backupitemsstatus.pm b/centreon-plugins/cloud/azure/management/recovery/mode/backupitemsstatus.pm index 23498e9ca..a5e473901 100644 --- a/centreon-plugins/cloud/azure/management/recovery/mode/backupitemsstatus.pm +++ b/centreon-plugins/cloud/azure/management/recovery/mode/backupitemsstatus.pm @@ -106,7 +106,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vault-name:s" => { name => 'vault_name' }, diff --git a/centreon-plugins/cloud/azure/management/recovery/mode/backupjobsstatus.pm b/centreon-plugins/cloud/azure/management/recovery/mode/backupjobsstatus.pm index e84da395d..cbda632d4 100644 --- a/centreon-plugins/cloud/azure/management/recovery/mode/backupjobsstatus.pm +++ b/centreon-plugins/cloud/azure/management/recovery/mode/backupjobsstatus.pm @@ -113,7 +113,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vault-name:s" => { name => 'vault_name' }, diff --git a/centreon-plugins/cloud/azure/management/recovery/mode/listbackupjobs.pm b/centreon-plugins/cloud/azure/management/recovery/mode/listbackupjobs.pm index 5db0ee1c0..aec31f8ea 100644 --- a/centreon-plugins/cloud/azure/management/recovery/mode/listbackupjobs.pm +++ b/centreon-plugins/cloud/azure/management/recovery/mode/listbackupjobs.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "vault-name:s" => { name => 'vault_name' }, diff --git a/centreon-plugins/cloud/azure/management/recovery/mode/listvaults.pm b/centreon-plugins/cloud/azure/management/recovery/mode/listvaults.pm index 818f87d47..7f7fbe5b7 100644 --- a/centreon-plugins/cloud/azure/management/recovery/mode/listvaults.pm +++ b/centreon-plugins/cloud/azure/management/recovery/mode/listvaults.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/management/resource/mode/deploymentsstatus.pm b/centreon-plugins/cloud/azure/management/resource/mode/deploymentsstatus.pm index 0f1988601..33efb7723 100644 --- a/centreon-plugins/cloud/azure/management/resource/mode/deploymentsstatus.pm +++ b/centreon-plugins/cloud/azure/management/resource/mode/deploymentsstatus.pm @@ -101,7 +101,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/management/resource/mode/items.pm b/centreon-plugins/cloud/azure/management/resource/mode/items.pm index 9c2f33211..b5fd9a27b 100644 --- a/centreon-plugins/cloud/azure/management/resource/mode/items.pm +++ b/centreon-plugins/cloud/azure/management/resource/mode/items.pm @@ -83,7 +83,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/management/resource/mode/listgroups.pm b/centreon-plugins/cloud/azure/management/resource/mode/listgroups.pm index dd7d26309..e7a3be234 100644 --- a/centreon-plugins/cloud/azure/management/resource/mode/listgroups.pm +++ b/centreon-plugins/cloud/azure/management/resource/mode/listgroups.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "location:s" => { name => 'location' }, diff --git a/centreon-plugins/cloud/azure/management/resource/mode/listresources.pm b/centreon-plugins/cloud/azure/management/resource/mode/listresources.pm index 6be51a002..56fe5c12e 100644 --- a/centreon-plugins/cloud/azure/management/resource/mode/listresources.pm +++ b/centreon-plugins/cloud/azure/management/resource/mode/listresources.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/network/expressroute/mode/circuitstatus.pm b/centreon-plugins/cloud/azure/network/expressroute/mode/circuitstatus.pm index dce032781..7e8542916 100644 --- a/centreon-plugins/cloud/azure/network/expressroute/mode/circuitstatus.pm +++ b/centreon-plugins/cloud/azure/network/expressroute/mode/circuitstatus.pm @@ -79,7 +79,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/network/expressroute/mode/listcircuits.pm b/centreon-plugins/cloud/azure/network/expressroute/mode/listcircuits.pm index a896fe865..dfff54079 100644 --- a/centreon-plugins/cloud/azure/network/expressroute/mode/listcircuits.pm +++ b/centreon-plugins/cloud/azure/network/expressroute/mode/listcircuits.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/network/expressroute/mode/traffic.pm b/centreon-plugins/cloud/azure/network/expressroute/mode/traffic.pm index cc1120864..087d83084 100644 --- a/centreon-plugins/cloud/azure/network/expressroute/mode/traffic.pm +++ b/centreon-plugins/cloud/azure/network/expressroute/mode/traffic.pm @@ -110,7 +110,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/network/networkinterface/mode/listresources.pm b/centreon-plugins/cloud/azure/network/networkinterface/mode/listresources.pm index 7862bfe4b..16593f594 100644 --- a/centreon-plugins/cloud/azure/network/networkinterface/mode/listresources.pm +++ b/centreon-plugins/cloud/azure/network/networkinterface/mode/listresources.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/network/networkinterface/mode/traffic.pm b/centreon-plugins/cloud/azure/network/networkinterface/mode/traffic.pm index 5aefe45be..d40682e4d 100644 --- a/centreon-plugins/cloud/azure/network/networkinterface/mode/traffic.pm +++ b/centreon-plugins/cloud/azure/network/networkinterface/mode/traffic.pm @@ -162,7 +162,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/network/virtualnetwork/mode/listvirtualnetworks.pm b/centreon-plugins/cloud/azure/network/virtualnetwork/mode/listvirtualnetworks.pm index 3b63b732e..332b43ea4 100644 --- a/centreon-plugins/cloud/azure/network/virtualnetwork/mode/listvirtualnetworks.pm +++ b/centreon-plugins/cloud/azure/network/virtualnetwork/mode/listvirtualnetworks.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/network/virtualnetwork/mode/peeringsstatus.pm b/centreon-plugins/cloud/azure/network/virtualnetwork/mode/peeringsstatus.pm index 29a09e34e..29cf6e5b9 100644 --- a/centreon-plugins/cloud/azure/network/virtualnetwork/mode/peeringsstatus.pm +++ b/centreon-plugins/cloud/azure/network/virtualnetwork/mode/peeringsstatus.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/network/vpngateway/mode/sitetraffic.pm b/centreon-plugins/cloud/azure/network/vpngateway/mode/sitetraffic.pm index eef5df12a..044798187 100644 --- a/centreon-plugins/cloud/azure/network/vpngateway/mode/sitetraffic.pm +++ b/centreon-plugins/cloud/azure/network/vpngateway/mode/sitetraffic.pm @@ -130,7 +130,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/network/vpngateway/mode/tunneltraffic.pm b/centreon-plugins/cloud/azure/network/vpngateway/mode/tunneltraffic.pm index fc76e74ef..5011642c9 100644 --- a/centreon-plugins/cloud/azure/network/vpngateway/mode/tunneltraffic.pm +++ b/centreon-plugins/cloud/azure/network/vpngateway/mode/tunneltraffic.pm @@ -163,7 +163,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/network/vpngateway/mode/vpngatewaystatus.pm b/centreon-plugins/cloud/azure/network/vpngateway/mode/vpngatewaystatus.pm index 902b89aff..7758f9d03 100644 --- a/centreon-plugins/cloud/azure/network/vpngateway/mode/vpngatewaystatus.pm +++ b/centreon-plugins/cloud/azure/network/vpngateway/mode/vpngatewaystatus.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/accountusedcapacity.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/accountusedcapacity.pm index 16bb7d6e6..dadba280e 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/accountusedcapacity.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/accountusedcapacity.pm @@ -62,7 +62,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcapacity.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcapacity.pm index 55bd5ef3f..f17738316 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcapacity.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcapacity.pm @@ -62,7 +62,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcontainercount.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcontainercount.pm index dc8d87585..9035f3c68 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcontainercount.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcontainercount.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcount.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcount.pm index 7577c860c..bc881d1c0 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcount.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcount.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecapacity.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecapacity.pm index c4d5b8a68..c1a6f4751 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecapacity.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecapacity.pm @@ -62,7 +62,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecount.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecount.pm index 60a6fedbe..6e5615736 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecount.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecount.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filesharecount.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/filesharecount.pm index 50660934e..264fff403 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filesharecount.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/filesharecount.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/listresources.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/listresources.pm index 36ea3ebbb..ea7cbc7a7 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/listresources.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/listresources.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecapacity.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecapacity.pm index 6863860b6..0d87d12b4 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecapacity.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecapacity.pm @@ -62,7 +62,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecount.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecount.pm index a286b4a11..8574744c6 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecount.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecount.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuemessagecount.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuemessagecount.pm index 6d7a874c1..16ca9ded7 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuemessagecount.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuemessagecount.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecapacity.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecapacity.pm index 4a1aea10d..f2e66485f 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecapacity.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecapacity.pm @@ -62,7 +62,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecount.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecount.pm index 2b902ab0c..f79d3a48a 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecount.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecount.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tableentitycount.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/tableentitycount.pm index cedc1c862..9ad0be437 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tableentitycount.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/tableentitycount.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsavailability.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsavailability.pm index 6aeb9dcdf..9a9af1283 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsavailability.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsavailability.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionscount.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionscount.pm index 9c6f3b22d..2a31df215 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionscount.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionscount.pm @@ -117,7 +117,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionslatency.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionslatency.pm index f43e289f6..61c5d96cc 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionslatency.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionslatency.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsthroughput.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsthroughput.pm index 5738d5fa9..dbbba0e9a 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsthroughput.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsthroughput.pm @@ -119,7 +119,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, diff --git a/centreon-plugins/cloud/cadvisor/restapi/mode/containerusage.pm b/centreon-plugins/cloud/cadvisor/restapi/mode/containerusage.pm index b6dd83bbe..d095ae7ae 100644 --- a/centreon-plugins/cloud/cadvisor/restapi/mode/containerusage.pm +++ b/centreon-plugins/cloud/cadvisor/restapi/mode/containerusage.pm @@ -133,7 +133,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "container-id:s" => { name => 'container_id' }, "container-name:s" => { name => 'container_name' }, diff --git a/centreon-plugins/cloud/cadvisor/restapi/mode/diskio.pm b/centreon-plugins/cloud/cadvisor/restapi/mode/diskio.pm index f07619e96..0f6c1acc5 100644 --- a/centreon-plugins/cloud/cadvisor/restapi/mode/diskio.pm +++ b/centreon-plugins/cloud/cadvisor/restapi/mode/diskio.pm @@ -62,7 +62,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "container-id:s" => { name => 'container_id' }, diff --git a/centreon-plugins/cloud/cadvisor/restapi/mode/listcontainers.pm b/centreon-plugins/cloud/cadvisor/restapi/mode/listcontainers.pm index 27f01caeb..7a810497b 100644 --- a/centreon-plugins/cloud/cadvisor/restapi/mode/listcontainers.pm +++ b/centreon-plugins/cloud/cadvisor/restapi/mode/listcontainers.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/cloud/cadvisor/restapi/mode/nodestatus.pm b/centreon-plugins/cloud/cadvisor/restapi/mode/nodestatus.pm index 30961a53a..5ed9d1dc3 100644 --- a/centreon-plugins/cloud/cadvisor/restapi/mode/nodestatus.pm +++ b/centreon-plugins/cloud/cadvisor/restapi/mode/nodestatus.pm @@ -87,7 +87,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/cloud/cadvisor/restapi/mode/traffic.pm b/centreon-plugins/cloud/cadvisor/restapi/mode/traffic.pm index 3682cfd35..f303bf84d 100644 --- a/centreon-plugins/cloud/cadvisor/restapi/mode/traffic.pm +++ b/centreon-plugins/cloud/cadvisor/restapi/mode/traffic.pm @@ -63,7 +63,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "container-id:s" => { name => 'container_id' }, "container-name:s" => { name => 'container_name' }, diff --git a/centreon-plugins/cloud/cloudfoundry/restapi/mode/appsstate.pm b/centreon-plugins/cloud/cloudfoundry/restapi/mode/appsstate.pm index 19d897772..8acfb2af3 100644 --- a/centreon-plugins/cloud/cloudfoundry/restapi/mode/appsstate.pm +++ b/centreon-plugins/cloud/cloudfoundry/restapi/mode/appsstate.pm @@ -94,7 +94,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "organization-guid:s" => { name => 'organization_guid' }, diff --git a/centreon-plugins/cloud/cloudfoundry/restapi/mode/instancesstate.pm b/centreon-plugins/cloud/cloudfoundry/restapi/mode/instancesstate.pm index af61e9073..5785e7636 100644 --- a/centreon-plugins/cloud/cloudfoundry/restapi/mode/instancesstate.pm +++ b/centreon-plugins/cloud/cloudfoundry/restapi/mode/instancesstate.pm @@ -179,7 +179,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "app-guid:s" => { name => 'app_guid' }, "warning-app-state:s" => { name => 'warning_app_state' }, diff --git a/centreon-plugins/cloud/cloudfoundry/restapi/mode/listapps.pm b/centreon-plugins/cloud/cloudfoundry/restapi/mode/listapps.pm index 7901af419..8f0f751be 100644 --- a/centreon-plugins/cloud/cloudfoundry/restapi/mode/listapps.pm +++ b/centreon-plugins/cloud/cloudfoundry/restapi/mode/listapps.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/cloud/cloudfoundry/restapi/mode/listorganizations.pm b/centreon-plugins/cloud/cloudfoundry/restapi/mode/listorganizations.pm index b2543680a..5a209f5a5 100644 --- a/centreon-plugins/cloud/cloudfoundry/restapi/mode/listorganizations.pm +++ b/centreon-plugins/cloud/cloudfoundry/restapi/mode/listorganizations.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/cloud/cloudfoundry/restapi/mode/listspaces.pm b/centreon-plugins/cloud/cloudfoundry/restapi/mode/listspaces.pm index 70e00adac..52f549ca3 100644 --- a/centreon-plugins/cloud/cloudfoundry/restapi/mode/listspaces.pm +++ b/centreon-plugins/cloud/cloudfoundry/restapi/mode/listspaces.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/cloud/docker/restapi/mode/containerusage.pm b/centreon-plugins/cloud/docker/restapi/mode/containerusage.pm index d3e931050..3e3d67c57 100644 --- a/centreon-plugins/cloud/docker/restapi/mode/containerusage.pm +++ b/centreon-plugins/cloud/docker/restapi/mode/containerusage.pm @@ -188,7 +188,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "container-id:s" => { name => 'container_id' }, @@ -250,7 +249,8 @@ sub manage_selection { write_io => $write_io, cpu_total_usage => $result->{$container_id}->{Stats}->{cpu_stats}->{cpu_usage}->{total_usage}, cpu_system_usage => $result->{$container_id}->{Stats}->{cpu_stats}->{system_cpu_usage}, - cpu_number => scalar(@{$result->{$container_id}->{Stats}->{cpu_stats}->{cpu_usage}->{percpu_usage}}), + cpu_number => defined($result->{$container_id}->{Stats}->{cpu_stats}->{cpu_usage}->{percpu_usage}) ? + scalar(@{$result->{$container_id}->{Stats}->{cpu_stats}->{cpu_usage}->{percpu_usage}}) : 1, memory_usage => $result->{$container_id}->{Stats}->{memory_stats}->{usage}, memory_total => $result->{$container_id}->{Stats}->{memory_stats}->{limit}, }; diff --git a/centreon-plugins/cloud/docker/restapi/mode/listcontainers.pm b/centreon-plugins/cloud/docker/restapi/mode/listcontainers.pm index 4308d7fd6..c583bca1f 100644 --- a/centreon-plugins/cloud/docker/restapi/mode/listcontainers.pm +++ b/centreon-plugins/cloud/docker/restapi/mode/listcontainers.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/cloud/docker/restapi/mode/nodestatus.pm b/centreon-plugins/cloud/docker/restapi/mode/nodestatus.pm index 92e22b803..f8e3216f9 100644 --- a/centreon-plugins/cloud/docker/restapi/mode/nodestatus.pm +++ b/centreon-plugins/cloud/docker/restapi/mode/nodestatus.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-node-status:s" => { name => 'warning_node_status', default => '' }, diff --git a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/cpu.pm b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/cpu.pm index ddec5ae43..82cf6e01f 100644 --- a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/cpu.pm +++ b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/cpu.pm @@ -96,7 +96,7 @@ sub set_counters { key_values => [ { name => $metric . '_' . $aggregation }, { name => 'display' }, { name => 'stat' } ], closure_custom_calc => $self->can('custom_metric_calc'), closure_custom_calc_extra_options => { metric_perf => $metric_perf, - metric_label => $metric_label, metric_name => $metric_name, metric => $metric }, + metric_label => $metric_label, metric_name => $metric_name, metric => $metric }, closure_custom_output => $self->can('custom_usage_output'), closure_custom_perfdata => $self->can('custom_usage_perfdata'), closure_custom_threshold_check => $self->can('custom_metric_threshold'), @@ -128,7 +128,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s@" => { name => 'instance' }, "filter-metric:s" => { name => 'filter_metric' }, @@ -175,6 +174,7 @@ sub manage_selection { foreach my $instance (@{$self->{gcp_instance}}) { foreach my $metric (@{$self->{gcp_metrics}}) { ($metric_results, undef) = $options{custom}->gcp_get_metrics( + dimension => 'metric.labels.instance_name', instance => $instance, metric => $metric, api => $self->{gcp_api}, diff --git a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/diskio.pm b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/diskio.pm index d583b3175..32b1c62b0 100644 --- a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/diskio.pm +++ b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/diskio.pm @@ -174,7 +174,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s@" => { name => 'instance' }, "filter-metric:s" => { name => 'filter_metric' }, @@ -224,6 +223,7 @@ sub manage_selection { foreach my $instance (@{$self->{gcp_instance}}) { foreach my $metric (@{$self->{gcp_metrics}}) { ($metric_results, undef) = $options{custom}->gcp_get_metrics( + dimension => 'metric.labels.instance_name', instance => $instance, metric => $metric, api => $self->{gcp_api}, diff --git a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/network.pm b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/network.pm index 9f2fefef6..3ce0a1e32 100644 --- a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/network.pm +++ b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/network.pm @@ -167,7 +167,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s@" => { name => 'instance' }, "filter-metric:s" => { name => 'filter_metric' }, @@ -216,6 +215,7 @@ sub manage_selection { foreach my $instance (@{$self->{gcp_instance}}) { foreach my $metric (@{$self->{gcp_metrics}}) { ($metric_results, undef) = $options{custom}->gcp_get_metrics( + dimension => 'metric.labels.instance_name', instance => $instance, metric => $metric, api => $self->{gcp_api}, diff --git a/centreon-plugins/cloud/google/gcp/custom/api.pm b/centreon-plugins/cloud/google/gcp/custom/api.pm index 3f3cf7abe..673dc1e4a 100644 --- a/centreon-plugins/cloud/google/gcp/custom/api.pm +++ b/centreon-plugins/cloud/google/gcp/custom/api.pm @@ -106,11 +106,11 @@ sub check_options { $self->{step} = (defined($self->{option_results}->{step})) ? $self->{option_results}->{step} : undef; $self->{key_file} = (defined($self->{option_results}->{key_file})) ? $self->{option_results}->{key_file} : undef; $self->{authorization_endpoint} = (defined($self->{option_results}->{authorization_endpoint})) ? - $self->{option_results}->{authorization_endpoint} : 'https://www.googleapis.com/oauth2/v4/token'; + $self->{option_results}->{authorization_endpoint} : 'https://www.googleapis.com/oauth2/v4/token'; $self->{monitoring_endpoint} = (defined($self->{option_results}->{monitoring_endpoint})) ? - $self->{option_results}->{monitoring_endpoint} : 'https://monitoring.googleapis.com/v3'; + $self->{option_results}->{monitoring_endpoint} : 'https://monitoring.googleapis.com/v3'; $self->{scope_endpoint} = (defined($self->{option_results}->{scope_endpoint})) ? - $self->{option_results}->{scope_endpoint} : 'https://www.googleapis.com/auth/cloud-platform'; + $self->{option_results}->{scope_endpoint} : 'https://www.googleapis.com/auth/cloud-platform'; if (!defined($self->{key_file}) || $self->{key_file} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --key-file option."); @@ -283,7 +283,7 @@ sub gcp_get_metrics_set_url { my $uri = URI::Encode->new({encode_reserved => 1}); my $encoded_filter = $uri->encode('metric.type = "' . $options{api} . '/' . $options{metric} . '"'); - $encoded_filter .= $uri->encode(' AND metric.labels.instance_name = starts_with(' . $options{instance} . ')'); + $encoded_filter .= $uri->encode(' AND ' . $options{dimension} . ' = starts_with(' . $options{instance} . ')'); $encoded_filter .= ' AND ' . $uri->encode(join(' AND ', @{$options{extra_filters}})) if (defined($options{extra_filters}) && $options{extra_filters} ne ''); my $encoded_start_time = $uri->encode($options{start_time}); my $encoded_end_time = $uri->encode($options{end_time}); diff --git a/centreon-plugins/cloud/google/gcp/management/stackdriver/mode/getmetrics.pm b/centreon-plugins/cloud/google/gcp/management/stackdriver/mode/getmetrics.pm index 8a9e0ce1d..bf39ff211 100644 --- a/centreon-plugins/cloud/google/gcp/management/stackdriver/mode/getmetrics.pm +++ b/centreon-plugins/cloud/google/gcp/management/stackdriver/mode/getmetrics.pm @@ -90,8 +90,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { + "dimension:s" => { name => 'dimension' }, "instance:s" => { name => 'instance' }, "metric:s" => { name => 'metric' }, "api:s" => { name => 'api' }, @@ -105,6 +105,10 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); + if (!defined($self->{option_results}->{dimension})) { + $self->{output}->add_option_msg(short_msg => "Need to specify --dimension ."); + $self->{output}->option_exit(); + } if (!defined($self->{option_results}->{instance})) { $self->{output}->add_option_msg(short_msg => "Need to specify --instance ."); $self->{output}->option_exit(); @@ -118,6 +122,7 @@ sub check_options { $self->{output}->option_exit(); } + $self->{gcp_dimension} = $self->{option_results}->{dimension}; $self->{gcp_instance} = $self->{option_results}->{instance}; $self->{gcp_metric} = $self->{option_results}->{metric}; $self->{gcp_api} = $self->{option_results}->{api}; @@ -145,21 +150,22 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - - my ($results, $raw_results) = $options{custom}->gcp_get_metrics( - instance => $self->{gcp_instance}, - metric => $self->{gcp_metric}, - api => $self->{gcp_api}, - extra_filters => $self->{gcp_extra_filters}, - aggregations => $self->{gcp_aggregation}, - timeframe => $self->{gcp_timeframe}, - ); - + $self->{metrics} = {}; + + my ($results, $raw_results) = $options{custom}->gcp_get_metrics( + dimension => $self->{gcp_dimension}, + instance => $self->{gcp_instance}, + metric => $self->{gcp_metric}, + api => $self->{gcp_api}, + extra_filters => $self->{gcp_extra_filters}, + aggregations => $self->{gcp_aggregation}, + timeframe => $self->{gcp_timeframe}, + ); + foreach my $label (keys %{$results}) { foreach my $aggregation (('minimum', 'maximum', 'average', 'total')) { next if (!defined($results->{$label}->{$aggregation})); - $self->{metrics} = { display => $self->{gcp_instance}, label => $label, @@ -168,7 +174,7 @@ sub manage_selection { perf_label => $label . '_' . $aggregation, }; } - } + } $self->{output}->output_add(long_msg => sprintf("Raw data:\n%s", Dumper($raw_results)), debug => 1); } @@ -197,6 +203,10 @@ Set GCP API (Required). Set stackdriver metric (Required). +=item B<--dimension> + +Set dimension primary filter (Required). + =item B<--instance> Set instance name (Required). diff --git a/centreon-plugins/cloud/ibm/softlayer/mode/events.pm b/centreon-plugins/cloud/ibm/softlayer/mode/events.pm index 1f3fb792a..acfe4f11b 100644 --- a/centreon-plugins/cloud/ibm/softlayer/mode/events.pm +++ b/centreon-plugins/cloud/ibm/softlayer/mode/events.pm @@ -119,7 +119,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-status:s" => { name => 'filter_status', default => 'Active' }, diff --git a/centreon-plugins/cloud/ibm/softlayer/mode/opentickets.pm b/centreon-plugins/cloud/ibm/softlayer/mode/opentickets.pm index 14e95ea75..db22a4019 100644 --- a/centreon-plugins/cloud/ibm/softlayer/mode/opentickets.pm +++ b/centreon-plugins/cloud/ibm/softlayer/mode/opentickets.pm @@ -94,7 +94,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "ticket-group:s" => { name => 'ticket_group' }, diff --git a/centreon-plugins/cloud/kubernetes/mode/daemonsetstatus.pm b/centreon-plugins/cloud/kubernetes/mode/daemonsetstatus.pm index 051928133..2d5404874 100644 --- a/centreon-plugins/cloud/kubernetes/mode/daemonsetstatus.pm +++ b/centreon-plugins/cloud/kubernetes/mode/daemonsetstatus.pm @@ -125,7 +125,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-namespace:s" => { name => 'filter_namespace' }, diff --git a/centreon-plugins/cloud/kubernetes/mode/deploymentstatus.pm b/centreon-plugins/cloud/kubernetes/mode/deploymentstatus.pm index 215e8a418..6aa99554a 100644 --- a/centreon-plugins/cloud/kubernetes/mode/deploymentstatus.pm +++ b/centreon-plugins/cloud/kubernetes/mode/deploymentstatus.pm @@ -117,7 +117,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-namespace:s" => { name => 'filter_namespace' }, diff --git a/centreon-plugins/cloud/kubernetes/mode/listdaemonsets.pm b/centreon-plugins/cloud/kubernetes/mode/listdaemonsets.pm index 511c3edcf..39671100f 100644 --- a/centreon-plugins/cloud/kubernetes/mode/listdaemonsets.pm +++ b/centreon-plugins/cloud/kubernetes/mode/listdaemonsets.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-namespace:s" => { name => 'filter_namespace' }, diff --git a/centreon-plugins/cloud/kubernetes/mode/listdeployments.pm b/centreon-plugins/cloud/kubernetes/mode/listdeployments.pm index 624b4decf..35ad9d032 100644 --- a/centreon-plugins/cloud/kubernetes/mode/listdeployments.pm +++ b/centreon-plugins/cloud/kubernetes/mode/listdeployments.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-namespace:s" => { name => 'filter_namespace' }, diff --git a/centreon-plugins/cloud/kubernetes/mode/listingresses.pm b/centreon-plugins/cloud/kubernetes/mode/listingresses.pm index 8fb703cdc..90b5fe04b 100644 --- a/centreon-plugins/cloud/kubernetes/mode/listingresses.pm +++ b/centreon-plugins/cloud/kubernetes/mode/listingresses.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-namespace:s" => { name => 'filter_namespace' }, diff --git a/centreon-plugins/cloud/kubernetes/mode/listnamespaces.pm b/centreon-plugins/cloud/kubernetes/mode/listnamespaces.pm index 8abbc8655..c3d9be071 100644 --- a/centreon-plugins/cloud/kubernetes/mode/listnamespaces.pm +++ b/centreon-plugins/cloud/kubernetes/mode/listnamespaces.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/cloud/kubernetes/mode/listnodes.pm b/centreon-plugins/cloud/kubernetes/mode/listnodes.pm index 706c7a774..497254536 100644 --- a/centreon-plugins/cloud/kubernetes/mode/listnodes.pm +++ b/centreon-plugins/cloud/kubernetes/mode/listnodes.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/cloud/kubernetes/mode/listpods.pm b/centreon-plugins/cloud/kubernetes/mode/listpods.pm index b71b8441b..d49b08c4b 100644 --- a/centreon-plugins/cloud/kubernetes/mode/listpods.pm +++ b/centreon-plugins/cloud/kubernetes/mode/listpods.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-namespace:s" => { name => 'filter_namespace' }, diff --git a/centreon-plugins/cloud/kubernetes/mode/listreplicasets.pm b/centreon-plugins/cloud/kubernetes/mode/listreplicasets.pm index 245423882..f4c2117a3 100644 --- a/centreon-plugins/cloud/kubernetes/mode/listreplicasets.pm +++ b/centreon-plugins/cloud/kubernetes/mode/listreplicasets.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-namespace:s" => { name => 'filter_namespace' }, diff --git a/centreon-plugins/cloud/kubernetes/mode/listservices.pm b/centreon-plugins/cloud/kubernetes/mode/listservices.pm index 7477795c1..7565a968c 100644 --- a/centreon-plugins/cloud/kubernetes/mode/listservices.pm +++ b/centreon-plugins/cloud/kubernetes/mode/listservices.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-namespace:s" => { name => 'filter_namespace' }, diff --git a/centreon-plugins/cloud/kubernetes/mode/liststatefulsets.pm b/centreon-plugins/cloud/kubernetes/mode/liststatefulsets.pm index b993c7483..641de892d 100644 --- a/centreon-plugins/cloud/kubernetes/mode/liststatefulsets.pm +++ b/centreon-plugins/cloud/kubernetes/mode/liststatefulsets.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-namespace:s" => { name => 'filter_namespace' }, diff --git a/centreon-plugins/cloud/kubernetes/mode/nodeusage.pm b/centreon-plugins/cloud/kubernetes/mode/nodeusage.pm index 39c578e84..a8a5a5ed0 100644 --- a/centreon-plugins/cloud/kubernetes/mode/nodeusage.pm +++ b/centreon-plugins/cloud/kubernetes/mode/nodeusage.pm @@ -119,7 +119,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/cloud/kubernetes/mode/podstatus.pm b/centreon-plugins/cloud/kubernetes/mode/podstatus.pm index d3046e0df..cfdbc8efd 100644 --- a/centreon-plugins/cloud/kubernetes/mode/podstatus.pm +++ b/centreon-plugins/cloud/kubernetes/mode/podstatus.pm @@ -205,7 +205,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-namespace:s" => { name => 'filter_namespace' }, diff --git a/centreon-plugins/cloud/microsoft/office365/custom/graphapi.pm b/centreon-plugins/cloud/microsoft/office365/custom/graphapi.pm index 8849d7995..9df22817c 100644 --- a/centreon-plugins/cloud/microsoft/office365/custom/graphapi.pm +++ b/centreon-plugins/cloud/microsoft/office365/custom/graphapi.pm @@ -145,10 +145,11 @@ sub get_access_token { if ($has_cache_file == 0 || !defined($access_token) || (($expires_on - time()) < 10)) { my $uri = URI::Encode->new({encode_reserved => 1}); + my $encoded_client_secret = $uri->encode($self->{client_secret}); my $encoded_graph_endpoint = $uri->encode($self->{graph_endpoint} . '/.default'); my $post_data = 'grant_type=client_credentials' . '&client_id=' . $self->{client_id} . - '&client_secret=' . $self->{client_secret} . + '&client_secret=' . $encoded_client_secret . '&scope=' . $encoded_graph_endpoint; $self->settings(); diff --git a/centreon-plugins/cloud/microsoft/office365/custom/managementapi.pm b/centreon-plugins/cloud/microsoft/office365/custom/managementapi.pm index 01d2433e1..7a5d8e8d3 100644 --- a/centreon-plugins/cloud/microsoft/office365/custom/managementapi.pm +++ b/centreon-plugins/cloud/microsoft/office365/custom/managementapi.pm @@ -143,10 +143,11 @@ sub get_access_token { if ($has_cache_file == 0 || !defined($access_token) || (($expires_on - time()) < 10)) { my $uri = URI::Encode->new({encode_reserved => 1}); + my $encoded_client_secret = $uri->encode($self->{client_secret}); my $encoded_management_endpoint = $uri->encode($self->{management_endpoint}); my $post_data = 'grant_type=client_credentials' . '&client_id=' . $self->{client_id} . - '&client_secret=' . $self->{client_secret} . + '&client_secret=' . $encoded_client_secret . '&resource=' . $encoded_management_endpoint; $self->settings(); diff --git a/centreon-plugins/cloud/microsoft/office365/exchange/mode/emailactivity.pm b/centreon-plugins/cloud/microsoft/office365/exchange/mode/emailactivity.pm index ac703fb99..71907040d 100644 --- a/centreon-plugins/cloud/microsoft/office365/exchange/mode/emailactivity.pm +++ b/centreon-plugins/cloud/microsoft/office365/exchange/mode/emailactivity.pm @@ -173,7 +173,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-mailbox:s" => { name => 'filter_mailbox' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/cloud/microsoft/office365/exchange/mode/mailboxusage.pm b/centreon-plugins/cloud/microsoft/office365/exchange/mode/mailboxusage.pm index 7f7fe4e0b..c8c5c7235 100644 --- a/centreon-plugins/cloud/microsoft/office365/exchange/mode/mailboxusage.pm +++ b/centreon-plugins/cloud/microsoft/office365/exchange/mode/mailboxusage.pm @@ -220,7 +220,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-mailbox:s" => { name => 'filter_mailbox' }, "warning-status:s" => { name => 'warning_status', default => '%{used} > %{issue_warning_quota}' }, diff --git a/centreon-plugins/cloud/microsoft/office365/management/mode/listservices.pm b/centreon-plugins/cloud/microsoft/office365/management/mode/listservices.pm index 2b8c850cd..cb4929f88 100644 --- a/centreon-plugins/cloud/microsoft/office365/management/mode/listservices.pm +++ b/centreon-plugins/cloud/microsoft/office365/management/mode/listservices.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/cloud/microsoft/office365/management/mode/servicestatus.pm b/centreon-plugins/cloud/microsoft/office365/management/mode/servicestatus.pm index 729456c36..6344c718c 100644 --- a/centreon-plugins/cloud/microsoft/office365/management/mode/servicestatus.pm +++ b/centreon-plugins/cloud/microsoft/office365/management/mode/servicestatus.pm @@ -101,7 +101,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-service-name:s" => { name => 'filter_service_name' }, "filter-feature-name:s" => { name => 'filter_feature_name' }, diff --git a/centreon-plugins/cloud/microsoft/office365/onedrive/mode/listsites.pm b/centreon-plugins/cloud/microsoft/office365/onedrive/mode/listsites.pm index 3d8bb79e5..5700f6a13 100644 --- a/centreon-plugins/cloud/microsoft/office365/onedrive/mode/listsites.pm +++ b/centreon-plugins/cloud/microsoft/office365/onedrive/mode/listsites.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-url:s" => { name => 'filter_url' }, diff --git a/centreon-plugins/cloud/microsoft/office365/onedrive/mode/usage.pm b/centreon-plugins/cloud/microsoft/office365/onedrive/mode/usage.pm index a32af5c53..c138ccc07 100644 --- a/centreon-plugins/cloud/microsoft/office365/onedrive/mode/usage.pm +++ b/centreon-plugins/cloud/microsoft/office365/onedrive/mode/usage.pm @@ -247,7 +247,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-url:s" => { name => 'filter_url' }, "filter-owner:s" => { name => 'filter_owner' }, diff --git a/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/listsites.pm b/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/listsites.pm index 6b6978fb9..75d89a884 100644 --- a/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/listsites.pm +++ b/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/listsites.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-url:s" => { name => 'filter_url' }, diff --git a/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/siteusage.pm b/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/siteusage.pm index d11533150..3fceccbc5 100644 --- a/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/siteusage.pm +++ b/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/siteusage.pm @@ -283,7 +283,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-url:s" => { name => 'filter_url' }, "filter-id:s" => { name => 'filter_id' }, diff --git a/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm b/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm index a4e0eeb53..1c2e7d259 100644 --- a/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm +++ b/centreon-plugins/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm @@ -209,7 +209,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-user:s" => { name => 'filter_user' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/cloud/microsoft/office365/skype/mode/devicesusage.pm b/centreon-plugins/cloud/microsoft/office365/skype/mode/devicesusage.pm index 6c740b8ab..7c69c377e 100644 --- a/centreon-plugins/cloud/microsoft/office365/skype/mode/devicesusage.pm +++ b/centreon-plugins/cloud/microsoft/office365/skype/mode/devicesusage.pm @@ -155,7 +155,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-user:s" => { name => 'filter_user' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/cloud/microsoft/office365/skype/mode/usersactivity.pm b/centreon-plugins/cloud/microsoft/office365/skype/mode/usersactivity.pm index 64650efdb..6ea515c61 100644 --- a/centreon-plugins/cloud/microsoft/office365/skype/mode/usersactivity.pm +++ b/centreon-plugins/cloud/microsoft/office365/skype/mode/usersactivity.pm @@ -173,7 +173,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-user:s" => { name => 'filter_user' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/cloud/microsoft/office365/teams/mode/devicesusage.pm b/centreon-plugins/cloud/microsoft/office365/teams/mode/devicesusage.pm index 48e0607e6..727586d8e 100644 --- a/centreon-plugins/cloud/microsoft/office365/teams/mode/devicesusage.pm +++ b/centreon-plugins/cloud/microsoft/office365/teams/mode/devicesusage.pm @@ -164,7 +164,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-user:s" => { name => 'filter_user' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/cloud/microsoft/office365/teams/mode/usersactivity.pm b/centreon-plugins/cloud/microsoft/office365/teams/mode/usersactivity.pm index 0b88f4706..c08fe6398 100644 --- a/centreon-plugins/cloud/microsoft/office365/teams/mode/usersactivity.pm +++ b/centreon-plugins/cloud/microsoft/office365/teams/mode/usersactivity.pm @@ -191,7 +191,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-user:s" => { name => 'filter_user' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/clusterusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/clusterusage.pm index 47ed893e0..0fcc3132b 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/clusterusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/clusterusage.pm @@ -156,7 +156,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/containerusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/containerusage.pm index 891819d53..1b8b632a2 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/containerusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/containerusage.pm @@ -132,7 +132,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/diskusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/diskusage.pm index 391294653..eba938d2a 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/diskusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/diskusage.pm @@ -165,7 +165,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/hypervisorusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/hypervisorusage.pm index 6098d99cd..607c71624 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/hypervisorusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/hypervisorusage.pm @@ -137,7 +137,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/listcontainers.pm b/centreon-plugins/cloud/nutanix/snmp/mode/listcontainers.pm index cd11e6439..00ce8cc17 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/listcontainers.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/listcontainers.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/listdisks.pm b/centreon-plugins/cloud/nutanix/snmp/mode/listdisks.pm index a5efedc67..3dc5dfdc6 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/listdisks.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/listdisks.pm @@ -41,7 +41,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/listhypervisors.pm b/centreon-plugins/cloud/nutanix/snmp/mode/listhypervisors.pm index 7709a9bfb..b5562c2ca 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/listhypervisors.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/listhypervisors.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/liststoragepools.pm b/centreon-plugins/cloud/nutanix/snmp/mode/liststoragepools.pm index 898f49369..34f5dc42a 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/liststoragepools.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/liststoragepools.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/listvms.pm b/centreon-plugins/cloud/nutanix/snmp/mode/listvms.pm index 1c3fe7f7e..0a8855a1a 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/listvms.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/listvms.pm @@ -36,7 +36,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/storagepoolusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/storagepoolusage.pm index 67fd531d1..592db43ac 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/storagepoolusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/storagepoolusage.pm @@ -132,7 +132,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/vmusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/vmusage.pm index 76ca43f3b..401612b2d 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/vmusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/vmusage.pm @@ -99,7 +99,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/cloud/ovh/restapi/mode/quotausage.pm b/centreon-plugins/cloud/ovh/restapi/mode/quotausage.pm index f6a6ef8ae..291c4fdd8 100644 --- a/centreon-plugins/cloud/ovh/restapi/mode/quotausage.pm +++ b/centreon-plugins/cloud/ovh/restapi/mode/quotausage.pm @@ -114,7 +114,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-service:s" => { name => 'filter_service' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/cloud/ovh/restapi/mode/sms.pm b/centreon-plugins/cloud/ovh/restapi/mode/sms.pm index 48faa7a0f..13a3d093a 100644 --- a/centreon-plugins/cloud/ovh/restapi/mode/sms.pm +++ b/centreon-plugins/cloud/ovh/restapi/mode/sms.pm @@ -51,7 +51,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-service:s" => { name => 'filter_service' }, diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm index ac5a6e3ed..3e75b1fc2 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "container:s" => { name => 'container', default => 'container=~".*"' }, "pod:s" => { name => 'pod', default => 'pod=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm index 097dbc039..d63f91070 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm @@ -134,7 +134,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "daemonset:s" => { name => 'daemonset', default => 'daemonset=~".*"' }, "warning-status:s" => { name => 'warning_status', default => '%{up_to_date} < %{desired}' }, diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm index 014f26375..51281d0f8 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm @@ -117,7 +117,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "deployment:s" => { name => 'deployment', default => 'deployment=~".*"' }, "warning-status:s" => { name => 'warning_status', default => '%{up_to_date} < %{desired}' }, diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listcontainers.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listcontainers.pm index 75d42f8a9..58af5cd91 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listcontainers.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listcontainers.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "container:s" => { name => 'container', default => 'container=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listdaemonsets.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listdaemonsets.pm index b169eb589..2ab111943 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listdaemonsets.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listdaemonsets.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "daemonset:s" => { name => 'daemonset', default => 'daemonset=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listdeployments.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listdeployments.pm index 5a26ce79a..723cb5d65 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listdeployments.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listdeployments.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "deployment:s" => { name => 'deployment', default => 'deployment=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listnamespaces.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listnamespaces.pm index 26212202a..371638475 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listnamespaces.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listnamespaces.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "namespace:s" => { name => 'namespace', default => 'namespace=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listnodes.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listnodes.pm index 74559b6e5..dc094fcff 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listnodes.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listnodes.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "node:s" => { name => 'node', default => 'node=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listservices.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listservices.pm index a0ca97111..625538544 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listservices.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/listservices.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "service:s" => { name => 'service', default => 'service=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/namespacestatus.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/namespacestatus.pm index a156c7fad..70309697d 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/namespacestatus.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/namespacestatus.pm @@ -105,7 +105,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "namespace:s" => { name => 'namespace', default => 'namespace=~".*"' }, "phase:s" => { name => 'phase', default => 'phase=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/nodestatus.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/nodestatus.pm index 46e580ac5..16c415511 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/nodestatus.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/mode/nodestatus.pm @@ -145,7 +145,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "node:s" => { name => 'node', default => 'node=~".*"' }, "warning-status:s" => { name => 'warning_status' }, diff --git a/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/mode/connections.pm b/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/mode/connections.pm index 344675232..37b9cd48a 100644 --- a/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/mode/connections.pm +++ b/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/mode/connections.pm @@ -104,7 +104,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "extra-filter:s@" => { name => 'extra_filter' }, "metric-overload:s@" => { name => 'metric_overload' }, diff --git a/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/mode/requests.pm b/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/mode/requests.pm index ac6814de8..bf8ebe1af 100644 --- a/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/mode/requests.pm +++ b/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/mode/requests.pm @@ -102,7 +102,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "extra-filter:s@" => { name => 'extra_filter' }, "metric-overload:s@" => { name => 'metric_overload' }, diff --git a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/cpu.pm b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/cpu.pm index 517ca82e5..e3949cc90 100644 --- a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/cpu.pm +++ b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/cpu.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "cpu-attribute:s" => { name => 'cpu_attribute', default => 'cpu="total"' }, "container:s" => { name => 'container', default => 'container_name!~".*POD.*"' }, diff --git a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/listcontainers.pm b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/listcontainers.pm index cecc2f798..28dbe7b25 100644 --- a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/listcontainers.pm +++ b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/listcontainers.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "container:s" => { name => 'container', default => 'container_name!~".*POD.*"' }, diff --git a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/load.pm b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/load.pm index 522860d75..76d3ac32d 100644 --- a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/load.pm +++ b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/load.pm @@ -58,7 +58,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "container:s" => { name => 'container', default => 'container_name!~".*POD.*"' }, "pod:s" => { name => 'pod', default => 'pod_name=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/memory.pm b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/memory.pm index a51e6e5bf..6093dcefb 100644 --- a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/memory.pm +++ b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/memory.pm @@ -170,7 +170,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "container:s" => { name => 'container', default => 'container_name!~".*POD.*"' }, "pod:s" => { name => 'pod', default => 'pod_name=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/storage.pm b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/storage.pm index da298a175..a2c92c482 100644 --- a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/storage.pm +++ b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/storage.pm @@ -47,7 +47,7 @@ sub custom_usage_perfdata { value => $value_perf, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options), - min => 0, max => $self->{result_values}->{total} + min => 0, max => $self->{result_values}->{total}, instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, ); } @@ -151,7 +151,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "container:s" => { name => 'container', default => 'container_name!~".*POD.*"' }, "pod:s" => { name => 'pod', default => 'pod_name=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/taskstate.pm b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/taskstate.pm index a72acf48a..bc7be7bc8 100644 --- a/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/taskstate.pm +++ b/centreon-plugins/cloud/prometheus/exporters/cadvisor/mode/taskstate.pm @@ -98,7 +98,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "container:s" => { name => 'container', default => 'container_name!~".*POD.*"' }, "pod:s" => { name => 'pod', default => 'pod_name=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/cpu.pm b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/cpu.pm index 9a07f38d1..a57eb4718 100644 --- a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/cpu.pm +++ b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/cpu.pm @@ -92,7 +92,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s" => { name => 'instance', default => 'instance=~".*"' }, "cpu:s" => { name => 'cpu', default => 'cpu=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/cpudetailed.pm b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/cpudetailed.pm index 6b4097ce2..49cd6acd6 100644 --- a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/cpudetailed.pm +++ b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/cpudetailed.pm @@ -218,7 +218,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s" => { name => 'instance', default => 'instance=~".*"' }, "cpu:s" => { name => 'cpu', default => 'cpu=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/load.pm b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/load.pm index c2847d2ef..d91e1d4ce 100644 --- a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/load.pm +++ b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/load.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s" => { name => 'instance', default => 'instance=~".*"' }, "extra-filter:s@" => { name => 'extra_filter' }, diff --git a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/memory.pm b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/memory.pm index c6c80e3ca..1d0b0d408 100644 --- a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/memory.pm +++ b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/memory.pm @@ -138,7 +138,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s" => { name => 'instance', default => 'instance=~".*"' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/storage.pm b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/storage.pm index 5dcc58c77..c8cfdf840 100644 --- a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/storage.pm +++ b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/mode/storage.pm @@ -47,7 +47,7 @@ sub custom_usage_perfdata { value => $value_perf, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options), - min => 0, max => $self->{result_values}->{total} + min => 0, max => $self->{result_values}->{total}, instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, ); } @@ -151,7 +151,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "instance:s" => { name => 'instance', default => 'instance=~".*"' }, "mountpoint:s" => { name => 'mountpoint', default => 'mountpoint=~".*"' }, diff --git a/centreon-plugins/cloud/prometheus/restapi/mode/expression.pm b/centreon-plugins/cloud/prometheus/restapi/mode/expression.pm index fd88d36d5..1af6d7d0c 100644 --- a/centreon-plugins/cloud/prometheus/restapi/mode/expression.pm +++ b/centreon-plugins/cloud/prometheus/restapi/mode/expression.pm @@ -89,7 +89,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "query:s@" => { name => 'query' }, "query-range:s@" => { name => 'query_range' }, diff --git a/centreon-plugins/cloud/prometheus/restapi/mode/targetstatus.pm b/centreon-plugins/cloud/prometheus/restapi/mode/targetstatus.pm index ea7bd63b4..e48a0be8f 100644 --- a/centreon-plugins/cloud/prometheus/restapi/mode/targetstatus.pm +++ b/centreon-plugins/cloud/prometheus/restapi/mode/targetstatus.pm @@ -131,7 +131,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-label:s@" => { name => 'filter_label' }, "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/custom/api.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/custom/api.pm new file mode 100644 index 000000000..a3d32c093 --- /dev/null +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/custom/api.pm @@ -0,0 +1,451 @@ +# +# Copyright 2019 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 cloud::vmware::velocloud::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use JSON::XS; +use DateTime; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port' }, + "proto:s" => { name => 'proto' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "operator-user" => { name => 'operator_user' }, + "api-path:s" => { name => 'api_path' }, + "timeframe:s" => { name => 'timeframe' }, + "timeout:s" => { name => 'timeout' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; + $self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef; + $self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef; + $self->{api_path} = (defined($self->{option_results}->{api_path})) ? $self->{option_results}->{api_path} : '/portal/rest'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{username}) || $self->{username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --username option."); + $self->{output}->option_exit(); + } + if (!defined($self->{password}) || $self->{password} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --password option."); + $self->{output}->option_exit(); + } + + return 0; +} + +sub get_connection_infos { + my ($self, %options) = @_; + + return $self->{hostname} . '_' . $self->{http}->get_port(); +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{unknown_status} = ''; + $self->{option_results}->{warning_status} = ''; + $self->{option_results}->{critical_status} = ''; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{http}->add_header(key => 'Content-Type', value => 'application/json'); + if (defined($self->{session_cookie})) { + $self->{http}->add_header(key => 'Cookie', value => 'velocloud.session=' . $self->{session_cookie}); + } + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub get_session_cookie { + my ($self, %options) = @_; + + my $form_post = { username => $self->{username}, password => $self->{password} }; + my $encoded; + eval { + $encoded = JSON::XS->new->utf8->encode($form_post); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot encode json request"); + $self->{output}->option_exit(); + } + + $self->settings(); + + my $login_url = (defined($self->{option_results}->{operator_user})) ? '/login/operatorLogin' : '/login/enterpriseLogin'; + my $content = $self->{http}->request( + method => 'POST', + url_path => $self->{api_path} . $login_url, + query_form_post => $encoded + ); + my (@cookies) = $self->{http}->get_header(name => 'Set-Cookie'); + + my $message = ''; + my $session = ''; + + foreach my $cookie (@cookies) { + $message = $1 if ($cookie =~ /^velocloud\.message=(.+?);/); + $session = $1 if ($cookie =~ /^velocloud\.session=(.+?);/); + } + + if (!defined($session) || $session eq '') { + $self->{output}->add_option_msg(short_msg => "Cannot get session cookie: " . $message); + $self->{output}->option_exit(); + } + + $self->{session_cookie} = $session; +} + +sub get_entreprise_id { + my ($self, %options) = @_; + + if (!defined($self->{session_cookie})) { + $self->get_session_cookie(); + } + + $self->settings(); + + my $content = $self->{http}->request( + method => 'POST', + url_path => $self->{api_path} . '/enterprise/getEnterprise' + ); + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); + $self->{output}->option_exit(); + } + + $self->{entreprise_id} = $decoded->{id}; +} + +sub request_api { + my ($self, %options) = @_; + + if (!defined($self->{session_cookie})) { + $self->get_session_cookie(); + } + + $self->settings(); + + my $encoded_form_post; + eval { + $encoded_form_post = JSON::XS->new->utf8->encode($options{query_form_post}); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot encode json request"); + $self->{output}->option_exit(); + } + + $self->{output}->output_add(long_msg => "URL: '" . $self->{proto} . '://' . $self->{hostname} . ':' . + $self->{port} . $self->{api_path} . $options{path} . "'", debug => 1); + + my $content = $self->{http}->request( + method => $options{method}, + url_path => $self->{api_path} . $options{path}, + query_form_post => $encoded_form_post, + critical_status => '', warning_status => '', unknown_status => '' + ); + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); + $self->{output}->option_exit(); + } + if (ref($decoded) ne 'ARRAY' && defined($decoded->{error})) { + $self->{output}->add_option_msg(short_msg => "API returned error code '" . $decoded->{error}->{code} . + "', message '" . $decoded->{error}->{message} . "'"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +sub list_edges { + my ($self, %options) = @_; + + if (!defined($self->{entreprise_id})) { + $self->get_entreprise_id(); + } + + my $response = $self->request_api( + method => 'POST', + path => '/enterprise/getEnterpriseEdges', + query_form_post => { enterpriseId => $self->{entreprise_id} } + ); + + return $response; +} + +sub list_links { + my ($self, %options) = @_; + + if (!defined($self->{entreprise_id})) { + $self->get_entreprise_id(); + } + + my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601.'Z'; + + my $results = $self->request_api( + method => 'POST', + path => '/metrics/getEdgeLinkMetrics', + query_form_post => { + enterpriseId => $self->{entreprise_id}, + edgeId => $options{edge_id}, + metrics => [ 'bytesRx' ], + interval => { + start => $start_time + }, + } + ); + + return $results; +} + +sub get_links_metrics { + my ($self, %options) = @_; + + if (!defined($self->{entreprise_id})) { + $self->get_entreprise_id(); + } + + my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601.'Z'; + + my $results = $self->request_api( + method => 'POST', + path => '/metrics/getEdgeLinkMetrics', + query_form_post => { + enterpriseId => $self->{entreprise_id}, + edgeId => $options{edge_id}, + metrics => [ 'bytesRx', 'bytesTx', 'bestJitterMsRx', 'bestJitterMsTx', + 'bestLatencyMsRx', 'bestLatencyMsTx', 'bestLossPctRx', 'bestLossPctTx' ], + interval => { + start => $start_time + }, + } + ); + + return $results; +} + +sub get_apps_metrics { + my ($self, %options) = @_; + + my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601.'Z'; + + my $results = $self->request_api( + method => 'POST', + path => '/metrics/getEdgeAppMetrics', + query_form_post => { + enterpriseId => $self->{entreprise_id}, + edgeId => $options{edge_id}, + metrics => [ 'bytesRx', 'bytesTx', 'packetsRx', 'packetsTx' ], + interval => { + start => $start_time + }, + } + ); + + return $results; +} + +sub get_links_qoe { + my ($self, %options) = @_; + + my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601.'Z'; + + my $results = $self->request_api( + method => 'POST', + path => '/linkQualityEvent/getLinkQualityEvents', + query_form_post => { + enterpriseId => $self->{entreprise_id}, + edgeId => $options{edge_id}, + debug => 'false', + individualScores => 'false', + maxSamples => '15', + interval => { + start => $start_time + }, + } + ); + + return $results; +} + +sub get_categories_metrics { + my ($self, %options) = @_; + + my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601.'Z'; + + my $results = $self->request_api( + method => 'POST', + path => '/metrics/getEdgeCategoryMetrics', + query_form_post => { + id => $options{edge_id}, + metrics => [ 'bytesRx', 'bytesTx', 'packetsRx', 'packetsTx' ], + interval => { + start => $start_time + }, + } + ); + + return $results; +} + +sub DESTROY { + my $self = shift; + + if (defined($self->{session_cookie})) { + $self->{http}->request(method => 'POST', url_path => $self->{api_path} . '/logout'); + } +} + +1; + +__END__ + +=head1 NAME + +VMware VeloCloud Orchestrator REST API + +=head1 SYNOPSIS + +VMware VeloCloud Orchestrator Rest API custom mode + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +VMware VeloCloud Orchestrator hostname. + +=item B<--port> + +Port used (Default: 443) + +=item B<--proto> + +Specify https if needed (Default: 'https') + +=item B<--username> + +VMware VeloCloud Orchestrator username. + +=item B<--password> + +VMware VeloCloud Orchestrator password. + +=item B<--operator-user> + +Set if the user is an operator. + +=item B<--api-path> + +API base url path (Default: '/portal/rest'). + +=item B<--timeframe> + +Set timeframe in seconds (Default: 900). + +=item B<--timeout> + +Set HTTP timeout in seconds (Default: '10'). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/applicationusage.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/applicationusage.pm new file mode 100644 index 000000000..477719ab3 --- /dev/null +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/applicationusage.pm @@ -0,0 +1,209 @@ +# +# Copyright 2019 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 cloud::vmware::velocloud::restapi::mode::applicationusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'edges', type => 3, cb_prefix_output => 'prefix_edge_output', cb_long_output => 'long_output', + message_multiple => 'All edges applications usage are ok', indent_long_output => ' ', + group => [ + { name => 'apps', display_long => 1, cb_prefix_output => 'prefix_app_output', + message_multiple => 'All applications usage are ok', type => 1 }, + ] + } + ]; + + $self->{maps_counters}->{apps} = [ + { label => 'traffic-in', nlabel => 'application.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in' }, { name => 'display' }, { name => 'id' } ], + output_change_bytes => 2, + output_template => 'Traffic In: %s %s/s', + perfdatas => [ + { value => 'traffic_in_absolute', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1 }, + ], + } + }, + { label => 'traffic-out', nlabel => 'application.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out' }, { name => 'display' }, { name => 'id' } ], + output_change_bytes => 2, + output_template => 'Traffic Out: %s %s/s', + perfdatas => [ + { value => 'traffic_out_absolute', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1 }, + ], + } + }, + { label => 'packets-in', nlabel => 'application.packets.in.persecond', set => { + key_values => [ { name => 'packets_in' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Packets In: %.2f packets/s', + perfdatas => [ + { value => 'packets_in_absolute', template => '%.2f', + min => 0, unit => 'packets/s', label_extra_instance => 1 }, + ], + } + }, + { label => 'packets-out', nlabel => 'application.packets.out.persecond', set => { + key_values => [ { name => 'packets_out' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Packets Out: %.2f packets/s', + perfdatas => [ + { value => 'packets_out_absolute', template => '%.2f', + min => 0, unit => 'packets/s', label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_edge_output { + my ($self, %options) = @_; + + return "Edge '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_app_output { + my ($self, %options) = @_; + + return "Application '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking edge '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-edge-name:s" => { name => 'filter_edge_name' }, + "filter-application-name:s" => { name => 'filter_application_name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{edges} = {}; + + my $results = $options{custom}->list_edges; + + foreach my $edge (@{$results}) { + if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && + $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{name} . "'.", debug => 1); + next; + } + + $self->{edges}->{$edge->{name}}->{id} = $edge->{id}; + $self->{edges}->{$edge->{name}}->{display} = $edge->{name}; + + my $apps = $options{custom}->get_apps_metrics( + edge_id => $edge->{id}, + timeframe => $self->{timeframe} + ); + + foreach my $app (@{$apps}) { + if (defined($self->{option_results}->{filter_application_name}) && + $self->{option_results}->{filter_application_name} ne '' && + $app->{name} !~ /$self->{option_results}->{filter_application_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{id} . "'.", debug => 1); + next; + } + + $self->{edges}->{$edge->{name}}->{apps}->{$app->{name}} = { + id => $app->{application}, + display => $app->{name}, + traffic_out => int($app->{bytesTx} * 8 / $self->{timeframe}), + traffic_in => int($app->{bytesRx} * 8 / $self->{timeframe}), + packets_out => $app->{packetsTx} / $self->{timeframe}, + packets_in => $app->{packetsRx} / $self->{timeframe}, + }; + } + } + + if (scalar(keys %{$self->{edges}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No edge found."); + $self->{output}->option_exit(); + } + foreach (keys %{$self->{edges}}) { + last if (defined($self->{edges}->{$_}->{apps})); + $self->{output}->add_option_msg(short_msg => "No applications found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check applications usage per edges. + +=over 8 + +=item B<--filter-edge-name> + +Filter edge by name (Can be a regexp). + +=item B<--filter-application-name> + +Filter application by name (Can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'traffic-in', 'traffic-out', +'packets-in', 'packets-out'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'traffic-in', 'traffic-out', +'packets-in', 'packets-out'. + +=back + +=cut diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/categoryusage.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/categoryusage.pm new file mode 100644 index 000000000..24d8bb339 --- /dev/null +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/categoryusage.pm @@ -0,0 +1,209 @@ +# +# Copyright 2019 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 cloud::vmware::velocloud::restapi::mode::categoryusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'edges', type => 3, cb_prefix_output => 'prefix_edge_output', cb_long_output => 'long_output', + message_multiple => 'All edges categories usage are ok', indent_long_output => ' ', + group => [ + { name => 'categories', display_long => 1, cb_prefix_output => 'prefix_category_output', + message_multiple => 'All categories usage are ok', type => 1 }, + ] + } + ]; + + $self->{maps_counters}->{categories} = [ + { label => 'traffic-in', nlabel => 'category.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in' }, { name => 'display' }, { name => 'id' } ], + output_change_bytes => 2, + output_template => 'Traffic In: %s %s/s', + perfdatas => [ + { value => 'traffic_in_absolute', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1 }, + ], + } + }, + { label => 'traffic-out', nlabel => 'category.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out' }, { name => 'display' }, { name => 'id' } ], + output_change_bytes => 2, + output_template => 'Traffic Out: %s %s/s', + perfdatas => [ + { value => 'traffic_out_absolute', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1 }, + ], + } + }, + { label => 'packets-in', nlabel => 'category.packets.in.persecond', set => { + key_values => [ { name => 'packets_in' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Packets In: %.2f packets/s', + perfdatas => [ + { value => 'packets_in_absolute', template => '%.2f', + min => 0, unit => 'packets/s', label_extra_instance => 1 }, + ], + } + }, + { label => 'packets-out', nlabel => 'category.packets.out.persecond', set => { + key_values => [ { name => 'packets_out' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Packets Out: %.2f packets/s', + perfdatas => [ + { value => 'packets_out_absolute', template => '%.2f', + min => 0, unit => 'packets/s', label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_edge_output { + my ($self, %options) = @_; + + return "Edge '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_category_output { + my ($self, %options) = @_; + + return "Category '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking edge '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-edge-name:s" => { name => 'filter_edge_name' }, + "filter-category-name:s" => { name => 'filter_category_name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{edges} = {}; + + my $results = $options{custom}->list_edges; + + foreach my $edge (@{$results}) { + if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && + $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{name} . "'.", debug => 1); + next; + } + + $self->{edges}->{$edge->{name}}->{id} = $edge->{id}; + $self->{edges}->{$edge->{name}}->{display} = $edge->{name}; + + my $categories = $options{custom}->get_categories_metrics( + edge_id => $edge->{id}, + timeframe => $self->{timeframe} + ); + + foreach my $category (@{$categories}) { + if (defined($self->{option_results}->{filter_category_name}) && + $self->{option_results}->{filter_category_name} ne '' && + $category->{name} !~ /$self->{option_results}->{filter_category_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{id} . "'.", debug => 1); + next; + } + + $self->{edges}->{$edge->{name}}->{categories}->{$category->{name}} = { + id => $category->{category}, + display => $category->{name}, + traffic_out => int($category->{bytesTx} * 8 / $self->{timeframe}), + traffic_in => int($category->{bytesRx} * 8 / $self->{timeframe}), + packets_out => $category->{packetsTx} / $self->{timeframe}, + packets_in => $category->{packetsRx} / $self->{timeframe}, + }; + } + } + + if (scalar(keys %{$self->{edges}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No edge found."); + $self->{output}->option_exit(); + } + foreach (keys %{$self->{edges}}) { + last if (defined($self->{edges}->{$_}->{categories})); + $self->{output}->add_option_msg(short_msg => "No category found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check categories usage per edges. + +=over 8 + +=item B<--filter-edge-name> + +Filter edge by name (Can be a regexp). + +=item B<--filter-category-name> + +Filter category by name (Can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'traffic-in', 'traffic-out', +'packets-in', 'packets-out'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'traffic-in', 'traffic-out', +'packets-in', 'packets-out'. + +=back + +=cut diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/discovery.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/discovery.pm new file mode 100644 index 000000000..1a37fc48b --- /dev/null +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/discovery.pm @@ -0,0 +1,107 @@ +# +# Copyright 2019 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 cloud::vmware::velocloud::restapi::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $results = $options{custom}->list_edges; + + foreach my $edge (@{$results}) { + my %edge; + $edge{id} = $edge->{id}; + $edge{site_id} = $edge->{siteId}; + $edge{enterprise_id} = $edge->{enterpriseId}; + $edge{activation_state} = $edge->{activationState}; + $edge{model_number} = $edge->{modelNumber}; + $edge{device_family} = $edge->{deviceFamily}; + $edge{name} = $edge->{name}; + $edge{description} = $edge->{description}; + $edge{edge_state} = $edge->{edgeState}; + $edge{service_state} = $edge->{serviceState}; + $edge{ha_state} = $edge->{haState}; + + push @disco_data, \%edge; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Resources discovery. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/edgeqoe.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/edgeqoe.pm new file mode 100644 index 000000000..8cc4a6910 --- /dev/null +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/edgeqoe.pm @@ -0,0 +1,237 @@ +# +# Copyright 2019 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 cloud::vmware::velocloud::restapi::mode::edgeqoe; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'edges', type => 3, cb_prefix_output => 'prefix_edge_output', cb_long_output => 'long_output', + message_multiple => 'All edges links QOE are ok', indent_long_output => ' ', + group => [ + { name => 'global', type => 0 }, + { name => 'links', display_long => 1, cb_prefix_output => 'prefix_link_output', + message_multiple => 'All links QOE are ok', type => 1 }, + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'qoe-voice', nlabel => 'qoe.voice.count', set => { + key_values => [ { name => 'voice' } ], + output_template => 'Voice QOE: %s', + perfdatas => [ + { value => 'voice_absolute', template => '%s', + min => 0, max => 10, label_extra_instance => 1 }, + ], + } + }, + { label => 'qoe-video', nlabel => 'qoe.video.count', set => { + key_values => [ { name => 'video' } ], + output_template => 'Video QOE: %s', + perfdatas => [ + { value => 'video_absolute', template => '%s', + min => 0, max => 10, label_extra_instance => 1 }, + ], + } + }, + { label => 'qoe-transactional', nlabel => 'qoe.transactional.count', set => { + key_values => [ { name => 'transactional' } ], + output_template => 'Transactional QOE: %s', + perfdatas => [ + { value => 'transactional_absolute', template => '%s', + min => 0, max => 10, label_extra_instance => 1 }, + ], + } + }, + ]; + $self->{maps_counters}->{links} = [ + { label => 'qoe-voice', nlabel => 'link.qoe.voice.count', set => { + key_values => [ { name => 'voice' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Voice QOE: %s', + perfdatas => [ + { value => 'voice_absolute', template => '%s', + min => 0, max => 10, label_extra_instance => 1 }, + ], + } + }, + { label => 'qoe-video', nlabel => 'link.qoe.video.count', set => { + key_values => [ { name => 'video' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Video QOE: %s', + perfdatas => [ + { value => 'video_absolute', template => '%s', + min => 0, max => 10, label_extra_instance => 1 }, + ], + } + }, + { label => 'qoe-transactional', nlabel => 'link.qoe.transactional.count', set => { + key_values => [ { name => 'transactional' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Transactional QOE: %s', + perfdatas => [ + { value => 'transactional_absolute', template => '%s', + min => 0, max => 10, label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_edge_output { + my ($self, %options) = @_; + + return "Edge '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_link_output { + my ($self, %options) = @_; + + return "Link '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking edge '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-edge-name:s" => { name => 'filter_edge_name' }, + "filter-link-name:s" => { name => 'filter_link_name' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{edges} = {}; + + my $results = $options{custom}->list_edges; + + foreach my $edge (@{$results}) { + if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && + $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{name} . "'.", debug => 1); + next; + } + + $self->{edges}->{$edge->{name}}->{id} = $edge->{id}; + $self->{edges}->{$edge->{name}}->{display} = $edge->{name}; + + my $links = $options{custom}->list_links( + edge_id => $edge->{id}, + timeframe => $self->{timeframe} + ); + + my $qoes = $options{custom}->get_links_qoe( + edge_id => $edge->{id}, + timeframe => $self->{timeframe} + ); + + next if (ref($qoes) ne 'HASH'); + + $self->{edges}->{$edge->{name}}->{global} = { + voice => $qoes->{overallLinkQuality}->{score}->{0}, + video => $qoes->{overallLinkQuality}->{score}->{1}, + transactional => $qoes->{overallLinkQuality}->{score}->{2}, + }; + + foreach my $link (@{$links}) { + next if (!defined($qoes->{$link->{link}->{internalId}})); + + if (defined($self->{option_results}->{filter_link_name}) && $self->{option_results}->{filter_link_name} ne '' && + $link->{link}->{displayName} !~ /$self->{option_results}->{filter_link_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{id} . "'.", debug => 1); + next; + } + + $self->{edges}->{$edge->{name}}->{links}->{$link->{link}->{displayName}} = { + id => $link->{linkId}, + display => $link->{link}->{displayName}, + voice => $qoes->{$link->{link}->{internalId}}->{score}->{0}, + video => $qoes->{$link->{link}->{internalId}}->{score}->{1}, + transactional => $qoes->{$link->{link}->{internalId}}->{score}->{2}, + }; + } + } + + if (scalar(keys %{$self->{edges}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No edge found."); + $self->{output}->option_exit(); + } + foreach (keys %{$self->{edges}}) { + last if (defined($self->{edges}->{$_}->{links})); + $self->{output}->add_option_msg(short_msg => "No link found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check links QOE before and global QOE after VeloCloud Enhancements. + +=over 8 + +=item B<--filter-edge-name> + +Filter edge by name (Can be a regexp). + +=item B<--filter-link-name> + +Filter link by name (Can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'qoe-voice', 'qoe-video', 'qoe-transactional'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'qoe-voice', 'qoe-video', 'qoe-transactional'. + +=back + +=cut diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/edgestatus.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/edgestatus.pm new file mode 100644 index 000000000..811bca773 --- /dev/null +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/edgestatus.pm @@ -0,0 +1,162 @@ +# +# Copyright 2019 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 cloud::vmware::velocloud::restapi::mode::edgestatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf("State is '%s', Service State is '%s', HA State is '%s', Activation State is '%s'", + $self->{result_values}->{edge_state}, + $self->{result_values}->{service_state}, + $self->{result_values}->{ha_state}, + $self->{result_values}->{activation_state}); +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{edge_state} = $options{new_datas}->{$self->{instance} . '_edge_state'}; + $self->{result_values}->{service_state} = $options{new_datas}->{$self->{instance} . '_service_state'}; + $self->{result_values}->{ha_state} = $options{new_datas}->{$self->{instance} . '_ha_state'}; + $self->{result_values}->{activation_state} = $options{new_datas}->{$self->{instance} . '_activation_state'}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'edges', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All edges status are ok' }, + ]; + + $self->{maps_counters}->{edges} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'edge_state' }, { name => 'service_state' }, { name => 'ha_state' }, + { name => 'activation_state' }, { 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 => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Edge '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{edge_state} =~ /NEVER_ACTIVATED/' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{edge_state} !~ /CONNECTED/ && %{edge_state} !~ /NEVER_ACTIVATED/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{edges} = {}; + + my $results = $options{custom}->list_edges; + + foreach my $edge (@{$results}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $edge->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{name} . "'.", debug => 1); + next; + } + + $self->{edges}->{$edge->{id}} = { + display => $edge->{name}, + edge_state => $edge->{edgeState}, + service_state => $edge->{serviceState}, + ha_state => $edge->{haState}, + activation_state => $edge->{activationState} + } + } + + if (scalar(keys %{$self->{edges}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No edge found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check edge status. + +=over 8 + +=item B<--filter-name> + +Filter edge by name (Can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status (Default: '%{edge_state} =~ /NEVER_ACTIVATED/'). +Can used special variables like: %{edge_state}, %{service_state}, +%{ha_state}, %{activation_state}. + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{edge_state}, %{service_state}, +%{ha_state}, %{activation_state}. + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{edge_state} !~ /CONNECTED/ && %{edge_state} !~ /NEVER_ACTIVATED/'). +Can used special variables like: %{edge_state}, %{service_state}, +%{ha_state}, %{activation_state}. + +=back + +=cut diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/linkstatus.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/linkstatus.pm new file mode 100644 index 000000000..a545a7d38 --- /dev/null +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/linkstatus.pm @@ -0,0 +1,199 @@ +# +# Copyright 2019 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 cloud::vmware::velocloud::restapi::mode::linkstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf("Status is '%s', VPN State is '%s'", + $self->{result_values}->{state}, $self->{result_values}->{vpn_state}); +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{vpn_state} = $options{new_datas}->{$self->{instance} . '_vpn_state'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'edges', type => 3, cb_prefix_output => 'prefix_edge_output', cb_long_output => 'long_output', + message_multiple => 'All edges links status are ok', indent_long_output => ' ', + group => [ + { name => 'links', display_long => 1, cb_prefix_output => 'prefix_link_output', + message_multiple => 'All links status are ok', type => 1 }, + ] + } + ]; + + $self->{maps_counters}->{links} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'vpn_state' }, + { name => 'display' }, { name => 'id' } ], + 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 => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_edge_output { + my ($self, %options) = @_; + + return "Edge '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_link_output { + my ($self, %options) = @_; + + return "Link '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking edge '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-edge-name:s" => { name => 'filter_edge_name' }, + "filter-link-name:s" => { name => 'filter_link_name' }, + "unknown-status:s" => { name => 'unknown_status', default => '' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{state} !~ /STABLE/ || %{vpn_state} !~ /STABLE/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{edges} = {}; + + my $results = $options{custom}->list_edges; + + foreach my $edge (@{$results}) { + if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && + $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{name} . "'.", debug => 1); + next; + } + + $self->{edges}->{$edge->{name}}->{id} = $edge->{id}; + $self->{edges}->{$edge->{name}}->{display} = $edge->{name}; + + my $links = $options{custom}->get_links_metrics( + edge_id => $edge->{id}, + timeframe => $self->{timeframe} + ); + + foreach my $link (@{$links}) { + if (defined($self->{option_results}->{filter_link_name}) && $self->{option_results}->{filter_link_name} ne '' && + $link->{link}->{displayName} !~ /$self->{option_results}->{filter_link_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{id} . "'.", debug => 1); + next; + } + + $self->{edges}->{$edge->{name}}->{links}->{$link->{link}->{displayName}} = { + id => $link->{linkId}, + display => $link->{link}->{displayName}, + state => $link->{link}->{state}, + vpn_state => $link->{link}->{vpnState}, + }; + } + } + + if (scalar(keys %{$self->{edges}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No edge found."); + $self->{output}->option_exit(); + } + foreach (keys %{$self->{edges}}) { + last if (defined($self->{edges}->{$_}->{links})); + $self->{output}->add_option_msg(short_msg => "No link found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check edge links status. + +=over 8 + +=item B<--filter-edge-name> + +Filter edge by name (Can be a regexp). + +=item B<--filter-link-name> + +Filter link by name (Can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{state}, %{vpn_state}. + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{state}, %{vpn_state}. + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{state} !~ /STABLE/ || %{vpn_state} !~ /STABLE/'). +Can used special variables like: %{state}, %{vpn_state}. + +=back + +=cut diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/linkusage.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/linkusage.pm new file mode 100644 index 000000000..c3b5c27c8 --- /dev/null +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/linkusage.pm @@ -0,0 +1,248 @@ +# +# Copyright 2019 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 cloud::vmware::velocloud::restapi::mode::linkusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'edges', type => 3, cb_prefix_output => 'prefix_edge_output', cb_long_output => 'long_output', + message_multiple => 'All edges links usage are ok', indent_long_output => ' ', + group => [ + { name => 'links', display_long => 1, cb_prefix_output => 'prefix_link_output', + message_multiple => 'All links status are ok', type => 1 }, + ] + } + ]; + + $self->{maps_counters}->{links} = [ + { label => 'traffic-in', nlabel => 'link.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in' }, { name => 'display' }, { name => 'id' } ], + output_change_bytes => 2, + output_template => 'Traffic In: %s %s/s', + perfdatas => [ + { value => 'traffic_in_absolute', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1 }, + ], + } + }, + { label => 'traffic-out', nlabel => 'link.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out' }, { name => 'display' }, { name => 'id' } ], + output_change_bytes => 2, + output_template => 'Traffic Out: %s %s/s', + perfdatas => [ + { value => 'traffic_out_absolute', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1 }, + ], + } + }, + { label => 'latency-in', nlabel => 'link.latency.in.milliseconds', set => { + key_values => [ { name => 'latency_in' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Latency In: %.2f ms', + perfdatas => [ + { value => 'latency_in_absolute', template => '%.2f', + min => 0, unit => 'ms', label_extra_instance => 1 }, + ], + } + }, + { label => 'latency-out', nlabel => 'link.latency.out.milliseconds', set => { + key_values => [ { name => 'latency_out' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Latency Out: %.2f ms', + perfdatas => [ + { value => 'latency_out_absolute', template => '%.2f', + min => 0, unit => 'ms', label_extra_instance => 1 }, + ], + } + }, + { label => 'jitter-in', nlabel => 'link.jitter.in.milliseconds', set => { + key_values => [ { name => 'jitter_in' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Jitter In: %.2f ms', + perfdatas => [ + { value => 'jitter_in_absolute', template => '%.2f', + min => 0, unit => 'ms', label_extra_instance => 1 }, + ], + } + }, + { label => 'jitter-out', nlabel => 'link.jitter.out.milliseconds', set => { + key_values => [ { name => 'jitter_out' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Jitter Out: %.2f ms', + perfdatas => [ + { value => 'jitter_out_absolute', template => '%.2f', + min => 0, unit => 'ms', label_extra_instance => 1 }, + ], + } + }, + { label => 'packet-loss-in', nlabel => 'link.packet.loss.in.percentage', set => { + key_values => [ { name => 'packet_loss_in' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Packet Loss In: %.2f%%', + perfdatas => [ + { value => 'packet_loss_in_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1 }, + ], + } + }, + { label => 'packet-loss-out', nlabel => 'link.packet.loss.out.percentage', set => { + key_values => [ { name => 'packet_loss_out' }, { name => 'display' }, { name => 'id' } ], + output_template => 'Packet Loss Out: %.2f%%', + perfdatas => [ + { value => 'packet_loss_out_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_edge_output { + my ($self, %options) = @_; + + return "Edge '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_link_output { + my ($self, %options) = @_; + + return "Link '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking edge '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-edge-name:s" => { name => 'filter_edge_name' }, + "filter-link-name:s" => { name => 'filter_link_name' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{edges} = {}; + + my $results = $options{custom}->list_edges; + + foreach my $edge (@{$results}) { + if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && + $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{name} . "'.", debug => 1); + next; + } + + $self->{edges}->{$edge->{name}}->{id} = $edge->{id}; + $self->{edges}->{$edge->{name}}->{display} = $edge->{name}; + + my $links = $options{custom}->get_links_metrics( + edge_id => $edge->{id}, + timeframe => $self->{timeframe} + ); + + foreach my $link (@{$links}) { + if (defined($self->{option_results}->{filter_link_name}) && $self->{option_results}->{filter_link_name} ne '' && + $link->{link}->{displayName} !~ /$self->{option_results}->{filter_link_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{id} . "'.", debug => 1); + next; + } + + $self->{edges}->{$edge->{name}}->{links}->{$link->{link}->{displayName}} = { + id => $link->{linkId}, + display => $link->{link}->{displayName}, + traffic_out => int($link->{bytesTx} * 8 / $self->{timeframe}), + traffic_in => int($link->{bytesRx} * 8 / $self->{timeframe}), + latency_out => $link->{bestLatencyMsTx}, + latency_in => $link->{bestLatencyMsRx}, + jitter_out => $link->{bestJitterMsTx}, + jitter_in => $link->{bestJitterMsRx}, + packet_loss_out => $link->{bestLossPctTx}, + packet_loss_in => $link->{bestLossPctRx}, + }; + } + } + + if (scalar(keys %{$self->{edges}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No edge found."); + $self->{output}->option_exit(); + } + foreach (keys %{$self->{edges}}) { + last if (defined($self->{edges}->{$_}->{links})); + $self->{output}->add_option_msg(short_msg => "No link found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check links usage per edges. + +=over 8 + +=item B<--filter-edge-name> + +Filter edge by name (Can be a regexp). + +=item B<--filter-link-name> + +Filter link by name (Can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'traffic-in', 'traffic-out', 'latency-in', +'latency-out', 'jitter-in', 'jitter-out', +'packet-loss-in', 'packet-loss-out'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'traffic-in', 'traffic-out', 'latency-in', +'latency-out', 'jitter-in', 'jitter-out', +'packet-loss-in', 'packet-loss-out'. + +=back + +=cut diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/listedges.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/listedges.pm new file mode 100644 index 000000000..99535d4ff --- /dev/null +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/listedges.pm @@ -0,0 +1,103 @@ +# +# Copyright 2019 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 cloud::vmware::velocloud::restapi::mode::listedges; + +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; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{edges} = $options{custom}->list_edges; +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $edge (@{$self->{edges}}) { + $self->{output}->output_add(long_msg => sprintf("[id = %s][name = %s][description = %s][edge_state = %s]" . + "[service_state = %s][ha_state = %s][activation_state = %s]", + $edge->{id}, $edge->{name}, $edge->{description}, $edge->{edgeState}, $edge->{serviceState}, + $edge->{haState}, $edge->{activationState})); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List edges:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['id', 'name', 'description', 'edge_state', 'service_state', + 'ha_state', 'activation_state']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $edge (@{$self->{edges}}) { + $self->{output}->add_disco_entry( + id => $edge->{id}, + name => $edge->{name}, + description => $edge->{description}, + edge_state => $edge->{edgeState}, + service_state => $edge->{serviceState}, + ha_state => $edge->{haState}, + activation_state => $edge->{activationState} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List edges. + +=over 8 + +=back + +=cut + diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/listlinks.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/listlinks.pm new file mode 100644 index 000000000..31afea133 --- /dev/null +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/listlinks.pm @@ -0,0 +1,121 @@ +# +# Copyright 2019 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 cloud::vmware::velocloud::restapi::mode::listlinks; + +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; + + $options{options}->add_options(arguments => { + "filter-edge-name:s" => { name => 'filter_edge_name' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $edges = $options{custom}->list_edges; + + foreach my $edge (@{$edges}) { + if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && + $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $edge->{name} . "'.", debug => 1); + next; + } + my $links = $options{custom}->list_links(edge_id => $edge->{id}); + foreach my $link (@{$links}) { + push @{$self->{links}}, { %{$link}, edgeName => $edge->{name} }; + } + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $link (@{$self->{links}}) { + $self->{output}->output_add(long_msg => sprintf("[id = %s][display_name = %s][name = %s][edge_id = %s]" . + "[edge_name = %s][state = %s][vpn_state = %s]", + $link->{linkId}, $link->{link}->{displayName}, $link->{name}, $link->{link}->{edgeId}, + $link->{edgeName}, $link->{link}->{state}, $link->{link}->{vpnState})); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List links:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['id', 'display_name', 'name', 'edge_id', 'edge_name', 'state', + 'vpn_state']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $link (@{$self->{links}}) { + $self->{output}->add_disco_entry( + id => $link->{linkId}, + display_name => $link->{link}->{displayName}, + name => $link->{name}, + edge_id => $link->{link}->{edgeId}, + edge_name => $link->{edgeName}, + state => $link->{link}->{state}, + vpn_state => $link->{link}->{vpnState} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List links. + +=over 8 + +=item B<--filter-edge-name> + +Filter edge by name (Can be a regexp). + +=back + +=cut + diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/plugin.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/plugin.pm new file mode 100644 index 000000000..a9e9816f0 --- /dev/null +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/plugin.pm @@ -0,0 +1,57 @@ +# +# Copyright 2019 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 cloud::vmware::velocloud::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'application-usage' => 'cloud::vmware::velocloud::restapi::mode::applicationusage', + 'category-usage' => 'cloud::vmware::velocloud::restapi::mode::categoryusage', + 'discovery' => 'cloud::vmware::velocloud::restapi::mode::discovery', + 'edge-qoe' => 'cloud::vmware::velocloud::restapi::mode::edgeqoe', + 'edge-status' => 'cloud::vmware::velocloud::restapi::mode::edgestatus', + 'link-status' => 'cloud::vmware::velocloud::restapi::mode::linkstatus', + 'link-usage' => 'cloud::vmware::velocloud::restapi::mode::linkusage', + 'list-edges' => 'cloud::vmware::velocloud::restapi::mode::listedges', + 'list-links' => 'cloud::vmware::velocloud::restapi::mode::listlinks', + ); + + $self->{custom_modes}{api} = 'cloud::vmware::velocloud::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check VMware VeloCloud through VeloCloud Orchestrator RestAPI. + +=cut diff --git a/centreon-plugins/database/cassandra/jmx/mode/cachesusage.pm b/centreon-plugins/database/cassandra/jmx/mode/cachesusage.pm index 19c939fcb..3f5fb3609 100644 --- a/centreon-plugins/database/cassandra/jmx/mode/cachesusage.pm +++ b/centreon-plugins/database/cassandra/jmx/mode/cachesusage.pm @@ -104,7 +104,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/database/cassandra/jmx/mode/clientrequestsusage.pm b/centreon-plugins/database/cassandra/jmx/mode/clientrequestsusage.pm index 235778e00..1fb2945be 100644 --- a/centreon-plugins/database/cassandra/jmx/mode/clientrequestsusage.pm +++ b/centreon-plugins/database/cassandra/jmx/mode/clientrequestsusage.pm @@ -78,7 +78,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/database/cassandra/jmx/mode/threadpoolsusage.pm b/centreon-plugins/database/cassandra/jmx/mode/threadpoolsusage.pm index c3ac7ed91..8303ee98a 100644 --- a/centreon-plugins/database/cassandra/jmx/mode/threadpoolsusage.pm +++ b/centreon-plugins/database/cassandra/jmx/mode/threadpoolsusage.pm @@ -87,7 +87,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/apps/elasticsearch/restapi/custom/api.pm b/centreon-plugins/database/elasticsearch/restapi/custom/api.pm similarity index 92% rename from centreon-plugins/apps/elasticsearch/restapi/custom/api.pm rename to centreon-plugins/database/elasticsearch/restapi/custom/api.pm index 389f6b76b..ae4b1179c 100644 --- a/centreon-plugins/apps/elasticsearch/restapi/custom/api.pm +++ b/centreon-plugins/database/elasticsearch/restapi/custom/api.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package apps::elasticsearch::restapi::custom::api; +package database::elasticsearch::restapi::custom::api; use strict; use warnings; @@ -107,13 +107,16 @@ sub build_options_for_httplib { my ($self, %options) = @_; $self->{option_results}->{hostname} = $self->{hostname}; - $self->{option_results}->{timeout} = $self->{timeout}; $self->{option_results}->{port} = $self->{port}; $self->{option_results}->{proto} = $self->{proto}; - $self->{option_results}->{credentials} = 1; - $self->{option_results}->{basic} = 1; - $self->{option_results}->{username} = $self->{username}; - $self->{option_results}->{password} = $self->{password}; + $self->{option_results}->{timeout} = $self->{timeout}; + + if (defined($self->{username}) && $self->{username} ne '') { + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{username}; + $self->{option_results}->{password} = $self->{password}; + } } sub settings { @@ -128,8 +131,8 @@ sub get { $self->settings(); - my $response = $self->{http}->request(url_path => $options{path}, - critical_status => '', warning_status => ''); + my $response = $self->{http}->request(url_path => $options{path}, critical_status => '', warning_status => ''); + my $content; eval { $content = JSON::XS->new->utf8->decode($response); diff --git a/centreon-plugins/database/elasticsearch/restapi/mode/clusterstatistics.pm b/centreon-plugins/database/elasticsearch/restapi/mode/clusterstatistics.pm new file mode 100644 index 000000000..42d6bec79 --- /dev/null +++ b/centreon-plugins/database/elasticsearch/restapi/mode/clusterstatistics.pm @@ -0,0 +1,291 @@ +# +# Copyright 2019 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 database::elasticsearch::restapi::mode::clusterstatistics; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + my $msg = "Cluster '" . $self->{result_values}->{display} . "' Status '" . $self->{result_values}->{status} . "'"; + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $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 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { 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 => \&catalog_status_threshold, + } + }, + { label => 'nodes-total', nlabel => 'nodes.total.count', set => { + key_values => [ { name => 'nodes_total' } ], + output_template => 'Nodes: %d', + perfdatas => [ + { value => 'nodes_total_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'nodes-data', nlabel => 'nodes.data.count', display_ok => 0, set => { + key_values => [ { name => 'nodes_data' }, { name => 'nodes_total' } ], + output_template => 'Nodes Data: %d', + perfdatas => [ + { value => 'nodes_data_absolute', template => '%d', + min => 0, max => 'nodes_total_absolute' }, + ], + } + }, + { label => 'nodes-coordinating', nlabel => 'nodes.coordinating.count', display_ok => 0, set => { + key_values => [ { name => 'nodes_coordinating' }, { name => 'nodes_total' } ], + output_template => 'Nodes Coordinating: %d', + perfdatas => [ + { value => 'nodes_coordinating_absolute', template => '%d', + min => 0, max => 'nodes_total_absolute' }, + ], + } + }, + { label => 'nodes-master', nlabel => 'nodes.master.count', display_ok => 0, set => { + key_values => [ { name => 'nodes_master' }, { name => 'nodes_total' } ], + output_template => 'Nodes Master: %d', + perfdatas => [ + { value => 'nodes_master_absolute', template => '%d', + min => 0, max => 'nodes_total_absolute' }, + ], + } + }, + { label => 'nodes-ingest', nlabel => 'nodes.ingest.count', display_ok => 0, set => { + key_values => [ { name => 'nodes_ingest' }, { name => 'nodes_total' } ], + output_template => 'Nodes Ingest: %d', + perfdatas => [ + { value => 'nodes_ingest_absolute', template => '%d', + min => 0, max => 'nodes_total_absolute' }, + ], + } + }, + { label => 'indices-total', nlabel => 'indices.total.count', set => { + key_values => [ { name => 'indices_count' } ], + output_template => 'Indices: %d', + perfdatas => [ + { value => 'indices_count_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'shards-total', nlabel => 'shards.total.count', set => { + key_values => [ { name => 'shards_total' } ], + output_template => 'Shards: %d', + perfdatas => [ + { value => 'shards_total_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'shards-active-count', nlabel => 'shards.active.count', display_ok => 0, set => { + key_values => [ { name => 'shards_active' } ], + output_template => 'Shards Active: %d', + perfdatas => [ + { value => 'shards_active_absolute', template => '%d', + min => 0, max => 'shards_total_absolute' }, + ], + } + }, + { label => 'shards-active-percentage', nlabel => 'shards.active.percentage', display_ok => 0, set => { + key_values => [ { name => 'active_shards_percent' } ], + output_template => 'Shards Active: %.2f%%', + perfdatas => [ + { value => 'active_shards_percent_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'shards-unassigned', nlabel => 'shards.unassigned.count', set => { + key_values => [ { name => 'shards_unassigned' }, { name => 'shards_total' } ], + output_template => 'Shards Unassigned: %d', + perfdatas => [ + { value => 'shards_unassigned_absolute', template => '%d', + min => 0, max => 'shards_total_absolute' }, + ], + } + }, + { label => 'shards-relocating', nlabel => 'shards.relocating.count', display_ok => 0, set => { + key_values => [ { name => 'shards_relocating' }, { name => 'shards_total' } ], + output_template => 'Shards Relocating: %d', + perfdatas => [ + { value => 'shards_relocating_absolute', template => '%d', + min => 0, max => 'shards_total_absolute' }, + ], + } + }, + { label => 'shards-initializing', nlabel => 'shards.initializing.count', display_ok => 0, set => { + key_values => [ { name => 'shards_initializing' }, { name => 'shards_total' } ], + output_template => 'Shards Initializing: %d', + perfdatas => [ + { value => 'shards_initializing_absolute', template => '%d', + min => 0, max => 'shards_total_absolute' }, + ], + } + }, + { label => 'tasks-pending', nlabel => 'tasks.pending.count', set => { + key_values => [ { name => 'tasks_pending' } ], + output_template => 'Tasks Pending: %d', + perfdatas => [ + { value => 'tasks_pending_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'documents-total', nlabel => 'documents.total.count', set => { + key_values => [ { name => 'docs_count' } ], + output_template => 'Documents: %d', + perfdatas => [ + { value => 'docs_count_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'data-size', nlabel => 'data.size.bytes', set => { + key_values => [ { name => 'size_in_bytes' } ], + output_template => 'Data: %s%s', + output_change_bytes => 1, + perfdatas => [ + { value => 'size_in_bytes_absolute', template => '%s', + min => 0, unit => 'B' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /yellow/i' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /red/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $cluster_health = $options{custom}->get(path => '/_cluster/health'); + my $cluster_stats = $options{custom}->get(path => '/_cluster/stats'); + + $self->{global} = { + display => $cluster_stats->{cluster_name}, + status => $cluster_stats->{status}, + nodes_total => $cluster_stats->{nodes}->{count}->{total}, + nodes_data => $cluster_stats->{nodes}->{count}->{data}, + nodes_coordinating => $cluster_stats->{nodes}->{count}->{coordinating_only}, + nodes_master => $cluster_stats->{nodes}->{count}->{master}, + nodes_ingest => $cluster_stats->{nodes}->{count}->{ingest}, + indices_count => $cluster_stats->{indices}->{count}, + shards_total => $cluster_stats->{indices}->{shards}->{total}, + shards_active => $cluster_health->{active_shards}, + shards_unassigned => $cluster_health->{unassigned_shards}, + shards_relocating => $cluster_health->{relocating_shards}, + shards_initializing => $cluster_health->{initializing_shards}, + active_shards_percent => $cluster_health->{active_shards_percent_as_number}, + tasks_pending => $cluster_health->{number_of_pending_tasks}, + docs_count => $cluster_stats->{indices}->{docs}->{count}, + size_in_bytes => $cluster_stats->{indices}->{store}->{size_in_bytes}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check cluster statistics. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^status$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'nodes-total', 'nodes-data', 'nodes-coordinating', +'nodes-master', 'nodes-ingest', 'indices-total', 'shards-total', +'shards-active-count', 'shards-active-percentage', +'shards-unassigned', 'shards-relocating', 'shards-initializing', +'tasks-pending', 'documents-total', 'data-size'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'nodes-total', 'nodes-data', 'nodes-coordinating', +'nodes-master', 'nodes-ingest', 'indices-total', 'shards-total', +'shards-active-count', 'shards-active-percentage', +'shards-unassigned', 'shards-relocating', 'shards-initializing', +'tasks-pending', 'documents-total', 'data-size'. + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /yellow/i') +Can used special variables like: %{status}. + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /red/i'). +Can used special variables like: %{status}. + +=back + +=cut diff --git a/centreon-plugins/apps/elasticsearch/restapi/mode/indices.pm b/centreon-plugins/database/elasticsearch/restapi/mode/indicestatistics.pm similarity index 53% rename from centreon-plugins/apps/elasticsearch/restapi/mode/indices.pm rename to centreon-plugins/database/elasticsearch/restapi/mode/indicestatistics.pm index c73510614..a2f897818 100644 --- a/centreon-plugins/apps/elasticsearch/restapi/mode/indices.pm +++ b/centreon-plugins/database/elasticsearch/restapi/mode/indicestatistics.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package apps::elasticsearch::restapi::mode::indices; +package database::elasticsearch::restapi::mode::indicestatistics; use base qw(centreon::plugins::templates::counter); @@ -28,9 +28,8 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{status}; - return $msg; + return "Status '" . $self->{result_values}->{status} . "'"; } sub custom_status_calc { @@ -57,20 +56,49 @@ sub set_counters { closure_custom_threshold_check => \&catalog_status_threshold, } }, - { label => 'active-primary-shards', set => { - key_values => [ { name => 'active_primary_shards' }, { name => 'display' } ], - output_template => 'Active Primary Shards : %s', + { label => 'documents-total', nlabel => 'indice.documents.total.count', set => { + key_values => [ { name => 'docs_count' }, { name => 'display' } ], + output_template => 'Documents: %d', perfdatas => [ - { label => 'active_primary_shards', value => 'active_primary_shards_absolute', template => '%s', + { value => 'docs_count_absolute', template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, - { label => 'active-shards', set => { - key_values => [ { name => 'active_shards' }, { name => 'display' } ], - output_template => 'Active Shards : %s', + { label => 'data-size-primaries', nlabel => 'indice.data.primaries.size.bytes', set => { + key_values => [ { name => 'size_in_bytes_primaries' }, { name => 'display' } ], + output_template => 'Data Primaries: %s%s', + output_change_bytes => 1, perfdatas => [ - { label => 'active_shards', value => 'active_shards_absolute', template => '%s', + { value => 'size_in_bytes_primaries_absolute', template => '%s', + min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'data-size-total', nlabel => 'indice.data.total.size.bytes', set => { + key_values => [ { name => 'size_in_bytes_total' }, { name => 'display' } ], + output_template => 'Data Total: %s%s', + output_change_bytes => 1, + perfdatas => [ + { value => 'size_in_bytes_total_absolute', template => '%s', + min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'shards-active', nlabel => 'shards.active.count', set => { + key_values => [ { name => 'shards_active' }, { name => 'display' } ], + output_template => 'Shards Active: %d', + perfdatas => [ + { value => 'shards_active_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'shards-unassigned', nlabel => 'shards.unassigned.count', set => { + key_values => [ { name => 'shards_unassigned' }, { name => 'display' } ], + output_template => 'Shards Unassigned: %d', + perfdatas => [ + { value => 'shards_unassigned_absolute', template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } @@ -80,17 +108,14 @@ sub set_counters { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "elastic-path:s" => { name => 'elastic_path', default => '/_cluster/health?level=indices' }, - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /yellow/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /red/i' }, - }); + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /yellow/i' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /red/i' }, + }); return $self; } @@ -108,23 +133,15 @@ sub prefix_indices_output { return "Indices '" . $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; - } - } -} - sub manage_selection { my ($self, %options) = @_; - + $self->{indices} = {}; - my $result = $options{custom}->get(path => $self->{option_results}->{elastic_path}); + + my $indices = $options{custom}->get(path => '/_cluster/health?level=indices'); + my $stats = $options{custom}->get(path => '/_stats'); - foreach my $indice (keys %{$result->{indices}}) { + foreach my $indice (keys %{$indices->{indices}}) { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $indice !~ /$self->{option_results}->{filter_name}/) { $self->{output}->output_add(long_msg => "skipping '" . $indice . "': no matching filter.", debug => 1); @@ -133,9 +150,12 @@ sub manage_selection { $self->{indices}->{$indice} = { display => $indice, - status => $result->{indices}->{$indice}->{status}, - active_primary_shards => $result->{indices}->{$indice}->{active_primary_shards}, - active_shards => $result->{indices}->{$indice}->{active_shards}, + status => $indices->{indices}->{$indice}->{status}, + shards_active => $indices->{indices}->{$indice}->{active_shards}, + shards_unassigned => $indices->{indices}->{$indice}->{unassigned_shards}, + docs_count => $stats->{indices}->{$indice}->{primaries}->{docs}->{count}, + size_in_bytes_primaries => $stats->{indices}->{$indice}->{primaries}->{store}->{size_in_bytes}, + size_in_bytes_total => $stats->{indices}->{$indice}->{total}->{store}->{size_in_bytes}, }; } @@ -151,14 +171,10 @@ __END__ =head1 MODE -Check Elasticsearch indices. +Check indices statistics. =over 8 -=item B<--elastic-path> - -Set path to get Elasticsearch information (Default: '/_cluster/health?level=indices') - =item B<--filter-name> Filter name (can be a regexp). @@ -171,12 +187,14 @@ Example: --filter-counters='^status$' =item B<--warning-*> Threshold warning. -Can be: 'active-primary-shards', 'active-shards'. +Can be: 'documents-total', 'data-size-primaries', +'data-size-total', 'shards-active', 'shards-unassigned'. =item B<--critical-*> Threshold critical. -Can be: 'active-primary-shards', 'active-shards'. +Can be: 'documents-total', 'data-size-primaries', +'data-size-total', 'shards-active', 'shards-unassigned'. =item B<--warning-status> diff --git a/centreon-plugins/database/elasticsearch/restapi/mode/license.pm b/centreon-plugins/database/elasticsearch/restapi/mode/license.pm new file mode 100644 index 000000000..ea67d2d64 --- /dev/null +++ b/centreon-plugins/database/elasticsearch/restapi/mode/license.pm @@ -0,0 +1,125 @@ +# +# Copyright 2019 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 database::elasticsearch::restapi::mode::license; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + my $msg = sprintf("License Status '%s' [type: %s] [issued to: %s] [issue date: %s]", + $self->{result_values}->{status}, + $self->{result_values}->{type}, + $self->{result_values}->{issued_to}, + $self->{result_values}->{issue_date}); + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; + $self->{result_values}->{issued_to} = $options{new_datas}->{$self->{instance} . '_issued_to'}; + $self->{result_values}->{issue_date} = $options{new_datas}->{$self->{instance} . '_issue_date'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'type' }, { name => 'issued_to' }, + { name => 'issue_date' } ], + 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 => \&catalog_status_threshold, + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /active/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->get(path => '/_license'); + + $self->{global} = { + type => $result->{license}->{type}, + status => $result->{license}->{status}, + issued_to => $result->{license}->{issued_to}, + issue_date => $result->{license}->{issue_date}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check license. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status (Default: '') +Can used special variables like: %{status}, %{type}, %{issued_to}. + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /active/i'). +Can used special variables like: %{status}, %{type}, %{issued_to}. + +=back + +=cut diff --git a/centreon-plugins/database/elasticsearch/restapi/mode/listindices.pm b/centreon-plugins/database/elasticsearch/restapi/mode/listindices.pm new file mode 100644 index 000000000..e684f433a --- /dev/null +++ b/centreon-plugins/database/elasticsearch/restapi/mode/listindices.pm @@ -0,0 +1,97 @@ +# +# Copyright 2019 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 database::elasticsearch::restapi::mode::listindices; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{results} = $options{custom}->get(path => '/_cluster/health?level=indices'); +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + + foreach my $indice (keys %{$self->{results}->{indices}}) { + $self->{output}->output_add(long_msg => sprintf("[name = %s][status = %s]", + $indice, + $self->{results}->{indices}->{$indice}->{status}) + ); + } + $self->{output}->output_add(severity => 'OK', + short_msg => "List indices:"); + + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $indice (keys %{$self->{results}->{indices}}) { + $self->{output}->add_disco_entry( + name => $indice, + status => $self->{results}->{indices}->{$indice}->{status} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List indices + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/database/elasticsearch/restapi/mode/listnodes.pm b/centreon-plugins/database/elasticsearch/restapi/mode/listnodes.pm new file mode 100644 index 000000000..ad876fdf5 --- /dev/null +++ b/centreon-plugins/database/elasticsearch/restapi/mode/listnodes.pm @@ -0,0 +1,99 @@ +# +# Copyright 2019 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 database::elasticsearch::restapi::mode::listnodes; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{results} = $options{custom}->get(path => '/_nodes/stats'); +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + + foreach my $node (keys %{$self->{results}->{nodes}}) { + $self->{output}->output_add(long_msg => sprintf("[name = %s][host = %s][ip = %s]", + $self->{results}->{nodes}->{$node}->{name}, + $self->{results}->{nodes}->{$node}->{host}, + $self->{results}->{nodes}->{$node}->{ip}) + ); + } + $self->{output}->output_add(severity => 'OK', + short_msg => "List nodes:"); + + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'host', 'ip']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $node (keys %{$self->{results}->{nodes}}) { + $self->{output}->add_disco_entry( + name => $self->{results}->{nodes}->{$node}->{name}, + host => $self->{results}->{nodes}->{$node}->{host}, + ip => $self->{results}->{nodes}->{$node}->{ip} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List nodes + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/database/elasticsearch/restapi/mode/nodestatistics.pm b/centreon-plugins/database/elasticsearch/restapi/mode/nodestatistics.pm new file mode 100644 index 000000000..14dc382c3 --- /dev/null +++ b/centreon-plugins/database/elasticsearch/restapi/mode/nodestatistics.pm @@ -0,0 +1,175 @@ +# +# Copyright 2019 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 database::elasticsearch::restapi::mode::nodestatistics; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'nodes', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All nodes are ok' }, + ]; + + $self->{maps_counters}->{nodes} = [ + { label => 'jvm-heap-usage', nlabel => 'node.jvm.heap.usage.percentage', set => { + key_values => [ { name => 'heap_used_percent' }, { name => 'display' } ], + output_template => 'JVM Heap: %d%%', + perfdatas => [ + { value => 'heap_used_percent_absolute', template => '%d', + min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'jvm-heap-usage-bytes', nlabel => 'node.jvm.heap.usage.bytes', display_ok => 0, set => { + key_values => [ { name => 'heap_used_in_bytes' }, { name => 'heap_max_in_bytes' }, { name => 'display' } ], + output_template => 'JVM Heap Bytes: %s%s', + output_change_bytes => 1, + perfdatas => [ + { value => 'heap_used_in_bytes_absolute', template => '%s', + min => 0, max => 'heap_max_in_bytes_absolute', unit => 'B', label_extra_instance => 1, + instance_use => 'display_absolute' }, + ], + } + }, + { label => 'disk-free', nlabel => 'node.disk.free.bytes', set => { + key_values => [ { name => 'available_in_bytes' }, { name => 'total_in_bytes' }, + { name => 'display' } ], + output_template => 'Free Disk Space: %s%s', + output_change_bytes => 1, + perfdatas => [ + { value => 'available_in_bytes_absolute', template => '%s', + min => 0, max => 'total_in_bytes_absolute', unit => 'B', + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'documents-total', nlabel => 'node.documents.total.count', set => { + key_values => [ { name => 'docs_count' }, { name => 'display' } ], + output_template => 'Documents: %d', + perfdatas => [ + { value => 'docs_count_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'data-size', nlabel => 'node.data.size.bytes', set => { + key_values => [ { name => 'size_in_bytes' }, { name => 'display' } ], + output_template => 'Data: %s%s', + output_change_bytes => 1, + perfdatas => [ + { value => 'size_in_bytes_absolute', template => '%s', + min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Node '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{nodes} = {}; + + my $nodes_stats = $options{custom}->get(path => '/_nodes/stats'); + + foreach my $node (keys %{$nodes_stats->{nodes}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $node !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $node . "': no matching filter.", debug => 1); + next; + } + + $self->{nodes}->{$node} = { + display => $nodes_stats->{nodes}->{$node}->{name}, + indices_count => $nodes_stats->{indices}->{count}, + heap_used_percent => $nodes_stats->{nodes}->{$node}->{jvm}->{mem}->{heap_used_percent}, + heap_used_in_bytes => $nodes_stats->{nodes}->{$node}->{jvm}->{mem}->{heap_used_in_bytes}, + heap_max_in_bytes => $nodes_stats->{nodes}->{$node}->{jvm}->{mem}->{heap_max_in_bytes}, + available_in_bytes => $nodes_stats->{nodes}->{$node}->{fs}->{total}->{available_in_bytes}, + total_in_bytes => $nodes_stats->{nodes}->{$node}->{fs}->{total}->{total_in_bytes}, + docs_count => $nodes_stats->{nodes}->{$node}->{indices}->{docs}->{count}, + size_in_bytes => $nodes_stats->{nodes}->{$node}->{indices}->{store}->{size_in_bytes}, + }; + } + + if (scalar(keys %{$self->{nodes}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No nodes found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check nodes statistics. + +=over 8 + +=item B<--filter-name> + +Filter name (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='heap' + +=item B<--warning-*> + +Threshold warning. +Can be: 'jvm-heap-usage', 'disk-free', +'documents-total', 'data-size'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'jvm-heap-usage', 'disk-free', +'documents-total', 'data-size'. + +=back + +=cut diff --git a/centreon-plugins/database/elasticsearch/restapi/plugin.pm b/centreon-plugins/database/elasticsearch/restapi/plugin.pm new file mode 100644 index 000000000..f9335dc07 --- /dev/null +++ b/centreon-plugins/database/elasticsearch/restapi/plugin.pm @@ -0,0 +1,53 @@ +# +# Copyright 2019 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 database::elasticsearch::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'cluster-statistics' => 'database::elasticsearch::restapi::mode::clusterstatistics', + 'indice-statistics' => 'database::elasticsearch::restapi::mode::indicestatistics', + 'license' => 'database::elasticsearch::restapi::mode::license', + 'list-indices' => 'database::elasticsearch::restapi::mode::listindices', + 'list-nodes' => 'database::elasticsearch::restapi::mode::listnodes', + 'node-statistics' => 'database::elasticsearch::restapi::mode::nodestatistics', + ); + $self->{custom_modes}{api} = 'database::elasticsearch::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Elasticsearch through HTTP/REST API. + +=cut diff --git a/centreon-plugins/database/firebird/mode/longqueries.pm b/centreon-plugins/database/firebird/mode/longqueries.pm index ba6ffb85b..0901c6a6a 100644 --- a/centreon-plugins/database/firebird/mode/longqueries.pm +++ b/centreon-plugins/database/firebird/mode/longqueries.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/firebird/mode/memory.pm b/centreon-plugins/database/firebird/mode/memory.pm index 30fdfcd09..9ccf098f6 100644 --- a/centreon-plugins/database/firebird/mode/memory.pm +++ b/centreon-plugins/database/firebird/mode/memory.pm @@ -152,7 +152,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/database/firebird/mode/pages.pm b/centreon-plugins/database/firebird/mode/pages.pm index 76724f6f1..6a8c7ba2b 100644 --- a/centreon-plugins/database/firebird/mode/pages.pm +++ b/centreon-plugins/database/firebird/mode/pages.pm @@ -88,7 +88,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/database/firebird/mode/queries.pm b/centreon-plugins/database/firebird/mode/queries.pm index a1523de21..e481ea86f 100644 --- a/centreon-plugins/database/firebird/mode/queries.pm +++ b/centreon-plugins/database/firebird/mode/queries.pm @@ -128,7 +128,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/database/firebird/mode/users.pm b/centreon-plugins/database/firebird/mode/users.pm index 4a4190e1d..e3325e70d 100644 --- a/centreon-plugins/database/firebird/mode/users.pm +++ b/centreon-plugins/database/firebird/mode/users.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/influxdb/custom/api.pm b/centreon-plugins/database/influxdb/custom/api.pm index 7ff97275c..21fe4f5c4 100644 --- a/centreon-plugins/database/influxdb/custom/api.pm +++ b/centreon-plugins/database/influxdb/custom/api.pm @@ -47,8 +47,6 @@ sub new { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port' }, "proto:s" => { name => 'proto' }, - "credentials" => { name => 'credentials' }, - "basic" => { name => 'basic' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "timeout:s" => { name => 'timeout' }, @@ -94,8 +92,6 @@ sub check_options { $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; $self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef; $self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef; - $self->{credentials} = (defined($self->{option_results}->{credentials})) ? 1 : undef; - $self->{basic} = (defined($self->{option_results}->{basic})) ? 1 : undef; if (!defined($self->{hostname}) || $self->{hostname} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); @@ -120,13 +116,19 @@ sub build_options_for_httplib { my ($self, %options) = @_; $self->{option_results}->{hostname} = $self->{hostname}; - $self->{option_results}->{timeout} = $self->{timeout}; $self->{option_results}->{port} = $self->{port}; $self->{option_results}->{proto} = $self->{proto}; $self->{option_results}->{timeout} = $self->{timeout}; $self->{option_results}->{warning_status} = ''; $self->{option_results}->{critical_status} = ''; $self->{option_results}->{unknown_status} = '%{http_code} < 200 or %{http_code} >= 300'; + + if (defined($self->{username}) && $self->{username} ne '') { + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{username}; + $self->{option_results}->{password} = $self->{password}; + } } sub settings { @@ -242,25 +244,13 @@ Port used (Default: 8086) Specify https if needed (Default: 'http') -=item B<--credentials> - -Specify this option if you access webpage with authentication - =item B<--username> -Specify username for authentication (Mandatory if --credentials is specified) +Specify username for authentication. =item B<--password> -Specify password for authentication (Mandatory if --credentials is specified) - -=item B<--basic> - -Specify this option if you access webpage over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your webserver. - -Specify this option if you access webpage over hidden basic authentication or you'll get a '404 NOT FOUND' error. - -(Use with --credentials) +Specify password for authentication. =item B<--timeout> diff --git a/centreon-plugins/database/influxdb/mode/connectiontime.pm b/centreon-plugins/database/influxdb/mode/connectiontime.pm index efd36be24..ae3f8e23e 100644 --- a/centreon-plugins/database/influxdb/mode/connectiontime.pm +++ b/centreon-plugins/database/influxdb/mode/connectiontime.pm @@ -51,7 +51,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; @@ -84,11 +83,11 @@ Check database connection time. =over 8 -=item B<--warning-connection-time-milliseconds> +=item B<--warning-connection-time> Threshold warning in milliseconds. -=item B<--critical-connection-time-milliseconds>> +=item B<--critical-connection-time> Threshold critical in milliseconds. diff --git a/centreon-plugins/database/influxdb/mode/databasestatistics.pm b/centreon-plugins/database/influxdb/mode/databasestatistics.pm index ce5c5e481..7d1e987e7 100644 --- a/centreon-plugins/database/influxdb/mode/databasestatistics.pm +++ b/centreon-plugins/database/influxdb/mode/databasestatistics.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-database:s" => { name => 'filter_database' }, }); diff --git a/centreon-plugins/database/influxdb/mode/httpserverstatistics.pm b/centreon-plugins/database/influxdb/mode/httpserverstatistics.pm index 9952b8e88..a17b399ca 100644 --- a/centreon-plugins/database/influxdb/mode/httpserverstatistics.pm +++ b/centreon-plugins/database/influxdb/mode/httpserverstatistics.pm @@ -132,7 +132,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/database/influxdb/mode/listdatabases.pm b/centreon-plugins/database/influxdb/mode/listdatabases.pm index 73c5686d0..fc7d0359d 100644 --- a/centreon-plugins/database/influxdb/mode/listdatabases.pm +++ b/centreon-plugins/database/influxdb/mode/listdatabases.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/database/influxdb/mode/query.pm b/centreon-plugins/database/influxdb/mode/query.pm index 0ea3379c7..e0b774df6 100644 --- a/centreon-plugins/database/influxdb/mode/query.pm +++ b/centreon-plugins/database/influxdb/mode/query.pm @@ -89,7 +89,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "query:s@" => { name => 'query' }, "instance:s" => { name => 'instance' }, diff --git a/centreon-plugins/database/influxdb/mode/writestatistics.pm b/centreon-plugins/database/influxdb/mode/writestatistics.pm index bbc6be578..8df01a94c 100644 --- a/centreon-plugins/database/influxdb/mode/writestatistics.pm +++ b/centreon-plugins/database/influxdb/mode/writestatistics.pm @@ -87,7 +87,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/database/informix/snmp/mode/archivelevel0.pm b/centreon-plugins/database/informix/snmp/mode/archivelevel0.pm index 03ecb3b45..b265efff5 100644 --- a/centreon-plugins/database/informix/snmp/mode/archivelevel0.pm +++ b/centreon-plugins/database/informix/snmp/mode/archivelevel0.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "timezone:s" => { name => 'timezone' }, diff --git a/centreon-plugins/database/informix/snmp/mode/chunkstatus.pm b/centreon-plugins/database/informix/snmp/mode/chunkstatus.pm index 94cc99ea5..d9d046594 100644 --- a/centreon-plugins/database/informix/snmp/mode/chunkstatus.pm +++ b/centreon-plugins/database/informix/snmp/mode/chunkstatus.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "unknown-status:s" => { name => 'unknown_status' }, diff --git a/centreon-plugins/database/informix/snmp/mode/dbspaceusage.pm b/centreon-plugins/database/informix/snmp/mode/dbspaceusage.pm index 2e5a7774f..5273b79e8 100644 --- a/centreon-plugins/database/informix/snmp/mode/dbspaceusage.pm +++ b/centreon-plugins/database/informix/snmp/mode/dbspaceusage.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/database/informix/snmp/mode/globalcache.pm b/centreon-plugins/database/informix/snmp/mode/globalcache.pm index 490ded242..60b02cab0 100644 --- a/centreon-plugins/database/informix/snmp/mode/globalcache.pm +++ b/centreon-plugins/database/informix/snmp/mode/globalcache.pm @@ -82,7 +82,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/informix/snmp/mode/listdbspaces.pm b/centreon-plugins/database/informix/snmp/mode/listdbspaces.pm index 5b4f9774e..798389b09 100644 --- a/centreon-plugins/database/informix/snmp/mode/listdbspaces.pm +++ b/centreon-plugins/database/informix/snmp/mode/listdbspaces.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-instance:s" => { name => 'filter_instance' }, "filter-dbspace:s" => { name => 'filter_dbspace' }, diff --git a/centreon-plugins/database/informix/snmp/mode/listinstances.pm b/centreon-plugins/database/informix/snmp/mode/listinstances.pm index 0a2b46736..1d6dea38d 100644 --- a/centreon-plugins/database/informix/snmp/mode/listinstances.pm +++ b/centreon-plugins/database/informix/snmp/mode/listinstances.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-instance:s" => { name => 'filter_instance' }, }); diff --git a/centreon-plugins/database/informix/snmp/mode/lockstats.pm b/centreon-plugins/database/informix/snmp/mode/lockstats.pm index dd5706fc6..6decbbc4b 100644 --- a/centreon-plugins/database/informix/snmp/mode/lockstats.pm +++ b/centreon-plugins/database/informix/snmp/mode/lockstats.pm @@ -84,7 +84,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/informix/snmp/mode/logfileusage.pm b/centreon-plugins/database/informix/snmp/mode/logfileusage.pm index d7f68160e..527bef0f5 100644 --- a/centreon-plugins/database/informix/snmp/mode/logfileusage.pm +++ b/centreon-plugins/database/informix/snmp/mode/logfileusage.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/database/informix/snmp/mode/sessions.pm b/centreon-plugins/database/informix/snmp/mode/sessions.pm index c14682bdd..435d60e2c 100644 --- a/centreon-plugins/database/informix/snmp/mode/sessions.pm +++ b/centreon-plugins/database/informix/snmp/mode/sessions.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/informix/sql/mode/archivelevel0.pm b/centreon-plugins/database/informix/sql/mode/archivelevel0.pm index 934912976..489917cc1 100644 --- a/centreon-plugins/database/informix/sql/mode/archivelevel0.pm +++ b/centreon-plugins/database/informix/sql/mode/archivelevel0.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/informix/sql/mode/checkpoints.pm b/centreon-plugins/database/informix/sql/mode/checkpoints.pm index 4fc7e7cc1..28c159d70 100644 --- a/centreon-plugins/database/informix/sql/mode/checkpoints.pm +++ b/centreon-plugins/database/informix/sql/mode/checkpoints.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-cp:s" => { name => 'warning_cp', }, diff --git a/centreon-plugins/database/informix/sql/mode/chunkstates.pm b/centreon-plugins/database/informix/sql/mode/chunkstates.pm index 287cb6989..1f1344e41 100644 --- a/centreon-plugins/database/informix/sql/mode/chunkstates.pm +++ b/centreon-plugins/database/informix/sql/mode/chunkstates.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/informix/sql/mode/dbspacesusage.pm b/centreon-plugins/database/informix/sql/mode/dbspacesusage.pm index fcabe13dd..2c0f5d4b1 100644 --- a/centreon-plugins/database/informix/sql/mode/dbspacesusage.pm +++ b/centreon-plugins/database/informix/sql/mode/dbspacesusage.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/informix/sql/mode/globalcache.pm b/centreon-plugins/database/informix/sql/mode/globalcache.pm index 9b4d9e55e..6107c2dd7 100644 --- a/centreon-plugins/database/informix/sql/mode/globalcache.pm +++ b/centreon-plugins/database/informix/sql/mode/globalcache.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-read:s" => { name => 'warning_read', }, diff --git a/centreon-plugins/database/informix/sql/mode/listdatabases.pm b/centreon-plugins/database/informix/sql/mode/listdatabases.pm index 05a7dacd6..9fe836649 100644 --- a/centreon-plugins/database/informix/sql/mode/listdatabases.pm +++ b/centreon-plugins/database/informix/sql/mode/listdatabases.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "exclude:s" => { name => 'exclude', }, diff --git a/centreon-plugins/database/informix/sql/mode/listdbspaces.pm b/centreon-plugins/database/informix/sql/mode/listdbspaces.pm index c20b47d0f..7379a4aa0 100644 --- a/centreon-plugins/database/informix/sql/mode/listdbspaces.pm +++ b/centreon-plugins/database/informix/sql/mode/listdbspaces.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "exclude:s" => { name => 'exclude', }, diff --git a/centreon-plugins/database/informix/sql/mode/lockoverflow.pm b/centreon-plugins/database/informix/sql/mode/lockoverflow.pm index fbd0764a5..e0acd2326 100644 --- a/centreon-plugins/database/informix/sql/mode/lockoverflow.pm +++ b/centreon-plugins/database/informix/sql/mode/lockoverflow.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/informix/sql/mode/logfilesusage.pm b/centreon-plugins/database/informix/sql/mode/logfilesusage.pm index 6a6579748..132bc175e 100644 --- a/centreon-plugins/database/informix/sql/mode/logfilesusage.pm +++ b/centreon-plugins/database/informix/sql/mode/logfilesusage.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/informix/sql/mode/longtxs.pm b/centreon-plugins/database/informix/sql/mode/longtxs.pm index d128fd5d8..dacafbcf5 100644 --- a/centreon-plugins/database/informix/sql/mode/longtxs.pm +++ b/centreon-plugins/database/informix/sql/mode/longtxs.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/informix/sql/mode/sessions.pm b/centreon-plugins/database/informix/sql/mode/sessions.pm index 9038a259c..7b1659ea2 100644 --- a/centreon-plugins/database/informix/sql/mode/sessions.pm +++ b/centreon-plugins/database/informix/sql/mode/sessions.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/informix/sql/mode/tablelocks.pm b/centreon-plugins/database/informix/sql/mode/tablelocks.pm index a49d0b737..e90d1087a 100644 --- a/centreon-plugins/database/informix/sql/mode/tablelocks.pm +++ b/centreon-plugins/database/informix/sql/mode/tablelocks.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-deadlks:s" => { name => 'warning_deadlks', }, diff --git a/centreon-plugins/database/mongodb/custom/driver.pm b/centreon-plugins/database/mongodb/custom/driver.pm index 0693cd2e0..866b6c7e9 100644 --- a/centreon-plugins/database/mongodb/custom/driver.pm +++ b/centreon-plugins/database/mongodb/custom/driver.pm @@ -43,11 +43,13 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port' }, + "protocol:s" => { name => 'protocol' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "timeout:s" => { name => 'timeout' }, + "ssl-opt:s@" => { name => 'ssl_opt' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'DRIVER OPTIONS', once => 1); @@ -85,10 +87,16 @@ sub check_options { $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : 'localhost'; $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 27017; + $self->{protocol} = (defined($self->{option_results}->{protocol})) ? $self->{option_results}->{protocol} : 'mongodb'; $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; $self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : ''; $self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : ''; + foreach (@{$self->{option_results}->{ssl_opt}}) { + $_ =~ /(\w+)\s*=>\s*(\w+)/; + $self->{ssl_opts}->{$1} = $2; + } + return 0; } @@ -111,14 +119,15 @@ sub connect { my $encoded_username = $uri->encode($self->{username}); my $encoded_password = $uri->encode($self->{password}); - $uri = 'mongodb://'; + $uri = $self->{protocol} . '://'; $uri .= $encoded_username . ':' . $encoded_password . '@' if ($encoded_username ne '' && $encoded_password ne ''); $uri .= $self->{hostname} if ($self->{hostname} ne ''); $uri .= ':' . $self->{port} if ($self->{port} ne ''); $self->{output}->output_add(long_msg => 'Connection URI: ' . $uri, debug => 1); - $self->{client} = MongoDB::MongoClient->new(host => $uri); + my $ssl = (defined($self->{ssl_opts})) ? $self->{ssl_opts} : 0; + $self->{client} = MongoDB::MongoClient->new(host => $uri, ssl => $ssl); $self->{client}->connect(); eval { @@ -201,6 +210,11 @@ MongoDB server hostname. Port used (Default: 27017) +=item B<--protocol> + +Protocol used (Default: mongodb) +DNS Seedlist Connection Format can be specified, i.e. 'mongodb+srv' + =item B<--username> MongoDB username. @@ -213,6 +227,10 @@ MongoDB password. Set timeout in seconds (Default: 10). +=item B<--ssl-opt> + +Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE"). + =back =head1 DESCRIPTION diff --git a/centreon-plugins/database/mongodb/mode/collectionstatistics.pm b/centreon-plugins/database/mongodb/mode/collectionstatistics.pm index c1486390c..d6aa16f4e 100644 --- a/centreon-plugins/database/mongodb/mode/collectionstatistics.pm +++ b/centreon-plugins/database/mongodb/mode/collectionstatistics.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-database:s" => { name => 'filter_database' }, }); diff --git a/centreon-plugins/database/mongodb/mode/connections.pm b/centreon-plugins/database/mongodb/mode/connections.pm index 3e05d8f02..1c5334f7e 100644 --- a/centreon-plugins/database/mongodb/mode/connections.pm +++ b/centreon-plugins/database/mongodb/mode/connections.pm @@ -81,7 +81,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/database/mongodb/mode/connectiontime.pm b/centreon-plugins/database/mongodb/mode/connectiontime.pm index aad805427..b1cc4b290 100644 --- a/centreon-plugins/database/mongodb/mode/connectiontime.pm +++ b/centreon-plugins/database/mongodb/mode/connectiontime.pm @@ -51,7 +51,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/database/mongodb/mode/databasestatistics.pm b/centreon-plugins/database/mongodb/mode/databasestatistics.pm index b2e7bd2f7..61380de87 100644 --- a/centreon-plugins/database/mongodb/mode/databasestatistics.pm +++ b/centreon-plugins/database/mongodb/mode/databasestatistics.pm @@ -114,7 +114,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-database:s" => { name => 'filter_database' }, }); diff --git a/centreon-plugins/database/mongodb/mode/listdatabases.pm b/centreon-plugins/database/mongodb/mode/listdatabases.pm index 4dd362e61..606b001a2 100644 --- a/centreon-plugins/database/mongodb/mode/listdatabases.pm +++ b/centreon-plugins/database/mongodb/mode/listdatabases.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/database/mongodb/mode/queries.pm b/centreon-plugins/database/mongodb/mode/queries.pm index 7201cd7a3..5e68e9c45 100644 --- a/centreon-plugins/database/mongodb/mode/queries.pm +++ b/centreon-plugins/database/mongodb/mode/queries.pm @@ -79,7 +79,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/database/mongodb/mode/replicationstatus.pm b/centreon-plugins/database/mongodb/mode/replicationstatus.pm index cd9996d34..2ddd36cd9 100644 --- a/centreon-plugins/database/mongodb/mode/replicationstatus.pm +++ b/centreon-plugins/database/mongodb/mode/replicationstatus.pm @@ -130,7 +130,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); 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 => '' }, diff --git a/centreon-plugins/database/mssql/mode/backupage.pm b/centreon-plugins/database/mssql/mode/backupage.pm index 06f232609..f7003b27f 100644 --- a/centreon-plugins/database/mssql/mode/backupage.pm +++ b/centreon-plugins/database/mssql/mode/backupage.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter:s" => { name => 'filter', }, diff --git a/centreon-plugins/database/mssql/mode/blockedprocesses.pm b/centreon-plugins/database/mssql/mode/blockedprocesses.pm index 5a78c961a..6f16f355c 100644 --- a/centreon-plugins/database/mssql/mode/blockedprocesses.pm +++ b/centreon-plugins/database/mssql/mode/blockedprocesses.pm @@ -102,7 +102,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-status:s" => { name => 'filter_status' }, diff --git a/centreon-plugins/database/mssql/mode/cachehitratio.pm b/centreon-plugins/database/mssql/mode/cachehitratio.pm index 438142e88..27289d5f1 100644 --- a/centreon-plugins/database/mssql/mode/cachehitratio.pm +++ b/centreon-plugins/database/mssql/mode/cachehitratio.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mssql/mode/connectedusers.pm b/centreon-plugins/database/mssql/mode/connectedusers.pm index 5054e56ff..f4847df0f 100644 --- a/centreon-plugins/database/mssql/mode/connectedusers.pm +++ b/centreon-plugins/database/mssql/mode/connectedusers.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mssql/mode/databasessize.pm b/centreon-plugins/database/mssql/mode/databasessize.pm index 25ae6fd20..aa379e97c 100644 --- a/centreon-plugins/database/mssql/mode/databasessize.pm +++ b/centreon-plugins/database/mssql/mode/databasessize.pm @@ -117,7 +117,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-database:s" => { name => 'filter_database' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/database/mssql/mode/deadlocks.pm b/centreon-plugins/database/mssql/mode/deadlocks.pm index de9bd3bc0..faad334d6 100644 --- a/centreon-plugins/database/mssql/mode/deadlocks.pm +++ b/centreon-plugins/database/mssql/mode/deadlocks.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mssql/mode/failedjobs.pm b/centreon-plugins/database/mssql/mode/failedjobs.pm index e2530577e..31a168cb6 100644 --- a/centreon-plugins/database/mssql/mode/failedjobs.pm +++ b/centreon-plugins/database/mssql/mode/failedjobs.pm @@ -40,7 +40,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter:s" => { name => 'filter', }, diff --git a/centreon-plugins/database/mssql/mode/listdatabases.pm b/centreon-plugins/database/mssql/mode/listdatabases.pm index cf42bad30..517a0229e 100644 --- a/centreon-plugins/database/mssql/mode/listdatabases.pm +++ b/centreon-plugins/database/mssql/mode/listdatabases.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-database:s" => { name => 'filter_database' }, }); diff --git a/centreon-plugins/database/mssql/mode/lockswaits.pm b/centreon-plugins/database/mssql/mode/lockswaits.pm index a4a787b8e..b70343ab7 100644 --- a/centreon-plugins/database/mssql/mode/lockswaits.pm +++ b/centreon-plugins/database/mssql/mode/lockswaits.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mssql/mode/logssize.pm b/centreon-plugins/database/mssql/mode/logssize.pm index 74bd21466..223c6663a 100644 --- a/centreon-plugins/database/mssql/mode/logssize.pm +++ b/centreon-plugins/database/mssql/mode/logssize.pm @@ -113,7 +113,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-log:s" => { name => 'filter_log' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/database/mssql/mode/transactions.pm b/centreon-plugins/database/mssql/mode/transactions.pm index 3d6524925..22af9e97c 100644 --- a/centreon-plugins/database/mssql/mode/transactions.pm +++ b/centreon-plugins/database/mssql/mode/transactions.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mssql/plugin.pm b/centreon-plugins/database/mssql/plugin.pm index f02e7a09b..5d9352402 100644 --- a/centreon-plugins/database/mssql/plugin.pm +++ b/centreon-plugins/database/mssql/plugin.pm @@ -116,6 +116,10 @@ Database Server Port. An alternative to hostname+port. will be looked up in the file freetds.conf. +=item B<--database> + +Select database . + =back =cut diff --git a/centreon-plugins/database/mysql/dbi.pm b/centreon-plugins/database/mysql/dbi.pm new file mode 100644 index 000000000..78a1fca96 --- /dev/null +++ b/centreon-plugins/database/mysql/dbi.pm @@ -0,0 +1,48 @@ +# +# Copyright 2019 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 database::mysql::dbi; + +use base qw(centreon::plugins::dbi); + +use strict; +use warnings; + +sub is_mariadb { + my ($self) = @_; + + return $self->{is_mariadb}; +} + +sub set_version { + my ($self) = @_; + + $self->{is_mariadb} = 0; + $self->{version} = $self->{instance}->get_info(18); # SQL_DBMS_VER + # MariaDB: 5.5.5-10.1.36-MariaDB or 10.1.36-MariaDB + if ($self->{version} =~ /([0-9\.]*?)-MariaDB/i) { + $self->{version} = $1; + $self->{is_mariadb} = 1; + } +} + +1; + +__END__ diff --git a/centreon-plugins/database/mysql/mode/databasessize.pm b/centreon-plugins/database/mysql/mode/databasessize.pm index df063125e..1e355a0bf 100644 --- a/centreon-plugins/database/mysql/mode/databasessize.pm +++ b/centreon-plugins/database/mysql/mode/databasessize.pm @@ -20,80 +20,209 @@ package database::mysql::mode::databasessize; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = '[connection state ' . $self->{result_values}->{connection_state} . '][power state ' . $self->{result_values}->{power_state} . ']'; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{connection_state} = $options{new_datas}->{$self->{instance} . '_connection_state'}; + $self->{result_values}->{power_state} = $options{new_datas}->{$self->{instance} . '_power_state'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', }, + { name => 'database', type => 3, cb_prefix_output => 'prefix_database_output', cb_long_output => 'database_long_output', indent_long_output => ' ', message_multiple => 'All databases are ok', + group => [ + { name => 'global_db', type => 0, skipped_code => { -10 => 1 } }, + { name => 'table', display_long => 0, cb_prefix_output => 'prefix_table_output', message_multiple => 'All tables are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-usage', nlabel => 'databases.space.usage.bytes', set => { + key_values => [ { name => 'used' } ], + output_template => 'used space %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'used_absolute', template => '%s', unit => 'B', + min => 0 }, + ], + } + }, + { label => 'total-free', nlabel => 'databases.space.free.bytes', set => { + key_values => [ { name => 'free' } ], + output_template => 'free space %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'free_absolute', template => '%s', unit => 'B', + min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{global_db} = [ + { label => 'db-usage', nlabel => 'database.space.usage.bytes', set => { + key_values => [ { name => 'used' } ], + output_template => 'used %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'used_absolute', template => '%s', unit => 'B', + min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'db-free', nlabel => 'database.space.free.bytes', set => { + key_values => [ { name => 'free' } ], + output_template => 'free %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'free_absolute', template => '%s', unit => 'B', + min => 0, label_extra_instance => 1 }, + ], + } + }, + ]; + + $self->{maps_counters}->{table} = [ + { label => 'table-usage', nlabel => 'table.space.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'display' } ], + output_template => 'used %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'used_absolute', template => '%s', unit => 'B', + min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'table-free', nlabel => 'table.space.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'display' } ], + output_template => 'free %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'free_absolute', template => '%s', unit => 'B', + min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'table-frag', nlabel => 'table.fragmentation.percentage', set => { + key_values => [ { name => 'frag' }, { name => 'display' } ], + output_template => 'fragmentation : %s %%', + perfdatas => [ + { value => 'frag_absolute', template => '%.2f', unit => '%', + min => 0, max => 100, label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "Total database "; +} + +sub prefix_database_output { + my ($self, %options) = @_; + + return "Database '" . $options{instance_value}->{display} . "' "; +} + +sub database_long_output { + my ($self, %options) = @_; + + return "checking database '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_table_output { + my ($self, %options) = @_; + + return "table '" . $options{instance_value}->{display} . "' "; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "filter:s" => { name => 'filter', }, - }); + $options{options}->add_options(arguments => { + 'filter-database:s' => { name => 'filter_database' }, + }); return $self; } -sub check_options { +sub manage_selection { 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{sql} = sqlmode object - $self->{sql} = $options{sql}; - - $self->{sql}->connect(); - $self->{sql}->query(query => 'SELECT table_schema AS NAME, IFNULL(SUM(data_length+index_length), 0) - FROM information_schema.tables - GROUP BY table_schema'); - my $result = $self->{sql}->fetchall_arrayref(); - - if (!($self->{sql}->is_version_minimum(version => '5'))) { + $options{sql}->connect(); + if (!($options{sql}->is_version_minimum(version => '5'))) { $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported."); $self->{output}->option_exit(); - } - - $self->{output}->output_add(severity => 'OK', - short_msg => "All databases are ok."); - foreach my $row (@$result) { - next if (defined($self->{option_results}->{filter}) && - $$row[0] !~ /$self->{option_results}->{filter}/); - - my $exit_code = $self->{perfdata}->threshold_check(value => $$row[1], threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - my ($value, $value_unit) = $self->{perfdata}->change_bytes(value => $$row[1]); - $self->{output}->output_add(long_msg => sprintf("DB '" . $$row[0] . "' size: %s%s", $value, $value_unit)); - if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("DB '" . $$row[0] . "' size: %s%s", $value, $value_unit)); - } - $self->{output}->perfdata_add(label => $$row[0] . '_size', unit => 'B', - value => $$row[1], - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); } + $options{sql}->query( + query => q{show variables like 'innodb_file_per_table'} + ); + my ($name, $value) = $options{sql}->fetchrow_array(); + my $innodb_per_table = 0; + $innodb_per_table = 1 if ($value =~ /on/i); + + $options{sql}->query( + query => q{SELECT table_schema, table_name, engine, data_free, data_length+index_length as data_used, (DATA_FREE / (DATA_LENGTH+INDEX_LENGTH)) as TAUX_FRAG FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND engine IN ('InnoDB', 'MyISAM')} + ); + my $result = $options{sql}->fetchall_arrayref(); - $self->{output}->display(); - $self->{output}->exit(); + my $innodb_ibdata_done = 0; + $self->{global} = { free => 0, used => 0 }; + $self->{database} = {}; + foreach my $row (@$result) { + next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne '' && + $$row[0] !~ /$self->{option_results}->{filter_database}/); + if (!defined($self->{database}->{$$row[0]})) { + $self->{database}->{$$row[0]} = { + display => $$row[0], + global_db => { free => 0, used => 0 }, + table => {} + }; + } + + if (($$row[2] =~ /innodb/i && ($innodb_per_table == 1 || $innodb_ibdata_done == 0))) { + $self->{global}->{free} += $$row[3]; + $self->{global}->{used} += $$row[4]; + $innodb_ibdata_done = 1; + } + + if ($$row[2] !~ /innodb/i || + ($$row[2] =~ /innodb/i && $innodb_per_table == 1) + ) { + $self->{database}->{$$row[0]}->{global_db}->{free} += $$row[3]; + $self->{database}->{$$row[0]}->{global_db}->{used} += $$row[4]; + + $self->{database}->{$$row[0]}->{table}->{$$row[1]} = { + display => $$row[1], + free => $$row[3], + used => $$row[4], + frag => $$row[5] + }; + } + } } 1; @@ -106,15 +235,7 @@ Check MySQL databases size. =over 8 -=item B<--warning> - -Threshold warning in bytes. - -=item B<--critical> - -Threshold critical in bytes. - -=item B<--filter> +=item B<--filter-database> Filter database to checks. diff --git a/centreon-plugins/database/mysql/mode/innodbbufferpoolhitrate.pm b/centreon-plugins/database/mysql/mode/innodbbufferpoolhitrate.pm index bae017993..8410f03ea 100644 --- a/centreon-plugins/database/mysql/mode/innodbbufferpoolhitrate.pm +++ b/centreon-plugins/database/mysql/mode/innodbbufferpoolhitrate.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mysql/mode/longqueries.pm b/centreon-plugins/database/mysql/mode/longqueries.pm index 8c41b2cf4..c46cc4cd5 100644 --- a/centreon-plugins/database/mysql/mode/longqueries.pm +++ b/centreon-plugins/database/mysql/mode/longqueries.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mysql/mode/myisamkeycachehitrate.pm b/centreon-plugins/database/mysql/mode/myisamkeycachehitrate.pm index 2eddc3f1e..18c91c34c 100644 --- a/centreon-plugins/database/mysql/mode/myisamkeycachehitrate.pm +++ b/centreon-plugins/database/mysql/mode/myisamkeycachehitrate.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mysql/mode/openfiles.pm b/centreon-plugins/database/mysql/mode/openfiles.pm index 371f84d56..321986bba 100644 --- a/centreon-plugins/database/mysql/mode/openfiles.pm +++ b/centreon-plugins/database/mysql/mode/openfiles.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mysql/mode/opentables.pm b/centreon-plugins/database/mysql/mode/opentables.pm index b048af187..b94cc46b0 100644 --- a/centreon-plugins/database/mysql/mode/opentables.pm +++ b/centreon-plugins/database/mysql/mode/opentables.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mysql/mode/qcachehitrate.pm b/centreon-plugins/database/mysql/mode/qcachehitrate.pm index 636c8cda2..96c5e60fe 100644 --- a/centreon-plugins/database/mysql/mode/qcachehitrate.pm +++ b/centreon-plugins/database/mysql/mode/qcachehitrate.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mysql/mode/queries.pm b/centreon-plugins/database/mysql/mode/queries.pm index e6f193fe1..e84a3c472 100644 --- a/centreon-plugins/database/mysql/mode/queries.pm +++ b/centreon-plugins/database/mysql/mode/queries.pm @@ -82,7 +82,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/mysql/mode/replicationmastermaster.pm b/centreon-plugins/database/mysql/mode/replicationmastermaster.pm index 9b77459a4..85ce73320 100644 --- a/centreon-plugins/database/mysql/mode/replicationmastermaster.pm +++ b/centreon-plugins/database/mysql/mode/replicationmastermaster.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mysql/mode/replicationmasterslave.pm b/centreon-plugins/database/mysql/mode/replicationmasterslave.pm index 780a5586a..5e14c20ec 100644 --- a/centreon-plugins/database/mysql/mode/replicationmasterslave.pm +++ b/centreon-plugins/database/mysql/mode/replicationmasterslave.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mysql/mode/slowqueries.pm b/centreon-plugins/database/mysql/mode/slowqueries.pm index 3163fa130..fcf165357 100644 --- a/centreon-plugins/database/mysql/mode/slowqueries.pm +++ b/centreon-plugins/database/mysql/mode/slowqueries.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mysql/mode/tablescount.pm b/centreon-plugins/database/mysql/mode/tablescount.pm index bf816f0ad..637f627aa 100644 --- a/centreon-plugins/database/mysql/mode/tablescount.pm +++ b/centreon-plugins/database/mysql/mode/tablescount.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mysql/mode/tablessize.pm b/centreon-plugins/database/mysql/mode/tablessize.pm index 29c97f7b9..077be63ff 100644 --- a/centreon-plugins/database/mysql/mode/tablessize.pm +++ b/centreon-plugins/database/mysql/mode/tablessize.pm @@ -64,7 +64,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-db:s" => { name => 'filter_db' }, diff --git a/centreon-plugins/database/mysql/mode/threadsconnected.pm b/centreon-plugins/database/mysql/mode/threadsconnected.pm index b5c544055..5a88eb755 100644 --- a/centreon-plugins/database/mysql/mode/threadsconnected.pm +++ b/centreon-plugins/database/mysql/mode/threadsconnected.pm @@ -20,69 +20,114 @@ package database::mysql::mode::threadsconnected; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub custom_usage_output { + my ($self, %options) = @_; + + my $msg = sprintf("Client Connection Threads Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $self->{result_values}->{total_absolute}, + $self->{result_values}->{used_absolute}, + $self->{result_values}->{prct_used_absolute}, + $self->{result_values}->{free_absolute}, + $self->{result_values}->{prct_free_absolute}); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'usage', nlabel => 'threads.connected.count', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'threads_connected', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute' }, + ], + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'threads.connected.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Client Connection Threads Used : %.2f %%', + perfdatas => [ + { label => 'threads_connected_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%' }, + ], + } + }, + ]; +} + 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', }, - }); + $options{options}->add_options(arguments => { + }); 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 { +sub manage_selection { my ($self, %options) = @_; $options{sql}->connect(); - if (!($options{sql}->is_version_minimum(version => '5'))) { $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); $self->{output}->option_exit(); } - - $options{sql}->query(query => q{SHOW /*!50000 global */ STATUS LIKE 'Threads_connected'}); - my ($name, $value) = $options{sql}->fetchrow_array(); - if (!defined($value)) { + + my $infos = {}; + if (!$options{sql}->is_mariadb() && $options{sql}->is_version_minimum(version => '5.7.6')) { + $options{sql}->query(query => q{ + SELECT 'max_connections' as name, @@GLOBAL.max_connections as value + UNION + SELECT VARIABLE_NAME as name, VARIABLE_VALUE as value FROM performance_schema.global_status WHERE VARIABLE_NAME = 'Threads_connected' + }); + while (my ($name, $value) = $options{sql}->fetchrow_array()) { + $infos->{lc($name)} = $value; + } + } elsif ($options{sql}->is_version_minimum(version => '5.1.12')) { + $options{sql}->query(query => q{ + SELECT 'max_connections' as name, @@GLOBAL.max_connections as value + UNION + SELECT VARIABLE_NAME as name, VARIABLE_VALUE as value FROM information_schema.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_connected' + }); + while (my ($name, $value) = $options{sql}->fetchrow_array()) { + $infos->{lc($name)} = $value; + } + } else { + $options{sql}->query(query => q{SELECT 'max_connections' as name, @@GLOBAL.max_connections as value}); + if (my ($name, $value) = $options{sql}->fetchrow_array()) { + $infos->{lc($name)} = $value + } + $options{sql}->query(query => q{SHOW /*!50000 global */ STATUS LIKE 'Threads_connected'}); + if (my ($name, $value) = $options{sql}->fetchrow_array()) { + $infos->{lc($name)} = $value + } + } + + if (scalar(keys %$infos) == 0) { $self->{output}->add_option_msg(short_msg => "Cannot get number of open connections."); $self->{output}->option_exit(); } - - my $exit_code = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("%d client connection threads", $value) - ); - $self->{output}->perfdata_add(label => 'threads_connected', - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - $self->{output}->display(); - $self->{output}->exit(); + my $prct_used = $infos->{threads_connected} * 100 / $infos->{max_connections}; + $self->{global} = { + total => $infos->{max_connections}, + used => $infos->{threads_connected}, + free => $infos->{max_connections} - $infos->{threads_connected}, + prct_used => $prct_used, + prct_free => 100 - $prct_used, + }; } 1; @@ -95,13 +140,10 @@ Check number of open connections. =over 8 -=item B<--warning> +=item B<--warning-*> B<--critical-*> -Threshold warning. - -=item B<--critical> - -Threshold critical. +Thresholds. +Can be: 'usage', 'usage-prct' (%). =back diff --git a/centreon-plugins/database/mysql/mode/uptime.pm b/centreon-plugins/database/mysql/mode/uptime.pm index b17e3814e..ae12ecab2 100644 --- a/centreon-plugins/database/mysql/mode/uptime.pm +++ b/centreon-plugins/database/mysql/mode/uptime.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/mysql/mysqlcmd.pm b/centreon-plugins/database/mysql/mysqlcmd.pm index 1653a90ea..55f0f86a1 100644 --- a/centreon-plugins/database/mysql/mysqlcmd.pm +++ b/centreon-plugins/database/mysql/mysqlcmd.pm @@ -43,14 +43,14 @@ sub new { $options{output}->option_exit(); } if (!defined($options{noptions})) { - $options{options}->add_options(arguments => - { "mysql-cmd:s" => { name => 'mysql_cmd', default => '/usr/bin/mysql' }, - "host:s@" => { name => 'host' }, - "port:s@" => { name => 'port' }, - "username:s@" => { name => 'username' }, - "password:s@" => { name => 'password' }, - "socket:s@" => { name => 'socket' }, - "sql-errors-exit:s" => { name => 'sql_errors_exit', default => 'unknown' }, + $options{options}->add_options(arguments => { + 'mysql-cmd:s' => { name => 'mysql_cmd', default => '/usr/bin/mysql' }, + 'host:s@' => { name => 'host' }, + 'port:s@' => { name => 'port' }, + 'username:s@' => { name => 'username' }, + 'password:s@' => { name => 'password' }, + 'socket:s@' => { name => 'socket' }, + 'sql-errors-exit:s' => { name => 'sql_errors_exit', default => 'unknown' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'MYSQLCMD OPTIONS', once => 1); @@ -112,7 +112,7 @@ sub check_options { $self->{mysql_cmd} = $self->{option_results}->{mysql_cmd}; if (!defined($self->{host}) || $self->{host} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify host argument."); + $self->{output}->add_option_msg(short_msg => 'Need to specify host argument.'); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); } @@ -184,12 +184,13 @@ sub command_execution { my ($self, %options) = @_; my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick( - command => $self->{mysql_cmd}, - arguments => [@{$self->{args}}, '-e', $options{request}], - timeout => 30, - wait_exit => 1, - redirect_stderr => 1 - ); + command => $self->{mysql_cmd}, + arguments => [@{$self->{args}}, '-e', $options{request}], + timeout => 30, + wait_exit => 1, + redirect_stderr => 1 + ); + if ($exit_code <= -1000) { if ($exit_code == -1000) { $self->{output}->output_add(severity => 'UNKNOWN', @@ -204,7 +205,24 @@ sub command_execution { sub disconnect {} -# Connection initializer +sub is_mariadb { + my ($self) = @_; + + return $self->{is_mariadb}; +} + +sub set_version { + my ($self, %options) = @_; + + $self->{is_mariadb} = 0; + $self->{version} = $options{version}; + # MariaDB: 5.5.5-10.1.36-MariaDB or 10.1.36-MariaDB + if ($self->{version} =~ /([0-9\.]*?)-MariaDB/i) { + $self->{version} = $1; + $self->{is_mariadb} = 1; + } +} + sub connect { my ($self, %options) = @_; my $dontquit = (defined($options{dontquit}) && $options{dontquit} == 1) ? 1 : 0; @@ -212,14 +230,14 @@ sub connect { (my $exit_code, $self->{stdout}) = $self->command_execution(request => "SHOW VARIABLES LIKE 'version'"); if ($exit_code != 0) { if ($dontquit == 0) { - $self->{output}->add_option_msg(short_msg => "Cannot connect: " . $self->{stdout}); + $self->{output}->add_option_msg(short_msg => 'Cannot connect: ' . $self->{stdout}); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); } - return (-1, "Cannot connect: " . $self->{stdout}); + return (-1, 'Cannot connect: ' . $self->{stdout}); } - + my $row = $self->fetchrow_hashref(); - $self->{version} = $row->{Value}; + $self->set_version(version => $row->{Value}); return 0; } @@ -284,7 +302,7 @@ sub query { (my $exit_code, $self->{stdout}) = $self->command_execution(request => $options{query}); if ($exit_code != 0) { - $self->{output}->add_option_msg(short_msg => "Cannot execute query: " . $self->{stdout}); + $self->{output}->add_option_msg(short_msg => 'Cannot execute query: ' . $self->{stdout}); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); } diff --git a/centreon-plugins/database/mysql/plugin.pm b/centreon-plugins/database/mysql/plugin.pm index fdd234d85..a4b11acdf 100644 --- a/centreon-plugins/database/mysql/plugin.pm +++ b/centreon-plugins/database/mysql/plugin.pm @@ -32,24 +32,25 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', - 'databases-size' => 'database::mysql::mode::databasessize', - 'innodb-bufferpool-hitrate' => 'database::mysql::mode::innodbbufferpoolhitrate', - 'long-queries' => 'database::mysql::mode::longqueries', - 'myisam-keycache-hitrate' => 'database::mysql::mode::myisamkeycachehitrate', - 'open-files' => 'database::mysql::mode::openfiles', - 'qcache-hitrate' => 'database::mysql::mode::qcachehitrate', - 'queries' => 'database::mysql::mode::queries', - 'replication-master-slave' => 'database::mysql::mode::replicationmasterslave', - 'replication-master-master' => 'database::mysql::mode::replicationmastermaster', - 'slow-queries' => 'database::mysql::mode::slowqueries', - 'sql' => 'centreon::common::protocols::sql::mode::sql', - 'sql-string' => 'centreon::common::protocols::sql::mode::sqlstring', - 'tables-size' => 'database::mysql::mode::tablessize', - 'threads-connected' => 'database::mysql::mode::threadsconnected', - 'uptime' => 'database::mysql::mode::uptime', - ); - + 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', + 'databases-size' => 'database::mysql::mode::databasessize', + 'innodb-bufferpool-hitrate' => 'database::mysql::mode::innodbbufferpoolhitrate', + 'long-queries' => 'database::mysql::mode::longqueries', + 'myisam-keycache-hitrate' => 'database::mysql::mode::myisamkeycachehitrate', + 'open-files' => 'database::mysql::mode::openfiles', + 'qcache-hitrate' => 'database::mysql::mode::qcachehitrate', + 'queries' => 'database::mysql::mode::queries', + 'replication-master-slave' => 'database::mysql::mode::replicationmasterslave', + 'replication-master-master' => 'database::mysql::mode::replicationmastermaster', + 'slow-queries' => 'database::mysql::mode::slowqueries', + 'sql' => 'centreon::common::protocols::sql::mode::sql', + 'sql-string' => 'centreon::common::protocols::sql::mode::sqlstring', + 'tables-size' => 'database::mysql::mode::tablessize', + 'threads-connected' => 'database::mysql::mode::threadsconnected', + 'uptime' => 'database::mysql::mode::uptime', + ); + + $self->{sql_modes}{dbi} = 'database::mysql::dbi'; $self->{sql_modes}{mysqlcmd} = 'database::mysql::mysqlcmd'; return $self; @@ -59,12 +60,12 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options( - arguments => { - 'host:s@' => { name => 'db_host' }, - 'port:s@' => { name => 'db_port' }, - 'socket:s@' => { name => 'db_socket' }, - } - ); + arguments => { + 'host:s@' => { name => 'db_host' }, + 'port:s@' => { name => 'db_port' }, + 'socket:s@' => { name => 'db_socket' }, + } + ); $self->{options}->parse_options(); my $options_result = $self->{options}->get_options(); $self->{options}->clean(); diff --git a/centreon-plugins/database/oracle/dbi.pm b/centreon-plugins/database/oracle/dbi.pm new file mode 100644 index 000000000..0bc209df3 --- /dev/null +++ b/centreon-plugins/database/oracle/dbi.pm @@ -0,0 +1,96 @@ +# +# Copyright 2019 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 database::oracle::dbi; + +use base qw(centreon::plugins::dbi); + +use strict; +use warnings; +use POSIX qw(:signal_h); + +sub connect_oracle { + my ($self, %options) = @_; + + $self->{instance} = DBI->connect( + 'DBI:' . $self->{data_source}, + $self->{username}, + $self->{password}, + { RaiseError => 0, PrintError => 0, AutoCommit => 1, %{$self->{connect_options_hash}} } + ); +} + +sub check_options { + my ($self, %options) = @_; + + $self->{container} = defined($self->{option_results}->{container}[0]) ? $self->{option_results}->{container}[0] : undef; + return $self->SUPER::check_options(%options); +} + +sub connect { + my ($self, %options) = @_; + my $dontquit = (defined($options{dontquit}) && $options{dontquit} == 1) ? 1 : 0; + + # Set ENV + if (defined($self->{env})) { + foreach (keys %{$self->{env}}) { + $ENV{$_} = $self->{env}->{$_}; + } + } + + if (defined($self->{timeout})) { + my $mask = POSIX::SigSet->new(SIGALRM); + my $action = POSIX::SigAction->new( + sub { $self->handle_ALRM() }, + $mask, + ); + my $oldaction = POSIX::SigAction->new(); + sigaction(SIGALRM, $action, $oldaction); + eval { + eval { + alarm($self->{timeout}); + $self->connect_oracle(); + }; + alarm(0); + }; + sigaction(SIGALRM, $oldaction); + } else { + $self->connect_oracle(); + } + + if (!defined($self->{instance})) { + my $err_msg = sprintf('Cannot connect: %s', defined($DBI::errstr) ? $DBI::errstr : '(no error string)'); + if ($dontquit == 0) { + $self->{output}->add_option_msg(short_msg => $err_msg); + $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); + } + return (-1, $err_msg); + } + + $self->set_version(); + if (defined($self->{container}) and $self->{container} ne '') { + $self->query(query => "alter session set container=$self->{container}"); + } + return 0; +} + +1; + +__END__ diff --git a/centreon-plugins/database/oracle/mode/asmdiskgroupusage.pm b/centreon-plugins/database/oracle/mode/asmdiskgroupusage.pm index 1940fb89f..beaa2c825 100644 --- a/centreon-plugins/database/oracle/mode/asmdiskgroupusage.pm +++ b/centreon-plugins/database/oracle/mode/asmdiskgroupusage.pm @@ -213,7 +213,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "unknown-status:s" => { name => 'unknown_status', default => '' }, "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/database/oracle/mode/connectedusers.pm b/centreon-plugins/database/oracle/mode/connectedusers.pm index 46dae0008..512d1f8a9 100644 --- a/centreon-plugins/database/oracle/mode/connectedusers.pm +++ b/centreon-plugins/database/oracle/mode/connectedusers.pm @@ -30,7 +30,6 @@ sub new { 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', }, diff --git a/centreon-plugins/database/oracle/mode/corruptedblocks.pm b/centreon-plugins/database/oracle/mode/corruptedblocks.pm index 6c3cf9e69..e72813123 100644 --- a/centreon-plugins/database/oracle/mode/corruptedblocks.pm +++ b/centreon-plugins/database/oracle/mode/corruptedblocks.pm @@ -30,7 +30,6 @@ sub new { 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', }, diff --git a/centreon-plugins/database/oracle/mode/datacachehitratio.pm b/centreon-plugins/database/oracle/mode/datacachehitratio.pm index 325aab0a7..a6647235f 100644 --- a/centreon-plugins/database/oracle/mode/datacachehitratio.pm +++ b/centreon-plugins/database/oracle/mode/datacachehitratio.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/oracle/mode/datafilesstatus.pm b/centreon-plugins/database/oracle/mode/datafilesstatus.pm index 24862642e..3d46adadf 100644 --- a/centreon-plugins/database/oracle/mode/datafilesstatus.pm +++ b/centreon-plugins/database/oracle/mode/datafilesstatus.pm @@ -132,7 +132,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-tablespace:s" => { name => 'filter_tablespace' }, "filter-data-file:s" => { name => 'filter_data_file' }, diff --git a/centreon-plugins/database/oracle/mode/dictionarycacheusage.pm b/centreon-plugins/database/oracle/mode/dictionarycacheusage.pm index d963b70be..662e323c5 100644 --- a/centreon-plugins/database/oracle/mode/dictionarycacheusage.pm +++ b/centreon-plugins/database/oracle/mode/dictionarycacheusage.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/oracle/mode/eventwaitsusage.pm b/centreon-plugins/database/oracle/mode/eventwaitsusage.pm index a1982bbc7..569a32448 100644 --- a/centreon-plugins/database/oracle/mode/eventwaitsusage.pm +++ b/centreon-plugins/database/oracle/mode/eventwaitsusage.pm @@ -85,7 +85,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "wait-time-min:s" => { name => 'wait_time_min', default => 1000 }, diff --git a/centreon-plugins/database/oracle/mode/frausage.pm b/centreon-plugins/database/oracle/mode/frausage.pm new file mode 100644 index 000000000..8a94294e4 --- /dev/null +++ b/centreon-plugins/database/oracle/mode/frausage.pm @@ -0,0 +1,132 @@ +# +# Copyright 2019 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 database::oracle::mode::frausage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'file', type => 1, cb_prefix_output => 'prefix_file_output', message_multiple => 'All recovery areas are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{file} = [ + { label => 'space-usage', nlabel => 'recoveryarea.space.usage.percentage', set => { + key_values => [ { name => 'percent_space_usage' }, { name => 'display' } ], + output_template => 'used : %.2f %%', + perfdatas => [ + { value => 'percent_space_usage_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'space-reclaimable', nlabel => 'recoveryarea.space.reclaimable.percentage', set => { + key_values => [ { name => 'percent_space_reclaimable' }, { name => 'display' } ], + output_template => 'reclaimable : %.2f %%', + perfdatas => [ + { value => 'percent_space_reclaimable_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-type:s' => { name => 'filter_type' }, + }); + + return $self; +} + +sub prefix_file_output { + my ($self, %options) = @_; + + return "File type '" . $options{instance_value}->{display} . "' recovery area "; +} + +sub manage_selection { + my ($self, %options) = @_; + + $options{sql}->connect(); + $options{sql}->query(query => q{ + SELECT file_type, percent_space_used, percent_space_reclaimable + FROM v$recovery_area_usage + }); + my $result = $options{sql}->fetchall_arrayref(); + $options{sql}->disconnect(); + + $self->{file} = {}; + foreach my $row (@$result) { + if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && + $$row[0] !~ /$self->{option_results}->{filter_type}/i) { + $self->{output}->output_add(long_msg => "skipping '" . $$row[0] . "': no matching filter.", debug => 1); + next; + } + + $self->{file}->{$$row[0]} = { + display => $$row[0], + percent_space_usage => $$row[1], + percent_space_reclaimable => $$row[2], + }; + } + + if (scalar(keys %{$self->{file}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No file type found"); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check fast recovery area space usage + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). + +=item B<--filter-type> + +Filter file type (can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'space-usage', 'space-reclaimable'. + +=back + +=cut diff --git a/centreon-plugins/database/oracle/mode/invalidobject.pm b/centreon-plugins/database/oracle/mode/invalidobject.pm index 5c51ea251..67474eebb 100644 --- a/centreon-plugins/database/oracle/mode/invalidobject.pm +++ b/centreon-plugins/database/oracle/mode/invalidobject.pm @@ -81,7 +81,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-message:s" => { name => 'filter_message' }, "retention-objects:s" => { name => 'retention_objects', default => 3 }, diff --git a/centreon-plugins/database/oracle/mode/librarycacheusage.pm b/centreon-plugins/database/oracle/mode/librarycacheusage.pm index 6799e74a6..d13b9055b 100644 --- a/centreon-plugins/database/oracle/mode/librarycacheusage.pm +++ b/centreon-plugins/database/oracle/mode/librarycacheusage.pm @@ -106,7 +106,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/oracle/mode/listasmdiskgroups.pm b/centreon-plugins/database/oracle/mode/listasmdiskgroups.pm index 105f1132f..b787fda60 100644 --- a/centreon-plugins/database/oracle/mode/listasmdiskgroups.pm +++ b/centreon-plugins/database/oracle/mode/listasmdiskgroups.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/oracle/mode/longqueries.pm b/centreon-plugins/database/oracle/mode/longqueries.pm index 6aea83f79..2c5a895e6 100644 --- a/centreon-plugins/database/oracle/mode/longqueries.pm +++ b/centreon-plugins/database/oracle/mode/longqueries.pm @@ -74,7 +74,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/database/oracle/mode/passwordexpiration.pm b/centreon-plugins/database/oracle/mode/passwordexpiration.pm index 407c8e30f..ece682f3c 100644 --- a/centreon-plugins/database/oracle/mode/passwordexpiration.pm +++ b/centreon-plugins/database/oracle/mode/passwordexpiration.pm @@ -76,7 +76,6 @@ sub new { 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 => '' }, @@ -134,7 +133,7 @@ sub manage_selection { $i++; } - $self->{sql}->disconnect(); + $options{sql}->disconnect(); } 1; diff --git a/centreon-plugins/database/oracle/mode/processusage.pm b/centreon-plugins/database/oracle/mode/processusage.pm index 2472fc187..04f58f838 100644 --- a/centreon-plugins/database/oracle/mode/processusage.pm +++ b/centreon-plugins/database/oracle/mode/processusage.pm @@ -30,7 +30,6 @@ sub new { 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', }, diff --git a/centreon-plugins/database/oracle/mode/redologusage.pm b/centreon-plugins/database/oracle/mode/redologusage.pm index 0c90f773a..f3deb0a54 100644 --- a/centreon-plugins/database/oracle/mode/redologusage.pm +++ b/centreon-plugins/database/oracle/mode/redologusage.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/oracle/mode/rmanbackupage.pm b/centreon-plugins/database/oracle/mode/rmanbackupage.pm index 6e5553fca..27c6b8a2f 100644 --- a/centreon-plugins/database/oracle/mode/rmanbackupage.pm +++ b/centreon-plugins/database/oracle/mode/rmanbackupage.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "skip-no-backup" => { name => 'skip_no_backup', }, "filter-type:s" => { name => 'filter_type', }, diff --git a/centreon-plugins/database/oracle/mode/rmanbackupproblems.pm b/centreon-plugins/database/oracle/mode/rmanbackupproblems.pm index 071cc388f..6c391fdf5 100644 --- a/centreon-plugins/database/oracle/mode/rmanbackupproblems.pm +++ b/centreon-plugins/database/oracle/mode/rmanbackupproblems.pm @@ -30,7 +30,6 @@ sub new { 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', }, diff --git a/centreon-plugins/database/oracle/mode/rmanonlinebackupage.pm b/centreon-plugins/database/oracle/mode/rmanonlinebackupage.pm index 8578e68de..6bf3279b8 100644 --- a/centreon-plugins/database/oracle/mode/rmanonlinebackupage.pm +++ b/centreon-plugins/database/oracle/mode/rmanonlinebackupage.pm @@ -31,7 +31,6 @@ sub new { 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', }, diff --git a/centreon-plugins/database/oracle/mode/rollbacksegmentusage.pm b/centreon-plugins/database/oracle/mode/rollbacksegmentusage.pm index 2b6b39b64..dff39275e 100644 --- a/centreon-plugins/database/oracle/mode/rollbacksegmentusage.pm +++ b/centreon-plugins/database/oracle/mode/rollbacksegmentusage.pm @@ -109,7 +109,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/oracle/mode/sessionusage.pm b/centreon-plugins/database/oracle/mode/sessionusage.pm index b349e1fca..390489139 100644 --- a/centreon-plugins/database/oracle/mode/sessionusage.pm +++ b/centreon-plugins/database/oracle/mode/sessionusage.pm @@ -30,7 +30,6 @@ sub new { 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', }, diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index effcac3be..8816414d3 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -116,7 +116,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-tablespace:s" => { name => 'filter_tablespace' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/database/oracle/mode/temptablespace.pm b/centreon-plugins/database/oracle/mode/temptablespace.pm index 7228ad317..b11808831 100644 --- a/centreon-plugins/database/oracle/mode/temptablespace.pm +++ b/centreon-plugins/database/oracle/mode/temptablespace.pm @@ -117,7 +117,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, diff --git a/centreon-plugins/database/oracle/mode/tnsping.pm b/centreon-plugins/database/oracle/mode/tnsping.pm index 0867fd90a..aba3516f3 100644 --- a/centreon-plugins/database/oracle/mode/tnsping.pm +++ b/centreon-plugins/database/oracle/mode/tnsping.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/oracle/mode/undotablespace.pm b/centreon-plugins/database/oracle/mode/undotablespace.pm index e034bbd26..0528dd1c3 100644 --- a/centreon-plugins/database/oracle/mode/undotablespace.pm +++ b/centreon-plugins/database/oracle/mode/undotablespace.pm @@ -115,7 +115,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, diff --git a/centreon-plugins/database/oracle/plugin.pm b/centreon-plugins/database/oracle/plugin.pm index 4e0913299..015e4d7e4 100644 --- a/centreon-plugins/database/oracle/plugin.pm +++ b/centreon-plugins/database/oracle/plugin.pm @@ -39,8 +39,8 @@ sub new { 'data-files-status' => 'database::oracle::mode::datafilesstatus', 'datacache-hitratio' => 'database::oracle::mode::datacachehitratio', 'dictionary-cache-usage' => 'database::oracle::mode::dictionarycacheusage', - 'library-cache-usage' => 'database::oracle::mode::librarycacheusage', 'event-waits-usage' => 'database::oracle::mode::eventwaitsusage', + 'fra-usage' => 'database::oracle::mode::frausage', 'invalid-object' => 'database::oracle::mode::invalidobject', 'library-cache-usage' => 'database::oracle::mode::librarycacheusage', 'list-asm-diskgroups' => 'database::oracle::mode::listasmdiskgroups', @@ -56,12 +56,13 @@ sub new { 'sql' => 'centreon::common::protocols::sql::mode::sql', 'sql-string' => 'centreon::common::protocols::sql::mode::sqlstring', 'tablespace-usage' => 'database::oracle::mode::tablespaceusage', - 'temp-usage' => 'database::oracle::mode::temptablespace', + 'temp-tablespace' => 'database::oracle::mode::temptablespace', 'tnsping' => 'database::oracle::mode::tnsping', - 'undo-usage' => 'database::oracle::mode::undotablespace', + 'undo-tablespace' => 'database::oracle::mode::undotablespace', ); - $self->{sql_modes}{sqlpluscmd} = 'database::oracle::sqlpluscmd'; + $self->{sql_modes}{dbi} = 'database::oracle::dbi'; + $self->{sql_modes}{sqlpluscmd} = 'database::oracle::sqlpluscmd'; return $self; } @@ -74,6 +75,7 @@ sub init { 'port:s@' => { name => 'port' }, 'sid:s' => { name => 'sid' }, 'servicename:s' => { name => 'servicename' }, + 'container:s' => { name => 'container' }, }); $self->{options}->parse_options(); @@ -98,9 +100,11 @@ sub init { $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';service_name=' . $options_result->{servicename}; $self->{sqldefault}->{sqlpluscmd}[$i]->{service_name} = $options_result->{servicename}; } + $self->{sqldefault}->{dbi}[$i]->{container} = $options_result->{container}; + $self->{sqldefault}->{sqlpluscmd}[$i]->{container} = $options_result->{container}; } } - $self->SUPER::init(%options); + $self->SUPER::init(%options); } 1; @@ -129,6 +133,10 @@ Database SID. Database Service Name. +=item B<--container> + +Change container (does an alter session set container command). + =back =cut diff --git a/centreon-plugins/database/oracle/sqlpluscmd.pm b/centreon-plugins/database/oracle/sqlpluscmd.pm index 60f44d576..2fbad25d8 100644 --- a/centreon-plugins/database/oracle/sqlpluscmd.pm +++ b/centreon-plugins/database/oracle/sqlpluscmd.pm @@ -109,12 +109,13 @@ sub check_options { # return 1 = ok still data_source # return 0 = no data_source left - $self->{sid} = defined($self->{option_results}->{sid}[0]) ? $self->{option_results}->{sid}[0]: $self->{option_results}->{tnsnames_sid}; - $self->{service_name} = defined($self->{option_results}->{service_name}[0]) ? $self->{option_results}->{service_name}[0]: $self->{option_results}->{tnsnames_servicename}; + $self->{sid} = defined($self->{option_results}->{sid}[0]) ? $self->{option_results}->{sid}[0] : $self->{option_results}->{tnsnames_sid}; + $self->{service_name} = defined($self->{option_results}->{service_name}[0]) ? $self->{option_results}->{service_name}[0] : $self->{option_results}->{tnsnames_servicename}; $self->{oracle_home} = defined($self->{option_results}->{oracle_home}) ? $self->{option_results}->{oracle_home} : $ENV{'ORACLE_HOME'}; $self->{tnsadmin_home} = defined($self->{option_results}->{tnsadmin_home}) ? $self->{option_results}->{tnsadmin_home} : $ENV{'TNSADMIN'}; $self->{local_connexion} = $self->{option_results}->{local_connexion}; $self->{sqlplus_cmd} = $self->{option_results}->{sqlplus_cmd}; + $self->{container} = defined($self->{option_results}->{container}[0]) ? $self->{option_results}->{container}[0] : undef; $self->{output}->output_add(long_msg => "*** DEBUG MODE****\n", debug => 1); $self->{output}->output_add(long_msg => Data::Dumper::Dumper($self->{option_results}), debug => 1); @@ -157,9 +158,9 @@ sub check_options { if ($self->{local_connexion} == 0) { if (defined($self->{option_results}->{hostname})) { my $port = defined($self->{option_results}->{port}) ? $self->{option_results}->{port}[0] : 1521; - $connection_string .= "\@//" . $self->{option_results}->{hostname}[0] . ":" . $port . "/" . (defined($self->{sid}) && $self->{sid} ne '') ? $self->{sid} : $self->{service_name}); + $connection_string .= "\@//" . $self->{option_results}->{hostname}[0] . ':' . $port . '/' . ((defined($self->{sid}) && $self->{sid} ne '') ? $self->{sid} : $self->{service_name}); } else { - $connection_string .= "\@" . (defined($self->{sid}) && $self->{sid} ne '') ? $self->{sid} : $self->{service_name}); + $connection_string .= "\@" . ((defined($self->{sid}) && $self->{sid} ne '') ? $self->{sid} : $self->{service_name}); } } else { $self->{output}->output_add(long_msg => "*** LOCAL CONNEXION MODE****", debug => 1); @@ -286,8 +287,10 @@ sub connect { } $self->{version} = $self->fetchrow_array(); - $self->{output}->output_add(long_msg => "VERSION: " . $self->{version}, debug => 1); + if (defined($self->{container}) and $self->{container} ne '') { + $self->query(query => "alter session set container=$self->{container}"); + } return 0; } diff --git a/centreon-plugins/database/postgres/mode/backends.pm b/centreon-plugins/database/postgres/mode/backends.pm index d367cf488..f766cd3a1 100644 --- a/centreon-plugins/database/postgres/mode/backends.pm +++ b/centreon-plugins/database/postgres/mode/backends.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/postgres/mode/databasesize.pm b/centreon-plugins/database/postgres/mode/databasesize.pm index b5ea7d6d9..c2d626b32 100644 --- a/centreon-plugins/database/postgres/mode/databasesize.pm +++ b/centreon-plugins/database/postgres/mode/databasesize.pm @@ -57,7 +57,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-database:s" => { name => 'filter_database' }, diff --git a/centreon-plugins/database/postgres/mode/hitratio.pm b/centreon-plugins/database/postgres/mode/hitratio.pm index 944921b14..34d207129 100644 --- a/centreon-plugins/database/postgres/mode/hitratio.pm +++ b/centreon-plugins/database/postgres/mode/hitratio.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/postgres/mode/listdatabases.pm b/centreon-plugins/database/postgres/mode/listdatabases.pm index 491c34b2d..a7f77caf2 100644 --- a/centreon-plugins/database/postgres/mode/listdatabases.pm +++ b/centreon-plugins/database/postgres/mode/listdatabases.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "exclude:s" => { name => 'exclude', }, }); diff --git a/centreon-plugins/database/postgres/mode/locks.pm b/centreon-plugins/database/postgres/mode/locks.pm index 4f17ca2da..12bba8fb9 100644 --- a/centreon-plugins/database/postgres/mode/locks.pm +++ b/centreon-plugins/database/postgres/mode/locks.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => ''}, diff --git a/centreon-plugins/database/postgres/mode/querytime.pm b/centreon-plugins/database/postgres/mode/querytime.pm index 3224c170a..3018fd43f 100644 --- a/centreon-plugins/database/postgres/mode/querytime.pm +++ b/centreon-plugins/database/postgres/mode/querytime.pm @@ -30,7 +30,6 @@ sub new { 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', }, diff --git a/centreon-plugins/database/postgres/mode/statistics.pm b/centreon-plugins/database/postgres/mode/statistics.pm index 626acddec..aa348e4fe 100644 --- a/centreon-plugins/database/postgres/mode/statistics.pm +++ b/centreon-plugins/database/postgres/mode/statistics.pm @@ -143,7 +143,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-database:s" => { name => 'filter_database' }, }); diff --git a/centreon-plugins/database/postgres/mode/tablespace.pm b/centreon-plugins/database/postgres/mode/tablespace.pm index 45f1653e7..ba94fe1ee 100644 --- a/centreon-plugins/database/postgres/mode/tablespace.pm +++ b/centreon-plugins/database/postgres/mode/tablespace.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => ''}, diff --git a/centreon-plugins/database/postgres/mode/timesync.pm b/centreon-plugins/database/postgres/mode/timesync.pm index 1354572f9..5fc241234 100644 --- a/centreon-plugins/database/postgres/mode/timesync.pm +++ b/centreon-plugins/database/postgres/mode/timesync.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/postgres/mode/vacuum.pm b/centreon-plugins/database/postgres/mode/vacuum.pm index c241f893f..dc94f1861 100644 --- a/centreon-plugins/database/postgres/mode/vacuum.pm +++ b/centreon-plugins/database/postgres/mode/vacuum.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/sap/hana/mode/blockedtransactions.pm b/centreon-plugins/database/sap/hana/mode/blockedtransactions.pm index 9078ef59b..f52ba84b7 100644 --- a/centreon-plugins/database/sap/hana/mode/blockedtransactions.pm +++ b/centreon-plugins/database/sap/hana/mode/blockedtransactions.pm @@ -48,7 +48,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/sap/hana/mode/connectedusers.pm b/centreon-plugins/database/sap/hana/mode/connectedusers.pm index a5061eb70..274e1a3bd 100644 --- a/centreon-plugins/database/sap/hana/mode/connectedusers.pm +++ b/centreon-plugins/database/sap/hana/mode/connectedusers.pm @@ -55,7 +55,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-username:s" => { name => 'filter_username' }, diff --git a/centreon-plugins/database/sap/hana/mode/diskusage.pm b/centreon-plugins/database/sap/hana/mode/diskusage.pm index 099211c03..37dd29d08 100644 --- a/centreon-plugins/database/sap/hana/mode/diskusage.pm +++ b/centreon-plugins/database/sap/hana/mode/diskusage.pm @@ -117,7 +117,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/database/sap/hana/mode/hostcpu.pm b/centreon-plugins/database/sap/hana/mode/hostcpu.pm index 420af0800..ad560c33e 100644 --- a/centreon-plugins/database/sap/hana/mode/hostcpu.pm +++ b/centreon-plugins/database/sap/hana/mode/hostcpu.pm @@ -101,7 +101,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/database/sap/hana/mode/hostmemory.pm b/centreon-plugins/database/sap/hana/mode/hostmemory.pm index d79ce2aff..3cc6da048 100644 --- a/centreon-plugins/database/sap/hana/mode/hostmemory.pm +++ b/centreon-plugins/database/sap/hana/mode/hostmemory.pm @@ -119,7 +119,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/database/sap/hana/mode/volumeusage.pm b/centreon-plugins/database/sap/hana/mode/volumeusage.pm index c463cb05d..cfe485931 100644 --- a/centreon-plugins/database/sap/hana/mode/volumeusage.pm +++ b/centreon-plugins/database/sap/hana/mode/volumeusage.pm @@ -117,7 +117,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/database/sybase/mode/blockedprocesses.pm b/centreon-plugins/database/sybase/mode/blockedprocesses.pm index 8ead5979a..05f01b374 100644 --- a/centreon-plugins/database/sybase/mode/blockedprocesses.pm +++ b/centreon-plugins/database/sybase/mode/blockedprocesses.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/sybase/mode/connectedusers.pm b/centreon-plugins/database/sybase/mode/connectedusers.pm index 21d9366de..eda6e4ff7 100644 --- a/centreon-plugins/database/sybase/mode/connectedusers.pm +++ b/centreon-plugins/database/sybase/mode/connectedusers.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/database/sybase/mode/databasessize.pm b/centreon-plugins/database/sybase/mode/databasessize.pm index 83baa96d7..9c225c645 100644 --- a/centreon-plugins/database/sybase/mode/databasessize.pm +++ b/centreon-plugins/database/sybase/mode/databasessize.pm @@ -126,7 +126,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-database:s" => { name => 'filter_database' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/database/warp10/sensision/mode/fetchstatistics.pm b/centreon-plugins/database/warp10/sensision/mode/fetchstatistics.pm new file mode 100644 index 000000000..c57b21c2c --- /dev/null +++ b/centreon-plugins/database/warp10/sensision/mode/fetchstatistics.pm @@ -0,0 +1,207 @@ +# +# Copyright 2019 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 database::warp10::sensision::mode::fetchstatistics; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::common::monitoring::openmetrics::scrape; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'fetchs', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All fetchs statistics are ok' }, + ]; + + $self->{maps_counters}->{fetchs} = [ + { label => 'calls-count', nlabel => 'fetch.calls.count', set => { + key_values => [ { name => 'calls', diff => 1 }, { name => 'display' } ], + output_template => 'Calls: %d', + perfdatas => [ + { value => 'calls_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'calls-persecond', nlabel => 'fetch.calls.persecond', set => { + key_values => [ { name => 'calls', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'Calls (per second): %.2f', + perfdatas => [ + { value => 'calls_per_second', template => '%.2f', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'bytes-values-count', nlabel => 'fetch.bytes.values.bytes', set => { + key_values => [ { name => 'bytes_values', diff => 1 }, { name => 'display' } ], + output_template => 'Bytes Values: %s%s', + output_change_bytes => 1, + perfdatas => [ + { value => 'bytes_values_absolute', template => '%s', + min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'bytes-values-persecond', nlabel => 'fetch.bytes.values.bytespersecond', set => { + key_values => [ { name => 'bytes_values', diff => 1 }, { name => 'display' } ], + output_change_bytes => 1, per_second => 1, + output_template => 'Bytes Values (per second): %s%s/s', + perfdatas => [ + { value => 'bytes_values_per_second', template => '%s', + min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'bytes-keys-count', nlabel => 'fetch.bytes.keys.bytes', set => { + key_values => [ { name => 'bytes_keys', diff => 1 }, { name => 'display' } ], + output_template => 'Bytes Keys: %s%s', + output_change_bytes => 1, + perfdatas => [ + { value => 'bytes_keys_absolute', template => '%s', + min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'bytes-keys-persecond', nlabel => 'fetch.bytes.keys.bytespersecond', set => { + key_values => [ { name => 'bytes_keys', diff => 1 }, { name => 'display' } ], + output_change_bytes => 1, per_second => 1, + output_template => 'Bytes Keys (per second): %s%s/s', + perfdatas => [ + { value => 'bytes_keys_per_second', template => '%s', + min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'datapoints-count', nlabel => 'fetch.datapoints.count', set => { + key_values => [ { name => 'datapoints', diff => 1 }, { name => 'display' } ], + output_template => 'Datapoints: %d', + perfdatas => [ + { value => 'datapoints_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'datapoints-persecond', nlabel => 'fetch.datapoints.persecond', set => { + key_values => [ { name => 'datapoints', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'Datapoints (per second): %.2f', + perfdatas => [ + { value => 'datapoints_per_second', template => '%.2f', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Fetch '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = "warp10_" . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + $self->{metrics} = centreon::common::monitoring::openmetrics::scrape::parse(%options); + + foreach my $fetch (@{$self->{metrics}->{'warp.fetch.count'}->{data}}) { + $self->{fetchs}->{$fetch->{dimensions}->{app}}->{calls} = $fetch->{value}; + $self->{fetchs}->{$fetch->{dimensions}->{app}}->{display} = $fetch->{dimensions}->{app}; + } + foreach my $fetch (@{$self->{metrics}->{'warp.fetch.bytes.values'}->{data}}) { + $self->{fetchs}->{$fetch->{dimensions}->{app}}->{bytes_values} = $fetch->{value}; + $self->{fetchs}->{$fetch->{dimensions}->{app}}->{display} = $fetch->{dimensions}->{app}; + } + foreach my $fetch (@{$self->{metrics}->{'warp.fetch.bytes.keys'}->{data}}) { + $self->{fetchs}->{$fetch->{dimensions}->{app}}->{bytes_keys} = $fetch->{value}; + $self->{fetchs}->{$fetch->{dimensions}->{app}}->{display} = $fetch->{dimensions}->{app}; + } + foreach my $fetch (@{$self->{metrics}->{'warp.fetch.datapoints'}->{data}}) { + $self->{fetchs}->{$fetch->{dimensions}->{app}}->{datapoints} = $fetch->{value}; + $self->{fetchs}->{$fetch->{dimensions}->{app}}->{display} = $fetch->{dimensions}->{app}; + } + + foreach (keys %{$self->{fetchs}}) { + delete $self->{fetchs}->{$_} if (defined($self->{option_results}->{filter_name}) && + $self->{option_results}->{filter_name} ne '' && + $_ !~ /$self->{option_results}->{filter_name}/); + } + + if (scalar(keys %{$self->{fetchs}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No fetchs found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check fetchs statistics. + +=over 8 + +=item B<--filter-name> + +Filter app name (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='calls' + +=item B<--warning-*-count/persecond> + +Threshold warning. +Can be: 'calls', 'bytes-values', 'bytes-keys'. + +=item B<--critical-*-count/persecond> + +Threshold critical. +Can be: 'calls', 'bytes-values', 'bytes-keys'. + +=back + +=cut diff --git a/centreon-plugins/database/warp10/sensision/mode/scriptstatistics.pm b/centreon-plugins/database/warp10/sensision/mode/scriptstatistics.pm new file mode 100644 index 000000000..3e083e9b5 --- /dev/null +++ b/centreon-plugins/database/warp10/sensision/mode/scriptstatistics.pm @@ -0,0 +1,248 @@ +# +# Copyright 2019 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 database::warp10::sensision::mode::scriptstatistics; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::common::monitoring::openmetrics::scrape; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'functions', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All functions statistics are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'time-total', nlabel => 'time.total.microseconds', set => { + key_values => [ { name => 'time', diff => 1 } ], + output_template => 'Time Spent: %d us', + perfdatas => [ + { value => 'time_absolute', template => '%d', + min => 0, unit => 'us' }, + ], + } + }, + { label => 'requests-count', nlabel => 'requests.count', set => { + key_values => [ { name => 'requests', diff => 1 } ], + output_template => 'Requests: %d', + perfdatas => [ + { value => 'requests_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'requests-persecond', nlabel => 'requests.persecond', set => { + key_values => [ { name => 'requests', diff => 1 } ], + per_second => 1, + output_template => 'Requests (per second): %.2f', + perfdatas => [ + { value => 'requests_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + { label => 'ops-count', nlabel => 'ops.count', set => { + key_values => [ { name => 'ops', diff => 1 } ], + output_template => 'Ops: %d', + perfdatas => [ + { value => 'ops_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'ops-persecond', nlabel => 'ops.persecond', set => { + key_values => [ { name => 'ops', diff => 1 } ], + per_second => 1, + output_template => 'Ops (per second): %.2f', + perfdatas => [ + { value => 'ops_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + { label => 'errors-count', nlabel => 'errors.count', set => { + key_values => [ { name => 'errors', diff => 1 } ], + output_template => 'Errors: %d', + perfdatas => [ + { value => 'errors_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'errors-persecond', nlabel => 'errors.persecond', set => { + key_values => [ { name => 'errors', diff => 1 } ], + per_second => 1, + output_template => 'Errors (per second): %.2f', + perfdatas => [ + { value => 'errors_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + { label => 'bootstrap-loads-count', nlabel => 'bootstrap.loads.count', set => { + key_values => [ { name => 'bootstrap_loads', diff => 1 } ], + output_template => 'Bootstrap Loads: %d', + perfdatas => [ + { value => 'bootstrap_loads_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'bootstrap-loads-persecond', nlabel => 'bootstrap.loads.persecond', set => { + key_values => [ { name => 'bootstrap_loads', diff => 1 } ], + per_second => 1, + output_template => 'Bootstrap Loads (per second): %.2f', + perfdatas => [ + { value => 'bootstrap_loads_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + ]; + $self->{maps_counters}->{functions} = [ + { label => 'time', nlabel => 'function.time.microseconds', set => { + key_values => [ { name => 'time', diff => 1 }, { name => 'display' } ], + output_template => 'Time Spent: %d us', + perfdatas => [ + { value => 'time_absolute', template => '%d', + min => 0, unit => 'us', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'uses-count', nlabel => 'function.uses.count', set => { + key_values => [ { name => 'count', diff => 1 }, { name => 'display' } ], + output_template => 'Uses: %d', + perfdatas => [ + { value => 'count_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'uses-persecond', nlabel => 'function.uses.persecond', set => { + key_values => [ { name => 'count', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'Uses (per second): %.2f', + perfdatas => [ + { value => 'count_per_second', template => '%.2f', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Function '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = "warp10_" . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + $self->{functions} = {}; + $self->{metrics} = centreon::common::monitoring::openmetrics::scrape::parse(%options); + + $self->{global} = { + time => $self->{metrics}->{'warp.script.time.us'}->{data}[0]->{value}, + requests => $self->{metrics}->{'warp.script.requests'}->{data}[0]->{value}, + ops => $self->{metrics}->{'warp.script.ops'}->{data}[0]->{value}, + errors => $self->{metrics}->{'warp.script.errors'}->{data}[0]->{value}, + bootstrap_loads => $self->{metrics}->{'warp.script.bootstrap.loads'}->{data}[0]->{value}, + }; + + foreach my $function (@{$self->{metrics}->{'warp.script.function.count'}->{data}}) { + $self->{functions}->{$function->{dimensions}->{function}}->{count} = $function->{value}; + $self->{functions}->{$function->{dimensions}->{function}}->{display} = $function->{dimensions}->{function}; + } + foreach my $function (@{$self->{metrics}->{'warp.script.function.time.us'}->{data}}) { + $self->{functions}->{$function->{dimensions}->{function}}->{time} = $function->{value}; + $self->{functions}->{$function->{dimensions}->{function}}->{display} = $function->{dimensions}->{function}; + } + + foreach (keys %{$self->{functions}}) { + delete $self->{functions}->{$_} if (defined($self->{option_results}->{filter_name}) && + $self->{option_results}->{filter_name} ne '' && + $_ !~ /$self->{option_results}->{filter_name}/); + } + + if (scalar(keys %{$self->{functions}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No functions found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check script and functions statistics. + +=over 8 + +=item B<--filter-name> + +Filter function name (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^time$|uses' + +=item B<--warning-*-count/persecond> + +Threshold warning. +Can be: 'time-total' (delta), 'requests', 'ops', +'errors', 'bootstrap-loads', 'time' (delta), 'uses'. + +=item B<--critical-*-count/persecond> + +Threshold critical. +Can be: 'time-total' (delta), 'requests', 'ops', +'errors', 'bootstrap-loads', 'time' (delta), 'uses'. + +=back + +=cut diff --git a/centreon-plugins/database/warp10/sensision/plugin.pm b/centreon-plugins/database/warp10/sensision/plugin.pm new file mode 100644 index 000000000..1c6d06eb6 --- /dev/null +++ b/centreon-plugins/database/warp10/sensision/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2019 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 database::warp10::sensision::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'fetch-statistics' => 'database::warp10::sensision::mode::fetchstatistics', + 'script-statistics' => 'database::warp10::sensision::mode::scriptstatistics', + ); + $self->{custom_modes}{web} = 'centreon::common::monitoring::openmetrics::custom::web'; + $self->{custom_modes}{file} = 'centreon::common::monitoring::openmetrics::custom::file'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Warp10 using Sensision metrics. + +=cut diff --git a/centreon-plugins/docs/fr/developer/guide.rst b/centreon-plugins/docs/fr/developer/guide.rst index 1ad51596b..3ff5b8c41 100644 --- a/centreon-plugins/docs/fr/developer/guide.rst +++ b/centreon-plugins/docs/fr/developer/guide.rst @@ -4,7 +4,7 @@ Description Ce document présente les bonnes pratiques pour le développement de "centreon-plugins". Comme tous les plugins sont écrits en Perl, "There's more than one way to do it". -Afib de ne pas réinventer la roue, vous devriez d'abord regarder le dossier “example”. Vous aurez alors un aperçu de la méthodologie pour construire votre propre plugin ainsi que ses modes associés. +Afin de ne pas réinventer la roue, vous devriez d'abord regarder le dossier “example”. Vous aurez alors un aperçu de la méthodologie pour construire votre propre plugin ainsi que ses modes associés. La dernière version est disponible sur le dépôt git suivant: https://github.com/centreon/centreon-plugins.git @@ -27,7 +27,7 @@ Les répertoires racines sont oganisés par catégorie: * Système d'exploitation : os * Equipement de stockage : storage -Selon l'objet supervisé, il existe une organisation qui peut être utilisé : +Selon l'objet supervisé, il existe une organisation qui peut être utilisée : * Type * Constructeur @@ -225,7 +225,7 @@ Par exemple, les seuils Dégradé (Warning) et Critique (Critical) doivent être Dans cet exemple, l'aide est affichée si les seuils spécifiés ne sont pas au bon format. -Ensuite vient la méthode **run** où sera effectué le traitement, vérifié les seuils et affichés le message de sortie et les données de performance. +Ensuite vient la méthode **run** où le traitement sera effectué, où les seuils seront vérifiés et où le message de sortie et les données de performance seront affichés. Voici un exemple pour vérifier une valeur SNMP : .. code-block:: perl @@ -597,7 +597,7 @@ Paramètres +--------------+--------------+----------+----------------------------------------------------------------------------+ | Paramètre | Type | Défaut | Description | +==============+==============+==========+============================================================================+ -| **oids** | String array | | Tableau d'OIDs à contrôler (Peut être spécifier avec la méthode ``load``). | +| **oids** | String array | | Tableau d'OIDs à contrôler (Peut être spécifié avec la méthode ``load``). | +--------------+--------------+----------+----------------------------------------------------------------------------+ | dont_quit | Int (0 or 1) | 0 | Ne pas quitter pas même si une erreur SNMP se produit. | +--------------+--------------+----------+----------------------------------------------------------------------------+ @@ -695,7 +695,7 @@ Paramètres +-----------------+----------------------+----------------+-----------------------------------------------------------------+ | Paramètre | Type | Défaut | Description | +=================+======================+================+=================================================================+ -| **oid** | String | | OID de la talbe SNMP à récupérer. | +| **oid** | String | | OID de la table SNMP à récupérer. | +-----------------+----------------------+----------------+-----------------------------------------------------------------+ | start | Int | | Premier OID à récupérer. | +-----------------+----------------------+----------------+-----------------------------------------------------------------+ @@ -1462,7 +1462,7 @@ Tout d'abord, créer le dossier du plugin, ainsi que le fichier du plugin : $ touch apps/pfsense/snmp/plugin.pm .. tip:: - PfSense est un pare-feu applicatif et il sera contrôler en utilisant le protocole SNMP + PfSense est un pare-feu applicatif et il sera contrôlé en utilisant le protocole SNMP Ensuite, éditer le fichier **plugin.pm** et ajouter les lignes suivantes : diff --git a/centreon-plugins/docs/fr/user/guide.rst b/centreon-plugins/docs/fr/user/guide.rst index af37347a5..4d8ebc377 100644 --- a/centreon-plugins/docs/fr/user/guide.rst +++ b/centreon-plugins/docs/fr/user/guide.rst @@ -59,7 +59,7 @@ Pour utiliser la fonctionnalité 'memcached', vous devez installer le module CPA Utilisation basique ******************* -Nous allons utiliser un exemple basique pour montrer comment superviser un système. J'ai terminé partie installation et je veux superviser un système Linux par SNMP. +Nous allons utiliser un exemple basique pour montrer comment superviser un système. J'ai terminé la partie installation et je veux superviser un système Linux par SNMP. Tout d'abord, j'ai besoin de trouver le plugin à utiliser dans la liste : :: @@ -485,7 +485,7 @@ Vous pouvez renseigner le serveur memcached avec l'option ``--memcached``: Un fichier local est utilisé si le serveur memcached ne répond pas. -------------------------------------------- -Qu'est-ce que l'option ``--dyn-mode`` fait ? +Quel est l'usage de l'option ``--dyn-mode`` ? -------------------------------------------- Avec cette option, vous pouvez utiliser un mode avec un plugin. Cela est couramment utilisé pour les bases de données. @@ -849,7 +849,7 @@ Pour résoudre le problème, vous devez privilégier le contrôle via NRPE. Pas d'accès en SNMP v3 ^^^^^^^^^^^^^^^^^^^^^^ -Tout d'abord, vous devez valider la connexion SNMP v3 avec snmpwalk. Lorsque cela fonctionne, vous renseignez les options SNMP v3 en ligne de commande. +Tout d'abord, vous devez valider la connexion SNMP v3 avec snmpwalk. Lorsque cela fonctionne, renseignez alors les options SNMP v3 en ligne de commande. L'association entre les options 'snmpwalk' et les options "centreon-plugins" : * -a => ``--authprotocol`` @@ -892,7 +892,7 @@ Le problème peut être: * Un module CPAN prérequis est manquant. Vous devez l'installer. * Le module CPAN ne peut pas être chargé en raison de son chemin d'accès. Les modules Perl doivent être installés dans des chemins spécifiques. -Je ne peux pas vois les messages d'aide +Je ne peux pas voir les messages d'aide ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Les fichiers "centreon-plugins" doivent être sous format Unix (pas de retour à la ligne Windows). Vous pouvez les modifier avec la commande suivante : @@ -1010,7 +1010,7 @@ Le résultat de la commande : Comment modifier la sortie ? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Il existe une section pour modifier la sortie globallement. Il est aussi possible de surcharger une métrique spécifiquement : +Il existe une section pour modifier la sortie de manière globale. Il est aussi possible de surcharger une métrique spécifiquement : :: { @@ -1135,7 +1135,7 @@ Le résultat de la commande : Multi-service plugin -------------------- -Ce mode permet de compiler/aggréger le résultat de plusieurs checks dans un seul. Il peut aussi être utilisé pour réaliser des aggregation dans des groupes logiques, il a été pensé pour récupérer au travers de réseaux bas débit des résultats de contrôle sur des Centreon distants, mais il peut aussi permettre d'éviter de checker deux fois les ressources dans deux Centreon différents. +Ce mode permet de compiler/aggréger le résultat de plusieurs checks dans un seul. Il peut aussi être utilisé pour réaliser des aggregations dans des groupes logiques, il a été pensé pour récupérer au travers de réseaux bas débit des résultats de contrôle sur des Centreon distants, mais il peut aussi permettre d'éviter de vérifier deux fois les ressources dans deux Centreon différents. Format du fichier de configuration ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1166,7 +1166,7 @@ Format du fichier de configuration } * mode (obligatoire) : valeurs possibles: 'sqlmatching' or 'exactmatch'. Liés au format du bloc "selection" ; -* selection (obligatoire) : Lorsque le mode 'sqlmatching' est choisis, on va alors définir les filtres comme ci-dessus (host/service_name_filter). Au contraire, si l'on utilise le mode "exactmatch", alors on passe des clés valeurs correspondant à la correspondant host/service. (Exemple avec deux aggregation logqies "groups" esx-status/load ci-dessous) +* selection (obligatoire) : Lorsque le mode 'sqlmatching' est choisi, on va alors définir les filtres comme ci-dessus (host/service_name_filter). Au contraire, si l'on utilise le mode "exactmatch", alors on passe des clés valeurs correspondant à host/service. (Exemple avec deux aggregations logiques "groups" esx-status/load ci-dessous) :: @@ -1187,7 +1187,7 @@ Format du fichier de configuration }, * counters (optionnel) : Contiens trois booléens, à configurer en 'true' ou 'false' selon les compteurs que l'on veut utiliser et considérer (totalservices, totalhosts, groups). -* formatting (optionnel) : Contiens trois clés/valeurs, 'groups_global_msg' pour définir un statut global lorsque tout va bien, 'host_service_separator' pour choisir le séparateur entre le nom de l'hôte et celui du service dans les éléments de l'output, 'display_details' afin de définir si le plugin doit détailler les hôtes et/ou services en erreur dans l'output étendu (mode verbose) +* formatting (optionnel) : Contient trois clés/valeurs, 'groups_global_msg' pour définir un statut global lorsque tout va bien, 'host_service_separator' pour choisir le séparateur entre le nom de l'hôte et celui du service dans les éléments de l'output, 'display_details' afin de définir si le plugin doit détailler les hôtes et/ou services en erreur dans l'output étendu (mode verbose) Ligne de commande, output, seuils ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/centreon-plugins/example/mode/getvalue.pm b/centreon-plugins/example/mode/getvalue.pm index 304e68526..d88b9d59b 100644 --- a/centreon-plugins/example/mode/getvalue.pm +++ b/centreon-plugins/example/mode/getvalue.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "oid:s" => { name => 'oid' }, diff --git a/centreon-plugins/example/mode/launchcmd.pm b/centreon-plugins/example/mode/launchcmd.pm index b06916574..d0a49f662 100644 --- a/centreon-plugins/example/mode/launchcmd.pm +++ b/centreon-plugins/example/mode/launchcmd.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "cmd:s" => { name => 'cmd' }, diff --git a/centreon-plugins/example/mode/testcustom.pm b/centreon-plugins/example/mode/testcustom.pm index f278a343f..3026b5f8d 100644 --- a/centreon-plugins/example/mode/testcustom.pm +++ b/centreon-plugins/example/mode/testcustom.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 30 } diff --git a/centreon-plugins/hardware/ats/apc/snmp/mode/devicestatus.pm b/centreon-plugins/hardware/ats/apc/snmp/mode/devicestatus.pm index 0ffeaacdb..f7aa0f047 100644 --- a/centreon-plugins/hardware/ats/apc/snmp/mode/devicestatus.pm +++ b/centreon-plugins/hardware/ats/apc/snmp/mode/devicestatus.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ats/apc/snmp/mode/inputlines.pm b/centreon-plugins/hardware/ats/apc/snmp/mode/inputlines.pm index 919e99386..2500e9eac 100644 --- a/centreon-plugins/hardware/ats/apc/snmp/mode/inputlines.pm +++ b/centreon-plugins/hardware/ats/apc/snmp/mode/inputlines.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ats/apc/snmp/mode/outputlines.pm b/centreon-plugins/hardware/ats/apc/snmp/mode/outputlines.pm index c9aabaf08..ec245a99d 100644 --- a/centreon-plugins/hardware/ats/apc/snmp/mode/outputlines.pm +++ b/centreon-plugins/hardware/ats/apc/snmp/mode/outputlines.pm @@ -116,7 +116,6 @@ sub new { 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 => '%{status} =~ /nearoverload/' }, diff --git a/centreon-plugins/hardware/ats/eaton/snmp/mode/inputlines.pm b/centreon-plugins/hardware/ats/eaton/snmp/mode/inputlines.pm index 61bc33582..2d1e947d8 100644 --- a/centreon-plugins/hardware/ats/eaton/snmp/mode/inputlines.pm +++ b/centreon-plugins/hardware/ats/eaton/snmp/mode/inputlines.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ats/eaton/snmp/mode/outputline.pm b/centreon-plugins/hardware/ats/eaton/snmp/mode/outputline.pm index 571b84f4c..44255e8c3 100644 --- a/centreon-plugins/hardware/ats/eaton/snmp/mode/outputline.pm +++ b/centreon-plugins/hardware/ats/eaton/snmp/mode/outputline.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ats/eaton/snmp/mode/system.pm b/centreon-plugins/hardware/ats/eaton/snmp/mode/system.pm index f9c132903..019a31419 100644 --- a/centreon-plugins/hardware/ats/eaton/snmp/mode/system.pm +++ b/centreon-plugins/hardware/ats/eaton/snmp/mode/system.pm @@ -82,7 +82,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "unknown-status:s" => { name => 'unknown_status', default => '' }, "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/acstatus.pm b/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/acstatus.pm index bc76fd530..2bc597956 100644 --- a/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/acstatus.pm +++ b/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/acstatus.pm @@ -64,7 +64,6 @@ sub new { 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 => '%{status} =~ /true/i' }, diff --git a/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/alarmsstatus.pm b/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/alarmsstatus.pm index 58ef680f7..41cf6ea6d 100644 --- a/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/alarmsstatus.pm +++ b/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/alarmsstatus.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/batterystatus.pm b/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/batterystatus.pm index 6b9556ae5..4aaf96184 100644 --- a/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/batterystatus.pm +++ b/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/batterystatus.pm @@ -136,7 +136,6 @@ sub new { 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 => '%{status} =~ /onBattery/i' }, "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /disconnected/i || %{status} =~ /shutdown/i' }, diff --git a/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/loadstatus.pm b/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/loadstatus.pm index d049838e1..3d7989454 100644 --- a/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/loadstatus.pm +++ b/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/loadstatus.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/rectifierstatus.pm b/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/rectifierstatus.pm index c3345a48f..532730215 100644 --- a/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/rectifierstatus.pm +++ b/centreon-plugins/hardware/devices/aeg/acm/snmp/mode/rectifierstatus.pm @@ -101,7 +101,6 @@ sub new { 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 => '%{status} !~ /ok|notInstalled/i' }, diff --git a/centreon-plugins/hardware/devices/camera/hanwha/snmp/mode/components/sdcard.pm b/centreon-plugins/hardware/devices/camera/hanwha/snmp/mode/components/sdcard.pm new file mode 100644 index 000000000..e9151fb1b --- /dev/null +++ b/centreon-plugins/hardware/devices/camera/hanwha/snmp/mode/components/sdcard.pm @@ -0,0 +1,57 @@ +# +# Copyright 2019 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 hardware::devices::camera::hanwha::snmp::mode::components::sdcard; + +use strict; +use warnings; + +my $oid_nwCam = '.1.3.6.1.4.1.36849.1.2'; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking sdcard"); + $self->{components}->{sdcard} = { name => 'sdcard', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'sdcard')); + + my $branch_sdcard_status = '4.3.0'; + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nwCam}})) { + next if ($oid !~ /^$oid_nwCam\.(\d+)\.$branch_sdcard_status$/); + + my $instance = '0'; + my $sdcard_status = $self->{results}->{$oid_nwCam}->{$oid}; + next if ($self->check_filter(section => 'sdcard', instance => $instance)); + + $self->{components}->{sdcard}->{total}++; + $self->{output}->output_add(long_msg => sprintf("sdcard '%s' status is '%s' [instance = %s]", + $instance, $sdcard_status, $instance)); + my $exit = $self->get_severity(section => 'sdcard', instance => $instance, value => $sdcard_status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("sdcard '%s' status is '%s'", $instance, $sdcard_status)); + } + } +} + +1; diff --git a/centreon-plugins/hardware/devices/camera/hanwha/snmp/mode/components/service.pm b/centreon-plugins/hardware/devices/camera/hanwha/snmp/mode/components/service.pm new file mode 100644 index 000000000..f2c680883 --- /dev/null +++ b/centreon-plugins/hardware/devices/camera/hanwha/snmp/mode/components/service.pm @@ -0,0 +1,81 @@ +# +# Copyright 2019 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 hardware::devices::camera::hanwha::snmp::mode::components::service; + +use strict; +use warnings; + +my $services = { + '3.1.1.1' => 'alarmInput1', + '3.1.2.1' => 'alarmInput2', + '3.1.3.1' => 'alarmInput3', + '3.1.4.1' => 'alarmInput4', + '3.2.1.1' => 'relayOutput1', + '3.2.2.1' => 'relayOutput2', + '3.2.3.1' => 'relayOutput3', + '3.2.4.1' => 'relayOutput4', + '3.3.1' => 'motionDetection', + '3.4.1' => 'videoAnalytics', + '3.5.1' => 'faceDetection', + '3.6.1' => 'networkDisconnection', + '3.7.1' => 'tampering', + '3.8.1' => 'audioDetection', + '3.10.1' => 'defocus', + '3.11.1' => 'fogDetection', + '3.12.1' => 'soundClassification', + '3.13.1' => 'shockDetection', + '3.14.1' => 'temperatureDetection', +}; +my $oid_nwCam = '.1.3.6.1.4.1.36849.1.2'; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking services"); + $self->{components}->{service} = { name => 'services', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'service')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nwCam}})) { + next if ($oid !~ /^$oid_nwCam\.(\d+)\.(.*?)\.0$/); + my ($product_id, $service) = ($1, $2); + next if (!defined($services->{$service})); + + my $instance = $services->{$service}; + my $service_status = $self->{results}->{$oid_nwCam}->{$oid}; + my $service_date = defined($self->{results}->{$oid_nwCam}->{$oid_nwCam . '.' . $product_id . '.' . $service . '.1'}) ? + $self->{results}->{$oid_nwCam}->{$oid_nwCam . '.' . $product_id . '.' . $service . '.1'} : '-'; + + next if ($self->check_filter(section => 'service', instance => $instance)); + + $self->{components}->{service}->{total}++; + $self->{output}->output_add(long_msg => sprintf("service '%s' status is '%s' [instance = %s] [date = %s]", + $instance, $service_status, $instance, $service_date)); + my $exit = $self->get_severity(section => 'service', instance => $instance, value => $service_status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("service '%s' status is '%s'", $instance, $service_status)); + } + } +} + +1; diff --git a/centreon-plugins/hardware/devices/camera/hanwha/snmp/mode/hardware.pm b/centreon-plugins/hardware/devices/camera/hanwha/snmp/mode/hardware.pm new file mode 100644 index 000000000..aec345f0f --- /dev/null +++ b/centreon-plugins/hardware/devices/camera/hanwha/snmp/mode/hardware.pm @@ -0,0 +1,100 @@ +# +# Copyright 2019 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 hardware::devices::camera::hanwha::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^service|sdcard$'; + + $self->{cb_hook2} = 'snmp_execute'; + $self->{thresholds} = { + service => [ + ['low', 'OK'], + ['high', 'CRITICAL'], + ], + sdcard => [ + ['normal', 'OK'], + ['fail', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'hardware::devices::camera::hanwha::snmp::mode::components'; + $self->{components_module} = ['service', 'sdcard']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + my $oid_nwCam = '.1.3.6.1.4.1.36849.1.2'; + $self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_nwCam } ]); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, no_performance => 1, no_absent => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'service', 'sdcard'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=instance,relayOutput1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='service,relayOutpu1,OK,high' + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/camera/hanwha/snmp/plugin.pm b/centreon-plugins/hardware/devices/camera/hanwha/snmp/plugin.pm new file mode 100644 index 000000000..d2778de8b --- /dev/null +++ b/centreon-plugins/hardware/devices/camera/hanwha/snmp/plugin.pm @@ -0,0 +1,48 @@ +# +# Copyright 2019 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 hardware::devices::camera::hanwha::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}} = ( + 'hardware' => 'hardware::devices::camera::hanwha::snmp::mode::hardware', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Hanwha camera in SNMP. + +=cut diff --git a/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/mode/globalstatus.pm b/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/mode/globalstatus.pm index 65679a71a..8ce1a958c 100644 --- a/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/mode/globalstatus.pm +++ b/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/mode/globalstatus.pm @@ -90,14 +90,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning-sync-status:s" => { name => 'warning_sync_status', default => '%{sync_status} =~ /Running with autonomy|Free running/i' }, - "critical-sync-status:s" => { name => 'critical_sync_status', default => '%{sync_status} =~ /Server locked|Never synchronized|Server not synchronized/i' }, - "warning-timebase-status:s" => { name => 'warning_timebase_status', default => '%{timebase_status} =~ /^(?!(XO|XO OK|TCXO Precision < 2usec|OCXO Precision < 1usec)$)/i' }, - "critical-timebase-status:s" => { name => 'critical_timebase_status', default => '%{timebase_status} =~ /^XO$/i' }, - }); + $options{options}->add_options(arguments => { + 'warning-sync-status:s' => { name => 'warning_sync_status', default => '%{sync_status} =~ /Running with autonomy|Free running/i' }, + 'critical-sync-status:s' => { name => 'critical_sync_status', default => '%{sync_status} =~ /Server locked|Never synchronized|Server not synchronized/i' }, + 'warning-timebase-status:s' => { name => 'warning_timebase_status', default => '%{timebase_status} =~ /^(?!(XO|XO OK|TCXO Precision < 2usec|OCXO Precision < 1usec)$)/i' }, + 'critical-timebase-status:s' => { name => 'critical_timebase_status', default => '%{timebase_status} =~ /^XO$/i' }, + }); return $self; } @@ -141,18 +139,22 @@ my $mapping = { sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $options{snmp}->get_leef(oids => [ - $mapping->{currentSyncState}->{oid} . '.0', - $mapping->{timeBaseState}->{oid} . '.0', - $mapping->{powerDownFlags}->{oid} . '.0', - $mapping->{ntpRequestsNumber}->{oid} . '.0', - ], - nothing_quit => 1); + my $snmp_result = $options{snmp}->get_leef( + oids => [ + $mapping->{currentSyncState}->{oid} . '.0', + $mapping->{timeBaseState}->{oid} . '.0', + $mapping->{powerDownFlags}->{oid} . '.0', + $mapping->{ntpRequestsNumber}->{oid} . '.0', + ], + nothing_quit => 1 + ); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); - $self->{global} = { sync_status => $result->{currentSyncState}, - timebase_status => $result->{timeBaseState}, - ntp_requests => $result->{ntpRequestsNumber} }; - + $self->{global} = { + sync_status => $result->{currentSyncState}, + timebase_status => $result->{timeBaseState}, + ntp_requests => $result->{ntpRequestsNumber} + }; + $self->{cache_name} = "gorgy_ntpserver_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); } diff --git a/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/mode/gpsstatus.pm b/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/mode/gpsstatus.pm index 72a522c71..e3bbef6a2 100644 --- a/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/mode/gpsstatus.pm +++ b/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/mode/gpsstatus.pm @@ -73,7 +73,6 @@ sub new { 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 => '%{satellites} =~ /No satellites in view/' }, diff --git a/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/mode/ntpperformance.pm b/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/mode/ntpperformance.pm index 1b193bb3e..106f73bbb 100644 --- a/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/mode/ntpperformance.pm +++ b/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/mode/ntpperformance.pm @@ -94,7 +94,6 @@ sub new { 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 => '%{health} !~ /No leap second today/' }, diff --git a/centreon-plugins/hardware/devices/polycom/groupseries/snmp/plugin.pm b/centreon-plugins/hardware/devices/polycom/groupseries/snmp/plugin.pm new file mode 100644 index 000000000..1250ede42 --- /dev/null +++ b/centreon-plugins/hardware/devices/polycom/groupseries/snmp/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2019 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 hardware::devices::polycom::groupseries::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}} = ( + 'hardware' => 'centreon::common::polycom::endpoint::snmp::mode::hardware', + 'videoconferencing' => 'centreon::common::polycom::endpoint::snmp::mode::videoconferencing' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Polycom GroupSeries equipments in SNMP. + +=cut diff --git a/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/hardware.pm b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/hardware.pm index 58c43aac8..e93d27ae2 100644 --- a/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/hardware.pm +++ b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/hardware.pm @@ -79,7 +79,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/hardware/devices/video/appeartv/snmp/mode/alarms.pm b/centreon-plugins/hardware/devices/video/appeartv/snmp/mode/alarms.pm index 0621a8eaa..dd3ead596 100644 --- a/centreon-plugins/hardware/devices/video/appeartv/snmp/mode/alarms.pm +++ b/centreon-plugins/hardware/devices/video/appeartv/snmp/mode/alarms.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-msg:s" => { name => 'filter_msg' }, diff --git a/centreon-plugins/hardware/devices/video/axis/snmp/mode/environment.pm b/centreon-plugins/hardware/devices/video/axis/snmp/mode/environment.pm index 27953df65..a063d1a1f 100644 --- a/centreon-plugins/hardware/devices/video/axis/snmp/mode/environment.pm +++ b/centreon-plugins/hardware/devices/video/axis/snmp/mode/environment.pm @@ -82,7 +82,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/kvm/adder/aim/snmp/mode/deviceusage.pm b/centreon-plugins/hardware/kvm/adder/aim/snmp/mode/deviceusage.pm index bd490ffe0..4f1cb20e2 100644 --- a/centreon-plugins/hardware/kvm/adder/aim/snmp/mode/deviceusage.pm +++ b/centreon-plugins/hardware/kvm/adder/aim/snmp/mode/deviceusage.pm @@ -90,7 +90,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/hardware/kvm/adder/aim/snmp/mode/serverusage.pm b/centreon-plugins/hardware/kvm/adder/aim/snmp/mode/serverusage.pm index 8efacd3bb..0d510de1b 100644 --- a/centreon-plugins/hardware/kvm/adder/aim/snmp/mode/serverusage.pm +++ b/centreon-plugins/hardware/kvm/adder/aim/snmp/mode/serverusage.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/hardware.pm b/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/hardware.pm index 2f3288ca4..c70ef2346 100644 --- a/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/hardware.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/components/humidity.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/humidity.pm index ea1ee4fb5..aad4ab5f5 100644 --- a/centreon-plugins/hardware/pdu/apc/snmp/mode/components/humidity.pm +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/humidity.pm @@ -49,12 +49,12 @@ my $mapping = { my $oid_rPDU2SensorTempHumidityStatusEntry = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1'; sub load { - my (%options) = @_; - - foreach (@{$options{request}}) { + my ($self) = @_; + + foreach (@{$self->{request}}) { return if ($_->{oid} eq $oid_rPDU2SensorTempHumidityStatusEntry); } - push @{$options{request}}, { oid => $oid_rPDU2SensorTempHumidityStatusEntry }; + push @{$self->{request}}, { oid => $oid_rPDU2SensorTempHumidityStatusEntry }; } sub check { diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/components/psu.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/psu.pm index af88b71c3..6d0865207 100644 --- a/centreon-plugins/hardware/pdu/apc/snmp/mode/components/psu.pm +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/psu.pm @@ -37,9 +37,9 @@ my $mapping = { my $oid_rPDUPowerSupplyDevice = '.1.3.6.1.4.1.318.1.1.12.4.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_rPDUPowerSupplyDevice }; + push @{$self->{request}}, { oid => $oid_rPDUPowerSupplyDevice }; } sub check { @@ -70,4 +70,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/temperature.pm index 91256a26c..6a555d0ae 100644 --- a/centreon-plugins/hardware/pdu/apc/snmp/mode/components/temperature.pm +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/temperature.pm @@ -49,12 +49,12 @@ my $mapping = { my $oid_rPDU2SensorTempHumidityStatusEntry = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1'; sub load { - my (%options) = @_; + my ($self) = @_; - foreach (@{$options{request}}) { + foreach (@{$self->{request}}) { return if ($_->{oid} eq $oid_rPDU2SensorTempHumidityStatusEntry); } - push @{$options{request}}, { oid => $oid_rPDU2SensorTempHumidityStatusEntry }; + push @{$self->{request}}, { oid => $oid_rPDU2SensorTempHumidityStatusEntry }; } sub check { diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/hardware.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/hardware.pm index 4b179940e..5eb489514 100644 --- a/centreon-plugins/hardware/pdu/apc/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/hardware.pm @@ -20,279 +20,64 @@ package hardware::pdu::apc::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use centreon::plugins::misc; -my $thresholds = { - humidity => [ - ['notPresent', 'OK'], - ['belowMin', 'CRITICAL'], - ['belowLow', 'WARNING'], - ['normal', 'OK'], - ['aboveHigh', 'WARNING'], - ['aboveMax', 'CRITICAL'], - ], - temperature => [ - ['notPresent', 'OK'], - ['belowMin', 'CRITICAL'], - ['belowLow', 'WARNING'], - ['normal', 'OK'], - ['aboveHigh', 'WARNING'], - ['aboveMax', 'CRITICAL'], - ], - psu => [ - ['ok', 'OK'], - ['failed', 'CRITICAL'], - ['notPresent', 'OK'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^humidity|temperature|psu$'; + $self->{regexp_threshold_numeric_check_section_option} = '^humidity|temperature$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + humidity => [ + ['notPresent', 'OK'], + ['belowMin', 'CRITICAL'], + ['belowLow', 'WARNING'], + ['normal', 'OK'], + ['aboveHigh', 'WARNING'], + ['aboveMax', 'CRITICAL'], + ], + temperature => [ + ['notPresent', 'OK'], + ['belowMin', 'CRITICAL'], + ['belowLow', 'WARNING'], + ['normal', 'OK'], + ['aboveHigh', 'WARNING'], + ['aboveMax', 'CRITICAL'], + ], + psu => [ + ['ok', 'OK'], + ['failed', 'CRITICAL'], + ['notPresent', 'OK'], + ], + }; + + $self->{components_path} = 'hardware::pdu::apc::snmp::mode::components'; + $self->{components_module} = ['psu', 'humidity', 'temperature']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} 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:s@" => { name => 'filter' }, - "absent-problem:s@" => { name => 'absent_problem' }, - "component:s" => { name => 'component', default => '.*' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - "warning:s@" => { name => 'warning' }, - "critical:s@" => { name => 'critical' }, - }); - - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => {}); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{filter} = []; - foreach my $val (@{$self->{option_results}->{filter}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; - } - - $self->{absent_problem} = []; - foreach my $val (@{$self->{option_results}->{absent_problem}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - push @{$self->{absent_problem}}, { filter => $values[0], instance => $values[1] }; - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - if (scalar(@values) < 3) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $instance, $status, $filter); - if (scalar(@values) == 3) { - ($section, $status, $filter) = @values; - $instance = '.*'; - } else { - ($section, $instance, $status, $filter) = @values; - } - if ($section !~ /^humidity|temperature|psu$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'."); - $self->{output}->option_exit(); - } - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; - } - - $self->{numeric_threshold} = {}; - foreach my $option (('warning', 'critical')) { - foreach my $val (@{$self->{option_results}->{$option}}) { - next if (!defined($val) || $val eq ''); - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $instance, $value) = ($1, $2, $3); - if ($section !~ /^humidity|temperature$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my $position = 0; - if (defined($self->{numeric_threshold}->{$section})) { - $position = scalar(@{$self->{numeric_threshold}->{$section}}); - } - if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); - $self->{output}->option_exit(); - } - $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); - push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance }; - } - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $snmp_request = []; - my @components = ('psu', 'humidity', 'temperature'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "hardware::pdu::apc::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "hardware::pdu::apc::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub absent_problem { - my ($self, %options) = @_; - - foreach (@{$self->{absent_problem}}) { - if ($options{section} =~ /$_->{filter}/) { - if (!defined($_->{instance}) || $options{instance} =~ /$_->{instance}/) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Component '%s' instance '%s' is not present", - $options{section}, $options{instance})); - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)")); - $self->{components}->{$options{section}}->{skip}++; - return 1; - } - } - } - - return 0; -} - -sub check_filter { - my ($self, %options) = @_; - - foreach (@{$self->{filter}}) { - if ($options{section} =~ /$_->{filter}/) { - if (!defined($options{instance}) && !defined($_->{instance})) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { - $self->{components}->{$options{section}}->{skip}++ if (defined($self->{components}->{$options{section}})); - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } - } - - return 0; -} - -sub get_severity_numeric { - my ($self, %options) = @_; - my $status = 'OK'; # default - my $thresholds = { warning => undef, critical => undef }; - my $checked = 0; - - if (defined($self->{numeric_threshold}->{$options{section}})) { - my $exits = []; - foreach (@{$self->{numeric_threshold}->{$options{section}}}) { - if ($options{instance} =~ /$_->{instance}/) { - push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); - $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); - $checked = 1; - } - } - $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); - } - - return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i && - (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) { - $status = $_->{status}; - return $status; - } - } - } - my $label = defined($options{label}) ? $options{label} : $options{section}; - foreach (@{$thresholds->{$label}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ @@ -338,6 +123,7 @@ Example: --warning='temperature,.*,30' Set critical threshold for temperatures (syntax: type,instance,threshold) Example: --critical='temperature,.*,40' + =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm index 1867d7141..24c0adcef 100644 --- a/centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm @@ -135,7 +135,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "unknown-bank-status:s" => { name => 'unknown_bank_status', default => '' }, "warning-bank-status:s" => { name => 'warning_bank_status', default => '%{status} =~ /low|nearOverload/i' }, diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm index 9b5bf4ec9..a0a552cdf 100644 --- a/centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm @@ -82,7 +82,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "unknown-status:s" => { name => 'unknown_status', default => '' }, "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/hardware/pdu/clever/snmp/mode/psusage.pm b/centreon-plugins/hardware/pdu/clever/snmp/mode/psusage.pm index 82f7c3682..78cd11460 100644 --- a/centreon-plugins/hardware/pdu/clever/snmp/mode/psusage.pm +++ b/centreon-plugins/hardware/pdu/clever/snmp/mode/psusage.pm @@ -67,7 +67,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm b/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm index 89e35eefb..bfe62f342 100644 --- a/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm +++ b/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm b/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm index cdfce890a..e346db160 100644 --- a/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm +++ b/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm b/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm index ccb26cfe5..2fab06d4e 100644 --- a/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm +++ b/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm b/centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm index 00aea1b93..a06370f3b 100644 --- a/centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm +++ b/centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm @@ -102,7 +102,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/mode/rbusage.pm b/centreon-plugins/hardware/pdu/emerson/snmp/mode/rbusage.pm index baeeb9867..8dce17930 100644 --- a/centreon-plugins/hardware/pdu/emerson/snmp/mode/rbusage.pm +++ b/centreon-plugins/hardware/pdu/emerson/snmp/mode/rbusage.pm @@ -93,7 +93,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/hardware/pdu/raritan/snmp/mode/inletsensors.pm b/centreon-plugins/hardware/pdu/raritan/snmp/mode/inletsensors.pm index 84cf8c90e..83333bdea 100644 --- a/centreon-plugins/hardware/pdu/raritan/snmp/mode/inletsensors.pm +++ b/centreon-plugins/hardware/pdu/raritan/snmp/mode/inletsensors.pm @@ -79,7 +79,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/pdu/raritan/snmp/mode/ocprotsensors.pm b/centreon-plugins/hardware/pdu/raritan/snmp/mode/ocprotsensors.pm index 84e8ca213..19adcd702 100644 --- a/centreon-plugins/hardware/pdu/raritan/snmp/mode/ocprotsensors.pm +++ b/centreon-plugins/hardware/pdu/raritan/snmp/mode/ocprotsensors.pm @@ -79,7 +79,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/pdu/raritan/snmp/mode/outletsensors.pm b/centreon-plugins/hardware/pdu/raritan/snmp/mode/outletsensors.pm index dc6ba649b..680503855 100644 --- a/centreon-plugins/hardware/pdu/raritan/snmp/mode/outletsensors.pm +++ b/centreon-plugins/hardware/pdu/raritan/snmp/mode/outletsensors.pm @@ -79,7 +79,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/pdu/schleifenbauer/gateway/snmp/mode/sensors.pm b/centreon-plugins/hardware/pdu/schleifenbauer/gateway/snmp/mode/sensors.pm index c40b1c5fd..7630871c3 100644 --- a/centreon-plugins/hardware/pdu/schleifenbauer/gateway/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/pdu/schleifenbauer/gateway/snmp/mode/sensors.pm @@ -53,7 +53,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/printers/standard/rfc3805/mode/coverstatus.pm b/centreon-plugins/hardware/printers/standard/rfc3805/mode/coverstatus.pm index 8cf0ae508..e9fbe1088 100644 --- a/centreon-plugins/hardware/printers/standard/rfc3805/mode/coverstatus.pm +++ b/centreon-plugins/hardware/printers/standard/rfc3805/mode/coverstatus.pm @@ -39,7 +39,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/printers/standard/rfc3805/mode/markerimpression.pm b/centreon-plugins/hardware/printers/standard/rfc3805/mode/markerimpression.pm index 554a88136..9350c9e01 100644 --- a/centreon-plugins/hardware/printers/standard/rfc3805/mode/markerimpression.pm +++ b/centreon-plugins/hardware/printers/standard/rfc3805/mode/markerimpression.pm @@ -36,7 +36,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/hardware/printers/standard/rfc3805/mode/markersupply.pm b/centreon-plugins/hardware/printers/standard/rfc3805/mode/markersupply.pm index 718d5cc8a..d24754c0e 100644 --- a/centreon-plugins/hardware/printers/standard/rfc3805/mode/markersupply.pm +++ b/centreon-plugins/hardware/printers/standard/rfc3805/mode/markersupply.pm @@ -44,7 +44,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/hardware/printers/standard/rfc3805/mode/papertray.pm b/centreon-plugins/hardware/printers/standard/rfc3805/mode/papertray.pm index 52f335e75..f109df7cd 100644 --- a/centreon-plugins/hardware/printers/standard/rfc3805/mode/papertray.pm +++ b/centreon-plugins/hardware/printers/standard/rfc3805/mode/papertray.pm @@ -35,7 +35,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/hardware/sensors/akcp/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/akcp/snmp/mode/sensors.pm index 4663beac9..f8e518969 100644 --- a/centreon-plugins/hardware/sensors/akcp/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/sensors/akcp/snmp/mode/sensors.pm @@ -69,7 +69,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/sensors/comet/p8000/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/comet/p8000/snmp/mode/sensors.pm index 9035bc1f0..bbfc3586a 100644 --- a/centreon-plugins/hardware/sensors/comet/p8000/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/sensors/comet/p8000/snmp/mode/sensors.pm @@ -107,7 +107,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/sensors/hwgste/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/hwgste/snmp/mode/sensors.pm index 0d681701a..b6bbb4818 100644 --- a/centreon-plugins/hardware/sensors/hwgste/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/sensors/hwgste/snmp/mode/sensors.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/sensors/jacarta/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/sensors.pm index 5b450f2f5..086f44ca2 100644 --- a/centreon-plugins/hardware/sensors/jacarta/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/sensors.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/sensors.pm index 2ec7f316f..68659c143 100644 --- a/centreon-plugins/hardware/sensors/netbotz/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/sensors.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/humidity.pm b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/humidity.pm index a4a7fc38d..9a21fd097 100644 --- a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/humidity.pm +++ b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/humidity.pm @@ -50,9 +50,9 @@ my $mapping = { my $oid_sensorProbeHumidityEntry = '.1.3.6.1.4.1.3854.1.2.2.1.17.1'; sub load { - my (%options) = @_; - - push @{$options{request}}, { oid => $oid_sensorProbeHumidityEntry, end => $mapping->{sensorProbeHumidityLowCritical}->{oid} }; + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_sensorProbeHumidityEntry, end => $mapping->{sensorProbeHumidityLowCritical}->{oid} }; } sub check { @@ -60,14 +60,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking humidity"); $self->{components}->{humidity} = {name => 'humidity', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'humidity')); + return if ($self->check_filter(section => 'humidity')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeHumidityEntry}})) { next if ($oid !~ /^$mapping->{sensorProbeHumidityPercent}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeHumidityEntry}, instance => $instance); - next if ($self->check_exclude(section => 'humidity', instance => $instance)); + next if ($self->check_filter(section => 'humidity', instance => $instance)); if ($result->{sensorProbeHumidityOnline} =~ /Offline/i) { $self->absent_problem(section => 'humidity', instance => $instance); next; diff --git a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/sp.pm b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/sp.pm index b7a790a23..214e5b64a 100644 --- a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/sp.pm +++ b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/sp.pm @@ -33,23 +33,24 @@ my %map_sp_status = ( my $oid_spStatus = '.1.3.6.1.4.1.3854.1.1.2'; sub load { - my (%options) = @_; - - push @{$options{request}}, { oid => $oid_spStatus }; + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_spStatus }; } sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking sp"); - $self->{components}->{sp} = {name => 'sp', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'sp')); + $self->{components}->{sp} = { name => 'sp', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'sp')); + return if (scalar(keys %{$self->{results}->{$oid_spStatus}}) <= 0); my $instance = 0; my $sp_status = defined($map_sp_status{$self->{results}->{$oid_spStatus}->{$oid_spStatus . '.' . $instance}}) ? $map_sp_status{$self->{results}->{$oid_spStatus}->{$oid_spStatus . '.' . $instance}} : 'unknown'; - return if ($self->check_exclude(section => 'sp', instance => $instance)); + return if ($self->check_filter(section => 'sp', instance => $instance)); return if ($sp_status =~ /noStatus/i && $self->absent_problem(section => 'sp', instance => $instance)); @@ -63,4 +64,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/switch.pm b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/switch.pm index adf941de7..dccd15c5c 100644 --- a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/switch.pm +++ b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/switch.pm @@ -45,9 +45,9 @@ my $mapping = { my $oid_sensorProbeSwitchEntry = '.1.3.6.1.4.1.3854.1.2.2.1.18.1'; sub load { - my (%options) = @_; - - push @{$options{request}}, { oid => $oid_sensorProbeSwitchEntry, end => $mapping->{sensorProbeSwitchOnline}->{oid} }; + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_sensorProbeSwitchEntry, end => $mapping->{sensorProbeSwitchOnline}->{oid} }; } sub check { @@ -55,14 +55,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking switch"); $self->{components}->{switch} = {name => 'switch', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'switch')); + return if ($self->check_filter(section => 'switch')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeSwitchEntry}})) { next if ($oid !~ /^$mapping->{sensorProbeSwitchStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeSwitchEntry}, instance => $instance); - next if ($self->check_exclude(section => 'switch', instance => $instance)); + next if ($self->check_filter(section => 'switch', instance => $instance)); if ($result->{sensorProbeSwitchOnline} =~ /Offline/i) { $self->absent_problem(section => 'switch', instance => $instance); next; @@ -79,4 +79,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/temperature.pm index dd108cb4c..e2610e1e2 100644 --- a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/temperature.pm +++ b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/components/temperature.pm @@ -50,9 +50,9 @@ my $mapping = { my $oid_sensorProbeTempEntry = '.1.3.6.1.4.1.3854.1.2.2.1.16.1'; sub load { - my (%options) = @_; - - push @{$options{request}}, { oid => $oid_sensorProbeTempEntry, end => $mapping->{sensorProbeTempLowCritical}->{oid} }; + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_sensorProbeTempEntry, end => $mapping->{sensorProbeTempLowCritical}->{oid} }; } sub check { @@ -60,14 +60,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking temperatures"); $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'temperature')); + return if ($self->check_filter(section => 'temperature')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeTempEntry}})) { next if ($oid !~ /^$mapping->{sensorProbeTempDegree}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeTempEntry}, instance => $instance); - next if ($self->check_exclude(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance)); if ($result->{sensorProbeTempOnline} =~ /Offline/i) { $self->absent_problem(section => 'temperature', instance => $instance); next; diff --git a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/sensors.pm index 5ac7bd972..540f3e92f 100644 --- a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/sensors.pm @@ -20,244 +20,66 @@ package hardware::sensors::sensorip::snmp::mode::sensors; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use centreon::plugins::misc; -my $thresholds = { - sp => [ - ['noStatus', 'UNKNOWN'], - ['normal', 'OK'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['sensorError', 'CRITICAL'], - ], - switch => [ - ['noStatus', 'UNKNOWN'], - ['normal', 'OK'], - ['highCritical', 'CRITICAL'], - ['lowCritical', 'CRITICAL'], - ['sensorError', 'CRITICAL'], - ['relayOn', 'OK'], - ['relayOff', 'OK'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^sp|temperature|humidity|switch$'; + $self->{regexp_threshold_numeric_check_section_option} = '^humidity|temperature$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + sp => [ + ['noStatus', 'UNKNOWN'], + ['normal', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['sensorError', 'CRITICAL'], + ], + switch => [ + ['noStatus', 'UNKNOWN'], + ['normal', 'OK'], + ['highCritical', 'CRITICAL'], + ['lowCritical', 'CRITICAL'], + ['sensorError', 'CRITICAL'], + ['relayOn', 'OK'], + ['relayOff', 'OK'], + ], + }; + + $self->{components_path} = 'hardware::sensors::sensorip::snmp::mode::components'; + $self->{components_module} = ['sp', 'temperature', 'humidity', 'switch']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} 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 => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => '.*' }, - "absent-problem:s" => { name => 'absent' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - "warning:s@" => { name => 'warning' }, - "critical:s@" => { name => 'critical' }, - }); - - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => {}); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } - - $self->{numeric_threshold} = {}; - foreach my $option (('warning', 'critical')) { - foreach my $val (@{$self->{option_results}->{$option}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $regexp, $value) = ($1, $2, $3); - if ($section !~ /(humidity|temperature)/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: battery or temperature)."); - $self->{output}->option_exit(); - } - my $position = 0; - if (defined($self->{numeric_threshold}->{$section})) { - $position = scalar(@{$self->{numeric_threshold}->{$section}}); - } - if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); - $self->{output}->option_exit(); - } - $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); - push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp }; - } - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $snmp_request = []; - my @components = ('sp', 'temperature', 'humidity', 'switch'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "hardware::sensors::sensorip::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "hardware::sensors::sensorip::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub absent_problem { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{absent}) && - $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Component '%s' instance '%s' is not present", - $options{section}, $options{instance})); - } - - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)")); - $self->{components}->{$options{section}}->{skip}++; - return 1; -} - -sub get_severity_numeric { - my ($self, %options) = @_; - my $status = 'OK'; # default - my $thresholds = { warning => undef, critical => undef }; - my $checked = 0; - - if (defined($self->{numeric_threshold}->{$options{section}})) { - my $exits = []; - foreach (@{$self->{numeric_threshold}->{$options{section}}}) { - if ($options{instance} =~ /$_->{regexp}/) { - push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); - $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); - $checked = 1; - } - } - $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); - } - - return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ =head1 MODE -Check sensor components (Sensor Probe status, Temperatures, Humidity, Switch). +Check sensor components. =over 8 @@ -266,10 +88,10 @@ Check sensor components (Sensor Probe status, Temperatures, Humidity, Switch). Which component to check (Default: '.*'). Can be: 'sp', 'temperature', 'humidity', 'switch'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=psu) -Can also exclude specific instance: --exclude='humidty#0#' +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=humidty,0 =item B<--absent-problem> diff --git a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/contact.pm b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/contact.pm index 65d7cbe43..f62eab4f5 100644 --- a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/contact.pm +++ b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/contact.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/flood.pm b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/flood.pm index f63a5bf85..21b57e373 100644 --- a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/flood.pm +++ b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/flood.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/humidity.pm b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/humidity.pm index 4bc058897..49085714c 100644 --- a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/humidity.pm +++ b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/humidity.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/illumination.pm b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/illumination.pm index 021fb8642..8ce5c3ed6 100644 --- a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/illumination.pm +++ b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/illumination.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/temperature.pm b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/temperature.pm index 770171e59..1fe4e4e22 100644 --- a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/temperature.pm +++ b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/temperature.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/thermistor.pm b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/thermistor.pm index 3eb3586d5..6690ef42d 100644 --- a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/thermistor.pm +++ b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/thermistor.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/voltage.pm b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/voltage.pm index c8365d86b..07847b734 100644 --- a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/voltage.pm +++ b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/mode/voltage.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, diff --git a/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/components/sensors.pm b/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/components/sensors.pm index 06de94951..f95adfc15 100644 --- a/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/components/sensors.pm +++ b/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/components/sensors.pm @@ -33,9 +33,9 @@ my $list_oids = { }; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_control }; + push @{$self->{request}}, { oid => $oid_control }; } sub check { @@ -43,7 +43,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking sensors"); $self->{components}->{sensors} = {name => 'sensors', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'sensors')); + return if ($self->check_filter(section => 'sensors')); foreach my $i (sort keys %{$list_oids}) { if (!defined($self->{results}->{$oid_control}->{'.1.3.6.1.4.1.17095.3.' . ($list_oids->{$i} + 1) . '.0'}) || @@ -56,7 +56,7 @@ sub check { my $name = $self->{results}->{$oid_control}->{'.1.3.6.1.4.1.17095.3.' . ($list_oids->{$i}) . '.0'}; my $value = $self->{results}->{$oid_control}->{'.1.3.6.1.4.1.17095.3.' . ($list_oids->{$i} + 1) . '.0'}; - next if ($self->check_exclude(section => 'sensors', instance => $name)); + next if ($self->check_filter(section => 'sensors', instance => $name)); $self->{components}->{sensors}->{total}++; $self->{output}->output_add(long_msg => sprintf("sensor '%s' value is %s.", @@ -67,11 +67,13 @@ sub check { short_msg => sprintf("sensor '%s' value is %s", $name, $value)); } - $self->{output}->perfdata_add(label => $name, - value => $value, - warning => $warn, - critical => $crit); + $self->{output}->perfdata_add( + label => $name, + value => $value, + warning => $warn, + critical => $crit + ); } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/sensors.pm index fe63815e7..861c78ab7 100644 --- a/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/sensors.pm @@ -20,209 +20,47 @@ package hardware::sensors::serverscheck::sensorgateway::snmp::mode::sensors; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -# After -my $thresholds = { - output => [ - ['open', 'CRITICAL'], - ['close', 'OK'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^sensors$'; + $self->{regexp_threshold_numeric_check_section_option} = '^sensors$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + output => [ + ['open', 'CRITICAL'], + ['close', 'OK'], + ], + }; + + $self->{components_path} = 'hardware::sensors::serverscheck::sensorgateway::snmp::mode::components'; + $self->{components_module} = ['sensors']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} 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 => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => '.*' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - "warning:s@" => { name => 'warning' }, - "critical:s@" => { name => 'critical' }, - }); - - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => {}); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } - - $self->{numeric_threshold} = {}; - foreach my $option (('warning', 'critical')) { - foreach my $val (@{$self->{option_results}->{$option}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $regexp, $value) = ($1, $2, $3); - if ($section !~ /(sensors)/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: sensors)."); - $self->{output}->option_exit(); - } - my $position = 0; - if (defined($self->{numeric_threshold}->{$section})) { - $position = scalar(@{$self->{numeric_threshold}->{$section}}); - } - if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); - $self->{output}->option_exit(); - } - $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); - push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp }; - } - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $snmp_request = []; - my @components = ('sensors'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "hardware::sensors::serverscheck::sensorgateway::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "hardware::sensors::serverscheck::sensorgateway::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub get_severity_numeric { - my ($self, %options) = @_; - my $status = 'OK'; # default - my $thresholds = { warning => undef, critical => undef }; - my $checked = 0; - - if (defined($self->{numeric_threshold}->{$options{section}})) { - my $exits = []; - foreach (@{$self->{numeric_threshold}->{$options{section}}}) { - if ($options{instance} =~ /$_->{regexp}/) { - push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); - $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); - $checked = 1; - } - } - $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); - } - - return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ @@ -238,10 +76,10 @@ Check sensors components (Sensor Probes). Which component to check (Default: '.*'). Can be: 'sensors'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=sensors) -Can also exclude specific instance: --exclude='sensors#Inter#' +Exclude some parts (comma seperated list) (Example: --filter=sensors) +Can also exclude specific instance: --filter=sensors,Inter =item B<--no-component> diff --git a/centreon-plugins/hardware/sensors/temperhum/local/mode/environment.pm b/centreon-plugins/hardware/sensors/temperhum/local/mode/environment.pm index 6893cd470..210fc6011 100644 --- a/centreon-plugins/hardware/sensors/temperhum/local/mode/environment.pm +++ b/centreon-plugins/hardware/sensors/temperhum/local/mode/environment.pm @@ -78,7 +78,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "remote" => { name => 'remote' }, diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/auditlogs.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/auditlogs.pm index e9a5481e9..fe8d50adb 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/auditlogs.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/auditlogs.pm @@ -49,7 +49,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-severity:s@" => { name => 'filter_severity', }, diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm index 1ec4ddd06..f263b0ee4 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm @@ -51,7 +51,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/faults.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/faults.pm index ca4446c48..e103ba4f8 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/faults.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/faults.pm @@ -48,7 +48,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-severity:s@" => { name => 'filter_severity', }, diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/serviceprofile.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/serviceprofile.pm index 402ca8c07..4bc728396 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/serviceprofile.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/serviceprofile.pm @@ -35,7 +35,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/chassis.pm b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/chassis.pm index a36ca0114..739eff057 100644 --- a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/chassis.pm +++ b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/chassis.pm @@ -31,24 +31,24 @@ my $mapping = { my $oid_drsCMCPowerTableEntrydrsCMCPowerTableEntry = '.1.3.6.1.4.1.674.10892.2.4.1.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_drsCMCPowerTableEntrydrsCMCPowerTableEntry }; + push @{$self->{request}}, { oid => $oid_drsCMCPowerTableEntrydrsCMCPowerTableEntry }; } sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking chassis"); - $self->{components}->{chassis} = {name => 'chassis', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'chassis')); + $self->{components}->{chassis} = { name => 'chassis', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'chassis')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_drsCMCPowerTableEntrydrsCMCPowerTableEntry}})) { next if ($oid !~ /^$mapping->{drsWattsReading}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_drsCMCPowerTableEntrydrsCMCPowerTableEntry}, instance => $instance); - next if ($self->check_exclude(section => 'chassis', instance => $instance)); + next if ($self->check_filter(section => 'chassis', instance => $instance)); $self->{components}->{chassis}->{total}++; $self->{output}->output_add(long_msg => sprintf("Chassis '%s': power %s W, current %s A [instance: %s].", diff --git a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/health.pm b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/health.pm index b94ce0aa2..98fb7f6db 100644 --- a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/health.pm +++ b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/health.pm @@ -46,9 +46,9 @@ my $mapping = { my $oid_drsStatusNowGroup = '.1.3.6.1.4.1.674.10892.2.3.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_drsStatusNowGroup, start => $mapping->{drsIOMCurrStatus}->{oid}, end => $mapping->{drsCMCCurrStatus}->{oid} }; + push @{$self->{request}}, { oid => $oid_drsStatusNowGroup, start => $mapping->{drsIOMCurrStatus}->{oid}, end => $mapping->{drsCMCCurrStatus}->{oid} }; } sub check { @@ -56,7 +56,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking health"); $self->{components}->{health} = {name => 'health', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'health')); + return if ($self->check_filter(section => 'health')); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_drsStatusNowGroup}, instance => '0'); foreach my $probe (keys %{$mapping}) { @@ -64,7 +64,7 @@ sub check { $mapping->{$probe}->{oid} =~ /\.(\d+)$/; my $instance = $1; - next if ($self->check_exclude(section => 'health', instance => $instance)); + next if ($self->check_filter(section => 'health', instance => $instance)); $self->{components}->{health}->{total}++; $self->{output}->output_add(long_msg => sprintf("%s is %s [instance: %s].", @@ -80,4 +80,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/psu.pm b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/psu.pm index a0d15df09..56c11eaca 100644 --- a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/psu.pm +++ b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/psu.pm @@ -40,9 +40,9 @@ my $mapping = { my $oid_drsCMCPSUTableEntry = '.1.3.6.1.4.1.674.10892.2.4.2.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_drsCMCPSUTableEntry }; + push @{$self->{request}}, { oid => $oid_drsCMCPSUTableEntry }; } sub check { @@ -50,14 +50,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking power supplies"); $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); + return if ($self->check_filter(section => 'psu')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_drsCMCPSUTableEntry}})) { next if ($oid !~ /^$mapping->{drsPSUMonitoringCapable}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_drsCMCPSUTableEntry}, instance => $instance); - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); next if ($result->{drsPSUMonitoringCapable} !~ /basic/i); $self->{components}->{psu}->{total}++; diff --git a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/temperature.pm index 30aa9e7b1..470ca11f1 100644 --- a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/temperature.pm +++ b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/components/temperature.pm @@ -32,9 +32,9 @@ my $mapping = { my $oid_drsChassisStatusGroup = '.1.3.6.1.4.1.674.10892.2.3'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_drsChassisStatusGroup, start => $mapping->{drsChassisFrontPanelAmbientTemperature}->{oid}, end => $mapping->{drsCMCProcessorTemperature}->{oid} }; + push @{$self->{request}}, { oid => $oid_drsChassisStatusGroup, start => $mapping->{drsChassisFrontPanelAmbientTemperature}->{oid}, end => $mapping->{drsCMCProcessorTemperature}->{oid} }; } sub check { @@ -42,14 +42,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking temperatures"); $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'temperature')); + return if ($self->check_filter(section => 'temperature')); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_drsChassisStatusGroup}, instance => '0'); foreach my $probe (keys %{$mapping}) { next if (!defined($result->{$probe})); - next if ($self->check_exclude(section => 'temperature', instance => $mapping->{$probe}->{instance})); + next if ($self->check_filter(section => 'temperature', instance => $mapping->{$probe}->{instance})); $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => sprintf("%s is %dC [instance: %s].", diff --git a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/hardware.pm index 7c5a9a41d..7f93e0422 100644 --- a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/hardware.pm @@ -20,245 +20,70 @@ package hardware::server::dell::cmc::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; use centreon::plugins::misc; -my $oid_drsProductShortName = '.1.3.6.1.4.1.674.10892.2.1.1.2'; -my $oid_drsChassisServiceTag = '.1.3.6.1.4.1.674.10892.2.1.1.6'; -my $oid_drsFirmwareVersion = '.1.3.6.1.4.1.674.10892.2.1.2.1'; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(health|chassis|temperature|psu)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|psu\.(voltage|power|current)|chassis\.(power|current))$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + health => [ + ['other', 'UNKNOWN'], + ['unknown', 'UNKNOWN'], + ['ok', 'OK'], + ['nonCritical', 'WARNING'], + ['critical', 'CRITICAL'], + ['nonRecoverable', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'hardware::server::dell::cmc::snmp::mode::components'; + $self->{components_module} = ['health', 'chassis', 'temperature', 'psu']; +} -my $thresholds = { - health => [ - ['other', 'UNKNOWN'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], -}; +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); + $self->display_system_information(); +} + +sub display_system_information { + my ($self, %options) = @_; + + my $oid_drsProductShortName = '.1.3.6.1.4.1.674.10892.2.1.1.2.0'; + my $oid_drsChassisServiceTag = '.1.3.6.1.4.1.674.10892.2.1.1.6.0'; + my $oid_drsFirmwareVersion = '.1.3.6.1.4.1.674.10892.2.1.2.1.0'; + + my $snmp_result = $self->{snmp}->get_leef(oids => [$oid_drsProductShortName, $oid_drsChassisServiceTag, $oid_drsFirmwareVersion]); + $self->{output}->output_add( + long_msg => sprintf("Product Name: %s, Service Tag: %s, Firmware Version: %s", + defined($snmp_result->{$oid_drsProductShortName}) ? centreon::plugins::misc::trim($snmp_result->{$oid_drsProductShortName}) : 'unknown', + defined($snmp_result->{$oid_drsChassisServiceTag}) ? $snmp_result->{$oid_drsChassisServiceTag} : 'unknown', + defined($snmp_result->{$oid_drsFirmwareVersion}) ? $snmp_result->{$oid_drsFirmwareVersion} : 'unknown' + ) + ); +} 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 => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => '.*' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - "warning:s@" => { name => 'warning' }, - "critical:s@" => { name => 'critical' }, - }); - - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => {}); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } - - $self->{numeric_threshold} = {}; - foreach my $option (('warning', 'critical')) { - foreach my $val (@{$self->{option_results}->{$option}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $regexp, $value) = ($1, $2, $3); - if ($section !~ /(temperature|psu\.(voltage|power|current)|chassis\.(power|current))/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature, psu.voltage, psu.power, psu.current, chassis.power or chassis.current)."); - $self->{output}->option_exit(); - } - my $position = 0; - if (defined($self->{numeric_threshold}->{$section})) { - $position = scalar(@{$self->{numeric_threshold}->{$section}}); - } - if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); - $self->{output}->option_exit(); - } - $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); - push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp }; - } - } -} - -sub display_system_information { - my ($self, %options) = @_; - - $self->{output}->output_add(long_msg => sprintf("Product Name: %s, Service Tag: %s, Firmware Version: %s", - defined($self->{results}->{$oid_drsProductShortName}->{$oid_drsProductShortName . '.0'}) ? centreon::plugins::misc::trim($self->{results}->{$oid_drsProductShortName}->{$oid_drsProductShortName . '.0'}) : 'unknown', - defined($self->{results}->{$oid_drsChassisServiceTag}->{$oid_drsChassisServiceTag . '.0'}) ? $self->{results}->{$oid_drsChassisServiceTag}->{$oid_drsChassisServiceTag . '.0'} : 'unknown', - defined($self->{results}->{$oid_drsFirmwareVersion}->{$oid_drsFirmwareVersion . '.0'}) ? $self->{results}->{$oid_drsFirmwareVersion}->{$oid_drsFirmwareVersion . '.0'} : 'unknown') - ); -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $snmp_request = [ { oid => $oid_drsProductShortName }, { oid => $oid_drsChassisServiceTag }, { oid => $oid_drsFirmwareVersion } ]; - my @components = ('health', 'chassis', 'temperature', 'psu'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "hardware::server::dell::cmc::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 3) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - $self->display_system_information(); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "hardware::server::dell::cmc::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s]", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub absent_problem { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{absent}) && - $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Component '%s' instance '%s' is not present", - $options{section}, $options{instance})); - } - - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)")); - $self->{components}->{$options{section}}->{skip}++; - return 1; -} - - -sub get_severity_numeric { - my ($self, %options) = @_; - my $status = 'OK'; # default - my $thresholds = { warning => undef, critical => undef }; - my $checked = 0; - - if (defined($self->{numeric_threshold}->{$options{section}})) { - my $exits = []; - foreach (@{$self->{numeric_threshold}->{$options{section}}}) { - if ($options{instance} =~ /$_->{regexp}/) { - push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); - $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); - $checked = 1; - } - } - $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); - } - - return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ @@ -274,10 +99,10 @@ Check Hardware (Health, Temperatures, Power supplies metrics and chassis metrics Which component to check (Default: '.*'). Can be: 'health', 'temperature', 'chassis', 'psu'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fan) -Can also exclude specific instance: --exclude=health#2#,psu#1.1# +Exclude some parts (comma seperated list) (Example: --filter=fan) +Can also exclude specific instance: --filter=health,2 =item B<--no-component> diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/amperage.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/amperage.pm index 8eb118bf4..b01969ba9 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/amperage.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/amperage.pm @@ -63,6 +63,7 @@ sub check { $divisor = 10; } elsif ($result->{amperageProbeType} =~ /amperageProbeTypeIsPowerSupplyWatts|amperageProbeTypeIsSystemWatts/) { $unit = 'W'; + $divisor = 1; } $result->{amperageProbeReading} = (defined($result->{amperageProbeReading})) ? $result->{amperageProbeReading} / $divisor : 'unknown'; $self->{output}->output_add(long_msg => sprintf("amperage '%s' status is '%s' [instance = %s] [state = %s] [value = %s]", diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/globalstatus.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/globalstatus.pm index 19a3733c8..0e1d40d01 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/globalstatus.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/globalstatus.pm @@ -86,7 +86,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "unknown-status:s" => { name => 'unknown_status', default => '%{status} =~ /^unknown/i' }, "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /nonRecoverable|non critical|other/i' }, diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/hardware.pm index a39bfd526..3ea7ffa43 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/hardware.pm @@ -102,7 +102,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/battery.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/battery.pm index ef70600a6..d719f4a44 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/battery.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/battery.pm @@ -47,9 +47,9 @@ my $mapping = { my $oid_batteryTableEntry = '.1.3.6.1.4.1.674.10892.1.600.50.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_batteryTableEntry, start => $mapping->{batteryStatus}->{oid}, end => $mapping->{batteryLocationName}->{oid} }; + push @{$self->{request}}, { oid => $oid_batteryTableEntry, start => $mapping->{batteryStatus}->{oid}, end => $mapping->{batteryLocationName}->{oid} }; } sub check { @@ -57,21 +57,21 @@ sub check { $self->{output}->output_add(long_msg => "Checking batteries"); $self->{components}->{battery} = {name => 'batteries', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'battery')); + return if ($self->check_filter(section => 'battery')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_batteryTableEntry}})) { next if ($oid !~ /^$mapping->{batteryStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_batteryTableEntry}, instance => $instance); - next if ($self->check_exclude(section => 'battery', instance => $instance)); + next if ($self->check_filter(section => 'battery', instance => $instance)); $self->{components}->{battery}->{total}++; $self->{output}->output_add(long_msg => sprintf("Battery '%s' status is '%s' [instance: %s, reading: %s, location: %s]", $instance, $result->{batteryStatus}, $instance, $result->{batteryReading}, $result->{batteryLocationName} )); - my $exit = $self->get_severity(section => 'battery', value => $result->{batteryStatus}); + my $exit = $self->get_severity(label => 'default', section => 'battery', value => $result->{batteryStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Battery '%s' status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/cachebattery.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/cachebattery.pm index 2c15d1458..2f711c8cd 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/cachebattery.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/cachebattery.pm @@ -72,9 +72,9 @@ my $mapping4 = { }; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $mapping->{batteryState}->{oid} }, { oid => $mapping2->{batteryComponentStatus}->{oid} }, + push @{$self->{request}}, { oid => $mapping->{batteryState}->{oid} }, { oid => $mapping2->{batteryComponentStatus}->{oid} }, { oid => $mapping3->{batteryPredictedCapicity}->{oid} }, { oid => $mapping4->{batteryLearnState}->{oid} }; } @@ -83,7 +83,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking cache batteries"); $self->{components}->{cachebattery} = {name => 'cache batteries', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'cachebattery')); + return if ($self->check_filter(section => 'cachebattery')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping2->{batteryComponentStatus}->{oid}}})) { next if ($oid !~ /^$mapping2->{batteryComponentStatus}->{oid}\.(.*)$/); @@ -95,7 +95,7 @@ sub check { $result4->{batteryLearnState} = defined($result4->{batteryLearnState}) ? $result4->{batteryLearnState} : '-'; $result3->{batteryPredictedCapicity} = defined($result3->{batteryPredictedCapicity}) ? $result3->{batteryPredictedCapicity} : '-'; - next if ($self->check_exclude(section => 'cachebattery', instance => $instance)); + next if ($self->check_filter(section => 'cachebattery', instance => $instance)); $self->{components}->{cachebattery}->{total}++; @@ -103,7 +103,7 @@ sub check { $instance, $result2->{batteryComponentStatus}, $instance, $result->{batteryState}, $result4->{batteryLearnState}, $result3->{batteryPredictedCapicity} )); - my $exit = $self->get_severity(section => 'cachebattery', value => $result2->{batteryComponentStatus}); + my $exit = $self->get_severity(label => 'default', section => 'cachebattery', value => $result2->{batteryComponentStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Cache battery '%s' status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/connector.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/connector.pm index 6742566ec..6d288b756 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/connector.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/connector.pm @@ -63,9 +63,9 @@ my $mapping3 = { my $oid_channelEntry = '.1.3.6.1.4.1.674.10893.1.20.130.2.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_channelEntry, start => $mapping->{channelName}->{oid}, end => $mapping->{channelState}->{oid} }, + push @{$self->{request}}, { oid => $oid_channelEntry, start => $mapping->{channelName}->{oid}, end => $mapping->{channelState}->{oid} }, { oid => $mapping2->{channelComponentStatus}->{oid} }, { oid => $mapping3->{channelBusType}->{oid} } ; } @@ -75,7 +75,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking connectors (channels)"); $self->{components}->{connector} = {name => 'connectors', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'connector')); + return if ($self->check_filter(section => 'connector')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping2->{channelComponentStatus}->{oid}}})) { next if ($oid !~ /^$mapping2->{channelComponentStatus}->{oid}\.(.*)$/); @@ -85,7 +85,7 @@ sub check { my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{$mapping3->{channelBusType}->{oid}}, instance => $instance); $result3->{channelBusType} = defined($result3->{channelBusType}) ? $result3->{channelBusType} : '-'; - next if ($self->check_exclude(section => 'connector', instance => $instance)); + next if ($self->check_filter(section => 'connector', instance => $instance)); $self->{components}->{connector}->{total}++; @@ -93,7 +93,7 @@ sub check { $result->{channelName}, $result2->{channelComponentStatus}, $instance, $result->{channelState}, $result3->{channelBusType} )); - my $exit = $self->get_severity(section => 'connector', value => $result2->{channelComponentStatus}); + my $exit = $self->get_severity(label => 'default', section => 'connector', value => $result2->{channelComponentStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Connector '%s' status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/controller.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/controller.pm index b88d6c45c..f4ffa7b1a 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/controller.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/controller.pm @@ -55,9 +55,9 @@ my $mapping4 = { }; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $mapping->{controllerName}->{oid} }, { oid => $mapping2->{controllerComponentStatus}->{oid} }, + push @{$self->{request}}, { oid => $mapping->{controllerName}->{oid} }, { oid => $mapping2->{controllerComponentStatus}->{oid} }, { oid => $mapping3->{controllerState}->{oid} }, { oid => $mapping4->{controllerFWVersion}->{oid} }; } @@ -66,7 +66,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking controllers"); $self->{components}->{controller} = {name => 'controllers', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'controller')); + return if ($self->check_filter(section => 'controller')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping2->{controllerComponentStatus}->{oid}}})) { next if ($oid !~ /^$mapping2->{controllerComponentStatus}->{oid}\.(.*)$/); @@ -76,7 +76,7 @@ sub check { my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{$mapping3->{controllerState}->{oid}}, instance => $instance); my $result4 = $self->{snmp}->map_instance(mapping => $mapping4, results => $self->{results}->{$mapping4->{controllerFWVersion}->{oid}}, instance => $instance); - next if ($self->check_exclude(section => 'controller', instance => $instance)); + next if ($self->check_filter(section => 'controller', instance => $instance)); $self->{components}->{controller}->{total}++; @@ -84,7 +84,7 @@ sub check { $result->{controllerName}, $result2->{controllerComponentStatus}, $instance, $result3->{controllerState}, $result4->{controllerFWVersion} )); - my $exit = $self->get_severity(section => 'controller', value => $result2->{controllerComponentStatus}); + my $exit = $self->get_severity(label => 'default', section => 'controller', value => $result2->{controllerComponentStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Controller '%s' status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/cpu.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/cpu.pm index c68ccab64..785034128 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/cpu.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/cpu.pm @@ -57,9 +57,9 @@ my $mapping4 = { my $oid_processorDeviceTableEntry = '.1.3.6.1.4.1.674.10892.1.1100.30.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $mapping->{processorDeviceStatus}->{oid} }, + push @{$self->{request}}, { oid => $mapping->{processorDeviceStatus}->{oid} }, { oid => $oid_processorDeviceTableEntry, start => $mapping2->{processorDeviceManufacturerName}->{oid}, end => $mapping2->{processorDeviceStatusState}->{oid} }, { oid => $mapping3->{processorDeviceCurrentSpeed}->{oid} }, { oid => $mapping4->{processorDeviceBrandName}->{oid} }; } @@ -69,7 +69,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking processor units"); $self->{components}->{cpu} = {name => 'CPUs', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'cpu')); + return if ($self->check_filter(section => 'cpu')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{processorDeviceStatus}->{oid}}})) { next if ($oid !~ /^$mapping->{processorDeviceStatus}->{oid}\.(.*)$/); @@ -79,7 +79,7 @@ sub check { my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{$mapping3->{processorDeviceCurrentSpeed}->{oid}}, instance => $instance); my $result4 = $self->{snmp}->map_instance(mapping => $mapping4, results => $self->{results}->{$mapping4->{processorDeviceBrandName}->{oid}}, instance => $instance); - next if ($self->check_exclude(section => 'cpu', instance => $instance)); + next if ($self->check_filter(section => 'cpu', instance => $instance)); $self->{components}->{cpu}->{total}++; @@ -89,7 +89,7 @@ sub check { defined($result4->{processorDeviceBrandName}) ? $result4->{processorDeviceBrandName} : '-', $result2->{processorDeviceStatusState}, $result3->{processorDeviceCurrentSpeed} )); - my $exit = $self->get_severity(section => 'cpu', value => $result->{processorDeviceStatus}); + my $exit = $self->get_severity(label => 'default', section => 'cpu', value => $result->{processorDeviceStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Cpu '%s' status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/esmlog.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/esmlog.pm index a3b7873d9..b05c826df 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/esmlog.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/esmlog.pm @@ -38,9 +38,9 @@ my $mapping = { }; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $mapping->{systemStateEventLogStatus}->{oid} }; + push @{$self->{request}}, { oid => $mapping->{systemStateEventLogStatus}->{oid} }; } sub check { @@ -48,21 +48,21 @@ sub check { $self->{output}->output_add(long_msg => "Checking ESM log filling"); $self->{components}->{esmlog} = {name => 'ESM log', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'esmlog')); + return if ($self->check_filter(section => 'esmlog')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{systemStateEventLogStatus}->{oid}}})) { next if ($oid !~ /^$mapping->{systemStateEventLogStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{systemStateEventLogStatus}->{oid}}, instance => $instance); - next if ($self->check_exclude(section => 'globalstatus', instance => $instance)); + next if ($self->check_filter(section => 'globalstatus', instance => $instance)); $self->{components}->{esmlog}->{total}++; $self->{output}->output_add(long_msg => sprintf("ESM '%s' log status is '%s' [instance: %s]", $instance, $result->{systemStateEventLogStatus}, $instance )); - my $exit = $self->get_severity(section => 'esmlog', value => $result->{systemStateEventLogStatus}); + my $exit = $self->get_severity(label => 'default', section => 'esmlog', value => $result->{systemStateEventLogStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("ESM '%s' log status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/fan.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/fan.pm index 815ed3fca..8508f786e 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/fan.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/fan.pm @@ -47,9 +47,9 @@ my $mapping2 = { my $oid_coolingDeviceTableEntry = '.1.3.6.1.4.1.674.10892.1.700.12.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_coolingDeviceTableEntry, start => $mapping->{coolingDeviceStatus}->{oid}, end => $mapping->{coolingDeviceReading}->{oid} }, + push @{$self->{request}}, { oid => $oid_coolingDeviceTableEntry, start => $mapping->{coolingDeviceStatus}->{oid}, end => $mapping->{coolingDeviceReading}->{oid} }, { oid => $mapping2->{coolingDeviceLocationName}->{oid} }; } @@ -58,7 +58,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking fans"); $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fan')); + return if ($self->check_filter(section => 'fan')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_coolingDeviceTableEntry}})) { next if ($oid !~ /^$mapping->{coolingDeviceStatus}->{oid}\.(.*)$/); @@ -66,7 +66,7 @@ sub check { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_coolingDeviceTableEntry}, instance => $instance); my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{coolingDeviceLocationName}->{oid}}, instance => $instance); - next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); $self->{components}->{fan}->{total}++; @@ -74,7 +74,7 @@ sub check { $instance, $result->{coolingDeviceStatus}, $instance, $result2->{coolingDeviceLocationName}, $result->{coolingDeviceReading} )); - my $exit = $self->get_severity(section => 'fan', value => $result->{coolingDeviceStatus}); + my $exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{coolingDeviceStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Fan '%s' status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/globalstatus.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/globalstatus.pm index 2f813fd55..a1184498b 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/globalstatus.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/globalstatus.pm @@ -38,9 +38,9 @@ my $mapping = { }; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $mapping->{globalSystemStatus}->{oid} }; + push @{$self->{request}}, { oid => $mapping->{globalSystemStatus}->{oid} }; } sub check { @@ -48,21 +48,21 @@ sub check { $self->{output}->output_add(long_msg => "Checking global system status"); $self->{components}->{globalstatus} = {name => 'global system status', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'globalstatus')); + return if ($self->check_filter(section => 'globalstatus')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{globalSystemStatus}->{oid}}})) { next if ($oid !~ /^$mapping->{globalSystemStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{globalSystemStatus}->{oid}}, instance => $instance); - next if ($self->check_exclude(section => 'globalstatus', instance => $instance)); + next if ($self->check_filter(section => 'globalstatus', instance => $instance)); $self->{components}->{globalstatus}->{total}++; $self->{output}->output_add(long_msg => sprintf("Chassis '%s' global status is '%s' [instance: %s]", $instance, $result->{globalSystemStatus}, $instance )); - my $exit = $self->get_severity(section => 'globalstatus', value => $result->{globalSystemStatus}); + my $exit = $self->get_severity(label => 'default', section => 'globalstatus', value => $result->{globalSystemStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Chassis '%s' global status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/logicaldrive.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/logicaldrive.pm index e80c5f249..81ae8b4de 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/logicaldrive.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/logicaldrive.pm @@ -84,9 +84,9 @@ my $mapping4 = { my $oid_virtualDiskEntry = '.1.3.6.1.4.1.674.10893.1.20.140.1.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_virtualDiskEntry, start => $mapping->{virtualDiskName}->{oid}, end => $mapping->{virtualDiskState}->{oid} }, + push @{$self->{request}}, { oid => $oid_virtualDiskEntry, start => $mapping->{virtualDiskName}->{oid}, end => $mapping->{virtualDiskState}->{oid} }, { oid => $mapping2->{virtualDiskLengthInMB}->{oid} }, { oid => $mapping3->{virtualDiskLayout}->{oid} }, { oid => $mapping4->{virtualDiskComponentStatus}->{oid} }; } @@ -95,7 +95,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking logical drives"); $self->{components}->{logicaldrive} = {name => 'logical drives', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'logicaldrive')); + return if ($self->check_filter(section => 'logicaldrive')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping4->{virtualDiskComponentStatus}->{oid}}})) { next if ($oid !~ /^$mapping4->{virtualDiskComponentStatus}->{oid}\.(.*)$/); @@ -105,7 +105,7 @@ sub check { my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{$mapping3->{virtualDiskLayout}->{oid}}, instance => $instance); my $result4 = $self->{snmp}->map_instance(mapping => $mapping4, results => $self->{results}->{$mapping4->{virtualDiskComponentStatus}->{oid}}, instance => $instance); - next if ($self->check_exclude(section => 'logicaldrive', instance => $instance)); + next if ($self->check_filter(section => 'logicaldrive', instance => $instance)); $self->{components}->{logicaldrive}->{total}++; @@ -114,7 +114,7 @@ sub check { $result2->{virtualDiskLengthInMB}, $result3->{virtualDiskLayout}, $result->{virtualDiskState}, $result->{virtualDiskDeviceName} )); - my $exit = $self->get_severity(section => 'logicaldrive', value => $result4->{virtualDiskComponentStatus}); + my $exit = $self->get_severity(label => 'default', section => 'logicaldrive', value => $result4->{virtualDiskComponentStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Logical drive '%s' status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/memory.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/memory.pm index 59644e4cc..d5b825e13 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/memory.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/memory.pm @@ -55,9 +55,9 @@ my $mapping4 = { }; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $mapping->{memoryDeviceStatus}->{oid} }, { oid => $mapping2->{memoryDeviceLocationName}->{oid} }, + push @{$self->{request}}, { oid => $mapping->{memoryDeviceStatus}->{oid} }, { oid => $mapping2->{memoryDeviceLocationName}->{oid} }, { oid => $mapping3->{memoryDeviceSize}->{oid} }, { oid => $mapping4->{memoryDeviceFailureModes}->{oid} }; } @@ -67,7 +67,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking memory modules"); $self->{components}->{memory} = {name => 'memory modules', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'memory')); + return if ($self->check_filter(section => 'memory')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{memoryDeviceStatus}->{oid}}})) { next if ($oid !~ /^$mapping->{memoryDeviceStatus}->{oid}\.(.*)$/); @@ -77,7 +77,7 @@ sub check { my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{$mapping3->{memoryDeviceSize}->{oid}}, instance => $instance); my $result4 = $self->{snmp}->map_instance(mapping => $mapping4, results => $self->{results}->{$mapping4->{memoryDeviceFailureModes}->{oid}}, instance => $instance); - next if ($self->check_exclude(section => 'memory', instance => $instance)); + next if ($self->check_filter(section => 'memory', instance => $instance)); $self->{components}->{memory}->{total}++; @@ -85,7 +85,7 @@ sub check { $instance, $result->{memoryDeviceStatus}, $instance, $result2->{memoryDeviceLocationName}, $result3->{memoryDeviceSize}, $result4->{memoryDeviceFailureModes} )); - my $exit = $self->get_severity(section => 'memory', value => $result->{memoryDeviceStatus}); + my $exit = $self->get_severity(label => 'default', section => 'memory', value => $result->{memoryDeviceStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Memory module '%s' status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/physicaldisk.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/physicaldisk.pm index 8a6645045..b5e7f9310 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/physicaldisk.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/physicaldisk.pm @@ -77,9 +77,9 @@ my $mapping5 = { }; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $mapping->{arrayDiskName}->{oid} }, { oid => $mapping2->{arrayDiskState}->{oid} }, + push @{$self->{request}}, { oid => $mapping->{arrayDiskName}->{oid} }, { oid => $mapping2->{arrayDiskState}->{oid} }, { oid => $mapping3->{arrayDiskSpareState}->{oid} }, { oid => $mapping4->{arrayDiskComponentStatus}->{oid} }, { oid => $mapping5->{arrayDiskSmartAlertIndication}->{oid} }; } @@ -90,7 +90,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking physical disks"); $self->{components}->{physicaldisk} = {name => 'physical disks', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'physicaldisk')); + return if ($self->check_filter(section => 'physicaldisk')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping4->{arrayDiskComponentStatus}->{oid}}})) { next if ($oid !~ /^$mapping4->{arrayDiskComponentStatus}->{oid}\.(.*)$/); @@ -101,7 +101,7 @@ sub check { my $result4 = $self->{snmp}->map_instance(mapping => $mapping4, results => $self->{results}->{$mapping4->{arrayDiskComponentStatus}->{oid}}, instance => $instance); my $result5 = $self->{snmp}->map_instance(mapping => $mapping5, results => $self->{results}->{$mapping5->{arrayDiskSmartAlertIndication}->{oid}}, instance => $instance); - next if ($self->check_exclude(section => 'physicaldisk', instance => $instance)); + next if ($self->check_filter(section => 'physicaldisk', instance => $instance)); $self->{components}->{physicaldisk}->{total}++; @@ -110,7 +110,7 @@ sub check { $result2->{arrayDiskState}, $result3->{arrayDiskSpareState}, defined($result5->{arrayDiskSmartAlertIndication}) ? $result5->{arrayDiskSmartAlertIndication} : '-' )); - my $exit = $self->get_severity(section => 'physicaldisk', value => $result4->{arrayDiskComponentStatus}); + my $exit = $self->get_severity(label => 'default', section => 'physicaldisk', value => $result4->{arrayDiskComponentStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Physical Disk '%s' status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/psu.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/psu.pm index e55704144..81cbef87a 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/psu.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/psu.pm @@ -74,9 +74,9 @@ my $oid_powerSupplyTable = '.1.3.6.1.4.1.674.10892.1.600.12'; my $oid_powerSupplyTableEntry = '.1.3.6.1.4.1.674.10892.1.600.12.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_powerSupplyTable, start => $mapping->{powerSupplyStatus}->{oid}, end => $mapping->{powerSupplyLocationName}->{oid} }, + push @{$self->{request}}, { oid => $oid_powerSupplyTable, start => $mapping->{powerSupplyStatus}->{oid}, end => $mapping->{powerSupplyLocationName}->{oid} }, { oid => $oid_powerSupplyTableEntry, start => $mapping2->{powerSupplySensorState}->{oid}, end => $mapping2->{powerSupplyConfigurationErrorType}->{oid} }; } @@ -85,7 +85,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking power supplies"); $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); + return if ($self->check_filter(section => 'psu')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerSupplyTable}})) { next if ($oid !~ /^$mapping->{powerSupplyStatus}->{oid}\.(.*)$/); @@ -94,7 +94,7 @@ sub check { my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_powerSupplyTableEntry}, instance => $instance); $result2->{powerSupplyConfigurationErrorType} = defined($result2->{powerSupplyConfigurationErrorType}) ? $result2->{powerSupplyConfigurationErrorType} : '-'; - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; @@ -104,7 +104,7 @@ sub check { defined($result->{powerSupplyOutputWatts}) ? $result->{powerSupplyOutputWatts} : '-', $result2->{powerSupplySensorState}, $result2->{powerSupplyConfigurationErrorType} )); - my $exit = $self->get_severity(section => 'psu', value => $result->{powerSupplyStatus}); + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{powerSupplyStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Power supply '%s' status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/temperature.pm index e37c7f710..6ad51e1d6 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/temperature.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/components/temperature.pm @@ -52,9 +52,9 @@ my $mapping = { my $oid_temperatureProbeTable = '.1.3.6.1.4.1.674.10892.1.700.20'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_temperatureProbeTable, start => $mapping->{temperatureProbeStatus}->{oid}, end => $mapping->{temperatureProbeLocationName}->{oid} }; + push @{$self->{request}}, { oid => $oid_temperatureProbeTable, start => $mapping->{temperatureProbeStatus}->{oid}, end => $mapping->{temperatureProbeLocationName}->{oid} }; } sub check { @@ -62,14 +62,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking temperatures"); $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'temperature')); + return if ($self->check_filter(section => 'temperature')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_temperatureProbeTable}})) { next if ($oid !~ /^$mapping->{temperatureProbeStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_temperatureProbeTable}, instance => $instance); - next if ($self->check_exclude(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance)); $self->{components}->{temperature}->{total}++; @@ -77,7 +77,7 @@ sub check { $instance, $result->{temperatureProbeStatus}, $instance, $result->{temperatureProbeLocationName}, $result->{temperatureProbeReading} )); - my $exit = $self->get_severity(section => 'temperature', value => $result->{temperatureProbeStatus}); + my $exit = $self->get_severity(label => 'default', section => 'temperature', value => $result->{temperatureProbeStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Temperature '%s' status is '%s'", diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/hardware.pm index faa4272c9..a837b32dc 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/hardware.pm @@ -20,337 +20,71 @@ package hardware::server::dell::openmanage::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; use centreon::plugins::misc; -my $thresholds = { - globalstatus => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - battery => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - cachebattery => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - connector => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - controller => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - controller => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - cpu => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - esmlog => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - fan => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCriticalUpper', 'WARNING'], - ['criticalUpper', 'CRITICAL'], - ['nonRecoverableUpper', 'CRITICAL'], - ['nonCriticalLower', 'WARNING'], - ['criticalLower', 'CRITICAL'], - ['nonRecoverableLower', 'CRITICAL'], - ['failed', 'CRITICAL'] - ], - logicaldrive => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - memory => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - physicaldisk => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - physicaldisk_smartalert => [ - ['yes', 'WARNING'], - ['no', 'OK'], - ], - psu => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCritical', 'WARNING'], - ['critical', 'CRITICAL'], - ['nonRecoverable', 'CRITICAL'], - ], - temperature => [ - ['other', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ['ok', 'OK'], - ['nonCriticalUpper', 'WARNING'], - ['criticalUpper', 'CRITICAL'], - ['nonRecoverableUpper', 'CRITICAL'], - ['nonCriticalLower', 'WARNING'], - ['criticalLower', 'CRITICAL'], - ['nonRecoverableLower', 'CRITICAL'], - ['failed', 'CRITICAL'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = + '^(globalstatus|fan|psu|temperature|cpu|cachebattery|memory|physicaldisk|logicaldrive|esmlog|battery|controller|connector)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan|psu\.power)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['other', 'CRITICAL'], + ['unknown', 'UNKNOWN'], + ['ok', 'OK'], + ['nonCritical', 'WARNING'], # nonCriticalUpper # nonCriticalLower + ['critical', 'CRITICAL'], # criticalUpper + ['nonRecoverable', 'CRITICAL'], # nonRecoverableUpper # nonRecoverableLower + ['failed', 'CRITICAL'] + ], + physicaldisk_smartalert => [ + ['yes', 'WARNING'], + ['no', 'OK'], + ], + }; + + $self->{components_path} = 'hardware::server::dell::openmanage::snmp::mode::components'; + $self->{components_module} = [ + 'globalstatus', 'fan', 'psu', 'temperature', 'cpu', 'cachebattery', 'memory', + 'physicaldisk', 'logicaldrive', 'esmlog', 'battery', 'controller', 'connector' + ]; +} + +sub snmp_execute { + my ($self, %options) = @_; + + # In '10892-MIB' + my $oid_chassisModelName = '.1.3.6.1.4.1.674.10892.1.300.10.1.9'; + + $self->{snmp} = $options{snmp}; + push @{$self->{request}}, { oid => $oid_chassisModelName }; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_chassisModelName}})) { + my $name = defined($self->{results}->{$oid_chassisModelName}->{$oid}) ? + centreon::plugins::misc::trim($self->{results}->{$oid_chassisModelName}->{$oid}) : 'unknown'; + $self->{output}->output_add(long_msg => sprintf("Product Name: %s", $name)); + } +} 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 => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => '.*' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - "warning:s@" => { name => 'warning' }, - "critical:s@" => { name => 'critical' }, - }); - - $self->{components} = {}; + $options{options}->add_options(arguments => {}); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } - - $self->{numeric_threshold} = {}; - foreach my $option (('warning', 'critical')) { - foreach my $val (@{$self->{option_results}->{$option}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $regexp, $value) = ($1, $2, $3); - if ($section !~ /^(temperature|fan|psu\.power)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature, fan, psu.power)."); - $self->{output}->option_exit(); - } - my $position = 0; - if (defined($self->{numeric_threshold}->{$section})) { - $position = scalar(@{$self->{numeric_threshold}->{$section}}); - } - if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); - $self->{output}->option_exit(); - } - $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); - push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp }; - } - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - # In '10892-MIB' - my $oid_chassisModelName = ".1.3.6.1.4.1.674.10892.1.300.10.1.9"; - my $snmp_request = [ { oid => $oid_chassisModelName } ]; - - my @components = ('globalstatus', 'fan', 'psu', 'temperature', 'cpu', 'cachebattery', 'memory', - 'physicaldisk', 'logicaldrive', 'esmlog', 'battery', 'controller', 'connector'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "hardware::server::dell::openmanage::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 1) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_chassisModelName}})) { - my $name = defined($self->{results}->{$oid_chassisModelName}->{$oid}) ? - centreon::plugins::misc::trim($self->{results}->{$oid_chassisModelName}->{$oid}) : 'unknown'; - $self->{output}->output_add(long_msg => sprintf("Product Name: %s", $name)); - } - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "hardware::server::dell::openmanage::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub get_severity_numeric { - my ($self, %options) = @_; - my $status = 'OK'; # default - my $thresholds = { warning => undef, critical => undef }; - my $checked = 0; - - if (defined($self->{numeric_threshold}->{$options{section}})) { - my $exits = []; - foreach (@{$self->{numeric_threshold}->{$options{section}}}) { - if ($options{instance} =~ /$_->{regexp}/) { - push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); - $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); - $checked = 1; - } - } - $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); - } - - return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} 1; __END__ @@ -367,10 +101,10 @@ Which component to check (Default: '.*'). Can be: 'globalstatus', 'fan', 'cpu', 'psu', 'temperature', 'cachebattery', 'physicaldisk', 'logicaldrive', 'battery', 'controller', 'connector'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fan,cpu) -Can also exclude specific instance: --exclude=fan#1#,cpu +Exclude some parts (comma seperated list) (Example: --filter=fan) +Can also exclude specific instance: --filter=fan,1 =item B<--no-component> diff --git a/centreon-plugins/hardware/server/fujitsu/snmp/mode/components/cpu.pm b/centreon-plugins/hardware/server/fujitsu/snmp/mode/components/cpu.pm index d27ac3766..afd9af382 100644 --- a/centreon-plugins/hardware/server/fujitsu/snmp/mode/components/cpu.pm +++ b/centreon-plugins/hardware/server/fujitsu/snmp/mode/components/cpu.pm @@ -45,7 +45,7 @@ my $oid_sc2CPUs = '.1.3.6.1.4.1.231.2.10.2.2.10.6.4.1'; sub load { my ($self) = @_; - + push @{$self->{request}}, { oid => $oid_sc2CPUs, end => $mapping->{sc2}->{sc2cpuStatus} }, { oid => $mapping->{sc}->{cpuStatus}->{oid} }; } diff --git a/centreon-plugins/hardware/server/fujitsu/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/fujitsu/snmp/mode/hardware.pm index d3405edec..32763186a 100644 --- a/centreon-plugins/hardware/server/fujitsu/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/fujitsu/snmp/mode/hardware.pm @@ -130,7 +130,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/blade.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/blade.pm index 53b61bb36..9e5744901 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/blade.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/blade.pm @@ -37,74 +37,72 @@ my %present_map = ( 4 => 'Weird!!!', # for blades it can return 4, which is NOT spesified in MIB ); +my $mapping = { + blade_name => { oid => '.1.3.6.1.4.1.232.22.2.4.1.1.1.4' }, # cpqRackServerBladeName + blade_part => { oid => '.1.3.6.1.4.1.232.22.2.4.1.1.1.6' }, # cpqRackServerBladePartNumber + blade_status => { oid => '.1.3.6.1.4.1.232.22.2.3.1.3.1.11', map => \%map_conditions }, # cpqRackServerBladeStatus (v2) + blade_spare => { oid => '.1.3.6.1.4.1.232.22.2.4.1.1.1.21' }, # cpqRackServerBladeSparePartNumber + blade_productid => { oid => '.1.3.6.1.4.1.232.22.2.4.1.1.1.17' }, # cpqRackServerBladeProductId + blade_diago => { oid => '.1.3.6.1.4.1.232.22.2.4.1.1.1.24' }, # cpqRackServerBladeFaultDiagnosticString (v2) +}; + sub check { my ($self) = @_; $self->{components}->{blade} = {name => 'blades', total => 0, skip => 0}; - $self->{output}->output_add(long_msg => "Checking blades"); - return if ($self->check_exclude(section => 'blade')); + $self->{output}->output_add(long_msg => "checking blades"); + return if ($self->check_filter(section => 'blade')); my $oid_cpqRackServerBladePresent = '.1.3.6.1.4.1.232.22.2.4.1.1.1.12'; - my $oid_cpqRackServerBladeIndex = '.1.3.6.1.4.1.232.22.2.4.1.1.1.3'; - my $oid_cpqRackServerBladeName = '.1.3.6.1.4.1.232.22.2.4.1.1.1.4'; - my $oid_cpqRackServerBladePartNumber = '.1.3.6.1.4.1.232.22.2.4.1.1.1.6'; - my $oid_cpqRackServerBladeSparePartNumber = '.1.3.6.1.4.1.232.22.2.4.1.1.1.7'; - my $oid_cpqRackServerBladeProductId = '.1.3.6.1.4.1.232.22.2.4.1.1.1.17'; - my $oid_cpqRackServerBladeStatus = '.1.3.6.1.4.1.232.22.2.4.1.1.1.21'; # v2 - my $oid_cpqRackServerBladeFaultDiagnosticString = '.1.3.6.1.4.1.232.22.2.4.1.1.1.24'; # v2 - my $result = $self->{snmp}->get_table(oid => $oid_cpqRackServerBladePresent); - return if (scalar(keys %$result) <= 0); + my $snmp_result = $self->{snmp}->get_table(oid => $oid_cpqRackServerBladePresent); + return if (scalar(keys %$snmp_result) <= 0); my @get_oids = (); my @oids_end = (); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { $key =~ /\.([0-9]+)$/; my $oid_end = $1; - next if ($present_map{$result->{$key}} ne 'present' && + next if ($present_map{$snmp_result->{$key}} ne 'present' && $self->absent_problem(section => 'blade', instance => $oid_end)); push @oids_end, $oid_end; - push @get_oids, $oid_cpqRackServerBladeIndex . "." . $oid_end, $oid_cpqRackServerBladeName . "." . $oid_end, - $oid_cpqRackServerBladePartNumber . "." . $oid_end, $oid_cpqRackServerBladeSparePartNumber . "." . $oid_end, - $oid_cpqRackServerBladeProductId . "." . $oid_end, - $oid_cpqRackServerBladeStatus . "." . $oid_end, $oid_cpqRackServerBladeFaultDiagnosticString . "." . $oid_end; + push @get_oids, map($_->{oid} . '.' . $oid_end, values(%$mapping)); } - $result = $self->{snmp}->get_leef(oids => \@get_oids); + $snmp_result = $self->{snmp}->get_leef(oids => \@get_oids); foreach (@oids_end) { - my $blade_index = $result->{$oid_cpqRackServerBladeIndex . '.' . $_}; - my $blade_status = defined($result->{$oid_cpqRackServerBladeStatus . '.' . $_}) ? $result->{$oid_cpqRackServerBladeStatus . '.' . $_} : ''; - my $blade_name = $result->{$oid_cpqRackServerBladeName . '.' . $_}; - my $blade_part = $result->{$oid_cpqRackServerBladePartNumber . '.' . $_}; - my $blade_spare = $result->{$oid_cpqRackServerBladeSparePartNumber . '.' . $_}; - my $blade_productid = $result->{$oid_cpqRackServerBladeProductId . '.' . $_}; - my $blade_diago = defined($result->{$oid_cpqRackServerBladeFaultDiagnosticString . '.' . $_}) ? $result->{$oid_cpqRackServerBladeFaultDiagnosticString . '.' . $_} : ''; - - next if ($self->check_exclude(section => 'blade', instance => $blade_index)); + my $blade_index = $_; + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $blade_index); + next if ($self->check_filter(section => 'blade', instance => $blade_index)); $self->{components}->{blade}->{total}++; - if ($blade_status eq '') { - $self->{output}->output_add(long_msg => sprintf("Skipping Blade %d (%s, %s). Cant get status.", - $blade_index, $blade_name, $blade_productid)); + if (!defined($result->{blade_status})) { + $self->{output}->output_add(long_msg => sprintf("skipping blade '%s' (%s, %s). Cant get status.", + $blade_index, $result->{blade_name}, $result->{blade_productid})); next; } - $self->{output}->output_add(long_msg => sprintf("Blade %d (%s, %s) status is %s [part: %s, spare: %s]%s.", - $blade_index, $blade_name, $blade_productid, - $map_conditions{$blade_status}, - $blade_part, $blade_spare, - ($blade_diago ne '') ? " (Diagnostic '$blade_diago')" : '' - )); - my $exit = $self->get_severity(section => 'blade', value => $map_conditions{$blade_status}); + $self->{output}->output_add( + long_msg => sprintf("blade '%s' (%s, %s) status is %s [part: %s, spare: %s]%s.", + $blade_index, $result->{blade_name}, $result->{blade_productid}, + $result->{blade_status}, + $result->{blade_part}, $result->{blade_spare}, + defined($result->{blade_diago}) ? " (Diagnostic '$result->{blade_diago}')" : '' + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'blade', instance => $blade_index, value => $result->{blade_status}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Blade %d (%s, %s) status is %s", - $blade_index, $blade_name, $blade_productid, - $map_conditions{$blade_status} - )); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Blade '%s' (%s, %s) status is %s", + $blade_index, $result->{blade_name}, $result->{blade_productid}, + $result->{blade_status} + ) + ); } } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/enclosure.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/enclosure.pm index 6f89151c4..a08fa668b 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/enclosure.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/enclosure.pm @@ -23,42 +23,65 @@ package hardware::server::hp::bladechassis::snmp::mode::components::enclosure; use strict; use warnings; -my %map_conditions = ( +my $map_conditions = { 1 => 'other', 2 => 'ok', 3 => 'degraded', 4 => 'failed', -); +}; + +my $mapping = { + cpqRackCommonEnclosureSparePartNumber => { oid => '.1.3.6.1.4.1.232.22.2.3.1.1.1.6' }, + cpqRackCommonEnclosureSerialNum => { oid => '.1.3.6.1.4.1.232.22.2.3.1.1.1.7' }, + cpqRackCommonEnclosureFWRev => { oid => '.1.3.6.1.4.1.232.22.2.3.1.1.1.8' }, + cpqRackCommonEnclosureCondition => { oid => '.1.3.6.1.4.1.232.22.2.3.1.1.1.16', map => $map_conditions }, +}; sub check { my ($self) = @_; - - my $oid_cpqRackCommonEnclosurePartNumber = '.1.3.6.1.4.1.232.22.2.3.1.1.1.5.1'; - my $oid_cpqRackCommonEnclosureSparePartNumber = '.1.3.6.1.4.1.232.22.2.3.1.1.1.6.1'; - my $oid_cpqRackCommonEnclosureSerialNum = '.1.3.6.1.4.1.232.22.2.3.1.1.1.7.1'; - my $oid_cpqRackCommonEnclosureFWRev = '.1.3.6.1.4.1.232.22.2.3.1.1.1.8.1'; - my $oid_cpqRackCommonEnclosureCondition = '.1.3.6.1.4.1.232.22.2.3.1.1.1.16.1'; $self->{components}->{enclosure} = {name => 'enclosure', total => 0, skip => 0}; - $self->{output}->output_add(long_msg => "Checking enclosure"); - return if ($self->check_exclude(section => 'enclosure')); - - my $result = $self->{snmp}->get_leef(oids => [$oid_cpqRackCommonEnclosurePartNumber, $oid_cpqRackCommonEnclosureSparePartNumber, - $oid_cpqRackCommonEnclosureSerialNum, $oid_cpqRackCommonEnclosureFWRev, - $oid_cpqRackCommonEnclosureCondition], nothing_quit => 1); - $self->{components}->{enclosure}->{total}++; - - $self->{output}->output_add(long_msg => sprintf("Enclosure overall health condition is %s [part: %s, spare: %s, sn: %s, fw: %s].", - $map_conditions{$result->{$oid_cpqRackCommonEnclosureCondition}}, - $result->{$oid_cpqRackCommonEnclosurePartNumber}, - $result->{$oid_cpqRackCommonEnclosureSparePartNumber}, - $result->{$oid_cpqRackCommonEnclosureSerialNum}, - $result->{$oid_cpqRackCommonEnclosureFWRev})); - my $exit = $self->get_severity(section => 'enclosure', value => $map_conditions{$result->{$oid_cpqRackCommonEnclosureCondition}}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Enclosure overall health condition is %s", $map_conditions{$result->{$oid_cpqRackCommonEnclosureCondition}})); + $self->{output}->output_add(long_msg => "checking enclosure"); + return if ($self->check_filter(section => 'enclosure')); + + my $oid_cpqRackCommonEnclosurePartNumber = '.1.3.6.1.4.1.232.22.2.3.1.1.1.5'; + my $snmp_result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosurePartNumber); + return if (scalar(keys %$snmp_result) <= 0); + + my @get_oids = (); + my @oids_end = (); + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { + $key =~ /^$oid_cpqRackCommonEnclosurePartNumber\.(.*)$/; + my $oid_end = $1; + push @oids_end, $oid_end; + push @get_oids, map($_->{oid} . '.' . $oid_end, values(%$mapping)); + } + + my $snmp_result2 = $self->{snmp}->get_leef(oids => \@get_oids); + foreach (@oids_end) { + my $instance = $_; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result2, instance => $instance); + + next if ($self->check_filter(section => 'enclosure', instance => $instance)); + + $self->{components}->{enclosure}->{total}++; + + $self->{output}->output_add(long_msg => + sprintf("enclosure '%s' overall health condition is %s [part: %s, spare: %s, sn: %s, fw: %s].", + $instance, + $result->{cpqRackCommonEnclosureCondition}, + $snmp_result->{$oid_cpqRackCommonEnclosurePartNumber . '.' . $instance}, + $result->{cpqRackCommonEnclosureSparePartNumber}, + $result->{cpqRackCommonEnclosureSerialNum}, + $result->{cpqRackCommonEnclosureFWRev} + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'enclosure', value => $result->{cpqRackCommonEnclosureCondition}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Enclosure '%s' overall health condition is %s", $instance, $result->{cpqRackCommonEnclosureCondition})); + } } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/fan.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/fan.pm index edc57df54..4a011cb2c 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/fan.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/fan.pm @@ -37,53 +37,53 @@ my %present_map = ( 4 => 'Weird!!!', # for blades it can return 4, which is NOT spesified in MIB ); +my $mapping = { + fan_part => { oid => '.1.3.6.1.4.1.232.22.2.3.1.3.1.6' }, # cpqRackCommonEnclosureFanPartNumber + fan_spare => { oid => '.1.3.6.1.4.1.232.22.2.3.1.3.1.7' }, # cpqRackCommonEnclosureFanSparePartNumber + fan_condition => { oid => '.1.3.6.1.4.1.232.22.2.3.1.3.1.11', map => \%map_conditions }, # cpqRackCommonEnclosureFanCondition +}; + sub check { my ($self) = @_; $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - $self->{output}->output_add(long_msg => "Checking fans"); - return if ($self->check_exclude(section => 'fan')); + $self->{output}->output_add(long_msg => "checking fans"); + return if ($self->check_filter(section => 'fan')); my $oid_cpqRackCommonEnclosureFanPresent = '.1.3.6.1.4.1.232.22.2.3.1.3.1.8'; - my $oid_cpqRackCommonEnclosureFanIndex = '.1.3.6.1.4.1.232.22.2.3.1.3.1.3'; - my $oid_cpqRackCommonEnclosureFanPartNumber = '.1.3.6.1.4.1.232.22.2.3.1.3.1.6'; - my $oid_cpqRackCommonEnclosureFanSparePartNumber = '.1.3.6.1.4.1.232.22.2.3.1.3.1.7'; - my $oid_cpqRackCommonEnclosureFanCondition = '.1.3.6.1.4.1.232.22.2.3.1.3.1.11'; - my $result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosureFanPresent); - return if (scalar(keys %$result) <= 0); + my $snmp_result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosureFanPresent); + return if (scalar(keys %$snmp_result) <= 0); my @get_oids = (); my @oids_end = (); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { $key =~ /\.([0-9]+)$/; my $oid_end = $1; - next if ($present_map{$result->{$key}} ne 'present' && + next if ($present_map{$snmp_result->{$key}} ne 'present' && $self->absent_problem(section => 'fan', instance => $oid_end)); push @oids_end, $oid_end; - push @get_oids, $oid_cpqRackCommonEnclosureFanIndex . "." . $oid_end, $oid_cpqRackCommonEnclosureFanPartNumber . "." . $oid_end, - $oid_cpqRackCommonEnclosureFanSparePartNumber . "." . $oid_end, $oid_cpqRackCommonEnclosureFanCondition . "." . $oid_end; + push @get_oids, map($_->{oid} . '.' . $oid_end, values(%$mapping)); } - $result = $self->{snmp}->get_leef(oids => \@get_oids); + $snmp_result = $self->{snmp}->get_leef(oids => \@get_oids); foreach (@oids_end) { - my $fan_index = $result->{$oid_cpqRackCommonEnclosureFanIndex . '.' . $_}; - my $fan_condition = $result->{$oid_cpqRackCommonEnclosureFanCondition . '.' . $_}; - my $fan_part = $result->{$oid_cpqRackCommonEnclosureFanPartNumber . '.' . $_}; - my $fan_spare = $result->{$oid_cpqRackCommonEnclosureFanSparePartNumber . '.' . $_}; - - next if ($self->check_exclude(section => 'fan', instance => $fan_index)); + my $fan_index = $_; + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $fan_index); + next if ($self->check_filter(section => 'fan', instance => $fan_index)); + $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan %d condition is %s [part: %s, spare: %s].", - $fan_index, $map_conditions{$fan_condition}, - $fan_part, $fan_spare)); - my $exit = $self->get_severity(section => 'fan', value => $map_conditions{$fan_condition}); + $self->{output}->output_add(long_msg => sprintf("fan '%s' condition is %s [part: %s, spare: %s].", + $fan_index, $result->{fan_condition}, + $result->{fan_part}, $result->{fan_spare})); + my $exit = $self->get_severity(label => 'default', section => 'fan', instance => $fan_index, value => $result->{fan_condition}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Fan %d condition is %s", $fan_index, $map_conditions{$fan_condition})); + short_msg => sprintf("Fan '%s' condition is %s", $fan_index, $result->{fan_condition})); } } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/fuse.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/fuse.pm index f606f6746..79286a2f6 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/fuse.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/fuse.pm @@ -37,54 +37,55 @@ my %present_map = ( 4 => 'Weird!!!', # for blades it can return 4, which is NOT spesified in MIB ); +my $mapping = { + fuse_name => { oid => '.1.3.6.1.4.1.232.22.2.3.1.4.1.4' }, # cpqRackCommonEnclosureFuseEnclosureName + fuse_location => { oid => '.1.3.6.1.4.1.232.22.2.3.1.4.1.5' }, # cpqRackCommonEnclosureFuseLocation + fuse_condition => { oid => '.1.3.6.1.4.1.232.22.2.3.1.4.1.7', map => \%map_conditions }, # cpqRackCommonEnclosureFuseCondition +}; + sub check { my ($self) = @_; $self->{components}->{fuse} = {name => 'fuses', total => 0, skip => 0}; - $self->{output}->output_add(long_msg => "Checking fuse"); - return if ($self->check_exclude(section => 'fuse')); + $self->{output}->output_add(long_msg => "checking fuse"); + return if ($self->check_filter(section => 'fuse')); my $oid_cpqRackCommonEnclosureFusePresent = '.1.3.6.1.4.1.232.22.2.3.1.4.1.6'; - my $oid_cpqRackCommonEnclosureFuseIndex = '.1.3.6.1.4.1.232.22.2.3.1.4.1.3'; - my $oid_cpqRackCommonEnclosureFuseEnclosureName = '.1.3.6.1.4.1.232.22.2.3.1.4.1.4'; - my $oid_cpqRackCommonEnclosureFuseLocation = '.1.3.6.1.4.1.232.22.2.3.1.4.1.5'; - my $oid_cpqRackCommonEnclosureFuseCondition = '.1.3.6.1.4.1.232.22.2.3.1.4.1.7'; - my $result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosureFusePresent); - return if (scalar(keys %$result) <= 0); + my $snmp_result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosureFusePresent); + return if (scalar(keys %$snmp_result) <= 0); + my @get_oids = (); my @oids_end = (); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /\.([0-9]+)$/; + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { + $key =~ /^$oid_cpqRackCommonEnclosureFusePresent\.(.*)$/; my $oid_end = $1; - next if ($present_map{$result->{$key}} ne 'present' && + next if ($present_map{$snmp_result->{$key}} ne 'present' && $self->absent_problem(section => 'fuse', instance => $oid_end)); push @oids_end, $oid_end; - push @get_oids, $oid_cpqRackCommonEnclosureFuseIndex . "." . $oid_end, $oid_cpqRackCommonEnclosureFuseEnclosureName . "." . $oid_end, - $oid_cpqRackCommonEnclosureFuseLocation . "." . $oid_end, $oid_cpqRackCommonEnclosureFuseCondition . "." . $oid_end; + push @get_oids, map($_->{oid} . '.' . $oid_end, values(%$mapping)); } - $result = $self->{snmp}->get_leef(oids => \@get_oids); + + $snmp_result = $self->{snmp}->get_leef(oids => \@get_oids); foreach (@oids_end) { - my $fuse_index = $result->{$oid_cpqRackCommonEnclosureFuseIndex . '.' . $_}; - my $fuse_name = $result->{$oid_cpqRackCommonEnclosureFuseEnclosureName . '.' . $_}; - my $fuse_location = $result->{$oid_cpqRackCommonEnclosureFuseLocation . '.' . $_}; - my $fuse_condition = $result->{$oid_cpqRackCommonEnclosureFuseCondition . '.' . $_}; + my $fuse_index = $_; - next if ($self->check_exclude(section => 'fuse', instance => $fuse_index)); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $fuse_index); + next if ($self->check_filter(section => 'fuse', instance => $fuse_index)); $self->{components}->{fuse}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fuse %d status is %s [name: %s, location: %s].", - $fuse_index, $map_conditions{$fuse_condition}, - $fuse_name, $fuse_location)); - my $exit = $self->get_severity(section => 'fuse', value => $map_conditions{$fuse_condition}); + $self->{output}->output_add(long_msg => sprintf("fuse '%s' status is %s [name: %s, location: %s].", + $fuse_index, $result->{fuse_condition}, + $result->{fuse_name}, $result->{fuse_location})); + my $exit = $self->get_severity(label => 'default', section => 'fuse', instance => $fuse_index, value => $result->{fuse_condition}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Fuse %d status is %s", - $fuse_index, $map_conditions{$fuse_condition})); + short_msg => sprintf("Fuse '%s' status is %s", + $fuse_index, $result->{fuse_condition})); } } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/manager.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/manager.pm index ddbaf03f3..e1a06a877 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/manager.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/manager.pm @@ -31,69 +31,57 @@ my %map_conditions = ( 4 => 'failed', ); -my %conditions = ( - 0 => ['other', 'UNKNOWN'], # maybe on standby mode only!! - 1 => ['other', 'CRITICAL'], - 2 => ['ok', 'OK'], - 3 => ['degraded', 'WARNING'], - 4 => ['failed', 'CRITICAL'], -); - my %map_role = ( 1 => 'Standby', 2 => 'Active', ); +my $mapping = { + man_part => { oid => '.1.3.6.1.4.1.232.22.2.3.1.6.1.6' }, # cpqRackCommonEnclosureManagerPartNumber + man_spare => { oid => '.1.3.6.1.4.1.232.22.2.3.1.6.1.7' }, # cpqRackCommonEnclosureManagerSparePartNumber + man_serial => { oid => '.1.3.6.1.4.1.232.22.2.3.1.6.1.8' }, # cpqRackCommonEnclosureManagerSerialNum + man_role => { oid => '.1.3.6.1.4.1.232.22.2.3.1.6.1.9', map => \%map_role }, # cpqRackCommonEnclosureManagerRole + man_condition => { oid => '.1.3.6.1.4.1.232.22.2.3.1.6.1.12', map => \%map_conditions }, # cpqRackCommonEnclosureManagerConditio +}; + sub check { my ($self, %options) = @_; - $self->{components}->{manager} = {name => 'managers', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'manager')); + $self->{components}->{manager} = { name => 'managers', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'manager')); + $self->{output}->output_add(long_msg => "checking managers"); - # No check if OK - if ((!defined($options{force}) || $options{force} != 1) && $self->{output}->is_status(compare => 'ok', litteral => 1)) { - return ; - } - $self->{output}->output_add(long_msg => "Checking managers"); - my $oid_cpqRackCommonEnclosureManagerIndex = '.1.3.6.1.4.1.232.22.2.3.1.6.1.3'; - my $oid_cpqRackCommonEnclosureManagerPartNumber = '.1.3.6.1.4.1.232.22.2.3.1.6.1.6'; - my $oid_cpqRackCommonEnclosureManagerSparePartNumber = '.1.3.6.1.4.1.232.22.2.3.1.6.1.7'; - my $oid_cpqRackCommonEnclosureManagerSerialNum = '.1.3.6.1.4.1.232.22.2.3.1.6.1.8'; - my $oid_cpqRackCommonEnclosureManagerRole = '.1.3.6.1.4.1.232.22.2.3.1.6.1.9'; - my $oid_cpqRackCommonEnclosureManagerCondition = '.1.3.6.1.4.1.232.22.2.3.1.6.1.12'; + my $snmp_result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosureManagerIndex); + return if (scalar(keys %$snmp_result) <= 0); - my $result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosureManagerIndex); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_cpqRackCommonEnclosureManagerPartNumber, $oid_cpqRackCommonEnclosureManagerSparePartNumber, - $oid_cpqRackCommonEnclosureManagerSerialNum, $oid_cpqRackCommonEnclosureManagerRole, - $oid_cpqRackCommonEnclosureManagerCondition], - instances => [keys %$result]); - my $result2 = $self->{snmp}->get_leef(); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)$/; - my $instance = $1; - - my $man_part = $result2->{$oid_cpqRackCommonEnclosureManagerPartNumber . '.' . $instance}; - my $man_spare = $result2->{$oid_cpqRackCommonEnclosureManagerSparePartNumber . '.' . $instance}; - my $man_serial = $result2->{$oid_cpqRackCommonEnclosureManagerSerialNum . '.' . $instance}; - my $man_role = $result2->{$oid_cpqRackCommonEnclosureManagerRole . '.' . $instance}; - my $man_condition = $result2->{$oid_cpqRackCommonEnclosureManagerCondition . '.' . $instance}; + my @get_oids = (); + my @oids_end = (); + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { + $key =~ /^$oid_cpqRackCommonEnclosureManagerIndex\.(.*)$/; + my $oid_end = $1; + push @oids_end, $oid_end; + push @get_oids, map($_->{oid} . '.' . $oid_end, values(%$mapping)); + } + + $snmp_result = $self->{snmp}->get_leef(oids => \@get_oids); + foreach (@oids_end) { + my $instance = $_; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - next if ($self->check_exclude(section => 'manager', instance => $instance)); + next if ($self->check_filter(section => 'manager', instance => $instance)); $self->{components}->{manager}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Enclosure management module %d is %s, status is %s [serial: %s, part: %s, spare: %s].", - $instance, $map_conditions{$man_condition}, $map_role{$man_role}, - $man_serial, $man_part, $man_spare)); - my $exit = $self->get_severity(section => 'manager', value => $map_conditions{$man_condition}); - if ($man_role == 2 && !$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(long_msg => sprintf("enclosure management module '%s' is %s, status is %s [serial: %s, part: %s, spare: %s].", + $instance, $result->{man_condition}, $result->{man_role}, + $result->{man_serial}, $result->{man_part}, $result->{man_spare})); + my $exit = $self->get_severity(label => 'default', section => 'manager', instance => $instance, value => $result->{man_condition}); + if ($result->{man_role} eq 'Active' && !$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Enclosure management module %d is %s, status is %s", - $instance, $map_conditions{$man_condition}, $map_role{$man_role})); + short_msg => sprintf("Enclosure management module '%s' is %s, status is %s", + $instance, $result->{man_condition}, $result->{man_role})); } } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/network.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/network.pm index ff57d7a29..51b012899 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/network.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/network.pm @@ -39,53 +39,51 @@ my %device_type = ( 6 => 'pciexpress', ); +my $mapping = { + nc_model => { oid => '.1.3.6.1.4.1.232.22.2.6.1.1.1.6' }, # cpqRackNetConnectorModel + nc_serial => { oid => '.1.3.6.1.4.1.232.22.2.6.1.1.1.7' }, # cpqRackNetConnectorSerialNum + nc_part => { oid => '.1.3.6.1.4.1.232.22.2.6.1.1.1.8' }, # cpqRackNetConnectorPartNumber + nc_spare => { oid => '.1.3.6.1.4.1.232.22.2.6.1.1.1.9' }, # cpqRackNetConnectorSparePartNumber + nc_device => { oid => '.1.3.6.1.4.1.232.22.2.6.1.1.1.17', map => \%device_type }, # cpqRackNetConnectorDeviceType +}; + sub check { my ($self) = @_; $self->{components}->{network} = {name => 'network connectors', total => 0, skip => 0}; - $self->{output}->output_add(long_msg => "Checking network connectors"); - return if ($self->check_exclude(section => 'network')); + $self->{output}->output_add(long_msg => "checking network connectors"); + return if ($self->check_filter(section => 'network')); my $oid_cpqRackNetConnectorPresent = '.1.3.6.1.4.1.232.22.2.6.1.1.1.13'; - my $oid_cpqRackNetConnectorIndex = '.1.3.6.1.4.1.232.22.2.6.1.1.1.3'; - my $oid_cpqRackNetConnectorModel = '.1.3.6.1.4.1.232.22.2.6.1.1.1.6'; - my $oid_cpqRackNetConnectorSerialNum = '.1.3.6.1.4.1.232.22.2.6.1.1.1.7'; - my $oid_cpqRackNetConnectorPartNumber = '.1.3.6.1.4.1.232.22.2.6.1.1.1.8'; - my $oid_cpqRackNetConnectorSparePartNumber = '.1.3.6.1.4.1.232.22.2.6.1.1.1.9'; - my $oid_cpqRackNetConnectorDeviceType = '.1.3.6.1.4.1.232.22.2.6.1.1.1.17'; - my $result = $self->{snmp}->get_table(oid => $oid_cpqRackNetConnectorPresent); - return if (scalar(keys %$result) <= 0); + my $snmp_result = $self->{snmp}->get_table(oid => $oid_cpqRackNetConnectorPresent); + return if (scalar(keys %$snmp_result) <= 0); my @get_oids = (); my @oids_end = (); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($present_map{$result->{$key}} ne 'present'); - $key =~ /\.([0-9]+)$/; + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { + next if ($present_map{$snmp_result->{$key}} ne 'present'); + $key =~ /^$oid_cpqRackNetConnectorPresent\.(.*)$/; my $oid_end = $1; push @oids_end, $oid_end; - push @get_oids, $oid_cpqRackNetConnectorIndex . "." . $oid_end, $oid_cpqRackNetConnectorModel . "." . $oid_end, - $oid_cpqRackNetConnectorSerialNum . "." . $oid_end, $oid_cpqRackNetConnectorPartNumber . "." . $oid_end, - $oid_cpqRackNetConnectorSparePartNumber . "." . $oid_end, $oid_cpqRackNetConnectorDeviceType . "." . $oid_end; + push @get_oids, map($_->{oid} . '.' . $oid_end, values(%$mapping)); } - $result = $self->{snmp}->get_leef(oids => \@get_oids); + $snmp_result = $self->{snmp}->get_leef(oids => \@get_oids); foreach (@oids_end) { - my $nc_index = $result->{$oid_cpqRackNetConnectorIndex . '.' . $_}; - my $nc_model = $result->{$oid_cpqRackNetConnectorModel . '.' . $_}; - my $nc_serial = $result->{$oid_cpqRackNetConnectorSerialNum . '.' . $_}; - my $nc_part = $result->{$oid_cpqRackNetConnectorPartNumber . '.' . $_}; - my $nc_spare = $result->{$oid_cpqRackNetConnectorSparePartNumber . '.' . $_}; - my $nc_device = $result->{$oid_cpqRackNetConnectorDeviceType . '.' . $_}; - - next if ($self->check_exclude(section => 'network', instance => $nc_index)); + my $nc_index = $_; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + next if ($self->check_filter(section => 'network', instance => $nc_index)); $self->{components}->{network}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Network Connector %d (%s) type '%s' is present [serial: %s, part: %s, spare: %s].", - $nc_index, $nc_model, - $device_type{$nc_device}, - $nc_serial, $nc_part, $nc_spare - )); + $self->{output}->output_add( + long_msg => sprintf("network connector '%s' (%s) type '%s' is present [serial: %s, part: %s, spare: %s].", + $nc_index, $result->{nc_model}, + $result->{nc_device}, + $result->{nc_serial}, $result->{nc_part}, $result->{nc_spare} + ) + ); } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/psu.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/psu.pm index 5e44e2b67..4bfa62ef5 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/psu.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/psu.pm @@ -64,6 +64,18 @@ my %inputline_status_map = ( 6 => 'linePowerLoss', ); +my $mapping = { + psu_status => { oid => '.1.3.6.1.4.1.232.22.2.5.1.1.1.14', map => \%psu_status_map }, # cpqRackPowerSupplyStatus + psu_serial => { oid => '.1.3.6.1.4.1.232.22.2.5.1.1.1.5' }, # cpqRackPowerSupplySerialNum + psu_part => { oid => '.1.3.6.1.4.1.232.22.2.5.1.1.1.6' }, # cpqRackPowerSupplyPartNumber + psu_spare => { oid => '.1.3.6.1.4.1.232.22.2.5.1.1.1.7' }, # cpqRackPowerSupplySparePartNumber + psu_inputlinestatus => { oid => '.1.3.6.1.4.1.232.22.2.5.1.1.1.15', map => \%inputline_status_map }, # cpqRackPowerSupplyInputLineStatus + psu_condition => { oid => '.1.3.6.1.4.1.232.22.2.5.1.1.1.17', map => \%map_conditions }, # cpqRackPowerSupplyCondition + psu_pwrout => { oid => '.1.3.6.1.4.1.232.22.2.5.1.1.1.10' }, # cpqRackPowerSupplyCurPwrOutput in Watts + psu_intemp => { oid => '.1.3.6.1.4.1.232.22.2.5.1.1.1.12' }, # cpqRackPowerSupplyIntakeTemp + psu_exhtemp => { oid => '.1.3.6.1.4.1.232.22.2.5.1.1.1.13' }, # cpqRackPowerSupplyExhaustTemp +}; + sub check { my ($self) = @_; @@ -71,91 +83,72 @@ sub check { # We check 'cpqRackPowerSupplyTable' (unitary) $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0}; - $self->{output}->output_add(long_msg => "Checking power supplies"); - return if ($self->check_exclude(section => 'psu')); + $self->{output}->output_add(long_msg => "checking power supplies"); + return if ($self->check_filter(section => 'psu')); my $oid_cpqRackPowerSupplyPresent = '.1.3.6.1.4.1.232.22.2.5.1.1.1.16'; - my $oid_cpqRackPowerSupplyIndex = '.1.3.6.1.4.1.232.22.2.5.1.1.1.3'; - my $oid_cpqRackPowerSupplySerialNum = '.1.3.6.1.4.1.232.22.2.5.1.1.1.5'; - my $oid_cpqRackPowerSupplyPartNumber = '.1.3.6.1.4.1.232.22.2.5.1.1.1.6'; - my $oid_cpqRackPowerSupplySparePartNumber = '.1.3.6.1.4.1.232.22.2.5.1.1.1.7'; - my $oid_cpqRackPowerSupplyStatus = '.1.3.6.1.4.1.232.22.2.5.1.1.1.14'; - my $oid_cpqRackPowerSupplyInputLineStatus = '.1.3.6.1.4.1.232.22.2.5.1.1.1.15'; - my $oid_cpqRackPowerSupplyCondition = '.1.3.6.1.4.1.232.22.2.5.1.1.1.17'; - my $oid_cpqRackPowerSupplyCurPwrOutput = '.1.3.6.1.4.1.232.22.2.5.1.1.1.10'; # Watts - my $oid_cpqRackPowerSupplyIntakeTemp = '.1.3.6.1.4.1.232.22.2.5.1.1.1.12'; - my $oid_cpqRackPowerSupplyExhaustTemp = '.1.3.6.1.4.1.232.22.2.5.1.1.1.13'; - my $result = $self->{snmp}->get_table(oid => $oid_cpqRackPowerSupplyPresent); - return if (scalar(keys %$result) <= 0); + my $snmp_result = $self->{snmp}->get_table(oid => $oid_cpqRackPowerSupplyPresent); + return if (scalar(keys %$snmp_result) <= 0); my @get_oids = (); my @oids_end = (); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /\.([0-9]+)$/; + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { + $key =~ /^$oid_cpqRackPowerSupplyPresent\.(.*)$/; my $oid_end = $1; - next if ($present_map{$result->{$key}} ne 'present' && + next if ($present_map{$snmp_result->{$key}} ne 'present' && $self->absent_problem(section => 'psu', instance => $oid_end)); push @oids_end, $oid_end; - push @get_oids, $oid_cpqRackPowerSupplyIndex . "." . $oid_end, $oid_cpqRackPowerSupplySerialNum . "." . $oid_end, - $oid_cpqRackPowerSupplyPartNumber . "." . $oid_end, $oid_cpqRackPowerSupplySparePartNumber . "." . $oid_end, - $oid_cpqRackPowerSupplyStatus . "." . $oid_end, $oid_cpqRackPowerSupplyInputLineStatus . "." . $oid_end, - $oid_cpqRackPowerSupplyCondition . "." . $oid_end, $oid_cpqRackPowerSupplyCurPwrOutput . "." . $oid_end, - $oid_cpqRackPowerSupplyIntakeTemp . "." . $oid_end, $oid_cpqRackPowerSupplyExhaustTemp . "." . $oid_end; + push @get_oids, map($_->{oid} . '.' . $oid_end, values(%$mapping)); } - $result = $self->{snmp}->get_leef(oids => \@get_oids); + + $snmp_result = $self->{snmp}->get_leef(oids => \@get_oids); my $total_watts = 0; foreach (@oids_end) { - my $psu_index = $result->{$oid_cpqRackPowerSupplyIndex . '.' . $_}; - my $psu_status = $result->{$oid_cpqRackPowerSupplyStatus . '.' . $_}; - my $psu_serial = $result->{$oid_cpqRackPowerSupplySerialNum . '.' . $_}; - my $psu_part = $result->{$oid_cpqRackPowerSupplyPartNumber . '.' . $_}; - my $psu_spare = $result->{$oid_cpqRackPowerSupplySparePartNumber . '.' . $_}; - my $psu_inputlinestatus = $result->{$oid_cpqRackPowerSupplyInputLineStatus . '.' . $_}; - my $psu_condition = $result->{$oid_cpqRackPowerSupplyCondition . '.' . $_}; - my $psu_pwrout = $result->{$oid_cpqRackPowerSupplyCurPwrOutput . '.' . $_}; - my $psu_intemp = $result->{$oid_cpqRackPowerSupplyIntakeTemp . '.' . $_}; - my $psu_exhtemp = $result->{$oid_cpqRackPowerSupplyExhaustTemp . '.' . $_}; + my $psu_index = $_; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + next if ($self->check_filter(section => 'psu', instance => $psu_index)); - next if ($self->check_exclude(section => 'psu', instance => $psu_index)); - - $total_watts += $psu_pwrout; + $total_watts += $result->{psu_pwrout}; $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("PSU %d status is %s [serial: %s, part: %s, spare: %s] (input line status %s) (status %s).", - $psu_index, $map_conditions{$psu_condition}, - $psu_serial, $psu_part, $psu_spare, - $inputline_status_map{$psu_inputlinestatus}, - $psu_status_map{$psu_status} - )); + $self->{output}->output_add( + long_msg => sprintf("psu '%s' status is %s [serial: %s, part: %s, spare: %s] (input line status %s) (status %s).", + $psu_index, $result->{psu_condition}, + $result->{psu_serial}, $result->{psu_part}, $result->{psu_spare}, + $result->{psu_inputlinestatus}, + $result->{psu_status} + ) + ); - my $exit = $self->get_severity(section => 'psu', value => $map_conditions{$psu_condition}); + my $exit = $self->get_severity(label => 'default', section => 'psu', instance => $psu_index, value => $result->{psu_condition}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("PSU %d status is %s", - $psu_index, $map_conditions{$psu_condition})); + short_msg => sprintf("PSU '%s' status is %s", + $psu_index, $result->{psu_condition})); } $self->{output}->perfdata_add( label => 'psu_power', unit => 'W', nlabel => 'hardware.powersupply.power.watt', instances => $psu_index, - value => $psu_pwrout + value => $result->{psu_pwrout} ); - if (defined($psu_intemp) && $psu_intemp != -1) { + if (defined($result->{psu_intemp}) && $result->{psu_intemp} != -1) { $self->{output}->perfdata_add( label => 'psu_temp', unit => 'C', nlabel => 'hardware.powersupply.temperature.celsius', instances => [$psu_index, 'intake'], - value => $psu_intemp + value => $result->{psu_intemp} ); } - if (defined($psu_exhtemp) && $psu_exhtemp != -1) { + if (defined($result->{psu_exhtemp}) && $result->{psu_exhtemp} != -1) { $self->{output}->perfdata_add( label => 'psu_temp', unit => 'C', nlabel => 'hardware.powersupply.temperature.celsius', instances => [$psu_index, 'exhaust'], - value => $psu_exhtemp + value => $result->{psu_exhtemp} ); } } diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/temperature.pm index 2eb61307b..3d9ac1ff0 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/temperature.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/components/temperature.pm @@ -23,87 +23,81 @@ package hardware::server::hp::bladechassis::snmp::mode::components::temperature; use strict; use warnings; -my %map_conditions = ( +my $map_conditions = { 1 => 'other', 2 => 'ok', 3 => 'degraded', 4 => 'failed', -); +}; -my %present_map = ( - 1 => 'other', - 2 => 'absent', - 3 => 'present', - 4 => 'Weird!!!', # for blades it can return 4, which is NOT spesified in MIB -); - -my %map_temp_type = ( +my $map_temp_type = { 1 => 'other', 5 => 'blowout', 9 => 'caution', 15 => 'critical', -); +}; + +my $mapping = { + temp_name => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.4' }, # cpqRackCommonEnclosureTempSensorEnclosureName + temp_location => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.5' }, # cpqRackCommonEnclosureTempLocation + temp_current => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.6' }, # cpqRackCommonEnclosureTempCurrent + temp_threshold => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.7' }, # cpqRackCommonEnclosureTempThreshold + temp_condition => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.8', map => $map_conditions }, # cpqRackCommonEnclosureTempCondition + temp_type => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.9', map => $map_temp_type }, # cpqRackCommonEnclosureTempType +}; sub check { my ($self) = @_; - $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; - $self->{output}->output_add(long_msg => "Checking temperatures"); - return if ($self->check_exclude(section => 'temperature')); + $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; + $self->{output}->output_add(long_msg => "checking temperatures"); + return if ($self->check_filter(section => 'temperature')); my $oid_cpqRackCommonEnclosureTempSensorIndex = '.1.3.6.1.4.1.232.22.2.3.1.2.1.3'; - my $oid_cpqRackCommonEnclosureTempSensorEnclosureName = '.1.3.6.1.4.1.232.22.2.3.1.2.1.4'; - my $oid_cpqRackCommonEnclosureTempLocation = '.1.3.6.1.4.1.232.22.2.3.1.2.1.5'; - my $oid_cpqRackCommonEnclosureTempCurrent = '.1.3.6.1.4.1.232.22.2.3.1.2.1.6'; - my $oid_cpqRackCommonEnclosureTempThreshold = '.1.3.6.1.4.1.232.22.2.3.1.2.1.7'; - my $oid_cpqRackCommonEnclosureTempCondition = '.1.3.6.1.4.1.232.22.2.3.1.2.1.8'; - my $oid_cpqRackCommonEnclosureTempType = '.1.3.6.1.4.1.232.22.2.3.1.2.1.9'; - my $result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosureTempSensorIndex); - return if (scalar(keys %$result) <= 0); + my $snmp_result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosureTempSensorIndex); + return if (scalar(keys %$snmp_result) <= 0); + + my @get_oids = (); + my @oids_end = (); + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { + $key =~ /^$oid_cpqRackCommonEnclosureTempSensorIndex\.(.*)$/; + my $oid_end = $1; + push @oids_end, $oid_end; + push @get_oids, map($_->{oid} . '.' . $oid_end, values(%$mapping)); + } - $self->{snmp}->load(oids => [$oid_cpqRackCommonEnclosureTempSensorEnclosureName, - $oid_cpqRackCommonEnclosureTempLocation, - $oid_cpqRackCommonEnclosureTempCurrent, $oid_cpqRackCommonEnclosureTempThreshold, - $oid_cpqRackCommonEnclosureTempCondition, $oid_cpqRackCommonEnclosureTempType], - instances => [keys %$result]); - my $result2 = $self->{snmp}->get_leef(); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /\.(\d+)$/; - my $temp_index = $1; - my $temp_name = $result2->{$oid_cpqRackCommonEnclosureTempSensorEnclosureName . '.' . $temp_index}; - my $temp_location = $result2->{$oid_cpqRackCommonEnclosureTempLocation . '.' . $temp_index}; - my $temp_current = $result2->{$oid_cpqRackCommonEnclosureTempCurrent . '.' . $temp_index}; - my $temp_threshold = $result2->{$oid_cpqRackCommonEnclosureTempThreshold . '.' . $temp_index}; - my $temp_condition = $result2->{$oid_cpqRackCommonEnclosureTempCondition . '.' . $temp_index}; - my $temp_type = $result2->{$oid_cpqRackCommonEnclosureTempType . '.' . $temp_index}; + $snmp_result = $self->{snmp}->get_leef(oids => \@get_oids); + foreach (@oids_end) { + my $temp_index = $_; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $temp_index); - if ($temp_current == -1) { - $self->{output}->output_add(long_msg => sprintf("Skipping instance $temp_index: current -1")); + if ($result->{temp_current} == -1) { + $self->{output}->output_add(long_msg => sprintf("skipping instance $temp_index: current -1"), debug => 1); next; } - next if ($self->check_exclude(section => 'temperature', instance => $temp_index)); + next if ($self->check_filter(section => 'temperature', instance => $temp_index)); $self->{components}->{temperature}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Temperature %d status is %s [name: %s, location: %s] (value = %s, threshold = %s%s).", - $temp_index, $map_conditions{$temp_condition}, - $temp_name, $temp_location, - $temp_current, $temp_threshold, - defined($map_temp_type{$temp_type}) ? ", status type = " . $map_temp_type{$temp_type} : '')); - my $exit = $self->get_severity(section => 'temperature', value => $map_conditions{$temp_condition}); + $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is %s [name: %s, location: %s] (value = %s, threshold = %s%s).", + $temp_index, $result->{temp_condition}, + $result->{temp_name}, $result->{temp_location}, + $result->{temp_current}, $result->{temp_threshold}, + defined($result->{temp_type}) ? ", status type = " . $result->{temp_type} : '')); + my $exit = $self->get_severity(label => 'default', section => 'temperature', instance => $temp_index, value => $result->{temp_condition}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Temperature %d status is %s", - $temp_index, $map_conditions{$temp_condition})); + short_msg => sprintf("Temperature '%s' status is %s", + $temp_index, $result->{temp_condition})); } $self->{output}->perfdata_add( label => "temp", unit => 'C', nlabel => 'hardware.temperature.celsius', instances => $temp_index, - value => $temp_current, - warning => $temp_threshold + value => $result->{temp_current}, + warning => $result->{temp_threshold} ); } } diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/hardware.pm index a29d48bbc..e464aaa27 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/hardware.pm @@ -20,253 +20,77 @@ package hardware::server::hp::bladechassis::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use hardware::server::hp::bladechassis::snmp::mode::components::enclosure; -use hardware::server::hp::bladechassis::snmp::mode::components::manager; -use hardware::server::hp::bladechassis::snmp::mode::components::fan; -use hardware::server::hp::bladechassis::snmp::mode::components::blade; -use hardware::server::hp::bladechassis::snmp::mode::components::network; -use hardware::server::hp::bladechassis::snmp::mode::components::psu; -use hardware::server::hp::bladechassis::snmp::mode::components::temperature; -use hardware::server::hp::bladechassis::snmp::mode::components::fuse; +use centreon::plugins::misc; -my $thresholds = { - temperature => [ - ['other', 'CRITICAL'], - ['ok', 'OK'], - ['degraded', 'WARNING'], - ['failed', 'CRITICAL'], - ], - blade => [ - ['other', 'CRITICAL'], - ['ok', 'OK'], - ['degraded', 'WARNING'], - ['failed', 'CRITICAL'], - ], - enclosure => [ - ['other', 'CRITICAL'], - ['ok', 'OK'], - ['degraded', 'WARNING'], - ['failed', 'CRITICAL'], - ], - fan => [ - ['other', 'CRITICAL'], - ['ok', 'OK'], - ['degraded', 'WARNING'], - ['failed', 'CRITICAL'], - ], - fuse => [ - ['other', 'CRITICAL'], - ['ok', 'OK'], - ['degraded', 'WARNING'], - ['failed', 'CRITICAL'], - ], - manager => [ - ['other', 'CRITICAL'], - ['ok', 'OK'], - ['degraded', 'WARNING'], - ['failed', 'CRITICAL'], - ], - psu => [ - ['other', 'CRITICAL'], - ['ok', 'OK'], - ['degraded', 'WARNING'], - ['failed', 'CRITICAL'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = + '^(enclosure|manager|fan|blade|network|psu|temperature|fuse)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['other', 'CRITICAL'], + ['ok', 'OK'], + ['degraded', 'WARNING'], + ['failed', 'CRITICAL'], + ], + }; + + $self->{components_exec_load} = 0; + + $self->{components_path} = 'hardware::server::hp::bladechassis::snmp::mode::components'; + $self->{components_module} = [ + 'enclosure', 'manager', 'fan', 'blade', 'network', 'psu', 'temperature', 'fuse' + ]; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "absent-problem:s" => { name => 'absent' }, - "component:s" => { name => 'component', default => 'all' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => {}); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } -} - -sub global { - my ($self, %options) = @_; - - hardware::server::hp::bladechassis::snmp::mode::components::enclosure::check($self); - hardware::server::hp::bladechassis::snmp::mode::components::manager::check($self); - hardware::server::hp::bladechassis::snmp::mode::components::fan::check($self); - hardware::server::hp::bladechassis::snmp::mode::components::blade::check($self); - hardware::server::hp::bladechassis::snmp::mode::components::network::check($self); - hardware::server::hp::bladechassis::snmp::mode::components::psu::check($self); - hardware::server::hp::bladechassis::snmp::mode::components::temperature::check($self); - hardware::server::hp::bladechassis::snmp::mode::components::fuse::check($self); -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - if ($self->{option_results}->{component} eq 'all') { - $self->global(); - } elsif ($self->{option_results}->{component} eq 'enclosure') { - hardware::server::hp::bladechassis::snmp::mode::components::enclosure::check($self); - } elsif ($self->{option_results}->{component} eq 'manager') { - hardware::server::hp::bladechassis::snmp::mode::components::manager::check($self, force => 1); - } elsif ($self->{option_results}->{component} eq 'fan') { - hardware::server::hp::bladechassis::snmp::mode::components::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'blade') { - hardware::server::hp::bladechassis::snmp::mode::components::blade::check($self); - } elsif ($self->{option_results}->{component} eq 'network') { - hardware::server::hp::bladechassis::snmp::mode::components::network::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - hardware::server::hp::bladechassis::snmp::mode::components::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'temperature') { - hardware::server::hp::bladechassis::snmp::mode::components::temperature::check($self); - } elsif ($self->{option_results}->{component} eq 'fuse') { - hardware::server::hp::bladechassis::snmp::mode::components::fuse::check($self); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components [%s] are ok.", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub absent_problem { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{absent}) && - $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Component '%s' instance '%s' is not present", - $options{section}, $options{instance})); - } - - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)")); - $self->{components}->{$options{section}}->{skip}++; - return 1; -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ =head1 MODE -Check Hardware (Fans, Power Supplies, Blades, Temperatures, Fuses). +Check hardware. =over 8 =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'enclosure', 'manager', 'fan', 'blade', 'network', 'psu', 'temperature', 'fuse'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=temperature,psu). -Can also exclude specific instance: --exclude=temperature#1# +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=temperature,1 =item B<--absent-problem> -Return an error if an entity is not 'present' (default is skipping) (comma seperated list) -Can be specific or global: --absent-problem=blade#12# +Return an error if an entity is not 'present' (default is skipping) +Can be specific or global: --absent-problem="blade,12" =item B<--no-component> @@ -275,7 +99,7 @@ If total (with skipped) is 0. (Default: 'critical' returns). =item B<--threshold-overload> -Set to overload default threshold values (syntax: section,status,regexp) +Set to overload default threshold values (syntax: section,[instance,]status,regexp) It used before default thresholds (order stays). Example: --threshold-overload='temperature,OK,other' diff --git a/centreon-plugins/hardware/server/hp/ilo/xmlapi/custom/api.pm b/centreon-plugins/hardware/server/hp/ilo/xmlapi/custom/api.pm index ac0266fc3..12e452e91 100644 --- a/centreon-plugins/hardware/server/hp/ilo/xmlapi/custom/api.pm +++ b/centreon-plugins/hardware/server/hp/ilo/xmlapi/custom/api.pm @@ -23,8 +23,8 @@ package hardware::server::hp::ilo::xmlapi::custom::api; use strict; use warnings; use IO::Socket::SSL; -use LWP::UserAgent; use XML::Simple; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -42,19 +42,19 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "port:s" => { name => 'port', default => 443 }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - 'ssl-opt:s%' => { name => 'ssl_opt' }, - "force-ilo3" => { name => 'force_ilo3' }, + 'hostname:s' => { name => 'hostname' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'port:s' => { name => 'port', default => 443 }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'force-ilo3' => { name => 'force_ilo3' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'XML API OPTIONS', once => 1); $self->{output} = $options{output}; $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); return $self; } @@ -99,13 +99,18 @@ sub check_options { $self->{ssl_opts} = ''; if (!defined($self->{option_results}->{ssl_opt})) { + $self->{option_results}->{ssl_opt} = ['SSL_verify_mode => SSL_VERIFY_NONE']; $self->{ssl_opts} = 'SSL_verify_mode => SSL_VERIFY_NONE'; } else { - foreach (keys %{$self->{option_results}->{ssl_opt}}) { - $self->{ssl_opts} .= "$_ => " . $self->{option_results}->{ssl_opt}->{$_} . ", "; + foreach (@{$self->{option_results}->{ssl_opt}}) { + $self->{ssl_opts} .= "$_, "; } } + if (!defined($self->{option_results}->{curl_opt})) { + $self->{option_results}->{curl_opt} = ['CURLOPT_SSL_VERIFYPEER => 0', 'CURLOPT_SSL_VERIFYHOST => 0']; + } + $self->{http}->set_options(%{$self->{option_results}}); return 0; } @@ -172,22 +177,14 @@ sub get_ilo3_data { "; - my $ua = LWP::UserAgent->new(keep_alive => 0, protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout}); - my $req = HTTP::Request->new(POST => "https://" . $self->{option_results}->{hostname} . '/ribcl'); - $req->content_length(length($xml_script)); - $req->content($xml_script); - $req->header(TE => 'chunked'); - $req->header(Connection => 'Close'); + $self->{http}->add_header(key => 'TE', value => 'chunked'); + $self->{http}->add_header(key => 'Connection', value => 'Close'); + $self->{http}->add_header(key => 'Content-Type', value => 'text/xml'); - my $context = new IO::Socket::SSL::SSL_Context(eval $self->{ssl_opts}); - IO::Socket::SSL::set_default_context($context); - - my $response = $ua->request($req); - $self->{content} = $response->content; - if (!$response->is_success) { - $self->{output}->add_option_msg(short_msg => "Cannot get data: $response->status_line"); - $self->{output}->option_exit(); - } + $self->{content} = $self->{http}->request( + method => 'POST', proto => 'https', url_path => '/ribcl', + query_form_post => $xml_script, + ); } sub check_ilo_error { @@ -369,11 +366,6 @@ Set timeout (Default: 30). Don't try to find ILO version. -=item B<--ssl-opt> - -Set SSL Options (--ssl-opt="SSL_version=SSLv3"). -Default: --ssl-opt="SSL_verify_mode=SSL_VERIFY_NONE" - =back =head1 DESCRIPTION diff --git a/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/hardware.pm b/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/hardware.pm index bc39e325a..85df8fea2 100644 --- a/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/hardware.pm +++ b/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/hardware.pm @@ -69,7 +69,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/server/hp/proliant/snmp/mode/globalstatus.pm b/centreon-plugins/hardware/server/hp/proliant/snmp/mode/globalstatus.pm index c6fe3706d..8421380bd 100644 --- a/centreon-plugins/hardware/server/hp/proliant/snmp/mode/globalstatus.pm +++ b/centreon-plugins/hardware/server/hp/proliant/snmp/mode/globalstatus.pm @@ -45,7 +45,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/hardware/server/hp/proliant/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/hp/proliant/snmp/mode/hardware.pm index 3e0065d14..eb0f499e0 100644 --- a/centreon-plugins/hardware/server/hp/proliant/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/hp/proliant/snmp/mode/hardware.pm @@ -162,7 +162,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/blade.pm b/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/blade.pm index 5eb0866b4..b009a6dff 100644 --- a/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/blade.pm +++ b/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/blade.pm @@ -58,7 +58,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "blade-id:s" => { name => 'blade_id' }, diff --git a/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/chassis.pm b/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/chassis.pm index 58eafece3..fc0b11987 100644 --- a/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/chassis.pm +++ b/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/chassis.pm @@ -57,7 +57,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/hardware.pm index 2b61afcb5..74476ed08 100644 --- a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/hardware.pm @@ -76,7 +76,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/server/ibm/bladecenter/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/ibm/bladecenter/snmp/mode/hardware.pm index 694805de2..41a0c0400 100644 --- a/centreon-plugins/hardware/server/ibm/bladecenter/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/ibm/bladecenter/snmp/mode/hardware.pm @@ -112,7 +112,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/server/ibm/hmc/ssh/mode/hardwareerrors.pm b/centreon-plugins/hardware/server/ibm/hmc/ssh/mode/hardwareerrors.pm index a4d30bd8c..b8472e14a 100644 --- a/centreon-plugins/hardware/server/ibm/hmc/ssh/mode/hardwareerrors.pm +++ b/centreon-plugins/hardware/server/ibm/hmc/ssh/mode/hardwareerrors.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, @@ -41,7 +40,7 @@ sub new { "ssh-path:s" => { name => 'ssh_path' }, "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, "hmc-command:s" => { name => 'hmc_command', default => 'lssvcevents' }, - "retention:i" => { name => 'retention' }, + "retention:s" => { name => 'retention' }, "minutes" => { name => 'minutes' }, "filter-status:s" => { name => 'filter_status', default => 'open' }, "filter-problem-nums:s" => { name => 'filter_problem_nums' }, diff --git a/centreon-plugins/hardware/server/ibm/hmc/ssh/mode/ledstatus.pm b/centreon-plugins/hardware/server/ibm/hmc/ssh/mode/ledstatus.pm index 83b35f9c6..6b30ab969 100644 --- a/centreon-plugins/hardware/server/ibm/hmc/ssh/mode/ledstatus.pm +++ b/centreon-plugins/hardware/server/ibm/hmc/ssh/mode/ledstatus.pm @@ -76,7 +76,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/fan.pm b/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/fan.pm index ead3b961b..6067bc464 100644 --- a/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/fan.pm +++ b/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/fan.pm @@ -33,7 +33,7 @@ my $oid_fanEntry = '.1.3.6.1.4.1.2.3.51.3.1.3.2.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_fanEntry }; + push @{$self->{request}}, { oid => $oid_fanEntry, start => $mapping->{fanDescr}->{oid}, end => $mapping->{fanSpeed}->{oid} }; } sub check { diff --git a/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/environment.pm b/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/environment.pm index 4984d13fd..e6547037e 100644 --- a/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/environment.pm +++ b/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/environment.pm @@ -62,7 +62,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm b/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm index 4bb4d591b..02f758503 100644 --- a/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm +++ b/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm @@ -73,7 +73,6 @@ sub new { 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 => '%{severity} =~ /warning/i' }, diff --git a/centreon-plugins/hardware/server/lenovo/xcc/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/lenovo/xcc/snmp/mode/hardware.pm index b622d5601..9b7128831 100644 --- a/centreon-plugins/hardware/server/lenovo/xcc/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/lenovo/xcc/snmp/mode/hardware.pm @@ -60,7 +60,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/disk.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/disk.pm index d402d5185..df2a63d95 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/disk.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/disk.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking disks"); $self->{components}->{disk} = {name => 'disks', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'disk')); + return if ($self->check_filter(section => 'disk')); if ($self->{stdout} =~ /^System Disks.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Disk Status Service OK2RM @@ -41,7 +41,7 @@ sub check { my $disk_status = defined($2) ? $2 : 'unknown'; my $disk_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'disk', instance => $disk_name)); + next if ($self->check_filter(section => 'disk', instance => $disk_name)); $self->{components}->{disk}->{total}++; $self->{output}->output_add(long_msg => "Disk Status '" . $disk_name . "' is " . $disk_status); @@ -54,4 +54,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/fan.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/fan.pm index 83cdca804..10c932241 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/fan.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/fan.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking fans"); $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fan')); + return if ($self->check_filter(section => 'fan')); if ($self->{stdout} =~ /^Fans.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Sensor Status Speed Warn Low @@ -41,7 +41,7 @@ sub check { my $fan_status = defined($2) ? $2 : 'unknown'; my $fan_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'fan', instance => $fan_name)); + next if ($self->check_filter(section => 'fan', instance => $fan_name)); $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => "Fan Sensor Status '" . $fan_name . "' is " . $fan_status); @@ -54,4 +54,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/psu.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/psu.pm index eac47116c..c773c21c3 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/psu.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/psu.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking power supplies"); $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); + return if ($self->check_filter(section => 'psu')); if ($self->{stdout} =~ /^Power Supplies.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Supply Status Underspeed Overtemp Overvolt Undervolt Overcurrent @@ -40,7 +40,7 @@ sub check { my $ps_status = defined($2) ? $2 : 'unknown'; my $ps_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'psu', instance => $ps_name)); + next if ($self->check_filter(section => 'psu', instance => $ps_name)); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => "Power Supplies Sensor Status '" . $ps_name . "' is " . $ps_status); @@ -53,4 +53,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/sensors.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/sensors.pm index 8c59a8b1a..247ba6900 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/sensors.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/sensors.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking sensors"); $self->{components}->{sensors} = {name => 'sensors', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'sensors')); + return if ($self->check_filter(section => 'sensors')); if ($self->{stdout} =~ /^Current sensors.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Sensor Status @@ -40,7 +40,7 @@ sub check { my $sensor_status = defined($2) ? $2 : 'unknown'; my $sensor_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'sensors', instance => $sensor_name)); + next if ($self->check_filter(section => 'sensors', instance => $sensor_name)); $self->{components}->{sensors}->{total}++; $self->{output}->output_add(long_msg => "Current Sensor status '" . $sensor_name . "' is " . $sensor_status); @@ -53,4 +53,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/si.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/si.pm index c909d0dc7..42407a5fe 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/si.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/si.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking system indicator"); $self->{components}->{si} = {name => 'system indicator', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'si')); + return if ($self->check_filter(section => 'si')); #-------------------------------------------------------- #System Indicator Status: @@ -55,7 +55,7 @@ sub check { my $si_name = defined($1) ? $1 : 'unknown'; my $si_status = defined($2) ? $2 : 'unknown'; - next if ($self->check_exclude(section => 'si', instance => $si_name)); + next if ($self->check_filter(section => 'si', instance => $si_name)); $self->{components}->{si}->{total}++; $self->{output}->output_add(long_msg => "System Indicator Status '$si_name' is " . $si_status); @@ -68,4 +68,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/temperature.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/temperature.pm index 9acb2740e..519f85b25 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/temperature.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/temperature.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking temperatures"); $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'temperature')); + return if ($self->check_filter(section => 'temperature')); if ($self->{stdout} =~ /^System Temperatures.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Sensor Status Temp LowHard LowSoft LowWarn HighWarn HighSoft HighHard @@ -40,7 +40,7 @@ sub check { my $sensor_status = defined($2) ? $2 : 'unknown'; my $sensor_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'temperature', instance => $sensor_name)); + next if ($self->check_filter(section => 'temperature', instance => $sensor_name)); $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => "System Temperature Sensor '" . $sensor_name . "' is " . $sensor_status); @@ -53,4 +53,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/voltage.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/voltage.pm index 2782499fb..24b8a3e4c 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/voltage.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/components/showenvironment/voltage.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking voltages"); $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'voltage')); + return if ($self->check_filter(section => 'voltage')); if ($self->{stdout} =~ /^Voltage sensors.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Sensor Status Voltage LowSoft LowWarn HighWarn HighSoft @@ -41,7 +41,7 @@ sub check { my $voltage_status = defined($2) ? $2 : 'unknown'; my $voltage_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'voltage', instance => $voltage_name)); + next if ($self->check_filter(section => 'voltage', instance => $voltage_name)); $self->{components}->{voltage}->{total}++; $self->{output}->output_add(long_msg => "Voltage Sensor status '" . $voltage_name . "' is " . $voltage_status); @@ -54,4 +54,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm index 6e2b7d267..583058de6 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentv4xx.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentv4xx.pm index 142e03a82..bc5595815 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentv4xx.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentv4xx.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentv8xx.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentv8xx.pm index 897946dd7..b16d6d6bf 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentv8xx.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentv8xx.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showboards.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showboards.pm index 08d5f5dd9..8dedc67e6 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showboards.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showboards.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showenvironment.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showenvironment.pm index 0cc0d0821..8b2196a25 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showenvironment.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showenvironment.pm @@ -20,48 +20,78 @@ package hardware::server::sun::mgmt_cards::mode::showenvironment; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; use centreon::plugins::misc; -use hardware::server::sun::mgmt_cards::components::showenvironment::resources qw($thresholds); -use hardware::server::sun::mgmt_cards::components::showenvironment::psu; -use hardware::server::sun::mgmt_cards::components::showenvironment::fan; -use hardware::server::sun::mgmt_cards::components::showenvironment::temperature; -use hardware::server::sun::mgmt_cards::components::showenvironment::sensors; -use hardware::server::sun::mgmt_cards::components::showenvironment::voltage; -use hardware::server::sun::mgmt_cards::components::showenvironment::si; -use hardware::server::sun::mgmt_cards::components::showenvironment::disk; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = + '^temperature|si|disk|fan|voltage|psu|sensors$'; + + $self->{cb_hook2} = 'execute_command'; + + $self->{components_exec_load} = 0; + + $self->{thresholds} = { + temperature => [ + ['^(?!(OK)$)', 'CRITICAL'], + ['^OK$', 'OK'], + ], + si => [ + ['^(?!(OFF)$)', 'CRITICAL'], + ['^OFF$', 'OK'], + ], + disk => [ + ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], + ['^OK|NOT PRESENT$', 'OK'], + ], + fan => [ + ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], + ['^OK|NOT PRESENT$', 'OK'], + ], + voltage => [ + ['^(?!(OK)$)', 'CRITICAL'], + ['^OK$', 'OK'], + ], + psu => [ + ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], + ['^OK|NOT PRESENT$', 'OK'], + ], + sensors => [ + ['^(?!(OK)$)', 'CRITICAL'], + ['^OK$', 'OK'], + ], + }; + + $self->{components_path} = 'hardware::server::sun::mgmt_cards::components::showenvironment'; + $self->{components_module} = ['temperature', 'si', 'disk', 'fan', 'voltage', 'psu', 'sensors']; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => 23 }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "command-plink:s" => { name => 'command_plink', default => 'plink' }, - "ssh" => { name => 'ssh' }, - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port', default => 23 }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'command-plink:s' => { name => 'command_plink', default => 'plink' }, + 'ssh' => { name => 'ssh' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); if (!defined($self->{option_results}->{hostname})) { $self->{output}->add_option_msg(short_msg => "Need to specify a hostname."); @@ -79,29 +109,6 @@ sub check_options { if (!defined($self->{option_results}->{ssh})) { require hardware::server::sun::mgmt_cards::lib::telnet; } - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } } sub ssh_command { @@ -110,10 +117,11 @@ sub ssh_command { my $cmd_in = $self->{option_results}->{username} . '\n' . $self->{option_results}->{password} . '\nshowenvironment\nlogout\n'; my $cmd = "echo -e '$cmd_in' | " . $self->{option_results}->{command_plink} . " -batch " . $self->{option_results}->{hostname} . " 2>&1"; my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick( - command => $cmd, - timeout => $self->{option_results}->{timeout}, - wait_exit => 1 - ); + command => $cmd, + timeout => $self->{option_results}->{timeout}, + wait_exit => 1 + ); + $stdout =~ s/\r//g; if ($lerror <= -1000) { $self->{output}->output_add(severity => 'UNKNOWN', @@ -140,128 +148,24 @@ sub ssh_command { return $stdout; } -sub global { +sub execute_command { my ($self, %options) = @_; - hardware::server::sun::mgmt_cards::components::showenvironment::psu::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::fan::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::temperature::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::sensors::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::voltage::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::si::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::disk::check($self); -} - -sub component { - my ($self, %options) = @_; - - if ($self->{option_results}->{component} eq 'si') { - hardware::server::sun::mgmt_cards::components::showenvironment::si::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - hardware::server::sun::mgmt_cards::components::showenvironment::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'fan') { - hardware::server::sun::mgmt_cards::components::showenvironment::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'temperature') { - hardware::server::sun::mgmt_cards::components::showenvironment::temperature::check($self); - } elsif ($self->{option_results}->{component} eq 'sensors') { - hardware::server::sun::mgmt_cards::components::showenvironment::sensors::check($self); - } elsif ($self->{option_results}->{component} eq 'voltage') { - hardware::server::sun::mgmt_cards::components::showenvironment::voltage::check($self); - } elsif ($self->{option_results}->{component} eq 'disk') { - hardware::server::sun::mgmt_cards::components::showenvironment::disk::check($self); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - if (defined($self->{option_results}->{ssh})) { $self->{stdout} = $self->ssh_command(); } else { my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect( - username => $self->{option_results}->{username}, - password => $self->{option_results}->{password}, - hostname => $self->{option_results}->{hostname}, - port => $self->{option_results}->{port}, - timeout => $self->{option_results}->{timeout}, - output => $self->{output}); + username => $self->{option_results}->{username}, + password => $self->{option_results}->{password}, + hostname => $self->{option_results}->{hostname}, + port => $self->{option_results}->{port}, + timeout => $self->{option_results}->{timeout}, + output => $self->{output} + ); my @lines = $telnet_handle->cmd("showenvironment"); $self->{stdout} = join("", @lines); } - $self->{stdout} =~ s/\r//msg; - - if ($self->{option_results}->{component} eq 'all') { - $self->global(); - } else { - $self->component(); - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components [%s] are ok.", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; } 1; @@ -304,13 +208,13 @@ Use ssh (with plink) instead of telnet. =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'temperature', 'si', 'disk', 'fan', 'voltage', 'psu', 'sensors'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fan) -Can also exclude specific instance: --exclude=fan#F1.RS# +Exclude some parts (comma seperated list) (Example: --filter=fan) +Can also exclude specific instance: --filter=fan,F1.RS =item B<--no-component> diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaults.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaults.pm index f54f4230d..5e63b3418 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaults.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaults.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaulty.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaulty.pm index 1bd3c7915..2d2d5d7fd 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaulty.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaulty.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'hostname:s' => { name => 'hostname' }, 'username:s' => { name => 'username' }, diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showstatus.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showstatus.pm index 21b407e94..e65295baf 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showstatus.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showstatus.pm @@ -39,7 +39,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/hardware/server/sun/mseries/mode/domains.pm b/centreon-plugins/hardware/server/sun/mseries/mode/domains.pm index f7cdc0423..120dc39e5 100644 --- a/centreon-plugins/hardware/server/sun/mseries/mode/domains.pm +++ b/centreon-plugins/hardware/server/sun/mseries/mode/domains.pm @@ -38,7 +38,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "skip" => { name => 'skip' }, diff --git a/centreon-plugins/hardware/server/sun/mseries/mode/hardware.pm b/centreon-plugins/hardware/server/sun/mseries/mode/hardware.pm index 7f2b4de74..3076c2927 100644 --- a/centreon-plugins/hardware/server/sun/mseries/mode/hardware.pm +++ b/centreon-plugins/hardware/server/sun/mseries/mode/hardware.pm @@ -127,7 +127,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "with-sensors" => { name => 'with_sensors' }, "exclude:s@" => { name => 'exclude' }, diff --git a/centreon-plugins/hardware/server/sun/sfxxk/mode/boards.pm b/centreon-plugins/hardware/server/sun/sfxxk/mode/boards.pm index fae2d4efa..bd967c3d5 100644 --- a/centreon-plugins/hardware/server/sun/sfxxk/mode/boards.pm +++ b/centreon-plugins/hardware/server/sun/sfxxk/mode/boards.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/hardware/server/sun/sfxxk/mode/environment.pm b/centreon-plugins/hardware/server/sun/sfxxk/mode/environment.pm index dd41befbe..2c9d6c67b 100644 --- a/centreon-plugins/hardware/server/sun/sfxxk/mode/environment.pm +++ b/centreon-plugins/hardware/server/sun/sfxxk/mode/environment.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/hardware/server/sun/sfxxk/mode/failover.pm b/centreon-plugins/hardware/server/sun/sfxxk/mode/failover.pm index e5fc8d947..76d50a30c 100644 --- a/centreon-plugins/hardware/server/sun/sfxxk/mode/failover.pm +++ b/centreon-plugins/hardware/server/sun/sfxxk/mode/failover.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/hardware/server/supermicro/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/supermicro/snmp/mode/hardware.pm index 6a6983358..0248198ce 100644 --- a/centreon-plugins/hardware/server/supermicro/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/supermicro/snmp/mode/hardware.pm @@ -54,7 +54,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/telephony/avaya/aes/snmp/mode/services.pm b/centreon-plugins/hardware/telephony/avaya/aes/snmp/mode/services.pm new file mode 100644 index 000000000..4e9738b84 --- /dev/null +++ b/centreon-plugins/hardware/telephony/avaya/aes/snmp/mode/services.pm @@ -0,0 +1,331 @@ +# +# Copyright 2019 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 hardware::telephony::avaya::aes::snmp::mode::services; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_service_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + "status: %s [state: '%s'] [license error: '%s']", + $self->{result_values}->{status}, + $self->{result_values}->{state}, + $self->{result_values}->{license_error} + ); + return $msg; +} + +sub custom_aep_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + "state: %s [link state: '%s']", + $self->{result_values}->{session_state}, + $self->{result_values}->{link_state} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'service', type => 1, cb_prefix_output => 'prefix_service_output', message_multiple => 'All services are ok', skipped_code => { -10 => 1 } }, + { name => 'aep', type => 1, cb_prefix_output => 'prefix_aep_output', message_multiple => 'All AEP connections are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{service} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'state' }, { name => 'license_error' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_service_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'tsapi-clients-connected', nlabel => 'service.tsapi.clients.connected.count', set => { + key_values => [ { name => 'avAesTsapiClientsConnected' } ], + output_template => 'client connected: %s', + perfdatas => [ + { value => 'avAesTsapiClientsConnected_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'dmcc-memory-usage', nlabel => 'service.dmcc.memory.usage.percentage', set => { + key_values => [ { name => 'mem_used_prct' } ], + output_template => 'memory used : %.2f %%', + perfdatas => [ + { value => 'mem_used_prct_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; + + $self->{maps_counters}->{aep} = [ + { label => 'aep-status', threshold => 0, set => { + key_values => [ { name => 'session_state' }, { name => 'link_state' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_aep_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_service_output { + my ($self, %options) = @_; + + return "Service '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_aep_output { + my ($self, %options) = @_; + + return "AEP session '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} ne "running" or %{status} ne "online"' }, + 'unknown-aep-status:s' => { name => 'unknown_aep_status', default => '' }, + 'warning-aep-status:s' => { name => 'warning_aep_status', default => '' }, + 'critical-aep-status:s' => { name => 'critical_aep_status', default => '%{link_state} ne "online" or %{session_state} ne "online"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => [ + 'unknown_status', 'warning_status', 'critical_status', + 'unknown_aep_status', 'warning_aep_status', 'critical_aep_status', + ]); +} + +my %map_state = ( + 1 => 'ready', 2 => 'running', 3 => 'stopped', + 4 => 'paused', 5 => 'stopping', 6 => 'starting', + 7 => 'unknown', 8 => 'resourceUnavailable', +); +my %map_status = ( + 1 => 'resuming', 2 => 'initializing', + 3 => 'online', 4 => 'offline', + 5 => 'pausing', 6 => 'stopping', + 7 => 'down', 8 => 'unknown', 9 => 'resourceUnavailable', +); +my %map_license_error = ( + -1 => 'resourceUnavailable', 0 => 'normal', 1 => 'productNotFound', + 2 => 'featureNotFound', 3 => 'serverConnection', 4 => 'invalidResponse', + 5 => 'invalidRequest', 6 => 'internalError', 7 => 'invalidParameters', + 8 => 'licenseExpired', 9 => 'noLicenseFound', 10 => 'unknownHost', + 11 => 'tryAgain', 12 => 'noRecovery', 13 => 'noData', 14 => 'connectionRefused', + 15 => 'noRouteToHost', 16 => 'authenticationError', 17 => 'incompatibleVersion', + 18 => 'timeout', 19 => 'notLicenseServer', 20 => 'multiSiteInvalid', + 21 => 'serverRestarting', 22 => 'sslConnection', 23 => 'invalidUrl', + 24 => 'invalidProtocol', 99 => 'unknownError', 100 => 'gracePeriodExpired', + 101 => 'invalidLicense', 102 => 'tooManyLicenses', 103 => 'dateTimeError', +); +my %map_aep_link_state = ( + 1 => 'offline', 2 => 'online', 3 => 'resourceUnavailable', +); +my $mapping = { + avAesTransportName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.1.1' }, + avAesTransportState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.1.2', map => \%map_state }, + avAesTransportStatus => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.1.3', map => \%map_status }, + avAesCvlanName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.2.1' }, + avAesCvlanState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.2.2', map => \%map_state }, + avAesCvlanStatus => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.2.3', map => \%map_status }, + avAesCvlanLicenseError => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.2.12', map => \%map_license_error }, + avAesTsapiName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.3.1' }, + avAesTsapiState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.3.2', map => \%map_state }, + avAesTsapiStatus => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.3.3', map => \%map_status }, + avAesTsapiClientsConnected => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.3.8' }, + avAesTsapiLicenseError => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.3.21', map => \%map_license_error }, + avAesDlgName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.4.1' }, + avAesDlgState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.4.2', map => \%map_state }, + avAesDlgStatus => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.4.3', map => \%map_status }, + avAesDlgLicenseError => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.4.10', map => \%map_license_error }, + avAesDmccName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.1' }, + avAesDmccState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.2', map => \%map_state }, + avAesDmccStatus => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.3', map => \%map_status }, + avAesDmccUsedMemory => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.6' }, + avAesDmccFreeMemory => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.7' }, + avAesDmccLicenseError => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.20', map => \%map_license_error }, +}; + +my $mapping2 = { + avAesAepLinkSessSwName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.1.6.1.3' }, + avAesAepLinkState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.1.6.1.5', map => \%map_aep_link_state }, +}; +my $oid_avAesAepLinkEntry = '.1.3.6.1.4.1.6889.2.27.2.1.1.6.1'; +my $oid_avAesAepSessionState = '.1.3.6.1.4.1.6889.2.27.2.1.1.7.1.4'; + +sub manage_aep { + my ($self, %options) = @_; + + $self->{aep} = {}; + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_avAesAepLinkEntry, start => $mapping2->{avAesAepLinkSessSwName}->{oid}, end => $mapping2->{avAesAepLinkState}->{oid} }, + { oid => $oid_avAesAepSessionState }, + ], + ); + + foreach my $oid (keys %{$snmp_result->{$oid_avAesAepLinkEntry}}) { + next if ($oid !~ /^$mapping2->{avAesAepLinkSessSwName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_avAesAepLinkEntry}, instance => $instance); + $self->{aep}->{$result->{avAesAepLinkSessSwName}} = { + display => $result->{avAesAepLinkSessSwName}, + link_state => $result->{avAesAepLinkState}, + }; + + $instance = length($result->{avAesAepLinkSessSwName}) . '.' . join('.', map(ord($_), split('', $result->{avAesAepLinkSessSwName}))); + $self->{aep}->{$result->{avAesAepLinkSessSwName}}->{session_state} = + $map_aep_link_state{ $snmp_result->{$oid_avAesAepSessionState}->{$oid_avAesAepSessionState . '.' . $instance} }; + } +} + +sub add_service { + my ($self, %options) = @_; + + return if (!defined($options{display})); + return if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $options{display} !~ /$self->{option_results}->{filter_name}/); + $self->{service}->{$options{display}} = { %options }; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{service} = {}; + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ], nothing_quit => 1 + ); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + $self->add_service( + display => $result->{avAesTransportName}, + state => $result->{avAesTransportState}, + status => $result->{avAesTransportStatus}, + license_error => 'normal', + ); + $self->add_service( + display => $result->{avAesCvlanName}, + state => $result->{avAesCvlanState}, + status => $result->{avAesCvlanStatus}, + license_error => $result->{avAesCvlanLicenseError}, + ); + $self->add_service( + display => $result->{avAesTsapiName}, + state => $result->{avAesTsapiState}, + status => $result->{avAesTsapiStatus}, + license_error => $result->{avAesTsapiLicenseError}, + avAesTsapiClientsConnected => + defined($result->{avAesTsapiClientsConnected}) && $result->{avAesTsapiClientsConnected} != -1 ? $result->{avAesTsapiClientsConnected} : undef, + ); + $self->add_service( + display => $result->{avAesDlgName}, + state => $result->{avAesDlgState}, + status => $result->{avAesDlgStatus}, + license_error => $result->{avAesDlgLicenseError}, + ); + $self->add_service( + display => $result->{avAesDmccName}, + state => $result->{avAesDmccState}, + status => $result->{avAesDmccStatus}, + license_error => $result->{avAesDmccLicenseError}, + mem_used_prct => + defined($result->{avAesDmccFreeMemory}) ? (($result->{avAesDmccUsedMemory} * 100) / ($result->{avAesDmccUsedMemory} + $result->{avAesDmccFreeMemory})) : undef + ); + + $self->manage_aep(%options); +} + +1; + +__END__ + +=head1 MODE + +Check services. + +=over 8 + +=item B<--filter-name> + +Filter service name (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status}, %{state}, %{license_error}, %{display} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{state}, %{license_error}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{state} ne "running" or %{status} ne "online"'). +Can used special variables like: %{status}, %{state}, %{license_error}, %{display} + +=item B<--unknown-aep-status> + +Set unknown threshold for status. +Can used special variables like: %{link_state}, %{session_state}, %{display} + +=item B<--warning-aep-status> + +Set warning threshold for status. +Can used special variables like: %{link_state}, %{session_state}, %{display} + +=item B<--critical-aep-status> + +Set critical threshold for status (Default: '%{link_state} ne "online" or %{session_state} ne "online"'). +Can used special variables like: %{link_state}, %{session_state}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'tsapi-clients-connected', 'dmcc-memory-usage' (%). + +=back + +=cut + diff --git a/centreon-plugins/hardware/telephony/avaya/aes/snmp/plugin.pm b/centreon-plugins/hardware/telephony/avaya/aes/snmp/plugin.pm new file mode 100644 index 000000000..ea9522983 --- /dev/null +++ b/centreon-plugins/hardware/telephony/avaya/aes/snmp/plugin.pm @@ -0,0 +1,55 @@ +# +# Copyright 2019 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 hardware::telephony::avaya::aes::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}} = ( + 'cpu' => 'snmp_standard::mode::cpu', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + 'services' => 'hardware::telephony::avaya::aes::snmp::mode::services', + 'storage' => 'snmp_standard::mode::storage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check avaya application enablement services in SNMP. + +=cut diff --git a/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/controllerstatus.pm b/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/controllerstatus.pm index 5efff4db7..18f1442e5 100644 --- a/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/controllerstatus.pm +++ b/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/controllerstatus.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "unknown-status:s" => { name => 'unknown_status', default => '' }, "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/hardware.pm b/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/hardware.pm index 76a0b3498..fd53b863a 100644 --- a/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/hardware.pm @@ -55,7 +55,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ups/alpha/snmp/mode/alarms.pm b/centreon-plugins/hardware/ups/alpha/snmp/mode/alarms.pm index 07588117c..2ab9142cb 100644 --- a/centreon-plugins/hardware/ups/alpha/snmp/mode/alarms.pm +++ b/centreon-plugins/hardware/ups/alpha/snmp/mode/alarms.pm @@ -48,7 +48,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ups/alpha/snmp/mode/batterystatus.pm b/centreon-plugins/hardware/ups/alpha/snmp/mode/batterystatus.pm index 48d0ae698..7db604316 100644 --- a/centreon-plugins/hardware/ups/alpha/snmp/mode/batterystatus.pm +++ b/centreon-plugins/hardware/ups/alpha/snmp/mode/batterystatus.pm @@ -100,7 +100,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "unknown-status:s" => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, diff --git a/centreon-plugins/hardware/ups/apc/snmp/mode/batterystatus.pm b/centreon-plugins/hardware/ups/apc/snmp/mode/batterystatus.pm index e9682342f..8b9f3b42f 100644 --- a/centreon-plugins/hardware/ups/apc/snmp/mode/batterystatus.pm +++ b/centreon-plugins/hardware/ups/apc/snmp/mode/batterystatus.pm @@ -110,7 +110,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "unknown-status:s" => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, diff --git a/centreon-plugins/hardware/ups/apc/snmp/mode/inputlines.pm b/centreon-plugins/hardware/ups/apc/snmp/mode/inputlines.pm index 051780b9a..650f704e2 100644 --- a/centreon-plugins/hardware/ups/apc/snmp/mode/inputlines.pm +++ b/centreon-plugins/hardware/ups/apc/snmp/mode/inputlines.pm @@ -82,7 +82,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/hardware/ups/apc/snmp/mode/outputlines.pm b/centreon-plugins/hardware/ups/apc/snmp/mode/outputlines.pm index 86c5cba18..b2e0ee559 100644 --- a/centreon-plugins/hardware/ups/apc/snmp/mode/outputlines.pm +++ b/centreon-plugins/hardware/ups/apc/snmp/mode/outputlines.pm @@ -100,7 +100,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "unknown-status:s" => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, diff --git a/centreon-plugins/hardware/ups/apc/snmp/mode/sensors.pm b/centreon-plugins/hardware/ups/apc/snmp/mode/sensors.pm index adb1f0f17..f720c8e07 100644 --- a/centreon-plugins/hardware/ups/apc/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/ups/apc/snmp/mode/sensors.pm @@ -51,7 +51,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ups/mge/snmp/mode/batterystatus.pm b/centreon-plugins/hardware/ups/mge/snmp/mode/batterystatus.pm index a1687722e..b1e68de29 100644 --- a/centreon-plugins/hardware/ups/mge/snmp/mode/batterystatus.pm +++ b/centreon-plugins/hardware/ups/mge/snmp/mode/batterystatus.pm @@ -42,7 +42,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/hardware/ups/mge/snmp/mode/environment.pm b/centreon-plugins/hardware/ups/mge/snmp/mode/environment.pm index 9b054c132..90fdb1d4d 100644 --- a/centreon-plugins/hardware/ups/mge/snmp/mode/environment.pm +++ b/centreon-plugins/hardware/ups/mge/snmp/mode/environment.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ups/mge/snmp/mode/inputlines.pm b/centreon-plugins/hardware/ups/mge/snmp/mode/inputlines.pm index b94c40118..dff55ffce 100644 --- a/centreon-plugins/hardware/ups/mge/snmp/mode/inputlines.pm +++ b/centreon-plugins/hardware/ups/mge/snmp/mode/inputlines.pm @@ -97,7 +97,6 @@ sub new { 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' }, "critical-status:s" => { name => 'critical_status', default => '%{badstatus} =~ /yes/' }, diff --git a/centreon-plugins/hardware/ups/mge/snmp/mode/outputlines.pm b/centreon-plugins/hardware/ups/mge/snmp/mode/outputlines.pm index db752567a..c58cb0723 100644 --- a/centreon-plugins/hardware/ups/mge/snmp/mode/outputlines.pm +++ b/centreon-plugins/hardware/ups/mge/snmp/mode/outputlines.pm @@ -89,7 +89,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ups/mge/snmp/mode/outputsource.pm b/centreon-plugins/hardware/ups/mge/snmp/mode/outputsource.pm index 9ee79deee..89aa56c89 100644 --- a/centreon-plugins/hardware/ups/mge/snmp/mode/outputsource.pm +++ b/centreon-plugins/hardware/ups/mge/snmp/mode/outputsource.pm @@ -46,7 +46,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-status:s" => { name => 'filter_status', default => '^OutputInverterOff'}, diff --git a/centreon-plugins/hardware/ups/nitram/snmp/plugin.pm b/centreon-plugins/hardware/ups/nitram/snmp/plugin.pm new file mode 100644 index 000000000..0954a2b88 --- /dev/null +++ b/centreon-plugins/hardware/ups/nitram/snmp/plugin.pm @@ -0,0 +1,48 @@ +# +# 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 hardware::ups::nitram::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} = '0.1'; + %{$self->{modes}} = ( + 'battery-status' => 'centreon::common::cps::ups::snmp::mode::batterystatus', + 'input-lines' => 'centreon::common::cps::ups::snmp::mode::inputlines', + 'output-lines' => 'centreon::common::cps::ups::snmp::mode::outputlines', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check UPS Nitram in SNMP. + +=cut diff --git a/centreon-plugins/hardware/ups/powerware/snmp/mode/alarms.pm b/centreon-plugins/hardware/ups/powerware/snmp/mode/alarms.pm index 414b1b6e0..ff9c3e9ab 100644 --- a/centreon-plugins/hardware/ups/powerware/snmp/mode/alarms.pm +++ b/centreon-plugins/hardware/ups/powerware/snmp/mode/alarms.pm @@ -75,7 +75,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-type:s" => { name => 'filter_type', diff --git a/centreon-plugins/hardware/ups/powerware/snmp/mode/batterystatus.pm b/centreon-plugins/hardware/ups/powerware/snmp/mode/batterystatus.pm index c36961535..a00cb05de 100644 --- a/centreon-plugins/hardware/ups/powerware/snmp/mode/batterystatus.pm +++ b/centreon-plugins/hardware/ups/powerware/snmp/mode/batterystatus.pm @@ -38,7 +38,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/hardware/ups/powerware/snmp/mode/environment.pm b/centreon-plugins/hardware/ups/powerware/snmp/mode/environment.pm index 967948e44..74eca2944 100644 --- a/centreon-plugins/hardware/ups/powerware/snmp/mode/environment.pm +++ b/centreon-plugins/hardware/ups/powerware/snmp/mode/environment.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ups/powerware/snmp/mode/inputlines.pm b/centreon-plugins/hardware/ups/powerware/snmp/mode/inputlines.pm index 486fee3c9..6b507ec53 100644 --- a/centreon-plugins/hardware/ups/powerware/snmp/mode/inputlines.pm +++ b/centreon-plugins/hardware/ups/powerware/snmp/mode/inputlines.pm @@ -81,7 +81,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ups/powerware/snmp/mode/outputlines.pm b/centreon-plugins/hardware/ups/powerware/snmp/mode/outputlines.pm index ba586b19e..e5c63105d 100644 --- a/centreon-plugins/hardware/ups/powerware/snmp/mode/outputlines.pm +++ b/centreon-plugins/hardware/ups/powerware/snmp/mode/outputlines.pm @@ -90,7 +90,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ups/powerware/snmp/mode/outputsource.pm b/centreon-plugins/hardware/ups/powerware/snmp/mode/outputsource.pm index 12b19e5ad..8c8b0bd46 100644 --- a/centreon-plugins/hardware/ups/powerware/snmp/mode/outputsource.pm +++ b/centreon-plugins/hardware/ups/powerware/snmp/mode/outputsource.pm @@ -53,7 +53,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/alarms.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/alarms.pm index 6c818aa26..ef4a64560 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/alarms.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/alarms.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/batterystatus.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/batterystatus.pm index 7422c257f..0511cbde9 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/batterystatus.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/batterystatus.pm @@ -20,105 +20,125 @@ package hardware::ups::standard::rfc1628::snmp::mode::batterystatus; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); -my %battery_status = ( - 1 => ['unknown', 'UNKNOWN'], - 2 => ['normal', 'OK'], - 3 => ['low', 'WARNING'], - 4 => ['depleted', 'CRITICAL'], -); +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf('battery status is %s', $self->{result_values}->{status}); +} + +sub custom_load_output { + my ($self, %options) = @_; + + return sprintf("charge remaining: %s%% (%s minutes remaining)", + $self->{result_values}->{charge_remain_absolute}, + $self->{result_values}->{minute_remain_absolute} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'charge-remaining', nlabel => 'battery.charge.remaining.percent', set => { + key_values => [ { name => 'charge_remain' }, { name => 'minute_remain' } ], + closure_custom_output => $self->can('custom_load_output'), + perfdatas => [ + { label => 'load', value => 'charge_remain_absolute', template => '%s', min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'current', nlabel => 'battery.current.ampere', display_ok => 0, set => { + key_values => [ { name => 'current', no_value => 0 } ], + output_template => 'current: %s A', + perfdatas => [ + { label => 'current', value => 'current_absolute', template => '%s', min => 0, unit => 'A' }, + ], + } + }, + { label => 'voltage', nlabel => 'battery.voltage.volt', display_ok => 0, set => { + key_values => [ { name => 'voltage', no_value => 0 } ], + output_template => 'voltage: %s V', + perfdatas => [ + { label => 'voltage', value => 'voltage_absolute', template => '%s', unit => 'V' }, + ], + } + }, + { label => 'temperature', nlabel => 'battery.temperature.celsius', display_ok => 0, set => { + key_values => [ { name => 'temperature', no_value => 0 } ], + output_template => 'temperature: %s C', + perfdatas => [ + { label => 'temp', value => 'temperature_absolute', template => '%s', 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 => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /low/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /depleted/i' }, + }); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%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(); - } + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); } -sub run { +my $map_status = { 1 => 'unknown', 2 => 'normal', 3 => 'low', 4 => 'depleted' }; + +my $mapping = { + upsBatteryStatus => { oid => '.1.3.6.1.2.1.33.1.2.1', map => $map_status }, + upsEstimatedMinutesRemaining => { oid => '.1.3.6.1.2.1.33.1.2.3' }, + upsEstimatedChargeRemaining => { oid => '.1.3.6.1.2.1.33.1.2.4' }, + upsBatteryVoltage => { oid => '.1.3.6.1.2.1.33.1.2.5' }, # in dV + upsBatteryCurrent => { oid => '.1.3.6.1.2.1.33.1.2.6' }, # in dA + upsBatteryTemperature => { oid => '.1.3.6.1.2.1.33.1.2.7' }, # in degrees Centigrade +}; + +sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; my $oid_upsBattery = '.1.3.6.1.2.1.33.1.2'; - my $oid_upsBatteryStatus = '.1.3.6.1.2.1.33.1.2.1.0'; - my $oid_upsEstimatedMinutesRemaining = '.1.3.6.1.2.1.33.1.2.3.0'; - my $oid_upsEstimatedChargeRemaining = '.1.3.6.1.2.1.33.1.2.4.0'; - my $oid_upsBatteryVoltage = '.1.3.6.1.2.1.33.1.2.5.0'; # in dV - my $oid_upsBatteryCurrent = '.1.3.6.1.2.1.33.1.2.6.0'; # in dA - my $oid_upsBatteryTemperature = '.1.3.6.1.2.1.33.1.2.7.0'; # in degrees Centigrade - - my $result = $self->{snmp}->get_table(oid => $oid_upsBattery, nothing_quit => 1); + my $snmp_result = $options{snmp}->get_table(oid => $oid_upsBattery, nothing_quit => 1); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); - my $current = (defined($result->{$oid_upsBatteryCurrent}) && $result->{$oid_upsBatteryCurrent} =~ /\d/) ? - $result->{$oid_upsBatteryCurrent} * 0.1 : 0; - my $voltage = (defined($result->{$oid_upsBatteryVoltage}) && $result->{$oid_upsBatteryVoltage} =~ /\d/) ? - $result->{$oid_upsBatteryVoltage} * 0.1 : 0; - my $temp = defined($result->{$oid_upsBatteryTemperature}) ? $result->{$oid_upsBatteryTemperature} : 0; - my $min_remain = (defined($result->{$oid_upsEstimatedMinutesRemaining}) && $result->{$oid_upsEstimatedMinutesRemaining} =~ /\d/) ? - $result->{$oid_upsEstimatedMinutesRemaining} : 'unknown'; - my $charge_remain = (defined($result->{$oid_upsEstimatedChargeRemaining}) && $result->{$oid_upsEstimatedChargeRemaining} =~ /\d/) ? - $result->{$oid_upsEstimatedChargeRemaining} : 'unknown'; - my $status = defined($result->{$oid_upsBatteryStatus}) ? $result->{$oid_upsBatteryStatus} : 1; # we put unknown ??? - - $self->{output}->output_add(severity => ${$battery_status{$status}}[1], - short_msg => sprintf("Battery status is %s", ${$battery_status{$status}}[0])); - my $exit_code = 'ok'; - if ($charge_remain ne 'unknown') { - $exit_code = $self->{perfdata}->threshold_check(value => $charge_remain, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->perfdata_add(label => 'load', unit => '%', - value => $charge_remain, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); - } - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Charge remaining: %s%% (%s minutes remaining)", $charge_remain, $min_remain)); - - if ($current != 0) { - $self->{output}->perfdata_add(label => 'current', unit => 'A', - value => $current, - ); - } - if ($voltage != 0) { - $self->{output}->perfdata_add(label => 'voltage', unit => 'V', - value => $voltage, - ); - } - if ($temp != 0) { - $self->{output}->perfdata_add(label => 'temp', unit => 'C', - value => $temp, - ); - } - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { + current => (defined($result->{upsBatteryCurrent}) && $result->{upsBatteryCurrent} =~ /\d/) ? $result->{upsBatteryCurrent} * 0.1 : 0, + voltage => (defined($result->{upsBatteryVoltage}) && $result->{upsBatteryVoltage} =~ /\d/) ? $result->{upsBatteryVoltage} * 0.1 : 0, + temperature => $result->{upsBatteryTemperature}, + minute_remain => (defined($result->{upsEstimatedMinutesRemaining}) && $result->{upsEstimatedMinutesRemaining} =~ /\d/) ? $result->{upsEstimatedMinutesRemaining} : 'unknown', + charge_remain => (defined($result->{upsEstimatedChargeRemaining}) && $result->{upsEstimatedChargeRemaining} =~ /\d/) ? $result->{upsEstimatedChargeRemaining} : undef, + status => $result->{upsBatteryStatus}, + }; } 1; @@ -127,17 +147,30 @@ __END__ =head1 MODE -Check Battery Status and battery charge remaining. +Check battery status and charge remaining. =over 8 -=item B<--warning> +=item B<--unknown-status> -Threshold warning in percent of charge remaining. +Set warning threshold for status (Default: '%{status} =~ /unknown/i'). +Can used special variables like: %{status} -=item B<--critical> +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /low/i'). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /depleted/i'). +Can used special variables like: %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'charge-remaining' (%), 'current' (A), 'voltage' (V), 'temperature' (C). -Threshold critical in percent of charge remaining. =back diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm index 03afcc08b..10216ae96 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm @@ -83,7 +83,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm index 6d34d78d4..55601b52b 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm @@ -89,7 +89,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputsource.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputsource.pm index 8445492fc..a277019f5 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputsource.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputsource.pm @@ -40,7 +40,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/3com/snmp/mode/components/fan.pm b/centreon-plugins/network/3com/snmp/mode/components/fan.pm index 9067a6d67..ee7fd6387 100644 --- a/centreon-plugins/network/3com/snmp/mode/components/fan.pm +++ b/centreon-plugins/network/3com/snmp/mode/components/fan.pm @@ -37,9 +37,9 @@ my $mapping = { my $oid_hwdevMFanStatusEntry = '.1.3.6.1.4.1.43.45.1.2.23.1.9.1.1.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_hwdevMFanStatusEntry }; + push @{$self->{request}}, { oid => $oid_hwdevMFanStatusEntry }; } sub check { @@ -62,7 +62,7 @@ sub check { $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is '%s' [instance: %s]", $instance, $result->{hwDevMFanStatus}, $instance)); - my $exit = $self->get_severity(section => 'fan', value => $result->{hwDevMFanStatus}); + my $exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{hwDevMFanStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Fan '%s' status is %s", @@ -71,4 +71,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/network/3com/snmp/mode/components/psu.pm b/centreon-plugins/network/3com/snmp/mode/components/psu.pm index 2ae8fb00f..362352f98 100644 --- a/centreon-plugins/network/3com/snmp/mode/components/psu.pm +++ b/centreon-plugins/network/3com/snmp/mode/components/psu.pm @@ -37,9 +37,9 @@ my $mapping = { my $oid_hwdevMPowerStatusEntry = '.1.3.6.1.4.1.43.45.1.2.23.1.9.1.2.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_hwdevMPowerStatusEntry }; + push @{$self->{request}}, { oid => $oid_hwdevMPowerStatusEntry }; } sub check { @@ -62,7 +62,7 @@ sub check { $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s' [instance: %s]", $instance, $result->{hwDevMPowerStatus}, $instance)); - my $exit = $self->get_severity(section => 'psu', value => $result->{hwDevMPowerStatus}); + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{hwDevMPowerStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Power supply '%s' status is %s", @@ -71,4 +71,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/network/3com/snmp/mode/cpu.pm b/centreon-plugins/network/3com/snmp/mode/cpu.pm index 41e59276c..995596e43 100644 --- a/centreon-plugins/network/3com/snmp/mode/cpu.pm +++ b/centreon-plugins/network/3com/snmp/mode/cpu.pm @@ -76,7 +76,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/3com/snmp/mode/hardware.pm b/centreon-plugins/network/3com/snmp/mode/hardware.pm index 457f2b60b..a4287f0b6 100644 --- a/centreon-plugins/network/3com/snmp/mode/hardware.pm +++ b/centreon-plugins/network/3com/snmp/mode/hardware.pm @@ -20,227 +20,55 @@ package network::3com::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use centreon::plugins::misc; -my $thresholds = { - fan => [ - ['active', 'OK'], - ['deactive', 'CRITICAL'], - ['not-install', 'OK'], - ['unsupport', 'WARNING'], - ], - psu => [ - ['active', 'OK'], - ['deactive', 'CRITICAL'], - ['not-install', 'OK'], - ['unsupport', 'WARNING'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^psu|fan$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['active', 'OK'], + ['deactive', 'CRITICAL'], + ['not-install', 'OK'], + ['unsupport', 'WARNING'], + ], + }; + + $self->{components_path} = 'network::3com::snmp::mode::components'; + $self->{components_module} = ['psu', 'fan']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter:s@" => { name => 'filter' }, - "absent-problem:s@" => { name => 'absent_problem' }, - "component:s" => { name => 'component', default => '.*' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => {}); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{filter} = []; - foreach my $val (@{$self->{option_results}->{filter}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; - } - - $self->{absent_problem} = []; - foreach my $val (@{$self->{option_results}->{absent_problem}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - push @{$self->{absent_problem}}, { filter => $values[0], instance => $values[1] }; - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - if (scalar(@values) < 3) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $instance, $status, $filter); - if (scalar(@values) == 3) { - ($section, $status, $filter) = @values; - $instance = '.*'; - } else { - ($section, $instance, $status, $filter) = @values; - } - if ($section !~ /^psu|fan$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'."); - $self->{output}->option_exit(); - } - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $snmp_request = []; - my @components = ('psu', 'fan'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::3com::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::3com::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub absent_problem { - my ($self, %options) = @_; - - foreach (@{$self->{absent_problem}}) { - if ($options{section} =~ /$_->{filter}/) { - if (!defined($_->{instance}) || $options{instance} =~ /$_->{instance}/) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Component '%s' instance '%s' is not present", - $options{section}, $options{instance})); - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)")); - $self->{components}->{$options{section}}->{skip}++; - return 1; - } - } - } - - return 0; -} - -sub check_filter { - my ($self, %options) = @_; - - foreach (@{$self->{filter}}) { - if ($options{section} =~ /$_->{filter}/) { - if (!defined($options{instance}) && !defined($_->{instance})) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } - } - - return 0; -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i && - (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) { - $status = $_->{status}; - return $status; - } - } - } - my $label = defined($options{label}) ? $options{label} : $options{section}; - foreach (@{$thresholds->{$label}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ =head1 MODE -Check Hardware (Power Supply, Fan). +Check hardware =over 8 @@ -272,4 +100,4 @@ Example: --threshold-overload='fan,CRITICAL,^(?!(active)$)' =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/network/3com/snmp/mode/memory.pm b/centreon-plugins/network/3com/snmp/mode/memory.pm index 311b74515..c8d4312e7 100644 --- a/centreon-plugins/network/3com/snmp/mode/memory.pm +++ b/centreon-plugins/network/3com/snmp/mode/memory.pm @@ -105,7 +105,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/a10/ax/snmp/mode/cpu.pm b/centreon-plugins/network/a10/ax/snmp/mode/cpu.pm index 195c1cc86..7b39a8c23 100644 --- a/centreon-plugins/network/a10/ax/snmp/mode/cpu.pm +++ b/centreon-plugins/network/a10/ax/snmp/mode/cpu.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/a10/ax/snmp/mode/disk.pm b/centreon-plugins/network/a10/ax/snmp/mode/disk.pm index 000ecda8c..1002ba19b 100644 --- a/centreon-plugins/network/a10/ax/snmp/mode/disk.pm +++ b/centreon-plugins/network/a10/ax/snmp/mode/disk.pm @@ -93,7 +93,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/a10/ax/snmp/mode/globalstats.pm b/centreon-plugins/network/a10/ax/snmp/mode/globalstats.pm index a597691dc..41267ad22 100644 --- a/centreon-plugins/network/a10/ax/snmp/mode/globalstats.pm +++ b/centreon-plugins/network/a10/ax/snmp/mode/globalstats.pm @@ -69,7 +69,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/a10/ax/snmp/mode/hardware.pm b/centreon-plugins/network/a10/ax/snmp/mode/hardware.pm index c90c051e6..a6b746bdf 100644 --- a/centreon-plugins/network/a10/ax/snmp/mode/hardware.pm +++ b/centreon-plugins/network/a10/ax/snmp/mode/hardware.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/a10/ax/snmp/mode/listvservers.pm b/centreon-plugins/network/a10/ax/snmp/mode/listvservers.pm index dba35e9f7..8c78cfa89 100644 --- a/centreon-plugins/network/a10/ax/snmp/mode/listvservers.pm +++ b/centreon-plugins/network/a10/ax/snmp/mode/listvservers.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/a10/ax/snmp/mode/memory.pm b/centreon-plugins/network/a10/ax/snmp/mode/memory.pm index 8c2eeeb70..61863676c 100644 --- a/centreon-plugins/network/a10/ax/snmp/mode/memory.pm +++ b/centreon-plugins/network/a10/ax/snmp/mode/memory.pm @@ -93,7 +93,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/a10/ax/snmp/mode/vserverusage.pm b/centreon-plugins/network/a10/ax/snmp/mode/vserverusage.pm index 0b2f85e1b..c88f0bed5 100644 --- a/centreon-plugins/network/a10/ax/snmp/mode/vserverusage.pm +++ b/centreon-plugins/network/a10/ax/snmp/mode/vserverusage.pm @@ -110,7 +110,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/acmepacket/snmp/mode/hardware.pm b/centreon-plugins/network/acmepacket/snmp/mode/hardware.pm index d2fe6bce2..80dc30ea1 100644 --- a/centreon-plugins/network/acmepacket/snmp/mode/hardware.pm +++ b/centreon-plugins/network/acmepacket/snmp/mode/hardware.pm @@ -62,7 +62,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/acmepacket/snmp/mode/listrealm.pm b/centreon-plugins/network/acmepacket/snmp/mode/listrealm.pm index 9557e7d6f..93924cfbc 100644 --- a/centreon-plugins/network/acmepacket/snmp/mode/listrealm.pm +++ b/centreon-plugins/network/acmepacket/snmp/mode/listrealm.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/acmepacket/snmp/mode/listsip.pm b/centreon-plugins/network/acmepacket/snmp/mode/listsip.pm index a910b476e..167236f58 100644 --- a/centreon-plugins/network/acmepacket/snmp/mode/listsip.pm +++ b/centreon-plugins/network/acmepacket/snmp/mode/listsip.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/acmepacket/snmp/mode/realmusage.pm b/centreon-plugins/network/acmepacket/snmp/mode/realmusage.pm index a5d35354b..bcde8652d 100644 --- a/centreon-plugins/network/acmepacket/snmp/mode/realmusage.pm +++ b/centreon-plugins/network/acmepacket/snmp/mode/realmusage.pm @@ -101,7 +101,7 @@ sub set_counters { key_values => [ { name => 'apSigRealmStatsTotalMajorRFactorExceeded', diff => 1 }, { name => 'display' } ], output_template => 'Total Rfactor Exceeded : %s', perfdatas => [ - { label => 'total_rfactor', value => 'apSigRealmStatsTotalMajorRFactorExceededabsolute', template => '%s', + { label => 'total_rfactor', value => 'apSigRealmStatsTotalMajorRFactorExceeded_absolute', template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } @@ -120,7 +120,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/acmepacket/snmp/mode/sipusage.pm b/centreon-plugins/network/acmepacket/snmp/mode/sipusage.pm index 65578e2b2..b5a135a0b 100644 --- a/centreon-plugins/network/acmepacket/snmp/mode/sipusage.pm +++ b/centreon-plugins/network/acmepacket/snmp/mode/sipusage.pm @@ -109,7 +109,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/acmepacket/snmp/mode/systemusage.pm b/centreon-plugins/network/acmepacket/snmp/mode/systemusage.pm index 8aa44ed19..3ffa10c49 100644 --- a/centreon-plugins/network/acmepacket/snmp/mode/systemusage.pm +++ b/centreon-plugins/network/acmepacket/snmp/mode/systemusage.pm @@ -118,7 +118,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-replication-status:s" => { name => 'warning_replication_status', default => '' }, diff --git a/centreon-plugins/network/adva/fsp3000/snmp/mode/alarms.pm b/centreon-plugins/network/adva/fsp3000/snmp/mode/alarms.pm index d41d3aa4e..9caf9e36e 100644 --- a/centreon-plugins/network/adva/fsp3000/snmp/mode/alarms.pm +++ b/centreon-plugins/network/adva/fsp3000/snmp/mode/alarms.pm @@ -74,7 +74,6 @@ sub new { 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 => '%{severity} =~ /warning|minor/i' }, diff --git a/centreon-plugins/network/aerohive/snmp/mode/connectedusers.pm b/centreon-plugins/network/aerohive/snmp/mode/connectedusers.pm index 527b7001e..a9df59658 100644 --- a/centreon-plugins/network/aerohive/snmp/mode/connectedusers.pm +++ b/centreon-plugins/network/aerohive/snmp/mode/connectedusers.pm @@ -67,7 +67,6 @@ sub new { 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' }, diff --git a/centreon-plugins/network/alcatel/isam/snmp/mode/cpu.pm b/centreon-plugins/network/alcatel/isam/snmp/mode/cpu.pm index 01e979b61..03b6f6bb6 100644 --- a/centreon-plugins/network/alcatel/isam/snmp/mode/cpu.pm +++ b/centreon-plugins/network/alcatel/isam/snmp/mode/cpu.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/alcatel/isam/snmp/mode/hardware.pm b/centreon-plugins/network/alcatel/isam/snmp/mode/hardware.pm index 5766d32e6..0c1893b8d 100644 --- a/centreon-plugins/network/alcatel/isam/snmp/mode/hardware.pm +++ b/centreon-plugins/network/alcatel/isam/snmp/mode/hardware.pm @@ -60,7 +60,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/alcatel/isam/snmp/mode/hubsapusage.pm b/centreon-plugins/network/alcatel/isam/snmp/mode/hubsapusage.pm index b0767fe1b..86a5a0ae5 100644 --- a/centreon-plugins/network/alcatel/isam/snmp/mode/hubsapusage.pm +++ b/centreon-plugins/network/alcatel/isam/snmp/mode/hubsapusage.pm @@ -282,7 +282,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "reload-cache-time:s" => { name => 'reload_cache_time', default => 300 }, "display-name:s" => { name => 'display_name', default => '%{SvcDescription}.%{IfName}.%{SapEncapName}' }, diff --git a/centreon-plugins/network/alcatel/isam/snmp/mode/listhubsap.pm b/centreon-plugins/network/alcatel/isam/snmp/mode/listhubsap.pm index 26f9088e6..42ffbb7f8 100644 --- a/centreon-plugins/network/alcatel/isam/snmp/mode/listhubsap.pm +++ b/centreon-plugins/network/alcatel/isam/snmp/mode/listhubsap.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/alcatel/isam/snmp/mode/memory.pm b/centreon-plugins/network/alcatel/isam/snmp/mode/memory.pm index d4aaf37da..86b2667c0 100644 --- a/centreon-plugins/network/alcatel/isam/snmp/mode/memory.pm +++ b/centreon-plugins/network/alcatel/isam/snmp/mode/memory.pm @@ -116,7 +116,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/network/alcatel/omniswitch/snmp/mode/cpu.pm b/centreon-plugins/network/alcatel/omniswitch/snmp/mode/cpu.pm index 0fa71361c..10f8f7126 100644 --- a/centreon-plugins/network/alcatel/omniswitch/snmp/mode/cpu.pm +++ b/centreon-plugins/network/alcatel/omniswitch/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '' }, "critical:s" => { name => 'critical', default => '' }, diff --git a/centreon-plugins/network/alcatel/omniswitch/snmp/mode/flashmemory.pm b/centreon-plugins/network/alcatel/omniswitch/snmp/mode/flashmemory.pm index d0c182d9a..f70f6ab90 100644 --- a/centreon-plugins/network/alcatel/omniswitch/snmp/mode/flashmemory.pm +++ b/centreon-plugins/network/alcatel/omniswitch/snmp/mode/flashmemory.pm @@ -84,7 +84,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/alcatel/omniswitch/snmp/mode/hardware.pm b/centreon-plugins/network/alcatel/omniswitch/snmp/mode/hardware.pm index 4ec73fc53..7425d9a42 100644 --- a/centreon-plugins/network/alcatel/omniswitch/snmp/mode/hardware.pm +++ b/centreon-plugins/network/alcatel/omniswitch/snmp/mode/hardware.pm @@ -26,7 +26,8 @@ use network::alcatel::omniswitch::snmp::mode::components::resources qw(%oids); sub set_system { my ($self, %options) = @_; - $self->{regexp_threshold_overload_check_section_option} = '^(backplane|chassis|container|fan|module|other|port|psu|sensor|stack|unknown)$'; + $self->{regexp_threshold_overload_check_section_option} = + '^(?:backplane|chassis|container|fan|module|other|port|psu|sensor|stack|unknown)\.(?:oper|admin|status)$'; $self->{cb_hook2} = 'snmp_execute'; @@ -90,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/alcatel/omniswitch/snmp/mode/memory.pm b/centreon-plugins/network/alcatel/omniswitch/snmp/mode/memory.pm index 582ae7489..1c7229be0 100644 --- a/centreon-plugins/network/alcatel/omniswitch/snmp/mode/memory.pm +++ b/centreon-plugins/network/alcatel/omniswitch/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '' }, "critical:s" => { name => 'critical', default => '' }, diff --git a/centreon-plugins/network/alcatel/oxe/snmp/mode/domainusage.pm b/centreon-plugins/network/alcatel/oxe/snmp/mode/domainusage.pm index 3502525ca..d4c5bbcda 100644 --- a/centreon-plugins/network/alcatel/oxe/snmp/mode/domainusage.pm +++ b/centreon-plugins/network/alcatel/oxe/snmp/mode/domainusage.pm @@ -133,7 +133,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-domain:s" => { name => 'filter_domain' }, }); diff --git a/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm b/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm index b2eff1af9..32ab5ea62 100644 --- a/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm +++ b/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm @@ -47,7 +47,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxstate.pm b/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxstate.pm index 0fc51400f..b6b6c288a 100644 --- a/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxstate.pm +++ b/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxstate.pm @@ -49,7 +49,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/network/alcatel/pss/1830/snmp/mode/listsap.pm b/centreon-plugins/network/alcatel/pss/1830/snmp/mode/listsap.pm index 98a46b8ed..e05382fdc 100644 --- a/centreon-plugins/network/alcatel/pss/1830/snmp/mode/listsap.pm +++ b/centreon-plugins/network/alcatel/pss/1830/snmp/mode/listsap.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/alcatel/pss/1830/snmp/mode/sapqosstats.pm b/centreon-plugins/network/alcatel/pss/1830/snmp/mode/sapqosstats.pm index 0a05b3d51..c34676f00 100644 --- a/centreon-plugins/network/alcatel/pss/1830/snmp/mode/sapqosstats.pm +++ b/centreon-plugins/network/alcatel/pss/1830/snmp/mode/sapqosstats.pm @@ -108,7 +108,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "reload-cache-time:s" => { name => 'reload_cache_time', default => 300 }, diff --git a/centreon-plugins/network/alvarion/breezeaccess/snmp/mode/radiostatus.pm b/centreon-plugins/network/alvarion/breezeaccess/snmp/mode/radiostatus.pm index 4e0dfe5f6..af225d0ca 100644 --- a/centreon-plugins/network/alvarion/breezeaccess/snmp/mode/radiostatus.pm +++ b/centreon-plugins/network/alvarion/breezeaccess/snmp/mode/radiostatus.pm @@ -80,7 +80,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/aruba/instant/snmp/mode/apusage.pm b/centreon-plugins/network/aruba/instant/snmp/mode/apusage.pm new file mode 100644 index 000000000..e8a647e50 --- /dev/null +++ b/centreon-plugins/network/aruba/instant/snmp/mode/apusage.pm @@ -0,0 +1,255 @@ +# +# Copyright 2019 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::aruba::instant::snmp::mode::apusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = "Status is '" . $self->{result_values}->{status} . "'"; + return $msg; +} + +sub custom_memory_output { + my ($self, %options) = @_; + + my $msg = sprintf("Memory Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)", + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute}); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', + message_multiple => 'All access points are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{ap} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'clients', nlabel => 'clients.current.count', set => { + key_values => [ { name => 'clients' }, { name => 'display' } ], + output_template => 'Current Clients: %s', + perfdatas => [ + { label => 'clients', value => 'clients_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'cpu', nlabel => 'cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu' }, { name => 'display' } ], + output_template => 'Cpu: %.2f%%', + perfdatas => [ + { label => 'cpu', value => 'cpu_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'mem-usage', nlabel => 'memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, + { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_memory_output'), + perfdatas => [ + { label => 'mem_used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'mem-usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, + { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_memory_output'), + perfdatas => [ + { label => 'mem_free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'mem-usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' }, { name => 'display' } ], + output_template => 'Memory Used: %.2f %%', + perfdatas => [ + { label => 'mem_used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /up/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub prefix_ap_output { + my ($self, %options) = @_; + + return "Access Point '" . $options{instance_value}->{display} . "' "; +} + +my $map_ap_status = { + 1 => 'up', 2 => 'down' +}; + +my $mapping = { + aiAPName => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.2' }, + aiAPIPAddress => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.3' }, + aiAPCPUUtilization => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.7' }, + aiAPMemoryFree => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.8' }, + aiAPTotalMemory => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.10' }, + aiAPStatus => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.11', map => $map_ap_status }, +}; +my $oid_aiAccessPointEntry = '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1'; +my $oid_aiClientAPIPAddress = '.1.3.6.1.4.1.14823.2.3.3.1.2.4.1.4'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_aiAccessPointEntry, start => $mapping->{aiAPName}->{oid}, + end => $mapping->{aiAPStatus}->{oid} }, + { oid => $oid_aiClientAPIPAddress }, + ], + nothing_quit => 1 + ); + + my $link_ap = {}; + $self->{ap} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_aiAccessPointEntry}}) { + next if ($oid !~ /^$mapping->{aiAPName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_aiAccessPointEntry}, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{aiAPName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping access point '" . $result->{aiAPName} . "'.", debug => 1); + next; + } + + $self->{ap}->{$result->{aiAPName}} = { + display => $result->{aiAPName}, + status => $result->{aiAPStatus}, + cpu => $result->{aiAPCPUUtilization}, + total => $result->{aiAPTotalMemory}, + free => $result->{aiAPMemoryFree}, + used => $result->{aiAPTotalMemory} - $result->{aiAPMemoryFree}, + prct_free => $result->{aiAPMemoryFree} * 100 / $result->{aiAPTotalMemory}, + prct_used => 100 - ($result->{aiAPMemoryFree} * 100 / $result->{aiAPTotalMemory}), + clients => 0, + }; + $link_ap->{$result->{aiAPIPAddress}} = $self->{ap}->{$result->{aiAPName}}; + } + + if (scalar(keys %{$snmp_result->{$oid_aiAccessPointEntry}}) == 0) { + $self->{ap}->{default} = { + display => 'default', + clients => 0, + }; + } + + foreach my $oid (keys %{$snmp_result->{$oid_aiClientAPIPAddress}}) { + my $ap_ipaddress = $snmp_result->{$oid_aiClientAPIPAddress}->{$oid}; + if (defined($link_ap->{$ap_ipaddress})) { + $link_ap->{$ap_ipaddress}->{clients}++; + } else { + $self->{ap}->{default}->{clients}++; + } + } + + if (scalar(keys %{$self->{ap}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No access point found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check access point usage. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^cpu$' + +=item B<--filter-name> + +Filter access point name (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /up/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'cpu', 'clients', +'mem-usage' (B), 'mem-usage-free' (B), 'mem-usage-prct' (%). + +=back + +=cut diff --git a/centreon-plugins/network/aruba/instant/snmp/mode/ssidstatus.pm b/centreon-plugins/network/aruba/instant/snmp/mode/ssidstatus.pm new file mode 100644 index 000000000..5b43d98ea --- /dev/null +++ b/centreon-plugins/network/aruba/instant/snmp/mode/ssidstatus.pm @@ -0,0 +1,159 @@ +# +# Copyright 2019 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::aruba::instant::snmp::mode::ssidstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = "Status is '" . $self->{result_values}->{status} . "'"; + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ssid', display_long => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All SSIDs are ok', type => 1 }, + ]; + + $self->{maps_counters}->{ssid} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "SSID '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /enable/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +my $map_status = { + 0 => 'enable', 1 => 'disable' +}; + +my $mapping = { + aiSSID => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.1.7.1.2' }, + aiSSIDStatus => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.1.7.1.3', map => $map_status }, +}; +my $oid_aiWlanSSIDEntry = '.1.3.6.1.4.1.14823.2.3.3.1.1.7.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_aiWlanSSIDEntry, + start => $mapping->{aiSSID}->{oid}, + end => $mapping->{aiSSIDStatus}->{oid}, + nothing_quit => 1 + ); + + $self->{ssid} = {}; + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{aiSSID}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance + ); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{aiSSID} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping ssid '" . $result->{aiSSID} . "'.", debug => 1); + next; + } + + $self->{ssid}->{$result->{aiSSID}} = { + status => $result->{aiSSIDStatus}, + display => $result->{aiSSID} + }; + } + + if (scalar(keys %{$self->{ssid}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No SSID found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check SSID status. + +=over 8 + +=item B<--filter-name> + +Filter SSID name (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /enable/i'). +Can used special variables like: %{status}, %{display} + +=back + +=cut diff --git a/centreon-plugins/network/aruba/instant/snmp/plugin.pm b/centreon-plugins/network/aruba/instant/snmp/plugin.pm new file mode 100644 index 000000000..9f822d1bf --- /dev/null +++ b/centreon-plugins/network/aruba/instant/snmp/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2019 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::aruba::instant::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}} = ( + 'ap-usage' => 'network::aruba::instant::snmp::mode::apusage', + 'ssid-status' => 'network::aruba::instant::snmp::mode::ssidstatus', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Aruba Instant in SNMP. + +=cut diff --git a/centreon-plugins/network/aruba/standard/snmp/plugin.pm b/centreon-plugins/network/aruba/standard/snmp/plugin.pm index 5dc8cba1f..2ff3a885e 100644 --- a/centreon-plugins/network/aruba/standard/snmp/plugin.pm +++ b/centreon-plugins/network/aruba/standard/snmp/plugin.pm @@ -31,15 +31,20 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'ap-connections' => 'centreon::common::aruba::snmp::mode::apconnections', - 'ap-users' => 'centreon::common::aruba::snmp::mode::apusers', - 'cpu' => 'centreon::common::aruba::snmp::mode::cpu', - 'hardware' => 'centreon::common::aruba::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'centreon::common::aruba::snmp::mode::memory', - 'storage' => 'centreon::common::aruba::snmp::mode::storage', - ); + 'ap-connections' => 'centreon::common::aruba::snmp::mode::apconnections', # Deprecated + 'ap-ssid-statistics' => 'centreon::common::aruba::snmp::mode::apssidstatistics', + 'ap-status' => 'centreon::common::aruba::snmp::mode::apstatus', + 'ap-users' => 'centreon::common::aruba::snmp::mode::apusers', # Deprecated + 'controller-status' => 'centreon::common::aruba::snmp::mode::controllerstatus', + 'cpu' => 'centreon::common::aruba::snmp::mode::cpu', + 'discovery' => 'centreon::common::aruba::snmp::mode::discovery', + 'hardware' => 'centreon::common::aruba::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'license' => 'centreon::common::aruba::snmp::mode::license', + 'memory' => 'centreon::common::aruba::snmp::mode::memory', + 'storage' => 'centreon::common::aruba::snmp::mode::storage', + ); return $self; } diff --git a/centreon-plugins/network/atto/fiberbridge/snmp/mode/components/alarm.pm b/centreon-plugins/network/atto/fibrebridge/snmp/mode/components/alarm.pm similarity index 97% rename from centreon-plugins/network/atto/fiberbridge/snmp/mode/components/alarm.pm rename to centreon-plugins/network/atto/fibrebridge/snmp/mode/components/alarm.pm index df79cbd68..99f83db2c 100644 --- a/centreon-plugins/network/atto/fiberbridge/snmp/mode/components/alarm.pm +++ b/centreon-plugins/network/atto/fibrebridge/snmp/mode/components/alarm.pm @@ -20,7 +20,7 @@ # Author : ArnoMLT # -package network::atto::fiberbridge::snmp::mode::components::alarm; +package network::atto::fibrebridge::snmp::mode::components::alarm; use strict; use warnings; diff --git a/centreon-plugins/network/atto/fiberbridge/snmp/mode/components/temperature.pm b/centreon-plugins/network/atto/fibrebridge/snmp/mode/components/temperature.pm similarity index 97% rename from centreon-plugins/network/atto/fiberbridge/snmp/mode/components/temperature.pm rename to centreon-plugins/network/atto/fibrebridge/snmp/mode/components/temperature.pm index f3ae18e17..eccf9cd4e 100644 --- a/centreon-plugins/network/atto/fiberbridge/snmp/mode/components/temperature.pm +++ b/centreon-plugins/network/atto/fibrebridge/snmp/mode/components/temperature.pm @@ -20,7 +20,7 @@ # Author : ArnoMLT # -package network::atto::fiberbridge::snmp::mode::components::temperature; +package network::atto::fibrebridge::snmp::mode::components::temperature; use strict; use warnings; diff --git a/centreon-plugins/network/atto/fiberbridge/snmp/mode/fcportusage.pm b/centreon-plugins/network/atto/fibrebridge/snmp/mode/fcportusage.pm similarity index 98% rename from centreon-plugins/network/atto/fiberbridge/snmp/mode/fcportusage.pm rename to centreon-plugins/network/atto/fibrebridge/snmp/mode/fcportusage.pm index c73c5cfb2..1913ed4ac 100644 --- a/centreon-plugins/network/atto/fiberbridge/snmp/mode/fcportusage.pm +++ b/centreon-plugins/network/atto/fibrebridge/snmp/mode/fcportusage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::atto::fiberbridge::snmp::mode::fcportusage; +package network::atto::fibrebridge::snmp::mode::fcportusage; use base qw(centreon::plugins::templates::counter); @@ -112,7 +112,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/network/atto/fiberbridge/snmp/mode/hardware.pm b/centreon-plugins/network/atto/fibrebridge/snmp/mode/hardware.pm similarity index 94% rename from centreon-plugins/network/atto/fiberbridge/snmp/mode/hardware.pm rename to centreon-plugins/network/atto/fibrebridge/snmp/mode/hardware.pm index fe573c18a..b17d13dce 100644 --- a/centreon-plugins/network/atto/fiberbridge/snmp/mode/hardware.pm +++ b/centreon-plugins/network/atto/fibrebridge/snmp/mode/hardware.pm @@ -20,7 +20,7 @@ # Author : ArnoMLT # -package network::atto::fiberbridge::snmp::mode::hardware; +package network::atto::fibrebridge::snmp::mode::hardware; use base qw(centreon::plugins::templates::hardware); @@ -47,7 +47,7 @@ sub set_system { ], }; - $self->{components_path} = 'network::atto::fiberbridge::snmp::mode::components'; + $self->{components_path} = 'network::atto::fibrebridge::snmp::mode::components'; $self->{components_module} = ['alarm', 'temperature']; } @@ -63,7 +63,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/atto/fiberbridge/snmp/plugin.pm b/centreon-plugins/network/atto/fibrebridge/snmp/plugin.pm similarity index 83% rename from centreon-plugins/network/atto/fiberbridge/snmp/plugin.pm rename to centreon-plugins/network/atto/fibrebridge/snmp/plugin.pm index 1947a9d01..45fdefd4c 100644 --- a/centreon-plugins/network/atto/fiberbridge/snmp/plugin.pm +++ b/centreon-plugins/network/atto/fibrebridge/snmp/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::atto::fiberbridge::snmp::plugin; +package network::atto::fibrebridge::snmp::plugin; use strict; use warnings; @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'network::atto::fiberbridge::snmp::mode::hardware', - 'fcport-usage' => 'network::atto::fiberbridge::snmp::mode::fcportusage', + 'hardware' => 'network::atto::fibrebridge::snmp::mode::hardware', + 'fcport-usage' => 'network::atto::fibrebridge::snmp::mode::fcportusage', ); return $self; @@ -44,6 +44,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Atto FiberBridge (6500, 7500,...) in SNMP. +Check Atto FibreBridge (6500, 7500,...) in SNMP. =cut diff --git a/centreon-plugins/network/audiocodes/snmp/mode/cpu.pm b/centreon-plugins/network/audiocodes/snmp/mode/cpu.pm index e3c7892c0..94cd328a2 100644 --- a/centreon-plugins/network/audiocodes/snmp/mode/cpu.pm +++ b/centreon-plugins/network/audiocodes/snmp/mode/cpu.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/audiocodes/snmp/mode/hardware.pm b/centreon-plugins/network/audiocodes/snmp/mode/hardware.pm index de5631ebb..fa42f7f4f 100644 --- a/centreon-plugins/network/audiocodes/snmp/mode/hardware.pm +++ b/centreon-plugins/network/audiocodes/snmp/mode/hardware.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/audiocodes/snmp/mode/listtrunks.pm b/centreon-plugins/network/audiocodes/snmp/mode/listtrunks.pm index a4ccd9a98..e689e71c6 100644 --- a/centreon-plugins/network/audiocodes/snmp/mode/listtrunks.pm +++ b/centreon-plugins/network/audiocodes/snmp/mode/listtrunks.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/audiocodes/snmp/mode/memory.pm b/centreon-plugins/network/audiocodes/snmp/mode/memory.pm index 8baf9c847..ccee3c067 100644 --- a/centreon-plugins/network/audiocodes/snmp/mode/memory.pm +++ b/centreon-plugins/network/audiocodes/snmp/mode/memory.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/audiocodes/snmp/mode/trunkstatus.pm b/centreon-plugins/network/audiocodes/snmp/mode/trunkstatus.pm index 150d52a56..81d8cb1c7 100644 --- a/centreon-plugins/network/audiocodes/snmp/mode/trunkstatus.pm +++ b/centreon-plugins/network/audiocodes/snmp/mode/trunkstatus.pm @@ -95,7 +95,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/barracuda/cloudgen/snmp/mode/boxservice.pm b/centreon-plugins/network/barracuda/cloudgen/snmp/mode/boxservice.pm index 26e27d29b..c074f629b 100644 --- a/centreon-plugins/network/barracuda/cloudgen/snmp/mode/boxservice.pm +++ b/centreon-plugins/network/barracuda/cloudgen/snmp/mode/boxservice.pm @@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use Digest::MD5 qw(md5_hex); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { @@ -69,16 +68,14 @@ sub prefix_services_output { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /^started$/i' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /^started$/i' }, + }); return $self; } @@ -141,10 +138,6 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => "No services found."); $self->{output}->option_exit(); } - - $self->{cache_name} = "barracuda_cloudgen_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . - (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . - (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); } 1; diff --git a/centreon-plugins/network/barracuda/cloudgen/snmp/mode/hardware.pm b/centreon-plugins/network/barracuda/cloudgen/snmp/mode/hardware.pm index 2032db399..9f69eeb34 100644 --- a/centreon-plugins/network/barracuda/cloudgen/snmp/mode/hardware.pm +++ b/centreon-plugins/network/barracuda/cloudgen/snmp/mode/hardware.pm @@ -57,10 +57,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); return $self; } diff --git a/centreon-plugins/network/barracuda/cloudgen/snmp/mode/listvpns.pm b/centreon-plugins/network/barracuda/cloudgen/snmp/mode/listvpns.pm index f6b7c7c67..a31dc0a5f 100644 --- a/centreon-plugins/network/barracuda/cloudgen/snmp/mode/listvpns.pm +++ b/centreon-plugins/network/barracuda/cloudgen/snmp/mode/listvpns.pm @@ -30,11 +30,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); $self->{vpn} = {}; return $self; diff --git a/centreon-plugins/network/barracuda/cloudgen/snmp/mode/serverservice.pm b/centreon-plugins/network/barracuda/cloudgen/snmp/mode/serverservice.pm index 551551b09..e43b8ec75 100644 --- a/centreon-plugins/network/barracuda/cloudgen/snmp/mode/serverservice.pm +++ b/centreon-plugins/network/barracuda/cloudgen/snmp/mode/serverservice.pm @@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use Digest::MD5 qw(md5_hex); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { @@ -69,16 +68,14 @@ sub prefix_services_output { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /^started$/i' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /^started$/i' }, + }); return $self; } @@ -141,10 +138,6 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => "No services found."); $self->{output}->option_exit(); } - - $self->{cache_name} = "barracuda_cloudgen_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . - (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . - (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); } 1; diff --git a/centreon-plugins/network/barracuda/cloudgen/snmp/mode/vpnstatus.pm b/centreon-plugins/network/barracuda/cloudgen/snmp/mode/vpnstatus.pm index 9b0730b8f..c127e941d 100644 --- a/centreon-plugins/network/barracuda/cloudgen/snmp/mode/vpnstatus.pm +++ b/centreon-plugins/network/barracuda/cloudgen/snmp/mode/vpnstatus.pm @@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use Digest::MD5 qw(md5_hex); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { @@ -69,17 +68,15 @@ sub prefix_vpns_output { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /^down$/i' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /^down$/i' }, + }); + return $self; } @@ -139,10 +136,6 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => "No VPNs found."); $self->{output}->option_exit(); } - - $self->{cache_name} = "barracuda_cloudgen_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . - (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . - (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); } 1; diff --git a/centreon-plugins/network/barracuda/cloudgen/snmp/plugin.pm b/centreon-plugins/network/barracuda/cloudgen/snmp/plugin.pm index e67fdb753..ba703ddb2 100644 --- a/centreon-plugins/network/barracuda/cloudgen/snmp/plugin.pm +++ b/centreon-plugins/network/barracuda/cloudgen/snmp/plugin.pm @@ -31,20 +31,20 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'snmp_standard::mode::cpu', - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'box-service' => 'network::barracuda::cloudgen::snmp::mode::boxservice', - 'hardware' => 'network::barracuda::cloudgen::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-vpns' => 'network::barracuda::cloudgen::snmp::mode::listvpns', - 'load' => 'snmp_standard::mode::loadaverage', - 'memory' => 'snmp_standard::mode::memory', - 'server-service' => 'network::barracuda::cloudgen::snmp::mode::serverservice', - 'storage' => 'snmp_standard::mode::storage', - 'uptime' => 'snmp_standard::mode::uptime', - 'vpn-status' => 'network::barracuda::cloudgen::snmp::mode::vpnstatus', - ); + 'cpu' => 'snmp_standard::mode::cpu', + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'box-service' => 'network::barracuda::cloudgen::snmp::mode::boxservice', + 'hardware' => 'network::barracuda::cloudgen::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-vpns' => 'network::barracuda::cloudgen::snmp::mode::listvpns', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + 'server-service' => 'network::barracuda::cloudgen::snmp::mode::serverservice', + 'storage' => 'snmp_standard::mode::storage', + 'uptime' => 'snmp_standard::mode::uptime', + 'vpn-status' => 'network::barracuda::cloudgen::snmp::mode::vpnstatus', + ); return $self; } diff --git a/centreon-plugins/network/beeware/snmp/mode/listreverseproxy.pm b/centreon-plugins/network/beeware/snmp/mode/listreverseproxy.pm index eaaa036d0..7721032aa 100644 --- a/centreon-plugins/network/beeware/snmp/mode/listreverseproxy.pm +++ b/centreon-plugins/network/beeware/snmp/mode/listreverseproxy.pm @@ -38,7 +38,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-status:s" => { name => 'filter_status' }, diff --git a/centreon-plugins/network/beeware/snmp/mode/reverseproxyusage.pm b/centreon-plugins/network/beeware/snmp/mode/reverseproxyusage.pm index bf91721f1..183c053dc 100644 --- a/centreon-plugins/network/beeware/snmp/mode/reverseproxyusage.pm +++ b/centreon-plugins/network/beeware/snmp/mode/reverseproxyusage.pm @@ -93,7 +93,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/bluecoat/snmp/mode/clientconnections.pm b/centreon-plugins/network/bluecoat/snmp/mode/clientconnections.pm index 775436e43..ffc726f53 100644 --- a/centreon-plugins/network/bluecoat/snmp/mode/clientconnections.pm +++ b/centreon-plugins/network/bluecoat/snmp/mode/clientconnections.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/bluecoat/snmp/mode/clientrequests.pm b/centreon-plugins/network/bluecoat/snmp/mode/clientrequests.pm index b757638c7..04cfd3d65 100644 --- a/centreon-plugins/network/bluecoat/snmp/mode/clientrequests.pm +++ b/centreon-plugins/network/bluecoat/snmp/mode/clientrequests.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/bluecoat/snmp/mode/clienttraffic.pm b/centreon-plugins/network/bluecoat/snmp/mode/clienttraffic.pm index ac9c56713..384160450 100644 --- a/centreon-plugins/network/bluecoat/snmp/mode/clienttraffic.pm +++ b/centreon-plugins/network/bluecoat/snmp/mode/clienttraffic.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-received:s" => { name => 'warning_received' }, diff --git a/centreon-plugins/network/bluecoat/snmp/mode/cpu.pm b/centreon-plugins/network/bluecoat/snmp/mode/cpu.pm index 7c10239a3..136762944 100644 --- a/centreon-plugins/network/bluecoat/snmp/mode/cpu.pm +++ b/centreon-plugins/network/bluecoat/snmp/mode/cpu.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/bluecoat/snmp/mode/disk.pm b/centreon-plugins/network/bluecoat/snmp/mode/disk.pm index f5d30a4f5..0579a78ec 100644 --- a/centreon-plugins/network/bluecoat/snmp/mode/disk.pm +++ b/centreon-plugins/network/bluecoat/snmp/mode/disk.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/bluecoat/snmp/mode/hardware.pm b/centreon-plugins/network/bluecoat/snmp/mode/hardware.pm index e62f258e6..3c27e2d24 100644 --- a/centreon-plugins/network/bluecoat/snmp/mode/hardware.pm +++ b/centreon-plugins/network/bluecoat/snmp/mode/hardware.pm @@ -87,7 +87,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/bluecoat/snmp/mode/memory.pm b/centreon-plugins/network/bluecoat/snmp/mode/memory.pm index f900297f3..ee34f5cfb 100644 --- a/centreon-plugins/network/bluecoat/snmp/mode/memory.pm +++ b/centreon-plugins/network/bluecoat/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/bluecoat/snmp/mode/serverconnections.pm b/centreon-plugins/network/bluecoat/snmp/mode/serverconnections.pm index 97d28fcb1..8bd88f8df 100644 --- a/centreon-plugins/network/bluecoat/snmp/mode/serverconnections.pm +++ b/centreon-plugins/network/bluecoat/snmp/mode/serverconnections.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/brocade/snmp/mode/cpu.pm b/centreon-plugins/network/brocade/snmp/mode/cpu.pm index be88e977c..ff70d8cb9 100644 --- a/centreon-plugins/network/brocade/snmp/mode/cpu.pm +++ b/centreon-plugins/network/brocade/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/brocade/snmp/mode/hardware.pm b/centreon-plugins/network/brocade/snmp/mode/hardware.pm index ecebb53f6..4097b6e89 100644 --- a/centreon-plugins/network/brocade/snmp/mode/hardware.pm +++ b/centreon-plugins/network/brocade/snmp/mode/hardware.pm @@ -60,7 +60,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/brocade/snmp/mode/memory.pm b/centreon-plugins/network/brocade/snmp/mode/memory.pm index fad020de9..3f8e50c06 100644 --- a/centreon-plugins/network/brocade/snmp/mode/memory.pm +++ b/centreon-plugins/network/brocade/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/checkpoint/snmp/mode/connections.pm b/centreon-plugins/network/checkpoint/snmp/mode/connections.pm index 59c0d19cc..706cf28ad 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/connections.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/connections.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm b/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm index fd41b37d4..534a90a76 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/checkpoint/snmp/mode/hardware.pm b/centreon-plugins/network/checkpoint/snmp/mode/hardware.pm index c27872a8f..cebb78fe6 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/hardware.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/hardware.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/checkpoint/snmp/mode/hastate.pm b/centreon-plugins/network/checkpoint/snmp/mode/hastate.pm index d2d57c130..0c56d6e79 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/hastate.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/hastate.pm @@ -63,7 +63,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/network/checkpoint/snmp/mode/memory.pm b/centreon-plugins/network/checkpoint/snmp/mode/memory.pm index 94960c093..28b62898d 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/memory.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/memory.pm @@ -103,7 +103,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); @@ -125,26 +124,31 @@ sub manage_selection { my $oid_memFreeReal64 = '.1.3.6.1.4.1.2620.1.6.7.4.5.0'; my $oid_fwKmemFailedAlloc = '.1.3.6.1.4.1.2620.1.1.26.2.15.0'; - my $results = $options{snmp}->get_leef(oids => [$oid_memTotalVirtual64, $oid_memActiveVirtual64, $oid_fwKmemFailedAlloc, - $oid_memTotalReal64, $oid_memActiveReal64, $oid_memFreeReal64], - nothing_quit => 1); + my $results = $options{snmp}->get_leef( + oids => [ + $oid_memTotalVirtual64, $oid_memActiveVirtual64, $oid_fwKmemFailedAlloc, + $oid_memTotalReal64, $oid_memActiveReal64, $oid_memFreeReal64 + ], + nothing_quit => 1 + ); - my $free_bytes_swap = $results->{$oid_memTotalVirtual64} - $results->{$oid_memActiveVirtual64}; + $self->{memory} = { + prct_used => $results->{$oid_memActiveReal64} * 100 / $results->{$oid_memTotalReal64}, + used => $results->{$oid_memActiveReal64}, + free => $results->{$oid_memFreeReal64}, + total => $results->{$oid_memTotalReal64}, + }; - $self->{memory} = {prct_used => $results->{$oid_memActiveReal64} * 100 / $results->{$oid_memTotalReal64}, - used => $results->{$oid_memActiveReal64}, - free => $results->{$oid_memFreeReal64}, - total => $results->{$oid_memTotalReal64}, - }; - - $self->{swap} = {prct_used => $results->{$oid_memActiveVirtual64} * 100 / $results->{$oid_memTotalVirtual64}, - used => $results->{$oid_memActiveVirtual64}, - free => $free_bytes_swap, - total => $results->{$oid_memTotalVirtual64}, - }; - - $self->{malloc} = {failed_mallocs => $results->{$oid_fwKmemFailedAlloc}}; + if ($results->{$oid_memTotalVirtual64} > $results->{$oid_memTotalReal64}) { + $self->{swap} = { + prct_used => ($results->{$oid_memActiveVirtual64} - $results->{$oid_memActiveReal64}) * 100 / ($results->{$oid_memTotalVirtual64} - $results->{$oid_memTotalReal64}), + used => $results->{$oid_memActiveVirtual64} - $results->{$oid_memActiveReal64}, + free => $results->{$oid_memTotalVirtual64} - $results->{$oid_memTotalReal64} - ($results->{$oid_memActiveVirtual64} - $results->{$oid_memActiveReal64}), + total => $results->{$oid_memTotalVirtual64} - $results->{$oid_memTotalReal64} + }; + } + $self->{malloc} = { failed_mallocs => $results->{$oid_fwKmemFailedAlloc} }; } 1; diff --git a/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm b/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm index fd03aa8b6..68056e75b 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'filter-name:s' => { name => 'filter_name' }, 'warning-status:s' => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/network/checkpoint/snmp/plugin.pm b/centreon-plugins/network/checkpoint/snmp/plugin.pm index 1a9fd4f52..48e0b732e 100644 --- a/centreon-plugins/network/checkpoint/snmp/plugin.pm +++ b/centreon-plugins/network/checkpoint/snmp/plugin.pm @@ -38,6 +38,7 @@ sub new { 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'network::checkpoint::snmp::mode::memory', + 'uptime' => 'snmp_standard::mode::uptime', 'vpn-status' => 'network::checkpoint::snmp::mode::vpnstatus', 'vrrp-status' => 'snmp_standard::mode::vrrp', ); diff --git a/centreon-plugins/network/cisco/WaaS/mode/sessions.pm b/centreon-plugins/network/cisco/WaaS/mode/sessions.pm index 18e6e9c0a..86d6c6112 100644 --- a/centreon-plugins/network/cisco/WaaS/mode/sessions.pm +++ b/centreon-plugins/network/cisco/WaaS/mode/sessions.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '60' }, diff --git a/centreon-plugins/network/cisco/aci/apic/restapi/mode/fabric.pm b/centreon-plugins/network/cisco/aci/apic/restapi/mode/fabric.pm index 239d1a67b..3492c8ccf 100644 --- a/centreon-plugins/network/cisco/aci/apic/restapi/mode/fabric.pm +++ b/centreon-plugins/network/cisco/aci/apic/restapi/mode/fabric.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'warning-health:s' => { name => 'warning_health' }, 'critical-health:s' => { name => 'critical_health' }, diff --git a/centreon-plugins/network/cisco/aci/apic/restapi/mode/node.pm b/centreon-plugins/network/cisco/aci/apic/restapi/mode/node.pm index 3dcd4a643..cb0e09f0c 100644 --- a/centreon-plugins/network/cisco/aci/apic/restapi/mode/node.pm +++ b/centreon-plugins/network/cisco/aci/apic/restapi/mode/node.pm @@ -75,7 +75,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'filter-node:s' => { name => 'filter_node' }, }); diff --git a/centreon-plugins/network/cisco/aci/apic/restapi/mode/tenant.pm b/centreon-plugins/network/cisco/aci/apic/restapi/mode/tenant.pm index 34856e43d..8089b9421 100644 --- a/centreon-plugins/network/cisco/aci/apic/restapi/mode/tenant.pm +++ b/centreon-plugins/network/cisco/aci/apic/restapi/mode/tenant.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'filter-tenant:s' => { name => 'filter_tenant' }, 'warning-health:s' => { name => 'warning_health' }, diff --git a/centreon-plugins/network/cisco/asa/snmp/mode/failover.pm b/centreon-plugins/network/cisco/asa/snmp/mode/failover.pm index 1cf1fe703..6d6d9dfb4 100644 --- a/centreon-plugins/network/cisco/asa/snmp/mode/failover.pm +++ b/centreon-plugins/network/cisco/asa/snmp/mode/failover.pm @@ -81,7 +81,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/ccmusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/ccmusage.pm index 41e14ccb6..ced30142a 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/mode/ccmusage.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/ccmusage.pm @@ -92,7 +92,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/ctiusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/ctiusage.pm new file mode 100644 index 000000000..9b067185f --- /dev/null +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/ctiusage.pm @@ -0,0 +1,184 @@ +# +# Copyright 2019 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::cisco::callmanager::snmp::mode::ctiusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_ccmCTIDeviceStatus'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_ccmCTIDeviceName'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, + { name => 'cti', type => 1, cb_prefix_output => 'prefix_cti_output', message_multiple => 'All ctis are ok' }, + ]; + + $self->{maps_counters}->{cti} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'ccmCTIDeviceStatus' }, { name => 'ccmCTIDeviceName' } ], + 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 => \&catalog_status_threshold, + } + }, + ]; + + my @map = ( + ['total-registered', 'Registered : %s', 'registered'], + ['total-unregistered', 'Unregistered : %s', 'unregistered'], + ['total-rejected', 'Rejected : %s', 'rejected'], + ['total-unknown', 'Unknown : %s', 'unknown'], + ['total-partiallyregistered', 'Partially Registered : %s', 'partiallyregistered'], + ); + + $self->{maps_counters}->{global} = []; + foreach (@map) { + push @{$self->{maps_counters}->{global}}, { label => $_->[0], nlabel => 'cti.devices.total.' . $_->[2] . '.count', set => { + key_values => [ { name => $_->[2] } ], + output_template => $_->[1], + perfdatas => [ + { value => $_->[2] . '_absolute', template => '%s', min => 0 }, + ], + } + }, + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + 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 => '%{status} !~ /^registered/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub prefix_cti_output { + my ($self, %options) = @_; + + return "Cti '" . $options{instance_value}->{ccmCTIDeviceName} . "' "; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "Total "; +} + +my %mapping_status = ( + 1 => 'unknown', 2 => 'registered', 3 => 'unregistered', + 4 => 'rejected', 5 => 'partiallyregistered', +); + +my $mapping = { + ccmCTIDeviceName => { oid => '.1.3.6.1.4.1.9.9.156.1.8.1.1.2' }, + ccmCTIDeviceStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.8.1.1.5', map => \%mapping_status }, +}; + +my $oid_ccmCtiEntry = '.1.3.6.1.4.1.9.9.156.1.8.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_ccmCtiEntry, + start => $mapping->{ccmCTIDeviceName}->{oid}, + end => $mapping->{ccmCTIDeviceStatus}->{oid}, + nothing_quit => 1 + ); + + $self->{phone} = {}; + $self->{global} = { unknown => 0, registered => 0, unregistered => 0, rejected => 0, partiallyregistered => 0 }; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{ccmCTIDeviceStatus}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $self->{phone}->{$instance} = { %$result }; + $self->{global}->{$result->{ccmCTIDeviceStatus}}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check cti usage. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='status' + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /^registered/'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total-registered', 'total-unregistered', 'total-rejected', +'total-unknown', 'total-partiallyregistered'. + +=back + +=cut diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/gatewayusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/gatewayusage.pm index 36ae42ddd..4c36f5de5 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/mode/gatewayusage.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/gatewayusage.pm @@ -88,7 +88,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/mediadeviceusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/mediadeviceusage.pm index 4834471d0..47d3ddd7c 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/mode/mediadeviceusage.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/mediadeviceusage.pm @@ -88,7 +88,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/phoneusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/phoneusage.pm index 565afd2ea..5554f99d3 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/mode/phoneusage.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/phoneusage.pm @@ -89,7 +89,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/network/cisco/callmanager/snmp/mode/voicemailusage.pm b/centreon-plugins/network/cisco/callmanager/snmp/mode/voicemailusage.pm new file mode 100644 index 000000000..e3708df35 --- /dev/null +++ b/centreon-plugins/network/cisco/callmanager/snmp/mode/voicemailusage.pm @@ -0,0 +1,180 @@ +# +# Copyright 2019 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::cisco::callmanager::snmp::mode::voicemailusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_ccmVMailDevStatus'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_ccmVMailDevName'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, + { name => 'voicemail', type => 1, cb_prefix_output => 'prefix_voicemail_output', message_multiple => 'All voicemails are ok' }, + ]; + + $self->{maps_counters}->{voicemail} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'ccmVMailDevStatus' }, { name => 'ccmVMailDevName' } ], + 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 => \&catalog_status_threshold, + } + }, + ]; + + my @map = ( + ['total-registered', 'Registered : %s', 'registered'], + ['total-unregistered', 'Unregistered : %s', 'unregistered'], + ['total-rejected', 'Rejected : %s', 'rejected'], + ['total-unknown', 'Unknown : %s', 'unknown'], + ['total-partiallyregistered', 'Partially Registered : %s', 'partiallyregistered'], + ); + + $self->{maps_counters}->{global} = []; + foreach (@map) { + push @{$self->{maps_counters}->{global}}, { label => $_->[0], nlabel => 'voicemail.devices.total.' . $_->[2] . '.count', set => { + key_values => [ { name => $_->[2] } ], + output_template => $_->[1], + perfdatas => [ + { value => $_->[2] . '_absolute', template => '%s', min => 0 }, + ], + } + }, + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + 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 => '%{status} !~ /^registered/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub prefix_voicemail_output { + my ($self, %options) = @_; + + return "Voicemail '" . $options{instance_value}->{ccmVMailDevName} . "' "; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "Total "; +} + +my %mapping_status = ( + 1 => 'unknown', 2 => 'registered', 3 => 'unregistered', + 4 => 'rejected', 5 => 'partiallyregistered', +); + +my $mapping = { + ccmVMailDevDescription => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.4' }, + ccmVMailDevName => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.2' }, + ccmVMailDevStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.5', map => \%mapping_status }, +}; + +my $oid_ccmVoicemailEntry = '.1.3.6.1.4.1.9.9.156.1.12.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_ccmVoicemailEntry, start => $mapping->{ccmVMailDevName}->{oid}, end => $mapping->{ccmVMailDevStatus}->{oid}, nothing_quit => 1); + + $self->{phone} = {}; + $self->{global} = { unknown => 0, registered => 0, unregistered => 0, rejected => 0, partiallyregistered => 0 }; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{ccmVMailDevStatus}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $self->{phone}->{$instance} = { %$result }; + $self->{global}->{$result->{ccmVMailDevStatus}}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check voicemail usage. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='status' + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /^registered/'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total-registered', 'total-unregistered', 'total-rejected', +'total-unknown', 'total-partiallyregistered'. + +=back + +=cut diff --git a/centreon-plugins/network/cisco/callmanager/snmp/plugin.pm b/centreon-plugins/network/cisco/callmanager/snmp/plugin.pm index 8df47868b..56e414800 100644 --- a/centreon-plugins/network/cisco/callmanager/snmp/plugin.pm +++ b/centreon-plugins/network/cisco/callmanager/snmp/plugin.pm @@ -32,9 +32,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( 'ccm-usage' => 'network::cisco::callmanager::snmp::mode::ccmusage', + 'cti-usage' => 'network::cisco::callmanager::snmp::mode::ctiusage', 'gateway-usage' => 'network::cisco::callmanager::snmp::mode::gatewayusage', 'mediadevice-usage' => 'network::cisco::callmanager::snmp::mode::mediadeviceusage', 'phone-usage' => 'network::cisco::callmanager::snmp::mode::phoneusage', + 'voicemail-usage' => 'network::cisco::callmanager::snmp::mode::voicemailusage', ); return $self; diff --git a/centreon-plugins/network/cisco/ironport/snmp/plugin.pm b/centreon-plugins/network/cisco/ironport/snmp/plugin.pm index 2cc0ae8da..f4323baae 100644 --- a/centreon-plugins/network/cisco/ironport/snmp/plugin.pm +++ b/centreon-plugins/network/cisco/ironport/snmp/plugin.pm @@ -33,7 +33,7 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'centreon::common::cisco::ironport::snmp::mode::cpu', 'hardware' => 'centreon::common::cisco::ironport::snmp::mode::hardware', - 'keys-expire' => 'centreon::common::cisco::ironport::snmp::mode::keysexpire', + 'mail-usage' => 'centreon::common::cisco::ironport::snmp::mode::mailusage', 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'centreon::common::cisco::ironport::snmp::mode::memory', diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/deviceusage.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/deviceusage.pm index 1123e38c9..70f468e91 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/deviceusage.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/deviceusage.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); @@ -172,19 +173,20 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "filter-interface:s" => { name => 'filter_interface' }, - "filter-network:s" => { name => 'filter_network' }, - "filter-product:s" => { name => 'filter_product' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /offline/' }, - "speed-in:s" => { name => 'speed_in' }, - "speed-out:s" => { name => 'speed_out' }, - "units-traffic:s" => { name => 'units_traffic', default => '%' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-interface:s' => { name => 'filter_interface' }, + 'filter-network:s' => { name => 'filter_network' }, + 'filter-product:s' => { name => 'filter_product' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /offline/' }, + 'speed-in:s' => { name => 'speed_in' }, + 'speed-out:s' => { name => 'speed_out' }, + 'units-traffic:s' => { name => 'units_traffic', default => '%' }, + 'cache-expires-on:s' => { name => 'cache_expires_on' }, }); - + + $self->{cache} = centreon::plugins::statefile->new(%options); return $self; } @@ -193,6 +195,10 @@ sub check_options { $self->SUPER::check_options(%options); $self->change_macros(macros => ['warning_status', 'critical_status']); + $self->{cache}->check_options(option_results => $self->{option_results}); + if (defined($self->{option_results}->{cache_expires_on}) && $self->{option_results}->{cache_expires_on} =~ /(\d+)/) { + $self->{cache_expires_on} = $1; + } } sub skip_global { @@ -231,20 +237,51 @@ my $mapping2 = { devInterfaceRecvBytes => { oid => '.1.3.6.1.4.1.29671.1.1.5.1.7' }, }; +sub get_devices_infos_snmp { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $mapping->{devName}->{oid} }, + { oid => $mapping2->{devInterfaceName}->{oid} }, + { oid => $mapping->{devProductCode}->{oid} }, + { oid => $mapping->{devNetworkName}->{oid} } + ], + nothing_quit => 1 + ); + + return $snmp_result; +} + +sub get_devices_infos { + my ($self, %options) = @_; + + my $snmp_result; + if (defined($self->{cache_expires_on})) { + my $has_cache_file = $self->{cache}->read(statefile => 'meraki_' . $self->{mode} . '_' . md5_hex($options{snmp}->get_hostname())); + my $timestamp = $self->{cache}->get(name => 'last_timestamp'); + if ($has_cache_file == 0 || !defined($timestamp) || ((time() - $self->{cache_expires_on}) > $timestamp)) { + $snmp_result = $self->get_devices_infos_snmp(%options); + my $datas = { last_timestamp => time(), snmp => $snmp_result }; + $self->{cache}->write(data => $datas); + } else { + $snmp_result = $self->{cache}->get(name => 'snmp'); + } + } else { + $snmp_result = $self->get_devices_infos_snmp(%options); + } + + return $snmp_result; +} + sub manage_selection { my ($self, %options) = @_; $self->{device} = {}; $self->{interface} = {}; $self->{global} = { total => 0 }; - - my $snmp_result = $options{snmp}->get_multiple_table(oids => [ - { oid => $mapping->{devName}->{oid} }, - { oid => $mapping2->{devInterfaceName}->{oid} }, - { oid => $mapping->{devProductCode}->{oid} }, - { oid => $mapping->{devNetworkName}->{oid} } - ], nothing_quit => 1); - + + my $snmp_result = $self->get_devices_infos(%options); foreach my $oid (keys %{$snmp_result->{ $mapping->{devName}->{oid} }}) { $oid =~ /^$mapping->{devName}->{oid}\.(.*)$/; my $instance = $1; @@ -348,6 +385,10 @@ Filter by network name (can be a regexp). Filter interface name (can be a regexp). +=item B<--cache-expires-on> + +Use cache file to speed up mode execution (X seconds before refresh cache file). + =item B<--speed-in> Set interface speed for incoming traffic (in Mb). diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/listdevices.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/listdevices.pm index 54b21b4af..2070ab898 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/listdevices.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/listdevices.pm @@ -41,7 +41,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/network/cisco/prime/restapi/mode/apusage.pm b/centreon-plugins/network/cisco/prime/restapi/mode/apusage.pm index cb8a78655..3fb4e46bf 100644 --- a/centreon-plugins/network/cisco/prime/restapi/mode/apusage.pm +++ b/centreon-plugins/network/cisco/prime/restapi/mode/apusage.pm @@ -124,7 +124,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-controller:s" => { name => 'filter_controller' }, diff --git a/centreon-plugins/network/cisco/standard/snmp/plugin.pm b/centreon-plugins/network/cisco/standard/snmp/plugin.pm index ed9f7f3fe..1a7a0a6c5 100644 --- a/centreon-plugins/network/cisco/standard/snmp/plugin.pm +++ b/centreon-plugins/network/cisco/standard/snmp/plugin.pm @@ -31,6 +31,7 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( + 'arp' => 'snmp_standard::mode::arp', 'configuration' => 'centreon::common::cisco::standard::snmp::mode::configuration', 'cpu' => 'centreon::common::cisco::standard::snmp::mode::cpu', 'environment' => 'centreon::common::cisco::standard::snmp::mode::environment', @@ -45,6 +46,7 @@ sub new { 'spanning-tree' => 'snmp_standard::mode::spanningtree', 'stack' => 'centreon::common::cisco::standard::snmp::mode::stack', 'uptime' => 'snmp_standard::mode::uptime', + 'voice-call' => 'centreon::common::cisco::standard::snmp::mode::voicecall', ); return $self; diff --git a/centreon-plugins/network/cisco/standard/ssh/custom/custom.pm b/centreon-plugins/network/cisco/standard/ssh/custom/custom.pm new file mode 100644 index 000000000..4d096628e --- /dev/null +++ b/centreon-plugins/network/cisco/standard/ssh/custom/custom.pm @@ -0,0 +1,177 @@ +# +# Copyright 2019 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::cisco::standard::ssh::custom::custom; + +use strict; +use warnings; +use centreon::plugins::misc; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 45 }, + 'command:s' => { name => 'command' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'SSH OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{option_results}->{remote} = 1; + if (defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '') { + $self->{option_results}->{remote} = undef; + } elsif (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to set hostname option."); + $self->{output}->option_exit(); + } + + return 0; +} + +############## +# Specific methods +############## +sub execute_command { + my ($self, %options) = @_; + + $self->{ssh_commands} = ''; + my $append = ''; + foreach (@{$options{commands}}) { + $self->{ssh_commands} .= $append . " $_"; + $append = "\n"; + } + + my ($content) = centreon::plugins::misc::execute( + ssh_pipe => 1, + output => $self->{output}, + options => $self->{option_results}, + command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands}, + command_path => $self->{option_results}->{command_path}, + command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef + ); + + $content =~ s/\r//mg; + return $content; +} + +1; + +__END__ + +=head1 NAME + +ssh + +=head1 SYNOPSIS + +my ssh + +=head1 SSH OPTIONS + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 45). + +=item B<--command> + +Command to get information. Used it you have output in a file. + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options. + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/network/cisco/standard/ssh/mode/cpu.pm b/centreon-plugins/network/cisco/standard/ssh/mode/cpu.pm new file mode 100644 index 000000000..27fb489b2 --- /dev/null +++ b/centreon-plugins/network/cisco/standard/ssh/mode/cpu.pm @@ -0,0 +1,112 @@ +# +# Copyright 2019 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::cisco::standard::ssh::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cpu_avg', type => 0, cb_prefix_output => 'prefix_cpu_avg_output', message_separator => ' ', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{cpu_avg} = [ + { label => 'average-5s', nlabel => 'cpu.utilization.5s.percentage', set => { + key_values => [ { name => 'average_5s' } ], + output_template => '%.2f %% (5s)', + perfdatas => [ + { label => 'total_cpu_5s_avg', value => 'average_5s_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'average-1m', nlabel => 'cpu.utilization.1m.percentage', set => { + key_values => [ { name => 'average_1m' } ], + output_template => '%.2f %% (1m)', + perfdatas => [ + { label => 'total_cpu_1m_avg', value => 'average_1m_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'average-5m', nlabel => 'cpu.utilization.5m.percentage', set => { + key_values => [ { name => 'average_5m' } ], + output_template => '%.2f %% (5m)', + perfdatas => [ + { label => 'total_cpu_5m_avg', value => 'average_5m_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + +sub prefix_cpu_avg_output { + my ($self, %options) = @_; + + return 'CPU(s) average usage is '; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my ($result) = $options{custom}->execute_command(commands => ['show proc cpu | include CPU utilization']); + #CPU utilization for five seconds: 17%/1%; one minute: 18%; five minutes: 18% + + $self->{cpu_avg} = {}; + $self->{cpu_avg}->{average_5s} = $1 if ($result =~ /^CPU utilization.*?five\s+seconds\s*:\s*(\d+)%/mi); + $self->{cpu_avg}->{average_1m} = $1 if ($result =~ /^CPU utilization.*?one\s+minute\s*:\s*(\d+)%/mi); + $self->{cpu_avg}->{average_5m} = $1 if ($result =~ /^CPU utilization.*?five\s+minutes\s*:\s*(\d+)%/mi); +} + +1; + +__END__ + +=head1 MODE + +Check cpu usage. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'average-5s', 'average-1m', 'average-5m'. + +=back + +=cut diff --git a/centreon-plugins/network/cisco/standard/ssh/mode/voicedialpeer.pm b/centreon-plugins/network/cisco/standard/ssh/mode/voicedialpeer.pm new file mode 100644 index 000000000..f71b9344b --- /dev/null +++ b/centreon-plugins/network/cisco/standard/ssh/mode/voicedialpeer.pm @@ -0,0 +1,186 @@ +# +# Copyright 2019 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::cisco::standard::ssh::mode::voicedialpeer; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'operation state: ' . $self->{result_values}->{oper} . ' [admin state: ' . $self->{result_values}->{admin} . ']'; + if ($self->{result_values}->{keepalive} ne '') { + $msg .= '[keepalive: ' . $self->{result_values}->{keepalive} . ']'; + } + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'voice_peers', type => 1, cb_prefix_output => 'prefix_voice_output', message_multiple => 'All voice dial peers are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'peers.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'peers total %s', + perfdatas => [ + { value => 'total_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'total-operational-up', nlabel => 'peers.total.operational.up.count', display_ok => 0, set => { + key_values => [ { name => 'oper_up' } ], + output_template => 'peers operational up %s', + perfdatas => [ + { value => 'oper_up_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{voice_peers} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'admin' }, { name => 'oper' }, { name => 'keepalive' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_voice_output { + my ($self, %options) = @_; + + return "Voice peer dial '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{admin} eq "up" and %{oper} eq "down"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my ($result) = $options{custom}->execute_command(commands => ['term length 0', 'show dial-peer voice']); + #VoiceOverIpPeer100 + # peer type = voice, system default peer = FALSE, information type = voice, + # ... + # group = 100, Admin state is up, Operation state is up, + # incoming called-number = `.T', + #connections/maximum = 0/unlimited, + # bandwidth/maximum = 0/unlimited, + # voice class sip options-keepalive dial-peer action = busyout, + #... + #VoiceOverIpPeer200 + #... + # voice class sip options-keepalive dial-peer action = active, + #... + + $self->{global} = { total => 0, oper_up => 0, oper_down => 0 }; + $self->{voice_peers} = {}; + while ($result =~ /^(\S+)\n(.*?)(?=\n\S+\n|\Z$)/msg) { + my ($display, $content) = ($1, $2); + next if ($content !~ /Admin\s+state\s+is\s+(\S+),\s*Operation\s+state\s+is\s+(\S+?),/msi); + + my ($admin, $oper) = ($1, $2); + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $display !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1); + next; + } + + my $keepalive = ''; + $keepalive = $1 if ($content =~ /options-keepalive\s+dial-peer\s+action\s+=\s+(\S+?),/msi); + $self->{voice_peers}->{$display} = { + display => $display, + admin => $admin, + oper => $oper, + keepalive => $keepalive, + }; + $self->{global}->{total}++; + $self->{global}->{'oper_' . $oper}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check voice dial peers status. + +=over 8 + +=item B<--filter-name> + +Filter name (can be a regexp). + +=item B<--unknown-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{admin}, %{oper}, %{keepalive}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{admin}, %{oper}, %{keepalive}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{admin} eq "up" and %{oper} eq "down"'). +Can used special variables like: %{admin}, %{oper}, %{keepalive}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total', 'total-operational-up'. + +=back + +=cut diff --git a/centreon-plugins/network/cisco/standard/ssh/plugin.pm b/centreon-plugins/network/cisco/standard/ssh/plugin.pm new file mode 100644 index 000000000..58c63aa13 --- /dev/null +++ b/centreon-plugins/network/cisco/standard/ssh/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2019 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::cisco::standard::ssh::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu' => 'network::cisco::standard::ssh::mode::cpu', + 'voice-dial-peer' => 'network::cisco::standard::ssh::mode::voicedialpeer', + ); + + $self->{custom_modes}{ssh} = 'network::cisco::standard::ssh::custom::custom'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check cisco IOS in SSH. + +=cut diff --git a/centreon-plugins/network/cisco/vcs/restapi/mode/calls.pm b/centreon-plugins/network/cisco/vcs/restapi/mode/calls.pm index 46d4c6122..17aff75fa 100644 --- a/centreon-plugins/network/cisco/vcs/restapi/mode/calls.pm +++ b/centreon-plugins/network/cisco/vcs/restapi/mode/calls.pm @@ -136,7 +136,6 @@ sub new { 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' }, diff --git a/centreon-plugins/network/cisco/vcs/restapi/mode/httpproxystats.pm b/centreon-plugins/network/cisco/vcs/restapi/mode/httpproxystats.pm index 557dd937b..b2d68e954 100644 --- a/centreon-plugins/network/cisco/vcs/restapi/mode/httpproxystats.pm +++ b/centreon-plugins/network/cisco/vcs/restapi/mode/httpproxystats.pm @@ -192,7 +192,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters' }, diff --git a/centreon-plugins/network/cisco/vcs/restapi/mode/zones.pm b/centreon-plugins/network/cisco/vcs/restapi/mode/zones.pm index 865640cbb..6be7b73d0 100644 --- a/centreon-plugins/network/cisco/vcs/restapi/mode/zones.pm +++ b/centreon-plugins/network/cisco/vcs/restapi/mode/zones.pm @@ -144,7 +144,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters' }, diff --git a/centreon-plugins/network/citrix/appacceleration/snmp/mode/cpu.pm b/centreon-plugins/network/citrix/appacceleration/snmp/mode/cpu.pm index ada786835..ba4143f56 100644 --- a/centreon-plugins/network/citrix/appacceleration/snmp/mode/cpu.pm +++ b/centreon-plugins/network/citrix/appacceleration/snmp/mode/cpu.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/citrix/appacceleration/snmp/mode/listserviceclass.pm b/centreon-plugins/network/citrix/appacceleration/snmp/mode/listserviceclass.pm index 41d756037..114a59126 100644 --- a/centreon-plugins/network/citrix/appacceleration/snmp/mode/listserviceclass.pm +++ b/centreon-plugins/network/citrix/appacceleration/snmp/mode/listserviceclass.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/citrix/appacceleration/snmp/mode/serviceclassusage.pm b/centreon-plugins/network/citrix/appacceleration/snmp/mode/serviceclassusage.pm index d419c2f36..1312e0fd7 100644 --- a/centreon-plugins/network/citrix/appacceleration/snmp/mode/serviceclassusage.pm +++ b/centreon-plugins/network/citrix/appacceleration/snmp/mode/serviceclassusage.pm @@ -115,7 +115,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/citrix/netscaler/snmp/mode/certificatesexpire.pm b/centreon-plugins/network/citrix/netscaler/snmp/mode/certificatesexpire.pm index de623e0c8..07d9f4874 100644 --- a/centreon-plugins/network/citrix/netscaler/snmp/mode/certificatesexpire.pm +++ b/centreon-plugins/network/citrix/netscaler/snmp/mode/certificatesexpire.pm @@ -53,7 +53,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/citrix/netscaler/snmp/mode/connections.pm b/centreon-plugins/network/citrix/netscaler/snmp/mode/connections.pm index b85b2b43a..4d5945cf0 100644 --- a/centreon-plugins/network/citrix/netscaler/snmp/mode/connections.pm +++ b/centreon-plugins/network/citrix/netscaler/snmp/mode/connections.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/citrix/netscaler/snmp/mode/cpu.pm b/centreon-plugins/network/citrix/netscaler/snmp/mode/cpu.pm index 9df4e38c3..abc25cc86 100644 --- a/centreon-plugins/network/citrix/netscaler/snmp/mode/cpu.pm +++ b/centreon-plugins/network/citrix/netscaler/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/citrix/netscaler/snmp/mode/hastate.pm b/centreon-plugins/network/citrix/netscaler/snmp/mode/hastate.pm index 24fcad469..9ceac2b54 100644 --- a/centreon-plugins/network/citrix/netscaler/snmp/mode/hastate.pm +++ b/centreon-plugins/network/citrix/netscaler/snmp/mode/hastate.pm @@ -20,126 +20,105 @@ package network::citrix::netscaler::snmp::mode::hastate; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); -my $oid_haPeerState = '.1.3.6.1.4.1.5951.4.1.1.23.3.0'; -my $oid_haCurState = '.1.3.6.1.4.1.5951.4.1.1.23.24.0'; +sub custom_peer_status_output { + my ($self, %options) = @_; -my $thresholds = { - peerstate => [ - ['standalone', 'OK'], - ['primary', 'OK'], - ['secondary', 'OK'], - ['unknown', 'UNKNOWN'], - ], - hastate => [ - ['unknown', 'UNKNOWN'], - ['down|partialFail|monitorFail|completeFail|partialFailSsl|routemonitorFail', 'CRITICAL'], - ['init|up|monitorOk|dump|disabled', 'OK'], - ], -}; + my $msg = sprintf("Peer status is '%s'", $self->{result_values}->{peer_status}); + return $msg; +} -my %map_hastate_status = ( - 0 => 'unknown', - 1 => 'init', - 2 => 'down', - 3 => 'up', - 4 => 'partialFail', - 5 => 'monitorFail', - 6 => 'monitorOk', - 7 => 'completeFail', - 8 => 'dumb', - 9 => 'disabled', - 10 => 'partialFailSsl', - 11 => 'routemonitorFail', -); +sub custom_ha_status_output { + my ($self, %options) = @_; -my %map_peerstate_status = ( - 0 => 'standalone', - 1 => 'primary', - 2 => 'secondary', - 3 => 'unknown', -); + my $msg = sprintf("High availibility status is '%s'", $self->{result_values}->{ha_status}); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'ha-status', set => { + key_values => [ { name => 'ha_status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_ha_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'peer-status', set => { + key_values => [ { name => 'peer_status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_peer_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} 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 => - { - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); + $options{options}->add_options(arguments => { + 'unknown-ha-status:s' => { name => 'unknown_ha_status', default => '%{ha_status} =~ /unknown/i' }, + 'warning-ha-status:s' => { name => 'warning_ha_status', default => '' }, + 'critical-ha-status:s' => { name => 'critical_ha_status', default => '%{ha_status} =~ /down|partialFail|monitorFail|completeFail|partialFailSsl|routemonitorFail/i' }, + 'unknown-peer-status:s' => { name => 'unknown_peer_status', default => '%{peer_status} =~ /unknown/i' }, + 'warning-peer-status:s' => { name => 'warning_peer_status', default => '' }, + 'critical-peer-status:s' => { name => 'critical_peer_status', default => '' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } + $self->SUPER::check_options(%options); + + $self->change_macros(macros => [ + 'unknown_peer_status', 'warning_peer_status', 'critical_peer_status', + 'unknown_ha_status', 'warning_ha_status', 'critical_ha_status', + ]); } -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - $self->{result} = $self->{snmp}->get_leef(oids => [$oid_haPeerState, $oid_haCurState], nothing_quit => 1); - - my $exit = $self->get_severity(section => 'peerstate', value => $map_peerstate_status{$self->{result}->{$oid_haPeerState}}); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Peer State is '%s'", - $map_peerstate_status{$self->{result}->{$oid_haPeerState}} - ) - ); - $exit = $self->get_severity(section => 'hastate', value => $map_hastate_status{$self->{result}->{$oid_haCurState}}); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("High Availibility Status is '%s'", - $map_hastate_status{$self->{result}->{$oid_haCurState}} - ) - ); +my $map_ha_status = { + 0 => 'unknown', 1 => 'init', + 2 => 'down', 3 => 'up', + 4 => 'partialFail', 5 => 'monitorFail', + 6 => 'monitorOk', 7 => 'completeFail', + 8 => 'dumb', 9 => 'disabled', + 10 => 'partialFailSsl', 11 => 'routemonitorFail', +}; - $self->{output}->display(); - $self->{output}->exit(); -} +my $map_peer_status = { + 0 => 'standalone', 1 => 'primary', + 2 => 'secondary', 3 => 'unknown', +}; -sub get_severity { +sub manage_selection { my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; + my $oid_haPeerState = '.1.3.6.1.4.1.5951.4.1.1.23.3.0'; + my $oid_haCurState = '.1.3.6.1.4.1.5951.4.1.1.23.24.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_haPeerState, $oid_haCurState], nothing_quit => 1); + + $self->{global} = { + peer_status => $map_peer_status->{$snmp_result->{$oid_haPeerState}}, + ha_status => $map_ha_status->{$snmp_result->{$oid_haCurState}}, + }; } 1; @@ -148,15 +127,39 @@ __END__ =head1 MODE -Check High Availability Status. +Check high availability status. =over 8 -=item B<--threshold-overload> +=item B<--unknown-ha-status> -Set to overload default threshold values (syntax: section,status,regexp). -It used before default thresholds (order stays). -Example: --threshold-overload='hastate,CRITICAL,^(?!(up)$)' +Set warning threshold for status. (Default: '%{ha_status} =~ /unknown/i'). +Can use special variables like: %{ha_status} + +=item B<--warning-ha-status> + +Set warning threshold for status. (Default: ''). +Can use special variables like: %{ha_status} + +=item B<--critical-ha-status> + +Set critical threshold for status. (Default: '%{ha_status} =~ /down|partialFail|monitorFail|completeFail|partialFailSsl|routemonitorFail/i'). +Can use special variables like: %{ha_status} + +=item B<--unknown-peer-status> + +Set warning threshold for status. (Default: '%{peer_status} =~ /unknown/i'). +Can use special variables like: %{peer_status} + +=item B<--warning-peer-status> + +Set warning threshold for status. (Default: ''). +Can use special variables like: %{peer_status} + +=item B<--critical-peer-status> + +Set critical threshold for status. (Default: ''). +Can use special variables like: %{peer_status} =back diff --git a/centreon-plugins/network/citrix/netscaler/snmp/mode/health.pm b/centreon-plugins/network/citrix/netscaler/snmp/mode/health.pm index 961c9b60a..ae2c823ff 100644 --- a/centreon-plugins/network/citrix/netscaler/snmp/mode/health.pm +++ b/centreon-plugins/network/citrix/netscaler/snmp/mode/health.pm @@ -70,7 +70,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/citrix/netscaler/snmp/mode/listvservers.pm b/centreon-plugins/network/citrix/netscaler/snmp/mode/listvservers.pm index 1e05bf963..305528fbc 100644 --- a/centreon-plugins/network/citrix/netscaler/snmp/mode/listvservers.pm +++ b/centreon-plugins/network/citrix/netscaler/snmp/mode/listvservers.pm @@ -42,7 +42,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s" => { name => 'name' }, diff --git a/centreon-plugins/network/citrix/netscaler/snmp/mode/memory.pm b/centreon-plugins/network/citrix/netscaler/snmp/mode/memory.pm index dec2f1e38..3b8468ea4 100644 --- a/centreon-plugins/network/citrix/netscaler/snmp/mode/memory.pm +++ b/centreon-plugins/network/citrix/netscaler/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/citrix/netscaler/snmp/mode/storage.pm b/centreon-plugins/network/citrix/netscaler/snmp/mode/storage.pm index 69bbac621..5fd583096 100644 --- a/centreon-plugins/network/citrix/netscaler/snmp/mode/storage.pm +++ b/centreon-plugins/network/citrix/netscaler/snmp/mode/storage.pm @@ -121,7 +121,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/network/citrix/netscaler/snmp/mode/vserverstatus.pm b/centreon-plugins/network/citrix/netscaler/snmp/mode/vserverstatus.pm index ea69818ce..ae71ebefe 100644 --- a/centreon-plugins/network/citrix/netscaler/snmp/mode/vserverstatus.pm +++ b/centreon-plugins/network/citrix/netscaler/snmp/mode/vserverstatus.pm @@ -155,7 +155,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-type:s" => { name => 'filter_type' }, diff --git a/centreon-plugins/network/citrix/sdx/snmp/mode/diskusage.pm b/centreon-plugins/network/citrix/sdx/snmp/mode/diskusage.pm index b616a03a8..10ec735aa 100644 --- a/centreon-plugins/network/citrix/sdx/snmp/mode/diskusage.pm +++ b/centreon-plugins/network/citrix/sdx/snmp/mode/diskusage.pm @@ -136,7 +136,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/network/citrix/sdx/snmp/mode/hardware.pm b/centreon-plugins/network/citrix/sdx/snmp/mode/hardware.pm index 5a7ce8424..69b4b985b 100644 --- a/centreon-plugins/network/citrix/sdx/snmp/mode/hardware.pm +++ b/centreon-plugins/network/citrix/sdx/snmp/mode/hardware.pm @@ -45,7 +45,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/citrix/sdx/snmp/mode/srusage.pm b/centreon-plugins/network/citrix/sdx/snmp/mode/srusage.pm index 2fe3216b0..f2525c5ff 100644 --- a/centreon-plugins/network/citrix/sdx/snmp/mode/srusage.pm +++ b/centreon-plugins/network/citrix/sdx/snmp/mode/srusage.pm @@ -139,7 +139,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/citrix/sdx/snmp/mode/xenusage.pm b/centreon-plugins/network/citrix/sdx/snmp/mode/xenusage.pm index 4353993d6..54b6b4386 100644 --- a/centreon-plugins/network/citrix/sdx/snmp/mode/xenusage.pm +++ b/centreon-plugins/network/citrix/sdx/snmp/mode/xenusage.pm @@ -124,7 +124,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/network/colubris/snmp/mode/apusage.pm b/centreon-plugins/network/colubris/snmp/mode/apusage.pm index 11575832d..7801f258b 100644 --- a/centreon-plugins/network/colubris/snmp/mode/apusage.pm +++ b/centreon-plugins/network/colubris/snmp/mode/apusage.pm @@ -101,7 +101,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/colubris/snmp/mode/cpu.pm b/centreon-plugins/network/colubris/snmp/mode/cpu.pm index 527eb0bf6..f5d6b6677 100644 --- a/centreon-plugins/network/colubris/snmp/mode/cpu.pm +++ b/centreon-plugins/network/colubris/snmp/mode/cpu.pm @@ -83,7 +83,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/colubris/snmp/mode/load.pm b/centreon-plugins/network/colubris/snmp/mode/load.pm index 3e9932f31..896853875 100644 --- a/centreon-plugins/network/colubris/snmp/mode/load.pm +++ b/centreon-plugins/network/colubris/snmp/mode/load.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/colubris/snmp/mode/memory.pm b/centreon-plugins/network/colubris/snmp/mode/memory.pm index 282108dfa..cd6a01b63 100644 --- a/centreon-plugins/network/colubris/snmp/mode/memory.pm +++ b/centreon-plugins/network/colubris/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/colubris/snmp/mode/storage.pm b/centreon-plugins/network/colubris/snmp/mode/storage.pm index 1c5753f12..babda539c 100644 --- a/centreon-plugins/network/colubris/snmp/mode/storage.pm +++ b/centreon-plugins/network/colubris/snmp/mode/storage.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/cyberoam/snmp/mode/cpu.pm b/centreon-plugins/network/cyberoam/snmp/mode/cpu.pm index 0cd10f968..9609d57f5 100644 --- a/centreon-plugins/network/cyberoam/snmp/mode/cpu.pm +++ b/centreon-plugins/network/cyberoam/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/cyberoam/snmp/mode/memory.pm b/centreon-plugins/network/cyberoam/snmp/mode/memory.pm index 7934f46df..ea0454b4b 100644 --- a/centreon-plugins/network/cyberoam/snmp/mode/memory.pm +++ b/centreon-plugins/network/cyberoam/snmp/mode/memory.pm @@ -115,7 +115,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters' }, diff --git a/centreon-plugins/network/cyberoam/snmp/mode/requests.pm b/centreon-plugins/network/cyberoam/snmp/mode/requests.pm index 46d0bc6e7..56c863526 100644 --- a/centreon-plugins/network/cyberoam/snmp/mode/requests.pm +++ b/centreon-plugins/network/cyberoam/snmp/mode/requests.pm @@ -95,7 +95,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/cyberoam/snmp/mode/services.pm b/centreon-plugins/network/cyberoam/snmp/mode/services.pm index 8857d11af..f40ac0ab7 100644 --- a/centreon-plugins/network/cyberoam/snmp/mode/services.pm +++ b/centreon-plugins/network/cyberoam/snmp/mode/services.pm @@ -60,7 +60,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/cyberoam/snmp/mode/storage.pm b/centreon-plugins/network/cyberoam/snmp/mode/storage.pm index 8206a56cf..d52143980 100644 --- a/centreon-plugins/network/cyberoam/snmp/mode/storage.pm +++ b/centreon-plugins/network/cyberoam/snmp/mode/storage.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/digi/anywhereusb/snmp/mode/cpu.pm b/centreon-plugins/network/digi/anywhereusb/snmp/mode/cpu.pm index 12c89d87a..d39f52d15 100644 --- a/centreon-plugins/network/digi/anywhereusb/snmp/mode/cpu.pm +++ b/centreon-plugins/network/digi/anywhereusb/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/digi/anywhereusb/snmp/mode/memory.pm b/centreon-plugins/network/digi/anywhereusb/snmp/mode/memory.pm index 4e55884b6..dbaf49728 100644 --- a/centreon-plugins/network/digi/anywhereusb/snmp/mode/memory.pm +++ b/centreon-plugins/network/digi/anywhereusb/snmp/mode/memory.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/digi/portserverts/snmp/mode/cpu.pm b/centreon-plugins/network/digi/portserverts/snmp/mode/cpu.pm index 22d89ab01..d80d009ae 100644 --- a/centreon-plugins/network/digi/portserverts/snmp/mode/cpu.pm +++ b/centreon-plugins/network/digi/portserverts/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/digi/portserverts/snmp/mode/memory.pm b/centreon-plugins/network/digi/portserverts/snmp/mode/memory.pm index 8c9da1bd1..aa6903ada 100644 --- a/centreon-plugins/network/digi/portserverts/snmp/mode/memory.pm +++ b/centreon-plugins/network/digi/portserverts/snmp/mode/memory.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/digi/sarian/snmp/mode/cpu.pm b/centreon-plugins/network/digi/sarian/snmp/mode/cpu.pm index dca4cf0dc..f21bc975a 100644 --- a/centreon-plugins/network/digi/sarian/snmp/mode/cpu.pm +++ b/centreon-plugins/network/digi/sarian/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/digi/sarian/snmp/mode/gprs.pm b/centreon-plugins/network/digi/sarian/snmp/mode/gprs.pm index 6687f7240..5f3a53965 100644 --- a/centreon-plugins/network/digi/sarian/snmp/mode/gprs.pm +++ b/centreon-plugins/network/digi/sarian/snmp/mode/gprs.pm @@ -98,7 +98,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/network/digi/sarian/snmp/mode/memory.pm b/centreon-plugins/network/digi/sarian/snmp/mode/memory.pm index 532cb0c32..99904c6a3 100644 --- a/centreon-plugins/network/digi/sarian/snmp/mode/memory.pm +++ b/centreon-plugins/network/digi/sarian/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/digi/sarian/snmp/mode/temperature.pm b/centreon-plugins/network/digi/sarian/snmp/mode/temperature.pm index 7f917ba3c..845bd3856 100644 --- a/centreon-plugins/network/digi/sarian/snmp/mode/temperature.pm +++ b/centreon-plugins/network/digi/sarian/snmp/mode/temperature.pm @@ -67,7 +67,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/dlink/dgs3100/snmp/mode/cpu.pm b/centreon-plugins/network/dlink/dgs3100/snmp/mode/cpu.pm index 970089897..58fae02d9 100644 --- a/centreon-plugins/network/dlink/dgs3100/snmp/mode/cpu.pm +++ b/centreon-plugins/network/dlink/dgs3100/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '' }, diff --git a/centreon-plugins/network/dlink/dgs3100/snmp/mode/hardware.pm b/centreon-plugins/network/dlink/dgs3100/snmp/mode/hardware.pm index b7f0731d5..4c81c2041 100644 --- a/centreon-plugins/network/dlink/dgs3100/snmp/mode/hardware.pm +++ b/centreon-plugins/network/dlink/dgs3100/snmp/mode/hardware.pm @@ -67,7 +67,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/dlink/standard/snmp/mode/cpu.pm b/centreon-plugins/network/dlink/standard/snmp/mode/cpu.pm index ab957e4e1..59410f85c 100644 --- a/centreon-plugins/network/dlink/standard/snmp/mode/cpu.pm +++ b/centreon-plugins/network/dlink/standard/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '' }, diff --git a/centreon-plugins/network/dlink/standard/snmp/mode/hardware.pm b/centreon-plugins/network/dlink/standard/snmp/mode/hardware.pm index 78ba203bb..83965801c 100644 --- a/centreon-plugins/network/dlink/standard/snmp/mode/hardware.pm +++ b/centreon-plugins/network/dlink/standard/snmp/mode/hardware.pm @@ -70,7 +70,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/efficientip/snmp/mode/dhcpusage.pm b/centreon-plugins/network/efficientip/snmp/mode/dhcpusage.pm index ce5b6da70..c62faf9b7 100644 --- a/centreon-plugins/network/efficientip/snmp/mode/dhcpusage.pm +++ b/centreon-plugins/network/efficientip/snmp/mode/dhcpusage.pm @@ -106,7 +106,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/efficientip/snmp/mode/dnsusage.pm b/centreon-plugins/network/efficientip/snmp/mode/dnsusage.pm index bbd7d2b58..d53f0d678 100644 --- a/centreon-plugins/network/efficientip/snmp/mode/dnsusage.pm +++ b/centreon-plugins/network/efficientip/snmp/mode/dnsusage.pm @@ -64,7 +64,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/evertz/AEA47721/snmp/mode/streamstatus.pm b/centreon-plugins/network/evertz/AEA47721/snmp/mode/streamstatus.pm index f3e816f4d..7c876fbf4 100644 --- a/centreon-plugins/network/evertz/AEA47721/snmp/mode/streamstatus.pm +++ b/centreon-plugins/network/evertz/AEA47721/snmp/mode/streamstatus.pm @@ -79,7 +79,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-audio-status:s" => { name => 'warning_audio_status', default => '' }, diff --git a/centreon-plugins/network/evertz/DA6HDL7700/snmp/mode/videostatus.pm b/centreon-plugins/network/evertz/DA6HDL7700/snmp/mode/videostatus.pm index 0bcf61c7d..7254b4590 100644 --- a/centreon-plugins/network/evertz/DA6HDL7700/snmp/mode/videostatus.pm +++ b/centreon-plugins/network/evertz/DA6HDL7700/snmp/mode/videostatus.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-video-status:s" => { name => 'warning_video_status', default => '' }, diff --git a/centreon-plugins/network/evertz/FC7800/snmp/mode/hardware.pm b/centreon-plugins/network/evertz/FC7800/snmp/mode/hardware.pm index 5558afb01..fbc128708 100644 --- a/centreon-plugins/network/evertz/FC7800/snmp/mode/hardware.pm +++ b/centreon-plugins/network/evertz/FC7800/snmp/mode/hardware.pm @@ -51,7 +51,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/extreme/snmp/mode/cpu.pm b/centreon-plugins/network/extreme/snmp/mode/cpu.pm index c2083a736..f2cba487f 100644 --- a/centreon-plugins/network/extreme/snmp/mode/cpu.pm +++ b/centreon-plugins/network/extreme/snmp/mode/cpu.pm @@ -109,7 +109,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/extreme/snmp/mode/hardware.pm b/centreon-plugins/network/extreme/snmp/mode/hardware.pm index 706f9f1f4..a9d471fdb 100644 --- a/centreon-plugins/network/extreme/snmp/mode/hardware.pm +++ b/centreon-plugins/network/extreme/snmp/mode/hardware.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/extreme/snmp/mode/memory.pm b/centreon-plugins/network/extreme/snmp/mode/memory.pm index a1d3de1fd..e8b195f93 100644 --- a/centreon-plugins/network/extreme/snmp/mode/memory.pm +++ b/centreon-plugins/network/extreme/snmp/mode/memory.pm @@ -101,7 +101,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/extreme/snmp/mode/stack.pm b/centreon-plugins/network/extreme/snmp/mode/stack.pm index 3adfcd543..c7832fc24 100644 --- a/centreon-plugins/network/extreme/snmp/mode/stack.pm +++ b/centreon-plugins/network/extreme/snmp/mode/stack.pm @@ -54,7 +54,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/connections.pm b/centreon-plugins/network/f5/bigip/snmp/mode/connections.pm index b7d28eff4..d0489878c 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/connections.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/connections.pm @@ -98,7 +98,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/failover.pm b/centreon-plugins/network/f5/bigip/snmp/mode/failover.pm index eb4f91521..1f14bc636 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/failover.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/failover.pm @@ -86,7 +86,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters' }, diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/hardware.pm b/centreon-plugins/network/f5/bigip/snmp/mode/hardware.pm index a7a5601e4..4f2f9c29e 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/hardware.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/hardware.pm @@ -62,7 +62,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/listnodes.pm b/centreon-plugins/network/f5/bigip/snmp/mode/listnodes.pm index bc7685d50..b26c3bcaa 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/listnodes.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/listnodes.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/listpools.pm b/centreon-plugins/network/f5/bigip/snmp/mode/listpools.pm index d979656b1..024a5b2f9 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/listpools.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/listpools.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s" => { name => 'name' }, diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/listtrunks.pm b/centreon-plugins/network/f5/bigip/snmp/mode/listtrunks.pm index e4efcbe81..f8c2672a7 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/listtrunks.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/listtrunks.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s" => { name => 'name' }, diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/listvirtualservers.pm b/centreon-plugins/network/f5/bigip/snmp/mode/listvirtualservers.pm index 5bac80b0c..8819a255e 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/listvirtualservers.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/listvirtualservers.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s" => { name => 'name' }, "regexp" => { name => 'use_regexp' }, diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/nodestatus.pm b/centreon-plugins/network/f5/bigip/snmp/mode/nodestatus.pm index 7179e9506..76a11204e 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/nodestatus.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/nodestatus.pm @@ -88,7 +88,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/poolstatus.pm b/centreon-plugins/network/f5/bigip/snmp/mode/poolstatus.pm index a1a7548d6..1fbc52c38 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/poolstatus.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/poolstatus.pm @@ -88,7 +88,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/tmmusage.pm b/centreon-plugins/network/f5/bigip/snmp/mode/tmmusage.pm index 93d02e3cd..c3f1aae4f 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/tmmusage.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/tmmusage.pm @@ -157,7 +157,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm b/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm index 608644689..6cf6ee1dd 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm @@ -300,7 +300,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/virtualserverstatus.pm b/centreon-plugins/network/f5/bigip/snmp/mode/virtualserverstatus.pm index e25c7def7..317df68f5 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/virtualserverstatus.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/virtualserverstatus.pm @@ -79,7 +79,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/network/fortinet/fortimanager/snmp/mode/cpu.pm b/centreon-plugins/network/fortinet/fortimanager/snmp/mode/cpu.pm index e9a9171d2..615021f95 100644 --- a/centreon-plugins/network/fortinet/fortimanager/snmp/mode/cpu.pm +++ b/centreon-plugins/network/fortinet/fortimanager/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/fortinet/fortimanager/snmp/mode/devicestatus.pm b/centreon-plugins/network/fortinet/fortimanager/snmp/mode/devicestatus.pm index 690f9af0a..170361ad9 100644 --- a/centreon-plugins/network/fortinet/fortimanager/snmp/mode/devicestatus.pm +++ b/centreon-plugins/network/fortinet/fortimanager/snmp/mode/devicestatus.pm @@ -95,7 +95,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/fortinet/fortimanager/snmp/mode/disk.pm b/centreon-plugins/network/fortinet/fortimanager/snmp/mode/disk.pm index a09147c22..d827764d9 100644 --- a/centreon-plugins/network/fortinet/fortimanager/snmp/mode/disk.pm +++ b/centreon-plugins/network/fortinet/fortimanager/snmp/mode/disk.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/fortinet/fortimanager/snmp/mode/memory.pm b/centreon-plugins/network/fortinet/fortimanager/snmp/mode/memory.pm index 465ad67b0..9b7a11279 100644 --- a/centreon-plugins/network/fortinet/fortimanager/snmp/mode/memory.pm +++ b/centreon-plugins/network/fortinet/fortimanager/snmp/mode/memory.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/freebox/restapi/mode/dslusage.pm b/centreon-plugins/network/freebox/restapi/mode/dslusage.pm index 080b777b0..ed1dbac3f 100644 --- a/centreon-plugins/network/freebox/restapi/mode/dslusage.pm +++ b/centreon-plugins/network/freebox/restapi/mode/dslusage.pm @@ -81,7 +81,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/freebox/restapi/mode/netusage.pm b/centreon-plugins/network/freebox/restapi/mode/netusage.pm index 7c1a3c45a..e5b68251a 100644 --- a/centreon-plugins/network/freebox/restapi/mode/netusage.pm +++ b/centreon-plugins/network/freebox/restapi/mode/netusage.pm @@ -101,7 +101,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/freebox/restapi/mode/system.pm b/centreon-plugins/network/freebox/restapi/mode/system.pm index 7f0b55407..694531c43 100644 --- a/centreon-plugins/network/freebox/restapi/mode/system.pm +++ b/centreon-plugins/network/freebox/restapi/mode/system.pm @@ -128,7 +128,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-wifi-status:s" => { name => 'warning_wifi_status', default => '%{status} =~ /bad_param/i' }, diff --git a/centreon-plugins/network/fritzbox/mode/traffic.pm b/centreon-plugins/network/fritzbox/mode/traffic.pm index d0ab40d84..f7903cec8 100644 --- a/centreon-plugins/network/fritzbox/mode/traffic.pm +++ b/centreon-plugins/network/fritzbox/mode/traffic.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/network/fritzbox/mode/upstatus.pm b/centreon-plugins/network/fritzbox/mode/upstatus.pm index 036ef8af5..49b7ba769 100644 --- a/centreon-plugins/network/fritzbox/mode/upstatus.pm +++ b/centreon-plugins/network/fritzbox/mode/upstatus.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/network/hirschmann/standard/snmp/mode/cpu.pm b/centreon-plugins/network/hirschmann/standard/snmp/mode/cpu.pm index d8f0c69fb..c2b9cba16 100644 --- a/centreon-plugins/network/hirschmann/standard/snmp/mode/cpu.pm +++ b/centreon-plugins/network/hirschmann/standard/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { 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' }, diff --git a/centreon-plugins/network/hirschmann/standard/snmp/mode/hardware.pm b/centreon-plugins/network/hirschmann/standard/snmp/mode/hardware.pm index 95fc50828..6e4ef6e4b 100644 --- a/centreon-plugins/network/hirschmann/standard/snmp/mode/hardware.pm +++ b/centreon-plugins/network/hirschmann/standard/snmp/mode/hardware.pm @@ -69,7 +69,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/hirschmann/standard/snmp/mode/memory.pm b/centreon-plugins/network/hirschmann/standard/snmp/mode/memory.pm index 75cfdf1d2..7cc7dcdec 100644 --- a/centreon-plugins/network/hirschmann/standard/snmp/mode/memory.pm +++ b/centreon-plugins/network/hirschmann/standard/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { 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' }, diff --git a/centreon-plugins/network/hirschmann/standard/snmp/mode/processcount.pm b/centreon-plugins/network/hirschmann/standard/snmp/mode/processcount.pm index d2862981f..7d8a18bb4 100644 --- a/centreon-plugins/network/hirschmann/standard/snmp/mode/processcount.pm +++ b/centreon-plugins/network/hirschmann/standard/snmp/mode/processcount.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/hp/procurve/snmp/mode/cpu.pm b/centreon-plugins/network/hp/procurve/snmp/mode/cpu.pm index 049cbbfaf..72c1f75f8 100644 --- a/centreon-plugins/network/hp/procurve/snmp/mode/cpu.pm +++ b/centreon-plugins/network/hp/procurve/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/hp/procurve/snmp/mode/environment.pm b/centreon-plugins/network/hp/procurve/snmp/mode/environment.pm index dd67a8c3c..2efd55b88 100644 --- a/centreon-plugins/network/hp/procurve/snmp/mode/environment.pm +++ b/centreon-plugins/network/hp/procurve/snmp/mode/environment.pm @@ -78,7 +78,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/hp/procurve/snmp/mode/memory.pm b/centreon-plugins/network/hp/procurve/snmp/mode/memory.pm index 60458a416..9b3e3f1ec 100644 --- a/centreon-plugins/network/hp/procurve/snmp/mode/memory.pm +++ b/centreon-plugins/network/hp/procurve/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/hp/vc/snmp/mode/hardware.pm b/centreon-plugins/network/hp/vc/snmp/mode/hardware.pm index aec985402..fcc8ea8a6 100644 --- a/centreon-plugins/network/hp/vc/snmp/mode/hardware.pm +++ b/centreon-plugins/network/hp/vc/snmp/mode/hardware.pm @@ -70,7 +70,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/huawei/snmp/mode/components/fan.pm b/centreon-plugins/network/huawei/snmp/mode/components/fan.pm new file mode 100644 index 000000000..4d5467b24 --- /dev/null +++ b/centreon-plugins/network/huawei/snmp/mode/components/fan.pm @@ -0,0 +1,91 @@ +# +# Copyright 2019 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::huawei::snmp::mode::components::fan; + +use strict; +use warnings; + +my $map_present = { 1 => 'present', 2 => 'absent' }; +my $map_state = { 1 => 'normal', 2 => 'abnormal' }; + +my $mapping = { + hwEntityFanSpeed => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.10.1.5' }, + hwEntityFanPresent => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.10.1.6', map => $map_present }, + hwEntityFanState => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.10.1.7', map => $map_state }, +}; +my $oid_hwFanStatusEntry = '.1.3.6.1.4.1.2011.5.25.31.1.1.10'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_hwFanStatusEntry, start => $mapping->{hwEntityFanSpeed}->{oid}, end => $mapping->{hwEntityFanState}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking fans"); + $self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'fan')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hwFanStatusEntry}})) { + next if ($oid !~ /^$mapping->{hwEntityFanState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hwFanStatusEntry}, instance => $instance); + + next if ($self->check_filter(section => 'fan', instance => $instance)); + next if ($result->{hwEntityFanPresent} =~ /absent/i && + $self->absent_problem(section => 'fan', instance => $instance)); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add(long_msg => + sprintf("fan '%s' state is '%s' [instance = %s, speed = %s]", + $instance, $result->{hwEntityFanState}, $instance, + defined($result->{hwEntityFanSpeed}) ? $result->{hwEntityFanSpeed} : '-') + ); + + my $exit = $self->get_severity(section => 'fan', value => $result->{hwEntityFanState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("fan '%s' state is '%s'", $instance, $result->{infoFanState})); + } + + next if (!defined($result->{hwEntityFanSpeed}) || $result->{hwEntityFanSpeed} !~ /[0-9]/); + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{hwEntityFanSpeed}); + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("fan '%s' speed is %s %%", $instance, $result->{hwEntityFanSpeed})); + } + $self->{output}->perfdata_add( + label => 'fan', unit => '%', + nlabel => 'hardware.fan.speed.percentage', + instances => $instance, + value => $result->{hwEntityFanSpeed}, + warning => $warn, + critical => $crit, + min => 0 + ); + } +} + +1; diff --git a/centreon-plugins/network/huawei/snmp/mode/components/temperature.pm b/centreon-plugins/network/huawei/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..82b51a343 --- /dev/null +++ b/centreon-plugins/network/huawei/snmp/mode/components/temperature.pm @@ -0,0 +1,93 @@ +# +# Copyright 2019 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::huawei::snmp::mode::components::temperature; + +use strict; +use warnings; + +my $mapping = { + hwEntityTemperature => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.1.1.11' }, + hwEntityTemperatureThreshold => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.1.1.12' }, +}; +my $oid_hwEntityStateEntry = '.1.3.6.1.4.1.2011.5.25.31.1.1.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_hwEntityStateEntry, start => $mapping->{hwEntityTemperature}->{oid}, end => $mapping->{hwEntityTemperatureThreshold}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking temperatures"); + $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'temperature')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hwEntityStateEntry}})) { + next if ($oid !~ /^$mapping->{hwEntityTemperature}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hwEntityStateEntry}, instance => $instance); + + next if (!defined($result->{hwEntityTemperature}) || $result->{hwEntityTemperature} <= 0); + next if ($self->check_filter(section => 'temperature', instance => $instance)); + $self->{components}->{temperature}->{total}++; + + my $name = ''; + $name = $self->get_short_name(instance => $instance) if (defined($self->{short_name}) && $self->{short_name} == 1); + $name = $self->get_long_name(instance => $instance) unless (defined($self->{short_name}) && $self->{short_name} == 1 && defined($name) && $name ne ''); + + $self->{output}->output_add(long_msg => + sprintf("temperature '%s' is '%s' C [instance = %s]", + $name, $result->{hwEntityTemperature}, $instance) + ); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{hwEntityTemperature}); + if ($checked == 0 && defined($result->{hwEntityTemperatureThreshold}) && $result->{hwEntityTemperatureThreshold} > 0) { + my $warn_th = ''; + my $crit_th = $result->{hwEntityTemperatureThreshold}; + $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); + + $exit = $self->{perfdata}->threshold_check( + value => $result->{hwEntityTemperature}, + threshold => [ { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } ]); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance) + } + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("temperature '%s' is %s C", $name, $result->{hwEntityTemperature})); + } + $self->{output}->perfdata_add( + label => 'temperature', unit => 'C', + nlabel => 'hardware.temperature.celsius', + instances => $name, + value => $result->{hwEntityTemperature}, + warning => $warn, + critical => $crit, + ); + } +} + +1; diff --git a/centreon-plugins/network/huawei/snmp/mode/cpu.pm b/centreon-plugins/network/huawei/snmp/mode/cpu.pm index 3f9ff5dee..4780e2998 100644 --- a/centreon-plugins/network/huawei/snmp/mode/cpu.pm +++ b/centreon-plugins/network/huawei/snmp/mode/cpu.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/huawei/snmp/mode/hardware.pm b/centreon-plugins/network/huawei/snmp/mode/hardware.pm new file mode 100644 index 000000000..272f53961 --- /dev/null +++ b/centreon-plugins/network/huawei/snmp/mode/hardware.pm @@ -0,0 +1,197 @@ +# +# Copyright 2019 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::huawei::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; +use centreon::plugins::statefile; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(fan|temperature)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(fan|temperature)$'; + + $self->{cb_hook1} = 'init_cache'; + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + fan => [ + ['abnormal', 'CRITICAL'], + ['normal', 'OK'], + ], + }; + + $self->{components_path} = 'network::huawei::snmp::mode::components'; + $self->{components_module} = ['fan', 'temperature']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); + $self->write_cache(); +} + +sub init_cache { + my ($self, %options) = @_; + + $self->check_cache(%options); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'reload-cache-time:s' => { name => 'reload_cache_time', default => 180 }, + 'short-name' => { name => 'short_name' }, + }); + + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{short_name} = (defined($self->{option_results}->{short_name})) ? 1 : 0; + $self->{statefile_cache}->check_options(%options); +} + +my $oid_entPhysicalEntry = '.1.3.6.1.2.1.47.1.1.1.1'; +my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2'; +my $oid_entPhysicalContainedIn = '.1.3.6.1.2.1.47.1.1.1.1.4'; +my $oid_entPhysicalClass = '.1.3.6.1.2.1.47.1.1.1.1.5'; +my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7'; + +sub check_cache { + my ($self, %options) = @_; + + $self->{hostname} = $options{snmp}->get_hostname(); + $self->{snmp_port} = $options{snmp}->get_port(); + + # init cache file + $self->{write_cache} = 0; + my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_huawei_entity_' . $self->{hostname} . '_' . $self->{snmp_port}); + my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); + if ($has_cache_file == 0 || + !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60)) && $self->{option_results}->{reload_cache_time} != '-1') { + push @{$self->{request}}, { oid => $oid_entPhysicalEntry, start => $oid_entPhysicalDescr, end => $oid_entPhysicalName }; + $self->{write_cache} = 1; + } +} + +sub write_cache { + my ($self, %options) = @_; + + if ($self->{write_cache} == 1) { + my $datas = {}; + $datas->{last_timestamp} = time(); + $datas->{oids} = $self->{results}->{$oid_entPhysicalEntry}; + $self->{statefile_cache}->write(data => $datas); + } else { + $self->{results}->{$oid_entPhysicalEntry} = $self->{statefile_cache}->get(name => 'oids'); + } +} + +sub get_short_name { + my ($self, %options) = @_; + + return $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalName . '.' . $options{instance}}; +} + +sub get_long_name { + my ($self, %options) = @_; + + my @names = ($self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $options{instance}}); + my %loop = ($options{instance} => 1); + my $child = $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalContainedIn . '.' . $options{instance}}; + while (1) { + last if (!defined($child) || defined($loop{$child}) || !defined($self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $child})); + + unshift @names, $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $child}; + $loop{$child} = 1; + $child = $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalContainedIn . '.' . $child}; + } + + return join(' > ', @names); +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'fan'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) +Can also exclude specific instance: --filter=fan,1.0 + +=item B<--absent-problem> + +Return an error if an entity is not 'present' (default is skipping) (comma seperated list) +Can be specific or global: --absent-problem=fan,1.0 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='fan,WARNING,abnormal' + +=item B<--warning> + +Set warning threshold for 'fan', 'temperature' (syntax: type,regexp,threshold) +Example: --warning='fan,.*,40' + +=item B<--critical> + +Set critical threshold for 'fan', 'temperature' (syntax: type,regexp,threshold) +Example: --critical='fan,.*,45' + +=item B<--reload-cache-time> + +Time in seconds before reloading cache file (Default: 180). +Use '-1' to disable cache reload. + +=back + +=cut diff --git a/centreon-plugins/network/huawei/snmp/mode/memory.pm b/centreon-plugins/network/huawei/snmp/mode/memory.pm index df2df7fd2..5211a9f14 100644 --- a/centreon-plugins/network/huawei/snmp/mode/memory.pm +++ b/centreon-plugins/network/huawei/snmp/mode/memory.pm @@ -120,7 +120,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/huawei/snmp/plugin.pm b/centreon-plugins/network/huawei/snmp/plugin.pm index 1718679e2..6c2a35788 100644 --- a/centreon-plugins/network/huawei/snmp/plugin.pm +++ b/centreon-plugins/network/huawei/snmp/plugin.pm @@ -31,12 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::huawei::snmp::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::huawei::snmp::mode::memory', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'cpu' => 'network::huawei::snmp::mode::cpu', + 'hardware' => 'network::huawei::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::huawei::snmp::mode::memory', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/network/infoblox/snmp/mode/cpu.pm b/centreon-plugins/network/infoblox/snmp/mode/cpu.pm index 3580e2b51..512e742a9 100644 --- a/centreon-plugins/network/infoblox/snmp/mode/cpu.pm +++ b/centreon-plugins/network/infoblox/snmp/mode/cpu.pm @@ -50,7 +50,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/infoblox/snmp/mode/dhcpusage.pm b/centreon-plugins/network/infoblox/snmp/mode/dhcpusage.pm index 5043bdcfe..345d0decd 100644 --- a/centreon-plugins/network/infoblox/snmp/mode/dhcpusage.pm +++ b/centreon-plugins/network/infoblox/snmp/mode/dhcpusage.pm @@ -78,7 +78,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/infoblox/snmp/mode/dnsusage.pm b/centreon-plugins/network/infoblox/snmp/mode/dnsusage.pm index a58d63423..aca05effd 100644 --- a/centreon-plugins/network/infoblox/snmp/mode/dnsusage.pm +++ b/centreon-plugins/network/infoblox/snmp/mode/dnsusage.pm @@ -100,7 +100,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/infoblox/snmp/mode/memory.pm b/centreon-plugins/network/infoblox/snmp/mode/memory.pm index c71d50849..3c96848d1 100644 --- a/centreon-plugins/network/infoblox/snmp/mode/memory.pm +++ b/centreon-plugins/network/infoblox/snmp/mode/memory.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/infoblox/snmp/mode/services.pm b/centreon-plugins/network/infoblox/snmp/mode/services.pm index 0809ff9c4..1e56910b0 100644 --- a/centreon-plugins/network/infoblox/snmp/mode/services.pm +++ b/centreon-plugins/network/infoblox/snmp/mode/services.pm @@ -51,7 +51,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/juniper/common/ive/mode/cpu.pm b/centreon-plugins/network/juniper/common/ive/mode/cpu.pm index a37bf7659..bc99a97f4 100644 --- a/centreon-plugins/network/juniper/common/ive/mode/cpu.pm +++ b/centreon-plugins/network/juniper/common/ive/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/juniper/common/ive/mode/disk.pm b/centreon-plugins/network/juniper/common/ive/mode/disk.pm index 6568dc680..4cb393621 100644 --- a/centreon-plugins/network/juniper/common/ive/mode/disk.pm +++ b/centreon-plugins/network/juniper/common/ive/mode/disk.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/juniper/common/ive/mode/logfile.pm b/centreon-plugins/network/juniper/common/ive/mode/logfile.pm index d6d81c733..8e69cd031 100644 --- a/centreon-plugins/network/juniper/common/ive/mode/logfile.pm +++ b/centreon-plugins/network/juniper/common/ive/mode/logfile.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/juniper/common/ive/mode/users.pm b/centreon-plugins/network/juniper/common/ive/mode/users.pm index e51cf717b..9dd7b86f3 100644 --- a/centreon-plugins/network/juniper/common/ive/mode/users.pm +++ b/centreon-plugins/network/juniper/common/ive/mode/users.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/juniper/common/junos/mode/bgppeerprefixstatistics.pm b/centreon-plugins/network/juniper/common/junos/mode/bgppeerprefixstatistics.pm new file mode 100644 index 000000000..163a4cce5 --- /dev/null +++ b/centreon-plugins/network/juniper/common/junos/mode/bgppeerprefixstatistics.pm @@ -0,0 +1,225 @@ +# +# Copyright 2019 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::juniper::common::junos::mode::bgppeerprefixstatistics; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'peers', type => 3, cb_prefix_output => 'prefix_output_peer', cb_long_output => 'long_output', + message_multiple => 'All peers prefix statistics are ok', indent_long_output => ' ', + group => [ + { name => 'afisafi', display_long => 1, cb_prefix_output => 'prefix_output_afisafi', + message_multiple => 'All prefix statistics are ok', type => 1 }, + ] + } + ]; + + $self->{maps_counters}->{afisafi} = [ + { label => 'prefixes-in', nlabel => 'peer.afisafi.prefixes.in.count', set => { + key_values => [ { name => 'jnxBgpM2PrefixInPrefixes' }, { name => 'jnxBgpM2PrefixCountersAfiSafi' } ], + output_template => 'Prefixes In: %d', + perfdatas => [ + { value => 'jnxBgpM2PrefixInPrefixes_absolute', template => '%d', + label_extra_instance => 1 }, + ], + } + }, + { label => 'prefixes-in-accepted', nlabel => 'peer.afisafi.prefixes.in.accepted.count', set => { + key_values => [ { name => 'jnxBgpM2PrefixInPrefixesAccepted' }, { name => 'jnxBgpM2PrefixCountersAfiSafi' } ], + output_template => 'Prefixes In Accepted: %d', + perfdatas => [ + { value => 'jnxBgpM2PrefixInPrefixesAccepted_absolute', template => '%d', + label_extra_instance => 1 }, + ], + } + }, + { label => 'prefixes-in-rejected', nlabel => 'peer.afisafi.prefixes.in.rejected.count', set => { + key_values => [ { name => 'jnxBgpM2PrefixInPrefixesRejected' }, { name => 'jnxBgpM2PrefixCountersAfiSafi' } ], + output_template => 'Prefixes In Rejected: %d', + perfdatas => [ + { value => 'jnxBgpM2PrefixInPrefixesRejected_absolute', template => '%d', + label_extra_instance => 1 }, + ], + } + }, + { label => 'prefixes-in-active', nlabel => 'peer.afisafi.prefixes.in.active.count', set => { + key_values => [ { name => 'jnxBgpM2PrefixInPrefixesActive' }, { name => 'jnxBgpM2PrefixCountersAfiSafi' } ], + output_template => 'Prefixes In Active: %d', + perfdatas => [ + { value => 'jnxBgpM2PrefixInPrefixesActive_absolute', template => '%d', + label_extra_instance => 1 }, + ], + } + }, + { label => 'prefixes-out', nlabel => 'peer.afisafi.prefixes.out.count', set => { + key_values => [ { name => 'jnxBgpM2PrefixOutPrefixes' }, { name => 'jnxBgpM2PrefixCountersAfiSafi' } ], + output_template => 'Prefixes Out: %d', + perfdatas => [ + { value => 'jnxBgpM2PrefixOutPrefixes_absolute', template => '%d', + label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_output_peer { + my ($self, %options) = @_; + + return "Peer '" . $options{instance_value}->{jnxBgpM2PeerIdentifier} . "' "; +} + +sub prefix_output_afisafi { + my ($self, %options) = @_; + + return "AFI/SAFI '" . $options{instance_value}->{jnxBgpM2PrefixCountersAfiSafi} . "' "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking peer '" . $options{instance_value}->{jnxBgpM2PeerIdentifier} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-peer:s" => { name => 'filter_peer' }, + }); + + return $self; +} + +my $oid_jnxBgpM2PeerIdentifier = '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1'; +my $oid_jnxBgpM2PeerIndex = '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.14' ; + +my $oid_jnxBgpM2PrefixCountersTable = '.1.3.6.1.4.1.2636.5.1.1.2.6.2.1'; + +my $mapping = { + jnxBgpM2PrefixInPrefixes => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.6.2.1.7' }, + jnxBgpM2PrefixInPrefixesAccepted => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.6.2.1.8' }, + jnxBgpM2PrefixInPrefixesRejected => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.6.2.1.9' }, + jnxBgpM2PrefixOutPrefixes => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.6.2.1.10' }, + jnxBgpM2PrefixInPrefixesActive => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.6.2.1.11' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{peers} = {}; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_jnxBgpM2PeerIdentifier }, + { oid => $oid_jnxBgpM2PeerIndex }, + ], + nothing_quit => 1 + ); + + my %peers; + foreach my $oid (keys %{$snmp_result->{$oid_jnxBgpM2PeerIndex}}) { + next if ($oid !~ /^$oid_jnxBgpM2PeerIndex\.(.*)$/); + my $instance = $1; + + $peers{$snmp_result->{$oid_jnxBgpM2PeerIndex}->{$oid}} = + join('.', map { hex($_) } unpack('(H2)*', $snmp_result->{$oid_jnxBgpM2PeerIdentifier}->{$oid_jnxBgpM2PeerIdentifier . '.' . $instance})); + } + + $snmp_result = $options{snmp}->get_table( + oid => $oid_jnxBgpM2PrefixCountersTable, + start => $mapping->{jnxBgpM2PrefixInPrefixes}->{oid}, + end => $mapping->{jnxBgpM2PrefixInPrefixesActive}->{oid}, + nothing_quit => 1 + ); + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{jnxBgpM2PrefixInPrefixes}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance + ); + + ($instance =~ /(\d+).(\d+).(\d+)/); + my $jnxBgpM2PeerIdentifier = $peers{$1}; + my $jnxBgpM2PrefixCountersAfiSafi = $2 . "-" . $3; + + if (defined($self->{option_results}->{filter_peer}) && $self->{option_results}->{filter_peer} ne '' && + $jnxBgpM2PeerIdentifier !~ /$self->{option_results}->{filter_peer}/) { + $self->{output}->output_add( + long_msg => "skipping peer '" . $jnxBgpM2PeerIdentifier . "': no matching filter.", + debug => 1 + ); + next; + } + + $self->{peers}->{$jnxBgpM2PeerIdentifier}->{jnxBgpM2PeerIdentifier} = $jnxBgpM2PeerIdentifier; + $self->{peers}->{$jnxBgpM2PeerIdentifier}->{afisafi}->{$jnxBgpM2PrefixCountersAfiSafi} = + { %{$result}, jnxBgpM2PrefixCountersAfiSafi => $jnxBgpM2PrefixCountersAfiSafi }; + } + + if (scalar(keys %{$self->{peers}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No peers found'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check BGP peer prefixes per AFI/SAFI (BGP4-V2-MIB-JUNIPER) + +=over 8 + +=item B<--filter-peer> + +Filter by peer identifier (Can be regexp) + +=item B<--warning-*> + +Specify warning threshold. +Can be: 'prefixes-in', 'prefixes-in-accepted', +'prefixes-in-rejected', 'prefixes-in-active', 'prefixes-out' + +=item B<--critical-*> + +Specify critical threshold. +Can be: 'prefixes-in', 'prefixes-in-accepted', +'prefixes-in-rejected', 'prefixes-in-active', 'prefixes-out' + +=back + +=cut diff --git a/centreon-plugins/network/juniper/common/junos/mode/bgppeerstate.pm b/centreon-plugins/network/juniper/common/junos/mode/bgppeerstate.pm new file mode 100644 index 000000000..9e504a1f2 --- /dev/null +++ b/centreon-plugins/network/juniper/common/junos/mode/bgppeerstate.pm @@ -0,0 +1,232 @@ +# +# Copyright 2019 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::juniper::common::junos::mode::bgppeerstate; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("[Local IP '%s:%s', Type '%s', AS '%s'][Remote IP '%s:%s', Type '%s', AS '%s'] State is '%s', Status is '%s'", + $self->{result_values}->{local_ip}, + $self->{result_values}->{local_port}, + $self->{result_values}->{local_type}, + $self->{result_values}->{local_as}, + $self->{result_values}->{remote_ip}, + $self->{result_values}->{remote_port}, + $self->{result_values}->{remote_type}, + $self->{result_values}->{remote_as}, + $self->{result_values}->{peer_state}, + $self->{result_values}->{peer_status} + ); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{peer_state} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerState'}; + $self->{result_values}->{peer_status} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerStatus'}; + $self->{result_values}->{local_type} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerLocalAddrType'}; + $self->{result_values}->{local_ip} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerLocalAddr'}; + $self->{result_values}->{local_port} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerLocalPort'}; + $self->{result_values}->{local_as} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerLocalAs'}; + $self->{result_values}->{remote_type} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerRemoteAddrType'}; + $self->{result_values}->{remote_ip} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerRemoteAddr'}; + $self->{result_values}->{remote_port} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerRemotePort'}; + $self->{result_values}->{remote_as} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerRemoteAs'}; + $self->{result_values}->{peer_identifier} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerIdentifier'}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'peers', type => 1, cb_prefix_output => 'prefix_peers_output', + message_multiple => 'All BGP peers are ok' }, + ]; + $self->{maps_counters}->{peers} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'jnxBgpM2PeerState' }, { name => 'jnxBgpM2PeerStatus' }, + { name => 'jnxBgpM2PeerLocalAddrType' }, { name => 'jnxBgpM2PeerLocalAddr' }, + { name => 'jnxBgpM2PeerLocalPort' }, { name => 'jnxBgpM2PeerLocalAs' }, + { name => 'jnxBgpM2PeerRemoteAddrType' }, { name => 'jnxBgpM2PeerRemoteAddr' }, + { name => 'jnxBgpM2PeerRemotePort' }, { name => 'jnxBgpM2PeerRemoteAs' }, + { name => 'jnxBgpM2PeerIdentifier' } ], + 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 => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_peers_output { + my ($self, %options) = @_; + + return "Peer '" . $options{instance_value}->{jnxBgpM2PeerIdentifier} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-peer:s" => { name => 'filter_peer' }, + "filter-as:s" => { name => 'filter_as' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', + default => '%{peer_status} =~ /running/ && %{peer_state} !~ /established/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +my %map_peer_state = ( + 1 => 'idle', + 2 => 'connect', + 3 => 'active', + 4 => 'opensent', + 5 => 'openconfirm', + 6 => 'established', +); + +my %map_peer_status = ( + 1 => 'halted', + 2 => 'running', +); + +my %map_type = ( + 0 => 'unknown', + 1 => 'ipv4', + 2 => 'ipv6', + 3 => 'ipv4z', + 4 => 'ipv6z', + 16 => 'dns', +); + +my $oid_jnxBgpM2PeerTable = '.1.3.6.1.4.1.2636.5.1.1.2.1.1'; + +my $mapping = { + jnxBgpM2PeerIdentifier => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1' }, + jnxBgpM2PeerState => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2', map => \%map_peer_state }, + jnxBgpM2PeerStatus => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3', map => \%map_peer_status }, + jnxBgpM2PeerLocalAddrType => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.6', map => \%map_type }, + jnxBgpM2PeerLocalAddr => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.7' }, + jnxBgpM2PeerLocalPort => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.8' }, + jnxBgpM2PeerLocalAs => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.9' }, + jnxBgpM2PeerRemoteAddrType => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.10', map => \%map_type }, + jnxBgpM2PeerRemoteAddr => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.11' }, + jnxBgpM2PeerRemotePort => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.12' }, + jnxBgpM2PeerRemoteAs => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{peers} = {}; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_jnxBgpM2PeerTable, + start => $mapping->{jnxBgpM2PeerIdentifier}->{oid}, + end => $mapping->{jnxBgpM2PeerRemoteAs}->{oid}, + nothing_quit => 1 + ); + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{jnxBgpM2PeerIdentifier}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance + ); + $result->{jnxBgpM2PeerIdentifier} = join('.', map { hex($_) } unpack('(H2)*', $result->{jnxBgpM2PeerIdentifier})); + $result->{jnxBgpM2PeerLocalAddr} = join('.', map { hex($_) } unpack('(H2)*', $result->{jnxBgpM2PeerLocalAddr})); + $result->{jnxBgpM2PeerRemoteAddr} = join('.', map { hex($_) } unpack('(H2)*', $result->{jnxBgpM2PeerRemoteAddr})); + + if (defined($self->{option_results}->{filter_peer}) && $self->{option_results}->{filter_peer} ne '' && + $result->{jnxBgpM2PeerIdentifier} !~ /$self->{option_results}->{filter_peer}/) { + $self->{output}->output_add( + long_msg => "skipping peer '" . $result->{jnxBgpM2PeerIdentifier} . "': no matching filter.", + debug => 1 + ); + next; + } + + $self->{peers}->{$instance} = { %{$result} }; + } + + if (scalar(keys %{$self->{peers}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No peers found'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check BGP peer state (BGP4-V2-MIB-JUNIPER) + +=over 8 + +=item B<--filter-peer> + +Filter by peer identifier (Can be regexp) + +=item B<--warning-status> + +Specify warning threshold. +Can use special variables like %{peer_identifier}, %{peer_state}, %{peer_status}, +%{local_type}, %{local_ip}, %{local_port}, %{local_as}, +%{remote_type}, %{remote_ip}, %{remote_port}, %{remote_as} +(Default: '') + +=item B<--critical-status> + +Specify critical threshold. +Can use special variables like %{peer_identifier}, %{peer_state}, %{peer_status}, +%{local_type}, %{local_ip}, %{local_port}, %{local_as}, +%{remote_type}, %{remote_ip}, %{remote_port}, %{remote_as} +(Default: '%{peer_status} =~ /running/ && %{peer_state} !~ /established/') + +=back + +=cut diff --git a/centreon-plugins/network/juniper/common/junos/mode/components/alarm.pm b/centreon-plugins/network/juniper/common/junos/mode/components/alarm.pm index fd132ea44..dec75e8a1 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/components/alarm.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/components/alarm.pm @@ -41,7 +41,7 @@ sub check_alarm { $options{name}, $options{value}, $options{instance} ) ); - my $exit = $self->get_severity(section => 'alarm', value => $options{value}); + my $exit = $self->get_severity(section => 'alarm', instance => $options{instance}, value => $options{value}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add( severity => $exit, @@ -66,7 +66,7 @@ sub check { check_alarm($self, instance => 0, name => 'yellow', value => $map_alarm_states{$results->{$oid_jnxYellowAlarmState}}) if (defined($results->{$oid_jnxYellowAlarmState})); - check_alarm($self, instance => 0, name => 'red', value => $map_alarm_states{$results->{$oid_jnxRedAlarmState}}) + check_alarm($self, instance => 1, name => 'red', value => $map_alarm_states{$results->{$oid_jnxRedAlarmState}}) if (defined($results->{$oid_jnxRedAlarmState})); } diff --git a/centreon-plugins/network/juniper/common/junos/mode/components/fru.pm b/centreon-plugins/network/juniper/common/junos/mode/components/fru.pm index 9cbb99589..aa47500fb 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/components/fru.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/components/fru.pm @@ -74,45 +74,54 @@ sub check { my $mapping = { jnxFruState => { oid => '.1.3.6.1.4.1.2636.3.1.15.1.8', map => \%map_fru_states }, - jnxFruTemp => { oid => '.1.3.6.1.4.1.2636.3.1.15.1.9' }, jnxFruOfflineReason => { oid => '.1.3.6.1.4.1.2636.3.1.15.1.10', map => \%map_fru_offline }, }; - my $results = $self->{snmp}->get_table(oid => $self->{oids_fru}->{jnxFruEntry}, start => $mapping->{jnxFruState}->{oid}, end => $mapping->{jnxFruOfflineReason}->{oid}); + my $results = $self->{snmp}->get_table( + oid => $self->{oids_fru}->{jnxFruEntry}, + start => $mapping->{jnxFruState}->{oid}, + end => $mapping->{jnxFruOfflineReason}->{oid} + ); - foreach my $instance (sort $self->get_instances(oid_entry => $self->{oids_fru}->{jnxFruEntry}, oid_name => $self->{oids_fru}->{jnxFruName})) { - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); - my $name = $self->get_cache(oid_entry => $self->{oids_fru}->{jnxFruEntry}, oid_name => $self->{oids_fru}->{jnxFruName}, instance => $instance); + foreach my $instance (sort $self->get_instances(oid_entry => $self->{oids_fru}->{jnxFruEntry}, + oid_name => $self->{oids_fru}->{jnxFruName})) { + my $result = $self->{snmp}->map_instance( + mapping => $mapping, + results => $results, + instance => $instance + ); + my $name = $self->get_cache( + oid_entry => $self->{oids_fru}->{jnxFruEntry}, + oid_name => $self->{oids_fru}->{jnxFruName}, + instance => $instance + ); next if ($self->check_filter(section => 'fru', instance => $instance, name => $name)); next if ($result->{jnxFruState} =~ /empty/i && $self->absent_problem(section => 'fru', instance => $instance, name => $name)); $self->{components}->{fru}->{total}++; - my $type = $self->get_cache(oid_entry => $self->{oids_fru}->{jnxFruEntry}, oid_name => $self->{oids_fru}->{jnxFruType}, instance => $instance); - $self->{output}->output_add(long_msg => sprintf("fru '%s' state is %s [instance: %s, type: %s, offline reason: %s]", - $name, $result->{jnxFruState}, - $instance, $map_fru_type{$type}, $result->{jnxFruOfflineReason})); - my $exit = $self->get_severity(section => 'fru', value => $result->{jnxFruState}); + my $type = $self->get_cache( + oid_entry => $self->{oids_fru}->{jnxFruEntry}, + oid_name => $self->{oids_fru}->{jnxFruType}, + instance => $instance + ); + $self->{output}->output_add( + long_msg => sprintf("fru '%s' state is %s [instance: %s, type: %s, offline reason: %s]", + $name, + $result->{jnxFruState}, + $instance, + $map_fru_type{$type}, + $result->{jnxFruOfflineReason}) + ); + my $exit = $self->get_severity(section => 'fru', instance => $instance, value => $result->{jnxFruState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Fru '%s' state is %s [offline reason: %s]", $name, $result->{jnxFruState}, - $result->{jnxFruOfflineReason})); - } - - if (defined($result->{jnxFruTemp}) && $result->{jnxFruTemp} != 0) { - my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fru-temperature', instance => $instance, name => $name, value => $result->{jnxFruTemp}); - if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit2, - short_msg => sprintf("Fru '%s' temperature is %s degree centigrade", $name, $result->{jnxFruTemp})); - } - $self->{output}->perfdata_add( - label => "temp", unit => 'C', - nlabel => 'hardware.temperature.celsius', - instances => $name, - value => $result->{jnxFruTemp}, - warning => $warn, - critical => $crit + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Fru '%s' state is %s [offline reason: %s]", + $name, + $result->{jnxFruState}, + $result->{jnxFruOfflineReason}) ); } } diff --git a/centreon-plugins/network/juniper/common/junos/mode/components/operating.pm b/centreon-plugins/network/juniper/common/junos/mode/components/operating.pm index 137aa5c79..873ea0962 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/components/operating.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/components/operating.pm @@ -42,24 +42,146 @@ sub check { my $mapping = { jnxOperatingState => { oid => '.1.3.6.1.4.1.2636.3.1.13.1.6', map => \%map_operating_states }, + jnxOperatingTemp => { oid => '.1.3.6.1.4.1.2636.3.1.13.1.7' }, + jnxOperatingCPU => { oid => '.1.3.6.1.4.1.2636.3.1.13.1.8' }, + jnxOperatingBuffer => { oid => '.1.3.6.1.4.1.2636.3.1.13.1.11' }, + jnxOperatingHeap => { oid => '.1.3.6.1.4.1.2636.3.1.13.1.12' }, }; - my $results = $self->{snmp}->get_table(oid => $self->{oids_operating}->{jnxOperatingEntry}, start => $mapping->{jnxOperatingState}->{oid}, end => $mapping->{jnxOperatingState}->{oid}); + my $results = $self->{snmp}->get_table( + oid => $self->{oids_operating}->{jnxOperatingEntry}, + start => $mapping->{jnxOperatingState}->{oid}, + end => $mapping->{jnxOperatingHeap}->{oid} + ); - foreach my $instance (sort $self->get_instances(oid_entry => $self->{oids_operating}->{jnxOperatingEntry}, oid_name => $self->{oids_operating}->{jnxOperatingDescr})) { - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); - my $desc = $self->get_cache(oid_entry => $self->{oids_operating}->{jnxOperatingEntry}, oid_name => $self->{oids_operating}->{jnxOperatingDescr}, instance => $instance); + foreach my $instance (sort $self->get_instances(oid_entry => $self->{oids_operating}->{jnxOperatingEntry}, + oid_name => $self->{oids_operating}->{jnxOperatingDescr})) { + my $result = $self->{snmp}->map_instance( + mapping => $mapping, + results => $results, + instance => $instance + ); + my $description = $self->get_cache( + oid_entry => $self->{oids_operating}->{jnxOperatingEntry}, + oid_name => $self->{oids_operating}->{jnxOperatingDescr}, + instance => $instance + ); - next if ($self->check_filter(section => 'operating', instance => $instance, name => $desc)); + next if ($self->check_filter(section => 'operating', instance => $instance, name => $description)); $self->{components}->{operating}->{total}++; - $self->{output}->output_add(long_msg => sprintf("operating '%s' state is %s [instance: %s]", - $desc, $result->{jnxOperatingState}, $instance)); - my $exit = $self->get_severity(section => 'operating', value => $result->{jnxOperatingState}); + $self->{output}->output_add( + long_msg => sprintf("operating '%s' state is %s [instance: %s]", + $description, + $result->{jnxOperatingState}, + $instance) + ); + my $exit = $self->get_severity(section => 'operating', instance => $instance, + value => $result->{jnxOperatingState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Operating '%s' state is %s", - $desc, $result->{jnxOperatingState})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Operating '%s' state is %s", + $description, + $result->{jnxOperatingState}) + ); + } + + if (defined($result->{jnxOperatingTemp}) && $result->{jnxOperatingTemp} != 0) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric( + section => 'operating-temperature', + instance => $instance, + name => $description, + value => $result->{jnxOperatingTemp} + ); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Operating '%s' temperature is %s degree centigrade", + $description, + $result->{jnxOperatingTemp}) + ); + } + $self->{output}->perfdata_add( + label => "temp", unit => 'C', + nlabel => 'hardware.temperature.celsius', + instances => $description, + value => $result->{jnxOperatingTemp}, + warning => $warn, + critical => $crit + ); + } + if (defined($result->{jnxOperatingCPU}) && $result->{jnxOperatingCPU} != 0) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric( + section => 'operating-cpu', + instance => $instance, + name => $description, + value => $result->{jnxOperatingCPU} + ); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Operating '%s' CPU utilization is %s%%", + $description, + $result->{jnxOperatingCPU}) + ); + } + $self->{output}->perfdata_add( + label => "cpu_utilization", unit => '%', + nlabel => 'hardware.cpu.utilization.percentage', + instances => $description, + value => $result->{jnxOperatingCPU}, + warning => $warn, + critical => $crit + ); + } + if (defined($result->{jnxOperatingBuffer}) && $result->{jnxOperatingBuffer} != 0) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric( + section => 'operating-buffer', + instance => $instance, + name => $description, + value => $result->{jnxOperatingBuffer} + ); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Operating '%s' buffer usage is %s%%", + $description, + $result->{jnxOperatingBuffer}) + ); + } + $self->{output}->perfdata_add( + label => "buffer_usage", unit => '%', + nlabel => 'hardware.buffer.usage.percentage', + instances => $description, + value => $result->{jnxOperatingBuffer}, + warning => $warn, + critical => $crit + ); + } + if (defined($result->{jnxOperatingHeap}) && $result->{jnxOperatingHeap} != 0) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric( + section => 'operating-heap', + instance => $instance, + name => $description, + value => $result->{jnxOperatingHeap} + ); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Operating '%s' heap usage is %s%%", + $description, + $result->{jnxOperatingHeap}) + ); + } + $self->{output}->perfdata_add( + label => "heap_usage", unit => '%', + nlabel => 'hardware.heap.usage.percentage', + instances => $description, + value => $result->{jnxOperatingHeap}, + warning => $warn, + critical => $crit + ); } } } diff --git a/centreon-plugins/network/juniper/common/junos/mode/cpsessions.pm b/centreon-plugins/network/juniper/common/junos/mode/cpsessions.pm index 3086f93d2..db134cf32 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/cpsessions.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/cpsessions.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/juniper/common/junos/mode/cpuforwarding.pm b/centreon-plugins/network/juniper/common/junos/mode/cpuforwarding.pm index d4678cdd0..341a433e9 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/cpuforwarding.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/cpuforwarding.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/juniper/common/junos/mode/cpurouting.pm b/centreon-plugins/network/juniper/common/junos/mode/cpurouting.pm index 38ae696a4..0a9d5ad72 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/cpurouting.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/cpurouting.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/juniper/common/junos/mode/flowsessions.pm b/centreon-plugins/network/juniper/common/junos/mode/flowsessions.pm index 34fffda61..367588c05 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/flowsessions.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/flowsessions.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/juniper/common/junos/mode/hardware.pm b/centreon-plugins/network/juniper/common/junos/mode/hardware.pm index fcf965888..0ca3b7b21 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/hardware.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/hardware.pm @@ -30,7 +30,7 @@ sub set_system { my ($self, %options) = @_; $self->{regexp_threshold_overload_check_section_option} = '^(fru|operating|alarm)$'; - $self->{regexp_threshold_numeric_check_section_option} = '^(fru-temperature)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(operating-temperature|operating-cpu|operating-buffer|operating-heap)$'; $self->{cb_hook1} = 'init_cache'; $self->{cb_hook2} = 'snmp_execute'; @@ -82,7 +82,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'reload-cache-time:s' => { name => 'reload_cache_time', default => 180 }, }); diff --git a/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm b/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm index c1fe904e8..82695b818 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm @@ -25,19 +25,170 @@ use base qw(snmp_standard::mode::interfaces); use strict; use warnings; +sub set_oids_errors { + my ($self, %options) = @_; + + $self->{oid_ifInDiscards} = '.1.3.6.1.2.1.2.2.1.13'; + $self->{oid_ifInErrors} = '.1.3.6.1.2.1.2.2.1.14'; + $self->{oid_ifOutDiscards} = '.1.3.6.1.2.1.2.2.1.19'; + $self->{oid_ifOutErrors} = '.1.3.6.1.2.1.2.2.1.20'; + $self->{oid_dot3StatsFCSErrors} = '.1.3.6.1.2.1.10.7.2.1.3'; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->SUPER::set_counters(%options); + + push @{$self->{maps_counters}->{int}}, + { label => 'fcs-errors', filter => 'add_errors', nlabel => 'interface.fcs.errors.count', set => { + key_values => [ { name => 'fcserror', diff => 1 }, { name => 'display' } ], + output_template => 'FCS Errors : %d', + perfdatas => [ + { value => 'fcserror_absolute', template => '%d', + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ; + + push @{$self->{maps_counters}->{int}}, + { label => 'input-power', filter => 'add_optical', nlabel => 'interface.input.power.dbm', set => { + key_values => [ { name => 'input_power' }, { name => 'display' } ], + output_template => 'Input Power : %s dBm', + perfdatas => [ + { value => 'input_power_absolute', template => '%s', + unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'bias-current', filter => 'add_optical', nlabel => 'interface.bias.current.milliampere', set => { + key_values => [ { name => 'bias_current' }, { name => 'display' } ], + output_template => 'Bias Current : %s mA', + perfdatas => [ + { value => 'bias_current_absolute', template => '%s', + unit => 'mA', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'output-power', filter => 'add_optical', nlabel => 'interface.output.power.dbm', set => { + key_values => [ { name => 'output_power' }, { name => 'display' } ], + output_template => 'Output Power : %s dBm', + perfdatas => [ + { value => 'output_power_absolute', template => '%s', + unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'module-temperature', filter => 'add_optical', nlabel => 'interface.module.temperature.celsius', set => { + key_values => [ { name => 'module_temperature' }, { name => 'display' } ], + output_template => 'Module Temperature : %.2f C', + perfdatas => [ + { value => 'module_temperature_absolute', template => '%.2f', + unit => 'C', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; + $options{options}->add_options(arguments => { + 'add-optical' => { name => 'add_optical' }, + } + ); + return $self; } -sub add_result_status { +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{checking} = ''; + foreach (('add_global', 'add_status', 'add_errors', 'add_traffic', 'add_cast', 'add_speed', 'add_volume', 'add_optical')) { + if (defined($self->{option_results}->{$_})) { + $self->{checking} .= $_; + } + } +} + +sub load_errors { my ($self, %options) = @_; - $self->{int}->{$options{instance}}->{opstatus} = defined($self->{results}->{$self->{oid_opstatus} . '.' . $options{instance}}) ? $self->{oid_opstatus_mapping}->{$self->{results}->{$self->{oid_opstatus} . '.' . $options{instance}}} : 'unknown'; - $self->{int}->{$options{instance}}->{admstatus} = defined($self->{results}->{$self->{oid_adminstatus} . '.' . $options{instance}}) ? $self->{oid_adminstatus_mapping}->{$self->{results}->{$self->{oid_adminstatus} . '.' . $options{instance}}} : 'unknown'; + $self->set_oids_errors(); + $self->{snmp}->load( + oids => [ + $self->{oid_ifInDiscards}, + $self->{oid_ifInErrors}, + $self->{oid_ifOutDiscards}, + $self->{oid_ifOutErrors}, + $self->{oid_dot3StatsFCSErrors} + ], + instances => $self->{array_interface_selected} + ); +} + +sub add_result_errors { + my ($self, %options) = @_; + + $self->{int}->{$options{instance}}->{indiscard} = $self->{results}->{$self->{oid_ifInDiscards} . '.' . $options{instance}}; + $self->{int}->{$options{instance}}->{inerror} = $self->{results}->{$self->{oid_ifInErrors} . '.' . $options{instance}}; + $self->{int}->{$options{instance}}->{outdiscard} = $self->{results}->{$self->{oid_ifOutDiscards} . '.' . $options{instance}}; + $self->{int}->{$options{instance}}->{outerror} = $self->{results}->{$self->{oid_ifOutErrors} . '.' . $options{instance}}; + $self->{int}->{$options{instance}}->{fcserror} = $self->{results}->{$self->{oid_dot3StatsFCSErrors} . '.' . $options{instance}}; +} + +my $oid_jnxDomCurrentRxLaserPower = '.1.3.6.1.4.1.2636.3.60.1.1.1.1.5'; +my $oid_jnxDomCurrentTxLaserBiasCurrent = '.1.3.6.1.4.1.2636.3.60.1.1.1.1.6'; +my $oid_jnxDomCurrentTxLaserOutputPower = '.1.3.6.1.4.1.2636.3.60.1.1.1.1.7'; +my $oid_jnxDomCurrentModuleTemperature = '.1.3.6.1.4.1.2636.3.60.1.1.1.1.8'; + +sub custom_load { + my ($self, %options) = @_; + + return if (!defined($self->{option_results}->{add_optical})); + + $self->{snmp}->load( + oids => [ + $oid_jnxDomCurrentRxLaserPower, + $oid_jnxDomCurrentTxLaserBiasCurrent, + $oid_jnxDomCurrentTxLaserOutputPower, + $oid_jnxDomCurrentModuleTemperature + ], + instances => $self->{array_interface_selected} + ); +} + +sub custom_add_result { + my ($self, %options) = @_; + + return if (!defined($self->{option_results}->{add_optical})); + + $self->{int}->{$options{instance}}->{input_power} = undef; + if (defined($self->{results}->{$oid_jnxDomCurrentRxLaserPower . '.' . $options{instance}}) && + $self->{results}->{$oid_jnxDomCurrentRxLaserPower . '.' . $options{instance}} != 0) { + $self->{int}->{$options{instance}}->{input_power} = $self->{results}->{$oid_jnxDomCurrentRxLaserPower . '.' . $options{instance}} / 100; + } + $self->{int}->{$options{instance}}->{bias_current} = undef; + if (defined($self->{results}->{$oid_jnxDomCurrentTxLaserBiasCurrent . '.' . $options{instance}}) && + $self->{results}->{$oid_jnxDomCurrentTxLaserBiasCurrent . '.' . $options{instance}} != 0) { + $self->{int}->{$options{instance}}->{bias_current} = $self->{results}->{$oid_jnxDomCurrentTxLaserBiasCurrent . '.' . $options{instance}} / 100; + } + $self->{int}->{$options{instance}}->{output_power} = undef; + if (defined($self->{results}->{$oid_jnxDomCurrentTxLaserOutputPower . '.' . $options{instance}}) && + $self->{results}->{$oid_jnxDomCurrentTxLaserOutputPower . '.' . $options{instance}} != 0) { + $self->{int}->{$options{instance}}->{output_power} = $self->{results}->{$oid_jnxDomCurrentTxLaserOutputPower . '.' . $options{instance}} / 100; + } + $self->{int}->{$options{instance}}->{module_temperature} = undef; + if (defined($self->{results}->{$oid_jnxDomCurrentModuleTemperature . '.' . $options{instance}}) && + $self->{results}->{$oid_jnxDomCurrentModuleTemperature . '.' . $options{instance}} != 0) { + $self->{int}->{$options{instance}}->{module_temperature} = $self->{results}->{$oid_jnxDomCurrentModuleTemperature . '.' . $options{instance}}; + } } 1; @@ -58,6 +209,10 @@ Check global port statistics (By default if no --add-* option is set). Check interface status. +=item B<--add-duplex-status> + +Check duplex status (with --warning-status and --critical-status). + =item B<--add-traffic> Check interface traffic. @@ -78,32 +233,60 @@ Check interface speed. Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). +=item B<--add-optical> + +Check interface optical metrics. + =item B<--warning-status> Set warning threshold for status. -Can used special variables like: %{admstatus}, %{opstatus}, %{display} +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} =item B<--critical-status> Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). -Can used special variables like: %{admstatus}, %{opstatus}, %{display} +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--warning-errors> + +Set warning threshold for all error counters. + +=item B<--critical-errors> + +Set critical threshold for all error counters. =item B<--warning-*> -Threshold warning. +Threshold warning (will superseed --warning-errors). Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', -'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', 'fcs-errors', 'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), 'speed' (b/s). +And also: 'in-tooshort' (%), 'in-toolong' (%), 'in-fcserror' (%), 'in-alignerror' (%), 'in-fragment' (%), +'in-overflow' (%), 'in-unknownop' (%), 'in-lengtherror' (%), 'in-codeerror' (%), 'in-carriererror' (%), +'in-jabber' (%), 'in-drop' (%), 'out-tooshort' (%), 'out-toolong' (%), 'out-underrun' (%), +'out-collision' (%), 'out-excessivecollision' (%), 'out-multiplecollision' (%), 'out-singlecollision' (%), +'out-excessivedeferred' (%),'out-deferred' (%), 'out-latecollision' (%), 'out-totalcollision' (%), +'out-drop' (%), 'out-jabber' (%), 'out-fcserror' (%), 'out-fragment' (%), +'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'module-temperature' (C). + =item B<--critical-*> -Threshold critical. +Threshold critical (will superseed --warning-errors). Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', -'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', 'fcs-errors', 'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), 'speed' (b/s). +And also: 'in-tooshort' (%), 'in-toolong' (%), 'in-fcserror' (%), 'in-alignerror' (%), 'in-fragment' (%), +'in-overflow' (%), 'in-unknownop' (%), 'in-lengtherror' (%), 'in-codeerror' (%), 'in-carriererror' (%), +'in-jabber' (%), 'in-drop' (%), 'out-tooshort' (%), 'out-toolong' (%), 'out-underrun' (%), +'out-collision' (%), 'out-excessivecollision' (%), 'out-multiplecollision' (%), 'out-singlecollision' (%), +'out-excessivedeferred' (%),'out-deferred' (%), 'out-latecollision' (%), 'out-totalcollision' (%), +'out-drop' (%), 'out-jabber' (%), 'out-fcserror' (%), 'out-fragment' (%), +'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'module-temperature' (C). + =item B<--units-traffic> Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). @@ -150,11 +333,11 @@ Time in minutes before reloading cache file (default: 180). =item B<--oid-filter> -Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName). +Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). =item B<--oid-display> -Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName). +Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). =item B<--oid-extra-display> diff --git a/centreon-plugins/network/juniper/common/junos/mode/ipsectunnel.pm b/centreon-plugins/network/juniper/common/junos/mode/ipsectunnel.pm new file mode 100644 index 000000000..dd6624a6e --- /dev/null +++ b/centreon-plugins/network/juniper/common/junos/mode/ipsectunnel.pm @@ -0,0 +1,271 @@ +# +# Copyright 2019 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::juniper::common::junos::mode::ipsectunnel; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'ike state: ' . $self->{result_values}->{ike_state}; + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'tunnel', type => 1, cb_prefix_output => 'prefix_tunnel_output', message_multiple => 'All tunnels are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'tunnels-total', nlabel => 'ipsec.tunnels.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'Total Tunnels: %s', + perfdatas => [ + { label => 'total_tunnels', value => 'total_absolute', template => '%s', + min => 0 }, + ], + } + }, + ]; + $self->{maps_counters}->{tunnel} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'ike_state' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'tunnel-traffic-in', nlabel => 'ipsec.tunnel.traffic.in.bitspersecond', set => { + key_values => [], + per_second => 1, manual_keys => 1, + closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, + closure_custom_output => $self->can('custom_traffic_output'), + threshold_use => 'traffic_per_second', + perfdatas => [ + { value => 'traffic_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'tunnel-traffic-out', nlabel => 'ipsec.tunnel.traffic.out.bitspersecond', set => { + key_values => [], + per_second => 1, manual_keys => 1, + closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, + closure_custom_output => $self->can('custom_traffic_output'), + threshold_use => 'traffic_per_second', + perfdatas => [ + { value => 'traffic_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + ]; +} + +sub custom_traffic_output { + my ($self, %options) = @_; + + my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_second}, network => 1); + my $msg = sprintf("traffic %s: %s/s", + $self->{result_values}->{label}, + $traffic_value . $traffic_unit + ); + return $msg; +} + +sub custom_traffic_calc { + my ($self, %options) = @_; + + my ($checked, $total_bits) = (0, 0); + foreach (keys %{$options{new_datas}}) { + if (/$self->{instance}_traffic_$options{extra_options}->{label_ref}_(\d+)/) { + $checked |= 1; + my $new_bits = $options{new_datas}->{$_}; + next if (!defined($options{old_datas}->{$_})); + my $old_bits = $options{old_datas}->{$_}; + + $checked |= 2; + my $diff_bits = $new_bits - $old_bits; + if ($diff_bits < 0) { + $total_bits += $new_bits; + } else { + $total_bits += $diff_bits; + } + } + } + + if ($checked == 0) { + $self->{error_msg} = 'skipped (no value)'; + return -10; + } + if ($checked == 1) { + $self->{error_msg} = 'buffer creation'; + return -1; + } + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{traffic_per_second} = $total_bits / $options{delta_time}; + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + return 0; +} + +sub prefix_tunnel_output { + my ($self, %options) = @_; + + return "Tunnel '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{ike_state} eq "down"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +my $map_ike_state = { 1 => 'up', 2 => 'down' }; + +my $mapping = { + jnxIkeTunMonState => { oid => '.1.3.6.1.4.1.2636.3.52.1.1.2.1.6', map => $map_ike_state }, + jnxIkeTunMonRemoteIdValue => { oid => '.1.3.6.1.4.1.2636.3.52.1.1.2.1.14' }, +}; +my $mapping2 = { + jnxIpSecTunMonOutEncryptedBytes => { oid => '.1.3.6.1.4.1.2636.3.52.1.2.2.1.10' }, + jnxIpSecTunMonInDecryptedBytes => { oid => '.1.3.6.1.4.1.2636.3.52.1.2.2.1.12' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{tunnel} = {}; + my $request_oids = [ + { oid => $mapping->{jnxIkeTunMonState}->{oid} }, + { oid => $mapping->{jnxIkeTunMonRemoteIdValue}->{oid} }, + ]; + my $snmp_result = $options{snmp}->get_multiple_table(oids => $request_oids, return_type => 1, nothing_quit => 1); + my $snmp_result2 = $options{snmp}->get_multiple_table( + oids => [ + { oid => $mapping2->{jnxIpSecTunMonOutEncryptedBytes}->{oid} }, + { oid => $mapping2->{jnxIpSecTunMonInDecryptedBytes}->{oid} }, + ], + return_type => 1 + ); + + foreach (keys %$snmp_result) { + next if (!/$mapping->{jnxIkeTunMonRemoteIdValue}->{oid}\.(\d+\.\d+)\.(\d+\.\d+\.\d+\.\d+)\.(\d+)/); + my $instance = $1 . '.' . $2 . '.' . $3; + my ($remote_type, $remote_addr, $tun_index) = ($1, $2, $3); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{jnxIkeTunMonRemoteIdValue} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{jnxIkeTunMonRemoteIdValue} . "': no matching filter name.", debug => 1); + next; + } + + $self->{tunnel}->{$instance} = { + display => $result->{jnxIkeTunMonRemoteIdValue}, + ike_state => $result->{jnxIkeTunMonState}, + }; + + foreach my $key (keys %$snmp_result2) { + next if ($key !~ /^$mapping2->{jnxIpSecTunMonInDecryptedBytes}->{oid}\.$remote_type\.$remote_addr\.(\d+)/); + + my $instance2 = $remote_type . '.' . $remote_addr . '.' . $1; + my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result2, instance => $instance2); + + $self->{tunnel}->{$instance}->{'traffic_in_' . $instance2} = $result2->{jnxIpSecTunMonInDecryptedBytes} * 8; + $self->{tunnel}->{$instance}->{'traffic_out_' . $instance2} = $result2->{jnxIpSecTunMonOutEncryptedBytes} * 8; + } + } + + $self->{cache_name} = "juniper_junos_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + $self->{global} = { total => scalar(keys %{$self->{tunnel}}) }; +} + +1; + +__END__ + +=head1 MODE + +Check ipsec tunnels. + +=over 8 + +=item B<--filter-name> + +Filter name (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='tunnels-total' + +=item B<--unknown-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{ike_state}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{ike_state}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{ike_state} eq "down"'). +Can used special variables like: %{ike_state}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'tunnels-total', 'tunnel-traffic-in', 'tunnel-traffic-out'. + +=back + +=cut diff --git a/centreon-plugins/network/juniper/common/junos/mode/ldpsessionstatus.pm b/centreon-plugins/network/juniper/common/junos/mode/ldpsessionstatus.pm index 5fa4ae42b..e1d67650b 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/ldpsessionstatus.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/ldpsessionstatus.pm @@ -81,7 +81,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-entity:s" => { name => 'filter_entity' }, diff --git a/centreon-plugins/network/juniper/common/junos/mode/listbgppeers.pm b/centreon-plugins/network/juniper/common/junos/mode/listbgppeers.pm new file mode 100644 index 000000000..4fbafb48e --- /dev/null +++ b/centreon-plugins/network/juniper/common/junos/mode/listbgppeers.pm @@ -0,0 +1,142 @@ +# +# Copyright 2019 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::juniper::common::junos::mode::listbgppeers; + +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; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my %map_peer_state = ( + 1 => 'idle', + 2 => 'connect', + 3 => 'active', + 4 => 'opensent', + 5 => 'openconfirm', + 6 => 'established', +); + +my %map_peer_status = ( + 1 => 'halted', + 2 => 'running', +); + +my $oid_jnxBgpM2PeerTable = '.1.3.6.1.4.1.2636.5.1.1.2.1.1'; + +my $mapping = { + jnxBgpM2PeerIdentifier => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1' }, + jnxBgpM2PeerState => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2', map => \%map_peer_state }, + jnxBgpM2PeerStatus => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3', map => \%map_peer_status }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{peers} = {}; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_jnxBgpM2PeerTable, + start => $mapping->{jnxBgpM2PeerIdentifier}->{oid}, + end => $mapping->{jnxBgpM2PeerStatus}->{oid}, + nothing_quit => 1 + ); + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{jnxBgpM2PeerIdentifier}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance + ); + $result->{jnxBgpM2PeerIdentifier} = join('.', map { hex($_) } unpack('(H2)*', $result->{jnxBgpM2PeerIdentifier})); + + $self->{peers}->{$instance} = { %{$result} }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{peers}}) { + $self->{output}->output_add( + long_msg => '[name = ' . $self->{peers}->{$instance}->{jnxBgpM2PeerIdentifier} . + "] [status = '" . $self->{peers}->{$instance}->{jnxBgpM2PeerStatus} . "'] [state = '" . + $self->{peers}->{$instance}->{jnxBgpM2PeerState} . "']" + ); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List peers:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'status', 'state']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{peers}}) { + $self->{output}->add_disco_entry( + name => $self->{peers}->{$instance}->{jnxBgpM2PeerIdentifier}, + status => $self->{peers}->{$instance}->{jnxBgpM2PeerStatus}, + state => $self->{peers}->{$instance}->{jnxBgpM2PeerState} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List peers. + +=over 8 + +=back + +=cut + diff --git a/centreon-plugins/network/juniper/common/junos/mode/lspstatus.pm b/centreon-plugins/network/juniper/common/junos/mode/lspstatus.pm index cc36a66a7..c02891e45 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/lspstatus.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/lspstatus.pm @@ -90,7 +90,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/juniper/common/junos/mode/memoryforwarding.pm b/centreon-plugins/network/juniper/common/junos/mode/memoryforwarding.pm index 7f26de7e7..c635a1d1b 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/memoryforwarding.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/memoryforwarding.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/juniper/common/junos/mode/memoryrouting.pm b/centreon-plugins/network/juniper/common/junos/mode/memoryrouting.pm index 376e14453..353777283 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/memoryrouting.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/memoryrouting.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/juniper/common/junos/mode/rsvpsessionstatus.pm b/centreon-plugins/network/juniper/common/junos/mode/rsvpsessionstatus.pm index d1af52154..11e213f28 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/rsvpsessionstatus.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/rsvpsessionstatus.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/juniper/common/junos/mode/stack.pm b/centreon-plugins/network/juniper/common/junos/mode/stack.pm new file mode 100644 index 000000000..b816bee15 --- /dev/null +++ b/centreon-plugins/network/juniper/common/junos/mode/stack.pm @@ -0,0 +1,162 @@ +# +# Copyright 2019 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::juniper::common::junos::mode::stack; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("role: %s", + $self->{result_values}->{role}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{roleLast} = $options{old_datas}->{$self->{instance} . '_role'}; + $self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'}; + if (!defined($options{old_datas}->{$self->{instance} . '_role'})) { + $self->{error_msg} = "buffer creation"; + return -2; + } + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'stack', type => 1, cb_prefix_output => 'prefix_stack_output', message_multiple => 'All stack members are ok' }, + ]; + + $self->{maps_counters}->{stack} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'role' }, { 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 => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_stack_output { + my ($self, %options) = @_; + + return "Stack member '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{role} ne %{roleLast}' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +my %map_role = ( + 1 => 'master', + 2 => 'backup', + 3 => 'linecard', +); + +my $mapping = { + jnxVirtualChassisMemberSerialnumber => { oid => '.1.3.6.1.4.1.2636.3.40.1.4.1.1.1.2' }, + jnxVirtualChassisMemberRole => { oid => '.1.3.6.1.4.1.2636.3.40.1.4.1.1.1.3', map => \%map_role }, +}; +my $oid_jnxVirtualChassisMemberEntry = '.1.3.6.1.4.1.2636.3.40.1.4.1.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{stack} = {}; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_jnxVirtualChassisMemberEntry, + start => $mapping->{jnxVirtualChassisMemberSerialnumber}->{oid}, + end => $mapping->{jnxVirtualChassisMemberRole}->{oid}, + nothing_quit => 1 + ); + + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{jnxVirtualChassisMemberRole}->{oid}\.(.*)$/); + my $instance_id = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance_id); + + $self->{stack}->{$instance_id} = { + display => $result->{jnxVirtualChassisMemberSerialnumber}, + role => $result->{jnxVirtualChassisMemberRole}, + }; + } + + $self->{cache_name} = "juniper_junos_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check stack members. + +=over 8 + +=item B<--unknown-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{role}, %{roleLast} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{role}, %{roleLast} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{role} ne %{roleLast}'). +Can used special variables like: %{role}, %{roleLast} + +=back + +=cut diff --git a/centreon-plugins/network/juniper/common/screenos/snmp/mode/cpu.pm b/centreon-plugins/network/juniper/common/screenos/snmp/mode/cpu.pm index 51de6811f..53c3b001d 100644 --- a/centreon-plugins/network/juniper/common/screenos/snmp/mode/cpu.pm +++ b/centreon-plugins/network/juniper/common/screenos/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '' }, diff --git a/centreon-plugins/network/juniper/common/screenos/snmp/mode/hardware.pm b/centreon-plugins/network/juniper/common/screenos/snmp/mode/hardware.pm index 9d72106b0..39b603fa4 100644 --- a/centreon-plugins/network/juniper/common/screenos/snmp/mode/hardware.pm +++ b/centreon-plugins/network/juniper/common/screenos/snmp/mode/hardware.pm @@ -64,7 +64,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/juniper/common/screenos/snmp/mode/listvpn.pm b/centreon-plugins/network/juniper/common/screenos/snmp/mode/listvpn.pm index 332625eb3..3c79661eb 100644 --- a/centreon-plugins/network/juniper/common/screenos/snmp/mode/listvpn.pm +++ b/centreon-plugins/network/juniper/common/screenos/snmp/mode/listvpn.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/juniper/common/screenos/snmp/mode/memory.pm b/centreon-plugins/network/juniper/common/screenos/snmp/mode/memory.pm index 9720f562f..0be7cc879 100644 --- a/centreon-plugins/network/juniper/common/screenos/snmp/mode/memory.pm +++ b/centreon-plugins/network/juniper/common/screenos/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/juniper/common/screenos/snmp/mode/nsrp.pm b/centreon-plugins/network/juniper/common/screenos/snmp/mode/nsrp.pm new file mode 100644 index 000000000..c2c91c517 --- /dev/null +++ b/centreon-plugins/network/juniper/common/screenos/snmp/mode/nsrp.pm @@ -0,0 +1,216 @@ +# +# Copyright 2019 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::juniper::common::screenos::snmp::mode::nsrp; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("status: %s", + $self->{result_values}->{status}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{statusLast} = $options{old_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + if (!defined($options{old_datas}->{$self->{instance} . '_status'})) { + $self->{error_msg} = "buffer creation"; + return -2; + } + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'nsrp', type => 3, cb_prefix_output => 'prefix_nsrp_output', cb_long_output => 'nsrp_long_output', indent_long_output => ' ', message_multiple => 'All nsrp groups are ok', + group => [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'member', cb_prefix_output => 'prefix_member_output', message_multiple => 'All members are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'group-transition-change', nlabel => 'nsrp.group.transition.change.count', set => { + key_values => [ { name => 'nsrpVsdGroupCntStateChange', diff => 1 } ], + output_template => 'number of state transition events: %s', + perfdatas => [ + { value => 'nsrpVsdGroupCntStateChange_absolute', template => '%s', + min => 0, label_extra_instance => 1 }, + ], + } + }, + ]; + + $self->{maps_counters}->{member} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { 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 => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_nsrp_output { + my ($self, %options) = @_; + + return "Nsrp group '" . $options{instance_value}->{display} . "' "; +} + +sub nsrp_long_output { + my ($self, %options) = @_; + + return "checking nsrp group '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_member_output { + my ($self, %options) = @_; + + return "member '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /undefined/i' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /ineligible|inoperable/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +my %map_status = ( + 0 => 'undefined', + 1 => 'init', + 2 => 'master', + 3 => 'primary-backup', + 4 => 'backup', + 5 => 'ineligible', + 6 => 'inoperable', +); + +my $mapping = { + nsrpVsdMemberStatus => { oid => '.1.3.6.1.4.1.3224.6.2.2.1.3', map => \%map_status }, +}; +my $mapping2 = { + nsrpVsdGroupCntStateChange => { oid => '.1.3.6.1.4.1.3224.6.2.1.1.6' }, + nsrpVsdGroupCntToInit => { oid => '.1.3.6.1.4.1.3224.6.2.1.1.7' }, + nsrpVsdGroupCntToMaster => { oid => '.1.3.6.1.4.1.3224.6.2.1.1.8' }, +}; +my $oid_nsrpVsdGroupEntry = '.1.3.6.1.4.1.3224.6.2.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{nsrp} = {}; + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $mapping->{nsrpVsdMemberStatus}->{oid} }, + { oid => $oid_nsrpVsdGroupEntry, start => $mapping2->{nsrpVsdGroupCntStateChange}->{oid}, end => $mapping2->{nsrpVsdGroupCntToMaster}->{oid} }, + ], + nothing_quit => 1 + ); + + foreach my $oid (keys %{$snmp_result->{ $mapping->{nsrpVsdMemberStatus}->{oid} }}) { + $oid =~ /^$mapping->{nsrpVsdMemberStatus}->{oid}\.(\d+)\.(\d+)$/; + my ($group_id, $member_id) = ($1, $2); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{ $mapping->{nsrpVsdMemberStatus}->{oid} }, instance => $group_id . '.' . $member_id); + + if (!defined($self->{nsrp}->{$group_id})) { + my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_nsrpVsdGroupEntry}, instance => $group_id); + $self->{nsrp}->{$group_id} = { + display => $group_id, + global => { + %$result2 + }, + member => {}, + }; + } + + $self->{nsrp}->{$group_id}->{member}->{$member_id} = { + display => $member_id, + status => $result->{nsrpVsdMemberStatus}, + }; + } + + $self->{cache_name} = "juniper_screenos_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check nsrp groups. + +=over 8 + +=item B<--unknown-status> + +Set warning threshold for status (Default: '%{status} =~ /undefined/i'). +Can used special variables like: %{status}, %{statusLast} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{statusLast} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /ineligible|inoperable/i'). +Can used special variables like: %{status}, %{statusLast} + +=item B<--warning-*> B<--critical-*> + +Threshold warning. +Can be: 'group-transition-change'. + +=back + +=cut diff --git a/centreon-plugins/network/juniper/common/screenos/snmp/mode/sessions.pm b/centreon-plugins/network/juniper/common/screenos/snmp/mode/sessions.pm index 2ce97e010..5c7344f47 100644 --- a/centreon-plugins/network/juniper/common/screenos/snmp/mode/sessions.pm +++ b/centreon-plugins/network/juniper/common/screenos/snmp/mode/sessions.pm @@ -70,7 +70,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/juniper/common/screenos/snmp/mode/vpnstatus.pm b/centreon-plugins/network/juniper/common/screenos/snmp/mode/vpnstatus.pm index 29f520e1f..7e81c90ed 100644 --- a/centreon-plugins/network/juniper/common/screenos/snmp/mode/vpnstatus.pm +++ b/centreon-plugins/network/juniper/common/screenos/snmp/mode/vpnstatus.pm @@ -89,7 +89,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/juniper/common/screenos/snmp/mode/vpnusage.pm b/centreon-plugins/network/juniper/common/screenos/snmp/mode/vpnusage.pm index ba5c3f180..db0a6274a 100644 --- a/centreon-plugins/network/juniper/common/screenos/snmp/mode/vpnusage.pm +++ b/centreon-plugins/network/juniper/common/screenos/snmp/mode/vpnusage.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/juniper/ex/plugin.pm b/centreon-plugins/network/juniper/ex/plugin.pm index cb92ff0ea..4318142e8 100644 --- a/centreon-plugins/network/juniper/ex/plugin.pm +++ b/centreon-plugins/network/juniper/ex/plugin.pm @@ -31,14 +31,15 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'network::juniper::common::junos::mode::hardware', - 'cpu-routing' => 'network::juniper::common::junos::mode::cpurouting', # routing engine - 'memory-routing' => 'network::juniper::common::junos::mode::memoryrouting', # routing engine - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-storages' => 'snmp_standard::mode::liststorages', - 'storage' => 'snmp_standard::mode::storage', - ); + 'cpu-routing' => 'network::juniper::common::junos::mode::cpurouting', # routing engine + 'hardware' => 'network::juniper::common::junos::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory-routing' => 'network::juniper::common::junos::mode::memoryrouting', # routing engine + 'list-storages' => 'snmp_standard::mode::liststorages', + 'stack' => 'network::juniper::common::junos::mode::stack', + 'storage' => 'snmp_standard::mode::storage', + ); return $self; } diff --git a/centreon-plugins/network/juniper/ggsn/mode/apnstats.pm b/centreon-plugins/network/juniper/ggsn/mode/apnstats.pm index fd681067b..44a96db7e 100644 --- a/centreon-plugins/network/juniper/ggsn/mode/apnstats.pm +++ b/centreon-plugins/network/juniper/ggsn/mode/apnstats.pm @@ -182,7 +182,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/network/juniper/ggsn/mode/globalstats.pm b/centreon-plugins/network/juniper/ggsn/mode/globalstats.pm index ad29c46fd..9d6616ce5 100644 --- a/centreon-plugins/network/juniper/ggsn/mode/globalstats.pm +++ b/centreon-plugins/network/juniper/ggsn/mode/globalstats.pm @@ -194,7 +194,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/juniper/mag/mode/bladetemperature.pm b/centreon-plugins/network/juniper/mag/mode/bladetemperature.pm index dcbf3544c..68350ca1e 100644 --- a/centreon-plugins/network/juniper/mag/mode/bladetemperature.pm +++ b/centreon-plugins/network/juniper/mag/mode/bladetemperature.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/juniper/mseries/plugin.pm b/centreon-plugins/network/juniper/mseries/plugin.pm index da05f664b..133de6a02 100644 --- a/centreon-plugins/network/juniper/mseries/plugin.pm +++ b/centreon-plugins/network/juniper/mseries/plugin.pm @@ -31,16 +31,19 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu-routing' => 'network::juniper::common::junos::mode::cpurouting', # routing engine - 'hardware' => 'network::juniper::common::junos::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'ldp-session-status' => 'network::juniper::common::junos::mode::ldpsessionstatus', - 'lsp-status' => 'network::juniper::common::junos::mode::lspstatus', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-storages' => 'snmp_standard::mode::liststorages', - 'memory-routing' => 'network::juniper::common::junos::mode::memoryrouting', # routing engine - 'rsvp-session-status' => 'network::juniper::common::junos::mode::rsvpsessionstatus', - 'storage' => 'snmp_standard::mode::storage', + 'bgp-peer-state' => 'network::juniper::common::junos::mode::bgppeerstate', + 'bgp-peer-prefix-statistics' => 'network::juniper::common::junos::mode::bgppeerprefixstatistics', + 'cpu-routing' => 'network::juniper::common::junos::mode::cpurouting', # routing engine + 'hardware' => 'network::juniper::common::junos::mode::hardware', + 'interfaces' => 'network::juniper::common::junos::mode::interfaces', + 'ldp-session-status' => 'network::juniper::common::junos::mode::ldpsessionstatus', + 'lsp-status' => 'network::juniper::common::junos::mode::lspstatus', + 'list-bgp-peers' => 'network::juniper::common::junos::mode::listbgppeers', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'memory-routing' => 'network::juniper::common::junos::mode::memoryrouting', # routing engine + 'rsvp-session-status' => 'network::juniper::common::junos::mode::rsvpsessionstatus', + 'storage' => 'snmp_standard::mode::storage', ); return $self; diff --git a/centreon-plugins/network/juniper/srx/plugin.pm b/centreon-plugins/network/juniper/srx/plugin.pm index 985234adc..e09cf27ad 100644 --- a/centreon-plugins/network/juniper/srx/plugin.pm +++ b/centreon-plugins/network/juniper/srx/plugin.pm @@ -31,18 +31,19 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'network::juniper::common::junos::mode::hardware', - 'cpu-routing' => 'network::juniper::common::junos::mode::cpurouting', # routing engine - 'cpu-forwarding' => 'network::juniper::common::junos::mode::cpuforwarding', # packet forwarding engine - 'memory-routing' => 'network::juniper::common::junos::mode::memoryrouting', # routing engine - 'memory-forwarding' => 'network::juniper::common::junos::mode::memoryforwarding', # packet forwarding engine - 'cp-sessions' => 'network::juniper::common::junos::mode::cpsessions', # CP = 'central point' - 'flow-sessions' => 'network::juniper::common::junos::mode::flowsessions', - 'interfaces' => 'network::juniper::common::junos::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-storages' => 'snmp_standard::mode::liststorages', - 'storage' => 'snmp_standard::mode::storage', - ); + 'hardware' => 'network::juniper::common::junos::mode::hardware', + 'cpu-routing' => 'network::juniper::common::junos::mode::cpurouting', # routing engine + 'cpu-forwarding' => 'network::juniper::common::junos::mode::cpuforwarding', # packet forwarding engine + 'memory-routing' => 'network::juniper::common::junos::mode::memoryrouting', # routing engine + 'memory-forwarding' => 'network::juniper::common::junos::mode::memoryforwarding', # packet forwarding engine + 'cp-sessions' => 'network::juniper::common::junos::mode::cpsessions', # CP = 'central point' + 'flow-sessions' => 'network::juniper::common::junos::mode::flowsessions', + 'interfaces' => 'network::juniper::common::junos::mode::interfaces', + 'ipsec-tunnel' => 'network::juniper::common::junos::mode::ipsectunnel', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'storage' => 'snmp_standard::mode::storage', + ); return $self; } diff --git a/centreon-plugins/network/juniper/ssg/snmp/plugin.pm b/centreon-plugins/network/juniper/ssg/snmp/plugin.pm index 5e0e0afe8..9a7f4a6d6 100644 --- a/centreon-plugins/network/juniper/ssg/snmp/plugin.pm +++ b/centreon-plugins/network/juniper/ssg/snmp/plugin.pm @@ -31,16 +31,17 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::juniper::common::screenos::snmp::mode::cpu', - 'hardware' => 'network::juniper::common::screenos::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-vpn' => 'network::juniper::common::screenos::snmp::mode::listvpn', - 'memory' => 'network::juniper::common::screenos::snmp::mode::memory', - 'sessions' => 'network::juniper::common::screenos::snmp::mode::sessions', - 'vpn-status' => 'network::juniper::common::screenos::snmp::mode::vpnstatus', - 'vpn-usage' => 'network::juniper::common::screenos::snmp::mode::vpnusage', - ); + 'cpu' => 'network::juniper::common::screenos::snmp::mode::cpu', + 'hardware' => 'network::juniper::common::screenos::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-vpn' => 'network::juniper::common::screenos::snmp::mode::listvpn', + 'memory' => 'network::juniper::common::screenos::snmp::mode::memory', + 'nsrp' => 'network::juniper::common::screenos::snmp::mode::nsrp', + 'sessions' => 'network::juniper::common::screenos::snmp::mode::sessions', + 'vpn-status' => 'network::juniper::common::screenos::snmp::mode::vpnstatus', + 'vpn-usage' => 'network::juniper::common::screenos::snmp::mode::vpnusage', + ); return $self; } diff --git a/centreon-plugins/network/juniper/trapeze/snmp/mode/apstatus.pm b/centreon-plugins/network/juniper/trapeze/snmp/mode/apstatus.pm index 695d1af4d..d528e3717 100644 --- a/centreon-plugins/network/juniper/trapeze/snmp/mode/apstatus.pm +++ b/centreon-plugins/network/juniper/trapeze/snmp/mode/apstatus.pm @@ -81,7 +81,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/juniper/trapeze/snmp/mode/apusers.pm b/centreon-plugins/network/juniper/trapeze/snmp/mode/apusers.pm index f8e2b5192..8f0b0ed85 100644 --- a/centreon-plugins/network/juniper/trapeze/snmp/mode/apusers.pm +++ b/centreon-plugins/network/juniper/trapeze/snmp/mode/apusers.pm @@ -77,7 +77,6 @@ sub new { 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' }, diff --git a/centreon-plugins/network/juniper/trapeze/snmp/mode/cpu.pm b/centreon-plugins/network/juniper/trapeze/snmp/mode/cpu.pm index c28e6f3e9..bf65b9dc6 100644 --- a/centreon-plugins/network/juniper/trapeze/snmp/mode/cpu.pm +++ b/centreon-plugins/network/juniper/trapeze/snmp/mode/cpu.pm @@ -83,7 +83,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/juniper/trapeze/snmp/mode/memory.pm b/centreon-plugins/network/juniper/trapeze/snmp/mode/memory.pm index 2fd4b6e99..f9ec9c328 100644 --- a/centreon-plugins/network/juniper/trapeze/snmp/mode/memory.pm +++ b/centreon-plugins/network/juniper/trapeze/snmp/mode/memory.pm @@ -90,7 +90,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/kemp/snmp/mode/hastatus.pm b/centreon-plugins/network/kemp/snmp/mode/hastatus.pm index 60c03c8bf..648c1660a 100644 --- a/centreon-plugins/network/kemp/snmp/mode/hastatus.pm +++ b/centreon-plugins/network/kemp/snmp/mode/hastatus.pm @@ -88,7 +88,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-ha-status:s" => { name => 'warning_ha_status', default => '' }, diff --git a/centreon-plugins/network/kemp/snmp/mode/listvs.pm b/centreon-plugins/network/kemp/snmp/mode/listvs.pm index fcf1c84b7..7d6a9513d 100644 --- a/centreon-plugins/network/kemp/snmp/mode/listvs.pm +++ b/centreon-plugins/network/kemp/snmp/mode/listvs.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/kemp/snmp/mode/rsstatus.pm b/centreon-plugins/network/kemp/snmp/mode/rsstatus.pm index fb54eb895..69a70c7de 100644 --- a/centreon-plugins/network/kemp/snmp/mode/rsstatus.pm +++ b/centreon-plugins/network/kemp/snmp/mode/rsstatus.pm @@ -95,7 +95,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/kemp/snmp/mode/vsstatus.pm b/centreon-plugins/network/kemp/snmp/mode/vsstatus.pm index 1f04ad5d9..d7a6affb5 100644 --- a/centreon-plugins/network/kemp/snmp/mode/vsstatus.pm +++ b/centreon-plugins/network/kemp/snmp/mode/vsstatus.pm @@ -95,7 +95,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm b/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm index 0ced1876d..cad24f554 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm @@ -24,7 +24,7 @@ use strict; use warnings; my $mapping = { - mtxrHlTemperature => { oid => '.1.3.6.1.4.1.14988.1.1.3.10' }, + mtxrHlTemperature => { oid => '.1.3.6.1.4.1.14988.1.1.3.10' }, # SoC or PCB according to Mikrotik support mtxrHlProcessorTemperature => { oid => '.1.3.6.1.4.1.14988.1.1.3.11' }, }; @@ -43,12 +43,12 @@ sub check { if (defined($result->{mtxrHlTemperature}) && $result->{mtxrHlTemperature} =~ /[0-9]+/) { - $self->{output}->output_add(long_msg => sprintf("Temperature is '%s' C", $result->{mtxrHlTemperature} / 10)); + $self->{output}->output_add(long_msg => sprintf("System temperature (SoC or PCB) is '%s' C", $result->{mtxrHlTemperature} / 10)); ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => '1', value => $result->{mtxrHlTemperature} / 10); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Temperature is '%s' C", $result->{mtxrHlTemperature} / 10)); + short_msg => sprintf("System temperature (SoC or PCB) is '%s' C", $result->{mtxrHlTemperature} / 10)); } $self->{output}->perfdata_add( label => 'temperature', unit => 'C', diff --git a/centreon-plugins/network/mikrotik/snmp/mode/environment.pm b/centreon-plugins/network/mikrotik/snmp/mode/environment.pm index 3012ab166..54b7badd3 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/environment.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/environment.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/mikrotik/snmp/mode/listfrequencies.pm b/centreon-plugins/network/mikrotik/snmp/mode/listfrequencies.pm index f3be9772d..ff92ca5fa 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/listfrequencies.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/listfrequencies.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "oid-filter:s" => { name => 'oid_filter', default => 'ifname' }, diff --git a/centreon-plugins/network/mikrotik/snmp/mode/listssids.pm b/centreon-plugins/network/mikrotik/snmp/mode/listssids.pm index c1eed01d8..325a478d9 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/listssids.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/listssids.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "oid-filter:s" => { name => 'oid_filter', default => 'ifname' }, diff --git a/centreon-plugins/network/mikrotik/snmp/mode/signal.pm b/centreon-plugins/network/mikrotik/snmp/mode/signal.pm index 48710904a..f17fa4bb9 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/signal.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/signal.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "strength" => { name => "strength" }, diff --git a/centreon-plugins/network/mitel/3300icp/snmp/mode/licenses.pm b/centreon-plugins/network/mitel/3300icp/snmp/mode/licenses.pm index 5ba3c5991..cbd1e0779 100644 --- a/centreon-plugins/network/mitel/3300icp/snmp/mode/licenses.pm +++ b/centreon-plugins/network/mitel/3300icp/snmp/mode/licenses.pm @@ -95,7 +95,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/mitel/3300icp/snmp/mode/listzaps.pm b/centreon-plugins/network/mitel/3300icp/snmp/mode/listzaps.pm index 4f95b2a2f..f277b19d5 100644 --- a/centreon-plugins/network/mitel/3300icp/snmp/mode/listzaps.pm +++ b/centreon-plugins/network/mitel/3300icp/snmp/mode/listzaps.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/mitel/3300icp/snmp/mode/zapbandwidth.pm b/centreon-plugins/network/mitel/3300icp/snmp/mode/zapbandwidth.pm index 1fe09d7fb..63d10afa5 100644 --- a/centreon-plugins/network/mitel/3300icp/snmp/mode/zapbandwidth.pm +++ b/centreon-plugins/network/mitel/3300icp/snmp/mode/zapbandwidth.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/network/mitel/3300icp/snmp/mode/zapcalls.pm b/centreon-plugins/network/mitel/3300icp/snmp/mode/zapcalls.pm index 897082043..a70c000fa 100644 --- a/centreon-plugins/network/mitel/3300icp/snmp/mode/zapcalls.pm +++ b/centreon-plugins/network/mitel/3300icp/snmp/mode/zapcalls.pm @@ -75,7 +75,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/moxa/switch/snmp/mode/cpu.pm b/centreon-plugins/network/moxa/switch/snmp/mode/cpu.pm index 281e2cb96..de029af18 100644 --- a/centreon-plugins/network/moxa/switch/snmp/mode/cpu.pm +++ b/centreon-plugins/network/moxa/switch/snmp/mode/cpu.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/moxa/switch/snmp/mode/memory.pm b/centreon-plugins/network/moxa/switch/snmp/mode/memory.pm index 75474e2bc..3db2ed9e5 100644 --- a/centreon-plugins/network/moxa/switch/snmp/mode/memory.pm +++ b/centreon-plugins/network/moxa/switch/snmp/mode/memory.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/mrv/optiswitch/snmp/mode/environment.pm b/centreon-plugins/network/mrv/optiswitch/snmp/mode/environment.pm index 9bcdd0646..45ff0cce9 100644 --- a/centreon-plugins/network/mrv/optiswitch/snmp/mode/environment.pm +++ b/centreon-plugins/network/mrv/optiswitch/snmp/mode/environment.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/netgear/mseries/snmp/mode/cpu.pm b/centreon-plugins/network/netgear/mseries/snmp/mode/cpu.pm index 1f9d7b571..8c4100155 100644 --- a/centreon-plugins/network/netgear/mseries/snmp/mode/cpu.pm +++ b/centreon-plugins/network/netgear/mseries/snmp/mode/cpu.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/netgear/mseries/snmp/mode/hardware.pm b/centreon-plugins/network/netgear/mseries/snmp/mode/hardware.pm index 9203d52f9..9a29bee7c 100644 --- a/centreon-plugins/network/netgear/mseries/snmp/mode/hardware.pm +++ b/centreon-plugins/network/netgear/mseries/snmp/mode/hardware.pm @@ -70,7 +70,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/netgear/mseries/snmp/mode/memory.pm b/centreon-plugins/network/netgear/mseries/snmp/mode/memory.pm index 25d291f84..21aca1b4f 100644 --- a/centreon-plugins/network/netgear/mseries/snmp/mode/memory.pm +++ b/centreon-plugins/network/netgear/mseries/snmp/mode/memory.pm @@ -93,7 +93,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/bgpusage.pm b/centreon-plugins/network/nokia/timos/snmp/mode/bgpusage.pm index 6809ac5ed..7349b9578 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/bgpusage.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/bgpusage.pm @@ -98,7 +98,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/cpu.pm b/centreon-plugins/network/nokia/timos/snmp/mode/cpu.pm index acf8322ff..7b678d0a0 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/cpu.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/cpu.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/hardware.pm b/centreon-plugins/network/nokia/timos/snmp/mode/hardware.pm index 93bf0cb1d..6b80c161f 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/hardware.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/hardware.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); @@ -202,7 +201,7 @@ sub check { $result->{tmnxHwName}, $result->{tmnxHwTemperature})); } $self->{output}->perfdata_add( - label => 'temperature' . , unit => 'C', + label => 'temperature', unit => 'C', nlabel => 'hardware.entity.temperature.celsius', instances => $result->{tmnxHwName}, value => $result->{tmnxHwTemperature}, diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/isisusage.pm b/centreon-plugins/network/nokia/timos/snmp/mode/isisusage.pm index 8c05881ec..2501e0aa5 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/isisusage.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/isisusage.pm @@ -121,7 +121,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/l2tpusage.pm b/centreon-plugins/network/nokia/timos/snmp/mode/l2tpusage.pm index 752b5e4c8..b876cd0c4 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/l2tpusage.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/l2tpusage.pm @@ -178,7 +178,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-vrtr-name:s" => { name => 'filter_vrtr_name' }, diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/ldpusage.pm b/centreon-plugins/network/nokia/timos/snmp/mode/ldpusage.pm index 40dd46244..6941be18c 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/ldpusage.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/ldpusage.pm @@ -109,7 +109,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/listbgp.pm b/centreon-plugins/network/nokia/timos/snmp/mode/listbgp.pm index 64e8a6cae..2a06e94d2 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/listbgp.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/listbgp.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/listisis.pm b/centreon-plugins/network/nokia/timos/snmp/mode/listisis.pm index 14f41cee6..d9746fc9d 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/listisis.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/listisis.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/listldp.pm b/centreon-plugins/network/nokia/timos/snmp/mode/listldp.pm index 3e3b78c7d..c16dc63e9 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/listldp.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/listldp.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/listsap.pm b/centreon-plugins/network/nokia/timos/snmp/mode/listsap.pm index df776fc79..fa3960e95 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/listsap.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/listsap.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/listvrtr.pm b/centreon-plugins/network/nokia/timos/snmp/mode/listvrtr.pm index cebe294fe..9ff909947 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/listvrtr.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/listvrtr.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/memory.pm b/centreon-plugins/network/nokia/timos/snmp/mode/memory.pm index f2f930d3a..e1304bb26 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/memory.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/memory.pm @@ -93,7 +93,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/sapusage.pm b/centreon-plugins/network/nokia/timos/snmp/mode/sapusage.pm index 2048eecdf..d9ad8508d 100644 --- a/centreon-plugins/network/nokia/timos/snmp/mode/sapusage.pm +++ b/centreon-plugins/network/nokia/timos/snmp/mode/sapusage.pm @@ -113,7 +113,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm b/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm index 46082b15f..e7da01c67 100644 --- a/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm +++ b/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm @@ -83,7 +83,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/nortel/standard/snmp/mode/hardware.pm b/centreon-plugins/network/nortel/standard/snmp/mode/hardware.pm index fb774ba38..f3d9b868e 100644 --- a/centreon-plugins/network/nortel/standard/snmp/mode/hardware.pm +++ b/centreon-plugins/network/nortel/standard/snmp/mode/hardware.pm @@ -84,7 +84,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/nortel/standard/snmp/mode/memory.pm b/centreon-plugins/network/nortel/standard/snmp/mode/memory.pm index 0ed23a6e5..4de3cc4fc 100644 --- a/centreon-plugins/network/nortel/standard/snmp/mode/memory.pm +++ b/centreon-plugins/network/nortel/standard/snmp/mode/memory.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/oneaccess/snmp/mode/cpu.pm b/centreon-plugins/network/oneaccess/snmp/mode/cpu.pm index 25b3acdb4..ab51b0317 100644 --- a/centreon-plugins/network/oneaccess/snmp/mode/cpu.pm +++ b/centreon-plugins/network/oneaccess/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/oneaccess/snmp/mode/memory.pm b/centreon-plugins/network/oneaccess/snmp/mode/memory.pm index e68d40c61..9c4df5b1b 100644 --- a/centreon-plugins/network/oneaccess/snmp/mode/memory.pm +++ b/centreon-plugins/network/oneaccess/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/oracle/infiniband/snmp/mode/infinibandusage.pm b/centreon-plugins/network/oracle/infiniband/snmp/mode/infinibandusage.pm index 20dbe18e0..c165441ad 100644 --- a/centreon-plugins/network/oracle/infiniband/snmp/mode/infinibandusage.pm +++ b/centreon-plugins/network/oracle/infiniband/snmp/mode/infinibandusage.pm @@ -212,7 +212,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-ib-name:s" => { name => 'filter_ib_name' }, "filter-ibgw-name:s" => { name => 'filter_ibgw_name' }, diff --git a/centreon-plugins/network/oracle/infiniband/snmp/mode/listinfinibands.pm b/centreon-plugins/network/oracle/infiniband/snmp/mode/listinfinibands.pm index 09ae6c298..b2029eb5f 100644 --- a/centreon-plugins/network/oracle/infiniband/snmp/mode/listinfinibands.pm +++ b/centreon-plugins/network/oracle/infiniband/snmp/mode/listinfinibands.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-ib-name:s" => { name => 'filter_ib_name' }, diff --git a/centreon-plugins/network/oracle/otd/snmp/mode/listvservers.pm b/centreon-plugins/network/oracle/otd/snmp/mode/listvservers.pm index 628388394..0683602ef 100644 --- a/centreon-plugins/network/oracle/otd/snmp/mode/listvservers.pm +++ b/centreon-plugins/network/oracle/otd/snmp/mode/listvservers.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/oracle/otd/snmp/mode/vserverusage.pm b/centreon-plugins/network/oracle/otd/snmp/mode/vserverusage.pm index 93faa6447..dd68ef38e 100644 --- a/centreon-plugins/network/oracle/otd/snmp/mode/vserverusage.pm +++ b/centreon-plugins/network/oracle/otd/snmp/mode/vserverusage.pm @@ -80,7 +80,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/paloalto/snmp/mode/clusterstatus.pm b/centreon-plugins/network/paloalto/snmp/mode/clusterstatus.pm index 8c2277b53..13fc992a0 100644 --- a/centreon-plugins/network/paloalto/snmp/mode/clusterstatus.pm +++ b/centreon-plugins/network/paloalto/snmp/mode/clusterstatus.pm @@ -41,7 +41,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/network/paloalto/snmp/mode/panorama.pm b/centreon-plugins/network/paloalto/snmp/mode/panorama.pm index a747ed2f6..4b4edf86c 100644 --- a/centreon-plugins/network/paloalto/snmp/mode/panorama.pm +++ b/centreon-plugins/network/paloalto/snmp/mode/panorama.pm @@ -37,7 +37,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/network/peplink/balance/snmp/mode/cpu.pm b/centreon-plugins/network/peplink/balance/snmp/mode/cpu.pm index 28d6cc279..ef0a3d594 100644 --- a/centreon-plugins/network/peplink/balance/snmp/mode/cpu.pm +++ b/centreon-plugins/network/peplink/balance/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/peplink/balance/snmp/mode/memory.pm b/centreon-plugins/network/peplink/balance/snmp/mode/memory.pm index 9d3de922e..e16f4076a 100644 --- a/centreon-plugins/network/peplink/balance/snmp/mode/memory.pm +++ b/centreon-plugins/network/peplink/balance/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/peplink/pepwave/snmp/mode/cpu.pm b/centreon-plugins/network/peplink/pepwave/snmp/mode/cpu.pm index c32d575ec..ef0ec9b23 100644 --- a/centreon-plugins/network/peplink/pepwave/snmp/mode/cpu.pm +++ b/centreon-plugins/network/peplink/pepwave/snmp/mode/cpu.pm @@ -48,7 +48,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/peplink/pepwave/snmp/mode/memory.pm b/centreon-plugins/network/peplink/pepwave/snmp/mode/memory.pm index 4585b1951..9881408a6 100644 --- a/centreon-plugins/network/peplink/pepwave/snmp/mode/memory.pm +++ b/centreon-plugins/network/peplink/pepwave/snmp/mode/memory.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/peplink/pepwave/snmp/mode/wanusage.pm b/centreon-plugins/network/peplink/pepwave/snmp/mode/wanusage.pm index 521196154..180822302 100644 --- a/centreon-plugins/network/peplink/pepwave/snmp/mode/wanusage.pm +++ b/centreon-plugins/network/peplink/pepwave/snmp/mode/wanusage.pm @@ -101,7 +101,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-health-status:s" => { name => 'warning_health_status', default => '' }, diff --git a/centreon-plugins/network/perle/ids/snmp/mode/alarms.pm b/centreon-plugins/network/perle/ids/snmp/mode/alarms.pm new file mode 100644 index 000000000..71b7adf74 --- /dev/null +++ b/centreon-plugins/network/perle/ids/snmp/mode/alarms.pm @@ -0,0 +1,193 @@ +# +# Copyright 2018 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::perle::ids::snmp::mode::alarms; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use POSIX; +use centreon::plugins::misc; +use centreon::plugins::statefile; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("alarm [severity: %s] [source: %s] [text: %s] %s", $self->{result_values}->{severity}, + $self->{result_values}->{source}, $self->{result_values}->{text}, $self->{result_values}->{generation_time}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{source} = $options{new_datas}->{$self->{instance} . '_perleEntityAlarmSourceName'}; + $self->{result_values}->{text} = $options{new_datas}->{$self->{instance} . '_perleEntityAlarmDescr'}; + $self->{result_values}->{severity} = $options{new_datas}->{$self->{instance} . '_perleEntityAlarmSeverity'}; + $self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'}; + $self->{result_values}->{generation_time} = $options{new_datas}->{$self->{instance} . '_perleEntityAlarmTimeStamp'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, + group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] + } + ]; + + $self->{maps_counters}->{alarm} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'perleEntityAlarmDescr' }, { name => 'perleEntityAlarmSeverity' }, { name => 'perleEntityAlarmTimeStamp' }, + { name => 'since' }, { name => 'perleEntityAlarmSourceName' }, { name => 'perleEntityAlarmType' } ], + 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 => \&catalog_status_threshold, + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-msg:s' => { name => 'filter_msg' }, + 'warning-status:s' => { name => 'warning_status', default => '%{severity} =~ /minor/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{severity} =~ /critical|major/i' }, + 'memory' => { name => 'memory' }, + }); + + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->check_options(%options); + } +} + +my %map_severity = ( + 1 => 'critical', + 2 => 'major', + 3 => 'minor', + 4 => 'info', +); + +my $mapping = { + perleEntityAlarmSourceName => { oid => '.1.3.6.1.4.1.1966.22.11.1.1.1.3' }, + perleEntityAlarmSeverity => { oid => '.1.3.6.1.4.1.1966.22.11.1.1.1.4', map => \%map_severity }, + perleEntityAlarmDescr => { oid => '.1.3.6.1.4.1.1966.22.11.1.1.1.5' }, + perleEntityAlarmTimeStamp => { oid => '.1.3.6.1.4.1.1966.22.11.1.1.1.6' }, +}; +my $oid_perleEntityAlarmEntry = '.1.3.6.1.4.1.1966.22.11.1.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{alarms}->{global} = { alarm => {} }; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_perleEntityAlarmEntry, + start => $mapping->{perleEntityAlarmSourceName}->{oid}, + end => $mapping->{perleEntityAlarmDescr}->{oid} + ); + + my $last_time; + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->read(statefile => "cache_perle_ids_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port(). '_' . $self->{mode}); + $last_time = $self->{statefile_cache}->get(name => 'last_time'); + } + + my ($i, $current_time) = (1, time()); + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{perleEntityAlarmSeverity}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + my $create_time = $result->{perleEntityAlarmTimeStamp}; + $result->{perleEntityAlarmTimeStamp} = strftime("%d/%m/%Y %H:%M:%S", localtime($result->{perleEntityAlarmTimeStamp})); + if (!defined($create_time)) { + $self->{manager}->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Can't get date '" . $create_time . "'" + ); + next; + } + + next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $create_time); + if (defined($self->{option_results}->{filter_msg}) && $self->{option_results}->{filter_msg} ne '' && + $result->{radwllMilOduAgnLastEventsText} !~ /$self->{option_results}->{perleEntityAlarmDescr}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{radwllMilOduAgnLastEventsText} . "': no matching filter.", debug => 1); + next; + } + + my $diff_time = $current_time - $create_time; + $self->{alarms}->{global}->{alarm}->{$i} = { %$result, since => $diff_time }; + $i++; + } + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->write(data => { last_time => $current_time }); + } +} + +1; + +__END__ + +=head1 MODE + +Check alarms. + +=over 8 + +=item B<--filter-msg> + +Filter by message (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{severity} =~ /minor/i') +Can used special variables like: %{severity}, %{text}, %{source}, %{since} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{severity} =~ /critical|major/i'). +Can used special variables like: %{severity}, %{text}, %{source}, %{since} + +=item B<--memory> + +Only check new alarms. + +=back + +=cut diff --git a/centreon-plugins/network/perle/ids/snmp/mode/components/psu.pm b/centreon-plugins/network/perle/ids/snmp/mode/components/psu.pm new file mode 100644 index 000000000..fbafdfec8 --- /dev/null +++ b/centreon-plugins/network/perle/ids/snmp/mode/components/psu.pm @@ -0,0 +1,70 @@ +# +# Copyright 2019 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::perle::ids::snmp::mode::components::psu; + +use strict; +use warnings; +use network::perle::ids::snmp::mode::components::resources qw($map_status); + +my $mapping = { + perleEnvMonPowerSupplyStatusDescr => { oid => '.1.3.6.1.4.1.1966.22.12.1.1.1.2' }, + perleEnvMonPowerSupplyState => { oid => '.1.3.6.1.4.1.1966.22.12.1.1.1.3', map => $map_status }, +}; +my $oid_perleEnvMonPowerSupplyStatusEntry = '.1.3.6.1.4.1.1966.22.12.1.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_perleEnvMonPowerSupplyStatusEntry, + start => $mapping->{perleEnvMonPowerSupplyStatusDescr}->{oid}, + end => $mapping->{perleEnvMonPowerSupplyState}->{oid}, + }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'psu')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_perleEnvMonPowerSupplyStatusEntry}})) { + next if ($oid !~ /^$mapping->{perleEnvMonPowerSupplyState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_perleEnvMonPowerSupplyStatusEntry}, instance => $instance); + + next if ($self->check_filter(section => 'psu', instance => $instance, name => $result->{perleEnvMonPowerSupplyStatusDescr})); + next if ($result->{perleEnvMonPowerSupplyState} =~ /notPresent/i && + $self->absent_problem(section => 'psu', instance => $instance, name => $result->{perleEnvMonPowerSupplyStatusDescr})); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance = %s]", + $result->{perleEnvMonPowerSupplyStatusDescr}, $result->{perleEnvMonPowerSupplyState}, $instance)); + my $exit = $self->get_severity(label => 'default', section => 'psu', name => $result->{perleEnvMonPowerSupplyStatusDescr}, value => $result->{perleEnvMonPowerSupplyState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' status is '%s'", $result->{perleEnvMonPowerSupplyStatusDescr}, $result->{perleEnvMonPowerSupplyState})); + } + } +} + +1; diff --git a/centreon-plugins/network/perle/ids/snmp/mode/components/resources.pm b/centreon-plugins/network/perle/ids/snmp/mode/components/resources.pm new file mode 100644 index 000000000..ea898b0de --- /dev/null +++ b/centreon-plugins/network/perle/ids/snmp/mode/components/resources.pm @@ -0,0 +1,37 @@ +# +# Copyright 2019 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::perle::ids::snmp::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our $map_status; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw($map_status); + +$map_status = { + 1 => 'normal', 2 => 'warning', 3 => 'critical', + 4 => 'shutdown', 5 => 'notPresent', 6 => 'notFunctioning', +}; + +1; diff --git a/centreon-plugins/network/perle/ids/snmp/mode/components/temperature.pm b/centreon-plugins/network/perle/ids/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..166f0c6e1 --- /dev/null +++ b/centreon-plugins/network/perle/ids/snmp/mode/components/temperature.pm @@ -0,0 +1,83 @@ +# +# Copyright 2019 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::perle::ids::snmp::mode::components::temperature; + +use strict; +use warnings; +use network::perle::ids::snmp::mode::components::resources qw($map_status); + +my $mapping = { + perleEnvMonTemperatureStatusDescr => { oid => '.1.3.6.1.4.1.1966.22.12.1.2.1.2' }, + perleEnvMonTemperatureStatusValue => { oid => '.1.3.6.1.4.1.1966.22.12.1.2.1.3' }, + perleEnvMonTemperatureState => { oid => '.1.3.6.1.4.1.1966.22.12.1.2.1.5', map => $map_status }, +}; +my $oid_perleEnvMonTemperatureStatusEntry = '.1.3.6.1.4.1.1966.22.12.1.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_perleEnvMonTemperatureStatusEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'temperature')); + + my ($exit, $warn, $crit, $checked); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_perleEnvMonTemperatureStatusEntry}})) { + next if ($oid !~ /^$mapping->{perleEnvMonTemperatureState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_perleEnvMonTemperatureStatusEntry}, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance, name => $result->{perleEnvMonTemperatureStatusDescr})); + next if ($result->{perleEnvMonTemperatureState} =~ /notPresent/i && + $self->absent_problem(section => 'temperature', instance => $instance, name => $result->{perleEnvMonTemperatureStatusDescr})); + + $self->{components}->{temperature}->{total}++; + $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is '%s' [instance = %s, value = %s]", + $result->{perleEnvMonTemperatureStatusDescr}, $result->{perleEnvMonTemperatureState}, $instance, + $result->{perleEnvMonTemperatureStatusValue})); + $exit = $self->get_severity(label => 'default', section => 'temperature', value => $result->{perleEnvMonTemperatureState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' status is '%s'", $result->{perleEnvMonTemperatureStatusDescr}, $result->{perleEnvMonTemperatureState})); + } + + ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, name => $result->{perleEnvMonTemperatureStatusDescr}, value => $result->{perleEnvMonTemperatureStatusValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' is '%s' C", $result->{perleEnvMonTemperatureStatusDescr}, $result->{perleEnvMonTemperatureStatusValue})); + } + $self->{output}->perfdata_add( + label => 'temperature', unit => 'C', + nlabel => 'hardware.temperature.celsius', + instances => $result->{perleEnvMonTemperatureStatusDescr}, + value => $result->{perleEnvMonTemperatureStatusValue}, + warning => $warn, + critical => $crit + ); + } +} + +1; diff --git a/centreon-plugins/network/perle/ids/snmp/mode/hardware.pm b/centreon-plugins/network/perle/ids/snmp/mode/hardware.pm new file mode 100644 index 000000000..82bbdf105 --- /dev/null +++ b/centreon-plugins/network/perle/ids/snmp/mode/hardware.pm @@ -0,0 +1,119 @@ +# +# Copyright 2019 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::perle::ids::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(temperature|psu)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature)$'; + + $self->{cb_hook2} = 'snmp_execute'; + $self->{thresholds} = { + default => [ + ['normal', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['shutdown', 'CRITICAL'], + ['notPresent', 'OK'], + ['notFunctioning', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'network::perle::ids::snmp::mode::components'; + $self->{components_module} = ['temperature', 'psu']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'temperature', 'psu'. + +=item B<--add-name-instance> + +Add literal description for instance value (used in filter, absent-problem and threshold options). + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=psu,1 + +=item B<--absent-problem> + +Return an error if an entity is not 'present' (default is skipping) (comma seperated list) +Can be specific or global: --absent-problem=psu,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,CRITICAL,^(?!(normal|initial)$)' + +=item B<--warning> + +Set warning threshold for 'temperature' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,40' + +=item B<--critical> + +Set critical threshold for 'temperature' (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,50' + +=back + +=cut diff --git a/centreon-plugins/network/perle/ids/snmp/mode/systemusage.pm b/centreon-plugins/network/perle/ids/snmp/mode/systemusage.pm new file mode 100644 index 000000000..856859df2 --- /dev/null +++ b/centreon-plugins/network/perle/ids/snmp/mode/systemusage.pm @@ -0,0 +1,125 @@ +# +# Copyright 2019 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::perle::ids::snmp::mode::systemusage; + +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, message_separator => ' - ' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'cpu-load', nlabel => 'cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu_load' } ], + output_template => 'cpu load : %.2f %%', + perfdatas => [ + { value => 'cpu_load_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'memory-free', nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'memory_free' } ], + output_template => 'memory free : %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'memory_free_absolute', template => '%d', + min => 0, unit => 'B' }, + ], + } + }, + { label => 'flashdisk-free', nlabel => 'flashdisk.free.bytes', set => { + key_values => [ { name => 'flashdisk_free' } ], + output_template => 'flash disk free : %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'flashdisk_free_absolute', template => '%d', + min => 0, unit => 'B' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_perleAverageCPUUtilization = '.1.3.6.1.4.1.1966.22.44.1.24.0'; + my $oid_perleMemory = '.1.3.6.1.4.1.1966.22.44.1.25.0'; # 295928 Kbytes free + my $oid_perleFlashdisk = '.1.3.6.1.4.1.1966.22.44.1.26.0'; + my $result = $options{snmp}->get_leef( + oids => [ + $oid_perleAverageCPUUtilization, $oid_perleMemory, $oid_perleFlashdisk + ], + nothing_quit => 1 + ); + + my ($cpu_load, $mem_free, $flashdisk_free); + $cpu_load = $1 + if (defined($result->{$oid_perleAverageCPUUtilization}) && $result->{$oid_perleAverageCPUUtilization} =~ /((?:\d+)(?:\.\d+)?)/); + $mem_free = $1 * 1024 if (defined($result->{$oid_perleMemory}) && $result->{$oid_perleMemory} =~ /(\d+)/); + $flashdisk_free = $1 * 1024 if (defined($result->{$oid_perleFlashdisk}) && $result->{$oid_perleFlashdisk} =~ /(\d+)/); + $self->{global} = { + cpu_load => $cpu_load, + memory_free => $mem_free, + flashdisk_free => $flashdisk_free, + }; +} + +1; + +__END__ + +=head1 MODE + +Check system usage. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^memory-free$' + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'memory-free' (B), 'cpu-load' (%), 'flashdisk-free' (B) + +=back + +=cut diff --git a/centreon-plugins/network/perle/ids/snmp/plugin.pm b/centreon-plugins/network/perle/ids/snmp/plugin.pm new file mode 100644 index 000000000..e131fb9db --- /dev/null +++ b/centreon-plugins/network/perle/ids/snmp/plugin.pm @@ -0,0 +1,52 @@ +# +# Copyright 2019 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::perle::ids::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}} = ( + 'alarms' => 'network::perle::ids::snmp::mode::alarms', + 'hardware' => 'network::perle::ids::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'system-usage' => 'network::perle::ids::snmp::mode::systemusage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Perle IDS (200, 300, 400) in SNMP. + +=cut diff --git a/centreon-plugins/network/polycom/rmx/snmp/mode/hardware.pm b/centreon-plugins/network/polycom/rmx/snmp/mode/hardware.pm index 2475d9028..c630db7d6 100644 --- a/centreon-plugins/network/polycom/rmx/snmp/mode/hardware.pm +++ b/centreon-plugins/network/polycom/rmx/snmp/mode/hardware.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/polycom/rmx/snmp/mode/videoconferencingusage.pm b/centreon-plugins/network/polycom/rmx/snmp/mode/videoconferencingusage.pm index dbb576abd..e7913b5d2 100644 --- a/centreon-plugins/network/polycom/rmx/snmp/mode/videoconferencingusage.pm +++ b/centreon-plugins/network/polycom/rmx/snmp/mode/videoconferencingusage.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/rad/airmux/snmp/mode/alarms.pm b/centreon-plugins/network/rad/airmux/snmp/mode/alarms.pm index 096db6bc0..a8faeb290 100644 --- a/centreon-plugins/network/rad/airmux/snmp/mode/alarms.pm +++ b/centreon-plugins/network/rad/airmux/snmp/mode/alarms.pm @@ -75,16 +75,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter-msg:s" => { name => 'filter_msg' }, - "warning-status:s" => { name => 'warning_status', default => '%{severity} =~ /minor|warning/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{severity} =~ /critical|major/i' }, - "memory" => { name => 'memory' }, + 'filter-msg:s' => { name => 'filter_msg' }, + 'warning-status:s' => { name => 'warning_status', default => '%{severity} =~ /minor|warning/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{severity} =~ /critical|major/i' }, + 'memory' => { name => 'memory' }, }); - - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Date::Parse', - error_msg => "Cannot load module 'Date::Parse'."); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); return $self; } @@ -132,8 +129,8 @@ sub manage_selection { my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - my $create_time = $result->{radwllMilOduAgnLastEventsTimeT}; - $result->{radwllMilOduAgnLastEventsTimeT} = strftime("%d/%m/%Y %H:%M:%S",localtime($result->{radwllMilOduAgnLastEventsTimeT})); + my $create_time = $result->{radwllMilOduAgnLastEventsTimeT}; + $result->{radwllMilOduAgnLastEventsTimeT} = strftime("%d/%m/%Y %H:%M:%S", localtime($result->{radwllMilOduAgnLastEventsTimeT})); if (!defined($create_time)) { $self->{manager}->{output}->output_add(severity => 'UNKNOWN', short_msg => "Can't get date '" . $result->{radwllMilOduAgnLastEventsTimeT} . "'"); diff --git a/centreon-plugins/network/rad/airmux/snmp/mode/radiostatus.pm b/centreon-plugins/network/rad/airmux/snmp/mode/radiostatus.pm index 5e56eb0a3..a0bf32336 100644 --- a/centreon-plugins/network/rad/airmux/snmp/mode/radiostatus.pm +++ b/centreon-plugins/network/rad/airmux/snmp/mode/radiostatus.pm @@ -80,7 +80,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/radware/alteon/snmp/mode/cpu.pm b/centreon-plugins/network/radware/alteon/snmp/mode/cpu.pm index fd32a8b5f..4d748dd4f 100644 --- a/centreon-plugins/network/radware/alteon/snmp/mode/cpu.pm +++ b/centreon-plugins/network/radware/alteon/snmp/mode/cpu.pm @@ -148,7 +148,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/radware/alteon/snmp/mode/hardware.pm b/centreon-plugins/network/radware/alteon/snmp/mode/hardware.pm index 40555ec55..796547183 100644 --- a/centreon-plugins/network/radware/alteon/snmp/mode/hardware.pm +++ b/centreon-plugins/network/radware/alteon/snmp/mode/hardware.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/radware/alteon/snmp/mode/listvservers.pm b/centreon-plugins/network/radware/alteon/snmp/mode/listvservers.pm index d2e5e2b62..6ed28b2f2 100644 --- a/centreon-plugins/network/radware/alteon/snmp/mode/listvservers.pm +++ b/centreon-plugins/network/radware/alteon/snmp/mode/listvservers.pm @@ -40,7 +40,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/radware/alteon/snmp/mode/memory.pm b/centreon-plugins/network/radware/alteon/snmp/mode/memory.pm index d24c3d248..3e293d183 100644 --- a/centreon-plugins/network/radware/alteon/snmp/mode/memory.pm +++ b/centreon-plugins/network/radware/alteon/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/radware/alteon/snmp/mode/vserverstatus.pm b/centreon-plugins/network/radware/alteon/snmp/mode/vserverstatus.pm index 18d2cb2ef..3041796f6 100644 --- a/centreon-plugins/network/radware/alteon/snmp/mode/vserverstatus.pm +++ b/centreon-plugins/network/radware/alteon/snmp/mode/vserverstatus.pm @@ -100,7 +100,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/raisecom/snmp/mode/cpu.pm b/centreon-plugins/network/raisecom/snmp/mode/cpu.pm index 345cddc42..038fa04e6 100644 --- a/centreon-plugins/network/raisecom/snmp/mode/cpu.pm +++ b/centreon-plugins/network/raisecom/snmp/mode/cpu.pm @@ -83,7 +83,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/raisecom/snmp/mode/hardware.pm b/centreon-plugins/network/raisecom/snmp/mode/hardware.pm index 9ad854e32..228e54e4a 100644 --- a/centreon-plugins/network/raisecom/snmp/mode/hardware.pm +++ b/centreon-plugins/network/raisecom/snmp/mode/hardware.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/raisecom/snmp/mode/memory.pm b/centreon-plugins/network/raisecom/snmp/mode/memory.pm index fb3b435be..2d4c8991c 100644 --- a/centreon-plugins/network/raisecom/snmp/mode/memory.pm +++ b/centreon-plugins/network/raisecom/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/redback/snmp/mode/cpu.pm b/centreon-plugins/network/redback/snmp/mode/cpu.pm index 4d9a38562..12fad1cf9 100644 --- a/centreon-plugins/network/redback/snmp/mode/cpu.pm +++ b/centreon-plugins/network/redback/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '' }, diff --git a/centreon-plugins/network/redback/snmp/mode/disk.pm b/centreon-plugins/network/redback/snmp/mode/disk.pm index 99d682cd0..0209ebb1e 100644 --- a/centreon-plugins/network/redback/snmp/mode/disk.pm +++ b/centreon-plugins/network/redback/snmp/mode/disk.pm @@ -101,7 +101,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/network/redback/snmp/mode/hardware.pm b/centreon-plugins/network/redback/snmp/mode/hardware.pm index 47e0d2f77..ccd7ebdc4 100644 --- a/centreon-plugins/network/redback/snmp/mode/hardware.pm +++ b/centreon-plugins/network/redback/snmp/mode/hardware.pm @@ -69,7 +69,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/redback/snmp/mode/memory.pm b/centreon-plugins/network/redback/snmp/mode/memory.pm index 2d524f79c..5f29c89dd 100644 --- a/centreon-plugins/network/redback/snmp/mode/memory.pm +++ b/centreon-plugins/network/redback/snmp/mode/memory.pm @@ -101,7 +101,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/riverbed/interceptor/snmp/mode/neighborconnections.pm b/centreon-plugins/network/riverbed/interceptor/snmp/mode/neighborconnections.pm index 9ed4794ce..97d0469ed 100644 --- a/centreon-plugins/network/riverbed/interceptor/snmp/mode/neighborconnections.pm +++ b/centreon-plugins/network/riverbed/interceptor/snmp/mode/neighborconnections.pm @@ -57,7 +57,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; $options{options}->add_options(arguments => { }); return $self; diff --git a/centreon-plugins/network/ruckus/ap/snmp/mode/cpu.pm b/centreon-plugins/network/ruckus/ap/snmp/mode/cpu.pm index 93a2864e1..3662709cd 100644 --- a/centreon-plugins/network/ruckus/ap/snmp/mode/cpu.pm +++ b/centreon-plugins/network/ruckus/ap/snmp/mode/cpu.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/ruckus/ap/snmp/mode/memory.pm b/centreon-plugins/network/ruckus/ap/snmp/mode/memory.pm index 3bd175edc..b11aee485 100644 --- a/centreon-plugins/network/ruckus/ap/snmp/mode/memory.pm +++ b/centreon-plugins/network/ruckus/ap/snmp/mode/memory.pm @@ -105,7 +105,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/ruckus/ap/snmp/mode/users.pm b/centreon-plugins/network/ruckus/ap/snmp/mode/users.pm index 2b44bdf0d..850c94e08 100644 --- a/centreon-plugins/network/ruckus/ap/snmp/mode/users.pm +++ b/centreon-plugins/network/ruckus/ap/snmp/mode/users.pm @@ -125,11 +125,9 @@ sub new { 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' }, - }); + $options{options}->add_options(arguments => { + 'filter-ssid:s' => { name => 'filter_ssid' }, + }); return $self; } @@ -161,7 +159,13 @@ sub manage_selection { $self->{global}->{total} = 0 if ($self->{global}->{total} == -1); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - + + if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' && + $result->{ruckusWLANStatsSSID} !~ /$self->{option_results}->{filter_ssid}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{ruckusWLANStatsSSID} . "': no matching filter.", debug => 1); + next; + } + $self->{ssid}->{$result->{ruckusWLANStatsSSID}} = { display => $result->{ruckusWLANStatsSSID}, total => $result->{ruckusWLANStatsNumSta} }; $self->{global}->{total} += $result->{ruckusWLANStatsNumSta}; } diff --git a/centreon-plugins/network/ruckus/scg/snmp/mode/apstatus.pm b/centreon-plugins/network/ruckus/scg/snmp/mode/apstatus.pm index a293e7d86..192ccc336 100644 --- a/centreon-plugins/network/ruckus/scg/snmp/mode/apstatus.pm +++ b/centreon-plugins/network/ruckus/scg/snmp/mode/apstatus.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/ruckus/scg/snmp/mode/apusage.pm b/centreon-plugins/network/ruckus/scg/snmp/mode/apusage.pm index 1e96fe958..a60ce00e8 100644 --- a/centreon-plugins/network/ruckus/scg/snmp/mode/apusage.pm +++ b/centreon-plugins/network/ruckus/scg/snmp/mode/apusage.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/ruckus/scg/snmp/mode/listaps.pm b/centreon-plugins/network/ruckus/scg/snmp/mode/listaps.pm index 78fbc8790..2d7c1d38c 100644 --- a/centreon-plugins/network/ruckus/scg/snmp/mode/listaps.pm +++ b/centreon-plugins/network/ruckus/scg/snmp/mode/listaps.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/ruckus/scg/snmp/mode/listssids.pm b/centreon-plugins/network/ruckus/scg/snmp/mode/listssids.pm index 71b095b1b..0848d33f5 100644 --- a/centreon-plugins/network/ruckus/scg/snmp/mode/listssids.pm +++ b/centreon-plugins/network/ruckus/scg/snmp/mode/listssids.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/ruckus/scg/snmp/mode/ssidusage.pm b/centreon-plugins/network/ruckus/scg/snmp/mode/ssidusage.pm index e5060106d..f72565937 100644 --- a/centreon-plugins/network/ruckus/scg/snmp/mode/ssidusage.pm +++ b/centreon-plugins/network/ruckus/scg/snmp/mode/ssidusage.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/ruckus/scg/snmp/mode/systemstats.pm b/centreon-plugins/network/ruckus/scg/snmp/mode/systemstats.pm index 4eaeda060..7d987b168 100644 --- a/centreon-plugins/network/ruckus/scg/snmp/mode/systemstats.pm +++ b/centreon-plugins/network/ruckus/scg/snmp/mode/systemstats.pm @@ -140,7 +140,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/ruggedcom/mode/components/fan.pm b/centreon-plugins/network/ruggedcom/mode/components/fan.pm new file mode 100644 index 000000000..7a2134beb --- /dev/null +++ b/centreon-plugins/network/ruggedcom/mode/components/fan.pm @@ -0,0 +1,73 @@ +# +# Copyright 2019 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::ruggedcom::mode::components::fan; + +use strict; +use warnings; + +my %map_states_fan = ( + 1 => 'notPresent', + 2 => 'failed', + 3 => 'standby', + 4 => 'off', + 5 => 'on', +); + +my $oid_rcDeviceStsFanBank1_entry = '.1.3.6.1.4.1.15004.4.2.2.10'; +my $oid_rcDeviceStsFanBank1 = '.1.3.6.1.4.1.15004.4.2.2.10.0'; +my $oid_rcDeviceStsFanBank2_entry = '.1.3.6.1.4.1.15004.4.2.2.11'; +my $oid_rcDeviceStsFanBank2 = '.1.3.6.1.4.1.15004.4.2.2.11.0'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_rcDeviceStsFanBank1_entry }, { oid => $oid_rcDeviceStsFanBank2_entry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking fans"); + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; + return if ($self->check_filter(section => 'fan')); + + my $instance = 0; + foreach my $value (($self->{results}->{$oid_rcDeviceStsFanBank1}, $self->{results}->{$oid_rcDeviceStsFanBank2})) { + $instance++; + next if (!defined($value)); + my $fan_state = $value; + + next if ($self->check_filter(section => 'fan', instance => $instance)); + next if ($map_states_fan{$fan_state} eq 'notPresent' && + $self->absent_problem(section => 'fan', instance => $instance)); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fan Bank '%s' state is %s.", + $instance, $map_states_fan{$fan_state})); + my $exit = $self->get_severity(section => 'fan', value => $map_states_fan{$fan_state}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan Bank '%s' state is %s.", $instance, $map_states_fan{$fan_state})); + } + } +} + +1; diff --git a/centreon-plugins/network/ruggedcom/mode/components/psu.pm b/centreon-plugins/network/ruggedcom/mode/components/psu.pm new file mode 100644 index 000000000..8ff414f94 --- /dev/null +++ b/centreon-plugins/network/ruggedcom/mode/components/psu.pm @@ -0,0 +1,73 @@ +# +# Copyright 2019 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::ruggedcom::mode::components::psu; + +use strict; +use warnings; + +my %map_states_psu = ( + 1 => 'notPresent', + 2 => 'functional', + 3 => 'notFunctional', + 4 => 'notConnected', +); + +my $oid_rcDeviceStsPowerSupply1_entry = '.1.3.6.1.4.1.15004.4.2.2.4'; +my $oid_rcDeviceStsPowerSupply1 = '.1.3.6.1.4.1.15004.4.2.2.4.0'; +my $oid_rcDeviceStsPowerSupply2_entry = '.1.3.6.1.4.1.15004.4.2.2.5'; +my $oid_rcDeviceStsPowerSupply2 = '.1.3.6.1.4.1.15004.4.2.2.5.0'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_rcDeviceStsPowerSupply1_entry }, { oid => $oid_rcDeviceStsPowerSupply2_entry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + my $instance = 0; + foreach my $value (($self->{results}->{$oid_rcDeviceStsPowerSupply1}, $self->{results}->{$oid_rcDeviceStsPowerSupply2})) { + $instance++; + next if (!defined($value)); + my $psu_state = $value; + + next if ($self->check_filter(section => 'psu', instance => $instance)); + next if ($map_states_psu{$psu_state} eq 'notPresent' && + $self->absent_problem(section => 'psu', instance => $instance)); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' state is %s.", + $instance, $map_states_psu{$psu_state})); + my $exit = $self->get_severity(section => 'psu', value => $map_states_psu{$psu_state}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power Supply '%s' state is %s.", $instance, $map_states_psu{$psu_state})); + } + } +} + + +1; diff --git a/centreon-plugins/network/ruggedcom/mode/errors.pm b/centreon-plugins/network/ruggedcom/mode/errors.pm index e5a152287..c6fbdcc52 100644 --- a/centreon-plugins/network/ruggedcom/mode/errors.pm +++ b/centreon-plugins/network/ruggedcom/mode/errors.pm @@ -58,7 +58,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "exclude:s" => { name => 'exclude' }, diff --git a/centreon-plugins/network/ruggedcom/mode/hardware.pm b/centreon-plugins/network/ruggedcom/mode/hardware.pm index ace2164ff..1cbf5c353 100644 --- a/centreon-plugins/network/ruggedcom/mode/hardware.pm +++ b/centreon-plugins/network/ruggedcom/mode/hardware.pm @@ -20,284 +20,80 @@ package network::ruggedcom::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; +use centreon::plugins::misc; -my $oid_rcDeviceStsPowerSupply1_entry = '.1.3.6.1.4.1.15004.4.2.2.4'; -my $oid_rcDeviceStsPowerSupply1 = '.1.3.6.1.4.1.15004.4.2.2.4.0'; -my $oid_rcDeviceStsPowerSupply2_entry = '.1.3.6.1.4.1.15004.4.2.2.5'; -my $oid_rcDeviceStsPowerSupply2 = '.1.3.6.1.4.1.15004.4.2.2.5.0'; -my $oid_rcDeviceStsFanBank1_entry = '.1.3.6.1.4.1.15004.4.2.2.10'; -my $oid_rcDeviceStsFanBank1 = '.1.3.6.1.4.1.15004.4.2.2.10.0'; -my $oid_rcDeviceStsFanBank2_entry = '.1.3.6.1.4.1.15004.4.2.2.11'; -my $oid_rcDeviceStsFanBank2 = '.1.3.6.1.4.1.15004.4.2.2.11.0'; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^psu|fan$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + psu => [ + ['notPresent', 'OK'], + ['functional', 'OK'], + ['notFunctional', 'CRITICAL'], + ['notConnected', 'WARNING'], + ], + fan => [ + ['notPresent', 'OK'], + ['failed', 'CRITICAL'], + ['standby', 'OK'], + ['on', 'OK'], + ['off', 'WARNING'], + ], + }; + + $self->{components_path} = 'network::ruggedcom::mode::components'; + $self->{components_module} = ['psu', 'fan']; +} -my $thresholds = { - psu => [ - ['notPresent', 'OK'], - ['functional', 'OK'], - ['notFunctional', 'CRITICAL'], - ['notConnected', 'WARNING'], - ], - fan => [ - ['notPresent', 'OK'], - ['failed', 'CRITICAL'], - ['standby', 'OK'], - ['on', 'OK'], - ['off', 'WARNING'], - ], -}; +sub snmp_execute { + my ($self, %options) = @_; -my %map_states_fan = ( - 1 => 'notPresent', - 2 => 'failed', - 3 => 'standby', - 4 => 'off', - 5 => 'on', -); - -my %map_states_psu = ( - 1 => 'notPresent', - 2 => 'functional', - 3 => 'notFunctional', - 4 => 'notConnected', -); + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "absent-problem:s" => { name => 'absent' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => {}); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - # There is a bug with get_leef and snmpv1. - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_rcDeviceStsPowerSupply1_entry }, - { oid => $oid_rcDeviceStsPowerSupply2_entry }, - { oid => $oid_rcDeviceStsFanBank1_entry }, - { oid => $oid_rcDeviceStsFanBank2_entry }, - ], - return_type => 1); - - if ($self->{option_results}->{component} eq 'all') { - $self->check_fan(); - $self->check_psu(); - } elsif ($self->{option_results}->{component} eq 'fan') { - $self->check_fan(); - } elsif ($self->{option_results}->{component} eq 'psu') { - $self->check_psu(); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub absent_problem { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{absent}) && - $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Component '%s' instance '%s' is not present", - $options{section}, $options{instance})); - } - - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)")); - $self->{components}->{$options{section}}->{skip}++; - return 1; -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - -sub check_fan { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking fans"); - $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fan')); - - my $instance = 0; - foreach my $value (($self->{results}->{$oid_rcDeviceStsFanBank1}, $self->{results}->{$oid_rcDeviceStsFanBank2})) { - $instance++; - next if (!defined($value)); - my $fan_state = $value; - - next if ($self->check_exclude(section => 'fan', instance => $instance)); - next if ($map_states_fan{$fan_state} eq 'notPresent' && - $self->absent_problem(section => 'fan', instance => $instance)); - - $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan Bank '%s' state is %s.", - $instance, $map_states_fan{$fan_state})); - my $exit = $self->get_severity(section => 'fan', value => $map_states_fan{$fan_state}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Fan Bank '%s' state is %s.", $instance, $map_states_fan{$fan_state})); - } - } -} - -sub check_psu { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking power supplies"); - $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); - - my $instance = 0; - foreach my $value (($self->{results}->{$oid_rcDeviceStsPowerSupply1}, $self->{results}->{$oid_rcDeviceStsPowerSupply2})) { - $instance++; - next if (!defined($value)); - my $psu_state = $value; - - next if ($self->check_exclude(section => 'psu', instance => $instance)); - next if ($map_states_psu{$psu_state} eq 'notPresent' && - $self->absent_problem(section => 'psu', instance => $instance)); - - $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' state is %s.", - $instance, $map_states_psu{$psu_state})); - my $exit = $self->get_severity(section => 'psu', value => $map_states_psu{$psu_state}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Power Supply '%s' state is %s.", $instance, $map_states_psu{$psu_state})); - } - } -} - 1; __END__ =head1 MODE -Check hardware (RUGGEDCOM-SYS-INFO-MIB) (Fans, Power Supplies). +Check hardware (RUGGEDCOM-SYS-INFO-MIB). =over 8 =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'psu', 'fan'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=psu) -Can also exclude specific instance: --exclude='psu#1#' +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=psu,1 =item B<--absent-problem> Return an error if an entity is not 'present' (default is skipping) (comma seperated list) -Can be specific or global: --absent-problem=fan#1# +Can be specific or global: --absent-problem=fan,1 =item B<--no-component> diff --git a/centreon-plugins/network/ruggedcom/mode/memory.pm b/centreon-plugins/network/ruggedcom/mode/memory.pm index a6a8a98bd..7051b420c 100644 --- a/centreon-plugins/network/ruggedcom/mode/memory.pm +++ b/centreon-plugins/network/ruggedcom/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/ruggedcom/mode/temperature.pm b/centreon-plugins/network/ruggedcom/mode/temperature.pm index 76b33e03d..02f66c966 100644 --- a/centreon-plugins/network/ruggedcom/mode/temperature.pm +++ b/centreon-plugins/network/ruggedcom/mode/temperature.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/securactive/mode/bca.pm b/centreon-plugins/network/securactive/mode/bca.pm index e6da5e01f..5eeee08e0 100644 --- a/centreon-plugins/network/securactive/mode/bca.pm +++ b/centreon-plugins/network/securactive/mode/bca.pm @@ -50,7 +50,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/securactive/mode/bcn.pm b/centreon-plugins/network/securactive/mode/bcn.pm index 506dda91b..0a5d7c4a3 100644 --- a/centreon-plugins/network/securactive/mode/bcn.pm +++ b/centreon-plugins/network/securactive/mode/bcn.pm @@ -42,7 +42,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "bcn:s" => { name => 'bcn' }, diff --git a/centreon-plugins/network/securactive/mode/listbca.pm b/centreon-plugins/network/securactive/mode/listbca.pm index 6b9f1d0ec..bf3030c22 100644 --- a/centreon-plugins/network/securactive/mode/listbca.pm +++ b/centreon-plugins/network/securactive/mode/listbca.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s" => { name => 'name' }, diff --git a/centreon-plugins/network/securactive/mode/listbcn.pm b/centreon-plugins/network/securactive/mode/listbcn.pm index 9b95c2441..b63809202 100644 --- a/centreon-plugins/network/securactive/mode/listbcn.pm +++ b/centreon-plugins/network/securactive/mode/listbcn.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "bcn:s" => { name => 'bcn' }, diff --git a/centreon-plugins/network/silverpeak/snmp/mode/alarms.pm b/centreon-plugins/network/silverpeak/snmp/mode/alarms.pm index d68c9e95b..6e97c4864 100644 --- a/centreon-plugins/network/silverpeak/snmp/mode/alarms.pm +++ b/centreon-plugins/network/silverpeak/snmp/mode/alarms.pm @@ -75,7 +75,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-msg:s" => { name => 'filter_msg' }, diff --git a/centreon-plugins/network/silverpeak/snmp/mode/status.pm b/centreon-plugins/network/silverpeak/snmp/mode/status.pm index d3867e172..1acd93ec6 100644 --- a/centreon-plugins/network/silverpeak/snmp/mode/status.pm +++ b/centreon-plugins/network/silverpeak/snmp/mode/status.pm @@ -61,7 +61,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/network/silverpeak/snmp/mode/uptime.pm b/centreon-plugins/network/silverpeak/snmp/mode/uptime.pm index 82e484bfb..ba536e9e1 100644 --- a/centreon-plugins/network/silverpeak/snmp/mode/uptime.pm +++ b/centreon-plugins/network/silverpeak/snmp/mode/uptime.pm @@ -34,7 +34,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/sonicwall/snmp/mode/connections.pm b/centreon-plugins/network/sonicwall/snmp/mode/connections.pm index ad10d6f71..63466e3c1 100644 --- a/centreon-plugins/network/sonicwall/snmp/mode/connections.pm +++ b/centreon-plugins/network/sonicwall/snmp/mode/connections.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/sonicwall/snmp/mode/cpu.pm b/centreon-plugins/network/sonicwall/snmp/mode/cpu.pm index 57e79aa82..59e6e09bd 100644 --- a/centreon-plugins/network/sonicwall/snmp/mode/cpu.pm +++ b/centreon-plugins/network/sonicwall/snmp/mode/cpu.pm @@ -50,7 +50,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/sonicwall/snmp/mode/memory.pm b/centreon-plugins/network/sonicwall/snmp/mode/memory.pm index 92de75619..243072e63 100644 --- a/centreon-plugins/network/sonicwall/snmp/mode/memory.pm +++ b/centreon-plugins/network/sonicwall/snmp/mode/memory.pm @@ -50,7 +50,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/sonicwall/snmp/mode/vpn.pm b/centreon-plugins/network/sonicwall/snmp/mode/vpn.pm index a780d6bf7..cf4ed8bd1 100644 --- a/centreon-plugins/network/sonicwall/snmp/mode/vpn.pm +++ b/centreon-plugins/network/sonicwall/snmp/mode/vpn.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/sonus/sbc/snmp/mode/callstats.pm b/centreon-plugins/network/sonus/sbc/snmp/mode/callstats.pm index a33b3119e..adbe16082 100644 --- a/centreon-plugins/network/sonus/sbc/snmp/mode/callstats.pm +++ b/centreon-plugins/network/sonus/sbc/snmp/mode/callstats.pm @@ -107,7 +107,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/sonus/sbc/snmp/mode/channels.pm b/centreon-plugins/network/sonus/sbc/snmp/mode/channels.pm index 3aa4ccfb8..59c20c057 100644 --- a/centreon-plugins/network/sonus/sbc/snmp/mode/channels.pm +++ b/centreon-plugins/network/sonus/sbc/snmp/mode/channels.pm @@ -246,7 +246,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/network/sonus/sbc/snmp/mode/dspstats.pm b/centreon-plugins/network/sonus/sbc/snmp/mode/dspstats.pm index 73a2ae7ad..818f9e65e 100644 --- a/centreon-plugins/network/sonus/sbc/snmp/mode/dspstats.pm +++ b/centreon-plugins/network/sonus/sbc/snmp/mode/dspstats.pm @@ -88,7 +88,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/network/sophos/es/snmp/mode/health.pm b/centreon-plugins/network/sophos/es/snmp/mode/health.pm index 2379c7b6d..e7f51750e 100644 --- a/centreon-plugins/network/sophos/es/snmp/mode/health.pm +++ b/centreon-plugins/network/sophos/es/snmp/mode/health.pm @@ -58,7 +58,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/sophos/es/snmp/mode/message.pm b/centreon-plugins/network/sophos/es/snmp/mode/message.pm index 2351233b4..c6f3ff3c0 100644 --- a/centreon-plugins/network/sophos/es/snmp/mode/message.pm +++ b/centreon-plugins/network/sophos/es/snmp/mode/message.pm @@ -95,7 +95,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-type:s" => { name => 'filter_type' }, diff --git a/centreon-plugins/network/stonesoft/snmp/mode/clusterload.pm b/centreon-plugins/network/stonesoft/snmp/mode/clusterload.pm index 52cafa38b..5f37f8926 100644 --- a/centreon-plugins/network/stonesoft/snmp/mode/clusterload.pm +++ b/centreon-plugins/network/stonesoft/snmp/mode/clusterload.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/stonesoft/snmp/mode/clusterstate.pm b/centreon-plugins/network/stonesoft/snmp/mode/clusterstate.pm index 68cf854a6..f7235ee33 100644 --- a/centreon-plugins/network/stonesoft/snmp/mode/clusterstate.pm +++ b/centreon-plugins/network/stonesoft/snmp/mode/clusterstate.pm @@ -44,7 +44,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/stonesoft/snmp/mode/connections.pm b/centreon-plugins/network/stonesoft/snmp/mode/connections.pm index 5d88a85d1..b0720d04c 100644 --- a/centreon-plugins/network/stonesoft/snmp/mode/connections.pm +++ b/centreon-plugins/network/stonesoft/snmp/mode/connections.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/stonesoft/snmp/mode/cpu.pm b/centreon-plugins/network/stonesoft/snmp/mode/cpu.pm index 97968f465..30616c213 100644 --- a/centreon-plugins/network/stonesoft/snmp/mode/cpu.pm +++ b/centreon-plugins/network/stonesoft/snmp/mode/cpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/network/stonesoft/snmp/mode/droppedpackets.pm b/centreon-plugins/network/stonesoft/snmp/mode/droppedpackets.pm index b727ef5b8..a03e6a7bf 100644 --- a/centreon-plugins/network/stonesoft/snmp/mode/droppedpackets.pm +++ b/centreon-plugins/network/stonesoft/snmp/mode/droppedpackets.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/stonesoft/snmp/mode/memory.pm b/centreon-plugins/network/stonesoft/snmp/mode/memory.pm index ddf6689fa..3686e37bb 100644 --- a/centreon-plugins/network/stonesoft/snmp/mode/memory.pm +++ b/centreon-plugins/network/stonesoft/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/stonesoft/snmp/mode/rejectedpackets.pm b/centreon-plugins/network/stonesoft/snmp/mode/rejectedpackets.pm index 388050ebe..57edc0407 100644 --- a/centreon-plugins/network/stonesoft/snmp/mode/rejectedpackets.pm +++ b/centreon-plugins/network/stonesoft/snmp/mode/rejectedpackets.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/stonesoft/snmp/mode/storage.pm b/centreon-plugins/network/stonesoft/snmp/mode/storage.pm index 5434e5e23..b3f603eae 100644 --- a/centreon-plugins/network/stonesoft/snmp/mode/storage.pm +++ b/centreon-plugins/network/stonesoft/snmp/mode/storage.pm @@ -34,7 +34,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/network/stormshield/local/mode/qosusage.pm b/centreon-plugins/network/stormshield/local/mode/qosusage.pm index 1144270ba..aded7a0ef 100644 --- a/centreon-plugins/network/stormshield/local/mode/qosusage.pm +++ b/centreon-plugins/network/stormshield/local/mode/qosusage.pm @@ -143,7 +143,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-vlan:s" => { name => 'filter_vlan' }, diff --git a/centreon-plugins/network/stormshield/snmp/mode/connections.pm b/centreon-plugins/network/stormshield/snmp/mode/connections.pm index f6e2b7031..d1507eee9 100644 --- a/centreon-plugins/network/stormshield/snmp/mode/connections.pm +++ b/centreon-plugins/network/stormshield/snmp/mode/connections.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/stormshield/snmp/mode/hanodes.pm b/centreon-plugins/network/stormshield/snmp/mode/hanodes.pm index 7e6d78fb5..c0774e3ec 100644 --- a/centreon-plugins/network/stormshield/snmp/mode/hanodes.pm +++ b/centreon-plugins/network/stormshield/snmp/mode/hanodes.pm @@ -127,7 +127,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-node:s" => { name => 'filter_node' }, diff --git a/centreon-plugins/network/stormshield/snmp/mode/vpnstatus.pm b/centreon-plugins/network/stormshield/snmp/mode/vpnstatus.pm index 3c9c47860..69b7b2961 100644 --- a/centreon-plugins/network/stormshield/snmp/mode/vpnstatus.pm +++ b/centreon-plugins/network/stormshield/snmp/mode/vpnstatus.pm @@ -89,7 +89,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-id:s" => { name => 'filter_id' }, "filter-src-ip:s" => { name => 'filter_src_ip' }, diff --git a/centreon-plugins/network/teltonika/snmp/mode/system.pm b/centreon-plugins/network/teltonika/snmp/mode/system.pm new file mode 100644 index 000000000..1909bd033 --- /dev/null +++ b/centreon-plugins/network/teltonika/snmp/mode/system.pm @@ -0,0 +1,201 @@ +# +# Copyright 2018 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::teltonika::snmp::mode::system; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("connection state is '%s' [pin state: '%s'] [net state: '%s'][sim state: '%s']", + $self->{result_values}->{connection_state}, + $self->{result_values}->{pin_state}, + $self->{result_values}->{net_state}, + $self->{result_values}->{sim_state}, + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'sim_state' }, { name => 'pin_state' }, { name => 'net_state' }, { name => 'connection_state' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'signal-strength', nlabel => 'system.signal.strength.dbm', display_ok => 0, set => { + key_values => [ { name => 'signal' } ], + output_template => 'signal strength: %s Dbm', + perfdatas => [ + { value => 'signal_absolute', template => '%s', min => 0 , unit => 'Dbm' }, + ], + } + }, + { label => 'temperature', nlabel => 'system.temperature.celsius', display_ok => 0, set => { + key_values => [ { name => 'temperature' } ], + output_template => 'temperature: %s C', + perfdatas => [ + { value => 'temperature_absolute', template => '%s', min => 0 , unit => 'C' }, + ], + } + }, + { label => 'traffic-in', nlabel => 'system.traffic.in.bitspersecond', display_ok => 0, set => { + key_values => [ { name => 'traffic_in', diff => 1 } ], + output_template => 'traffic in: %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_in_per_second', template => '%s', + min => 0, unit => 'b/s' }, + ], + } + }, + { label => 'traffic-out', nlabel => 'system.traffic.out.bitspersecond', display_ok => 0, set => { + key_values => [ { name => 'traffic_out', diff => 1 } ], + output_template => 'traffic out: %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_out_per_second', template => '%s', + min => 0, unit => 'b/s' }, + ], + } + }, + { label => 'signal-receive-power', nlabel => 'system.signal.receive.power.dbm', display_ok => 0, set => { + key_values => [ { name => 'rsrp' } ], + output_template => 'signal receive power: %s Dbm', + perfdatas => [ + { value => 'rsrp_absolute', template => '%s', min => 0 , unit => 'Dbm' }, + ], + } + }, + { label => 'signal-receive-quality', nlabel => 'system.signal.receive.quality.dbm', display_ok => 0, set => { + key_values => [ { name => 'rsrq' } ], + output_template => 'signal receive quality: %s Dbm', + perfdatas => [ + { value => 'rsrq_absolute', template => '%s', min => 0 , unit => 'Dbm' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{connection_state} !~ /connected/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_SimState = '.1.3.6.1.4.1.48690.2.1.0'; + my $oid_PinState = '.1.3.6.1.4.1.48690.2.2.0'; + my $oid_NetState = '.1.3.6.1.4.1.48690.2.3.0'; + my $oid_Signal = '.1.3.6.1.4.1.48690.2.4.0'; + my $oid_ConnectionState = '.1.3.6.1.4.1.48690.2.7.0'; + my $oid_Temperature = '.1.3.6.1.4.1.48690.2.9.0'; + my $oid_Sent = '.1.3.6.1.4.1.48690.2.19.0'; + my $oid_Received = '.1.3.6.1.4.1.48690.2.20.0'; + my $oid_RSRP = '.1.3.6.1.4.1.48690.2.23.0'; + my $oid_RSRQ = '.1.3.6.1.4.1.48690.2.24.0'; + my $result = $options{snmp}->get_leef(oids => [ + $oid_SimState, $oid_PinState, $oid_NetState, $oid_ConnectionState, + $oid_Signal, $oid_Temperature, $oid_Sent, $oid_Received, + $oid_RSRP, $oid_RSRQ + ], nothing_quit => 1); + + $self->{cache_name} = "teltonika_" . $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->{global} = { + sim_state => defined($result->{$oid_SimState}) ? $result->{$oid_SimState} : '-', + pin_state => defined($result->{$oid_PinState}) ? $result->{$oid_PinState} : '-', + net_state => defined($result->{$oid_NetState}) ? $result->{$oid_NetState} : '-', + connection_state => $result->{$oid_ConnectionState}, + signal => $result->{$oid_Signal}, + temperature => $result->{$oid_Temperature} / 10, + traffic_in => $result->{$oid_Received} * 8, + traffic_out => $result->{$oid_Sent} * 8, + rsrp => $result->{$oid_RSRP}, + rsrq => $result->{$oid_RSRQ}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check system. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='status' + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{sim_state}, %{pin_state}, %{net_state}, %{connection_state} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{connection_state} !~ /connected/i'). +Can used special variables like: %{sim_state}, %{pin_state}, %{net_state}, %{connection_state} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'signal-strength', 'temperature', 'traffic-in', 'traffic-out' +'signal-receive-power', 'signal-receive-quality'. + +=back + +=cut diff --git a/centreon-plugins/network/teltonika/snmp/plugin.pm b/centreon-plugins/network/teltonika/snmp/plugin.pm new file mode 100644 index 000000000..1c0317ad6 --- /dev/null +++ b/centreon-plugins/network/teltonika/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2018 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::teltonika::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', + 'system' => 'network::teltonika::snmp::mode::system', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Teltonika equipments in SNMP + +=cut diff --git a/centreon-plugins/network/ucopia/wlc/snmp/mode/system.pm b/centreon-plugins/network/ucopia/wlc/snmp/mode/system.pm new file mode 100644 index 000000000..6e072ce1d --- /dev/null +++ b/centreon-plugins/network/ucopia/wlc/snmp/mode/system.pm @@ -0,0 +1,252 @@ +# +# Copyright 2018 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::ucopia::wlc::snmp::mode::system; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_service_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("status is %s", + $self->{result_values}->{status}, + ); + return $msg; +} + +sub custom_ha_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("high-availablity status is %s", + $self->{result_values}->{ha_status}, + ); + return $msg; +} + +sub custom_users_output { + my ($self, %options) = @_; + + my $msg = sprintf("%d connected users (Available licence: %s)", + $self->{result_values}->{connected_users_absolute}, + $self->{result_values}->{max_users_absolute} ne '' ? $self->{result_values}->{max_users_absolute} : '-' + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, + { name => 'service', type => 1, cb_prefix_output => 'prefix_service_output', message_multiple => 'All services are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'users-connected', nlabel => 'system.users.connected.count', set => { + key_values => [ { name => 'connected_users' }, { name => 'max_users' } ], + closure_custom_output => $self->can('custom_users_output'), + perfdatas => [ + { value => 'connected_users_absolute', template => '%s', min => 0, max => 'max_users_absolute' }, + ], + } + }, + { label => 'users-connected-prct', nlabel => 'system.users.connected.percentage', display_ok => 0, set => { + key_values => [ { name => 'connected_users_prct' } ], + output_template => 'users connected: %.2f %%', + perfdatas => [ + { value => 'connected_users_prct_absolute', template => '%.2f', unit => '%', min => 0, max => 100 }, + ], + } + }, + { label => 'ha-status', threshold => 0, set => { + key_values => [ { name => 'ha_status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_ha_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'disk-temperature', nlabel => 'system.disk.temperature.celsius', display_ok => 0, set => { + key_values => [ { name => 'disk_temperature', no_value => 0 } ], + output_template => 'disk temperature: %s C', + perfdatas => [ + { value => 'disk_temperature_absolute', template => '%s', unit => 'C' }, + ], + } + }, + { label => 'cpu-temperature', nlabel => 'system.cpu.temperature.celsius', display_ok => 0, set => { + key_values => [ { name => 'cpu_temperature', no_value => 0 } ], + output_template => 'cpu temperature: %s C', + perfdatas => [ + { value => 'cpu_temperature_absolute', template => '%s', unit => 'C' }, + ], + } + }, + ]; + + $self->{maps_counters}->{service} = [ + { label => 'service-status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_service_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_service_output { + my ($self, %options) = @_; + + return "Service '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'warning-service-status:s' => { name => 'warning_service_status', default => '' }, + 'critical-service-status:s' => { name => 'critical_service_status', default => '%{status} eq "stopped"' }, + 'warning-ha-status:s' => { name => 'warning_ha_status', default => '' }, + 'critical-ha-status:s' => { name => 'critical_ha_status', default => '%{ha_status} eq "fault"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => [ + 'warning_service_status', 'critical_service_status', + 'warning_ha_status', 'critical_ha_status', + ]); +} + +my $map_sc_status = { 1 => 'running', 2 => 'stopped', 3 => 'disabled' }; +my $map_ha_status = { 0 => 'standalone', 1 => 'master', 2 => 'active', 3 => 'passive', 4 => 'fault' }; + +my $mapping = { + totalConnectedUsers => { oid => '.1.3.6.1.4.1.31218.3.1' }, + cpuTemperature => { oid => '.1.3.6.1.4.1.31218.3.3' }, + diskTemperature => { oid => '.1.3.6.1.4.1.31218.3.4' }, + licenseUsers => { oid => '.1.3.6.1.4.1.31218.3.5' }, + highAvailabilityStatus => { oid => '.1.3.6.1.4.1.31218.3.7', map => $map_ha_status }, +}; + +my $mapping2 = { + webServer => { oid => '.1.3.6.1.4.1.31218.4.1', map => $map_sc_status }, + sqlServer => { oid => '.1.3.6.1.4.1.31218.4.2', map => $map_sc_status }, + urlSniffer => { oid => '.1.3.6.1.4.1.31218.4.3', map => $map_sc_status }, + portal => { oid => '.1.3.6.1.4.1.31218.4.4', map => $map_sc_status }, + webProxy => { oid => '.1.3.6.1.4.1.31218.4.5', map => $map_sc_status }, + autodisconnect => { oid => '.1.3.6.1.4.1.31218.4.6', map => $map_sc_status }, + printingServer => { oid => '.1.3.6.1.4.1.31218.4.7', map => $map_sc_status }, + dhcpServer => { oid => '.1.3.6.1.4.1.31218.4.8', map => $map_sc_status }, + dnsServer => { oid => '.1.3.6.1.4.1.31218.4.9', map => $map_sc_status }, + staticIpManager => { oid => '.1.3.6.1.4.1.31218.4.10', map => $map_sc_status }, + highAvailability => { oid => '.1.3.6.1.4.1.31218.4.11', map => $map_sc_status }, + ldapDirectory => { oid => '.1.3.6.1.4.1.31218.4.12', map => $map_sc_status }, + ldapReplicationManager => { oid => '.1.3.6.1.4.1.31218.4.13', map => $map_sc_status }, + timeServer => { oid => '.1.3.6.1.4.1.31218.4.14', map => $map_sc_status }, + radiusServer => { oid => '.1.3.6.1.4.1.31218.4.15', map => $map_sc_status }, + samba => { oid => '.1.3.6.1.4.1.31218.4.16', map => $map_sc_status }, + ssh => { oid => '.1.3.6.1.4.1.31218.4.17', map => $map_sc_status }, + syslog => { oid => '.1.3.6.1.4.1.31218.4.18', map => $map_sc_status }, + usersLog => { oid => '.1.3.6.1.4.1.31218.4.19', map => $map_sc_status }, + pmsClient => { oid => '.1.3.6.1.4.1.31218.4.20', map => $map_sc_status }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)), map($_->{oid} . '.0', values(%$mapping2)) ], nothing_quit => 1 + ); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + $self->{global} = { + ha_status => $result->{highAvailabilityStatus}, + disk_temperature => $result->{diskTemperature}, + cpu_temperature => $result->{cpuTemperature}, + connected_users => $result->{totalConnectedUsers}, + max_users => defined($result->{licenseUsers}) ? $result->{licenseUsers} : '', + connected_users_prct => defined($result->{licenseUsers}) ? $result->{totalConnectedUsers} * 100 / $result->{licenseUsers} : undef + }; + + $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => '0'); + $self->{service} = {}; + foreach (keys %$result) { + $self->{service}->{$_} = { display => $_, status => $result->{$_} }; + } +} + +1; + +__END__ + +=head1 MODE + +Check system. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='service-status' + +=item B<--warning-service-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-service-status> + +Set critical threshold for status (Default: '%{status} eq "stopped"'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-ha-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{ha_status} + +=item B<--critical-ha-status> + +Set critical threshold for status (Default: '%{ha_status} eq "fault"'). +Can used special variables like: %{ha_status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'users-connected', 'users-connected-prct', +'disk-temperature', 'cpu-temperature'. + +=back + +=cut diff --git a/centreon-plugins/network/ucopia/wlc/snmp/mode/temperature.pm b/centreon-plugins/network/ucopia/wlc/snmp/mode/temperature.pm deleted file mode 100644 index 52f8e50c5..000000000 --- a/centreon-plugins/network/ucopia/wlc/snmp/mode/temperature.pm +++ /dev/null @@ -1,111 +0,0 @@ -# -# Copyright 2019 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::ucopia::wlc::snmp::mode::temperature; - -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) = @_; - - my $oid_cpuTemperature = '.1.3.6.1.4.1.31218.3.3.0'; - my $oid_diskTemperature = '.1.3.6.1.4.1.31218.3.4.0'; - - my $result = $options{snmp}->get_leef(oids => [$oid_cpuTemperature, $oid_diskTemperature], nothing_quit => 1); - - if ($result->{$oid_cpuTemperature} != 0) { - my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_cpuTemperature}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("CPU Temp: %dC", $result->{$oid_cpuTemperature})); - $self->{output}->perfdata_add(value => $result->{$oid_cpuTemperature}, - label => 'cpu_temp', unit => 'C', - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - } - - if ($result->{$oid_diskTemperature} != 0) { - my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_diskTemperature}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("DISK Temp: %dC", $result->{$oid_diskTemperature})); - $self->{output}->perfdata_add(value => $result->{$oid_diskTemperature}, - label => 'disk_temp', unit => 'C', - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check temperatures. - -=over 8 - -=item B<--warning> - -Threshold warning. - -=item B<--critical> - -Threshold critical. - -=back - -=cut - diff --git a/centreon-plugins/network/ucopia/wlc/snmp/mode/users.pm b/centreon-plugins/network/ucopia/wlc/snmp/mode/users.pm deleted file mode 100644 index abaf6d37a..000000000 --- a/centreon-plugins/network/ucopia/wlc/snmp/mode/users.pm +++ /dev/null @@ -1,100 +0,0 @@ -# -# Copyright 2019 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::ucopia::wlc::snmp::mode::users; - -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) = @_; - - my $oid_totalConnectedUsers = '.1.3.6.1.4.1.31218.3.1.0'; - my $oid_licenceUsers = '.1.3.6.1.4.1.31218.3.5.0'; - - my $result = $options{snmp}->get_leef(oids => [$oid_totalConnectedUsers, $oid_licenceUsers], nothing_quit => 1); - my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_totalConnectedUsers}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $result->{$oid_licenceUsers} = undef if ($result->{$oid_licenceUsers} == 0); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("'%d' connected users (Available licence: %s)", - $result->{$oid_totalConnectedUsers}, - defined($result->{$oid_licenceUsers}) ? $result->{$oid_licenceUsers} : '-')); - $self->{output}->perfdata_add(value => $result->{$oid_totalConnectedUsers}, label => 'users', - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => $result->{$oid_licenceUsers}); - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check connected users. - -=over 8 - -=item B<--warning> - -Threshold warning. - -=item B<--critical> - -Threshold critical. - -=back - -=cut - diff --git a/centreon-plugins/network/ucopia/wlc/snmp/plugin.pm b/centreon-plugins/network/ucopia/wlc/snmp/plugin.pm index 18cbb2479..325ba53c9 100644 --- a/centreon-plugins/network/ucopia/wlc/snmp/plugin.pm +++ b/centreon-plugins/network/ucopia/wlc/snmp/plugin.pm @@ -31,9 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'temperature' => 'network::ucopia::wlc::snmp::mode::temperature', - 'users' => 'network::ucopia::wlc::snmp::mode::users', - ); + 'system' => 'network::ucopia::wlc::snmp::mode::system', + ); return $self; } diff --git a/centreon-plugins/network/watchguard/snmp/mode/cpu.pm b/centreon-plugins/network/watchguard/snmp/mode/cpu.pm index aa4c423d3..52f7d9ea3 100644 --- a/centreon-plugins/network/watchguard/snmp/mode/cpu.pm +++ b/centreon-plugins/network/watchguard/snmp/mode/cpu.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/watchguard/snmp/mode/ipsectunnel.pm b/centreon-plugins/network/watchguard/snmp/mode/ipsectunnel.pm new file mode 100644 index 000000000..90b449d91 --- /dev/null +++ b/centreon-plugins/network/watchguard/snmp/mode/ipsectunnel.pm @@ -0,0 +1,173 @@ +# +# Copyright 2019 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::watchguard::snmp::mode::ipsectunnel; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use Socket; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'tunnel', type => 1, cb_prefix_output => 'prefix_tunnel_output', message_multiple => 'All tunnels are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'tunnels-total', nlabel => 'ipsec.tunnels.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'Total Tunnels: %s', + perfdatas => [ + { label => 'total_tunnels', value => 'total_absolute', template => '%s', + min => 0 }, + ], + } + }, + ]; + $self->{maps_counters}->{tunnel} = [ + { label => 'tunnel-traffic-in', nlabel => 'ipsec.tunnel.traffic.in.bitspersecond', set => { + key_values => [ { name => 'wgIpsecTunnelInKbytes', diff => 1 }, { name => 'display' } ], + output_template => 'Traffic In : %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'wgIpsecTunnelInKbytes_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'tunnel-traffic-out', nlabel => 'ipsec.tunnel.traffic.out.bitspersecond', set => { + key_values => [ { name => 'wgIpsecTunnelOutKbytes', diff => 1 }, { name => 'display' } ], + output_template => 'Traffic Out : %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'wgIpsecTunnelOutKbytes_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_tunnel_output { + my ($self, %options) = @_; + + return "Tunnel '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); + + return $self; +} + +my $mapping = { + wgIpsecTunnelLocalAddr => { oid => '.1.3.6.1.4.1.3097.6.5.1.2.1.2' }, + wgIpsecTunnelPeerAddr => { oid => '.1.3.6.1.4.1.3097.6.5.1.2.1.3' }, +}; + +my $oid_wgIpsecTunnelEntry = '.1.3.6.1.4.1.3097.6.5.1.2.1'; +my $mapping2 = { + wgIpsecTunnelInKbytes => { oid => '.1.3.6.1.4.1.3097.6.5.1.2.1.28' }, + wgIpsecTunnelOutKbytes => { oid => '.1.3.6.1.4.1.3097.6.5.1.2.1.29' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{tunnel} = {}; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_wgIpsecTunnelEntry, + start => $mapping->{wgIpsecTunnelLocalAddr}->{oid}, + end => $mapping->{wgIpsecTunnelPeerAddr}->{oid}, + nothing_quit => 1 + ); + foreach (keys %$snmp_result) { + next if (!/$mapping->{wgIpsecTunnelLocalAddr}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + my $name = $result->{wgIpsecTunnelLocalAddr} . ':' . $result->{wgIpsecTunnelPeerAddr}; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter name.", debug => 1); + next; + } + + $self->{tunnel}->{$instance} = { display => $name }; + } + + if (scalar(keys %{$self->{tunnel}}) > 0) { + $options{snmp}->load(oids => [ + map($_->{oid}, values(%$mapping2)) + ], + instances => [keys %{$self->{tunnel}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + foreach (keys %{$self->{tunnel}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_); + $result->{wgIpsecTunnelInKbytes} *= 1024 * 8; + $result->{wgIpsecTunnelOutKbytes} *= 1024 * 8; + $self->{tunnel}->{$_} = { %{$self->{tunnel}->{$_}}, %$result }; + } + } + + $self->{global} = { total => scalar(keys %{$self->{tunnel}}) }; + + $self->{cache_name} = 'watchguard_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check ipsec tunnels. + +=over 8 + +=item B<--filter-name> + +Filter name (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='tunnels-total' + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'tunnels-total', 'tunnel-traffic-in', 'tunnel-traffic-out'. + +=back + +=cut diff --git a/centreon-plugins/network/watchguard/snmp/mode/policyusage.pm b/centreon-plugins/network/watchguard/snmp/mode/policyusage.pm index e68b0279a..124420f62 100644 --- a/centreon-plugins/network/watchguard/snmp/mode/policyusage.pm +++ b/centreon-plugins/network/watchguard/snmp/mode/policyusage.pm @@ -80,7 +80,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/watchguard/snmp/mode/system.pm b/centreon-plugins/network/watchguard/snmp/mode/system.pm index 71c3ef242..2230e3ec0 100644 --- a/centreon-plugins/network/watchguard/snmp/mode/system.pm +++ b/centreon-plugins/network/watchguard/snmp/mode/system.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/watchguard/snmp/plugin.pm b/centreon-plugins/network/watchguard/snmp/plugin.pm index dc4d96861..41723f932 100644 --- a/centreon-plugins/network/watchguard/snmp/plugin.pm +++ b/centreon-plugins/network/watchguard/snmp/plugin.pm @@ -31,15 +31,16 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::watchguard::snmp::mode::cpu', - 'hardware' => 'snmp_standard::mode::hardwaredevice', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-storages' => 'snmp_standard::mode::liststorages', - 'policy-usage' => 'network::watchguard::snmp::mode::policyusage', - 'storage' => 'snmp_standard::mode::storage', - 'system' => 'network::watchguard::snmp::mode::system', - ); + 'cpu' => 'network::watchguard::snmp::mode::cpu', + 'hardware' => 'snmp_standard::mode::hardwaredevice', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'ipsec-tunnel' => 'network::watchguard::snmp::mode::ipsectunnel', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'policy-usage' => 'network::watchguard::snmp::mode::policyusage', + 'storage' => 'snmp_standard::mode::storage', + 'system' => 'network::watchguard::snmp::mode::system', + ); return $self; } diff --git a/centreon-plugins/network/zyxel/snmp/mode/cpu.pm b/centreon-plugins/network/zyxel/snmp/mode/cpu.pm index 781924f75..f2f25d6be 100644 --- a/centreon-plugins/network/zyxel/snmp/mode/cpu.pm +++ b/centreon-plugins/network/zyxel/snmp/mode/cpu.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/zyxel/snmp/mode/listvpn.pm b/centreon-plugins/network/zyxel/snmp/mode/listvpn.pm index 016e4f211..f5a1b907b 100644 --- a/centreon-plugins/network/zyxel/snmp/mode/listvpn.pm +++ b/centreon-plugins/network/zyxel/snmp/mode/listvpn.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/network/zyxel/snmp/mode/memory.pm b/centreon-plugins/network/zyxel/snmp/mode/memory.pm index d50a76eca..e42366fb1 100644 --- a/centreon-plugins/network/zyxel/snmp/mode/memory.pm +++ b/centreon-plugins/network/zyxel/snmp/mode/memory.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/zyxel/snmp/mode/sessions.pm b/centreon-plugins/network/zyxel/snmp/mode/sessions.pm index c5837639d..db443ea9c 100644 --- a/centreon-plugins/network/zyxel/snmp/mode/sessions.pm +++ b/centreon-plugins/network/zyxel/snmp/mode/sessions.pm @@ -49,7 +49,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/network/zyxel/snmp/mode/vpnstatus.pm b/centreon-plugins/network/zyxel/snmp/mode/vpnstatus.pm index f5e387b74..5a0d121ad 100644 --- a/centreon-plugins/network/zyxel/snmp/mode/vpnstatus.pm +++ b/centreon-plugins/network/zyxel/snmp/mode/vpnstatus.pm @@ -93,7 +93,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/notification/foxbox/mode/alert.pm b/centreon-plugins/notification/foxbox/mode/alert.pm index 38749a61d..a7ad53762 100644 --- a/centreon-plugins/notification/foxbox/mode/alert.pm +++ b/centreon-plugins/notification/foxbox/mode/alert.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "foxbox-username:s" => { name => 'foxbox_username', default => 'centreon' }, "foxbox-password:s" => { name => 'foxbox_password' }, diff --git a/centreon-plugins/notification/highsms/mode/alert.pm b/centreon-plugins/notification/highsms/mode/alert.pm index 34f5389c1..d2b895164 100644 --- a/centreon-plugins/notification/highsms/mode/alert.pm +++ b/centreon-plugins/notification/highsms/mode/alert.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => 443 }, diff --git a/centreon-plugins/notification/ovhsms/mode/alert.pm b/centreon-plugins/notification/ovhsms/mode/alert.pm index 8ac832aba..55ce19172 100644 --- a/centreon-plugins/notification/ovhsms/mode/alert.pm +++ b/centreon-plugins/notification/ovhsms/mode/alert.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname', default => 'www.ovh.com' }, "port:s" => { name => 'port', default => 443 }, diff --git a/centreon-plugins/notification/slack/mode/alert.pm b/centreon-plugins/notification/slack/mode/alert.pm index aa1266ecc..54af05bdc 100644 --- a/centreon-plugins/notification/slack/mode/alert.pm +++ b/centreon-plugins/notification/slack/mode/alert.pm @@ -44,7 +44,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "slack-url:s" => { name => 'slack_url' }, "slack-channel:s" => { name => 'slack_channel' }, diff --git a/centreon-plugins/notification/telegram/mode/alert.pm b/centreon-plugins/notification/telegram/mode/alert.pm index 996991ec3..1c3df7da9 100644 --- a/centreon-plugins/notification/telegram/mode/alert.pm +++ b/centreon-plugins/notification/telegram/mode/alert.pm @@ -44,7 +44,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname', default => 'api.telegram.org' }, "port:s" => { name => 'port', default => 443 }, diff --git a/centreon-plugins/os/aix/local/mode/errpt.pm b/centreon-plugins/os/aix/local/mode/errpt.pm index f1c3ce084..b29bbf2f7 100644 --- a/centreon-plugins/os/aix/local/mode/errpt.pm +++ b/centreon-plugins/os/aix/local/mode/errpt.pm @@ -31,29 +31,28 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'errpt' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '' }, - "error-type:s" => { name => 'error_type' }, - "error-class:s" => { name => 'error_class' }, - "error-id:s" => { name => 'error_id' }, - "retention:s" => { name => 'retention' }, - "timezone:s" => { name => 'timezone' }, - "description" => { name => 'description' }, - "filter-resource:s" => { name => 'filter_resource' }, - "filter-id:s" => { name => 'filter_id' }, - "exclude-id:s" => { name => 'exclude_id' }, - }); + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'errpt' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '' }, + 'error-type:s' => { name => 'error_type' }, + 'error-class:s' => { name => 'error_class' }, + 'error-id:s' => { name => 'error_id' }, + 'retention:s' => { name => 'retention' }, + 'timezone:s' => { name => 'timezone' }, + 'description' => { name => 'description' }, + 'filter-resource:s' => { name => 'filter_resource' }, + 'filter-id:s' => { name => 'filter_id' }, + 'exclude-id:s' => { name => 'exclude_id' }, + 'format-date' => { name => 'format_date' }, + }); $self->{result} = {}; return $self; } @@ -63,7 +62,7 @@ sub check_options { $self->SUPER::init(%options); if (defined($self->{option_results}->{exclude_id}) && defined($self->{option_results}->{error_id})) { - $self->{output}->add_option_msg(short_msg => "Please use --error-id OR --exclude-id, these options are mutually exclusives"); + $self->{output}->add_option_msg(short_msg => "Please use --error-id OR --exclude-id, these options are mutually exclusives"); $self->{output}->option_exit(); } } @@ -113,12 +112,14 @@ sub manage_selection { $extra_options .= $self->{option_results}->{command_options}; - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $extra_options); + my $stdout = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $extra_options + ); my @lines = split /\n/, $stdout; # Header not needed shift @lines; @@ -154,13 +155,20 @@ sub run { $resource_name !~ /$self->{option_results}->{filter_resource}/); next if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' && $identifier !~ /$self->{option_results}->{filter_id}/); + + my $output_date = $split_error[0]; + if (defined($self->{option_results}->{format_date})) { + my ($month, $day, $hour, $minute, $year) = unpack("(A2)*", $output_date); + $output_date = sprintf("20%s/%s/%s %s:%s", $year, $month, $day, $hour, $minute); + } + $total_error++; - if (defined($self->{option_results}->{description})) { + if (defined($description)) { $self->{output}->output_add(long_msg => sprintf("Error '%s' Date: %s ResourceName: %s Description: %s", $identifier, - $timestamp, $resource_name, $description)); + $output_date, $resource_name, $description)); } else { $self->{output}->output_add(long_msg => sprintf("Error '%s' Date: %s ResourceName: %s", $identifier, - $timestamp, $resource_name)); + $output_date, $resource_name)); } } @@ -252,6 +260,10 @@ Filter error code (can use a regexp). Filter on specific error code (can be a comma separated list). +=item B<--format-date> + +Print the date to format 20YY/mm/dd HH:MM instead of mmddHHMMYY. + =back =cut diff --git a/centreon-plugins/os/aix/local/mode/inodes.pm b/centreon-plugins/os/aix/local/mode/inodes.pm index f078e3f02..0f8964d51 100644 --- a/centreon-plugins/os/aix/local/mode/inodes.pm +++ b/centreon-plugins/os/aix/local/mode/inodes.pm @@ -57,7 +57,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, diff --git a/centreon-plugins/os/aix/local/mode/liststorages.pm b/centreon-plugins/os/aix/local/mode/liststorages.pm index ba0cd266c..1e0ece357 100644 --- a/centreon-plugins/os/aix/local/mode/liststorages.pm +++ b/centreon-plugins/os/aix/local/mode/liststorages.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/aix/local/mode/lvsync.pm b/centreon-plugins/os/aix/local/mode/lvsync.pm index 045e41246..05534e658 100644 --- a/centreon-plugins/os/aix/local/mode/lvsync.pm +++ b/centreon-plugins/os/aix/local/mode/lvsync.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/aix/local/mode/process.pm b/centreon-plugins/os/aix/local/mode/process.pm new file mode 100644 index 000000000..4bc3c31ba --- /dev/null +++ b/centreon-plugins/os/aix/local/mode/process.pm @@ -0,0 +1,272 @@ +# +# Copyright 2019 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 os::aix::local::mode::process; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::misc; + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf('Process [command => %s] [arg: %s] [state: %s] [elapsed => %s]', + $self->{result_values}->{cmd}, + $self->{result_values}->{args}, + $self->{result_values}->{state}, + $self->{result_values}->{elapsed} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'alarms', type => 2, message_multiple => '0 process problem detected', format_output => '%s process(es) problem(s) detected', + display_counter_problem => { nlabel => 'processes.alerts.count', min => 0 }, + group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'processes.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'Number of current processes: %s', + perfdatas => [ + { value => 'total_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{alarm} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'ppid' }, { name => 'state' }, + { name => 'elapsed' }, { name => 'cmd' }, { name => 'args' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'ps' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-e -o state -o ===%t===%p===%P=== -o comm:50 -o ===%a 2>&1' }, + 'filter-command:s' => { name => 'filter_command' }, + 'filter-arg:s' => { name => 'filter_arg' }, + 'filter-state:s' => { name => 'filter_state' }, + 'filter-ppid:s' => { name => 'filter_ppid' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +my %state_map = ( + Z => 'Canceled', + O => 'Nonexistent', + A => 'Active', + W => 'Swapped', + I => 'Idle', + T => 'Stopped', + R => 'Running', + S => 'Sleeping', +); + +sub get_time_seconds { + my ($self, %options) = @_; + + my $time = $options{value}; + # Format: [[dd-]hh:]mm:ss + my @values = split /:/, $time; + my ($seconds, $min, $lpart) = (pop @values, pop @values, pop @values); + my $total_seconds_elapsed = $seconds + ($min * 60); + if (defined($lpart)) { + my ($day, $hour) = split /-/, $lpart; + if (defined($hour)) { + $total_seconds_elapsed += ($hour * 60 * 60); + } + if (defined($day)) { + $total_seconds_elapsed += ($day * 86400); + } + } + + return $total_seconds_elapsed; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $stdout = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); + + $self->{alarms}->{global} = { alarm => {} }; + my @lines = split /\n/, $stdout; + my $line = shift @lines; + foreach my $line (@lines) { + next if ($line !~ /^(.*?)===(.*?)===(.*?)===(.*?)===(.*?)===(.*)$/); + my ($state, $elapsed, $pid, $ppid, $cmd, $args) = ( + centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), centreon::plugins::misc::trim($3), + centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5), centreon::plugins::misc::trim($6) + ); + + next if (defined($self->{option_results}->{filter_command}) && $self->{option_results}->{filter_command} ne '' && + $cmd !~ /$self->{option_results}->{filter_command}/); + next if (defined($self->{option_results}->{filter_arg}) && $self->{option_results}->{filter_arg} ne '' && + $args !~ /$self->{option_results}->{filter_arg}/); + next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' && + $state_map{$state} !~ /$self->{option_results}->{filter_state}/i); + next if (defined($self->{option_results}->{filter_ppid}) && $self->{option_results}->{filter_ppid} ne '' && + $ppid !~ /$self->{option_results}->{filter_ppid}/); + + $self->{alarms}->{global}->{alarm}->{$pid} = { + ppid => $ppid, + state => $state_map{$state}, + elapsed => $self->get_time_seconds(value => $elapsed), + cmd => $cmd, + args => $args + }; + } + + $self->{global} = { total => scalar(keys %{$self->{alarms}->{global}->{alarm}}) }; +} + +1; + +__END__ + +=head1 MODE + +Check AIX processes. +Can filter on commands, arguments and states. + +=over 8 + +=item B<--remote> + +Execute command remotely in 'ssh'. + +=item B<--hostname> + +Hostname to query (need --remote). + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'ps'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '-e -o state -o ===%t===%p===%P=== -o comm:50 -o ===%a 2>&1'). + +=item B<--filter-command> + +Filter process commands (regexp can be used). + +=item B<--filter-arg> + +Filter process arguments (regexp can be used). + +=item B<--filter-ppid> + +Filter process ppid (regexp can be used). + +=item B<--filter-state> + +Filter process states (regexp can be used). +You can use: 'Canceled', 'Nonexistent', 'Active', +'Swapped', 'Idle', 'Stopped', 'Running', 'Sleeping'. + +=item B<--warning-status> + +Set warning threshold for status (Default: '') +Can used special variables like: %{ppid}, %{state}, %{elapsed}, %{cmd}, %{args} + +=item B<--critical-status> + +Set critical threshold for status (Default: ''). +Can used special variables like: %{ppid}, %{state}, %{elapsed}, %{cmd}, %{args} + +=item B<--warning-*> B<--critical-*> + +Thresholds. Can be: 'total'. + +=back + +=cut diff --git a/centreon-plugins/os/aix/local/mode/storage.pm b/centreon-plugins/os/aix/local/mode/storage.pm index 1e5924d08..2398d158a 100644 --- a/centreon-plugins/os/aix/local/mode/storage.pm +++ b/centreon-plugins/os/aix/local/mode/storage.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/aix/local/plugin.pm b/centreon-plugins/os/aix/local/plugin.pm index 40e6feb1b..0946a3b24 100644 --- a/centreon-plugins/os/aix/local/plugin.pm +++ b/centreon-plugins/os/aix/local/plugin.pm @@ -31,12 +31,13 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'errpt' => 'os::aix::local::mode::errpt', - 'list-storages' => 'os::aix::local::mode::liststorages', - 'storage' => 'os::aix::local::mode::storage', - 'inodes' => 'os::aix::local::mode::inodes', - 'lvsync' => 'os::aix::local::mode::lvsync', - ); + 'errpt' => 'os::aix::local::mode::errpt', + 'inodes' => 'os::aix::local::mode::inodes', + 'list-storages' => 'os::aix::local::mode::liststorages', + 'lvsync' => 'os::aix::local::mode::lvsync', + 'process' => 'os::aix::local::mode::process', + 'storage' => 'os::aix::local::mode::storage', + ); return $self; } diff --git a/centreon-plugins/os/aix/snmp/mode/swap.pm b/centreon-plugins/os/aix/snmp/mode/swap.pm index 0acd85dd4..4b7774302 100644 --- a/centreon-plugins/os/aix/snmp/mode/swap.pm +++ b/centreon-plugins/os/aix/snmp/mode/swap.pm @@ -117,9 +117,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "paging-state-buggy" => { name => 'paging_state_buggy' }, + 'paging-state-buggy' => { name => 'paging_state_buggy' }, }); return $self; @@ -187,13 +186,16 @@ sub manage_selection { $self->{global}->{nactive}++; my $swap_name = $results->{$aix_swap_pool}->{$aix_swap_name . "." . $_}; + my $used = ($results->{$aix_swap_pool}->{$aix_swap_usage . "." . $_} * $results->{$aix_swap_pool}->{$aix_swap_total . "." . $_} / 100) + * 1024 * 1024; + my $total = $results->{$aix_swap_pool}->{$aix_swap_total . "." . $_} * 1024 * 1024; $self->{swap}->{$swap_name} = { display => $swap_name, - used => $results->{$aix_swap_pool}->{$aix_swap_usage . "." . $_}, - total => $results->{$aix_swap_pool}->{$aix_swap_total . "." . $_} * 1024 * 1024, + used => $used, + total => $total, }; - $self->{global}->{used} += $self->{swap}->{$swap_name}->{used}; - $self->{global}->{total} += $self->{swap}->{$swap_name}->{total}; + $self->{global}->{used} += $used; + $self->{global}->{total} += $total; } } } diff --git a/centreon-plugins/os/freebsd/snmp/mode/memory.pm b/centreon-plugins/os/freebsd/snmp/mode/memory.pm index 3b523b47e..fea31673f 100644 --- a/centreon-plugins/os/freebsd/snmp/mode/memory.pm +++ b/centreon-plugins/os/freebsd/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/os/hpux/local/mode/inodes.pm b/centreon-plugins/os/hpux/local/mode/inodes.pm index 4913e69ed..951169a10 100644 --- a/centreon-plugins/os/hpux/local/mode/inodes.pm +++ b/centreon-plugins/os/hpux/local/mode/inodes.pm @@ -57,7 +57,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/hpux/local/mode/storage.pm b/centreon-plugins/os/hpux/local/mode/storage.pm index 491216d70..6393fd226 100644 --- a/centreon-plugins/os/hpux/local/mode/storage.pm +++ b/centreon-plugins/os/hpux/local/mode/storage.pm @@ -126,7 +126,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, diff --git a/centreon-plugins/os/hpux/snmp/mode/cpu.pm b/centreon-plugins/os/hpux/snmp/mode/cpu.pm index 0162b4b4b..23a6ad5a8 100644 --- a/centreon-plugins/os/hpux/snmp/mode/cpu.pm +++ b/centreon-plugins/os/hpux/snmp/mode/cpu.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters' }, diff --git a/centreon-plugins/os/hpux/snmp/mode/load.pm b/centreon-plugins/os/hpux/snmp/mode/load.pm index 5c6f958d8..08c1818c3 100644 --- a/centreon-plugins/os/hpux/snmp/mode/load.pm +++ b/centreon-plugins/os/hpux/snmp/mode/load.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '' }, diff --git a/centreon-plugins/os/hpux/snmp/mode/memory.pm b/centreon-plugins/os/hpux/snmp/mode/memory.pm index 1a2f72174..00cf27edc 100644 --- a/centreon-plugins/os/hpux/snmp/mode/memory.pm +++ b/centreon-plugins/os/hpux/snmp/mode/memory.pm @@ -115,7 +115,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-counters:s" => { name => 'filter_counters' }, diff --git a/centreon-plugins/os/hpux/snmp/mode/process.pm b/centreon-plugins/os/hpux/snmp/mode/process.pm index b7b6b397f..8bbc2799e 100644 --- a/centreon-plugins/os/hpux/snmp/mode/process.pm +++ b/centreon-plugins/os/hpux/snmp/mode/process.pm @@ -39,7 +39,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/os/hpux/snmp/mode/storage.pm b/centreon-plugins/os/hpux/snmp/mode/storage.pm index c111898e3..f514a8c76 100644 --- a/centreon-plugins/os/hpux/snmp/mode/storage.pm +++ b/centreon-plugins/os/hpux/snmp/mode/storage.pm @@ -115,7 +115,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/os/linux/local/mode/cmdreturn.pm b/centreon-plugins/os/linux/local/mode/cmdreturn.pm index d4a182701..c0d587058 100644 --- a/centreon-plugins/os/linux/local/mode/cmdreturn.pm +++ b/centreon-plugins/os/linux/local/mode/cmdreturn.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/connections.pm b/centreon-plugins/os/linux/local/mode/connections.pm index e667a8e52..185da40d7 100644 --- a/centreon-plugins/os/linux/local/mode/connections.pm +++ b/centreon-plugins/os/linux/local/mode/connections.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/cpu.pm b/centreon-plugins/os/linux/local/mode/cpu.pm index a09797271..131f0e508 100644 --- a/centreon-plugins/os/linux/local/mode/cpu.pm +++ b/centreon-plugins/os/linux/local/mode/cpu.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/cpudetailed.pm b/centreon-plugins/os/linux/local/mode/cpudetailed.pm index 6b71ace8e..a8d6d6bf2 100644 --- a/centreon-plugins/os/linux/local/mode/cpudetailed.pm +++ b/centreon-plugins/os/linux/local/mode/cpudetailed.pm @@ -45,7 +45,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/directlvmusage.pm b/centreon-plugins/os/linux/local/mode/directlvmusage.pm index d7498c20b..a512ea78e 100644 --- a/centreon-plugins/os/linux/local/mode/directlvmusage.pm +++ b/centreon-plugins/os/linux/local/mode/directlvmusage.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/discoverysnmp.pm b/centreon-plugins/os/linux/local/mode/discoverysnmp.pm index bd1db6610..1d26863e4 100644 --- a/centreon-plugins/os/linux/local/mode/discoverysnmp.pm +++ b/centreon-plugins/os/linux/local/mode/discoverysnmp.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "subnet:s" => { name => 'subnet' }, "snmp-port:s" => { name => 'snmp_port', default => 161 }, diff --git a/centreon-plugins/os/linux/local/mode/diskio.pm b/centreon-plugins/os/linux/local/mode/diskio.pm index ed1c863ed..0b5203a2c 100644 --- a/centreon-plugins/os/linux/local/mode/diskio.pm +++ b/centreon-plugins/os/linux/local/mode/diskio.pm @@ -33,7 +33,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/filesdate.pm b/centreon-plugins/os/linux/local/mode/filesdate.pm index ad9a320d0..79ce4602c 100644 --- a/centreon-plugins/os/linux/local/mode/filesdate.pm +++ b/centreon-plugins/os/linux/local/mode/filesdate.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/filessize.pm b/centreon-plugins/os/linux/local/mode/filessize.pm index ef9858886..dd43db6d9 100644 --- a/centreon-plugins/os/linux/local/mode/filessize.pm +++ b/centreon-plugins/os/linux/local/mode/filessize.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/inodes.pm b/centreon-plugins/os/linux/local/mode/inodes.pm index 52e16ea49..4d7bd75bd 100644 --- a/centreon-plugins/os/linux/local/mode/inodes.pm +++ b/centreon-plugins/os/linux/local/mode/inodes.pm @@ -57,7 +57,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/listinterfaces.pm b/centreon-plugins/os/linux/local/mode/listinterfaces.pm index 70b80e998..c981ee0e5 100644 --- a/centreon-plugins/os/linux/local/mode/listinterfaces.pm +++ b/centreon-plugins/os/linux/local/mode/listinterfaces.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, diff --git a/centreon-plugins/os/linux/local/mode/listpartitions.pm b/centreon-plugins/os/linux/local/mode/listpartitions.pm index 60566c51a..427e7c6aa 100644 --- a/centreon-plugins/os/linux/local/mode/listpartitions.pm +++ b/centreon-plugins/os/linux/local/mode/listpartitions.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/liststorages.pm b/centreon-plugins/os/linux/local/mode/liststorages.pm index ba174db3f..a769da77a 100644 --- a/centreon-plugins/os/linux/local/mode/liststorages.pm +++ b/centreon-plugins/os/linux/local/mode/liststorages.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/loadaverage.pm b/centreon-plugins/os/linux/local/mode/loadaverage.pm index 6be7e9972..549b49cb2 100644 --- a/centreon-plugins/os/linux/local/mode/loadaverage.pm +++ b/centreon-plugins/os/linux/local/mode/loadaverage.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/memory.pm b/centreon-plugins/os/linux/local/mode/memory.pm index e0d08e406..3444a2d86 100644 --- a/centreon-plugins/os/linux/local/mode/memory.pm +++ b/centreon-plugins/os/linux/local/mode/memory.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/mountpoint.pm b/centreon-plugins/os/linux/local/mode/mountpoint.pm index 459ea303c..34cb7c076 100644 --- a/centreon-plugins/os/linux/local/mode/mountpoint.pm +++ b/centreon-plugins/os/linux/local/mode/mountpoint.pm @@ -73,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/ntp.pm b/centreon-plugins/os/linux/local/mode/ntp.pm index 354b733da..6485f5076 100644 --- a/centreon-plugins/os/linux/local/mode/ntp.pm +++ b/centreon-plugins/os/linux/local/mode/ntp.pm @@ -192,7 +192,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, diff --git a/centreon-plugins/os/linux/local/mode/openfiles.pm b/centreon-plugins/os/linux/local/mode/openfiles.pm new file mode 100644 index 000000000..b1d553352 --- /dev/null +++ b/centreon-plugins/os/linux/local/mode/openfiles.pm @@ -0,0 +1,181 @@ +# +# Copyright 2019 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 os::linux::local::mode::openfiles; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'files-open', nlabel => 'system.files.open.count', set => { + key_values => [ { name => 'openfiles' } ], + output_template => 'current open files: %s', + perfdatas => [ + { value => 'openfiles_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'lsof' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-a -d ^mem -d ^cwd -d ^rtd -d ^txt -d ^DEL 2>&1' }, + 'filter-username:s' => { name => 'filter_username' }, + 'filter-appname:s' => { name => 'filter_appname' }, + 'filter-pid:s' => { name => 'filter_pid' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{hostname} = $self->{option_results}->{hostname}; + if (!defined($self->{hostname})) { + $self->{hostname} = 'me'; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); + + $self->{global} = { openfiles => 0 }; + my @lines = split /\n/, $stdout; + shift @lines; + foreach (@lines) { + /^(\S+)\s+(\S+)\s+(\S+)/; + my ($name, $pid, $user) = ($1, $2, $3); + next if (defined($self->{option_results}->{filter_username}) && $self->{option_results}->{filter_username} ne '' && + $user !~ /$self->{option_results}->{filter_username}/); + next if (defined($self->{option_results}->{filter_appname}) && $self->{option_results}->{filter_appname} ne '' && + $name !~ /$self->{option_results}->{filter_appname}/); + next if (defined($self->{option_results}->{filter_pid}) && $self->{option_results}->{filter_pid} ne '' && + $pid !~ /$self->{option_results}->{filter_pid}/); + + $self->{global}->{openfiles}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check open files. + +=over 8 + +=item B<--remote> + +Execute command remotely in 'ssh'. + +=item B<--hostname> + +Hostname to query (need --remote). + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'lsof'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '-a -d ^mem -d ^cwd -d ^rtd -d ^txt -d ^DEL 2>&1'). + +=item B<--filter-appname> + +Filter application name (can be a regexp). + +=item B<--filter-username> + +Filter username name (can be a regexp). + +=item B<--filter-pid> + +Filter PID (can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'files-open'. + +=back + +=cut diff --git a/centreon-plugins/os/linux/local/mode/packeterrors.pm b/centreon-plugins/os/linux/local/mode/packeterrors.pm index af5d1c856..48b22dec1 100644 --- a/centreon-plugins/os/linux/local/mode/packeterrors.pm +++ b/centreon-plugins/os/linux/local/mode/packeterrors.pm @@ -138,7 +138,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, diff --git a/centreon-plugins/os/linux/local/mode/paging.pm b/centreon-plugins/os/linux/local/mode/paging.pm index f1af72ed4..908039cc5 100644 --- a/centreon-plugins/os/linux/local/mode/paging.pm +++ b/centreon-plugins/os/linux/local/mode/paging.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, diff --git a/centreon-plugins/os/linux/local/mode/pendingupdates.pm b/centreon-plugins/os/linux/local/mode/pendingupdates.pm index b7ad6afa8..cebc7b352 100644 --- a/centreon-plugins/os/linux/local/mode/pendingupdates.pm +++ b/centreon-plugins/os/linux/local/mode/pendingupdates.pm @@ -81,7 +81,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/process.pm b/centreon-plugins/os/linux/local/mode/process.pm index 47c5e046f..619d7b6e1 100644 --- a/centreon-plugins/os/linux/local/mode/process.pm +++ b/centreon-plugins/os/linux/local/mode/process.pm @@ -42,7 +42,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, diff --git a/centreon-plugins/os/linux/local/mode/quota.pm b/centreon-plugins/os/linux/local/mode/quota.pm index a1a3824b2..c02c64df6 100644 --- a/centreon-plugins/os/linux/local/mode/quota.pm +++ b/centreon-plugins/os/linux/local/mode/quota.pm @@ -138,7 +138,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, diff --git a/centreon-plugins/os/linux/local/mode/storage.pm b/centreon-plugins/os/linux/local/mode/storage.pm index 1cc50e19e..20ee88380 100644 --- a/centreon-plugins/os/linux/local/mode/storage.pm +++ b/centreon-plugins/os/linux/local/mode/storage.pm @@ -126,7 +126,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, diff --git a/centreon-plugins/os/linux/local/mode/swap.pm b/centreon-plugins/os/linux/local/mode/swap.pm index 0e62c1401..aed97d2ce 100644 --- a/centreon-plugins/os/linux/local/mode/swap.pm +++ b/centreon-plugins/os/linux/local/mode/swap.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/systemdscstatus.pm b/centreon-plugins/os/linux/local/mode/systemdscstatus.pm index b46ac99d1..511883ffd 100644 --- a/centreon-plugins/os/linux/local/mode/systemdscstatus.pm +++ b/centreon-plugins/os/linux/local/mode/systemdscstatus.pm @@ -107,7 +107,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/mode/traffic.pm b/centreon-plugins/os/linux/local/mode/traffic.pm index f8df4ee70..40b527317 100644 --- a/centreon-plugins/os/linux/local/mode/traffic.pm +++ b/centreon-plugins/os/linux/local/mode/traffic.pm @@ -147,7 +147,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, diff --git a/centreon-plugins/os/linux/local/mode/uptime.pm b/centreon-plugins/os/linux/local/mode/uptime.pm index 586646b7b..9fe63caf2 100644 --- a/centreon-plugins/os/linux/local/mode/uptime.pm +++ b/centreon-plugins/os/linux/local/mode/uptime.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/linux/local/plugin.pm b/centreon-plugins/os/linux/local/plugin.pm index 7fdb99f7e..ebacccbc9 100644 --- a/centreon-plugins/os/linux/local/plugin.pm +++ b/centreon-plugins/os/linux/local/plugin.pm @@ -47,6 +47,7 @@ sub new { 'list-storages' => 'os::linux::local::mode::liststorages', 'memory' => 'os::linux::local::mode::memory', 'mountpoint' => 'os::linux::local::mode::mountpoint', + 'open-files' => 'os::linux::local::mode::openfiles', 'ntp' => 'os::linux::local::mode::ntp', 'packet-errors' => 'os::linux::local::mode::packeterrors', 'paging' => 'os::linux::local::mode::paging', diff --git a/centreon-plugins/os/linux/snmp/plugin.pm b/centreon-plugins/os/linux/snmp/plugin.pm index 2f150a692..5ac58c8b9 100644 --- a/centreon-plugins/os/linux/snmp/plugin.pm +++ b/centreon-plugins/os/linux/snmp/plugin.pm @@ -31,6 +31,7 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( + 'arp' => 'snmp_standard::mode::arp', 'cpu' => 'snmp_standard::mode::cpu', 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', 'diskio' => 'snmp_standard::mode::diskio', diff --git a/centreon-plugins/os/mac/snmp/mode/memory.pm b/centreon-plugins/os/mac/snmp/mode/memory.pm index 7075f8b28..080d602a3 100644 --- a/centreon-plugins/os/mac/snmp/mode/memory.pm +++ b/centreon-plugins/os/mac/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/os/solaris/local/mode/analyzedisks.pm b/centreon-plugins/os/solaris/local/mode/analyzedisks.pm index 8d98bb7ef..4694716f3 100644 --- a/centreon-plugins/os/solaris/local/mode/analyzedisks.pm +++ b/centreon-plugins/os/solaris/local/mode/analyzedisks.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/solaris/local/mode/cpu.pm b/centreon-plugins/os/solaris/local/mode/cpu.pm index 7f70701e2..4e7fec1ed 100644 --- a/centreon-plugins/os/solaris/local/mode/cpu.pm +++ b/centreon-plugins/os/solaris/local/mode/cpu.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/solaris/local/mode/fcconnected.pm b/centreon-plugins/os/solaris/local/mode/fcconnected.pm index cc057f05c..bce3609a6 100644 --- a/centreon-plugins/os/solaris/local/mode/fcconnected.pm +++ b/centreon-plugins/os/solaris/local/mode/fcconnected.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/solaris/local/mode/fmadm.pm b/centreon-plugins/os/solaris/local/mode/fmadm.pm index de87f48db..3dbae83a5 100644 --- a/centreon-plugins/os/solaris/local/mode/fmadm.pm +++ b/centreon-plugins/os/solaris/local/mode/fmadm.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/solaris/local/mode/hwraidctl.pm b/centreon-plugins/os/solaris/local/mode/hwraidctl.pm index 626b11ad3..1ff62ced3 100644 --- a/centreon-plugins/os/solaris/local/mode/hwraidctl.pm +++ b/centreon-plugins/os/solaris/local/mode/hwraidctl.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/solaris/local/mode/hwsas2ircu.pm b/centreon-plugins/os/solaris/local/mode/hwsas2ircu.pm index 14b4c3482..d9102a41e 100644 --- a/centreon-plugins/os/solaris/local/mode/hwsas2ircu.pm +++ b/centreon-plugins/os/solaris/local/mode/hwsas2ircu.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/solaris/local/mode/lomv120.pm b/centreon-plugins/os/solaris/local/mode/lomv120.pm index 6a4a27974..30f38f3ff 100644 --- a/centreon-plugins/os/solaris/local/mode/lomv120.pm +++ b/centreon-plugins/os/solaris/local/mode/lomv120.pm @@ -20,132 +20,66 @@ package os::solaris::local::mode::lomv120; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; use centreon::plugins::misc; -use os::solaris::local::mode::lomv120components::fan; -use os::solaris::local::mode::lomv120components::psu; -use os::solaris::local::mode::lomv120components::voltage; -use os::solaris::local::mode::lomv120components::sf; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^fan|psu|voltage|sf$'; + + $self->{cb_hook2} = 'command_execute'; + + $self->{thresholds} = { + default => [ + ['^(?!(OK)$)' => 'CRITICAL'], + ], + }; + + $self->{components_exec_load} = 0; + + $self->{components_path} = 'os::solaris::local::mode::lomv120components'; + $self->{components_module} = ['fan', 'psu', 'voltage', 'sf']; +} + +sub command_execute { + my ($self, %options) = @_; + + ($self->{stdout}) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + no_quit => 1 + ); +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'lom' }, - "command-path:s" => { name => 'command_path', default => '/usr/sbin' }, - "command-options:s" => { name => 'command_options', default => '-fpv 2>&1'}, - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "no-component:s" => { name => 'no_component' }, - }); - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'lom' }, + 'command-path:s' => { name => 'command_path', default => '/usr/sbin' }, + 'command-options:s' => { name => 'command_options', default => '-fpv 2>&1'}, + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } -} - -sub component { - my ($self, %options) = @_; - - if ($self->{option_results}->{component} eq 'all') { - os::solaris::local::mode::lomv120components::fan::check($self); - os::solaris::local::mode::lomv120components::psu::check($self); - os::solaris::local::mode::lomv120components::voltage::check($self); - os::solaris::local::mode::lomv120components::sf::check($self); - } elsif ($self->{option_results}->{component} eq 'fan') { - os::solaris::local::mode::lomv120components::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - os::solaris::local::mode::lomv120components::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'voltage') { - os::solaris::local::mode::lomv120components::voltage::check($self); - } elsif ($self->{option_results}->{component} eq 'sf') { - os::solaris::local::mode::lomv120components::sf::check($self); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components [%s] are ok.", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } -} - -sub run { - my ($self, %options) = @_; - - ($self->{stdout}) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}, - no_quit => 1); - $self->component(); - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - 1; __END__ @@ -199,19 +133,25 @@ Command options (Default: '-fpv 2>&1'). =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'fan', 'psu', 'voltage', 'sf'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fan,sf) -Can also exclude specific instance: --exclude=fan#1#,sf +Exclude some parts (comma seperated list) (Example: --filter=fan) +Can also exclude specific instance: --filter=fan,1 =item B<--no-component> Return an error if no compenents are checked. If total (with skipped) is 0. (Default: 'critical' returns). +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,WARNING,^(?!(ok)$)' + =back =cut diff --git a/centreon-plugins/os/solaris/local/mode/lomv120components/fan.pm b/centreon-plugins/os/solaris/local/mode/lomv120components/fan.pm index bff26f283..73161bf42 100644 --- a/centreon-plugins/os/solaris/local/mode/lomv120components/fan.pm +++ b/centreon-plugins/os/solaris/local/mode/lomv120components/fan.pm @@ -23,16 +23,12 @@ package os::solaris::local::mode::lomv120components::fan; use strict; use warnings; -my %conditions = ( - 1 => ['^(?!(OK)$)' => 'CRITICAL'], -); - sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking fans"); $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fan')); + return if ($self->check_filter(section => 'fan')); #Fans: #1 FAULT speed 0% @@ -48,21 +44,22 @@ sub check { next if ($line !~ /^\s*(\S+)\s+(\S+)/); my ($instance, $status) = ($1, $2); - next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s.", - $instance, $status) - ); - foreach (keys %conditions) { - if ($status =~ /${$conditions{$_}}[0]/i) { - $self->{output}->output_add(severity => ${$conditions{$_}}[1], - short_msg => sprintf("fan '%s' status is %s", - $instance, $status)); - last; - } + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is %s.", + $instance, $status + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'fan', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("fan '%s' status is %s", + $instance, $status)); } } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/os/solaris/local/mode/lomv120components/psu.pm b/centreon-plugins/os/solaris/local/mode/lomv120components/psu.pm index 2685b6a2b..9e2891a44 100644 --- a/centreon-plugins/os/solaris/local/mode/lomv120components/psu.pm +++ b/centreon-plugins/os/solaris/local/mode/lomv120components/psu.pm @@ -23,16 +23,12 @@ package os::solaris::local::mode::lomv120components::psu; use strict; use warnings; -my %conditions = ( - 1 => ['^(?!(OK)$)' => 'CRITICAL'], -); - sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking power supplies"); $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); + return if ($self->check_filter(section => 'psu')); #PSUs: #1 OK @@ -44,21 +40,22 @@ sub check { next if ($line !~ /^\s*(\S+)\s+(\S+)/); my ($instance, $status) = ($1, $2); - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("psu '%s' status is %s.", - $instance, $status) - ); - foreach (keys %conditions) { - if ($status =~ /${$conditions{$_}}[0]/i) { - $self->{output}->output_add(severity => ${$conditions{$_}}[1], - short_msg => sprintf("psu '%s' status is %s", - $instance, $status)); - last; - } + $self->{output}->output_add( + long_msg => sprintf( + "psu '%s' status is %s.", + $instance, $status + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("psu '%s' status is %s", + $instance, $status)); } } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/os/solaris/local/mode/lomv120components/sf.pm b/centreon-plugins/os/solaris/local/mode/lomv120components/sf.pm index 9921f8234..afcbacaba 100644 --- a/centreon-plugins/os/solaris/local/mode/lomv120components/sf.pm +++ b/centreon-plugins/os/solaris/local/mode/lomv120components/sf.pm @@ -24,16 +24,12 @@ use strict; use warnings; use centreon::plugins::misc; -my %conditions = ( - 1 => ['^(?!(ok)$)' => 'CRITICAL'], -); - sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking system flag"); $self->{components}->{sf} = {name => 'system flag', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'sf')); + return if ($self->check_filter(section => 'sf')); #System status flags: # 1 SCSI-Term status=ok @@ -48,21 +44,22 @@ sub check { next if ($line !~ /^\s*(\S+).*?status=(.*)/); my ($instance, $status) = ($1, $2); - next if ($self->check_exclude(section => 'sf', instance => $instance)); + next if ($self->check_filter(section => 'sf', instance => $instance)); $self->{components}->{sf}->{total}++; - $self->{output}->output_add(long_msg => sprintf("System flag '%s' status is %s.", - $instance, $status) - ); - foreach (keys %conditions) { - if ($status =~ /${$conditions{$_}}[0]/i) { - $self->{output}->output_add(severity => ${$conditions{$_}}[1], - short_msg => sprintf("System flag '%s' status is %s", - $instance, $status)); - last; - } + $self->{output}->output_add( + long_msg => sprintf( + "system flag '%s' status is %s.", + $instance, $status + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'sf', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("system flag '%s' status is %s", + $instance, $status)); } } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/os/solaris/local/mode/lomv120components/voltage.pm b/centreon-plugins/os/solaris/local/mode/lomv120components/voltage.pm index 199eaaa4d..c7d2e8695 100644 --- a/centreon-plugins/os/solaris/local/mode/lomv120components/voltage.pm +++ b/centreon-plugins/os/solaris/local/mode/lomv120components/voltage.pm @@ -24,16 +24,12 @@ use strict; use warnings; use centreon::plugins::misc; -my %conditions = ( - 1 => ['^(?!(ok)$)' => 'CRITICAL'], -); - sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking supply voltages"); $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'voltage')); + return if ($self->check_filter(section => 'voltage')); #Supply voltages: #1 5V status=ok @@ -48,21 +44,22 @@ sub check { next if ($line !~ /^\s*(\S+).*?status=(.*)/); my ($instance, $status) = ($1, $2); - next if ($self->check_exclude(section => 'voltage', instance => $instance)); + next if ($self->check_filter(section => 'voltage', instance => $instance)); $self->{components}->{voltage}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Supply voltage '%s' status is %s.", - $instance, $status) - ); - foreach (keys %conditions) { - if ($status =~ /${$conditions{$_}}[0]/i) { - $self->{output}->output_add(severity => ${$conditions{$_}}[1], - short_msg => sprintf("Supply voltage '%s' status is %s", - $instance, $status)); - last; - } + $self->{output}->output_add( + long_msg => sprintf( + "Supply voltage '%s' status is %s.", + $instance, $status + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'voltage', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("supply voltage '%s' status is %s", + $instance, $status)); } } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/os/solaris/local/mode/lomv1280.pm b/centreon-plugins/os/solaris/local/mode/lomv1280.pm index defe69fdf..fb6f5f748 100644 --- a/centreon-plugins/os/solaris/local/mode/lomv1280.pm +++ b/centreon-plugins/os/solaris/local/mode/lomv1280.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/solaris/local/mode/prtdiag.pm b/centreon-plugins/os/solaris/local/mode/prtdiag.pm index 50d664056..070899911 100644 --- a/centreon-plugins/os/solaris/local/mode/prtdiag.pm +++ b/centreon-plugins/os/solaris/local/mode/prtdiag.pm @@ -34,7 +34,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/solaris/local/mode/svmdisks.pm b/centreon-plugins/os/solaris/local/mode/svmdisks.pm index fa67b41c3..b40a9de0e 100644 --- a/centreon-plugins/os/solaris/local/mode/svmdisks.pm +++ b/centreon-plugins/os/solaris/local/mode/svmdisks.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/solaris/local/mode/vxdisks.pm b/centreon-plugins/os/solaris/local/mode/vxdisks.pm index c1a01a8c8..a2038494f 100644 --- a/centreon-plugins/os/solaris/local/mode/vxdisks.pm +++ b/centreon-plugins/os/solaris/local/mode/vxdisks.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/os/windows/local/conf/qwinsta.xml b/centreon-plugins/os/windows/local/conf/qwinsta.xml index d3c842101..3471260a3 100644 --- a/centreon-plugins/os/windows/local/conf/qwinsta.xml +++ b/centreon-plugins/os/windows/local/conf/qwinsta.xml @@ -5,6 +5,7 @@ Total sessions disconnected Total sessions reconnected Active + Disc SESSIONNAME STATE @@ -13,6 +14,7 @@ Nombre total de sessions d.*?connect.*?es Nombre total de sessions reconnect.*?es Actif + D.*?co SESSION ^.*?TAT diff --git a/centreon-plugins/os/windows/local/mode/cmdreturn.pm b/centreon-plugins/os/windows/local/mode/cmdreturn.pm index 867d51123..0c2689f55 100644 --- a/centreon-plugins/os/windows/local/mode/cmdreturn.pm +++ b/centreon-plugins/os/windows/local/mode/cmdreturn.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-time:s" => { name => 'warning_time' }, diff --git a/centreon-plugins/os/windows/local/mode/liststorages.pm b/centreon-plugins/os/windows/local/mode/liststorages.pm index 6ed0474cb..fbee6ae7a 100644 --- a/centreon-plugins/os/windows/local/mode/liststorages.pm +++ b/centreon-plugins/os/windows/local/mode/liststorages.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { diff --git a/centreon-plugins/os/windows/local/mode/ntp.pm b/centreon-plugins/os/windows/local/mode/ntp.pm index dae5b5453..630dae824 100644 --- a/centreon-plugins/os/windows/local/mode/ntp.pm +++ b/centreon-plugins/os/windows/local/mode/ntp.pm @@ -36,7 +36,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'ntp-hostname:s' => { name => 'ntp_hostname' }, 'ntp-port:s' => { name => 'ntp_port', default => 123 }, diff --git a/centreon-plugins/os/windows/local/mode/pendingreboot.pm b/centreon-plugins/os/windows/local/mode/pendingreboot.pm index acbe652db..051f2e846 100644 --- a/centreon-plugins/os/windows/local/mode/pendingreboot.pm +++ b/centreon-plugins/os/windows/local/mode/pendingreboot.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "timeout:s" => { name => 'timeout', default => 50 }, diff --git a/centreon-plugins/os/windows/local/mode/sessions.pm b/centreon-plugins/os/windows/local/mode/sessions.pm index ed5649292..27f4b7123 100644 --- a/centreon-plugins/os/windows/local/mode/sessions.pm +++ b/centreon-plugins/os/windows/local/mode/sessions.pm @@ -35,38 +35,47 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'sessions-created', set => { + { label => 'sessions-created', nlabel => 'sessions.created.total.count', set => { key_values => [ { name => 'sessions_created', diff => 1 } ], - output_template => 'Created : %s', + output_template => 'created : %s', perfdatas => [ { label => 'sessions_created', value => 'sessions_created_absolute', template => '%s', min => 0 }, ], } }, - { label => 'sessions-disconnected', set => { + { label => 'sessions-disconnected', nlabel => 'sessions.disconnected.total.count', set => { key_values => [ { name => 'sessions_disconnected', diff => 1 } ], - output_template => 'Disconnected : %s', + output_template => 'disconnected : %s', perfdatas => [ { label => 'sessions_disconnected', value => 'sessions_disconnected_absolute', template => '%s', min => 0 }, ], } }, - { label => 'sessions-reconnected', set => { + { label => 'sessions-reconnected', nlabel => 'sessions.reconnected.total.count', set => { key_values => [ { name => 'sessions_reconnected', diff => 1 } ], - output_template => 'Reconnected : %s', + output_template => 'reconnected : %s', perfdatas => [ { label => 'sessions_reconnected', value => 'sessions_reconnected_absolute', template => '%s', min => 0 }, ], } }, - { label => 'sessions-active', set => { + { label => 'sessions-active', nlabel => 'sessions.active.current.count', set => { key_values => [ { name => 'sessions_active' } ], - output_template => 'Active : %s', + output_template => 'current active : %s', perfdatas => [ { label => 'sessions_active', value => 'sessions_active_absolute', template => '%s', min => 0 }, ], } }, + { label => 'sessions-disconnected-current', nlabel => 'sessions.disconnected.current.count', set => { + key_values => [ { name => 'sessions_disconnected_current' } ], + output_template => 'current disconnected : %s', + perfdatas => [ + { label => 'sessions_disconnected_current', value => 'sessions_disconnected_current_absolute', + template => '%s', min => 0 }, + ], + } + }, ]; } @@ -81,17 +90,15 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "command:s" => { name => 'command', default => 'qwinsta' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '/COUNTER' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "filter-sessionname:s" => { name => 'filter_sessionname' }, - "config:s" => { name => 'config' }, - "language:s" => { name => 'language', default => 'en' }, - }); + $options{options}->add_options(arguments => { + 'command:s' => { name => 'command', default => 'qwinsta' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '/COUNTER' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'filter-sessionname:s' => { name => 'filter_sessionname' }, + 'config:s' => { name => 'config' }, + 'language:s' => { name => 'language', default => 'en' }, + }); return $self; } @@ -204,16 +211,18 @@ sub manage_selection { my ($self, %options) = @_; my $config = $self->read_config(); - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); my $datas = $self->read_qwinsta(stdout => $stdout, config => $config); my $counters = $self->read_qwinsta_counters(stdout => $stdout, config => $config); - my $active = 0; + my ($active, $disconnected) = (0, 0); foreach my $session (@$datas) { if (defined($self->{option_results}->{filter_sessionname}) && $self->{option_results}->{filter_sessionname} ne '' && $session->{$config->{header_sessionname}} !~ /$self->{option_results}->{filter_sessionname}/) { @@ -221,21 +230,24 @@ sub manage_selection { next; } - my $matching = 0; + my ($matching_active, $matching_discon) = (0, 0); foreach my $label (keys %$session) { - $matching = 1 if ($label =~ /$config->{header_state}/ && - $session->{$label} =~ /$config->{activestate}/); + $matching_active = 1 if ($label =~ /$config->{header_state}/ && + $session->{$label} =~ /$config->{activestate}/); + $matching_discon = 1 if ($label =~ /$config->{header_state}/ && + $session->{$label} =~ /$config->{disconnectedstate}/); } - if ($matching == 1) { - $active++; + if ($matching_active == 1 || $matching_discon == 1) { + $active++ if ($matching_active == 1); + $disconnected++ if ($matching_discon == 1); my $output = ''; $output .= " [$_ => $session->{$_}]" for (sort keys %$session); $self->{output}->output_add(long_msg => $output); } } - $self->{global} = { %$counters, sessions_active => $active }; + $self->{global} = { %$counters, sessions_active => $active, sessions_disconnected_current => $disconnected }; $self->{cache_name} = "windows_" . $self->{mode} . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . @@ -282,17 +294,11 @@ Timeout in seconds for the command (Default: 30). Filter session name (can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. Can be: 'sessions-created', 'sessions-disconnected', -'sessions-reconnected', 'sessions-active'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'sessions-created', 'sessions-disconnected', -'sessions-reconnected', 'sessions-active'. +'sessions-reconnected', 'sessions-active', 'sessions-disconnected-current'. =back diff --git a/centreon-plugins/os/windows/snmp/mode/memory.pm b/centreon-plugins/os/windows/snmp/mode/memory.pm index 61fbb4bfc..f187990ed 100644 --- a/centreon-plugins/os/windows/snmp/mode/memory.pm +++ b/centreon-plugins/os/windows/snmp/mode/memory.pm @@ -115,7 +115,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, diff --git a/centreon-plugins/os/windows/snmp/mode/service.pm b/centreon-plugins/os/windows/snmp/mode/service.pm index d1e4c8888..0902acf79 100644 --- a/centreon-plugins/os/windows/snmp/mode/service.pm +++ b/centreon-plugins/os/windows/snmp/mode/service.pm @@ -43,7 +43,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, @@ -83,7 +82,7 @@ sub run { my $oid_svSvcName = '.1.3.6.1.4.1.77.1.2.3.1.1'; my $oid_svSvcInstalledState = '.1.3.6.1.4.1.77.1.2.3.1.2'; my $oid_svSvcOperatingState = '.1.3.6.1.4.1.77.1.2.3.1.3'; - my $result = $self->{snmp}->get_table(oid => $oid_svSvcEntry); + my $result = $self->{snmp}->get_table(oid => $oid_svSvcEntry, start => $oid_svSvcName, end => $oid_svSvcOperatingState); my %services_match = (); $self->{output}->output_add(severity => 'OK', diff --git a/centreon-plugins/os/windows/snmp/mode/swap.pm b/centreon-plugins/os/windows/snmp/mode/swap.pm index f074bf3fd..a086a469b 100644 --- a/centreon-plugins/os/windows/snmp/mode/swap.pm +++ b/centreon-plugins/os/windows/snmp/mode/swap.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/os/windows/wsman/mode/listservices.pm b/centreon-plugins/os/windows/wsman/mode/listservices.pm index ab6e5ca50..4751538bd 100644 --- a/centreon-plugins/os/windows/wsman/mode/listservices.pm +++ b/centreon-plugins/os/windows/wsman/mode/listservices.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s" => { name => 'name' }, diff --git a/centreon-plugins/os/windows/wsman/mode/service.pm b/centreon-plugins/os/windows/wsman/mode/service.pm index b209d5de3..03e303fe6 100644 --- a/centreon-plugins/os/windows/wsman/mode/service.pm +++ b/centreon-plugins/os/windows/wsman/mode/service.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning" => { name => 'warning', }, diff --git a/centreon-plugins/snmp_standard/mode/arp.pm b/centreon-plugins/snmp_standard/mode/arp.pm new file mode 100644 index 000000000..e73b9a989 --- /dev/null +++ b/centreon-plugins/snmp_standard/mode/arp.pm @@ -0,0 +1,156 @@ +# +# Copyright 2019 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 snmp_standard::mode::arp; + +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, message_separator => ' - ' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-entries', nlabel => 'arp.total.entries.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'total entries %s', + perfdatas => [ + { value => 'total_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'duplicate-macaddr', nlabel => 'arp.duplicate.macaddr.count', set => { + key_values => [ { name => 'duplicate_macaddress' } ], + output_template => 'duplicate mac address %s', + perfdatas => [ + { value => 'duplicate_macaddress_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'duplicate-ipaddr', nlabel => 'arp.duplicate.ipaddr.count', set => { + key_values => [ { name => 'duplicate_ipaddress' } ], + output_template => 'duplicate ip address %s', + perfdatas => [ + { value => 'duplicate_ipaddress_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub check_ipNetToMediaTable { + my ($self, %options) = @_; + + my $oid_ipNetToMediaPhysAddress = '.1.3.6.1.2.1.4.22.1.2'; + my $result = $options{snmp}->get_table(oid => $oid_ipNetToMediaPhysAddress); + return if (scalar(keys %$result) <= 0); + + $self->check_arp(result => $result, oid => $oid_ipNetToMediaPhysAddress); +} + +sub check_atTable { + my ($self, %options) = @_; + + return if (defined($self->{global})); + + my $oid_atPhysAddress = '.1.3.6.1.2.1.4.22.1.2'; + my $result = $options{snmp}->get_table(oid => $oid_atPhysAddress, nothing_quit => 1); + $self->check_arp(result => $result, oid => $oid_atPhysAddress); +} + +sub check_arp { + my ($self, %options) = @_; + + $self->{global} = { total => 0, duplicate_macaddress => 0, duplicate_ipaddress => 0 }; + my $duplicate = { mac => { }, ip => {} }; + foreach (keys %{$options{result}}) { + $self->{global}->{total}++; + my $mac = join(':', unpack('(H2)*', $options{result}->{$_})); + /^$options{oid}\.(\d+)\.(.*)$/; + $duplicate->{ip}->{$2} = [] if (!defined($duplicate->{ip}->{$2})); + push @{$duplicate->{ip}->{$2}}, $mac; + $duplicate->{mac}->{$mac} = [] if (!defined($duplicate->{mac}->{$mac})); + push @{$duplicate->{mac}->{$mac}}, $2; + } + + $self->test_duplicate(duplicate => $duplicate); +} + +sub test_duplicate { + my ($self, %options) = @_; + + foreach (keys %{$options{duplicate}->{ip}}) { + next if (scalar(@{$options{duplicate}->{ip}->{$_}}) == 1); + $self->{global}->{duplicate_ipaddress}++; + $self->{output}->output_add(long_msg => + sprintf("ip address '%s' ==> mac address: %s", $_, join(' ', @{$options{duplicate}->{ip}->{$_}})) + ); + } + + foreach (keys %{$options{duplicate}->{mac}}) { + next if (scalar(@{$options{duplicate}->{mac}->{$_}}) == 1); + $self->{global}->{duplicate_macaddress}++; + $self->{output}->output_add(long_msg => + sprintf("mac address '%s' ==> ip address: %s", $_, join(' ', @{$options{duplicate}->{mac}->{$_}})) + ); + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->check_ipNetToMediaTable(%options); + $self->check_atTable(%options); +} + +1; + +__END__ + +=head1 MODE + +Check arp table. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total-entries', 'duplicate-macaddr', 'duplicate-ipaddr'. + +=back + +=cut diff --git a/centreon-plugins/snmp_standard/mode/cpu.pm b/centreon-plugins/snmp_standard/mode/cpu.pm index beed16c03..8f508b455 100644 --- a/centreon-plugins/snmp_standard/mode/cpu.pm +++ b/centreon-plugins/snmp_standard/mode/cpu.pm @@ -76,7 +76,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/snmp_standard/mode/cpudetailed.pm b/centreon-plugins/snmp_standard/mode/cpudetailed.pm index 7264536dc..a8e58b62e 100644 --- a/centreon-plugins/snmp_standard/mode/cpudetailed.pm +++ b/centreon-plugins/snmp_standard/mode/cpudetailed.pm @@ -211,7 +211,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/snmp_standard/mode/diskio.pm b/centreon-plugins/snmp_standard/mode/diskio.pm index 87b8934e7..737551210 100644 --- a/centreon-plugins/snmp_standard/mode/diskio.pm +++ b/centreon-plugins/snmp_standard/mode/diskio.pm @@ -150,7 +150,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name" => { name => 'use_name' }, diff --git a/centreon-plugins/snmp_standard/mode/diskusage.pm b/centreon-plugins/snmp_standard/mode/diskusage.pm index 7841bd3af..ca8a72c11 100644 --- a/centreon-plugins/snmp_standard/mode/diskusage.pm +++ b/centreon-plugins/snmp_standard/mode/diskusage.pm @@ -161,7 +161,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, diff --git a/centreon-plugins/snmp_standard/mode/dynamiccommand.pm b/centreon-plugins/snmp_standard/mode/dynamiccommand.pm index 8f657081c..adbfb6b24 100644 --- a/centreon-plugins/snmp_standard/mode/dynamiccommand.pm +++ b/centreon-plugins/snmp_standard/mode/dynamiccommand.pm @@ -41,7 +41,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "label:s" => { name => 'label' }, diff --git a/centreon-plugins/snmp_standard/mode/entity.pm b/centreon-plugins/snmp_standard/mode/entity.pm index b234d1909..cae44837e 100644 --- a/centreon-plugins/snmp_standard/mode/entity.pm +++ b/centreon-plugins/snmp_standard/mode/entity.pm @@ -50,7 +50,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "sensor-scale" => { name => 'sensor_scale' }, diff --git a/centreon-plugins/snmp_standard/mode/hardwaredevice.pm b/centreon-plugins/snmp_standard/mode/hardwaredevice.pm index 441d40417..042fdb605 100644 --- a/centreon-plugins/snmp_standard/mode/hardwaredevice.pm +++ b/centreon-plugins/snmp_standard/mode/hardwaredevice.pm @@ -51,7 +51,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/snmp_standard/mode/hardwarefibrealliance.pm b/centreon-plugins/snmp_standard/mode/hardwarefibrealliance.pm index 87ab3e9a4..c4c8c7dd6 100644 --- a/centreon-plugins/snmp_standard/mode/hardwarefibrealliance.pm +++ b/centreon-plugins/snmp_standard/mode/hardwarefibrealliance.pm @@ -20,38 +20,103 @@ package snmp_standard::mode::hardwarefibrealliance; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my %oids = ( - connUnitSensorName => '.1.3.6.1.3.94.1.8.1.3', - connUnitSensorStatus => '.1.3.6.1.3.94.1.8.1.4', - connUnitSensorMessage => '.1.3.6.1.3.94.1.8.1.6', - connUnitSensorType => '.1.3.6.1.3.94.1.8.1.7', - connUnitSensorCharacteristic => '.1.3.6.1.3.94.1.8.1.8', - - connUnitPortName => '.1.3.6.1.3.94.1.10.1.17', - connUnitPortStatus => '.1.3.6.1.3.94.1.10.1.7', -); +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(sensors|port)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + sensors => [ + ['unknown', 'UNKNOWN'], + ['other', 'UNKNOWN'], + ['warning', 'WARNING'], + ['failed', 'CRITICAL'], + ['ok', 'OK'], + ], + port => [ + ['warning', 'WARNING'], + ['failure', 'CRITICAL'], + ['unused', 'OK'], + ['initializing', 'OK'], + ['ready', 'OK'], + ['.*', 'UNKNOWN'], + ], + }; + + $self->{components_path} = 'snmp_standard::mode::components'; + $self->{components_module} = ['sensors', 'port']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, + no_absent => 1, no_performance => 1, no_load_components => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +1; + +=head1 MODE + +Check status of SAN Hardware (Following FibreAlliance MIB: MIB40) +http://www.emc.com/microsites/fibrealliance/index.htm + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'sensors', 'port'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=sensors,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='sensors,CRITICAL,^(?!(ok)$)' + +=back + +=cut + +package snmp_standard::mode::components::sensors; + +use strict; +use warnings; my %map_sensor_status = ( - 1 => 'unknown', - 2 => 'other', - 3 => 'ok', - 4 => 'warning', + 1 => 'unknown', 2 => 'other', + 3 => 'ok', 4 => 'warning', 5 => 'failed', ); -my %map_port_status = ( - 1 => 'unknown', 2 => 'unused', - 3 => 'ready', 4 => 'warning', - 5 => 'failure', 6 => 'notparticipating', - 7 => 'initializing', 8 => 'bypass', - 9 => 'ols', 10 => 'other', -); - my %map_sensor_type = ( 1 => 'unknown', 2 => 'other', 3 => 'battery', 4 => 'fan', @@ -66,259 +131,96 @@ my %map_sensor_chara = ( 8 => 'frequency', 9 => 'power', 10 => 'door', ); -my $thresholds = { - sensors => [ - ['unknown', 'UNKNOWN'], - ['other', 'UNKNOWN'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['ok', 'OK'], - ], - port => [ - ['warning', 'WARNING'], - ['failure', 'CRITICAL'], - ['unused', 'OK'], - ['initializing', 'OK'], - ['ready', 'OK'], - ['.*', 'UNKNOWN'], - ], +my $mapping = { + connUnitSensorName => { oid => '.1.3.6.1.3.94.1.8.1.3' }, + connUnitSensorStatus => { oid => '.1.3.6.1.3.94.1.8.1.4', map => \%map_sensor_status }, + connUnitSensorMessage => { oid => '.1.3.6.1.3.94.1.8.1.6' }, + connUnitSensorType => { oid => '.1.3.6.1.3.94.1.8.1.7', map => \%map_sensor_type }, + connUnitSensorCharacteristic => { oid => '.1.3.6.1.3.94.1.8.1.8', map => \%map_sensor_chara }, }; +my $oid_connUnitSensorEntry = '.1.3.6.1.3.94.1.8.1'; -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 => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - - $self->{components} = {}; - $self->{no_components} = undef; - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } -} - -sub component { - my ($self, %options) = @_; - - if ($self->{option_results}->{component} eq 'all') { - $self->check_sensors(); - $self->check_port(); - } elsif ($self->{option_results}->{component} eq 'sensors') { - $self->check_sensors(); - } elsif ($self->{option_results}->{component} eq 'port') { - $self->check_port(); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components [%s] are ok.", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oids{connUnitSensorName} }, - { oid => $oids{connUnitSensorStatus} }, - { oid => $oids{connUnitSensorMessage} }, - { oid => $oids{connUnitSensorType} }, - { oid => $oids{connUnitSensorCharacteristic} }, - { oid => $oids{connUnitPortName} }, - { oid => $oids{connUnitPortStatus} }, - ]); - $self->component(); - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - -sub check_sensors { +sub load { my ($self) = @_; - $self->{output}->output_add(long_msg => "Checking sensors"); + push @{$self->{request}}, { oid => $oid_connUnitSensorEntry, start => $mapping->{connUnitSensorName}->{oid}, end => $mapping->{connUnitSensorCharacteristic}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking sensors"); $self->{components}->{sensors} = {name => 'sensors', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'sensors')); + return if ($self->check_filter(section => 'sensors')); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oids{connUnitSensorName}}})) { - $key =~ /^$oids{connUnitSensorName}\.(.*)/; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_connUnitSensorEntry}})) { + next if ($oid !~ /^$mapping->{connUnitSensorName}->{oid}\.(.*)$/); my $instance = $1; - my $name = $self->{results}->{ $oids{connUnitSensorName} }->{$key}; - my $status = defined($self->{results}->{$oids{connUnitSensorStatus}}->{$oids{connUnitSensorStatus} . '.' . $instance}) ? - $self->{results}->{$oids{connUnitSensorStatus}}->{$oids{connUnitSensorStatus} . '.' . $instance} : 1; - my $msg = defined($self->{results}->{$oids{connUnitSensorMessage}}->{$oids{connUnitSensorMessage} . '.' . $instance}) ? - $self->{results}->{$oids{connUnitSensorMessage}}->{$oids{connUnitSensorMessage} . '.' . $instance} : 1; - my $type = defined($self->{results}->{$oids{connUnitSensorType}}->{$oids{connUnitSensorType} . '.' . $instance}) ? - $self->{results}->{$oids{connUnitSensorType}}->{$oids{connUnitSensorType} . '.' . $instance} : 1; - my $chara = defined($self->{results}->{$oids{connUnitSensorCharacteristic}}->{$oids{connUnitSensorCharacteristic} . '.' . $instance}) ? - $self->{results}->{$oids{connUnitSensorCharacteristic}}->{$oids{connUnitSensorCharacteristic} . '.' . $instance} : 1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_connUnitSensorEntry}, instance => $instance); - next if ($self->check_exclude(section => 'sensors', instance => $name)); + next if ($self->check_filter(section => 'sensors', instance => $instance, name => $result->{connUnitSensorName})); $self->{components}->{sensors}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Sensor '%s' status is %s [msg = %s] [type = %s] [chara = %s]", - $name, $map_sensor_status{$status}, $msg, $map_sensor_type{$type}, $map_sensor_chara{$chara})); - my $exit = $self->get_severity(section => 'sensors', value => $map_sensor_status{$status}); + $self->{output}->output_add(long_msg => sprintf( + "sensor '%s' status is %s [msg: %s] [type: %s] [chara: %s] [instance: %s]", + $result->{connUnitSensorName}, $result->{connUnitSensorStatus}, + $result->{connUnitSensorMessage}, $result->{connUnitSensorType}, $result->{connUnitSensorCharacteristic}, $instance) + ); + my $exit = $self->get_severity(section => 'sensors', name => $result->{connUnitSensorName}, value => $result->{connUnitSensorStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => "Sensor '" . $name . "' status is " . $map_sensor_status{$status}); + short_msg => "Sensor '%s' status is %s", $result->{connUnitSensorName}, $result->{connUnitSensorStatus}); } } } -sub check_port { +package snmp_standard::mode::components::port; + +use strict; +use warnings; + +my %map_port_status = ( + 1 => 'unknown', 2 => 'unused', + 3 => 'ready', 4 => 'warning', + 5 => 'failure', 6 => 'notparticipating', + 7 => 'initializing', 8 => 'bypass', + 9 => 'ols', 10 => 'other', +); + +my $mapping_port = { + connUnitPortName => { oid => '.1.3.6.1.3.94.1.10.1.17' }, + connUnitPortStatus => { oid => '.1.3.6.1.3.94.1.10.1.7', map => \%map_port_status }, +}; + +sub load { my ($self) = @_; - $self->{output}->output_add(long_msg => "Checking ports"); - $self->{components}->{port} = {name => 'ports', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'port')); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oids{connUnitPortName}}})) { - $key =~ /^$oids{connUnitPortName}\.(.*)/; - my $instance = $1; - my $name = $self->{results}->{ $oids{connUnitPortName} }->{$key}; - my $status = defined($self->{results}->{$oids{connUnitPortStatus}}->{$oids{connUnitPortStatus} . '.' . $instance}) ? - $self->{results}->{$oids{connUnitPortStatus}}->{$oids{connUnitPortStatus} . '.' . $instance} : 1; + push @{$self->{request}}, { oid => $mapping_port->{connUnitPortName}->{oid} }, { oid => $mapping_port->{connUnitPortStatus}->{oid} }; +} - next if ($self->check_exclude(section => 'port', instance => $name)); +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking ports"); + $self->{components}->{port} = {name => 'ports', total => 0, skip => 0}; + return if ($self->check_filter(section => 'port')); + + + foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_port->{connUnitPortName}->{oid} }})) { + $key =~ /^$mapping_port->{connUnitPortName}->{oid}\.(.*)/; + my $instance = $1; + my $name = $self->{results}->{ $mapping_port->{connUnitPortName}->{oid} }->{$key}; + my $result = $self->{snmp}->map_instance(mapping => $mapping_port, results => $self->{results}->{ $mapping_port->{connUnitPortStatus}->{oid} }, instance => $instance); + + next if ($self->check_filter(section => 'port', instance => $instance, name => $name)); $self->{components}->{port}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Port '%s' status is %s", - $name, $map_port_status{$status})); - my $exit = $self->get_severity(section => 'port', value => $map_port_status{$status}); + $self->{output}->output_add(long_msg => sprintf("port '%s' status is %s [instance: %s]", + $name, $result->{connUnitPortStatus}, $instance)); + my $exit = $self->get_severity(section => 'port', name => $name, value => $result->{connUnitPortStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => "Port '" . $name . "' status is " . $map_port_status{$status}); + short_msg => sprintf("Port '%s' status is %s", $name, $result->{connUnitPortStatus})); } } } - -1; - -__END__ - -=head1 MODE - -Check status of SAN Hardware (Following FibreAlliance MIB: MIB40) -http://www.emc.com/microsites/fibrealliance/index.htm - -=over 8 - -=item B<--component> - -Which component to check (Default: 'all'). -Can be: 'sensors', 'port'. - -=item B<--exclude> - -Exclude some parts (comma seperated list) (Example: --exclude=port) -Can also exclude specific instance: --exclude='sensors#Temperature Loc:upper-IOM A#' - -=item B<--no-component> - -Return an error if no compenents are checked. -If total (with skipped) is 0. (Default: 'critical' returns). - -=item B<--threshold-overload> - -Set to overload default threshold values (syntax: section,status,regexp) -It used before default thresholds (order stays). -Example: --threshold-overload='sensors,CRITICAL,^(?!(ok)$)' - -=back - -=cut diff --git a/centreon-plugins/snmp_standard/mode/inodes.pm b/centreon-plugins/snmp_standard/mode/inodes.pm index cee88b73d..548a13fb6 100644 --- a/centreon-plugins/snmp_standard/mode/inodes.pm +++ b/centreon-plugins/snmp_standard/mode/inodes.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'name' => { name => 'use_name' }, 'diskpath:s' => { name => 'diskpath' }, diff --git a/centreon-plugins/snmp_standard/mode/interfaces.pm b/centreon-plugins/snmp_standard/mode/interfaces.pm index d9301749e..961e092a3 100644 --- a/centreon-plugins/snmp_standard/mode/interfaces.pm +++ b/centreon-plugins/snmp_standard/mode/interfaces.pm @@ -65,13 +65,13 @@ sub custom_status_output { if (defined($self->{instance_mode}->{option_results}->{add_duplex_status})) { $msg .= ' (duplex: ' . $self->{result_values}->{duplexstatus} . ')'; } - + 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}->{duplexstatus} = $options{new_datas}->{$self->{instance} . '_duplexstatus'}; @@ -776,7 +776,6 @@ sub new { $self->{no_interfaceid_options} = defined($options{no_interfaceid_options}) && $options{no_interfaceid_options} =~ /^[01]$/ ? $options{no_interfaceid_options} : 0; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'add-global' => { name => 'add_global' }, 'add-status' => { name => 'add_status' }, diff --git a/centreon-plugins/snmp_standard/mode/isdnusage.pm b/centreon-plugins/snmp_standard/mode/isdnusage.pm index 149816e5c..29dda01fb 100644 --- a/centreon-plugins/snmp_standard/mode/isdnusage.pm +++ b/centreon-plugins/snmp_standard/mode/isdnusage.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/snmp_standard/mode/listdiskspath.pm b/centreon-plugins/snmp_standard/mode/listdiskspath.pm index 19fce0f27..82cf506e0 100644 --- a/centreon-plugins/snmp_standard/mode/listdiskspath.pm +++ b/centreon-plugins/snmp_standard/mode/listdiskspath.pm @@ -34,7 +34,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "diskpath:s" => { name => 'diskpath' }, diff --git a/centreon-plugins/snmp_standard/mode/listinterfaces.pm b/centreon-plugins/snmp_standard/mode/listinterfaces.pm index 7ee64092d..acc357637 100644 --- a/centreon-plugins/snmp_standard/mode/listinterfaces.pm +++ b/centreon-plugins/snmp_standard/mode/listinterfaces.pm @@ -94,7 +94,6 @@ sub new { bless $self, $class; $self->{no_speed} = defined($options{no_speed}) && $options{no_speed} =~ /^[01]$/ ? $options{no_speed} : 0; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name" => { name => 'use_name' }, "interface:s" => { name => 'interface' }, diff --git a/centreon-plugins/snmp_standard/mode/listspanningtrees.pm b/centreon-plugins/snmp_standard/mode/listspanningtrees.pm index a763065e4..bb5f0ef21 100644 --- a/centreon-plugins/snmp_standard/mode/listspanningtrees.pm +++ b/centreon-plugins/snmp_standard/mode/listspanningtrees.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-port:s" => { name => 'filter_port' }, diff --git a/centreon-plugins/snmp_standard/mode/liststorages.pm b/centreon-plugins/snmp_standard/mode/liststorages.pm index 186209675..47d993d1b 100644 --- a/centreon-plugins/snmp_standard/mode/liststorages.pm +++ b/centreon-plugins/snmp_standard/mode/liststorages.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "storage:s" => { name => 'storage' }, diff --git a/centreon-plugins/snmp_standard/mode/loadaverage.pm b/centreon-plugins/snmp_standard/mode/loadaverage.pm index 1c641d0ac..5ae7a14e9 100644 --- a/centreon-plugins/snmp_standard/mode/loadaverage.pm +++ b/centreon-plugins/snmp_standard/mode/loadaverage.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', default => '' }, diff --git a/centreon-plugins/snmp_standard/mode/memory.pm b/centreon-plugins/snmp_standard/mode/memory.pm index 78849fb02..88b1158ac 100644 --- a/centreon-plugins/snmp_standard/mode/memory.pm +++ b/centreon-plugins/snmp_standard/mode/memory.pm @@ -80,7 +80,7 @@ sub set_counters { key_values => [ { name => 'prct_used' } ], output_template => 'Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 0, + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, ], } @@ -139,7 +139,7 @@ sub set_counters { key_values => [ { name => 'prct_used' } ], output_template => 'Used : %.2f %%', perfdatas => [ - { label => 'swap_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 0, + { label => 'swap_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, ], } @@ -152,11 +152,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'units:s' => { name => 'units', default => '%' }, 'free' => { name => 'free' }, 'swap' => { name => 'check_swap' }, + 'redhat' => { name => 'redhat' }, }); return $self; @@ -166,13 +166,16 @@ sub compat_threshold_counter { my ($self, %options) = @_; foreach ('warning', 'critical') { - next if (!defined($options{option_results}->{$_ . '-' . $options{compat}->{th}}) || $options{option_results}->{$_ . '-' . $options{compat}->{th}} eq ''); - if (defined($options{compat}->{free})) { - $options{option_results}->{$_ . '-' . $options{compat}->{th} . '-free'} = $options{option_results}->{$_ . '-' . $options{compat}->{th}}; - $options{option_results}->{$_ . '-' . $options{compat}->{th}} = undef; - } elsif (defined($options{compat}->{units}) && $options{compat}->{units} eq '%') { - $options{option_results}->{$_ . '-' . $options{compat}->{th} . '-prct'} = $options{option_results}->{$_ . '-' . $options{compat}->{th}}; - $options{option_results}->{$_ . '-' . $options{compat}->{th}} = undef; + foreach my $th (@{$options{compat}->{th}}) { + next if (!defined($options{option_results}->{$_ . '-' . $th->[0]}) || $options{option_results}->{$_ . '-' . $th->[0]} eq ''); + + if (defined($options{compat}->{free})) { + $options{option_results}->{$_ . '-' . $th->[1]->{free}} = $options{option_results}->{$_ . '-' . $th->[0]}; + $options{option_results}->{$_ . '-' . $th->[0]} = undef; + } elsif (defined($options{compat}->{units}) && $options{compat}->{units} eq '%') { + $options{option_results}->{$_ . '-' . $th->[1]->{prct}} = $options{option_results}->{$_ . '-' . $th->[0]}; + $options{option_results}->{$_ . '-' . $th->[0]} = undef; + } } } } @@ -181,8 +184,18 @@ sub check_options { my ($self, %options) = @_; # Compatibility - $self->compat_threshold_counter(%options, compat => { th => 'usage', units => $options{option_results}->{units}, free => $options{option_results}->{free}}); - $self->compat_threshold_counter(%options, compat => { th => 'swap', units => $options{option_results}->{units}, free => $options{option_results}->{free}}); + $self->compat_threshold_counter(%options, + compat => { + th => [ ['usage', { free => 'usage-free', prct => 'usage-prct'} ], [ 'memory-usage-bytes', { free => 'memory-free-bytes', prct => 'memory-usage-percentage' } ] ], + units => $options{option_results}->{units}, free => $options{option_results}->{free} + } + ); + $self->compat_threshold_counter(%options, + compat => { + th => [ ['swap', { free => 'swap-free', prct => 'swap-prct' } ], [ 'swap-usage-bytes', { free => 'swap-free-bytes', prct => 'swap-usage-percentage' } ] ], + units => $options{option_results}->{units}, free => $options{option_results}->{free} + } + ); $self->SUPER::check_options(%options); } @@ -209,8 +222,54 @@ sub memory_calc { my ($used, $free, $prct_used, $prct_free) = (0, 0, 0, 0); if ($total != 0) { - $used = $total - $available - $buffer - $cached; - $free = $total - $used; + #### procps-ng-3.3.10-23 + ## Mem: + ## total = MemTotal in /proc/meminfo + ## used = total - free - buffer - cache + ## free = MemFree in /proc/meminfo + ## shared = Shmem in /proc/meminfo + ## buffers = Buffers in /proc/meminfo + ## cache = Cached and Slab in /proc/meminfo + ## available = MemAvailable in /proc/meminfo + ## Swap: + ## total = SwapTotal in /proc/meminfo + ## used = total - free + ## free = SwapFree in /proc/meminfo + #### net-snmp-5.7.2-38 + ## memTotalSwap = SwapTotal in /proc/meminfo + ## memAvailSwap = SwapFree in /proc/meminfo + ## memTotalReal = MemTotal in /proc/meminfo + ## memAvailReal = MemFree in /proc/meminfo + ## memTotalFree = memAvailSwap + memAvailReal + ## memShared = MemShared in /proc/meminfo + ## memBuffer = Buffers in /proc/meminfo + ## memCached = Cached in /proc/meminfo (missing Slab) + + #### procps-ng-3.3.10-26 + ## Mem: + ## total = MemTotal in /proc/meminfo + ## used = total - free - buffer - cache + ## free = MemFree in /proc/meminfo + ## shared = Shmem in /proc/meminfo + ## buffers = Buffers in /proc/meminfo + ## cache = Cached and SReclaimable in /proc/meminfo (https://gitlab.com/procps-ng/procps/commit/05d751c4f076a2f0118b914c5e51cfbb4762ad8e) + ## available = MemAvailable in /proc/meminfo + ## Swap: + ## total = SwapTotal in /proc/meminfo + ## used = total - free + ## free = SwapFree in /proc/meminfo + #### net-snmp-5.7.2-43 + ## memTotalSwap = SwapTotal in /proc/meminfo + ## memAvailSwap = SwapFree in /proc/meminfo + ## memTotalReal = MemTotal in /proc/meminfo + ## memAvailReal = MemFree + Buffers + Cached + SReclaimable in /proc/meminfo (https://bugzilla.redhat.com/attachment.cgi?id=1554747&action=diff) + ## memTotalFree = memAvailSwap + memAvailReal + ## memShared = MemShared in /proc/meminfo + ## memBuffer = Buffers in /proc/meminfo + ## memCached = Cached + SReclaimable in /proc/meminfo (https://bugzilla.redhat.com/attachment.cgi?id=1554747&action=diff) + + $used = (defined($self->{option_results}->{redhat})) ? $total - $available : $total - $available - $buffer - $cached; + $free = (defined($self->{option_results}->{redhat})) ? $available : $total - $used; $prct_used = $used * 100 / $total; $prct_free = 100 - $prct_used; } @@ -290,6 +349,16 @@ Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%), 'swap' (B), 'swap-free' (B), 'swap-prct' (%), 'buffer' (B), 'cached' (B), 'shared' (B). +=item B<--redhat> + +If using RedHat distribution with net-snmp >= 5.7.2-43. + +This version: used = memTotalReal - memAvailReal // free = memAvailReal + +Others versions: used = memTotalReal - memAvailReal - memBuffer - memCached // free = total - used + +(grep for '##' in this mode for more informations) + =back =cut diff --git a/centreon-plugins/snmp_standard/mode/mtausage.pm b/centreon-plugins/snmp_standard/mode/mtausage.pm index 584f22747..8fc7cc6fd 100644 --- a/centreon-plugins/snmp_standard/mode/mtausage.pm +++ b/centreon-plugins/snmp_standard/mode/mtausage.pm @@ -181,7 +181,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/snmp_standard/mode/ntp.pm b/centreon-plugins/snmp_standard/mode/ntp.pm index 03e340e72..e4c40a6e7 100644 --- a/centreon-plugins/snmp_standard/mode/ntp.pm +++ b/centreon-plugins/snmp_standard/mode/ntp.pm @@ -32,7 +32,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "ntp-hostname:s" => { name => 'ntp_hostname' }, diff --git a/centreon-plugins/snmp_standard/mode/numericvalue.pm b/centreon-plugins/snmp_standard/mode/numericvalue.pm index fb422ce10..00406a8cf 100644 --- a/centreon-plugins/snmp_standard/mode/numericvalue.pm +++ b/centreon-plugins/snmp_standard/mode/numericvalue.pm @@ -32,24 +32,24 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "oid:s" => { name => 'oid' }, - "oid-type:s" => { name => 'oid_type' }, - "counter-per-seconds" => { name => 'counter_per_seconds' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "format:s" => { name => 'format' }, - "format-custom:s" => { name => 'format_custom' }, - "format-scale" => { name => 'format_scale' }, - "format-scale-type:s" => { name => 'format_scale_type' }, - "perfdata-unit:s" => { name => 'perfdata_unit' }, - "perfdata-name:s" => { name => 'perfdata_name' }, - "perfdata-min:s" => { name => 'perfdata_min' }, - "perfdata-max:s" => { name => 'perfdata_max' }, - "config-json:s" => { name => 'config_json' }, - }); + $options{options}->add_options(arguments => { + 'oid:s' => { name => 'oid' }, + 'oid-type:s' => { name => 'oid_type' }, + 'counter-per-seconds' => { name => 'counter_per_seconds' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'extracted-pattern:s' => { name => 'extracted_pattern' }, + 'format:s' => { name => 'format' }, + 'format-custom:s' => { name => 'format_custom' }, + 'format-scale' => { name => 'format_scale' }, + 'format-scale-type:s' => { name => 'format_scale_type' }, + 'perfdata-unit:s' => { name => 'perfdata_unit' }, + 'perfdata-name:s' => { name => 'perfdata_name' }, + 'perfdata-min:s' => { name => 'perfdata_min' }, + 'perfdata-max:s' => { name => 'perfdata_max' }, + 'config-json:s' => { name => 'config_json' }, + }); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{use_statefile} = 0; return $self; @@ -87,7 +87,7 @@ sub add_data { foreach (['oid_type', 'gauge'], ['counter_per_seconds'], ['format', 'current value is %s'], ['format_custom', ''], ['format_scale'], ['perfdata_unit', ''], ['perfdata_name', 'value'], - ['perfdata_min', ''], ['perfdata_max', '']) { + ['perfdata_min', ''], ['perfdata_max', ''], ['extracted_pattern', '']) { if (defined($options{data}->{$_->[0]})) { $entry->{$_->[0]} = $options{data}->{$_->[0]}; } elsif (defined($_->[1])) { @@ -109,8 +109,10 @@ sub check_options { ($self->{entries}, $self->{oids}) = ([], []); if (defined($self->{option_results}->{config_json}) && $self->{option_results}->{config_json} ne '') { - centreon::plugins::misc::mymodule_load(module => 'JSON', - error_msg => "Cannot load module 'JSON'."); + centreon::plugins::misc::mymodule_load( + module => 'JSON', + error_msg => "Cannot load module 'JSON'." + ); my $json = JSON->new; my $content; eval { @@ -144,11 +146,27 @@ sub check_data { my ($self, %options) = @_; if (!defined($self->{results}->{$options{entry}->{oid}})) { - $self->{output}->output_add(severity => "UNKNOWN", - short_msg => "Cannot find oid:" . $options{entry}->{oid}); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => 'Cannot find oid:' . $options{entry}->{oid} + ); return ; } + my $value = $self->{results}->{$options{entry}->{oid}}; + if (defined($options{entry}->{extracted_pattern}) && $options{entry}->{extracted_pattern} ne '') { + if ($value =~ /$options{entry}->{extracted_pattern}/ && defined($1)) { + $value = $1; + } + } + if ($value !~ /^\d+(\.\d+)?$/) { + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => 'oid value is not numeric (' . $value . ')' + ); + return ; + } + if ($options{entry}->{oid_type} =~ /^counter$/i) { my $old_timestamp = $self->{statefile_cache}->get(name => 'timestamp'); my $old_value = $self->{statefile_cache}->get(name => 'value-' . $options{num}); @@ -204,7 +222,7 @@ sub run { if ($self->{use_statefile} == 1) { $self->{cache_datas} = {}; - $self->{statefile_cache}->read(statefile => "snmpstandard_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . md5_hex(join('-', @{$self->{request_oids}}))); + $self->{statefile_cache}->read(statefile => 'snmpstandard_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . md5_hex(join('-', @{$self->{request_oids}}))); } $self->{results} = $options{snmp}->get_leef(oids => $self->{request_oids}, nothing_quit => 1); @@ -257,6 +275,10 @@ Can be 'counter' also. 'counter' will use a retention file. Convert counter value on a value per seconds (only with type 'counter'). +=item B<--extracted-pattern> + +Set pattern to extracted a number. + =item B<--format> Output format (Default: 'current value is %s') diff --git a/centreon-plugins/snmp_standard/mode/printererror.pm b/centreon-plugins/snmp_standard/mode/printererror.pm index 10f060be4..f4f38df84 100644 --- a/centreon-plugins/snmp_standard/mode/printererror.pm +++ b/centreon-plugins/snmp_standard/mode/printererror.pm @@ -74,12 +74,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "ok-status:s" => { name => 'ok_status', default => '%{status} =~ /ok/' }, - "unknown-status:s" => { name => 'unknown_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /.*/' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'ok-status:s' => { name => 'ok_status', default => '%{status} =~ /ok/' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /.*/' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, }); return $self; @@ -122,7 +121,10 @@ sub manage_selection { my $instance = $1; # 16 bits value my $value = unpack('S', $result->{$_}); - + if (!defined($value)) { + $value = ord($result->{$_}); + } + $self->{printer}->{$instance} = { display => $instance, errors => {} }; my $i = 0; foreach my $key (keys %errors_printer) { diff --git a/centreon-plugins/snmp_standard/mode/processcount.pm b/centreon-plugins/snmp_standard/mode/processcount.pm index 194a896e7..dbab3a80f 100644 --- a/centreon-plugins/snmp_standard/mode/processcount.pm +++ b/centreon-plugins/snmp_standard/mode/processcount.pm @@ -39,7 +39,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "process-status:s" => { name => 'process_status', default => 'running|runnable' }, diff --git a/centreon-plugins/snmp_standard/mode/spanningtree.pm b/centreon-plugins/snmp_standard/mode/spanningtree.pm index 0dff2d4b3..c699faa29 100644 --- a/centreon-plugins/snmp_standard/mode/spanningtree.pm +++ b/centreon-plugins/snmp_standard/mode/spanningtree.pm @@ -76,7 +76,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-port:s" => { name => 'filter_port' }, diff --git a/centreon-plugins/snmp_standard/mode/storage.pm b/centreon-plugins/snmp_standard/mode/storage.pm index 8ea8588cf..d71654a64 100644 --- a/centreon-plugins/snmp_standard/mode/storage.pm +++ b/centreon-plugins/snmp_standard/mode/storage.pm @@ -203,7 +203,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, diff --git a/centreon-plugins/snmp_standard/mode/stringvalue.pm b/centreon-plugins/snmp_standard/mode/stringvalue.pm index 1e4142b75..8f0d3d925 100644 --- a/centreon-plugins/snmp_standard/mode/stringvalue.pm +++ b/centreon-plugins/snmp_standard/mode/stringvalue.pm @@ -31,47 +31,46 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "oid:s" => { name => 'oid' }, - "oid-leef:s" => { name => 'oid_leef' }, - "oid-table:s" => { name => 'oid_table' }, - "oid-instance:s" => { name => 'oid_instance' }, - "filter-table-value:s" => { name => 'filter_table_value' }, - "filter-table-instance:s" => { name => 'filter_table_instance' }, - - "warning-regexp:s" => { name => 'warning_regexp' }, - "critical-regexp:s" => { name => 'critical_regexp' }, - "unknown-regexp:s" => { name => 'unknown_regexp' }, - "regexp-isensitive" => { name => 'use_iregexp' }, - - "warning-absent:s@" => { name => 'warning_absent' }, - "critical-absent:s@" => { name => 'critical_absent' }, - "unknown-absent:s@" => { name => 'unknown_absent' }, - "warning-present:s@" => { name => 'warning_present' }, - "critical-present:s@" => { name => 'critical_present' }, - "unknown-present:s@" => { name => 'unknown_present' }, - - "format-ok:s" => { name => 'format_ok', default => '%{filter_rows} value(s)' }, - "format-warning:s" => { name => 'format_warning', default => 'value(s): %{details_warning}' }, - "format-critical:s" => { name => 'format_critical', default => 'value(s): %{details_critical}' }, - "format-unknown:s" => { name => 'format_unknown', default => 'value(s): %{details_unknown}' }, - - "format-details-ok:s" => { name => 'format_details_ok', default => '%{value}' }, - "format-details-warning:s" => { name => 'format_details_warning', default => '%{value}' }, - "format-details-critical:s" => { name => 'format_details_critical', default => '%{value}' }, - "format-details-unknown:s" => { name => 'format_details_unknown', default => '%{value}' }, - - "format-details-separator-ok:s" => { name => 'format_details_separator_ok', default => ', ' }, - "format-details-separator-warning:s" => { name => 'format_details_separator_warning', default => ', ' }, - "format-details-separator-critical:s" => { name => 'format_details_separator_critical', default => ', ' }, - "format-details-separator-unknown:s" => { name => 'format_details_separator_unknown', default => ', ' }, - - "map-values:s" => { name => 'map_values' }, - "map-value-other:s" => { name => 'map_value_other' }, - "map-values-separator:s" => { name => 'map_values_separator', default => ',' }, - }); + $options{options}->add_options(arguments => { + 'oid:s' => { name => 'oid' }, + 'oid-leef:s' => { name => 'oid_leef' }, + 'oid-table:s' => { name => 'oid_table' }, + 'oid-instance:s' => { name => 'oid_instance' }, + 'filter-table-value:s' => { name => 'filter_table_value' }, + 'filter-table-instance:s' => { name => 'filter_table_instance' }, + + 'warning-regexp:s' => { name => 'warning_regexp' }, + 'critical-regexp:s' => { name => 'critical_regexp' }, + 'unknown-regexp:s' => { name => 'unknown_regexp' }, + 'regexp-isensitive' => { name => 'use_iregexp' }, + + 'warning-absent:s@' => { name => 'warning_absent' }, + 'critical-absent:s@' => { name => 'critical_absent' }, + 'unknown-absent:s@' => { name => 'unknown_absent' }, + 'warning-present:s@' => { name => 'warning_present' }, + 'critical-present:s@' => { name => 'critical_present' }, + 'unknown-present:s@' => { name => 'unknown_present' }, + + 'format-ok:s' => { name => 'format_ok', default => '%{filter_rows} value(s)' }, + 'format-warning:s' => { name => 'format_warning', default => 'value(s): %{details_warning}' }, + 'format-critical:s' => { name => 'format_critical', default => 'value(s): %{details_critical}' }, + 'format-unknown:s' => { name => 'format_unknown', default => 'value(s): %{details_unknown}' }, + + 'format-details-ok:s' => { name => 'format_details_ok', default => '%{value}' }, + 'format-details-warning:s' => { name => 'format_details_warning', default => '%{value}' }, + 'format-details-critical:s' => { name => 'format_details_critical', default => '%{value}' }, + 'format-details-unknown:s' => { name => 'format_details_unknown', default => '%{value}' }, + + 'format-details-separator-ok:s' => { name => 'format_details_separator_ok', default => ', ' }, + 'format-details-separator-warning:s' => { name => 'format_details_separator_warning', default => ', ' }, + 'format-details-separator-critical:s' => { name => 'format_details_separator_critical', default => ', ' }, + 'format-details-separator-unknown:s' => { name => 'format_details_separator_unknown', default => ', ' }, + + 'map-values:s' => { name => 'map_values' }, + 'map-value-other:s' => { name => 'map_value_other' }, + 'map-values-separator:s' => { name => 'map_values_separator', default => ',' }, + 'convert-custom-values:s' => { name => 'convert_custom_values' }, + }); $self->{macros} = { ok => {}, warning => {}, critical => {}, unknown => {} }; return $self; @@ -84,7 +83,7 @@ sub check_options { $self->{option_results}->{oid_leef} = $self->{option_results}->{oid} if (defined($self->{option_results}->{oid}) && $self->{option_results}->{oid} ne ''); if ((!defined($self->{option_results}->{oid_leef}) || $self->{option_results}->{oid_leef} eq '') && (!defined($self->{option_results}->{oid_table}) || $self->{option_results}->{oid_table} eq '')) { - $self->{output}->add_option_msg(short_msg => "Need to specify an OID with option --oid-leef or --oid-table."); + $self->{output}->add_option_msg(short_msg => 'Need to specify an OID with option --oid-leef or --oid-table.'); $self->{output}->option_exit(); } foreach (('oid_leef', 'oid_table', 'oid_instance')) { @@ -111,7 +110,7 @@ sub get_instance_value { return $self->{results}->{$self->{option_results}->{oid_instance} . '.' . $options{instance}}; } -sub get_map_value { +sub get_change_value { my ($self, %options) = @_; my $value = $options{value}; @@ -121,7 +120,11 @@ sub get_map_value { } elsif (defined($self->{option_results}->{map_value_other}) && $self->{option_results}->{map_value_other} ne '') { $value = $self->{option_results}->{map_value_other}; } - + + if (defined($self->{option_results}->{convert_custom_values}) && $self->{option_results}->{convert_custom_values} ne '') { + eval "\$value = $self->{option_results}->{convert_custom_values}"; + } + return $value; } @@ -133,7 +136,7 @@ sub get_snmp_values { $self->{results} = $self->{snmp}->get_leef(oids => [$self->{option_results}->{oid_leef}], nothing_quit => 1); $self->{macros}->{rows} = 1; $self->{macros}->{filter_rows} = 1; - $self->{instances}->{0} = $self->get_map_value(value => $self->{results}->{$self->{option_results}->{oid_leef}}); + $self->{instances}->{0} = $self->get_change_value(value => $self->{results}->{$self->{option_results}->{oid_leef}}); return 0; } @@ -146,8 +149,8 @@ sub get_snmp_values { $row++; my $instance = $self->get_instance_value(instance => $1); - my $value = $self->get_map_value(value => $self->{results}->{$_}); - $self->{output}->output_add(long_msg => sprintf("[instance: %s][value: %s]", $_, $value), debug => 1); + my $value = $self->get_change_value(value => $self->{results}->{$_}); + $self->{output}->output_add(long_msg => sprintf('[instance: %s][value: %s]', $_, $value), debug => 1); if (defined($self->{option_results}->{filter_table_value}) && $self->{option_results}->{filter_table_value} ne '' && $value !~ /$self->{option_results}->{filter_table_value}/) { $self->{output}->output_add(long_msg => sprintf("skipping oid '%s' value '%s': not matching the filter", $_, $value), debug => 1); @@ -378,6 +381,11 @@ Use to transform an integer value not defined in --map-values option. Separator uses between values (default: coma). +=item B<--convert-custom-values> + +Custom code to convert values. +Example to convert octetstring to macaddress: --convert-custom-values='join(":", unpack("(H2)*", $value))' + =back =cut diff --git a/centreon-plugins/snmp_standard/mode/swap.pm b/centreon-plugins/snmp_standard/mode/swap.pm index d2a2e59cd..b12930fdc 100644 --- a/centreon-plugins/snmp_standard/mode/swap.pm +++ b/centreon-plugins/snmp_standard/mode/swap.pm @@ -67,7 +67,7 @@ sub set_counters { key_values => [ { name => 'prct_used' } ], output_template => 'Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 0, + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, ], } @@ -80,7 +80,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'no-swap:s' => { name => 'no_swap' }, }); diff --git a/centreon-plugins/snmp_standard/mode/tcpcon.pm b/centreon-plugins/snmp_standard/mode/tcpcon.pm index 54a10734b..11a243ebe 100644 --- a/centreon-plugins/snmp_standard/mode/tcpcon.pm +++ b/centreon-plugins/snmp_standard/mode/tcpcon.pm @@ -54,7 +54,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/snmp_standard/mode/uptime.pm b/centreon-plugins/snmp_standard/mode/uptime.pm index 17021d7df..ff67f7785 100644 --- a/centreon-plugins/snmp_standard/mode/uptime.pm +++ b/centreon-plugins/snmp_standard/mode/uptime.pm @@ -34,7 +34,6 @@ sub new { 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' }, diff --git a/centreon-plugins/snmp_standard/mode/vrrp.pm b/centreon-plugins/snmp_standard/mode/vrrp.pm index fd6a326ac..6b5f4d3da 100644 --- a/centreon-plugins/snmp_standard/mode/vrrp.pm +++ b/centreon-plugins/snmp_standard/mode/vrrp.pm @@ -80,7 +80,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/storage/adic/tape/snmp/plugin.pm b/centreon-plugins/storage/adic/tape/snmp/plugin.pm new file mode 100644 index 000000000..3df2ef86d --- /dev/null +++ b/centreon-plugins/storage/adic/tape/snmp/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2019 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 storage::adic::tape::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}} = ( + 'hardware' => 'centreon::common::adic::tape::snmp::mode::hardware' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Adic tape library in SNMP. +Buyed by Quantum in 2006. To be tested for some Quantum scalar (i6000, i500, ...). + +=cut diff --git a/centreon-plugins/storage/avid/isis/snmp/mode/performance.pm b/centreon-plugins/storage/avid/isis/snmp/mode/performance.pm index d99604970..a44ba625d 100644 --- a/centreon-plugins/storage/avid/isis/snmp/mode/performance.pm +++ b/centreon-plugins/storage/avid/isis/snmp/mode/performance.pm @@ -126,7 +126,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "percent" => { name => 'percent' }, }); diff --git a/centreon-plugins/storage/avid/isis/snmp/mode/status.pm b/centreon-plugins/storage/avid/isis/snmp/mode/status.pm index 726712463..dee0ed1bc 100644 --- a/centreon-plugins/storage/avid/isis/snmp/mode/status.pm +++ b/centreon-plugins/storage/avid/isis/snmp/mode/status.pm @@ -73,7 +73,6 @@ sub new { 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 => '%{status} !~ /Online/i' }, diff --git a/centreon-plugins/storage/avid/isis/snmp/mode/usage.pm b/centreon-plugins/storage/avid/isis/snmp/mode/usage.pm index 2f43b5f67..effa3d249 100644 --- a/centreon-plugins/storage/avid/isis/snmp/mode/usage.pm +++ b/centreon-plugins/storage/avid/isis/snmp/mode/usage.pm @@ -149,7 +149,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, diff --git a/centreon-plugins/storage/buffalo/terastation/snmp/mode/arrayusage.pm b/centreon-plugins/storage/buffalo/terastation/snmp/mode/arrayusage.pm index 46f2a1fdc..a9ac43a66 100644 --- a/centreon-plugins/storage/buffalo/terastation/snmp/mode/arrayusage.pm +++ b/centreon-plugins/storage/buffalo/terastation/snmp/mode/arrayusage.pm @@ -79,7 +79,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/storage/buffalo/terastation/snmp/mode/hardware.pm b/centreon-plugins/storage/buffalo/terastation/snmp/mode/hardware.pm index d6c53527e..e8bd5cbcf 100644 --- a/centreon-plugins/storage/buffalo/terastation/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/buffalo/terastation/snmp/mode/hardware.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/dell/TL2000/mode/globalstatus.pm b/centreon-plugins/storage/dell/TL2000/mode/globalstatus.pm index 3fcbc1ff0..6564f9a04 100644 --- a/centreon-plugins/storage/dell/TL2000/mode/globalstatus.pm +++ b/centreon-plugins/storage/dell/TL2000/mode/globalstatus.pm @@ -39,7 +39,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm b/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm index de34fd448..5ac781bb6 100644 --- a/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm +++ b/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm @@ -106,7 +106,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "cem-host:s" => { name => 'cem_host' }, diff --git a/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm b/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm index fcf42410c..9a4ce5645 100644 --- a/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm +++ b/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm @@ -176,7 +176,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "cem-host:s" => { name => 'cem_host' }, "cem-user:s" => { name => 'cem_user' }, diff --git a/centreon-plugins/storage/dell/compellent/snmp/mode/hardware.pm b/centreon-plugins/storage/dell/compellent/snmp/mode/hardware.pm index 33e0612bb..62abec521 100644 --- a/centreon-plugins/storage/dell/compellent/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/dell/compellent/snmp/mode/hardware.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/dell/equallogic/snmp/mode/arrayusage.pm b/centreon-plugins/storage/dell/equallogic/snmp/mode/arrayusage.pm index 8b7a521b2..e9517b4d6 100644 --- a/centreon-plugins/storage/dell/equallogic/snmp/mode/arrayusage.pm +++ b/centreon-plugins/storage/dell/equallogic/snmp/mode/arrayusage.pm @@ -247,7 +247,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/storage/dell/equallogic/snmp/mode/diskusage.pm b/centreon-plugins/storage/dell/equallogic/snmp/mode/diskusage.pm index 224eeab98..8f4996e2d 100644 --- a/centreon-plugins/storage/dell/equallogic/snmp/mode/diskusage.pm +++ b/centreon-plugins/storage/dell/equallogic/snmp/mode/diskusage.pm @@ -102,7 +102,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "unknown-status:s" => { name => 'unknown_status', default => '' }, diff --git a/centreon-plugins/storage/dell/equallogic/snmp/mode/hardware.pm b/centreon-plugins/storage/dell/equallogic/snmp/mode/hardware.pm index e2e976848..e94cf1c08 100644 --- a/centreon-plugins/storage/dell/equallogic/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/dell/equallogic/snmp/mode/hardware.pm @@ -95,7 +95,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/dell/equallogic/snmp/mode/poolusage.pm b/centreon-plugins/storage/dell/equallogic/snmp/mode/poolusage.pm index 9274305f8..86a651136 100644 --- a/centreon-plugins/storage/dell/equallogic/snmp/mode/poolusage.pm +++ b/centreon-plugins/storage/dell/equallogic/snmp/mode/poolusage.pm @@ -101,7 +101,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/storage/dell/fluidfs/snmp/mode/hardware.pm b/centreon-plugins/storage/dell/fluidfs/snmp/mode/hardware.pm index d0c814edd..38afd14ed 100644 --- a/centreon-plugins/storage/dell/fluidfs/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/dell/fluidfs/snmp/mode/hardware.pm @@ -63,7 +63,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/dell/fluidfs/snmp/mode/volumeusage.pm b/centreon-plugins/storage/dell/fluidfs/snmp/mode/volumeusage.pm index c3c1d885f..550f77a46 100644 --- a/centreon-plugins/storage/dell/fluidfs/snmp/mode/volumeusage.pm +++ b/centreon-plugins/storage/dell/fluidfs/snmp/mode/volumeusage.pm @@ -116,7 +116,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/storage/dell/me4/custom/api.pm b/centreon-plugins/storage/dell/me4/restapi/custom/api.pm similarity index 94% rename from centreon-plugins/storage/dell/me4/custom/api.pm rename to centreon-plugins/storage/dell/me4/restapi/custom/api.pm index 2b0df6e5b..f2e9f35cb 100644 --- a/centreon-plugins/storage/dell/me4/custom/api.pm +++ b/centreon-plugins/storage/dell/me4/restapi/custom/api.pm @@ -18,15 +18,13 @@ # limitations under the License. # -package storage::dell::me4::custom::api; +package storage::dell::me4::restapi::custom::api; use strict; use warnings; -use DateTime; use centreon::plugins::http; use centreon::plugins::statefile; use JSON::XS; -use URI::Encode; use Digest::MD5 qw(md5_hex); sub new { @@ -45,12 +43,12 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "api-username:s" => { name => 'api_username' }, - "api-password:s" => { name => 'api_password' }, - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port' }, - "proto:s" => { name => 'proto' }, - "timeout:s" => { name => 'timeout' }, + 'api-username:s' => { name => 'api_username' }, + 'api-password:s' => { name => 'api_password' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'timeout:s' => { name => 'timeout' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); diff --git a/centreon-plugins/storage/dell/me4/mode/components/controller.pm b/centreon-plugins/storage/dell/me4/restapi/mode/components/controller.pm similarity index 97% rename from centreon-plugins/storage/dell/me4/mode/components/controller.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/components/controller.pm index c0727a830..aecd3ba6c 100644 --- a/centreon-plugins/storage/dell/me4/mode/components/controller.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/components/controller.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::components::controller; +package storage::dell::me4::restapi::mode::components::controller; use strict; use warnings; diff --git a/centreon-plugins/storage/dell/me4/mode/components/disk.pm b/centreon-plugins/storage/dell/me4/restapi/mode/components/disk.pm similarity index 98% rename from centreon-plugins/storage/dell/me4/mode/components/disk.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/components/disk.pm index be7faf39a..77709e4d2 100644 --- a/centreon-plugins/storage/dell/me4/mode/components/disk.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/components/disk.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::components::disk; +package storage::dell::me4::restapi::mode::components::disk; use strict; use warnings; diff --git a/centreon-plugins/storage/dell/me4/mode/components/fan.pm b/centreon-plugins/storage/dell/me4/restapi/mode/components/fan.pm similarity index 98% rename from centreon-plugins/storage/dell/me4/mode/components/fan.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/components/fan.pm index 81e915a71..e98120104 100644 --- a/centreon-plugins/storage/dell/me4/mode/components/fan.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/components/fan.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::components::fan; +package storage::dell::me4::restapi::mode::components::fan; use strict; use warnings; diff --git a/centreon-plugins/storage/dell/me4/mode/components/fru.pm b/centreon-plugins/storage/dell/me4/restapi/mode/components/fru.pm similarity index 97% rename from centreon-plugins/storage/dell/me4/mode/components/fru.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/components/fru.pm index f9f964c61..d97901d3b 100644 --- a/centreon-plugins/storage/dell/me4/mode/components/fru.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/components/fru.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::components::fru; +package storage::dell::me4::restapi::mode::components::fru; use strict; use warnings; diff --git a/centreon-plugins/storage/dell/me4/mode/components/psu.pm b/centreon-plugins/storage/dell/me4/restapi/mode/components/psu.pm similarity index 97% rename from centreon-plugins/storage/dell/me4/mode/components/psu.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/components/psu.pm index c131a8e1d..d241eb631 100644 --- a/centreon-plugins/storage/dell/me4/mode/components/psu.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/components/psu.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::components::psu; +package storage::dell::me4::restapi::mode::components::psu; use strict; use warnings; diff --git a/centreon-plugins/storage/dell/me4/mode/components/sensor.pm b/centreon-plugins/storage/dell/me4/restapi/mode/components/sensor.pm similarity index 98% rename from centreon-plugins/storage/dell/me4/mode/components/sensor.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/components/sensor.pm index 47e0d4913..d172ed1a1 100644 --- a/centreon-plugins/storage/dell/me4/mode/components/sensor.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/components/sensor.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::components::sensor; +package storage::dell::me4::restapi::mode::components::sensor; use strict; use warnings; diff --git a/centreon-plugins/storage/dell/me4/mode/components/volume.pm b/centreon-plugins/storage/dell/me4/restapi/mode/components/volume.pm similarity index 97% rename from centreon-plugins/storage/dell/me4/mode/components/volume.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/components/volume.pm index 10317beb3..65dc14229 100644 --- a/centreon-plugins/storage/dell/me4/mode/components/volume.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/components/volume.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::components::volume; +package storage::dell::me4::restapi::mode::components::volume; use strict; use warnings; diff --git a/centreon-plugins/storage/dell/me4/mode/controllerstatistics.pm b/centreon-plugins/storage/dell/me4/restapi/mode/controllerstatistics.pm similarity index 98% rename from centreon-plugins/storage/dell/me4/mode/controllerstatistics.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/controllerstatistics.pm index 97b3d6443..627eb65c7 100644 --- a/centreon-plugins/storage/dell/me4/mode/controllerstatistics.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/controllerstatistics.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::controllerstatistics; +package storage::dell::me4::restapi::mode::controllerstatistics; use base qw(centreon::plugins::templates::counter); @@ -189,9 +189,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, + 'filter-name:s' => { name => 'filter_name' }, }); return $self; diff --git a/centreon-plugins/storage/dell/me4/mode/hardware.pm b/centreon-plugins/storage/dell/me4/restapi/mode/hardware.pm similarity index 97% rename from centreon-plugins/storage/dell/me4/mode/hardware.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/hardware.pm index fd5620ee4..a24294603 100644 --- a/centreon-plugins/storage/dell/me4/mode/hardware.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/hardware.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::hardware; +package storage::dell::me4::restapi::mode::hardware; use base qw(centreon::plugins::templates::hardware); @@ -121,7 +121,7 @@ sub set_system { ], }; - $self->{components_path} = 'storage::dell::me4::mode::components'; + $self->{components_path} = 'storage::dell::me4::restapi::mode::components'; $self->{components_module} = ['controller', 'disk', 'fan', 'fru', 'psu', 'sensor', 'volume']; } @@ -130,7 +130,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => {}); return $self; diff --git a/centreon-plugins/storage/dell/me4/mode/listcontrollers.pm b/centreon-plugins/storage/dell/me4/restapi/mode/listcontrollers.pm similarity index 94% rename from centreon-plugins/storage/dell/me4/mode/listcontrollers.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/listcontrollers.pm index 74f004cb0..71e9453c6 100644 --- a/centreon-plugins/storage/dell/me4/mode/listcontrollers.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/listcontrollers.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::listcontrollers; +package storage::dell::me4::restapi::mode::listcontrollers; use base qw(centreon::plugins::mode); @@ -30,9 +30,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, + 'filter-name:s' => { name => 'filter_name' }, }); return $self; diff --git a/centreon-plugins/storage/dell/me4/mode/listvolumes.pm b/centreon-plugins/storage/dell/me4/restapi/mode/listvolumes.pm similarity index 95% rename from centreon-plugins/storage/dell/me4/mode/listvolumes.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/listvolumes.pm index a500bc1a8..66a5dd27d 100644 --- a/centreon-plugins/storage/dell/me4/mode/listvolumes.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/listvolumes.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::listvolumes; +package storage::dell::me4::restapi::mode::listvolumes; use base qw(centreon::plugins::mode); @@ -30,9 +30,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, + 'filter-name:s' => { name => 'filter_name' }, }); return $self; diff --git a/centreon-plugins/storage/dell/me4/mode/volumestatistics.pm b/centreon-plugins/storage/dell/me4/restapi/mode/volumestatistics.pm similarity index 98% rename from centreon-plugins/storage/dell/me4/mode/volumestatistics.pm rename to centreon-plugins/storage/dell/me4/restapi/mode/volumestatistics.pm index e91444ae7..0405b9e10 100644 --- a/centreon-plugins/storage/dell/me4/mode/volumestatistics.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/volumestatistics.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::mode::volumestatistics; +package storage::dell::me4::restapi::mode::volumestatistics; use base qw(centreon::plugins::templates::counter); @@ -169,9 +169,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, + 'filter-name:s' => { name => 'filter_name' }, }); return $self; diff --git a/centreon-plugins/storage/dell/me4/plugin.pm b/centreon-plugins/storage/dell/me4/restapi/plugin.pm similarity index 67% rename from centreon-plugins/storage/dell/me4/plugin.pm rename to centreon-plugins/storage/dell/me4/restapi/plugin.pm index fb9ac2cd9..3eb05a8f6 100644 --- a/centreon-plugins/storage/dell/me4/plugin.pm +++ b/centreon-plugins/storage/dell/me4/restapi/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::dell::me4::plugin; +package storage::dell::me4::restapi::plugin; use strict; use warnings; @@ -31,14 +31,14 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'controller-statistics' => 'storage::dell::me4::mode::controllerstatistics', - 'hardware' => 'storage::dell::me4::mode::hardware', - 'list-controllers' => 'storage::dell::me4::mode::listcontrollers', - 'list-volumes' => 'storage::dell::me4::mode::listvolumes', - 'volume-statistics' => 'storage::dell::me4::mode::volumestatistics', + 'controller-statistics' => 'storage::dell::me4::restapi::mode::controllerstatistics', + 'hardware' => 'storage::dell::me4::restapi::mode::hardware', + 'list-controllers' => 'storage::dell::me4::restapi::mode::listcontrollers', + 'list-volumes' => 'storage::dell::me4::restapi::mode::listvolumes', + 'volume-statistics' => 'storage::dell::me4::restapi::mode::volumestatistics', ); - $self->{custom_modes}{api} = 'storage::dell::me4::custom::api'; + $self->{custom_modes}{api} = 'storage::dell::me4::restapi::custom::api'; return $self; } diff --git a/centreon-plugins/storage/emc/DataDomain/mode/filesystem.pm b/centreon-plugins/storage/emc/DataDomain/mode/filesystem.pm index c0d7eb9d6..2cac3d283 100644 --- a/centreon-plugins/storage/emc/DataDomain/mode/filesystem.pm +++ b/centreon-plugins/storage/emc/DataDomain/mode/filesystem.pm @@ -85,7 +85,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'name' => { name => 'use_name' }, 'filesystem:s' => { name => 'filesystem' }, diff --git a/centreon-plugins/storage/emc/DataDomain/mode/hardware.pm b/centreon-plugins/storage/emc/DataDomain/mode/hardware.pm index 28d06d607..59c391c81 100644 --- a/centreon-plugins/storage/emc/DataDomain/mode/hardware.pm +++ b/centreon-plugins/storage/emc/DataDomain/mode/hardware.pm @@ -90,7 +90,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/emc/DataDomain/mode/replication.pm b/centreon-plugins/storage/emc/DataDomain/mode/replication.pm index 1e6695d73..9b18d8cd6 100644 --- a/centreon-plugins/storage/emc/DataDomain/mode/replication.pm +++ b/centreon-plugins/storage/emc/DataDomain/mode/replication.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "unknown-status:s" => { name => 'unknown_status', default => '' }, "warning-status:s" => { name => 'warning_status', default => '%{state} =~ /initializing|recovering/i' }, diff --git a/centreon-plugins/storage/emc/celerra/local/mode/getreason.pm b/centreon-plugins/storage/emc/celerra/local/mode/getreason.pm index bf5a1bbb4..123786a27 100644 --- a/centreon-plugins/storage/emc/celerra/local/mode/getreason.pm +++ b/centreon-plugins/storage/emc/celerra/local/mode/getreason.pm @@ -84,7 +84,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/emc/isilon/snmp/mode/clusterusage.pm b/centreon-plugins/storage/emc/isilon/snmp/mode/clusterusage.pm index c507e0367..3c6b36c05 100644 --- a/centreon-plugins/storage/emc/isilon/snmp/mode/clusterusage.pm +++ b/centreon-plugins/storage/emc/isilon/snmp/mode/clusterusage.pm @@ -143,7 +143,6 @@ sub new { 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 => '%{status} =~ /attn/' }, diff --git a/centreon-plugins/storage/emc/isilon/snmp/mode/hardware.pm b/centreon-plugins/storage/emc/isilon/snmp/mode/hardware.pm index f7eace39d..5346b5f4d 100644 --- a/centreon-plugins/storage/emc/isilon/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/emc/isilon/snmp/mode/hardware.pm @@ -58,7 +58,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm b/centreon-plugins/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm index 3eb1620bf..a9112ab46 100644 --- a/centreon-plugins/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm +++ b/centreon-plugins/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/emc/recoverypoint/ssh/mode/systemstatus.pm b/centreon-plugins/storage/emc/recoverypoint/ssh/mode/systemstatus.pm index a61ea78bf..78317f053 100644 --- a/centreon-plugins/storage/emc/recoverypoint/ssh/mode/systemstatus.pm +++ b/centreon-plugins/storage/emc/recoverypoint/ssh/mode/systemstatus.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/emc/symmetrix/dmx34/local/mode/hardware.pm b/centreon-plugins/storage/emc/symmetrix/dmx34/local/mode/hardware.pm index 286c3838a..1a48b37a7 100644 --- a/centreon-plugins/storage/emc/symmetrix/dmx34/local/mode/hardware.pm +++ b/centreon-plugins/storage/emc/symmetrix/dmx34/local/mode/hardware.pm @@ -76,7 +76,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "file-health:s" => { name => 'file_health' }, diff --git a/centreon-plugins/storage/emc/symmetrix/vmax/local/mode/hardware.pm b/centreon-plugins/storage/emc/symmetrix/vmax/local/mode/hardware.pm index 3e7e20d96..3c1ceacf9 100644 --- a/centreon-plugins/storage/emc/symmetrix/vmax/local/mode/hardware.pm +++ b/centreon-plugins/storage/emc/symmetrix/vmax/local/mode/hardware.pm @@ -98,7 +98,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "health-directory:s" => { name => 'health_directory' }, diff --git a/centreon-plugins/storage/emc/unisphere/restapi/custom/api.pm b/centreon-plugins/storage/emc/unisphere/restapi/custom/api.pm new file mode 100644 index 000000000..329c1d45a --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/custom/api.pm @@ -0,0 +1,222 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use JSON::XS; +use Digest::MD5 qw(md5_hex); + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'api-username:s' => { name => 'api_username' }, + 'api-password:s' => { name => 'api_password' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'timeout:s' => { name => 'timeout' }, + 'unknown-http-status:s' => { name => 'unknown_http_status' }, + 'warning-http-status:s' => { name => 'warning_http_status' }, + 'critical-http-status:s' => { name => 'critical_http_status' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : ''; + $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : ''; + $self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300'; + $self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : ''; + $self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : ''; + + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_username}) || $self->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_password}) || $self->{api_password} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option."); + $self->{output}->option_exit(); + } + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{api_username}; + $self->{option_results}->{password} = $self->{api_password}; +} + +sub settings { + my ($self, %options) = @_; + + return if (defined($self->{settings_done})); + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{http}->add_header(key => 'Content-Type', value => 'application/json'); + $self->{http}->add_header(key => 'X-EMC-REST-CLIENT', value => 'true'); + $self->{http}->set_options(%{$self->{option_results}}); + $self->{settings_done} = 1; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + my $content = $self->{http}->request( + method => defined($options{method}) ? $options{method} : 'GET', + url_path => $options{url_path}, + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status}, + cookies_file => '', # in memory + ); + + if (!defined($content) || $content eq '') { + $self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); + $self->{output}->option_exit(); + } + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +1; + +__END__ + +=head1 NAME + +EMC Unisphere Rest API + +=head1 REST API OPTIONS + +EMC Unisphere Rest API + +=over 8 + +=item B<--hostname> + +EMC Unisphere hostname. + +=item B<--port> + +Port used (Default: 443) + +=item B<--proto> + +Specify https if needed (Default: 'https') + +=item B<--api-username> + +EMC Unisphere API username. + +=item B<--api-password> + +EMC Unisphere API password. + +=item B<--timeout> + +Set timeout in seconds (Default: 10). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/components/battery.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/battery.pm new file mode 100644 index 000000000..484c8d93a --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/battery.pm @@ -0,0 +1,65 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::components::battery; + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); + +sub load { + my ($self) = @_; + + $self->{json_results}->{battery} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/battery/instances'); +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking batteries'); + $self->{components}->{battery} = { name => 'batteries', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'battery')); + return if (!defined($self->{json_results}->{battery})); + + foreach my $result (@{$self->{json_results}->{battery}->{entries}}) { + my $instance = $result->{content}->{id}; + + next if ($self->check_filter(section => 'battery', instance => $instance)); + $self->{components}->{battery}->{total}++; + + my $health = $health_status->{ $result->{content}->{health}->{value} }; + $self->{output}->output_add( + long_msg => sprintf( + "battery '%s' status is '%s' [instance = %s]", + $result->{content}->{name}, $health, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'health', section => 'battery', value => $health); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Battery '%s' status is '%s'", $result->{content}->{name}, $health) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/components/disk.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/disk.pm new file mode 100644 index 000000000..1d1565256 --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/disk.pm @@ -0,0 +1,65 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::components::disk; + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); + +sub load { + my ($self) = @_; + + $self->{json_results}->{disks} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/disk/instances'); +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking disks'); + $self->{components}->{disk} = { name => 'disks', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'disk')); + return if (!defined($self->{json_results}->{disks})); + + foreach my $result (@{$self->{json_results}->{disks}->{entries}}) { + my $instance = $result->{content}->{id}; + + next if ($self->check_filter(section => 'disk', instance => $instance)); + $self->{components}->{disk}->{total}++; + + my $health = $health_status->{ $result->{content}->{health}->{value} }; + $self->{output}->output_add( + long_msg => sprintf( + "disk '%s' status is '%s' [instance = %s]", + $result->{content}->{name}, $health, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'health', section => 'disk', value => $health); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Disk '%s' status is '%s'", $result->{content}->{name}, $health) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/components/dpe.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/dpe.pm new file mode 100644 index 000000000..473cea495 --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/dpe.pm @@ -0,0 +1,99 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::components::dpe; + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); + +sub load { + my ($self) = @_; + + $self->{json_results}->{dpe} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/dpe/instances'); +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking disk processor enclosures'); + $self->{components}->{dpe} = { name => 'dpe', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'dpe')); + return if (!defined($self->{json_results}->{dpe})); + + foreach my $result (@{$self->{json_results}->{dpe}->{entries}}) { + my $instance = $result->{content}->{id}; + + next if ($self->check_filter(section => 'dpe', instance => $instance)); + $self->{components}->{dpe}->{total}++; + + my $health = $health_status->{ $result->{content}->{health}->{value} }; + $self->{output}->output_add( + long_msg => sprintf( + "dpe '%s' status is '%s' [instance = %s]", + $result->{content}->{name}, $health, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'health', section => 'dpe', value => $health); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("dpe '%s' status is '%s'", $result->{content}->{name}, $health) + ); + } + + if (defined($result->{content}->{currentTemperature}) && $result->{content}->{currentTemperature} =~ /[0-9]/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{content}->{currentTemperature}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit2, + short_msg => sprintf("dpe '%s' temperature is %s C", $result->{content}->{name}, $result->{content}->{currentTemperature}) + ); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.dpe.temperature.celsius', unit => 'C', + instances => $result->{content}->{name}, + value => $result->{content}->{currentTemperature}, + warning => $warn, + critical => $crit, + ); + } + + if (defined($result->{content}->{currentPower}) && $result->{content}->{currentPower} =~ /[0-9]/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'power', instance => $instance, value => $result->{content}->{currentPower}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit2, + short_msg => sprintf("dpe '%s' current power is %s W", $result->{content}->{name}, $result->{content}->{currentPower}) + ); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.dpe.power.watt', unit => 'W', + instances => $result->{content}->{name}, + value => $result->{content}->{currentPower}, + warning => $warn, + critical => $crit, + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/components/fan.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/fan.pm new file mode 100644 index 000000000..468b575e1 --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/fan.pm @@ -0,0 +1,65 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::components::fan; + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); + +sub load { + my ($self) = @_; + + $self->{json_results}->{fans} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/fan/instances'); +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking fans'); + $self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'fan')); + return if (!defined($self->{json_results}->{fan})); + + foreach my $result (@{$self->{json_results}->{fans}->{entries}}) { + my $instance = $result->{content}->{id}; + + next if ($self->check_filter(section => 'fan', instance => $instance)); + $self->{components}->{fan}->{total}++; + + my $health = $health_status->{ $result->{content}->{health}->{value} }; + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is '%s' [instance = %s]", + $result->{content}->{id}, $health, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'health', section => 'fan', value => $health); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Fan '%s' status is '%s'", $result->{content}->{id}, $health) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/components/iomodule.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/iomodule.pm new file mode 100644 index 000000000..9c3584859 --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/iomodule.pm @@ -0,0 +1,65 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::components::iomodule; + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); + +sub load { + my ($self) = @_; + + $self->{json_results}->{iomodules} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/ioModule/instances'); +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking iomodules'); + $self->{components}->{iomodule} = { name => 'iomodules', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'iomodule')); + return if (!defined($self->{json_results}->{iomodules})); + + foreach my $result (@{$self->{json_results}->{iomodules}->{entries}}) { + my $instance = $result->{content}->{id}; + + next if ($self->check_filter(section => 'iomodule', instance => $instance)); + $self->{components}->{iomodule}->{total}++; + + my $health = $health_status->{ $result->{content}->{health}->{value} }; + $self->{output}->output_add( + long_msg => sprintf( + "iomodule '%s' status is '%s' [instance = %s]", + $result->{content}->{name}, $health, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'health', section => 'iomodule', value => $health); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("iomodule '%s' status is '%s'", $result->{content}->{name}, $health) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/components/psu.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/psu.pm new file mode 100644 index 000000000..493f6cb4f --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/psu.pm @@ -0,0 +1,65 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::components::psu; + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); + +sub load { + my ($self) = @_; + + $self->{json_results}->{psus} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/powerSupply/instances'); +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking power supplies'); + $self->{components}->{psu} = { name => 'psus', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'psu')); + return if (!defined($self->{json_results}->{psus})); + + foreach my $result (@{$self->{json_results}->{psus}->{entries}}) { + my $instance = $result->{content}->{id}; + + next if ($self->check_filter(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; + + my $health = $health_status->{ $result->{content}->{health}->{value} }; + $self->{output}->output_add( + long_msg => sprintf( + "power supply '%s' status is '%s' [instance = %s]", + $result->{content}->{name}, $health, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'health', section => 'psu', value => $health); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Power supply '%s' status is '%s'", $result->{content}->{name}, $health) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/components/resources.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/resources.pm new file mode 100644 index 000000000..956bd6d39 --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/resources.pm @@ -0,0 +1,43 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our $health_status; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw($health_status); + +$health_status = { + 0 => 'unknown', + 5 => 'ok', + 7 => 'ok_but', + 10 => 'degraded', + 15 => 'minor', + 20 => 'major', + 25 => 'critical', + 30 => 'non_recoverable' +}; + +1; diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/components/sp.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/sp.pm new file mode 100644 index 000000000..fda696a87 --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/sp.pm @@ -0,0 +1,65 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::components::sp; + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); + +sub load { + my ($self) = @_; + + $self->{json_results}->{sp} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/storageProcessor/instances'); +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking storage processors'); + $self->{components}->{sp} = { name => 'sp', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'sp')); + return if (!defined($self->{json_results}->{sp})); + + foreach my $result (@{$self->{json_results}->{sp}->{entries}}) { + my $instance = $result->{content}->{id}; + + next if ($self->check_filter(section => 'sp', instance => $instance)); + $self->{components}->{sp}->{total}++; + + my $health = $health_status->{ $result->{content}->{health}->{value} }; + $self->{output}->output_add( + long_msg => sprintf( + "storage processor '%s' status is '%s' [instance = %s]", + $result->{content}->{name}, $health, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'health', section => 'sp', value => $health); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Storage processor '%s' status is '%s'", $result->{content}->{name}, $health) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/components/ssd.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/ssd.pm new file mode 100644 index 000000000..900475de2 --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/components/ssd.pm @@ -0,0 +1,65 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::components::ssd; + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); + +sub load { + my ($self) = @_; + + $self->{json_results}->{ssd} = $self->{custom}->request_api(method => 'GET', url_path => '/api/types/ssd/instances'); +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking ssd'); + $self->{components}->{ssd} = { name => 'ssd', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'ssd')); + return if (!defined($self->{json_results}->{ssd})); + + foreach my $result (@{$self->{json_results}->{ssd}->{entries}}) { + my $instance = $result->{content}->{id}; + + next if ($self->check_filter(section => 'ssd', instance => $instance)); + $self->{components}->{ssd}->{total}++; + + my $health = $health_status->{ $result->{content}->{health}->{value} }; + $self->{output}->output_add( + long_msg => sprintf( + "ssd '%s' status is '%s' [instance = %s]", + $result->{content}->{name}, $health, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'health', section => 'ssd', value => $health); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("ssd '%s' status is '%s'", $result->{content}->{name}, $health) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/hardware.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/hardware.pm new file mode 100644 index 000000000..d873dc1c1 --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/hardware.pm @@ -0,0 +1,110 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(disk|fan|iomodule|psu|dpe|battery|ssd|sp)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|power)$'; + + $self->{cb_hook1} = 'init_custom'; + + $self->{thresholds} = { + health => [ + ['ok_but', 'WARNING'], + ['ok', 'OK'], + ['degraded', 'WARNING'], + ['minor', 'WARNING'], + ['major', 'CRITICAL'], + ['critical', 'CRITICAL'], + ['non_recoverable', 'CRITICAL'], + ['unknown', 'UNKNOWN'], + ], + }; + + $self->{components_path} = 'storage::emc::unisphere::restapi::mode::components'; + $self->{components_module} = ['disk', 'fan', 'iomodule', 'psu', 'dpe', 'battery', 'ssd', 'sp']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub init_custom { + my ($self, %options) = @_; + + $self->{custom} = $options{custom}; +} + +1; + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'disk', 'fan', 'iomodule', 'psu', 'dpe', 'battery', 'ssd', 'sp'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter='disk,dpe_disk_6' + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='disk,OK,ok_but' + +=item B<--warning> + +Set warning threshold for 'temperature', 'power' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,40' + +=item B<--critical> + +Set critical threshold for 'temperature', 'power' (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,50' + +=back + +=cut diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/listpools.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/listpools.pm new file mode 100644 index 000000000..df1bce6ff --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/listpools.pm @@ -0,0 +1,109 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::listpools; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + return $options{custom}->request_api(url_path => '/api/types/pool/instances'); +} + +sub run { + my ($self, %options) = @_; + + my $pools = $self->manage_selection(%options); + foreach (@{$pools->{entries}}) { + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' + && $_->{content}->{name} !~ /$self->{option_results}->{filter_name}/); + + $self->{output}->output_add(long_msg => sprintf( + '[name = %s][status = %s]', + $_->{content}->{name}, + $health_status->{ $_->{content}->{health}->{value} }, + )); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List pools:' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + my $pools = $self->manage_selection(%options); + foreach (@{$pools->{entries}}) { + $self->{output}->add_disco_entry( + name => $_->{content}->{name}, + status => $health_status->{ $_->{content}->{health}->{value} }, + ); + } +} + +1; + +__END__ + +=head1 MODE + +List pools. + +=over 8 + +=item B<--filter-name> + +Filter pool name (Can be a regexp). + +=back + +=cut diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/liststorageresources.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/liststorageresources.pm new file mode 100644 index 000000000..6718703c4 --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/liststorageresources.pm @@ -0,0 +1,109 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::liststorageresources; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + return $options{custom}->request_api(url_path => '/api/types/storageResource/instances'); +} + +sub run { + my ($self, %options) = @_; + + my $storages = $self->manage_selection(%options); + foreach (@{$storages->{entries}}) { + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' + && $_->{content}->{name} !~ /$self->{option_results}->{filter_name}/); + + $self->{output}->output_add(long_msg => sprintf( + '[name = %s][status = %s]', + $_->{content}->{name}, + $health_status->{ $_->{content}->{health}->{value} }, + )); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List storage resources:' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + my $storages = $self->manage_selection(%options); + foreach (@{$storages->{entries}}) { + $self->{output}->add_disco_entry( + name => $_->{content}->{name}, + status => $health_status->{ $_->{content}->{health}->{value} }, + ); + } +} + +1; + +__END__ + +=head1 MODE + +List pools. + +=over 8 + +=item B<--filter-name> + +Filter pool name (Can be a regexp). + +=back + +=cut diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/pools.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/pools.pm new file mode 100644 index 000000000..97c128ad6 --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/pools.pm @@ -0,0 +1,237 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::pools; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space_absolute}); + my $msg = sprintf('space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space_absolute} + ); + return $msg; +} + +sub custom_subscribed_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_sub_absolute}); + $self->{result_values}->{free_sub_absolute} = 0 if ($self->{result_values}->{free_sub_absolute} < 0); + $self->{result_values}->{prct_free_sub_absolute} = 0 if ($self->{result_values}->{prct_free_sub_absolute} < 0); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_sub_absolute}); + my $msg = sprintf('subscribed usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_sub_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_sub_absolute} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All pools are ok' }, + ]; + + $self->{maps_counters}->{pool} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'usage', nlabel => 'pool.space.usage.bytes', set => { + key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-free', nlabel => 'pool.space.free.bytes', display_ok => 0, set => { + key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-prct', nlabel => 'pool.space.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], + output_template => 'used : %.2f %%', + perfdatas => [ + { value => 'prct_used_space_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'subscribed', nlabel => 'pool.subscribed.usage.bytes', display_ok => 0, set => { + key_values => [ { name => 'used_sub' }, { name => 'free_sub' }, { name => 'prct_used_sub' }, { name => 'prct_free_sub' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_subscribed_output'), + perfdatas => [ + { value => 'used_sub_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'subscribed-prct', display_ok => 0, nlabel => 'pool.subscribed.usage.percentage', set => { + key_values => [ { name => 'prct_used_sub' }, { name => 'display' } ], + output_template => 'subcribed used : %.2f %%', + perfdatas => [ + { value => 'prct_used_sub_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /ok_but|degraded|minor/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /major|criticalnon_recoverable/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +sub prefix_pool_output { + my ($self, %options) = @_; + + return "Pool '" . $options{instance_value}->{display} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->request_api(url_path => '/api/types/pool/instances'); + + $self->{pool} = {}; + foreach (@{$results->{entries}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{content}->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping pool '" . $_->{content}->{name} . "': no matching filter.", debug => 1); + next; + } + + my $used = $_->{content}->{sizeTotal} - $_->{content}->{sizeFree}; + $self->{pool}->{$_->{content}->{id}} = { + display => $_->{content}->{name}, + status => $health_status->{ $_->{content}->{health}->{value} }, + total_space => $_->{content}->{sizeTotal}, + used_space => $used, + free_space => $_->{content}->{sizeFree}, + prct_used_space => $used * 100 / $_->{content}->{sizeTotal}, + prct_free_space => $_->{content}->{sizeFree} * 100 / $_->{content}->{sizeTotal}, + + used_sub => $_->{content}->{sizeSubscribed}, + free_sub => $_->{content}->{sizeTotal} - $_->{content}->{sizeSubscribed}, + prct_used_sub => $_->{content}->{sizeSubscribed} * 100 / $_->{content}->{sizeTotal}, + prct_free_sub => 100 - ($_->{content}->{sizeSubscribed} * 100 / $_->{content}->{sizeTotal}), + }; + } + + if (scalar(keys %{$self->{pool}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No pool found"); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check pool usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^usage$' + +=item B<--filter-name> + +Filter pool name (can be a regexp). + +=item B<--unknown-status> + +Set warning threshold for status (Default: '%{status} =~ /unknown/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /ok_but|degraded|minor/i'). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /major|criticalnon_recoverable/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%), +'subscribed', 'subscribed-prct'. + +=back + +=cut diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/storageresources.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/storageresources.pm new file mode 100644 index 000000000..4dac3db47 --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/storageresources.pm @@ -0,0 +1,236 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::mode::storageresources; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use storage::emc::unisphere::restapi::mode::components::resources qw($health_status); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space_absolute}); + my $msg = sprintf('space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space_absolute} + ); + return $msg; +} + +sub custom_allocated_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_alloc_absolute}); + $self->{result_values}->{free_alloc_absolute} = 0 if ($self->{result_values}->{free_alloc_absolute} < 0); + $self->{result_values}->{prct_free_alloc_absolute} = 0 if ($self->{result_values}->{prct_free_alloc_absolute} < 0); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_alloc_absolute}); + my $msg = sprintf('allocated usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_alloc_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_alloc_absolute} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'sr', type => 1, cb_prefix_output => 'prefix_sr_output', message_multiple => 'All storage resources are ok' }, + ]; + + $self->{maps_counters}->{sr} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'usage', nlabel => 'storageresource.space.usage.bytes', set => { + key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-free', nlabel => 'storageresource.space.free.bytes', display_ok => 0, set => { + key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-prct', nlabel => 'storageresource.space.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], + output_template => 'used : %.2f %%', + perfdatas => [ + { value => 'prct_used_space_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'allocated', nlabel => 'storageresource.allocated.usage.bytes', display_ok => 0, set => { + key_values => [ { name => 'used_alloc' }, { name => 'free_alloc' }, { name => 'prct_used_alloc' }, { name => 'prct_free_alloc' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_allocated_output'), + perfdatas => [ + { value => 'used_alloc_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'allocated-prct', display_ok => 0, nlabel => 'storageresource.allocated.usage.percentage', set => { + key_values => [ { name => 'prct_used_alloc' }, { name => 'display' } ], + output_template => 'allocated used : %.2f %%', + perfdatas => [ + { value => 'prct_used_alloc_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /ok_but|degraded|minor/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /major|criticalnon_recoverable/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +sub prefix_sr_output { + my ($self, %options) = @_; + + return "Storage resource '" . $options{instance_value}->{display} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->request_api(url_path => '/api/types/storageResource/instances'); + + $self->{sr} = {}; + foreach (@{$results->{entries}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{content}->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping storage resource '" . $_->{content}->{name} . "': no matching filter.", debug => 1); + next; + } + + $self->{sr}->{$_->{content}->{id}} = { + display => $_->{content}->{name}, + status => $health_status->{ $_->{content}->{health}->{value} }, + total_space => $_->{content}->{sizeTotal}, + used_space => $_->{content}->{sizeUsed}, + free_space => $_->{content}->{sizeTotal} - $_->{content}->{sizeUsed}, + prct_used_space => $_->{content}->{sizeUsed} * 100 / $_->{content}->{sizeTotal}, + prct_free_space => 100 - ($_->{content}->{sizeUsed} * 100 / $_->{content}->{sizeTotal}), + + used_alloc => $_->{content}->{sizeAllocated}, + free_alloc => $_->{content}->{sizeTotal} - $_->{content}->{sizeAllocated}, + prct_used_alloc => $_->{content}->{sizeAllocated} * 100 / $_->{content}->{sizeTotal}, + prct_free_alloc => 100 - ($_->{content}->{sizeAllocated} * 100 / $_->{content}->{sizeTotal}), + }; + } + + if (scalar(keys %{$self->{sr}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No storage resource found"); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check storage resources. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^usage$' + +=item B<--filter-name> + +Filter name (can be a regexp). + +=item B<--unknown-status> + +Set warning threshold for status (Default: '%{status} =~ /unknown/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /ok_but|degraded|minor/i'). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /major|criticalnon_recoverable/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%), +'allocated', 'allocated-prct'. + +=back + +=cut diff --git a/centreon-plugins/storage/emc/unisphere/restapi/plugin.pm b/centreon-plugins/storage/emc/unisphere/restapi/plugin.pm new file mode 100644 index 000000000..3e0c716bc --- /dev/null +++ b/centreon-plugins/storage/emc/unisphere/restapi/plugin.pm @@ -0,0 +1,53 @@ +# +# Copyright 2019 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 storage::emc::unisphere::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{ $self->{modes} } = ( + 'hardware' => 'storage::emc::unisphere::restapi::mode::hardware', + 'list-pools' => 'storage::emc::unisphere::restapi::mode::listpools', + 'list-storage-resources' => 'storage::emc::unisphere::restapi::mode::liststorageresources', + 'pools' => 'storage::emc::unisphere::restapi::mode::pools', + 'storage-resources' => 'storage::emc::unisphere::restapi::mode::storageresources', + ); + + $self->{custom_modes}{api} = 'storage::emc::unisphere::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check EMC storage with Unisphere using Rest API. + +=cut diff --git a/centreon-plugins/storage/emc/vplex/restapi/mode/clustercommunication.pm b/centreon-plugins/storage/emc/vplex/restapi/mode/clustercommunication.pm index cd4f646ba..9de2ce5e2 100644 --- a/centreon-plugins/storage/emc/vplex/restapi/mode/clustercommunication.pm +++ b/centreon-plugins/storage/emc/vplex/restapi/mode/clustercommunication.pm @@ -38,7 +38,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "filter:s@" => { name => 'filter' }, diff --git a/centreon-plugins/storage/emc/vplex/restapi/mode/clusterdevices.pm b/centreon-plugins/storage/emc/vplex/restapi/mode/clusterdevices.pm index a6055aeb0..dc8365c3c 100644 --- a/centreon-plugins/storage/emc/vplex/restapi/mode/clusterdevices.pm +++ b/centreon-plugins/storage/emc/vplex/restapi/mode/clusterdevices.pm @@ -37,7 +37,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "cluster:s" => { name => 'cluster' }, diff --git a/centreon-plugins/storage/emc/vplex/restapi/mode/directors.pm b/centreon-plugins/storage/emc/vplex/restapi/mode/directors.pm index baabbc3f3..1f89ab28c 100644 --- a/centreon-plugins/storage/emc/vplex/restapi/mode/directors.pm +++ b/centreon-plugins/storage/emc/vplex/restapi/mode/directors.pm @@ -53,7 +53,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "engine:s" => { name => 'engine' }, diff --git a/centreon-plugins/storage/emc/vplex/restapi/mode/distributeddevices.pm b/centreon-plugins/storage/emc/vplex/restapi/mode/distributeddevices.pm index 3c7bd2a0c..6f5ea0292 100644 --- a/centreon-plugins/storage/emc/vplex/restapi/mode/distributeddevices.pm +++ b/centreon-plugins/storage/emc/vplex/restapi/mode/distributeddevices.pm @@ -45,7 +45,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "filter:s@" => { name => 'filter' }, diff --git a/centreon-plugins/storage/emc/vplex/restapi/mode/fans.pm b/centreon-plugins/storage/emc/vplex/restapi/mode/fans.pm index 10d6a35b1..cb8cfbf85 100644 --- a/centreon-plugins/storage/emc/vplex/restapi/mode/fans.pm +++ b/centreon-plugins/storage/emc/vplex/restapi/mode/fans.pm @@ -41,7 +41,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "engine:s" => { name => 'engine' }, diff --git a/centreon-plugins/storage/emc/vplex/restapi/mode/psus.pm b/centreon-plugins/storage/emc/vplex/restapi/mode/psus.pm index f58e5377d..96107d2c7 100644 --- a/centreon-plugins/storage/emc/vplex/restapi/mode/psus.pm +++ b/centreon-plugins/storage/emc/vplex/restapi/mode/psus.pm @@ -40,7 +40,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "engine:s" => { name => 'engine' }, diff --git a/centreon-plugins/storage/emc/vplex/restapi/mode/storagevolumes.pm b/centreon-plugins/storage/emc/vplex/restapi/mode/storagevolumes.pm index 2fb80bdb0..5c5c5850d 100644 --- a/centreon-plugins/storage/emc/vplex/restapi/mode/storagevolumes.pm +++ b/centreon-plugins/storage/emc/vplex/restapi/mode/storagevolumes.pm @@ -37,7 +37,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "cluster:s" => { name => 'cluster' }, diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm index 2a0040d89..6801c877e 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "filter:s@" => { name => 'filter' }, diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdendurance.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdendurance.pm index 361df7761..1536cf267 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdendurance.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdendurance.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "filter:s@" => { name => 'filter' }, diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm index db12f5cc5..0dca8a7f4 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm @@ -99,7 +99,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvscpu.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvscpu.pm index 95b04a01e..4678fdd8f 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvscpu.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvscpu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "filter:s@" => { name => 'filter' }, diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvsstate.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvsstate.pm index 6cbf0aff8..d60076438 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvsstate.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvsstate.pm @@ -37,7 +37,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; $options{options}->add_options(arguments => { "filter:s@" => { name => 'filter' }, diff --git a/centreon-plugins/storage/exagrid/snmp/mode/serverusage.pm b/centreon-plugins/storage/exagrid/snmp/mode/serverusage.pm index 2f242e1f5..e32e6e5b2 100644 --- a/centreon-plugins/storage/exagrid/snmp/mode/serverusage.pm +++ b/centreon-plugins/storage/exagrid/snmp/mode/serverusage.pm @@ -128,7 +128,6 @@ sub new { 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 => '%{status} =~ /warning/i' }, @@ -170,9 +169,9 @@ sub manage_selection { $self->{server} = { status => $result->{egServerAlarmState}, retention_total => $result->{egRetentionSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000, - retention_used => $result->{egRetentionSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000 - $result->{egLandingSpaceAvailableWholeGigabytes} * 1000 * 1000 * 1000, - landing_total => $result->{egRetentionSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000, - landing_used => $result->{egRetentionSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000 - $result->{egRetentionSpaceAvailableWholeGigabytes} * 1000 * 1000 * 1000, + retention_used => $result->{egRetentionSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000 - $result->{egRetentionSpaceAvailableWholeGigabytes} * 1000 * 1000 * 1000, + landing_total => $result->{egLandingSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000, + landing_used => $result->{egLandingSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000 - $result->{egLandingSpaceAvailableWholeGigabytes} * 1000 * 1000 * 1000, }; } diff --git a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/cpu.pm b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/cpu.pm index 3f5b77760..5e44fd2a4 100644 --- a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/cpu.pm +++ b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/cpu.pm @@ -57,7 +57,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "ssh-option:s@" => { name => 'ssh_option' }, diff --git a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/physicaldisk.pm b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/physicaldisk.pm index 7aa795c8d..aaf7d559b 100644 --- a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/physicaldisk.pm +++ b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/physicaldisk.pm @@ -50,7 +50,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/portstats.pm b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/portstats.pm index 3ca8cf100..5111c0550 100644 --- a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/portstats.pm +++ b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/portstats.pm @@ -84,7 +84,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "ssh-option:s@" => { name => 'ssh_option' }, diff --git a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/psu.pm b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/psu.pm index a047ad160..d4f7944da 100644 --- a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/psu.pm +++ b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/psu.pm @@ -44,7 +44,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/raidgroups.pm b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/raidgroups.pm index cc191b1be..0e05730a9 100644 --- a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/raidgroups.pm +++ b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/raidgroups.pm @@ -125,7 +125,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "ssh-option:s@" => { name => 'ssh_option' }, diff --git a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/volumestats.pm b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/volumestats.pm index 4a7774eb6..0cb5b9002 100644 --- a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/volumestats.pm +++ b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/volumestats.pm @@ -138,7 +138,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "ssh-option:s@" => { name => 'ssh_option' }, diff --git a/centreon-plugins/storage/hitachi/standard/snmp/mode/hardware.pm b/centreon-plugins/storage/hitachi/standard/snmp/mode/hardware.pm index 6befb3ebe..4a10d2be2 100644 --- a/centreon-plugins/storage/hitachi/standard/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/hitachi/standard/snmp/mode/hardware.pm @@ -62,7 +62,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/hp/3par/ssh/custom/custom.pm b/centreon-plugins/storage/hp/3par/ssh/custom/custom.pm index aa0b39945..0e5c003a9 100644 --- a/centreon-plugins/storage/hp/3par/ssh/custom/custom.pm +++ b/centreon-plugins/storage/hp/3par/ssh/custom/custom.pm @@ -108,9 +108,10 @@ sub execute_command { } return centreon::plugins::misc::execute( + ssh_pipe => 1, output => $self->{output}, options => $self->{option_results}, - command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands} . "; exit\n", + command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands}, command_path => $self->{option_results}->{command_path}, command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef ); diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/components/battery.pm b/centreon-plugins/storage/hp/3par/ssh/mode/components/battery.pm index 9c819f7e2..69953ca75 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/components/battery.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/components/battery.pm @@ -31,7 +31,7 @@ sub load { # 0,1 1 0 6CQUBA1HN5063G OK 100 n/a No No # 2,3 0 0 6CQUBA1HN484RB OK 100 n/a No No # 2,3 1 0 6CQUBA1HN484R9 OK 100 n/a No No - push @{$self->{commands}}, 'echo "===showbattery===', 'showbattery'; + push @{$self->{commands}}, 'echo "===showbattery==="', 'showbattery'; } sub check { diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/components/cim.pm b/centreon-plugins/storage/hp/3par/ssh/mode/components/cim.pm index 7187b63d5..5ba3e8d9d 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/components/cim.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/components/cim.pm @@ -28,7 +28,7 @@ sub load { #-Service- -State- --SLP-- SLPPort -HTTP-- HTTPPort -HTTPS- HTTPSPort PGVer CIMVer #Enabled Active Enabled 427 Enabled 5988 Enabled 5989 2.9.1 3.2.2 - push @{$self->{commands}}, 'echo "===showcim===', 'showcim'; + push @{$self->{commands}}, 'echo "===showcim==="', 'showcim'; } sub check { diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/components/disk.pm b/centreon-plugins/storage/hp/3par/ssh/mode/components/disk.pm index 5fc080bff..f3f5b76f0 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/components/disk.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/components/disk.pm @@ -33,7 +33,7 @@ sub load { #... # 10 normal # 11 normal - push @{$self->{commands}}, 'echo "===showdisk===', 'showpd -showcols Id,State'; + push @{$self->{commands}}, 'echo "===showdisk==="', 'showpd -showcols Id,State'; } sub check { diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/components/node.pm b/centreon-plugins/storage/hp/3par/ssh/mode/components/node.pm index e5275fccc..ddbdf4bfb 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/components/node.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/components/node.pm @@ -31,7 +31,7 @@ sub load { #1 OK OK #2 OK OK #3 OK OK - push @{$self->{commands}}, 'echo "===shownode===', 'shownode -state'; + push @{$self->{commands}}, 'echo "===shownode==="', 'shownode -state'; } sub check { diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/components/port.pm b/centreon-plugins/storage/hp/3par/ssh/mode/components/port.pm index 3d4d759d0..35c08a4b9 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/components/port.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/components/port.pm @@ -38,7 +38,7 @@ sub load { #0:3:1 peer offline - B4B52FA71D43 free IP IP0 - - #1:0:1 initiator ready 50002ACFF70047C0 50002AC1010047C0 disk SAS DP-1 - - #1:0:2 initiator ready 50002ACFF70047C0 50002AC1020047C0 disk SAS DP-2 - - - push @{$self->{commands}}, 'echo "===showport===', 'showport'; + push @{$self->{commands}}, 'echo "===showport==="', 'showport'; } sub check { diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/components/psu.pm b/centreon-plugins/storage/hp/3par/ssh/mode/components/psu.pm index c1295eca9..58d9b52d2 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/components/psu.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/components/psu.pm @@ -31,7 +31,7 @@ sub load { # 0,1 1 682372-001 5CQLQA1434W2ED OK OK OK # 2,3 0 682372-001 5CQLQA1433Y0KS OK OK OK # 2,3 1 682372-001 5CQLQX1XX3E056 OK OK OK - push @{$self->{commands}}, 'echo "===showpsu===', 'shownode -ps'; + push @{$self->{commands}}, 'echo "===showpsu==="', 'shownode -ps'; } sub check { diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/components/sensor.pm b/centreon-plugins/storage/hp/3par/ssh/mode/components/sensor.pm index 3e41af3d8..b179e868a 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/components/sensor.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/components/sensor.pm @@ -47,7 +47,7 @@ sub load { # PCM 0 inlet 27 C 10 C 50 C Within Tolerance # PCM 0 hotspot 21 C 10 C 65 C Within Tolerance # Node Input PWR 87.6 W 0.0 W 264.0 W Within Tolerance - push @{$self->{commands}}, 'echo "===shownodeenv===', 'shownodeenv'; + push @{$self->{commands}}, 'echo "===shownodeenv==="', 'shownodeenv'; } sub check { diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/components/wsapi.pm b/centreon-plugins/storage/hp/3par/ssh/mode/components/wsapi.pm index f7db4f896..be80688db 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/components/wsapi.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/components/wsapi.pm @@ -28,7 +28,7 @@ sub load { #-Service- -State- -HTTP_State- HTTP_Port -HTTPS_State- HTTPS_Port -Version- -----------------API_URL------------------ #Enabled Active Disabled 8008 Enabled 8080 1.5.3 https://xxxx:8080/api/v1 - push @{$self->{commands}}, 'echo "===showwsapi===', 'showwsapi'; + push @{$self->{commands}}, 'echo "===showwsapi==="', 'showwsapi'; } sub check { diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/diskusage.pm b/centreon-plugins/storage/hp/3par/ssh/mode/diskusage.pm index 731f9ab99..10dfcb2fb 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/diskusage.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/diskusage.pm @@ -84,7 +84,7 @@ sub set_counters { key_values => [ { name => 'prct_used' }, { name => 'display' } ], output_template => 'Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%d', min => 0, max => 0, + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-status:s" => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/hardware.pm b/centreon-plugins/storage/hp/3par/ssh/mode/hardware.pm index 3561052a5..e814a5de3 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/hardware.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/hardware.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm b/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm index 18bbcf013..e4e6326b9 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm @@ -68,7 +68,7 @@ sub set_counters { key_values => [ { name => 'prct_used' }, { name => 'display' } ], output_template => 'Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%d', min => 0, max => 0, + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } @@ -81,7 +81,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/storage/hp/eva/cli/mode/hardware.pm b/centreon-plugins/storage/hp/eva/cli/mode/hardware.pm index ec7b27017..213a43264 100644 --- a/centreon-plugins/storage/hp/eva/cli/mode/hardware.pm +++ b/centreon-plugins/storage/hp/eva/cli/mode/hardware.pm @@ -60,7 +60,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/hp/eva/cli/mode/storageusage.pm b/centreon-plugins/storage/hp/eva/cli/mode/storageusage.pm index a30a974be..37ddf6015 100644 --- a/centreon-plugins/storage/hp/eva/cli/mode/storageusage.pm +++ b/centreon-plugins/storage/hp/eva/cli/mode/storageusage.pm @@ -112,7 +112,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, diff --git a/centreon-plugins/storage/hp/lefthand/snmp/mode/hardware.pm b/centreon-plugins/storage/hp/lefthand/snmp/mode/hardware.pm index db3f5a08d..90f1a3b96 100644 --- a/centreon-plugins/storage/hp/lefthand/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/hp/lefthand/snmp/mode/hardware.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/hp/lefthand/snmp/mode/volumeusage.pm b/centreon-plugins/storage/hp/lefthand/snmp/mode/volumeusage.pm index 4823b86ec..231bff25a 100644 --- a/centreon-plugins/storage/hp/lefthand/snmp/mode/volumeusage.pm +++ b/centreon-plugins/storage/hp/lefthand/snmp/mode/volumeusage.pm @@ -198,7 +198,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-replication-status:s" => { name => 'warning_replication_status', default => '' }, diff --git a/centreon-plugins/storage/hp/msa2000/snmp/plugin.pm b/centreon-plugins/storage/hp/msa2000/snmp/plugin.pm index 905c7a8e2..e7cf7c00a 100644 --- a/centreon-plugins/storage/hp/msa2000/snmp/plugin.pm +++ b/centreon-plugins/storage/hp/msa2000/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'snmp_standard::mode::hardwarefibrealliance', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'hardware' => 'snmp_standard::mode::hardwarefibrealliance', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); return $self; } diff --git a/centreon-plugins/storage/hp/msl/snmp/mode/hardware.pm b/centreon-plugins/storage/hp/msl/snmp/mode/hardware.pm index 0d1587a25..a5ca00ba3 100644 --- a/centreon-plugins/storage/hp/msl/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/hp/msl/snmp/mode/hardware.pm @@ -52,7 +52,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/hp/p2000/xmlapi/mode/components/enclosure.pm b/centreon-plugins/storage/hp/p2000/xmlapi/mode/components/enclosure.pm index 032380ea4..8bf4bfe10 100644 --- a/centreon-plugins/storage/hp/p2000/xmlapi/mode/components/enclosure.pm +++ b/centreon-plugins/storage/hp/p2000/xmlapi/mode/components/enclosure.pm @@ -52,7 +52,7 @@ sub check { my $state = $health{$results->{$enc_id}->{'health-numeric'}}; $self->{output}->output_add(long_msg => sprintf("enclosure '%s' status is %s [instance: %s] [reason: %s]", - $enc_id, $state, $enc_id, $health{$results->{$enc_id}->{'health-reason'}}) + $enc_id, $state, $enc_id, $results->{$enc_id}->{'health-reason'}) ); my $exit = $self->get_severity(label => 'default', section => 'enclosure', value => $state); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { diff --git a/centreon-plugins/storage/hp/p2000/xmlapi/mode/components/sensor.pm b/centreon-plugins/storage/hp/p2000/xmlapi/mode/components/sensor.pm index c5983c119..b180d8ac9 100644 --- a/centreon-plugins/storage/hp/p2000/xmlapi/mode/components/sensor.pm +++ b/centreon-plugins/storage/hp/p2000/xmlapi/mode/components/sensor.pm @@ -62,7 +62,7 @@ sub check { # Warning # foreach my $sensor_id (keys %$results) { - my ($value, $unit); + my ($value, $unit) = (undef, '');; ($value, $unit) = ($1, $2) if ($results->{$sensor_id}->{value} =~ /\s*([0-9\.,]+)\s*(\S*)\s*/); if (defined($results->{$sensor_id}->{'sensor-type'}) && defined($sensor_type{$results->{$sensor_id}->{'sensor-type'}})) { $unit = $sensor_type{$results->{$sensor_id}->{'sensor-type'}}->{unit}; diff --git a/centreon-plugins/storage/hp/p2000/xmlapi/mode/health.pm b/centreon-plugins/storage/hp/p2000/xmlapi/mode/health.pm index 5314177fe..152c1d7ca 100644 --- a/centreon-plugins/storage/hp/p2000/xmlapi/mode/health.pm +++ b/centreon-plugins/storage/hp/p2000/xmlapi/mode/health.pm @@ -38,19 +38,22 @@ sub set_system { $self->{thresholds} = { # disk, enclosure, vdisk default => [ + ['ok', 'OK'], ['degraded', 'WARNING'], - ['failed', 'CRITICAL'], + ['failed|fault', 'CRITICAL'], ['unknown|not available', 'UNKNOWN'], ], fru => [ + ['ok', 'OK'], ['absent', 'WARNING'], ['fault', 'CRITICAL'], ['not available', 'UNKNOWN'], ], sensor => [ + ['ok', 'OK'], ['warning|not installed|unavailable', 'WARNING'], ['error|unrecoverable', 'CRITICAL'], - ['nknown|unsupported', 'UNKNOWN'], + ['unknown|unsupported', 'UNKNOWN'], ], }; @@ -70,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/hp/p2000/xmlapi/mode/listvolumes.pm b/centreon-plugins/storage/hp/p2000/xmlapi/mode/listvolumes.pm index 839796534..10acb2ac5 100644 --- a/centreon-plugins/storage/hp/p2000/xmlapi/mode/listvolumes.pm +++ b/centreon-plugins/storage/hp/p2000/xmlapi/mode/listvolumes.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'name:s' => { name => 'name' }, 'regexp" => { name => 'use_regexp' }, diff --git a/centreon-plugins/storage/hp/p2000/xmlapi/mode/volumesstats.pm b/centreon-plugins/storage/hp/p2000/xmlapi/mode/volumesstats.pm index 2b0a8954c..a214ca364 100644 --- a/centreon-plugins/storage/hp/p2000/xmlapi/mode/volumesstats.pm +++ b/centreon-plugins/storage/hp/p2000/xmlapi/mode/volumesstats.pm @@ -125,7 +125,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'name:s' => { name => 'name' }, 'regexp' => { name => 'use_regexp' }, diff --git a/centreon-plugins/storage/hp/storeonce/restapi/mode/clusterusage.pm b/centreon-plugins/storage/hp/storeonce/restapi/mode/clusterusage.pm index d1e27e4eb..6a2b92e41 100644 --- a/centreon-plugins/storage/hp/storeonce/restapi/mode/clusterusage.pm +++ b/centreon-plugins/storage/hp/storeonce/restapi/mode/clusterusage.pm @@ -148,7 +148,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-status:s" => { name => 'warning_status', default => '%{health} =~ /warning/' }, diff --git a/centreon-plugins/storage/hp/storeonce/restapi/mode/fcsusage.pm b/centreon-plugins/storage/hp/storeonce/restapi/mode/fcsusage.pm index 714de7392..831d2ee11 100644 --- a/centreon-plugins/storage/hp/storeonce/restapi/mode/fcsusage.pm +++ b/centreon-plugins/storage/hp/storeonce/restapi/mode/fcsusage.pm @@ -94,7 +94,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-status:s" => { name => 'warning_status', default => '%{is_online} == 1 and %{health} =~ /warning/i' }, diff --git a/centreon-plugins/storage/hp/storeonce/restapi/mode/nasusage.pm b/centreon-plugins/storage/hp/storeonce/restapi/mode/nasusage.pm index cb5d2c9de..b90d738a6 100644 --- a/centreon-plugins/storage/hp/storeonce/restapi/mode/nasusage.pm +++ b/centreon-plugins/storage/hp/storeonce/restapi/mode/nasusage.pm @@ -94,7 +94,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-nas-status:s" => { name => 'warning_nas_status', default => '%{health} =~ /warning/i' }, diff --git a/centreon-plugins/storage/hp/storeonce/restapi/mode/servicesetusage.pm b/centreon-plugins/storage/hp/storeonce/restapi/mode/servicesetusage.pm index 4c1a33279..d76d6200b 100644 --- a/centreon-plugins/storage/hp/storeonce/restapi/mode/servicesetusage.pm +++ b/centreon-plugins/storage/hp/storeonce/restapi/mode/servicesetusage.pm @@ -152,7 +152,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-status:s" => { name => 'warning_status', default => '%{health} =~ /warning/' }, diff --git a/centreon-plugins/storage/hp/storeonce/ssh/mode/hardware.pm b/centreon-plugins/storage/hp/storeonce/ssh/mode/hardware.pm index 203ce95ea..aed9bf82e 100644 --- a/centreon-plugins/storage/hp/storeonce/ssh/mode/hardware.pm +++ b/centreon-plugins/storage/hp/storeonce/ssh/mode/hardware.pm @@ -61,7 +61,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/ibm/fs900/snmp/mode/arraysstatus.pm b/centreon-plugins/storage/ibm/fs900/snmp/mode/arraysstatus.pm index 3889c19f7..1c56b44d9 100644 --- a/centreon-plugins/storage/ibm/fs900/snmp/mode/arraysstatus.pm +++ b/centreon-plugins/storage/ibm/fs900/snmp/mode/arraysstatus.pm @@ -79,7 +79,6 @@ sub new { 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 => '' }, diff --git a/centreon-plugins/storage/ibm/fs900/snmp/mode/arraysusage.pm b/centreon-plugins/storage/ibm/fs900/snmp/mode/arraysusage.pm index 05d019c91..376b48245 100644 --- a/centreon-plugins/storage/ibm/fs900/snmp/mode/arraysusage.pm +++ b/centreon-plugins/storage/ibm/fs900/snmp/mode/arraysusage.pm @@ -123,7 +123,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/ibm/fs900/snmp/mode/fcusage.pm b/centreon-plugins/storage/ibm/fs900/snmp/mode/fcusage.pm index ddd8eefa9..69ad2040d 100644 --- a/centreon-plugins/storage/ibm/fs900/snmp/mode/fcusage.pm +++ b/centreon-plugins/storage/ibm/fs900/snmp/mode/fcusage.pm @@ -142,7 +142,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/ibm/fs900/snmp/mode/hardware.pm b/centreon-plugins/storage/ibm/fs900/snmp/mode/hardware.pm index 9cb818e44..932457d2c 100644 --- a/centreon-plugins/storage/ibm/fs900/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/ibm/fs900/snmp/mode/hardware.pm @@ -63,7 +63,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/eventlog.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/eventlog.pm index a40ddd986..e177af9a5 100644 --- a/centreon-plugins/storage/ibm/storwize/ssh/mode/eventlog.pm +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/eventlog.pm @@ -31,7 +31,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/hardware.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/hardware.pm index c7e64a0d2..cce86c9f6 100644 --- a/centreon-plugins/storage/ibm/storwize/ssh/mode/hardware.pm +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/hardware.pm @@ -94,7 +94,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/poolusage.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/poolusage.pm index 91b032193..09aa245d2 100644 --- a/centreon-plugins/storage/ibm/storwize/ssh/mode/poolusage.pm +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/poolusage.pm @@ -139,7 +139,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /degraded/i' }, diff --git a/centreon-plugins/storage/ibm/ts2900/snmp/mode/hardware.pm b/centreon-plugins/storage/ibm/ts2900/snmp/mode/hardware.pm index b438ddc93..ec7be65ba 100644 --- a/centreon-plugins/storage/ibm/ts2900/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/ibm/ts2900/snmp/mode/hardware.pm @@ -48,7 +48,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/ibm/ts3100/snmp/mode/globalstatus.pm b/centreon-plugins/storage/ibm/ts3100/snmp/mode/globalstatus.pm index 8c31dfc98..8e2201935 100644 --- a/centreon-plugins/storage/ibm/ts3100/snmp/mode/globalstatus.pm +++ b/centreon-plugins/storage/ibm/ts3100/snmp/mode/globalstatus.pm @@ -39,7 +39,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/storage/ibm/ts3200/snmp/mode/globalstatus.pm b/centreon-plugins/storage/ibm/ts3200/snmp/mode/globalstatus.pm index 819807157..b84f0cd4c 100644 --- a/centreon-plugins/storage/ibm/ts3200/snmp/mode/globalstatus.pm +++ b/centreon-plugins/storage/ibm/ts3200/snmp/mode/globalstatus.pm @@ -39,7 +39,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/storage/kaminario/restapi/mode/systemusage.pm b/centreon-plugins/storage/kaminario/restapi/mode/systemusage.pm index 760146c97..70864fcb5 100644 --- a/centreon-plugins/storage/kaminario/restapi/mode/systemusage.pm +++ b/centreon-plugins/storage/kaminario/restapi/mode/systemusage.pm @@ -119,7 +119,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/kaminario/restapi/mode/volumeusage.pm b/centreon-plugins/storage/kaminario/restapi/mode/volumeusage.pm index ab4815de1..42699dbdb 100644 --- a/centreon-plugins/storage/kaminario/restapi/mode/volumeusage.pm +++ b/centreon-plugins/storage/kaminario/restapi/mode/volumeusage.pm @@ -78,7 +78,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/storage/netapp/restapi/mode/aggregateraidstatus.pm b/centreon-plugins/storage/netapp/restapi/mode/aggregateraidstatus.pm index b03290318..695e50381 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/aggregateraidstatus.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/aggregateraidstatus.pm @@ -75,7 +75,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/aggregatestatus.pm b/centreon-plugins/storage/netapp/restapi/mode/aggregatestatus.pm index 191f0bb4e..b23bf72d0 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/aggregatestatus.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/aggregatestatus.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/aggregateusage.pm b/centreon-plugins/storage/netapp/restapi/mode/aggregateusage.pm index 0fad8190e..2b52658c1 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/aggregateusage.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/aggregateusage.pm @@ -189,7 +189,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-node:s" => { name => 'filter_node' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/clusterio.pm b/centreon-plugins/storage/netapp/restapi/mode/clusterio.pm index 1148f754b..cd913ca69 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/clusterio.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/clusterio.pm @@ -66,7 +66,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/clusterstatus.pm b/centreon-plugins/storage/netapp/restapi/mode/clusterstatus.pm index 6e909eda4..b27aa6c08 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/clusterstatus.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/clusterstatus.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/clusterusage.pm b/centreon-plugins/storage/netapp/restapi/mode/clusterusage.pm index 028882906..e6030d4d9 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/clusterusage.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/clusterusage.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/diskfailed.pm b/centreon-plugins/storage/netapp/restapi/mode/diskfailed.pm index 711abfd3e..4e37157c2 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/diskfailed.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/diskfailed.pm @@ -59,7 +59,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-node:s" => { name => 'filter_node' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/diskspare.pm b/centreon-plugins/storage/netapp/restapi/mode/diskspare.pm index bd78735dc..2d04eb7d6 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/diskspare.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/diskspare.pm @@ -68,7 +68,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-node:s" => { name => 'filter_node' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/fcportstatus.pm b/centreon-plugins/storage/netapp/restapi/mode/fcportstatus.pm index 8c535fa1b..41970d8bd 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/fcportstatus.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/fcportstatus.pm @@ -79,7 +79,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/listaggregates.pm b/centreon-plugins/storage/netapp/restapi/mode/listaggregates.pm index 3f7052e47..252f1cf92 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listaggregates.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/listaggregates.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/listclusters.pm b/centreon-plugins/storage/netapp/restapi/mode/listclusters.pm index 26122519a..f1c1b556f 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listclusters.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/listclusters.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/listfcports.pm b/centreon-plugins/storage/netapp/restapi/mode/listfcports.pm index 3ada7e572..0f056e197 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listfcports.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/listfcports.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/listluns.pm b/centreon-plugins/storage/netapp/restapi/mode/listluns.pm index 5f95d2adc..f95787647 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listluns.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/listluns.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/listnodes.pm b/centreon-plugins/storage/netapp/restapi/mode/listnodes.pm index c09973e84..8e4de44e3 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listnodes.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/listnodes.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/listsnapmirrors.pm b/centreon-plugins/storage/netapp/restapi/mode/listsnapmirrors.pm index bd4675e8a..8dee0dd94 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listsnapmirrors.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/listsnapmirrors.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/listvolumes.pm b/centreon-plugins/storage/netapp/restapi/mode/listvolumes.pm index 79ba11fe4..329778836 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listvolumes.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/listvolumes.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/lunalignment.pm b/centreon-plugins/storage/netapp/restapi/mode/lunalignment.pm index 4510bd465..f6776f296 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/lunalignment.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/lunalignment.pm @@ -95,7 +95,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-volume:s" => { name => 'filter_volume' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/lunonline.pm b/centreon-plugins/storage/netapp/restapi/mode/lunonline.pm index e2f82199f..44389bf93 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/lunonline.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/lunonline.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-volume:s" => { name => 'filter_volume' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/lunusage.pm b/centreon-plugins/storage/netapp/restapi/mode/lunusage.pm index 367d6cac3..c48c22f60 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/lunusage.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/lunusage.pm @@ -118,7 +118,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/nodefailoverstatus.pm b/centreon-plugins/storage/netapp/restapi/mode/nodefailoverstatus.pm index 35ada3f36..c7f0ce280 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/nodefailoverstatus.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/nodefailoverstatus.pm @@ -80,7 +80,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/nodehardwarestatus.pm b/centreon-plugins/storage/netapp/restapi/mode/nodehardwarestatus.pm index 65ec54503..00b5f213e 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/nodehardwarestatus.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/nodehardwarestatus.pm @@ -96,7 +96,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/qtreestatus.pm b/centreon-plugins/storage/netapp/restapi/mode/qtreestatus.pm index d74cd419d..e12b2bb17 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/qtreestatus.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/qtreestatus.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/snapmirrorstatus.pm b/centreon-plugins/storage/netapp/restapi/mode/snapmirrorstatus.pm index 0133b7adc..28d6afbad 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/snapmirrorstatus.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/snapmirrorstatus.pm @@ -73,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/snapmirrorusage.pm b/centreon-plugins/storage/netapp/restapi/mode/snapmirrorusage.pm index 0c19ffa92..b0a0e3f7d 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/snapmirrorusage.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/snapmirrorusage.pm @@ -75,7 +75,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/volumeio.pm b/centreon-plugins/storage/netapp/restapi/mode/volumeio.pm index 1075c5d9c..8e9e03e60 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/volumeio.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/volumeio.pm @@ -110,7 +110,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/volumestatus.pm b/centreon-plugins/storage/netapp/restapi/mode/volumestatus.pm index 3a0658af9..1ffca2353 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/volumestatus.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/volumestatus.pm @@ -73,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/netapp/restapi/mode/volumeusage.pm b/centreon-plugins/storage/netapp/restapi/mode/volumeusage.pm index dd161f07f..e25cad92d 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/volumeusage.pm +++ b/centreon-plugins/storage/netapp/restapi/mode/volumeusage.pm @@ -370,7 +370,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-state:s" => { name => 'filter_state' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/aggregatestate.pm b/centreon-plugins/storage/netapp/snmp/mode/aggregatestate.pm index 5c6c3fe4e..9f2952fae 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/aggregatestate.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/aggregatestate.pm @@ -91,7 +91,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/cacheage.pm b/centreon-plugins/storage/netapp/snmp/mode/cacheage.pm index ae3309e94..dcd476704 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/cacheage.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/cacheage.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/cpstatistics.pm b/centreon-plugins/storage/netapp/snmp/mode/cpstatistics.pm index 0dbae0fed..bb5140520 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/cpstatistics.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/cpstatistics.pm @@ -130,7 +130,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/netapp/snmp/mode/cpuload.pm b/centreon-plugins/storage/netapp/snmp/mode/cpuload.pm index 4867a8107..a69878ddd 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/cpuload.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/cpuload.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/diskfailed.pm b/centreon-plugins/storage/netapp/snmp/mode/diskfailed.pm index f834ab710..c110c4787 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/diskfailed.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/diskfailed.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/netapp/snmp/mode/fan.pm b/centreon-plugins/storage/netapp/snmp/mode/fan.pm index bdb8fe029..091a7a2f1 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/fan.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/fan.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/netapp/snmp/mode/filesys.pm b/centreon-plugins/storage/netapp/snmp/mode/filesys.pm index 5afa3674b..2ab15c43a 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/filesys.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/filesys.pm @@ -165,27 +165,30 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - 'units:s' => { name => 'units', default => '%' }, - 'free' => { name => 'free' }, - 'filter-name:s' => { name => 'filter_name' }, - 'filter-type:s' => { name => 'filter_type' }, - 'filter-vserver:s' => { name => 'filter_vserver' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-type:s' => { name => 'filter_type' }, + 'filter-vserver:s' => { name => 'filter_vserver' }, + 'filter-vserver-state:s' => { name => 'filter_vserver_state' }, }); return $self; } -my %map_types = ( +my $map_types = { 1 => 'traditionalVolume', 2 => 'flexibleVolume', 3 => 'aggregate', 4 => 'stripedAggregate', 5 => 'stripedVolume' -); +}; +my $map_vserver_state = { + 0 => 'running', 1 => 'stopped', 2 => 'starting', 3 => 'stopping' +}; my $mapping = { - dfType => { oid => '.1.3.6.1.4.1.789.1.5.4.1.23', map => \%map_types }, + dfType => { oid => '.1.3.6.1.4.1.789.1.5.4.1.23', map => $map_types }, }; my $mapping2 = { dfFileSys => { oid => '.1.3.6.1.4.1.789.1.5.4.1.2' }, @@ -198,6 +201,31 @@ my $mapping2 = { dfCompressSavedPercent => { oid => '.1.3.6.1.4.1.789.1.5.4.1.38' }, dfDedupeSavedPercent => { oid => '.1.3.6.1.4.1.789.1.5.4.1.40' }, }; +my $mapping3 = { + vserverName => { oid => '.1.3.6.1.4.1.789.1.27.1.1.2' }, + vserverState => { oid => '.1.3.6.1.4.1.789.1.27.1.1.16', map => $map_vserver_state }, +}; + +sub get_vserver_state { + my ($self, %options) = @_; + + return if (!defined($self->{option_results}->{filter_vserver_state}) || $self->{option_results}->{filter_vserver} eq ''); + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $mapping3->{vserverName}->{oid} }, + { oid => $mapping3->{vserverState}->{oid} } + ], + return_type => 1, + nothing_quit => 1 + ); + + $self->{vserver} = {}; + foreach (keys %$snmp_result) { + next if (! /^$mapping3->{vserverName}->{oid}\.(.*)/); + my $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result, instance => $1); + $self->{vserver}->{$result->{vserverName}} = $result->{vserverState}; + } +} sub manage_selection { my ($self, %options) = @_; @@ -213,9 +241,10 @@ sub manage_selection { if (!$options{snmp}->is_snmpv1()) { push @oids, $mapping2->{df64TotalKBytes}->{oid}; push @oids, $mapping2->{df64UsedKBytes}->{oid}; - } + $self->get_vserver_state(%options); + my $results; if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '') { $results = $options{snmp}->get_multiple_table( @@ -240,7 +269,7 @@ sub manage_selection { next; } if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && - $map_types{$results->{$mapping->{dfType}->{oid} . '.' . $instance}} !~ /$self->{option_results}->{filter_type}/) { + $map_types->{$results->{$mapping->{dfType}->{oid} . '.' . $instance}} !~ /$self->{option_results}->{filter_type}/) { $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter type.", debug => 1); next; } @@ -257,7 +286,19 @@ sub manage_selection { my $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); foreach my $instance (sort @fs_selected) { my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $instance); - + + if (defined($result2->{dfVserver}) && $result2->{dfVserver} ne '' && + defined($self->{option_results}->{filter_vserver_state}) && $self->{option_results}->{filter_vserver_state} ne '' && + $self->{vserver}->{$result2->{dfVserver}} !~ /$self->{option_results}->{filter_vserver_state}/) { + $self->{output}->output_add(long_msg => "skipping '" . $instance . "': no matching filter vserver state.", debug => 1); + next; + } + if (defined($result2->{dfVserver}) && defined($self->{option_results}->{filter_vserver}) && $self->{option_results}->{filter_vserver} ne '' && + $result2->{dfVserver} !~ /$self->{option_results}->{filter_vserver}/) { + $self->{output}->output_add(long_msg => "skipping '" . $instance . "': no matching filter vserver.", debug => 1); + next; + } + $self->{fs}->{$instance} = { display => defined($result2->{dfVserver}) && $result2->{dfVserver} ne '' ? $result2->{dfVserver} . ':' . $results->{$mapping2->{dfFileSys}->{oid} . '.' . $instance} : @@ -313,6 +354,10 @@ Filter by filesystem name (can be a regexp). Filter by vserver name (can be a regexp). +=item B<--filter-vserver-state> + +Filter by vserver state (can be a regexp). + =item B<--filter-type> Filter filesystem type (can be a regexp. Example: 'flexibleVolume|aggregate'). diff --git a/centreon-plugins/storage/netapp/snmp/mode/globalstatus.pm b/centreon-plugins/storage/netapp/snmp/mode/globalstatus.pm index cb26ba1c4..58b653320 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/globalstatus.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/globalstatus.pm @@ -64,7 +64,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/netapp/snmp/mode/listfilesys.pm b/centreon-plugins/storage/netapp/snmp/mode/listfilesys.pm index 3829e04e2..760fd17a5 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/listfilesys.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/listfilesys.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { 'filter-name:s' => { name => 'filter_name' }, 'filter-type:s' => { name => 'filter_type' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/listsnapvault.pm b/centreon-plugins/storage/netapp/snmp/mode/listsnapvault.pm index c939442d9..0aae3e383 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/listsnapvault.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/listsnapvault.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/netapp/snmp/mode/ndmpsessions.pm b/centreon-plugins/storage/netapp/snmp/mode/ndmpsessions.pm index 5c8354d2d..eac6e831e 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/ndmpsessions.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/ndmpsessions.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/nvram.pm b/centreon-plugins/storage/netapp/snmp/mode/nvram.pm index 88469f8f1..ebe57ab5f 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/nvram.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/nvram.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/partnerstatus.pm b/centreon-plugins/storage/netapp/snmp/mode/partnerstatus.pm index 9a28015cf..9d1a58f69 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/partnerstatus.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/partnerstatus.pm @@ -55,7 +55,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "threshold-overload:s@" => { name => 'threshold_overload' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/psu.pm b/centreon-plugins/storage/netapp/snmp/mode/psu.pm index 6ecc29ed5..2dacc9a0d 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/psu.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/psu.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/netapp/snmp/mode/qtreeusage.pm b/centreon-plugins/storage/netapp/snmp/mode/qtreeusage.pm index 76b2a12d7..af77c7104 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/qtreeusage.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/qtreeusage.pm @@ -135,7 +135,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/sharecalls.pm b/centreon-plugins/storage/netapp/snmp/mode/sharecalls.pm index f96cd111c..03c840531 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/sharecalls.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/sharecalls.pm @@ -60,7 +60,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/netapp/snmp/mode/shelf.pm b/centreon-plugins/storage/netapp/snmp/mode/shelf.pm index ba04056b7..d8cb959bd 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/shelf.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/shelf.pm @@ -100,7 +100,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/netapp/snmp/mode/sis.pm b/centreon-plugins/storage/netapp/snmp/mode/sis.pm new file mode 100644 index 000000000..24e09fa44 --- /dev/null +++ b/centreon-plugins/storage/netapp/snmp/mode/sis.pm @@ -0,0 +1,192 @@ +# +# Copyright 2019 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 storage::netapp::snmp::mode::sis; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf('status : %s [state: %s] [lastOpError: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{state}, + $self->{result_values}->{lastOpError}, + ); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_sisStatus'}; + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_sisState'}; + $self->{result_values}->{lastOpError} = $options{new_datas}->{$self->{instance} . '_sisLastOpError'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'sis', type => 1, cb_prefix_output => 'prefix_sis_output', message_multiple => 'All single instance storages are ok', skipped_code => { -10 => 1, -11 => 1 } } + ]; + + $self->{maps_counters}->{sis} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'sisStatus' }, { name => 'sisState' }, { name => 'sisLastOpError' }, { 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 => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_sis_output { + my ($self, %options) = @_; + + return "Single instance storage '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} eq "enabled" and %{lastOpError} !~ /-|Success/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +my $map_status = { + 1 => 'idle', 2 => 'active', 3 => 'undoing', + 4 => 'pending', 5 => 'initializing', + 6 => 'downgrading', 7 => 'disabled', +}; + +my $map_state = { 1 => 'disabled', 2 => 'enabled' }; + +my $mapping = { + sisState => { oid => '.1.3.6.1.4.1.789.1.23.2.1.3', map => $map_state }, + sisStatus => { oid => '.1.3.6.1.4.1.789.1.23.2.1.4', map => $map_status }, + sisLastOpError => { oid => '.1.3.6.1.4.1.789.1.23.2.1.12' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_sisIsLicensed = '.1.3.6.1.4.1.789.1.23.1.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_sisIsLicensed]); + if (!defined($snmp_result->{$oid_sisIsLicensed}) || $snmp_result->{$oid_sisIsLicensed} != 2) { + $self->{output}->add_option_msg(short_msg => 'single instance storage is not licensed'); + $self->{output}->option_exit(); + } + + my $oid_sisPath = '.1.3.6.1.4.1.789.1.23.2.1.2'; + my $oid_sisVserver = '.1.3.6.1.4.1.789.1.23.2.1.16'; + + $self->{snapvault} = {}; + $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_sisPath }, { oid => $oid_sisVserver }], return_type => 1, nothing_quit => 1); + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$oid_sisPath\.(.*)$/); + my $instance = $1; + my $name = defined($snmp_result->{$oid_sisVserver . '.' . $instance}) && $snmp_result->{$oid_sisVserver . '.' . $instance} ne '' ? + $snmp_result->{$oid_sisVserver . '.' . $instance} . ':' . $snmp_result->{$oid} : + $snmp_result->{$oid}; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping sis '" . $name . "'.", debug => 1); + next; + } + + $self->{sis}->{$instance} = { display => $name }; + } + + if (scalar(keys %{$self->{sis}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No entry found."); + $self->{output}->option_exit(); + } + + $options{snmp}->load(oids => [ + map($_->{oid}, values(%$mapping)) + ], + instances => [keys %{$self->{sis}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{sis}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + $self->{sis}->{$_} = { %{$self->{sis}->{$_}}, %$result }; + } +} + +1; + +__END__ + +=head1 MODE + +Check single instance storage. + +=over 8 + +=item B<--filter-name> + +Filter name (can be a regexp). + +=item B<--unknown-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{state}, %{status}, %{lastOpError}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{state}, %{status}, %{lastOpError}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{state} eq "enabled" and %{lastOpError} !~ /-|Success/i'). +Can used special variables like: %{state}, %{status}, %{lastOpError}, %{display} + +=back + +=cut diff --git a/centreon-plugins/storage/netapp/snmp/mode/snapmirrorlag.pm b/centreon-plugins/storage/netapp/snmp/mode/snapmirrorlag.pm index 034531b5e..0c1d7291f 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/snapmirrorlag.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/snapmirrorlag.pm @@ -74,7 +74,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-status:s" => { name => 'filter_status' }, "unknown-status:s" => { name => 'unknown_status', default => '' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/snapshotage.pm b/centreon-plugins/storage/netapp/snmp/mode/snapshotage.pm index 604d2b53c..03d50e8e7 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/snapshotage.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/snapshotage.pm @@ -38,7 +38,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "name:s" => { name => 'name' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/snapvaultusage.pm b/centreon-plugins/storage/netapp/snmp/mode/snapvaultusage.pm index 84e2f9bff..3355febe0 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/snapvaultusage.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/snapvaultusage.pm @@ -110,7 +110,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "unknown-status:s" => { name => 'unknown_status', default => '' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/temperature.pm b/centreon-plugins/storage/netapp/snmp/mode/temperature.pm index 16ef19bc2..cee2a40d3 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/temperature.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/temperature.pm @@ -35,7 +35,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/netapp/snmp/mode/volumeoptions.pm b/centreon-plugins/storage/netapp/snmp/mode/volumeoptions.pm index 4498bfc8c..d8fc33b82 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/volumeoptions.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/volumeoptions.pm @@ -104,7 +104,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-status:s" => { name => 'filter_status' }, diff --git a/centreon-plugins/storage/netapp/snmp/plugin.pm b/centreon-plugins/storage/netapp/snmp/plugin.pm index 6c50add2d..a237f66b3 100644 --- a/centreon-plugins/storage/netapp/snmp/plugin.pm +++ b/centreon-plugins/storage/netapp/snmp/plugin.pm @@ -48,6 +48,7 @@ sub new { 'qtree-usage' => 'storage::netapp::snmp::mode::qtreeusage', 'share-calls' => 'storage::netapp::snmp::mode::sharecalls', 'shelf' => 'storage::netapp::snmp::mode::shelf', + 'sis' => 'storage::netapp::snmp::mode::sis', 'snapmirrorlag' => 'storage::netapp::snmp::mode::snapmirrorlag', 'snapshotage' => 'storage::netapp::snmp::mode::snapshotage', 'snapvault-usage' => 'storage::netapp::snmp::mode::snapvaultusage', diff --git a/centreon-plugins/storage/netgear/readynas/snmp/mode/hardware.pm b/centreon-plugins/storage/netgear/readynas/snmp/mode/hardware.pm index f151eff8d..599541676 100644 --- a/centreon-plugins/storage/netgear/readynas/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/netgear/readynas/snmp/mode/hardware.pm @@ -93,7 +93,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/nimble/snmp/mode/globalstats.pm b/centreon-plugins/storage/nimble/snmp/mode/globalstats.pm index 8975119ea..7c4a765e3 100644 --- a/centreon-plugins/storage/nimble/snmp/mode/globalstats.pm +++ b/centreon-plugins/storage/nimble/snmp/mode/globalstats.pm @@ -102,7 +102,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/nimble/snmp/mode/volumeusage.pm b/centreon-plugins/storage/nimble/snmp/mode/volumeusage.pm index a906ffc14..faaae74c1 100644 --- a/centreon-plugins/storage/nimble/snmp/mode/volumeusage.pm +++ b/centreon-plugins/storage/nimble/snmp/mode/volumeusage.pm @@ -96,7 +96,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, }); diff --git a/centreon-plugins/storage/oracle/zs/snmp/mode/hardware.pm b/centreon-plugins/storage/oracle/zs/snmp/mode/hardware.pm index 37c818ba9..19c310dbb 100644 --- a/centreon-plugins/storage/oracle/zs/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/oracle/zs/snmp/mode/hardware.pm @@ -56,7 +56,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/oracle/zs/snmp/mode/listshares.pm b/centreon-plugins/storage/oracle/zs/snmp/mode/listshares.pm index 7ed41cde8..def977f2b 100644 --- a/centreon-plugins/storage/oracle/zs/snmp/mode/listshares.pm +++ b/centreon-plugins/storage/oracle/zs/snmp/mode/listshares.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, diff --git a/centreon-plugins/storage/oracle/zs/snmp/mode/shareusage.pm b/centreon-plugins/storage/oracle/zs/snmp/mode/shareusage.pm index a5542e0a3..601e75323 100644 --- a/centreon-plugins/storage/oracle/zs/snmp/mode/shareusage.pm +++ b/centreon-plugins/storage/oracle/zs/snmp/mode/shareusage.pm @@ -127,7 +127,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "filter-project:s" => { name => 'filter_project' }, diff --git a/centreon-plugins/storage/overland/neo/snmp/mode/eventlog.pm b/centreon-plugins/storage/overland/neo/snmp/mode/eventlog.pm index 29bda5d23..6c687d166 100644 --- a/centreon-plugins/storage/overland/neo/snmp/mode/eventlog.pm +++ b/centreon-plugins/storage/overland/neo/snmp/mode/eventlog.pm @@ -44,7 +44,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-severity:s" => { name => 'filter_severity', default => 'hard|severe' }, diff --git a/centreon-plugins/storage/overland/neo/snmp/mode/hardware.pm b/centreon-plugins/storage/overland/neo/snmp/mode/hardware.pm index 7bb8cbe1c..4aa78b0f2 100644 --- a/centreon-plugins/storage/overland/neo/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/overland/neo/snmp/mode/hardware.pm @@ -63,7 +63,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/panzura/snmp/mode/cpucloud.pm b/centreon-plugins/storage/panzura/snmp/mode/cpucloud.pm index ba65a7837..e4ec1e022 100644 --- a/centreon-plugins/storage/panzura/snmp/mode/cpucloud.pm +++ b/centreon-plugins/storage/panzura/snmp/mode/cpucloud.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/storage/panzura/snmp/mode/diskusagelocal.pm b/centreon-plugins/storage/panzura/snmp/mode/diskusagelocal.pm index 4a7820f03..9ef99c26b 100644 --- a/centreon-plugins/storage/panzura/snmp/mode/diskusagelocal.pm +++ b/centreon-plugins/storage/panzura/snmp/mode/diskusagelocal.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning', }, diff --git a/centreon-plugins/storage/panzura/snmp/mode/memory.pm b/centreon-plugins/storage/panzura/snmp/mode/memory.pm index b855077b5..f39d55b6c 100644 --- a/centreon-plugins/storage/panzura/snmp/mode/memory.pm +++ b/centreon-plugins/storage/panzura/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/storage/panzura/snmp/mode/ratios.pm b/centreon-plugins/storage/panzura/snmp/mode/ratios.pm index 5886cd51e..793f4e079 100644 --- a/centreon-plugins/storage/panzura/snmp/mode/ratios.pm +++ b/centreon-plugins/storage/panzura/snmp/mode/ratios.pm @@ -65,7 +65,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/purestorage/restapi/mode/alarms.pm b/centreon-plugins/storage/purestorage/restapi/mode/alarms.pm index 5356f70dc..5557c5d61 100644 --- a/centreon-plugins/storage/purestorage/restapi/mode/alarms.pm +++ b/centreon-plugins/storage/purestorage/restapi/mode/alarms.pm @@ -76,7 +76,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-category:s" => { name => 'filter_category' }, diff --git a/centreon-plugins/storage/purestorage/restapi/mode/hardware.pm b/centreon-plugins/storage/purestorage/restapi/mode/hardware.pm index 926bfe0f6..c7ba4bbe1 100644 --- a/centreon-plugins/storage/purestorage/restapi/mode/hardware.pm +++ b/centreon-plugins/storage/purestorage/restapi/mode/hardware.pm @@ -54,7 +54,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/purestorage/restapi/mode/listpgroups.pm b/centreon-plugins/storage/purestorage/restapi/mode/listpgroups.pm index 21f41d589..788c345e0 100644 --- a/centreon-plugins/storage/purestorage/restapi/mode/listpgroups.pm +++ b/centreon-plugins/storage/purestorage/restapi/mode/listpgroups.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/purestorage/restapi/mode/listvolumes.pm b/centreon-plugins/storage/purestorage/restapi/mode/listvolumes.pm index f607162c2..e2273c95e 100644 --- a/centreon-plugins/storage/purestorage/restapi/mode/listvolumes.pm +++ b/centreon-plugins/storage/purestorage/restapi/mode/listvolumes.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm b/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm index 5f70c2ef0..0476e23d5 100644 --- a/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm +++ b/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm @@ -92,12 +92,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "timezone:s" => { name => 'timezone', default => 'GMT' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'timezone:s' => { name => 'timezone', default => 'GMT' }, + }); return $self; } @@ -151,6 +149,11 @@ sub manage_selection { duration_human => centreon::plugins::misc::change_seconds(value => $completed_time - $created_time), }; } + + if (scalar(keys %{$self->{pgroup}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No replication group found."); + $self->{output}->option_exit(); + } } 1; diff --git a/centreon-plugins/storage/purestorage/restapi/mode/volumeusage.pm b/centreon-plugins/storage/purestorage/restapi/mode/volumeusage.pm index 595aaa3a6..481297ca8 100644 --- a/centreon-plugins/storage/purestorage/restapi/mode/volumeusage.pm +++ b/centreon-plugins/storage/purestorage/restapi/mode/volumeusage.pm @@ -143,11 +143,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, + 'filter-name:s' => { name => 'filter_name' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, }); return $self; @@ -181,6 +180,11 @@ sub manage_selection { %{$entry}, }; } + + if (scalar(keys %{$self->{volume}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No volume found."); + $self->{output}->option_exit(); + } } 1; diff --git a/centreon-plugins/storage/purestorage/snmp/mode/stats.pm b/centreon-plugins/storage/purestorage/snmp/mode/stats.pm index 990f0e39c..4cb0d4c87 100644 --- a/centreon-plugins/storage/purestorage/snmp/mode/stats.pm +++ b/centreon-plugins/storage/purestorage/snmp/mode/stats.pm @@ -97,7 +97,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/qnap/snmp/mode/hardware.pm b/centreon-plugins/storage/qnap/snmp/mode/hardware.pm index 52e253b58..5edeb69cf 100644 --- a/centreon-plugins/storage/qnap/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/qnap/snmp/mode/hardware.pm @@ -70,7 +70,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/qnap/snmp/mode/memory.pm b/centreon-plugins/storage/qnap/snmp/mode/memory.pm index 5be2e608f..ac28c447d 100644 --- a/centreon-plugins/storage/qnap/snmp/mode/memory.pm +++ b/centreon-plugins/storage/qnap/snmp/mode/memory.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/storage/qnap/snmp/mode/volumeusage.pm b/centreon-plugins/storage/qnap/snmp/mode/volumeusage.pm index 6956ceff9..d0ff89b8a 100644 --- a/centreon-plugins/storage/qnap/snmp/mode/volumeusage.pm +++ b/centreon-plugins/storage/qnap/snmp/mode/volumeusage.pm @@ -122,7 +122,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, "units:s" => { name => 'units', default => '%' }, diff --git a/centreon-plugins/storage/qsan/nas/snmp/mode/hardware.pm b/centreon-plugins/storage/qsan/nas/snmp/mode/hardware.pm index 2bb31310b..e81d48a57 100644 --- a/centreon-plugins/storage/qsan/nas/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/qsan/nas/snmp/mode/hardware.pm @@ -67,7 +67,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/compaction.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/compaction.pm index c95c2a86e..f7038de5a 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/compaction.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/compaction.pm @@ -144,7 +144,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/dedupnas.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/dedupnas.pm index 958d84d64..1da58ca22 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/dedupnas.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/dedupnas.pm @@ -113,7 +113,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/dedupvtl.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/dedupvtl.pm index ac4f20e1b..0532056e9 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/dedupvtl.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/dedupvtl.pm @@ -113,7 +113,6 @@ my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/diskusage.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/diskusage.pm index 6693b70c4..626a8946c 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/diskusage.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/diskusage.pm @@ -216,7 +216,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "ssh-option:s@" => { name => 'ssh_option' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/health.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/health.pm index a90cc53c6..931c4bd93 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/health.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/health.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/hostbusadapterstatus.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/hostbusadapterstatus.pm index a91d976a2..363aa1671 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/hostbusadapterstatus.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/hostbusadapterstatus.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/memory.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/memory.pm index e2108c692..f421d16e5 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/memory.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/memory.pm @@ -126,7 +126,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "ssh-option:s@" => { name => 'ssh_option' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/network.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/network.pm index e139ca6b6..2cefdef59 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/network.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/network.pm @@ -72,7 +72,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/reclamation.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/reclamation.pm index e9e54a4bf..90453724f 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/reclamation.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/reclamation.pm @@ -153,7 +153,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/reduction.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/reduction.pm index aeb2ab7a8..3329e15ff 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/reduction.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/reduction.pm @@ -193,7 +193,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "ssh-option:s@" => { name => 'ssh_option' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/storagearraystatus.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/storagearraystatus.pm index 41100b3bf..d68037a9e 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/storagearraystatus.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/storagearraystatus.pm @@ -71,7 +71,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/systemstatus.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/systemstatus.pm index 9b7f582c2..0d3145fb5 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/systemstatus.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/systemstatus.pm @@ -73,7 +73,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, diff --git a/centreon-plugins/storage/quantum/dxi/ssh/mode/throughput.pm b/centreon-plugins/storage/quantum/dxi/ssh/mode/throughput.pm index 50d96c596..519070dd2 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/mode/throughput.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/mode/throughput.pm @@ -112,7 +112,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "ssh-option:s@" => { name => 'ssh_option' }, diff --git a/centreon-plugins/storage/quantum/scalar/snmp/mode/components/global.pm b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/global.pm new file mode 100644 index 000000000..e0e4f0f5f --- /dev/null +++ b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/global.pm @@ -0,0 +1,73 @@ +# +# Copyright 2019 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 storage::quantum::scalar::snmp::mode::components::global; + +use strict; +use warnings; +use storage::quantum::scalar::snmp::mode::components::resources qw($map_rassubsytem_status); + +# In MIB 'QUANTUM-MIDRANGE-TAPE-LIBRARY-MIB' +my $oid_mrTapeLibrary = '.1.3.6.1.4.1.3697.1.10.15.5'; +my $oid_libraryFirmwareVersion = '.1.3.6.1.4.1.3697.1.10.15.5.9'; +my $oid_libraryGlobalStatus = '.1.3.6.1.4.1.3697.1.10.15.5.10'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_mrTapeLibrary, start => $oid_libraryFirmwareVersion, end => $oid_libraryGlobalStatus }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking global"); + $self->{components}->{global} = {name => 'global', total => 0, skip => 0}; + return if ($self->check_filter(section => 'global')); + + return if (!defined($self->{results}->{$oid_mrTapeLibrary}) || + scalar(keys %{$self->{results}->{$oid_mrTapeLibrary}}) <= 0); + + my $instance = '0'; + my $status = defined($self->{results}->{$oid_mrTapeLibrary}->{$oid_libraryGlobalStatus . '.0'}) ? + $map_rassubsytem_status->{ $self->{results}->{$oid_mrTapeLibrary}->{$oid_libraryGlobalStatus . '.0'} } : + $map_rassubsytem_status->{ $self->{results}->{$oid_mrTapeLibrary}->{$oid_libraryGlobalStatus} }; + + return if ($self->check_filter(section => 'global', instance => $instance)); + $self->{components}->{global}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + 'library global status is %s [instance: %s]', + $status, $instance + ) + ); + my $exit = $self->get_severity(section => 'global', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => + sprintf("Library global status is %s", $status + ) + ); + } +} + +1; diff --git a/centreon-plugins/storage/quantum/scalar/snmp/mode/components/humidity.pm b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/humidity.pm new file mode 100644 index 000000000..2adc20a87 --- /dev/null +++ b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/humidity.pm @@ -0,0 +1,89 @@ +# +# Copyright 2019 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 storage::quantum::scalar::snmp::mode::components::humidity; + +use strict; +use warnings; +use storage::quantum::scalar::snmp::mode::components::resources qw($map_sensor_status); + +# In MIB 'QUANTUM-MIDRANGE-TAPE-LIBRARY-MIB' +my $mapping = { + libraryHumiditySensorName => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.1.2.1.2' }, + libraryHumiditySensorLocation => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.1.2.1.3' }, + libraryHumiditySensorStatus => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.1.2.1.4', map => $map_sensor_status }, + libraryHumiditySensorValue => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.1.2.1.5' }, +}; +my $oid_libraryHumiditySensorEntry = '.1.3.6.1.4.1.3697.1.10.15.5.120.1.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_libraryHumiditySensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking humidities"); + $self->{components}->{humidity} = {name => 'humidity', total => 0, skip => 0}; + return if ($self->check_filter(section => 'humidity')); + + my ($exit, $warn, $crit, $checked); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_libraryHumiditySensorEntry}})) { + next if ($oid !~ /^$mapping->{libraryHumiditySensorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_libraryHumiditySensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'humidity', instance => $instance)); + $self->{components}->{humidity}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("humidity '%s' status is '%s' [instance = %s] [value = %s]", + $result->{libraryHumiditySensorLocation}, $result->{libraryHumiditySensorStatus}, $instance, + $result->{libraryHumiditySensorValue})); + + $exit = $self->get_severity(label => 'default', section => 'humidity', instance => $instance, value => $result->{libraryHumiditySensorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Humidity '%s' status is '%s'", $result->{libraryHumiditySensorLocation}, $result->{libraryHumiditySensorStatus})); + } + + next if (!defined($result->{libraryHumiditySensorValue}) || $result->{libraryHumiditySensorValue} !~ /[0-9]/); + + ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{libraryHumiditySensorValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Humdity '%s' is %s %%", $result->{libraryHumiditySensorLocation}, $result->{libraryHumiditySensorValue}) + ); + } + + $self->{output}->perfdata_add( + nlabel => 'hardware.sensor.humidity.percentage', unit => '%', + instances => $result->{libraryHumiditySensorLocation}, + value => $result->{libraryHumiditySensorValue}, + warning => $warn, + critical => $crit, + min => 0, max => 100 + ); + } +} + +1; diff --git a/centreon-plugins/storage/quantum/scalar/snmp/mode/components/physicaldrive.pm b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/physicaldrive.pm new file mode 100644 index 000000000..cb932fb7f --- /dev/null +++ b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/physicaldrive.pm @@ -0,0 +1,91 @@ +# +# Copyright 2019 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 storage::quantum::scalar::snmp::mode::components::physicaldrive; + +use strict; +use warnings; +use storage::quantum::scalar::snmp::mode::components::resources qw($map_rassubsytem_status); + +my $map_cleaning_status = { + 0 => 'unknown', 1 => 'notNeeded', 2 => 'recommended', 3 => 'required', +}; + +# In MIB 'QUANTUM-MIDRANGE-TAPE-LIBRARY-MIB' +my $mapping = { + phDriveLocation => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.80.2.1.2' }, + phDriveRasStatus => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.80.2.1.13', map => $map_rassubsytem_status }, + phDriveCleaningStatus => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.80.2.1.15', map => $map_cleaning_status }, +}; +my $oid_physicalDriveEntry = '.1.3.6.1.4.1.3697.1.10.15.5.80.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_physicalDriveEntry, end => $mapping->{phDriveCleaningStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking physical drives"); + $self->{components}->{physicaldrive} = {name => 'physical drives', total => 0, skip => 0}; + return if ($self->check_filter(section => 'physicaldrive')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_physicalDriveEntry}})) { + next if ($oid !~ /^$mapping->{phDriveRasStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_physicalDriveEntry}, instance => $instance); + + next if ($self->check_filter(section => 'physicaldrive', instance => $instance)); + $self->{components}->{physicaldrive}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "physical drive '%s' status is %s [instance: %s, cleaning status: %s]", + $result->{phDriveLocation}, $result->{phDriveRasStatus}, + $instance, $result->{phDriveCleaningStatus} + ) + ); + my $exit = $self->get_severity(section => 'physicaldrive.status', label => 'default', instance => $instance, value => $result->{phDriveRasStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Physical drive '%s' status is %s", + $result->{phDriveLocation}, $result->{phDriveRasStatus} + ) + ); + } + + $exit = $self->get_severity(section => 'physicaldrive.cleaning', label => 'cleaning', instance => $instance, value => $result->{phDriveCleaningStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Physical drive '%s' cleaning status is %s", + $result->{phDriveLocation}, $result->{phDriveCleaningStatus} + ) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/quantum/scalar/snmp/mode/components/psu.pm b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/psu.pm new file mode 100644 index 000000000..8dc329ca1 --- /dev/null +++ b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/psu.pm @@ -0,0 +1,92 @@ +# +# Copyright 2019 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 storage::quantum::scalar::snmp::mode::components::psu; + +use strict; +use warnings; + +my $map_psu_status = { + 0 => 'unknown', 1 => 'good', 2 => 'failed', 3 => 'missing' +}; + +# In MIB 'QUANTUM-MIDRANGE-TAPE-LIBRARY-MIB' +my $mapping = { + libraryPSName => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.100.2.1.2' }, + libraryPSLocation => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.100.2.1.3' }, + libraryPSStatus => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.100.2.1.6', map => $map_psu_status }, + libraryPSPowerConsumption => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.100.2.1.7' }, +}; +my $oid_libraryPowerSupplyEntry = '.1.3.6.1.4.1.3697.1.10.15.5.100.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_libraryPowerSupplyEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking power supplies"); + $self->{components}->{psu} = {name => 'psu', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + my ($exit, $warn, $crit, $checked); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_libraryPowerSupplyEntry}})) { + next if ($oid !~ /^$mapping->{libraryPSStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_libraryPowerSupplyEntry}, instance => $instance); + + next if ($self->check_filter(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance = %s] [power consumption = %s]", + $result->{libraryPSLocation}, $result->{libraryPSStatus}, $instance, + $result->{libraryPSPowerConsumption})); + + $exit = $self->get_severity(section => 'psu', instance => $instance, value => $result->{libraryPSStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' status is '%s'", $result->{libraryPSLocation}, $result->{libraryPSStatus})); + } + + next if (!defined($result->{libraryPSPowerConsumption}) || $result->{libraryPSPowerConsumption} !~ /[0-9]/); + + ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'power', instance => $instance, value => $result->{libraryPSPowerConsumption}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Power supply consumption '%s' is %s W", $result->{libraryPSLocation}, $result->{libraryPSPowerConsumption}) + ); + } + + $self->{output}->perfdata_add( + nlabel => 'hardware.psu.power.watt', unit => 'W', + instances => $result->{libraryPSLocation}, + value => $result->{libraryPSPowerConsumption}, + warning => $warn, + critical => $crit, + min => 0 + ); + } +} + +1; diff --git a/centreon-plugins/storage/quantum/scalar/snmp/mode/components/resources.pm b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/resources.pm new file mode 100644 index 000000000..2c32286f2 --- /dev/null +++ b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/resources.pm @@ -0,0 +1,43 @@ +# +# Copyright 2019 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 storage::quantum::scalar::snmp::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our $map_rassubsytem_status; +our $map_sensor_status; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw($map_rassubsytem_status $map_sensor_status); + +$map_rassubsytem_status = { + 0 => 'unknown', 1 => 'redFailure', 2 => 'orangeDegraded', + 3 => 'yellowWarning', 4 => 'blueAttention', + 5 => 'greenInformation', 6 => 'greenGood', +}; + +$map_sensor_status = { + 0 => 'unknown', 1 => 'normal', 2 => 'warning', 3 => 'critical', +}; + +1; diff --git a/centreon-plugins/storage/quantum/scalar/snmp/mode/components/subsystem.pm b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/subsystem.pm new file mode 100644 index 000000000..ee25033b8 --- /dev/null +++ b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/subsystem.pm @@ -0,0 +1,77 @@ +# +# Copyright 2019 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 storage::quantum::scalar::snmp::mode::components::subsystem; + +use strict; +use warnings; +use storage::quantum::scalar::snmp::mode::components::resources qw($map_rassubsytem_status); + +# In MIB 'QUANTUM-MIDRANGE-TAPE-LIBRARY-MIB' +my $mapping = { + libraryStatus => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.50.1', label => 'library', instance => 1 }, + driveStatus => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.50.2', label => 'drive', instance => 2 }, + mediaStatus => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.50.3', label => 'media', instance => 3 }, +}; +my $oid_rasSubSystem = '.1.3.6.1.4.1.3697.1.10.15.5.50'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_rasSubSystem }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking subsystems"); + $self->{components}->{subsystem} = {name => 'subsystems', total => 0, skip => 0}; + return if ($self->check_filter(section => 'subsystem')); + + return if (!defined($self->{results}->{$oid_rasSubSystem}) || + scalar(keys %{$self->{results}->{$oid_rasSubSystem}}) <= 0); + + foreach (values %$mapping) { + my $status = defined($self->{results}->{$oid_rasSubSystem}->{$_->{oid} . '.0'}) ? + $map_rassubsytem_status->{ $self->{results}->{$oid_rasSubSystem}->{$_->{oid} . '.0'} } : + $map_rassubsytem_status->{ $self->{results}->{$oid_rasSubSystem}->{$_->{oid}} }; + next if (!defined($status)); + + next if ($self->check_filter(section => 'subsystem', instance => $_->{instance})); + $self->{components}->{subsystem}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "subsystem '%s' status is %s [instance: %s].", + $_->{label}, $status, + $_->{instance} + ) + ); + my $exit = $self->get_severity(section => 'subsystem', label => 'default', instance => $_->{instance}, value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("subsystem '%s' status is %s", $_->{label}, $status) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/quantum/scalar/snmp/mode/components/temperature.pm b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..9ca6b45d7 --- /dev/null +++ b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/temperature.pm @@ -0,0 +1,88 @@ +# +# Copyright 2019 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 storage::quantum::scalar::snmp::mode::components::temperature; + +use strict; +use warnings; +use storage::quantum::scalar::snmp::mode::components::resources qw($map_sensor_status); + +# In MIB 'QUANTUM-MIDRANGE-TAPE-LIBRARY-MIB' +my $mapping = { + libraryTemperatureSensorName => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.2.2.1.2' }, + libraryTemperatureSensorLocation => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.2.2.1.3' }, + libraryTemperatureSensorStatus => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.2.2.1.4', map => $map_sensor_status }, + libraryTemperatureSensorValue => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.2.2.1.5' }, +}; +my $oid_libraryTemperatureSensorEntry = '.1.3.6.1.4.1.3697.1.10.15.5.120.2.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_libraryTemperatureSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking temperatures"); + $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; + return if ($self->check_filter(section => 'temperature')); + + my ($exit, $warn, $crit, $checked); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_libraryTemperatureSensorEntry}})) { + next if ($oid !~ /^$mapping->{libraryTemperatureSensorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_libraryTemperatureSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is '%s' [instance = %s] [value = %s]", + $result->{libraryTemperatureSensorLocation}, $result->{libraryTemperatureSensorStatus}, $instance, + $result->{libraryTemperatureSensorValue})); + + $exit = $self->get_severity(label => 'default', section => 'temperature', instance => $instance, value => $result->{libraryTemperatureSensorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' status is '%s'", $result->{libraryTemperatureSensorLocation}, $result->{libraryTemperatureSensorStatus})); + } + + next if (!defined($result->{libraryTemperatureSensorValue}) || $result->{libraryTemperatureSensorValue} !~ /[0-9]/); + + ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{libraryTemperatureSensorValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Temperature '%s' is %s degree centigrade", $result->{libraryTemperatureSensorLocation}, $result->{libraryTemperatureSensorValue}) + ); + } + + $self->{output}->perfdata_add( + nlabel => 'hardware.sensor.temperature.celsius', unit => 'C', + instances => $result->{libraryTemperatureSensorLocation}, + value => $result->{libraryTemperatureSensorValue}, + warning => $warn, + critical => $crit, + ); + } +} + +1; diff --git a/centreon-plugins/storage/quantum/scalar/snmp/mode/components/voltage.pm b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/voltage.pm new file mode 100644 index 000000000..f9c030bb4 --- /dev/null +++ b/centreon-plugins/storage/quantum/scalar/snmp/mode/components/voltage.pm @@ -0,0 +1,89 @@ +# +# Copyright 2019 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 storage::quantum::scalar::snmp::mode::components::voltage; + +use strict; +use warnings; +use storage::quantum::scalar::snmp::mode::components::resources qw($map_sensor_status); + +# In MIB 'QUANTUM-MIDRANGE-TAPE-LIBRARY-MIB' +my $mapping = { + libraryVoltageSensorName => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.110.2.1.2' }, + libraryVoltageSensorLocation => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.110.2.1.3' }, + libraryVoltageSensorStatus => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.110.2.1.5', map => $map_sensor_status }, + libraryVoltageSensorValue => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.110.2.1.6' }, # in mV +}; +my $oid_libraryVoltageSensorEntry = '.1.3.6.1.4.1.3697.1.10.15.5.110.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_libraryVoltageSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking voltages"); + $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; + return if ($self->check_filter(section => 'voltage')); + + my ($exit, $warn, $crit, $checked); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_libraryVoltageSensorEntry}})) { + next if ($oid !~ /^$mapping->{libraryVoltageSensorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_libraryVoltageSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'voltage', instance => $instance)); + $self->{components}->{voltage}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("voltage '%s' status is '%s' [instance = %s] [value = %s]", + $result->{libraryVoltageSensorLocation}, $result->{libraryVoltageSensorStatus}, $instance, + $result->{libraryVoltageSensorValue})); + + $exit = $self->get_severity(label => 'default', section => 'voltage', instance => $instance, value => $result->{libraryVoltageSensorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Voltage '%s' status is '%s'", $result->{libraryVoltageSensorLocation}, $result->{libraryVoltageSensorStatus})); + } + + next if (!defined($result->{libraryVoltageSensorValue}) || $result->{libraryVoltageSensorValue} !~ /[0-9]/); + + $result->{libraryVoltageSensorValue} /= 1000; + ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{libraryVoltageSensorValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Voltage '%s' is %s V", $result->{libraryVoltageSensorLocation}, $result->{libraryVoltageSensorValue}) + ); + } + + $self->{output}->perfdata_add( + nlabel => 'hardware.sensor.voltage.volt', unit => 'V', + instances => $result->{libraryVoltageSensorLocation}, + value => $result->{libraryVoltageSensorValue}, + warning => $warn, + critical => $crit, + ); + } +} + +1; diff --git a/centreon-plugins/storage/quantum/scalar/snmp/mode/hardware.pm b/centreon-plugins/storage/quantum/scalar/snmp/mode/hardware.pm new file mode 100644 index 000000000..c167cd6a6 --- /dev/null +++ b/centreon-plugins/storage/quantum/scalar/snmp/mode/hardware.pm @@ -0,0 +1,127 @@ +# +# Copyright 2019 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 storage::quantum::scalar::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(?:subsystem|physicaldrive\.(status|cleaning)|psu|voltage|humidity|temperature)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(?:temperature|humidity|power|voltage)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['normal', 'OK'], + ['greenGood', 'OK'], + ['unknown', 'UNKNOWN'], + ['redFailure', 'CRITICAL'], + ['orangeDegraded', 'WARNING'], + ['yellowWarning', 'WARNING'], + ['blueAttention', 'WARNING'], + ['greenInformation', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ], + cleaning => [ + ['unknown', 'UNKNOWN'], + ['notNeeded', 'OK'], + ['recommended', 'WARNING'], + ['required', 'CRITICAL'], + ], + psu => [ + ['unknown', 'UNKNOWN'], + ['good', 'OK'], + ['failed', 'CRITICAL'], + ['missing', 'WARNING'], + ], + }; + + $self->{components_path} = 'storage::quantum::scalar::snmp::mode::components'; + $self->{components_module} = ['global', 'subsystem', 'physicaldrive', 'psu', 'temperature', 'humidity', 'voltage']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'global', 'subsystem', 'physicaldrive', 'psu', 'voltage', 'humidity', 'temperature'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=subsystem) +Can also exclude specific instance: --filter=physicaldrive,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='physicaldrive.status,OK,yellowWarning' + +=item B<--warning> + +Set warning threshold (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,40' + +=back + +=cut diff --git a/centreon-plugins/storage/quantum/scalar/snmp/plugin.pm b/centreon-plugins/storage/quantum/scalar/snmp/plugin.pm index 0e91e5433..f8bb61a24 100644 --- a/centreon-plugins/storage/quantum/scalar/snmp/plugin.pm +++ b/centreon-plugins/storage/quantum/scalar/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'centreon::common::adic::tape::snmp::mode::hardware', - ); + 'hardware' => 'storage::quantum::scalar::snmp::mode::hardware', + ); return $self; } @@ -43,6 +43,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Quantum Scalar (i6000, i500, ...) in SNMP. +Check Quantum Scalar in SNMP. =cut diff --git a/centreon-plugins/storage/storagetek/sl/snmp/mode/hardware.pm b/centreon-plugins/storage/storagetek/sl/snmp/mode/hardware.pm index 633288fb8..7ada68255 100644 --- a/centreon-plugins/storage/storagetek/sl/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/storagetek/sl/snmp/mode/hardware.pm @@ -63,7 +63,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/synology/snmp/mode/hardware.pm b/centreon-plugins/storage/synology/snmp/mode/hardware.pm index 65996f5fc..91f139eed 100644 --- a/centreon-plugins/storage/synology/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/synology/snmp/mode/hardware.pm @@ -77,7 +77,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/storage/synology/snmp/mode/temperature.pm b/centreon-plugins/storage/synology/snmp/mode/temperature.pm index 1e1aaab13..ccb995a88 100644 --- a/centreon-plugins/storage/synology/snmp/mode/temperature.pm +++ b/centreon-plugins/storage/synology/snmp/mode/temperature.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' }, diff --git a/centreon-plugins/storage/synology/snmp/mode/ups.pm b/centreon-plugins/storage/synology/snmp/mode/ups.pm index b1a2b8b75..f314695b0 100644 --- a/centreon-plugins/storage/synology/snmp/mode/ups.pm +++ b/centreon-plugins/storage/synology/snmp/mode/ups.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { "warning:s" => { name => 'warning' },