diff --git a/apps/apache/serverstatus/mode/cpuload.pm b/apps/apache/serverstatus/mode/cpuload.pm index 9f3f1c671..c17664b50 100644 --- a/apps/apache/serverstatus/mode/cpuload.pm +++ b/apps/apache/serverstatus/mode/cpuload.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -36,7 +36,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/server-status/?auto" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -44,8 +44,9 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -61,20 +62,13 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); # If not present: cpuload is 0 my ($cpuload) = 0; diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm index 7da4a7afb..b167b4d30 100644 --- a/apps/apache/serverstatus/mode/requests.pm +++ b/apps/apache/serverstatus/mode/requests.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use centreon::plugins::statefile; sub new { @@ -37,7 +37,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/server-status/?auto" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -49,8 +49,9 @@ sub new { "critical-bytes:s" => { name => 'critical_bytes' }, "warning-access:s" => { name => 'warning_access' }, "critical-access:s" => { name => 'critical_access' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); $self->{statefile_value} = centreon::plugins::statefile->new(%options); return $self; } @@ -83,22 +84,15 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_access} . "'."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - + + $self->{http}->set_options(%{$self->{option_results}}); $self->{statefile_value}->check_options(%options); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my ($rPerSec, $bPerReq, $total_access, $total_bytes, $avg_bPerSec); $total_access = $1 if ($webcontent =~ /^Total Accesses:\s+([^\s]+)/mi); @@ -121,7 +115,7 @@ sub run { $avg_bPerSec = '0' . $avg_bPerSec if ($avg_bPerSec =~ /^\./); $bPerReq = '0' . $bPerReq if ($bPerReq =~ /^\./); - $self->{statefile_value}->read(statefile => 'apache_' . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode}); + $self->{statefile_value}->read(statefile => 'apache_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); my $old_total_access = $self->{statefile_value}->get(name => 'total_access'); my $old_total_bytes = $self->{statefile_value}->get(name => 'total_bytes'); diff --git a/apps/apache/serverstatus/mode/responsetime.pm b/apps/apache/serverstatus/mode/responsetime.pm index 65cad0078..1cd608c45 100644 --- a/apps/apache/serverstatus/mode/responsetime.pm +++ b/apps/apache/serverstatus/mode/responsetime.pm @@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use Time::HiRes qw(gettimeofday tv_interval); -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -37,7 +37,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/server-status/?auto" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -45,8 +45,12 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, + "unknown-status:s" => { name => 'unknown_status', default => '' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{http_code} < 200 or %{http_code} >= 300' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -63,19 +67,7 @@ sub check_options { $self->{output}->option_exit(); } - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { @@ -83,18 +75,19 @@ sub run { my $timing0 = [gettimeofday]; - my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical'); + my $webcontent = $self->{http}->request(); my $timeelapsed = tv_interval ($timing0, [gettimeofday]); my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Response time %fs ", $timeelapsed)); - $self->{output}->perfdata_add(label => "time", - value => $timeelapsed, + short_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'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); $self->{output}->display(); $self->{output}->exit(); @@ -146,6 +139,18 @@ Proxy URL if any Threshold for HTTP timeout +=item B<--unknown-status> + +Threshold warning for http response code + +=item B<--warning-status> + +Threshold warning for http response code + +=item B<--critical-status> + +Threshold critical for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300') + =item B<--warning> Threshold warning in seconds (server-status page response time) diff --git a/apps/apache/serverstatus/mode/slotstates.pm b/apps/apache/serverstatus/mode/slotstates.pm index 53800694b..7bd20c257 100644 --- a/apps/apache/serverstatus/mode/slotstates.pm +++ b/apps/apache/serverstatus/mode/slotstates.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -36,7 +36,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/server-status/?auto" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -44,8 +44,9 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -61,26 +62,14 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my $ScoreBoard = ""; if ($webcontent =~ /^Scoreboard:\s+([^\s]+)/mi) { $ScoreBoard = $1; diff --git a/apps/apache/serverstatus/mode/workers.pm b/apps/apache/serverstatus/mode/workers.pm index cdcde2069..37e97675e 100644 --- a/apps/apache/serverstatus/mode/workers.pm +++ b/apps/apache/serverstatus/mode/workers.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -36,7 +36,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/server-status/?auto" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -44,8 +44,9 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -61,25 +62,13 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my ($BusyWorkers, $IdleWorkers, $ScoreBoard); if ($webcontent =~ /^BusyWorkers:\s+([^\s]+)/mi) { $BusyWorkers = $1; diff --git a/apps/bluemind/mode/incoming.pm b/apps/bluemind/mode/incoming.pm index a4ebec430..3e2c4de35 100644 --- a/apps/bluemind/mode/incoming.pm +++ b/apps/bluemind/mode/incoming.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use centreon::plugins::statefile; use JSON; @@ -38,18 +38,18 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '8086'}, - "proto:s" => { name => 'proto', default => 'http' }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/db" }, "database:s" => { name => 'database' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); $self->{statefile_value} = centreon::plugins::statefile->new(%options); - + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -65,10 +65,6 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } if (!defined($self->{option_results}->{database})) { $self->{output}->add_option_msg(short_msg => "Please set the database option"); $self->{output}->option_exit(); @@ -77,14 +73,20 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= option"); $self->{output}->option_exit(); } + + my $query = 'select sum("success") as "success_sum", sum("failure") as "failure_sum" from lmtpd.deliveries where time > '.$old_timestamp.'s and time < now()'; + $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/".$self->{option_results}->{database}."/series"; + $self->{option_results}->{get_param} = []; + push @{$self->{option_results}->{get_param}}, "q=" . $query, "p=" . $self->{option_results}->{password}, "u=" . $self->{option_results}->{username}; + $self->{http}->set_options(%{$self->{option_results}}); $self->{statefile_value}->check_options(%options); } sub run { my ($self, %options) = @_; - $self->{statefile_value}->read(statefile => 'bluemind_' . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode}); + $self->{statefile_value}->read(statefile => 'bluemind_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); my $new_datas = {}; @@ -98,14 +100,9 @@ sub run { $self->{output}->exit(); } - $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/".$self->{option_results}->{database}."/series"; - $self->{option_results}->{query} = 'select sum("success") as "success_sum", sum("failure") as "failure_sum" from lmtpd.deliveries where time > '.$old_timestamp.'s and time < now()'; - - my $query_form_get = { q => $self->{option_results}->{query}, p => $self->{option_results}->{password}, u => $self->{option_results}->{username} }; - my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get); + my $jsoncontent = $self->{http}->request(); my $json = JSON->new; - my $webcontent; eval { diff --git a/apps/checkmyws/mode/status.pm b/apps/checkmyws/mode/status.pm index 5759b1aae..81b1aa75d 100644 --- a/apps/checkmyws/mode/status.pm +++ b/apps/checkmyws/mode/status.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use JSON; my $thresholds = { @@ -50,10 +50,11 @@ sub new { "urlpath:s" => { name => 'url_path', default => "/api/status" }, "proxyurl:s" => { name => 'proxyurl' }, "uid:s" => { name => 'uid' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, "threshold-overload:s@" => { name => 'threshold_overload' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -88,19 +89,19 @@ sub check_options { $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; } + + $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/".$self->{option_results}->{uid}; + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/".$self->{option_results}->{uid}; - - my $jsoncontent = centreon::plugins::httplib::connect($self); + my $jsoncontent = $self->{http}->request(); my $json = JSON->new; my $webcontent; - eval { $webcontent = $json->decode($jsoncontent); }; @@ -214,7 +215,7 @@ ID for checkmyws API =item B<--timeout> -Threshold for HTTP timeout (Default: '3') +Threshold for HTTP timeout (Default: 5) =item B<--threshold-overload> diff --git a/apps/elasticsearch/mode/cluster.pm b/apps/elasticsearch/mode/cluster.pm index b58c5c075..a72dedd5f 100644 --- a/apps/elasticsearch/mode/cluster.pm +++ b/apps/elasticsearch/mode/cluster.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use JSON; my $thresholds = { @@ -45,15 +45,16 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '9200'}, - "proto:s" => { name => 'proto', default => 'http' }, - "urlpath:s" => { name => 'url_path', default => '/' }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, "threshold-overload:s@" => { name => 'threshold_overload' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -61,15 +62,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - $self->{overload_th} = {}; foreach my $val (@{$self->{option_results}->{threshold_overload}}) { if ($val !~ /^(.*?),(.*?),(.*)$/) { @@ -84,6 +76,9 @@ sub check_options { $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; } + + $self->{option_results}->{url_path} = $self->{option_results}->{url_path} . "_cluster/health/"; + $self->{http}->set_options(%{$self->{option_results}}); } sub get_severity { @@ -111,9 +106,7 @@ sub get_severity { sub run { my ($self, %options) = @_; - $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."_cluster/health/"; - - my $jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical'); + my $jsoncontent = $self->{http}->request(); my $json = JSON->new; @@ -199,7 +192,7 @@ Specify password for API authentification =item B<--timeout> -Threshold for HTTP timeout (Default: 3) +Threshold for HTTP timeout (Default: 5) =item B<--threshold-overload> diff --git a/apps/elasticsearch/mode/indices.pm b/apps/elasticsearch/mode/indices.pm index ac8d29a90..42c4e5b63 100644 --- a/apps/elasticsearch/mode/indices.pm +++ b/apps/elasticsearch/mode/indices.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use JSON; use Data::Dumper; @@ -52,15 +52,16 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '9200'}, - "proto:s" => { name => 'proto', default => 'http' }, - "urlpath:s" => { name => 'url_path', default => '/' }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, "threshold-overload:s@" => { name => 'threshold_overload' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -68,15 +69,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - $self->{overload_th} = {}; foreach my $val (@{$self->{option_results}->{threshold_overload}}) { if ($val !~ /^(.*?),(.*?),(.*)$/) { @@ -92,6 +84,9 @@ sub check_options { push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; } + $self->{option_results}->{url_path} = $self->{option_results}->{url_path} . "_cluster/health"; + $self->{option_results}->{get_param} = ['level=indices']; + $self->{http}->set_options(%{$self->{option_results}}); } sub get_severity { @@ -119,10 +114,7 @@ sub get_severity { sub run { my ($self, %options) = @_; - $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."_cluster/health"; - my $query_form_get = { level => 'indices' }; - - my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical'); + my $jsoncontent = $self->{http}->request(); my $json = JSON->new; my $webcontent; @@ -130,7 +122,6 @@ sub run { eval { $webcontent = $json->decode($jsoncontent); }; - if ($@) { $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); $self->{output}->option_exit(); diff --git a/apps/elasticsearch/mode/nodescount.pm b/apps/elasticsearch/mode/nodescount.pm index e5686f858..d55e25f3c 100644 --- a/apps/elasticsearch/mode/nodescount.pm +++ b/apps/elasticsearch/mode/nodescount.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use JSON; sub new { @@ -37,16 +37,17 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '9200'}, - "proto:s" => { name => 'proto', default => 'http' }, - "urlpath:s" => { name => 'url_path', default => '/' }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -54,15 +55,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - 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(); @@ -71,17 +63,17 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } + + $self->{option_results}->{url_path} = $self->{option_results}->{url_path} . "_cluster/stats/"; + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."_cluster/stats/"; - - my $jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical'); + my $jsoncontent = $self->{http}->request(); my $json = JSON->new; - my $webcontent; eval { @@ -173,7 +165,7 @@ Threshold critical. =item B<--timeout> -Threshold for HTTP timeout (Default: 3) +Threshold for HTTP timeout (Default: 5) =back diff --git a/apps/github/mode/commits.pm b/apps/github/mode/commits.pm index 6f248c116..015db74ba 100644 --- a/apps/github/mode/commits.pm +++ b/apps/github/mode/commits.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use centreon::plugins::statefile; use JSON; use DateTime; @@ -45,9 +45,10 @@ sub new { "password:s" => { name => 'password' }, "owner:s" => { name => 'owner' }, "repository:s" => { name => 'repository' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); $self->{statefile_value} = centreon::plugins::statefile->new(%options); return $self; @@ -57,14 +58,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } if (!defined($self->{option_results}->{repository})) { $self->{output}->add_option_msg(short_msg => "Please set the repository option"); $self->{output}->option_exit(); @@ -74,13 +67,15 @@ sub check_options { $self->{output}->option_exit(); } + $self->{option_results}->{url_path} = "/repos/" . $self->{option_results}->{owner} . "/" . $self->{option_results}->{repository}."/commits"; + $self->{http}->set_options(%{$self->{option_results}}); $self->{statefile_value}->check_options(%options); } sub run { my ($self, %options) = @_; - $self->{statefile_value}->read(statefile => 'github_' . $self->{option_results}->{repository} . '_' . $self->{option_results}->{owner} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode}); + $self->{statefile_value}->read(statefile => 'github_' . $self->{option_results}->{repository} . '_' . $self->{option_results}->{owner} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); my $new_datas = {}; @@ -97,15 +92,10 @@ sub run { # Change date format from epoch to iso8601 my $old_iso8601 = DateTime->from_epoch(epoch => $old_timestamp)."Z"; - $self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{owner}."/".$self->{option_results}->{repository}."/commits"; - - my $query_form_get = { per_page => '1000', since => $old_iso8601 }; - my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get , connection_exit => 'critical'); + my $jsoncontent = $self->{http}->request(get_param => ['per_page=1000', 'since=' . $old_iso8601]); my $json = JSON->new; - my $webcontent; - eval { $webcontent = $json->decode($jsoncontent); }; @@ -127,7 +117,6 @@ sub run { $self->{output}->display(); $self->{output}->exit(); - } 1; @@ -174,7 +163,7 @@ Specify GitHub's repository =item B<--timeout> -Threshold for HTTP timeout (Default: 3) +Threshold for HTTP timeout (Default: 5) =back diff --git a/apps/github/mode/issues.pm b/apps/github/mode/issues.pm index b538db208..0b081cad2 100644 --- a/apps/github/mode/issues.pm +++ b/apps/github/mode/issues.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use JSON; sub new { @@ -46,9 +46,10 @@ sub new { "owner:s" => { name => 'owner' }, "repository:s" => { name => 'repository' }, "label:s" => { name => 'label', default => '' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -56,14 +57,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } if (!defined($self->{option_results}->{repository})) { $self->{output}->add_option_msg(short_msg => "Please set the repository option"); $self->{output}->option_exit(); @@ -73,33 +66,30 @@ sub check_options { $self->{output}->option_exit(); } 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(); + $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->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } + + $self->{option_results}->{url_path} = "/repos/" . $self->{option_results}->{owner} . "/" . $self->{option_results}->{repository} . "/issues"; + if (defined($self->{option_results}->{label}) && $self->{option_results}->{label} ne '') { + $self->{option_results}->{get_param} = ['state=open', 'labels=' . $self->{option_results}->{label}, 'per_page=1000']; + } else { + $self->{option_results}->{get_param} = ['state=open', 'per_page=1000']; + } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { - my ($self, %options) = @_; - $self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{owner}."/".$self->{option_results}->{repository} . "/issues"; - - my $query_form_get; - if (defined($self->{option_results}->{label}) && $self->{option_results}->{label} ne '') { - $query_form_get = { state => 'open', labels => $self->{option_results}->{label}, per_page => '1000' }; - } else { - $query_form_get = { state => 'open', per_page => '1000' }; - } - my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get , connection_exit => 'critical'); + my $jsoncontent = $self->{http}->request(); my $json = JSON->new; - my $webcontent; - eval { $webcontent = $json->decode($jsoncontent); }; @@ -136,7 +126,6 @@ sub run { $self->{output}->display(); $self->{output}->exit(); - } 1; diff --git a/apps/github/mode/pullrequests.pm b/apps/github/mode/pullrequests.pm index b5324fe28..edfb7c1c1 100644 --- a/apps/github/mode/pullrequests.pm +++ b/apps/github/mode/pullrequests.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use JSON; sub new { @@ -36,7 +36,7 @@ sub new { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname', default => 'api.github.com' }, - "port:s" => { name => 'port', default => '443'}, + "port:s" => { name => 'port', default => '443' }, "proto:s" => { name => 'proto', default => 'https' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -45,9 +45,10 @@ sub new { "critical:s" => { name => 'critical' }, "owner:s" => { name => 'owner' }, "repository:s" => { name => 'repository' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -55,14 +56,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } if (!defined($self->{option_results}->{repository})) { $self->{output}->add_option_msg(short_msg => "Please set the repository option"); $self->{output}->option_exit(); @@ -79,21 +72,19 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } + + $self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{owner}."/".$self->{option_results}->{repository}."/pulls"; + $self->{option_results}->{get_param} = ['state=open', 'per_page=1000']; + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - $self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{owner}."/".$self->{option_results}->{repository}."/pulls"; - - my $query_form_get = { state => 'open', per_page => '1000' }; - - my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get , connection_exit => 'critical'); + my $jsoncontent = $self->{http}->request(); my $json = JSON->new; - my $webcontent; - eval { $webcontent = $json->decode($jsoncontent); }; @@ -118,7 +109,6 @@ sub run { ); $self->{output}->display(); $self->{output}->exit(); - } 1; @@ -173,7 +163,7 @@ Specify GitHub's repository =item B<--timeout> -Threshold for HTTP timeout (Default: 3) +Threshold for HTTP timeout (Default: 5) =back diff --git a/apps/github/mode/status.pm b/apps/github/mode/status.pm index 93e4b8e99..5058e80db 100644 --- a/apps/github/mode/status.pm +++ b/apps/github/mode/status.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use JSON; my $thresholds = { @@ -50,10 +50,11 @@ sub new { "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, "threshold-overload:s@" => { name => 'threshold_overload' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -61,15 +62,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - $self->{overload_th} = {}; foreach my $val (@{$self->{option_results}->{threshold_overload}}) { if ($val !~ /^(.*?),(.*)$/) { @@ -84,6 +76,8 @@ sub check_options { $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; } + + $self->{http}->set_options(%{$self->{option_results}}); } sub get_severity { @@ -110,12 +104,10 @@ sub get_severity { sub run { my ($self, %options) = @_; - my $jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical'); + my $jsoncontent = $self->{http}->request(); my $json = JSON->new; - my $webcontent; - eval { $webcontent = $json->decode($jsoncontent); }; @@ -132,7 +124,6 @@ sub run { $self->{output}->display(); $self->{output}->exit(); - } 1; @@ -175,7 +166,7 @@ Specify password =item B<--timeout> -Threshold for HTTP timeout (Default: 3) +Threshold for HTTP timeout (Default: 5 =item B<--threshold-overload> diff --git a/apps/jenkins/mode/jobstate.pm b/apps/jenkins/mode/jobstate.pm index fd277a9e1..34c80a98a 100644 --- a/apps/jenkins/mode/jobstate.pm +++ b/apps/jenkins/mode/jobstate.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use centreon::plugins::statefile; use JSON; @@ -37,8 +37,8 @@ sub new { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '80'}, - "proto:s" => { name => 'proto', default => 'http' }, + "port:s" => { name => 'port' }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path' }, "jobname:s" => { name => 'jobname' }, "credentials" => { name => 'credentials' }, @@ -47,9 +47,10 @@ sub new { "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, "checkstyle" => { name => 'checkstyle' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -65,32 +66,23 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } if (!defined($self->{option_results}->{jobname})) { $self->{output}->add_option_msg(short_msg => "Please set the jobname option"); $self->{output}->option_exit(); } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + + $self->{option_results}->{url_path} = $self->{option_results}->{url_path} . "/job/" . $self->{option_results}->{jobname} . "/api/json"; + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - - $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/job/".$self->{option_results}->{jobname}."/api/json"; - - my $jsoncontent = centreon::plugins::httplib::connect($self); + my $jsoncontent = $self->{http}->request(); my $json = JSON->new; my $webcontent; - eval { $webcontent = $json->decode($jsoncontent); }; @@ -187,7 +179,7 @@ Add checkstyle's violation output and perfdata =item B<--timeout> -Threshold for HTTP timeout (Default: 3) +Threshold for HTTP timeout (Default: 5) =back diff --git a/apps/kayako/api/mode/listdepartment.pm b/apps/kayako/api/mode/listdepartment.pm index c65434ed3..353e5df33 100644 --- a/apps/kayako/api/mode/listdepartment.pm +++ b/apps/kayako/api/mode/listdepartment.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use XML::XPath; use Digest::SHA qw(hmac_sha256_base64); @@ -38,74 +38,49 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port' }, - "proto:s" => { name => 'proto', default => "http" }, - "urlpath:s" => { name => 'url_path', default => '/api/index.php?' }, - "kayako-api-key:s" => { name => 'kayako_api_key' }, - "kayako-secret-key:s" => { name => 'kayako_secret_key' }, + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port' }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path', default => '/api/index.php?' }, + "kayako-api-key:s" => { name => 'kayako_api_key' }, + "kayako-secret-key:s" => { name => 'kayako_secret_key' }, }); - $self->set_signal_handlers; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } -sub set_signal_handlers { - my $self = shift; - - $SIG{ALRM} = \&class_handle_ALRM; - $handlers{ALRM}->{$self} = sub { $self->handle_ALRM() }; -} - -sub class_handle_ALRM { - foreach (keys %{$handlers{ALRM}}) { - &{$handlers{ALRM}->{$_}}(); - } -} - -sub handle_ALRM { - my $self = shift; - - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => sprintf("Cannot finished API execution (timeout received)")); - $self->{output}->display(); - $self->{output}->exit(); -} - sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ && - $self->{option_results}->{timeout} > 0) { - alarm($self->{option_results}->{timeout}); - } - if (!defined($self->{option_results}->{'kayako_api_key'})) { + if (!defined($self->{option_results}->{kayako_api_key})) { $self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{'kayako_secret_key'})) { + if (!defined($self->{option_results}->{kayako_secret_key})) { $self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako."); $self->{output}->option_exit(); } + my $salt = ''; + $salt .= int(rand(10)) for 1..10; + my $digest = hmac_sha256_base64($salt, $self->{option_results}->{kayako_secret_key}); + $self->{option_results}->{url_path} .= "/Base/Department&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "="; + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $salt; - $salt .= int(rand(10)) for 1..10; - my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'}); - $self->{option_results}->{'url_path'} .= "/Base/Department&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "="; - my $webcontent = centreon::plugins::httplib::connect($self); - my $xp = XML::XPath->new( $webcontent ); - my $nodes = $xp->find('departments/department'); + + my $webcontent = $self->{http}->set_options(%{$self->{option_results}}); + my $xp = XML::XPath->new($webcontent); + my $nodes = $xp->find('departments/department'); + + foreach my $actionNode ($nodes->get_nodelist) { + my ($id) = $xp->find('./id', $actionNode)->get_nodelist; + my $trim_id = centreon::plugins::misc::trim($id->string_value); + my ($title) = $xp->find('./title', $actionNode)->get_nodelist; + my $trim_title = centreon::plugins::misc::trim($title->string_value); - foreach my $actionNode ($nodes->get_nodelist) { - my ($id) = $xp->find('./id', $actionNode)->get_nodelist; - my $trim_id = centreon::plugins::misc::trim($id->string_value); - my ($title) = $xp->find('./title', $actionNode)->get_nodelist; - my $trim_title = centreon::plugins::misc::trim($title->string_value); -# print $trim_id." : ". $trim_title."\n"; -# } $self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]"); } diff --git a/apps/kayako/api/mode/listpriority.pm b/apps/kayako/api/mode/listpriority.pm index e69beb14e..2917a8848 100644 --- a/apps/kayako/api/mode/listpriority.pm +++ b/apps/kayako/api/mode/listpriority.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use XML::XPath; use Digest::SHA qw(hmac_sha256_base64); @@ -38,72 +38,49 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port' }, - "proto:s" => { name => 'proto', default => "http" }, - "urlpath:s" => { name => 'url_path', default => '/api/index.php?' }, - "kayako-api-key:s" => { name => 'kayako_api_key' }, - "kayako-secret-key:s" => { name => 'kayako_secret_key' }, + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port' }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path', default => '/api/index.php?' }, + "kayako-api-key:s" => { name => 'kayako_api_key' }, + "kayako-secret-key:s" => { name => 'kayako_secret_key' }, }); - $self->set_signal_handlers; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } -sub set_signal_handlers { - my $self = shift; - - $SIG{ALRM} = \&class_handle_ALRM; - $handlers{ALRM}->{$self} = sub { $self->handle_ALRM() }; -} - -sub class_handle_ALRM { - foreach (keys %{$handlers{ALRM}}) { - &{$handlers{ALRM}->{$_}}(); - } -} - -sub handle_ALRM { - my $self = shift; - - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => sprintf("Cannot finished API execution (timeout received)")); - $self->{output}->display(); - $self->{output}->exit(); -} - sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ && - $self->{option_results}->{timeout} > 0) { - alarm($self->{option_results}->{timeout}); - } - if (!defined($self->{option_results}->{'kayako_api_key'})) { + if (!defined($self->{option_results}->{kayako_api_key})) { $self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{'kayako_secret_key'})) { + if (!defined($self->{option_results}->{kayako_secret_key})) { $self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako."); $self->{output}->option_exit(); } + + my $salt; + $salt .= int(rand(10)) for 1..10; + my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{kayako_secret_key}); + $self->{option_results}->{url_path} .= "/Tickets/TicketPriority&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "="; + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $salt; - $salt .= int(rand(10)) for 1..10; - my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'}); - $self->{option_results}->{'url_path'} .= "/Tickets/TicketPriority&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "="; - my $webcontent = centreon::plugins::httplib::connect($self); - my $xp = XML::XPath->new( $webcontent ); - my $nodes = $xp->find('ticketpriorities/ticketpriority'); + + my $webcontent = $self->{http}->request(); + my $xp = XML::XPath->new( $webcontent ); + my $nodes = $xp->find('ticketpriorities/ticketpriority'); - foreach my $actionNode ($nodes->get_nodelist) { - my ($id) = $xp->find('./id', $actionNode)->get_nodelist; - my $trim_id = centreon::plugins::misc::trim($id->string_value); - my ($title) = $xp->find('./title', $actionNode)->get_nodelist; - my $trim_title = centreon::plugins::misc::trim($title->string_value); + foreach my $actionNode ($nodes->get_nodelist) { + my ($id) = $xp->find('./id', $actionNode)->get_nodelist; + my $trim_id = centreon::plugins::misc::trim($id->string_value); + my ($title) = $xp->find('./title', $actionNode)->get_nodelist; + my $trim_title = centreon::plugins::misc::trim($title->string_value); $self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]"); } diff --git a/apps/kayako/api/mode/liststaff.pm b/apps/kayako/api/mode/liststaff.pm index 34c1605ee..d28c6503b 100644 --- a/apps/kayako/api/mode/liststaff.pm +++ b/apps/kayako/api/mode/liststaff.pm @@ -24,12 +24,10 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use XML::XPath; use Digest::SHA qw(hmac_sha256_base64); -my %handlers = (ALRM => {} ); - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -38,72 +36,50 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port' }, - "proto:s" => { name => 'proto', default => "http" }, - "urlpath:s" => { name => 'url_path', default => '/api/index.php?' }, - "kayako-api-key:s" => { name => 'kayako_api_key' }, - "kayako-secret-key:s" => { name => 'kayako_secret_key' }, + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port' }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path', default => '/api/index.php?' }, + "kayako-api-key:s" => { name => 'kayako_api_key' }, + "kayako-secret-key:s" => { name => 'kayako_secret_key' }, }); - $self->set_signal_handlers; + + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } -sub set_signal_handlers { - my $self = shift; - - $SIG{ALRM} = \&class_handle_ALRM; - $handlers{ALRM}->{$self} = sub { $self->handle_ALRM() }; -} - -sub class_handle_ALRM { - foreach (keys %{$handlers{ALRM}}) { - &{$handlers{ALRM}->{$_}}(); - } -} - -sub handle_ALRM { - my $self = shift; - - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => sprintf("Cannot finished API execution (timeout received)")); - $self->{output}->display(); - $self->{output}->exit(); -} - sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ && - $self->{option_results}->{timeout} > 0) { - alarm($self->{option_results}->{timeout}); - } - if (!defined($self->{option_results}->{'kayako_api_key'})) { + if (!defined($self->{option_results}->{kayako_api_key})) { $self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{'kayako_secret_key'})) { + if (!defined($self->{option_results}->{kayako_secret_key})) { $self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako."); $self->{output}->option_exit(); } + + my $salt; + $salt .= int(rand(10)) for 1..10; + my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'}); + $self->{option_results}->{url_path} .= "/Base/Staff&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "="; + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $salt; - $salt .= int(rand(10)) for 1..10; - my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'}); - $self->{option_results}->{'url_path'} .= "/Base/Staff&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "="; - my $webcontent = centreon::plugins::httplib::connect($self); - my $xp = XML::XPath->new( $webcontent ); - my $nodes = $xp->find('staffusers/staff'); + + my $webcontent = $self->{http}->request(); + my $xp = XML::XPath->new( $webcontent ); + my $nodes = $xp->find('staffusers/staff'); - foreach my $actionNode ($nodes->get_nodelist) { - my ($id) = $xp->find('./id', $actionNode)->get_nodelist; - my $trim_id = centreon::plugins::misc::trim($id->string_value); - my ($title) = $xp->find('./username', $actionNode)->get_nodelist; - my $trim_title = centreon::plugins::misc::trim($title->string_value); + foreach my $actionNode ($nodes->get_nodelist) { + my ($id) = $xp->find('./id', $actionNode)->get_nodelist; + my $trim_id = centreon::plugins::misc::trim($id->string_value); + my ($title) = $xp->find('./username', $actionNode)->get_nodelist; + my $trim_title = centreon::plugins::misc::trim($title->string_value); $self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]"); } diff --git a/apps/kayako/api/mode/liststatus.pm b/apps/kayako/api/mode/liststatus.pm index a1d38466d..822e45aad 100644 --- a/apps/kayako/api/mode/liststatus.pm +++ b/apps/kayako/api/mode/liststatus.pm @@ -24,12 +24,10 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use XML::XPath; use Digest::SHA qw(hmac_sha256_base64); -my %handlers = (ALRM => {} ); - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -38,72 +36,50 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port' }, - "proto:s" => { name => 'proto', default => "http" }, - "urlpath:s" => { name => 'url_path', default => '/api/index.php?' }, - "kayako-api-key:s" => { name => 'kayako_api_key' }, - "kayako-secret-key:s" => { name => 'kayako_secret_key' }, + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port' }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path', default => '/api/index.php?' }, + "kayako-api-key:s" => { name => 'kayako_api_key' }, + "kayako-secret-key:s" => { name => 'kayako_secret_key' }, }); - $self->set_signal_handlers; - return $self; -} - -sub set_signal_handlers { - my $self = shift; - - $SIG{ALRM} = \&class_handle_ALRM; - $handlers{ALRM}->{$self} = sub { $self->handle_ALRM() }; -} - -sub class_handle_ALRM { - foreach (keys %{$handlers{ALRM}}) { - &{$handlers{ALRM}->{$_}}(); - } -} - -sub handle_ALRM { - my $self = shift; - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => sprintf("Cannot finished scenario execution (timeout received)")); - $self->{output}->display(); - $self->{output}->exit(); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ && - $self->{option_results}->{timeout} > 0) { - alarm($self->{option_results}->{timeout}); - } - if (!defined($self->{option_results}->{'kayako_api_key'})) { + if (!defined($self->{option_results}->{kayako_api_key})) { $self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{'kayako_secret_key'})) { + if (!defined($self->{option_results}->{kayako_secret_key})) { $self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako."); $self->{output}->option_exit(); } + + my $salt; + $salt .= int(rand(10)) for 1..10; + my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'}); + $self->{option_results}->{'url_path'} .= "/Tickets/TicketStatus&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "="; + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $salt; - $salt .= int(rand(10)) for 1..10; - my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'}); - $self->{option_results}->{'url_path'} .= "/Tickets/TicketStatus&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "="; - my $webcontent = centreon::plugins::httplib::connect($self); - my $xp = XML::XPath->new( $webcontent ); - my $nodes = $xp->find('ticketstatuses/ticketstatus'); - foreach my $actionNode ($nodes->get_nodelist) { - my ($id) = $xp->find('./id', $actionNode)->get_nodelist; - my $trim_id = centreon::plugins::misc::trim($id->string_value); - my ($title) = $xp->find('./title', $actionNode)->get_nodelist; - my $trim_title = centreon::plugins::misc::trim($title->string_value); + my $webcontent = $self->{http}->request(); + my $xp = XML::XPath->new($webcontent); + my $nodes = $xp->find('ticketstatuses/ticketstatus'); + + foreach my $actionNode ($nodes->get_nodelist) { + my ($id) = $xp->find('./id', $actionNode)->get_nodelist; + my $trim_id = centreon::plugins::misc::trim($id->string_value); + my ($title) = $xp->find('./title', $actionNode)->get_nodelist; + my $trim_title = centreon::plugins::misc::trim($title->string_value); $self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]"); } diff --git a/apps/kayako/api/mode/ticketcount.pm b/apps/kayako/api/mode/ticketcount.pm index 97b69d28e..36770e3de 100644 --- a/apps/kayako/api/mode/ticketcount.pm +++ b/apps/kayako/api/mode/ticketcount.pm @@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use centreon::plugins::statefile; -use centreon::plugins::httplib; +use centreon::plugins::http; use XML::XPath; use Digest::SHA qw(hmac_sha256_base64); use Time::Local; @@ -38,7 +38,6 @@ my @priority_filters; my $ticket_total = 0; my %tickets; my $label; -my %handlers = (ALRM => {} ); sub new { my ($class, %options) = @_; @@ -50,7 +49,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port' }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => '/api/index.php?' }, "kayako-api-key:s" => { name => 'kayako_api_key' }, "kayako-secret-key:s" => { name => 'kayako_secret_key' }, @@ -64,82 +63,56 @@ sub new { "start-date:s" => { name => 'start_date' }, "end-date:s" => { name => 'end_date' }, }); - $self->set_signal_handlers; $self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{statefile_value} = centreon::plugins::statefile->new(%options); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } -sub set_signal_handlers { - my $self = shift; - - $SIG{ALRM} = \&class_handle_ALRM; - $handlers{ALRM}->{$self} = sub { $self->handle_ALRM() }; -} - -sub class_handle_ALRM { - foreach (keys %{$handlers{ALRM}}) { - &{$handlers{ALRM}->{$_}}(); - } -} - -sub handle_ALRM { - my $self = shift; - - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => sprintf("Cannot finished API execution (timeout received)")); - $self->{output}->display(); - $self->{output}->exit(); -} - sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ && - $self->{option_results}->{timeout} > 0) { - alarm($self->{option_results}->{timeout}); - } - if (!defined($self->{option_results}->{'kayako_api_key'})) { + if (!defined($self->{option_results}->{kayako_api_key})) { $self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{'kayako_secret_key'})) { + if (!defined($self->{option_results}->{kayako_secret_key})) { $self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{'department_id'})) { + if (!defined($self->{option_results}->{department_id})) { $self->{output}->add_option_msg(short_msg => "Please specify at least one department ID."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{'staff_id'})) { - $self->{option_results}->{'staff_id'} = "-1"; + if (!defined($self->{option_results}->{staff_id})) { + $self->{option_results}->{staff_id} = "-1"; } - if (!defined($self->{option_results}->{'status_id'})) { - $self->{option_results}->{'status_id'} = "-1"; + if (!defined($self->{option_results}->{status_id})) { + $self->{option_results}->{status_id} = "-1"; } - if (defined($self->{option_results}->{'priority_id'})) { - @priority_filters = split(/,/, $self->{option_results}->{'priority_id'}); + if (defined($self->{option_results}->{priority_id})) { + @priority_filters = split(/,/, $self->{option_results}->{priority_id}); } - if (defined($self->{option_results}->{'start_date'})) { - if ($self->{option_results}->{'start_date'} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){ + if (defined($self->{option_results}->{start_date})) { + if ($self->{option_results}->{start_date} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){ $self->{output}->add_option_msg(short_msg => "Please specify a valid date (DD-MM-YYYY)."); $self->{output}->option_exit(); } else { - my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{'start_date'}); - $start = $self->{option_results}->{'start_date'}; - $self->{option_results}->{'start_date'} = timelocal(0,0,0,$mday,$mon-1,$year); + my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{start_date}); + $start = $self->{option_results}->{start_date}; + $self->{option_results}->{start_date} = timelocal(0,0,0,$mday,$mon-1,$year); } } - if (defined($self->{option_results}->{'end_date'})) { - if ($self->{option_results}->{'end_date'} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){ + if (defined($self->{option_results}->{end_date})) { + if ($self->{option_results}->{end_date} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){ $self->{output}->add_option_msg(short_msg => "Please specify a valid date (DD-MM-YYYY)."); $self->{output}->option_exit(); } else { - my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{'end_date'}); - $end = $self->{option_results}->{'end_date'}; - $self->{option_results}->{'end_date'} = timelocal(59,59,23,$mday,$mon-1,$year); + my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{end_date}); + $end = $self->{option_results}->{end_date}; + $self->{option_results}->{end_date} = timelocal(59,59,23,$mday,$mon-1,$year); } } if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { @@ -153,6 +126,9 @@ sub check_options { $self->{statefile_cache}->check_options(%options); $self->{statefile_value}->check_options(%options); + + + $self->{http}->set_options(%{$self->{option_results}}); } sub reload_cache { @@ -161,12 +137,12 @@ sub reload_cache { $datas->{last_timestamp} = time(); - my $salt; + my $salt = ''; $salt .= int(rand(10)) for 1..10; - my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'}); - $self->{option_results}->{'url_path'} = $url_original_path . "/Base/Department&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "="; - my $webcontent = centreon::plugins::httplib::connect($self); - my $xp = XML::XPath->new( $webcontent ); + my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{kayako_secret_key}); + my $webcontent = $self->{http}->request(url_path => $url_original_path . "/Base/Department&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=";); + + my $xp = XML::XPath->new($webcontent); my $nodes = $xp->find('departments/department'); foreach my $actionNode ($nodes->get_nodelist) { my ($id) = $xp->find('./id', $actionNode)->get_nodelist; @@ -176,8 +152,7 @@ sub reload_cache { $datas->{"department_".$trim_id} = $self->{output}->to_utf8($trim_title); } - $self->{option_results}->{'url_path'} = $url_original_path . "/Tickets/TicketPriority&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "="; - $webcontent = centreon::plugins::httplib::connect($self); + $webcontent = $self->{http}->request(url_path => $url_original_path . "/Tickets/TicketPriority&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "="); $xp = XML::XPath->new( $webcontent ); $nodes = $xp->find('ticketpriorities/ticketpriority'); foreach my $actionNode ($nodes->get_nodelist) { @@ -188,8 +163,7 @@ sub reload_cache { $datas->{"priority_".$trim_id} = $self->{output}->to_utf8($trim_title); } - $self->{option_results}->{'url_path'} = $url_original_path . "/Base/Staff&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "="; - $webcontent = centreon::plugins::httplib::connect($self); + $webcontent = $self->{http}->request(url_path => $url_original_path . "/Base/Staff&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "="); $xp = XML::XPath->new( $webcontent ); $nodes = $xp->find('staffusers/staff'); foreach my $actionNode ($nodes->get_nodelist) { @@ -200,8 +174,7 @@ sub reload_cache { $datas->{"staff_".$trim_id} = $self->{output}->to_utf8($trim_title); } - $self->{option_results}->{'url_path'} = $url_original_path . "/Tickets/TicketStatus&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "="; - $webcontent = centreon::plugins::httplib::connect($self); + $webcontent = $self->{http}->request(url_path => $url_original_path . "/Tickets/TicketStatus&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "="); $xp = XML::XPath->new( $webcontent ); $nodes = $xp->find('ticketstatuses/ticketstatus'); foreach my $actionNode ($nodes->get_nodelist) { @@ -217,10 +190,10 @@ sub reload_cache { sub run { my ($self, %options) = @_; - my $salt; + my $salt = ''; $salt .= int(rand(10)) for 1..10; - my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'}); - $url_original_path = $self->{option_results}->{'url_path'}; + my $digest = hmac_sha256_base64($salt, $self->{option_results}->{kayako_secret_key}); + $url_original_path = $self->{option_results}->{url_path}; my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_api_' . ($self->{option_results}->{hostname}) . '_kayako'); my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); @@ -230,8 +203,7 @@ sub run { $self->{statefile_cache}->read(); } - $self->{option_results}->{'url_path'} = $url_original_path . "/Tickets/Ticket/ListAll/" . $self->{option_results}->{'department_id'} . "/" . $self->{option_results}->{'status_id'} . "/" . $self->{option_results}->{'staff_id'} . "/-1/-1/1420120620/-1/-1&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "="; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(url_path => $url_original_path . "/Tickets/Ticket/ListAll/" . $self->{option_results}->{department_id} . "/" . $self->{option_results}->{status_id} . "/" . $self->{option_results}->{staff_id} . "/-1/-1/1420120620/-1/-1&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "="); my $xp = XML::XPath->new( $webcontent ); my $nodes = $xp->find('tickets/ticket'); @@ -243,9 +215,9 @@ sub run { my $trim_priorityid = centreon::plugins::misc::trim($priorityid->string_value); my ($date) = $xp->find('./lastactivity', $actionNode)->get_nodelist; my $trim_date = centreon::plugins::misc::trim($date->string_value); - if (defined($self->{option_results}->{'start_date'}) and (defined($self->{option_results}->{'end_date'}))) { - if ($trim_date > $self->{option_results}->{'start_date'} and $trim_date < $self->{option_results}->{'end_date'}) { - if (defined($self->{option_results}->{'priority_id'})){ + if (defined($self->{option_results}->{start_date}) and (defined($self->{option_results}->{end_date}))) { + if ($trim_date > $self->{option_results}->{start_date} and $trim_date < $self->{option_results}->{end_date}) { + if (defined($self->{option_results}->{priority_id})){ foreach $priority_filter (@priority_filters) { if ($priority_filter == $trim_priorityid){ $tickets{$priority_filter}++; @@ -256,9 +228,9 @@ sub run { $ticket_total++; } } - } elsif (defined($self->{option_results}->{'start_date'}) and (!defined($self->{option_results}->{'end_date'}))) { - if ($trim_date > $self->{option_results}->{'start_date'}) { - if (defined($self->{option_results}->{'priority_id'})){ + } elsif (defined($self->{option_results}->{start_date}) and (!defined($self->{option_results}->{end_date}))) { + if ($trim_date > $self->{option_results}->{start_date}) { + if (defined($self->{option_results}->{priority_id})){ foreach $priority_filter (@priority_filters) { if ($priority_filter == $trim_priorityid){ $tickets{$priority_filter}++; @@ -269,9 +241,9 @@ sub run { $ticket_total++; } } - } elsif (!defined($self->{option_results}->{'start_date'}) and (defined($self->{option_results}->{'end_date'}))) { - if ($trim_date < $self->{option_results}->{'end_date'}) { - if (defined($self->{option_results}->{'priority_id'})){ + } elsif (!defined($self->{option_results}->{start_date}) and (defined($self->{option_results}->{end_date}))) { + if ($trim_date < $self->{option_results}->{end_date}) { + if (defined($self->{option_results}->{priority_id})){ foreach $priority_filter (@priority_filters) { if ($priority_filter == $trim_priorityid){ $tickets{$priority_filter}++; @@ -283,7 +255,7 @@ sub run { } } } else { - if (defined($self->{option_results}->{'priority_id'})){ + if (defined($self->{option_results}->{priority_id})){ foreach $priority_filter (@priority_filters) { if ($priority_filter == $trim_priorityid){ $tickets{$priority_filter}++; @@ -299,32 +271,32 @@ sub run { ########### # Manage Output ########### - my $exit = $self->{perfdata}->threshold_check(value => $ticket_total, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check(value => $ticket_total, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $staff = ""; my $ticket_status = ""; my $period = ""; - if (defined($self->{option_results}->{'staff_id'}) && ($self->{option_results}->{'staff_id'} =~ m/^\d*$/)) { - $staff = " for staff '" . $self->{statefile_cache}->get(name => 'staff_'.$self->{option_results}->{'staff_id'}) ."'"; + if (defined($self->{option_results}->{staff_id}) && ($self->{option_results}->{staff_id} =~ m/^\d*$/)) { + $staff = " for staff '" . $self->{statefile_cache}->get(name => 'staff_'.$self->{option_results}->{staff_id}) ."'"; } - if (defined($self->{option_results}->{'status_id'}) && ($self->{option_results}->{'status_id'} =~ m/^\d*$/)) { - $ticket_status = " in status '" . $self->{statefile_cache}->get(name => 'status_'.$self->{option_results}->{'status_id'}) ."'"; + if (defined($self->{option_results}->{status_id}) && ($self->{option_results}->{status_id} =~ m/^\d*$/)) { + $ticket_status = " in status '" . $self->{statefile_cache}->get(name => 'status_'.$self->{option_results}->{status_id}) ."'"; } - if (defined($self->{option_results}->{'start_date'}) || defined($self->{option_results}->{'end_date'})){ + if (defined($self->{option_results}->{start_date}) || defined($self->{option_results}->{end_date})){ $period = " -"; } - if (defined($self->{option_results}->{'start_date'})){ + if (defined($self->{option_results}->{start_date})){ $start = " Start: " . $start; } - if (defined($self->{option_results}->{'end_date'})){ + if (defined($self->{option_results}->{end_date})){ $end = " End: " . $end; } - if (defined($self->{option_results}->{'priority_id'})){ + if (defined($self->{option_results}->{priority_id})){ foreach $priority_filter (@priority_filters) { $label = $self->{statefile_cache}->get(name => 'priority_'.$priority_filter); $self->{output}->perfdata_add(label => $label, value => $tickets{$priority_filter}, diff --git a/apps/kayako/sql/mode/listdepartment.pm b/apps/kayako/sql/mode/listdepartment.pm index 4b11ee5b1..b50c01cfe 100644 --- a/apps/kayako/sql/mode/listdepartment.pm +++ b/apps/kayako/sql/mode/listdepartment.pm @@ -45,16 +45,11 @@ sub run { $self->{sql}->connect(); - if (!($self->{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(); - } - $self->{sql}->query(query => "SELECT departmentid, title FROM swdepartments"); while ((my $row = $self->{sql}->fetchrow_hashref())) { - $self->{output}->output_add(long_msg => "'" . $row->{title} . "' [id = " . $row->{departmentid} . "]"); + $self->{output}->output_add(long_msg => "'" . $row->{title} . "' [id = " . $row->{departmentid} . "]"); } - + $self->{output}->output_add(severity => 'OK', short_msg => 'List departments:'); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); diff --git a/apps/kayako/sql/mode/listpriority.pm b/apps/kayako/sql/mode/listpriority.pm index 5fbea641c..533d6763b 100644 --- a/apps/kayako/sql/mode/listpriority.pm +++ b/apps/kayako/sql/mode/listpriority.pm @@ -45,16 +45,11 @@ sub run { $self->{sql}->connect(); - if (!($self->{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(); - } - $self->{sql}->query(query => "SELECT priorityid, title FROM swticketpriorities"); while ((my $row = $self->{sql}->fetchrow_hashref())) { - $self->{output}->output_add(long_msg => "'" . $row->{title} . "' [id = " . $row->{priorityid} . "]"); + $self->{output}->output_add(long_msg => "'" . $row->{title} . "' [id = " . $row->{priorityid} . "]"); } - + $self->{output}->output_add(severity => 'OK', short_msg => 'List priorities:'); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); diff --git a/apps/kayako/sql/mode/liststaff.pm b/apps/kayako/sql/mode/liststaff.pm index 796583442..90d7aa34e 100644 --- a/apps/kayako/sql/mode/liststaff.pm +++ b/apps/kayako/sql/mode/liststaff.pm @@ -45,16 +45,11 @@ sub run { $self->{sql}->connect(); - if (!($self->{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(); - } - $self->{sql}->query(query => "SELECT staffid, username FROM swstaff"); while ((my $row = $self->{sql}->fetchrow_hashref())) { - $self->{output}->output_add(long_msg => "'" . $row->{username} . "' [id = " . $row->{staffid} . "]"); + $self->{output}->output_add(long_msg => "'" . $row->{username} . "' [id = " . $row->{staffid} . "]"); } - + $self->{output}->output_add(severity => 'OK', short_msg => 'List staff:'); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); diff --git a/apps/kayako/sql/mode/liststatus.pm b/apps/kayako/sql/mode/liststatus.pm index 92741312d..f30adab93 100644 --- a/apps/kayako/sql/mode/liststatus.pm +++ b/apps/kayako/sql/mode/liststatus.pm @@ -45,16 +45,11 @@ sub run { $self->{sql}->connect(); - if (!($self->{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(); - } - $self->{sql}->query(query => "SELECT ticketstatusid, title FROM swticketstatus"); while ((my $row = $self->{sql}->fetchrow_hashref())) { - $self->{output}->output_add(long_msg => "'" . $row->{title} . "' [id = " . $row->{ticketstatusid} . "]"); + $self->{output}->output_add(long_msg => "'" . $row->{title} . "' [id = " . $row->{ticketstatusid} . "]"); } - + $self->{output}->output_add(severity => 'OK', short_msg => 'List status:'); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); diff --git a/apps/kayako/sql/mode/ticketcount.pm b/apps/kayako/sql/mode/ticketcount.pm index 9ce6bcc88..567e1fdfd 100644 --- a/apps/kayako/sql/mode/ticketcount.pm +++ b/apps/kayako/sql/mode/ticketcount.pm @@ -30,7 +30,6 @@ use Time::Local; my $ticket_total = 0; my %tickets; my $label; -my %handlers = (ALRM => {} ); my $start = ""; my $end = ""; my $priority_filter; @@ -44,15 +43,15 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, - "department-id:s" => { name => 'department_id' }, - "staff-id:s" => { name => 'staff_id' }, - "status-id:s" => { name => 'status_id' }, - "priority-id:s" => { name => 'priority_id' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "start-date:s" => { name => 'start_date' }, - "end-date:s" => { name => 'end_date' }, + "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, + "department-id:s" => { name => 'department_id' }, + "staff-id:s" => { name => 'staff_id' }, + "status-id:s" => { name => 'status_id' }, + "priority-id:s" => { name => 'priority_id' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "start-date:s" => { name => 'start_date' }, + "end-date:s" => { name => 'end_date' }, }); $self->{statefile_cache} = centreon::plugins::statefile->new(%options); @@ -63,36 +62,36 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (defined($self->{option_results}->{'start_date'})) { - if ($self->{option_results}->{'start_date'} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){ - $self->{output}->add_option_msg(short_msg => "Please specify a valid date (DD-MM-YYYY)."); - $self->{output}->option_exit(); - } else { - my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{'start_date'}); - $start = $self->{option_results}->{'start_date'}; - $self->{option_results}->{'start_date'} = timelocal(0,0,0,$mday,$mon-1,$year); - } - } - if (defined($self->{option_results}->{'end_date'})) { - if ($self->{option_results}->{'end_date'} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){ + if (defined($self->{option_results}->{start_date})) { + if ($self->{option_results}->{start_date} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){ + $self->{output}->add_option_msg(short_msg => "Please specify a valid date (DD-MM-YYYY)."); + $self->{output}->option_exit(); + } else { + my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{'start_date'}); + $start = $self->{option_results}->{start_date}; + $self->{option_results}->{start_date} = timelocal(0,0,0,$mday,$mon-1,$year); + } + } + if (defined($self->{option_results}->{end_date})) { + if ($self->{option_results}->{end_date} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){ $self->{output}->add_option_msg(short_msg => "Please specify a valid date (DD-MM-YYYY)."); $self->{output}->option_exit(); } else { - my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{'end_date'}); - $end = $self->{option_results}->{'end_date'}; - $self->{option_results}->{'end_date'} = timelocal(59,59,23,$mday,$mon-1,$year); + my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{end_date}); + $end = $self->{option_results}->{end_date}; + $self->{option_results}->{end_date} = timelocal(59,59,23,$mday,$mon-1,$year); } } 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(); + $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->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } - if (defined($self->{option_results}->{'priority_id'})) { - @priority_filters = split(/,/, $self->{option_results}->{'priority_id'}); + if (defined($self->{option_results}->{priority_id})) { + @priority_filters = split(/,/, $self->{option_results}->{priority_id}); } $self->{statefile_cache}->check_options(%options); @@ -132,22 +131,16 @@ sub run { $self->{sql} = $options{sql}; $self->{sql}->connect(); - - if (!($self->{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(); - } my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_sql_' . $self->{sql}->get_unique_id4save() . '_kayako'); 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->reload_cache(); - $self->{statefile_cache}->read(); + $self->reload_cache(); + $self->{statefile_cache}->read(); } my $query = "SELECT priorityid FROM swtickets WHERE ticketid IS NOT NULL"; - if (defined($self->{option_results}->{'department_id'})) { $query .= " AND departmentid IN (" . $self->{option_results}->{'department_id'} . ")"; } @@ -170,59 +163,60 @@ sub run { $self->{sql}->query(query => $query); while ((my $row = $self->{sql}->fetchrow_hashref())) { - if (defined($self->{option_results}->{'priority_id'})){ + if (defined($self->{option_results}->{priority_id})) { foreach $priority_filter (@priority_filters) { - if ($priority_filter == $row->{priorityid}){ + if ($priority_filter == $row->{priorityid}) { $tickets{$priority_filter}++; $ticket_total++; } } } else { $ticket_total++; - } + } } - -########### -# Manage Output -########### - my $exit = $self->{perfdata}->threshold_check(value => $ticket_total, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - my $staff = ""; - my $ticket_status = ""; - my $period = ""; - - if (defined($self->{option_results}->{'staff_id'}) && ($self->{option_results}->{'staff_id'} =~ m/^\d*$/)) { + + ########### + # Manage Output + ########### + my $exit = $self->{perfdata}->threshold_check(value => $ticket_total, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $staff = ""; + my $ticket_status = ""; + my $period = ""; + + if (defined($self->{option_results}->{staff_id}) && ($self->{option_results}->{staff_id} =~ m/^\d*$/)) { $staff = " for staff '" . $self->{statefile_cache}->get(name => 'staff_'.$self->{option_results}->{'staff_id'}) ."'"; } - if (defined($self->{option_results}->{'status_id'}) && ($self->{option_results}->{'status_id'} =~ m/^\d*$/)) { + if (defined($self->{option_results}->{status_id}) && ($self->{option_results}->{status_id} =~ m/^\d*$/)) { $ticket_status = " in status '" . $self->{statefile_cache}->get(name => 'status_'.$self->{option_results}->{'status_id'}) ."'"; } - if (defined($self->{option_results}->{'start_date'}) || defined($self->{option_results}->{'end_date'})){ + if (defined($self->{option_results}->{start_date}) || defined($self->{option_results}->{end_date})){ $period = " -"; } - if (defined($self->{option_results}->{'start_date'})){ - $start = " Start: " . $start; + if (defined($self->{option_results}->{start_date})){ + $start = " Start: " . $start; } - if (defined($self->{option_results}->{'end_date'})){ - $end = " End: " . $end; - } + if (defined($self->{option_results}->{end_date})){ + $end = " End: " . $end; + } - if (defined($self->{option_results}->{'priority_id'})){ - foreach $priority_filter (@priority_filters) { - $label = $self->{statefile_cache}->get(name => 'priority_'.$priority_filter); - $self->{output}->perfdata_add(label => $label, value => $tickets{$priority_filter}, - min => 0, max => $ticket_total); - } - } - $self->{output}->perfdata_add(label => 'Total', value => $ticket_total, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + if (defined($self->{option_results}->{priority_id})) { + foreach $priority_filter (@priority_filters) { + $label = $self->{statefile_cache}->get(name => 'priority_' . $priority_filter); + $self->{output}->perfdata_add(label => $label, value => $tickets{$priority_filter}, + min => 0, max => $ticket_total); + } + } + $self->{output}->perfdata_add(label => 'Total', value => $ticket_total, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("%s tickets%s%s%s%s%s", $ticket_total, $staff, $ticket_status, $period, $start, $end)); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%s tickets%s%s%s%s%s", $ticket_total, $staff, $ticket_status, $period, $start, $end)); $self->{output}->display(); $self->{output}->exit(); diff --git a/apps/nginx/serverstatus/mode/connections.pm b/apps/nginx/serverstatus/mode/connections.pm index 7f3fea6fa..3d3816837 100644 --- a/apps/nginx/serverstatus/mode/connections.pm +++ b/apps/nginx/serverstatus/mode/connections.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; my $maps = [ { counter => 'active', output => 'Active connections %d', match => 'Active connections:\s*(\d+)' }, @@ -43,13 +43,13 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/nginx_status" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); foreach (@{$maps}) { $options{options}->add_options(arguments => { @@ -57,6 +57,8 @@ sub new { 'critical-' . $_->{counter} . ':s' => { name => 'critical_' . $_->{counter} }, }); } + + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -74,25 +76,14 @@ sub check_options { $self->{output}->option_exit(); } } - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); foreach (@{$maps}) { if ($webcontent !~ /$_->{match}/msi) { $self->{output}->output_add(severity => 'UNKNOWN', diff --git a/apps/nginx/serverstatus/mode/requests.pm b/apps/nginx/serverstatus/mode/requests.pm index 204e276c0..790cb1705 100644 --- a/apps/nginx/serverstatus/mode/requests.pm +++ b/apps/nginx/serverstatus/mode/requests.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use centreon::plugins::statefile; my $maps = [ @@ -43,13 +43,13 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/nginx_status" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); foreach (@{$maps}) { $options{options}->add_options(arguments => { @@ -58,6 +58,7 @@ sub new { }); } $self->{statefile_value} = centreon::plugins::statefile->new(%options); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -75,27 +76,20 @@ sub check_options { $self->{output}->option_exit(); } } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } $self->{statefile_value}->check_options(%options); + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my ($buffer_creation, $exit) = (0, 0); my $new_datas = {}; my $old_datas = {}; - $self->{statefile_value}->read(statefile => 'nginx_' . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode}); + $self->{statefile_value}->read(statefile => 'nginx_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); $old_datas->{timestamp} = $self->{statefile_value}->get(name => 'timestamp'); $new_datas->{timestamp} = time(); foreach (@{$maps}) { diff --git a/apps/nginx/serverstatus/mode/responsetime.pm b/apps/nginx/serverstatus/mode/responsetime.pm index 5b142c23e..9e1693e4e 100644 --- a/apps/nginx/serverstatus/mode/responsetime.pm +++ b/apps/nginx/serverstatus/mode/responsetime.pm @@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use Time::HiRes qw(gettimeofday tv_interval); -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -37,7 +37,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/nginx_status" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -45,8 +45,12 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, + "unknown-status:s" => { name => 'unknown_status', default => '' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{http_code} < 200 or %{http_code} >= 300' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -63,19 +67,7 @@ sub check_options { $self->{output}->option_exit(); } - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { @@ -83,12 +75,12 @@ sub run { my $timing0 = [gettimeofday]; - my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical'); + my $webcontent = $self->{http}->request(); my $timeelapsed = tv_interval ($timing0, [gettimeofday]); my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, short_msg => sprintf("Response time %fs ", $timeelapsed)); $self->{output}->perfdata_add(label => "time", @@ -146,6 +138,18 @@ Proxy URL if any Threshold for HTTP timeout +=item B<--unknown-status> + +Threshold warning for http response code + +=item B<--warning-status> + +Threshold warning for http response code + +=item B<--critical-status> + +Threshold critical for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300') + =item B<--warning> Threshold warning in seconds (nginx_status page response time) diff --git a/apps/apc/web/mode/filecache.pm b/apps/php/apc/web/mode/filecache.pm similarity index 94% rename from apps/apc/web/mode/filecache.pm rename to apps/php/apc/web/mode/filecache.pm index 7c92b3658..aa83f8253 100644 --- a/apps/apc/web/mode/filecache.pm +++ b/apps/php/apc/web/mode/filecache.pm @@ -18,15 +18,14 @@ # limitations under the License. # -package apps::apc::web::mode::filecache; +package apps::php::apc::web::mode::filecache; use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use centreon::plugins::statefile; -use Digest::MD5 qw(md5_hex); use centreon::plugins::values; my $maps_counters = { @@ -216,7 +215,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/apc.php" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -225,6 +224,7 @@ sub new { "timeout:s" => { name => 'timeout', default => 30 }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); $self->{statefile_value} = centreon::plugins::statefile->new(%options); foreach (keys %{$maps_counters}) { @@ -246,30 +246,22 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - foreach (keys %{$maps_counters}) { $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); } + $self->{http}->set_options(%{$self->{option_results}}); $self->{statefile_value}->check_options(%options); } sub run { my ($self, %options) = @_; - $self->{webcontent} = centreon::plugins::httplib::connect($self); + $self->{webcontent} = $self->{http}->request(); $self->manage_selection(); $self->{new_datas} = {}; - $self->{statefile_value}->read(statefile => "apc_" . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode}); + $self->{statefile_value}->read(statefile => "apc_" . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); $self->{new_datas}->{last_timestamp} = time(); my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); diff --git a/apps/apc/web/mode/memory.pm b/apps/php/apc/web/mode/memory.pm similarity index 92% rename from apps/apc/web/mode/memory.pm rename to apps/php/apc/web/mode/memory.pm index aa8f7682f..6a5fee586 100644 --- a/apps/apc/web/mode/memory.pm +++ b/apps/php/apc/web/mode/memory.pm @@ -18,13 +18,13 @@ # limitations under the License. # -package apps::apc::web::mode::memory; +package apps::php::apc::web::mode::memory; use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use centreon::plugins::values; my $maps_counters = { @@ -92,7 +92,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/apc.php" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -100,7 +100,9 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "timeout:s" => { name => 'timeout', default => 30 }, }); - + + $self->{http} = centreon::plugins::http->new(output => $self->{output}); + foreach (keys %{$maps_counters}) { $options{options}->add_options(arguments => { 'warning-' . $_ . ':s' => { name => 'warning-' . $_ }, @@ -118,24 +120,17 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - + foreach (keys %{$maps_counters}) { $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); } + + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - $self->{webcontent} = centreon::plugins::httplib::connect($self); + $self->{webcontent} = $self->{http}->request(); $self->manage_selection(); diff --git a/apps/apc/web/plugin.pm b/apps/php/apc/web/plugin.pm similarity index 87% rename from apps/apc/web/plugin.pm rename to apps/php/apc/web/plugin.pm index d9dc94abf..6e240bf96 100644 --- a/apps/apc/web/plugin.pm +++ b/apps/php/apc/web/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package apps::apc::web::plugin; +package apps::php::apc::web::plugin; use strict; use warnings; @@ -32,8 +32,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'file-cache' => 'apps::apc::web::mode::filecache', - 'memory' => 'apps::apc::web::mode::memory', + 'file-cache' => 'apps::php::apc::web::mode::filecache', + 'memory' => 'apps::php::apc::web::mode::memory', ); return $self; diff --git a/apps/php/fpm/web/mode/usage.pm b/apps/php/fpm/web/mode/usage.pm new file mode 100644 index 000000000..fd149d20a --- /dev/null +++ b/apps/php/fpm/web/mode/usage.pm @@ -0,0 +1,308 @@ +# +# Copyright 2015 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::php::fpm::web::mode::usage; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::http; +use centreon::plugins::values; +use centreon::plugins::statefile; + +my $maps_counters = { + fpm => { + '000_active-processes' => { set => { + key_values => [ { name => 'active' }, { name => 'total' } ], + closure_custom_calc => \&custom_active_calc, + closure_custom_output => \&custom_active_output, + threshold_use => 'active_prct', + closure_custom_perfdata => => \&custom_active_perfdata, + } + }, + '001_idle-processes' => { set => { + key_values => [ { name => 'idle' }, { name => 'total' } ], + closure_custom_calc => \&custom_idle_calc, + closure_custom_output => \&custom_idle_output, + threshold_use => 'idle_prct', + closure_custom_perfdata => => \&custom_idle_perfdata, + } + }, + '002_listen-queue' => { set => { + key_values => [ { name => 'listen_queue' }, { name => 'max_listen_queue' } ], + output_template => 'Listen queue : %s', + output_use => 'listen_queue_absolute', threshold_use => 'listen_queue_absolute', + perfdatas => [ + { label => 'listen_queue', template => '%s', value => 'listen_queue_absolute', + min => 0, max => 'max_listen_queue_absolute' }, + ], + } + }, + '003_requests' => { set => { + key_values => [ { name => 'request', diff => 1 } ], + per_second => 1, + output_template => 'Requests : %.2f/s', + perfdatas => [ + { label => 'requests', template => '%.2f', value => 'request_per_second', + unit => '/s', min => 0 }, + ], + } + }, + }, +}; + +sub custom_active_calc { + my ($self, %options) = @_; + + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'}; + $self->{result_values}->{active_prct} = $self->{result_values}->{active} * 100 / $self->{result_values}->{total}; + return 0; +} + +sub custom_active_output { + my ($self, %options) = @_; + + return sprintf("Active processes: %s (%.2f%%)", + $self->{result_values}->{active}, + $self->{result_values}->{active_prct}); +} + +sub custom_active_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add(label => 'active', + value => $self->{result_values}->{active}, + 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_idle_calc { + my ($self, %options) = @_; + + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{idle} = $options{new_datas}->{$self->{instance} . '_idle'}; + $self->{result_values}->{idle_prct} = $self->{result_values}->{idle} * 100 / $self->{result_values}->{total}; + return 0; +} + +sub custom_idle_output { + my ($self, %options) = @_; + + return sprintf("Idle processes: %s (%.2f%%)", + $self->{result_values}->{idle}, + $self->{result_values}->{idle_prct}); +} + +sub custom_idle_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add(label => 'idle', + value => $self->{result_values}->{idle}, + 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 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', }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path', default => "/fpm-status" }, + "credentials" => { name => 'credentials' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "proxyurl:s" => { name => 'proxyurl' }, + "timeout:s" => { name => 'timeout', default => 5 }, + }); + $self->{statefile_value} = centreon::plugins::statefile->new(%options); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); + + foreach my $key (('fpm')) { + foreach (keys %{$maps_counters->{$key}}) { + my ($id, $name) = split /_/; + if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $name . ':s' => { name => 'warning-' . $name }, + 'critical-' . $name . ':s' => { name => 'critical-' . $name }, + }); + } + $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value}, + output => $self->{output}, perfdata => $self->{perfdata}, + label => $name); + $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); + } + } + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + foreach my $key (('fpm')) { + foreach (keys %{$maps_counters->{$key}}) { + $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); + } + } + + $self->{statefile_value}->check_options(%options); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub run { + my ($self, %options) = @_; + $self->{webcontent} = $self->{http}->request(); + + $self->manage_selection(); + + $self->{new_datas} = {}; + $self->{statefile_value}->read(statefile => "php_fpm_" . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); + $self->{new_datas}->{last_timestamp} = time(); + + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits; + + foreach (sort keys %{$maps_counters->{fpm}}) { + my $obj = $maps_counters->{fpm}->{$_}->{obj}; + + $obj->set(instance => 'fpm'); + + my ($value_check) = $obj->execute(values => $self->{fpm}, + new_datas => $self->{new_datas}); + + if ($value_check != 0) { + $long_msg .= $long_msg_append . $obj->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $obj->threshold_check(); + push @exits, $exit2; + + my $output = $obj->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $obj->perfdata(); + } + + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => "php-fpm $short_msg" + ); + } else { + $self->{output}->output_add(short_msg => "php-fpm $long_msg"); + } + + $self->{statefile_value}->write(data => $self->{new_datas}); + $self->{output}->display(); + $self->{output}->exit(); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{fpm} = { request => undef, listen_queue => undef, max_listen_queue => undef, + idle => undef, active => undef, total => undef }; + $self->{fpm}->{request} = $1 if ($self->{webcontent} =~ /accepted\s+conn:\s+(\d+)/msi); + $self->{fpm}->{listen_queue} = $1 if ($self->{webcontent} =~ /listen\s+queue:\s+(\d+)/msi); + $self->{fpm}->{max_listen_queue} = $1 if ($self->{webcontent} =~ /max\s+listen\s+queue:\s+(\d+)/msi); + $self->{fpm}->{idle} = $1 if ($self->{webcontent} =~ /idle\s+processes:\s+(\d+)/msi); + $self->{fpm}->{active} = $1 if ($self->{webcontent} =~ /active\s+processes:\s+(\d+)/msi); + $self->{fpm}->{total} = $1 if ($self->{webcontent} =~ /total\s+processes:\s+(\d+)/msi); +} + +1; + +__END__ + +=head1 MODE + +Check php-fpm usage. + +=over 8 + +=item B<--hostname> + +IP Addr/FQDN of the webserver host + +=item B<--port> + +Port used by web server + +=item B<--proxyurl> + +Proxy URL if any + +=item B<--proto> + +Specify https if needed + +=item B<--urlpath> + +Set path to get server-status page in auto mode (Default: '/fpm-status') + +=item B<--credentials> + +Specify this option if you access server-status page over basic authentification + +=item B<--username> + +Specify username for basic authentification (Mandatory if --credentials is specidied) + +=item B<--password> + +Specify password for basic authentification (Mandatory if --credentials is specidied) + +=item B<--timeout> + +Threshold for HTTP timeout (Default: 5) + +=item B<--warning-*> + +Threshold warning. +Can be: 'active-processes' (%), 'idle-processes' (%), +'listen-queue', 'requests'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'active-processes' (%), 'idle-processes' (%), +'listen-queue', 'requests'. + +=back + +=cut diff --git a/apps/php/fpm/web/plugin.pm b/apps/php/fpm/web/plugin.pm new file mode 100644 index 000000000..73e76f92f --- /dev/null +++ b/apps/php/fpm/web/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2015 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::php::fpm::web::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_simple); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'usage' => 'apps::php::fpm::web::mode::usage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check php-fpm module through the webpage. + +=cut diff --git a/apps/protocols/http/mode/expectedcontent.pm b/apps/protocols/http/mode/expectedcontent.pm index c28f145f0..cd818c741 100644 --- a/apps/protocols/http/mode/expectedcontent.pm +++ b/apps/protocols/http/mode/expectedcontent.pm @@ -24,7 +24,8 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; +use Time::HiRes qw(gettimeofday tv_interval); sub new { my ($class, %options) = @_; @@ -35,23 +36,38 @@ sub new { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, + "http-peer-addr:s" => { name => 'http_peer_addr' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, - "urlpath:s" => { name => 'url_path', default => "/" }, + "method:s" => { name => 'method' }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, "expected-string:s" => { name => 'expected_string' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, + "no-follow" => { name => 'no_follow', }, "ssl:s" => { name => 'ssl', }, "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' }, + "header:s@" => { name => 'header' }, + "get-param:s@" => { name => 'get_param' }, + "post-param:s@" => { name => 'post_param' }, + "cookies-file:s" => { name => 'cookies_file' }, + "unknown-status:s" => { name => 'unknown_status' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "warning-size:s" => { name => 'warning_size' }, + "critical-size:s" => { name => 'critical_size' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -59,36 +75,36 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "You need to specify hostname."); - $self->{output}->option_exit(); - } if (!defined($self->{option_results}->{expected_string})) { $self->{output}->add_option_msg(short_msg => "You need to specify --expected-string option."); $self->{output}->option_exit(); } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); + 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 ((!defined($self->{option_results}->{credentials})) && (defined($self->{option_results}->{ntlm}))) { - $self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option"); + 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(); } - if ((defined($self->{option_results}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used"); + if (($self->{perfdata}->threshold_validate(label => 'warning-size', value => $self->{option_results}->{warning_size})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-size threshold '" . $self->{option_results}->{warning_size} . "'."); $self->{output}->option_exit(); } + if (($self->{perfdata}->threshold_validate(label => 'critical-size', value => $self->{option_results}->{critical_size})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-size threshold '" . $self->{option_results}->{critical_size} . "'."); + $self->{output}->option_exit(); + } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - if (!defined($self->{option_results}->{port})) { - $self->{option_results}->{port} = centreon::plugins::httplib::get_port($self); - } - - my $webcontent = centreon::plugins::httplib::connect($self); + my $timing0 = [gettimeofday]; + my $webcontent = $self->{http}->request(); + my $timeelapsed = tv_interval($timing0, [gettimeofday]); + $self->{output}->output_add(long_msg => $webcontent); if ($webcontent =~ /$self->{option_results}->{expected_string}/mi) { @@ -98,6 +114,37 @@ sub run { $self->{output}->output_add(severity => 'CRITICAL', short_msg => sprintf("'%s' is not present in content.", $self->{option_results}->{expected_string})); } + + # Time check + my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_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'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + # Size check + { + require bytes; + + my $content_size = bytes::length($webcontent); + $exit = $self->{perfdata}->threshold_check(value => $content_size, + threshold => [ { label => 'critical-size', exit_litteral => 'critical' }, { label => 'warning-size', exit_litteral => 'warning' } ]); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Content size : %s", $content_size)); + } + $self->{output}->perfdata_add(label => "size", unit => 'B', + value => $content_size, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-size'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-size'), + min => 0); + } + $self->{output}->display(); $self->{output}->exit(); } @@ -116,6 +163,10 @@ Check Webpage content IP Addr/FQDN of the Webserver host +=item B<--http-peer-addr> + +Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve) + =item B<--port> Port used by Webserver @@ -124,9 +175,13 @@ Port used by Webserver Proxy URL if any +=item B<--method> + +Specify http method used (Default: 'GET') + =item B<--proto> -Specify https if needed +Specify https if needed (Default: 'http') =item B<--urlpath> @@ -150,7 +205,11 @@ Specify password for basic authentification (Mandatory if --credentials is speci =item B<--timeout> -Threshold for HTTP timeout +Threshold for HTTP timeout (Default: 5) + +=item B<--no-follow> + +Do not follow http redirect =item B<--ssl> @@ -176,6 +235,50 @@ Specify certificate's password Specify type of certificate (PKCS12) +=item B<--header> + +Set HTTP headers (Multiple option) + +=item B<--get-param> + +Set GET params (Multiple option. Example: --get-param='key=value') + +=item B<--post-param> + +Set POST params (Multiple option. Example: --post-param='key=value') + +=item B<--cookies-file> + +Save cookies in a file (Example: '/tmp/lwp_cookies.dat') + +=item B<--unknown-status> + +Threshold warning for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300') + +=item B<--warning-status> + +Threshold warning for http response code + +=item B<--critical-status> + +Threshold critical for http response code + +=item B<--warning> + +Threshold warning in seconds (Webpage response time) + +=item B<--critical> + +Threshold critical in seconds (Webpage response time) + +=item B<--warning-size> + +Threshold warning for content size + +=item B<--critical-size> + +Threshold critical for content size + =item B<--expected-string> Specify String to check on the Webpage diff --git a/apps/protocols/http/mode/jsoncontent.pm b/apps/protocols/http/mode/jsoncontent.pm index 4341f2ea0..ae858f6a4 100644 --- a/apps/protocols/http/mode/jsoncontent.pm +++ b/apps/protocols/http/mode/jsoncontent.pm @@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use Time::HiRes qw(gettimeofday tv_interval); -use centreon::plugins::httplib; +use centreon::plugins::http; use JSON::Path; use JSON; @@ -40,9 +40,11 @@ sub new { "data:s" => { name => 'data' }, "lookup:s@" => { name => 'lookup' }, "hostname:s" => { name => 'hostname' }, + "http-peer-addr:s" => { name => 'http_peer_addr' }, + "vhost:s" => { name => 'vhost' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, - "urlpath:s" => { name => 'url_path', default => "/" }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, "username:s" => { name => 'username' }, @@ -57,6 +59,9 @@ sub new { "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' }, @@ -80,6 +85,7 @@ sub new { $self->{values_string_ok} = []; $self->{values_string_warning} = []; $self->{values_string_critical} = []; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -106,47 +112,8 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical-time threshold '" . $self->{option_results}->{critical_time} . "'."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "You need to specify hostname."); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - if ((!defined($self->{option_results}->{credentials})) && (defined($self->{option_results}->{ntlm}))) { - $self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used"); - $self->{output}->option_exit(); - } - $self->{headers} = {}; - if (defined($self->{option_results}->{header})) { - foreach (@{$self->{option_results}->{header}}) { - if (/^(.*?):(.*)/) { - $self->{headers}->{$1} = $2; - } - } - } - $self->{get_params} = {}; - if (defined($self->{option_results}->{get_param})) { - foreach (@{$self->{option_results}->{get_param}}) { - if (/^([^=]+)={0,1}(.*)$/) { - my $key = $1; - my $value = defined($2) ? $2 : 1; - if (defined($self->{get_params}->{$key})) { - if (ref($self->{get_params}->{$key}) ne 'ARRAY') { - $self->{get_params}->{$key} = [ $self->{get_params}->{$key} ]; - } - push @{$self->{get_params}->{$key}}, $value; - } else { - $self->{get_params}->{$key} = $value; - } - } - } - } + + $self->{http}->set_options(%{$self->{option_results}}); } sub load_request { @@ -265,14 +232,10 @@ sub lookup { sub run { my ($self, %options) = @_; - if (!defined($self->{option_results}->{port})) { - $self->{option_results}->{port} = centreon::plugins::httplib::get_port($self); - } $self->load_request(); my $timing0 = [gettimeofday]; - $self->{json_response} = centreon::plugins::httplib::connect($self, headers => $self->{headers}, method => $self->{method}, - query_form_get => $self->{get_params}, query_form_post => $self->{json_request}); + $self->{json_response} = $self->{http}->request(method => $self->{method}, query_form_post => $self->{json_request}); my $timeelapsed = tv_interval ($timing0, [gettimeofday]); $self->{output}->output_add(long_msg => $self->{json_response}); @@ -395,6 +358,10 @@ HTTP OPTIONS: IP Addr/FQDN of the Webserver host +=item B<--http-peer-addr> + +Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve) + =item B<--port> Port used by Webserver @@ -463,6 +430,18 @@ Set GET params (Multiple option. Example: --get-param='key=value') Set HTTP headers (Multiple option. Example: --header='Content-Type: xxxxx') +=item B<--unknown-status> + +Threshold warning for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300') + +=item B<--warning-status> + +Threshold warning for http response code + +=item B<--critical-status> + +Threshold critical for http response code + =back =cut diff --git a/apps/protocols/http/mode/responsetime.pm b/apps/protocols/http/mode/response.pm similarity index 53% rename from apps/protocols/http/mode/responsetime.pm rename to apps/protocols/http/mode/response.pm index d709b9664..f9cada349 100644 --- a/apps/protocols/http/mode/responsetime.pm +++ b/apps/protocols/http/mode/response.pm @@ -18,14 +18,14 @@ # limitations under the License. # -package apps::protocols::http::mode::responsetime; +package apps::protocols::http::mode::response; use base qw(centreon::plugins::mode); use strict; use warnings; use Time::HiRes qw(gettimeofday tv_interval); -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -36,24 +36,38 @@ sub new { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, + "http-peer-addr:s" => { name => 'http_peer_addr' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, - "urlpath:s" => { name => 'url_path', default => "/" }, + "method:s" => { name => 'method' }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, + "no-follow" => { name => 'no_follow', }, "ssl:s" => { name => 'ssl' }, "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' }, + "header:s@" => { name => 'header' }, + "get-param:s@" => { name => 'get_param' }, + "post-param:s@" => { name => 'post_param' }, + "cookies-file:s" => { name => 'cookies_file' }, + "unknown-status:s" => { name => 'unknown_status', default => '' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{http_code} < 200 or %{http_code} >= 300' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "warning-size:s" => { name => 'warning_size' }, + "critical-size:s" => { name => 'critical_size' }, }); + + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -69,38 +83,24 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); + if (($self->{perfdata}->threshold_validate(label => 'warning-size', value => $self->{option_results}->{warning_size})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-size threshold '" . $self->{option_results}->{warning_size} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-size', value => $self->{option_results}->{critical_size})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-size threshold '" . $self->{option_results}->{critical_size} . "'."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - if (!defined($self->{option_results}->{port})) { - $self->{option_results}->{port} = centreon::plugins::httplib::get_port($self); - } - my $timing0 = [gettimeofday]; - - my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical'); - - my $timeelapsed = tv_interval ($timing0, [gettimeofday]); + my $webcontent = $self->{http}->request(); + my $timeelapsed = tv_interval($timing0, [gettimeofday]); $self->{output}->output_add(long_msg => $webcontent); @@ -108,11 +108,29 @@ sub run { threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, short_msg => sprintf("Response time %.3fs", $timeelapsed)); - $self->{output}->perfdata_add(label => "time", + $self->{output}->perfdata_add(label => "time", unit => 's', value => sprintf('%.3f', $timeelapsed), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); - + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + # Size check + { + require bytes; + + my $content_size = bytes::length($webcontent); + $exit = $self->{perfdata}->threshold_check(value => $content_size, + threshold => [ { label => 'critical-size', exit_litteral => 'critical' }, { label => 'warning-size', exit_litteral => 'warning' } ]); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Content size : %s", $content_size)); + } + $self->{output}->perfdata_add(label => "size", unit => 'B', + value => $content_size, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-size'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-size'), + min => 0); + } + $self->{output}->display(); $self->{output}->exit(); } @@ -123,7 +141,7 @@ __END__ =head1 MODE -Check Webpage Time Response +Check Webpage response and size. =over 8 @@ -131,13 +149,21 @@ Check Webpage Time Response IP Addr/FQDN of the webserver host +=item B<--http-peer-addr> + +Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve) + =item B<--port> Port used by Webserver +=item B<--method> + +Specify http method used (Default: 'GET') + =item B<--proto> -Specify https if needed +Specify https if needed (Default: 'http') =item B<--urlpath> @@ -165,20 +191,16 @@ Proxy URL if any =item B<--timeout> -Threshold for HTTP timeout +Threshold for HTTP timeout (Default: 5) + +=item B<--no-follow> + +Do not follow http redirect =item B<--ssl> Specify SSL version (example : 'sslv3', 'tlsv1'...) -=item B<--warning> - -Threshold warning in seconds (Webpage response time) - -=item B<--critical> - -Threshold critical in seconds (Webpage response time) - =item B<--cert-file> Specify certificate to send to the webserver @@ -199,6 +221,42 @@ Specify certificate's password Specify type of certificate (PKCS12) +=item B<--header> + +Set HTTP headers (Multiple option) + +=item B<--get-param> + +Set GET params (Multiple option. Example: --get-param='key=value') + +=item B<--post-param> + +Set POST params (Multiple option. Example: --post-param='key=value') + +=item B<--cookies-file> + +Save cookies in a file (Example: '/tmp/lwp_cookies.dat') + +=item B<--unknown-status> + +Threshold warning for http response code + +=item B<--warning-status> + +Threshold warning for http response code + +=item B<--critical-status> + +Threshold critical for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300') + +=item B<--warning> + +Threshold warning in seconds (Webpage response time) + +=item B<--critical> + +Threshold critical in seconds (Webpage response time) + =back =cut diff --git a/apps/protocols/http/mode/soapcontent.pm b/apps/protocols/http/mode/soapcontent.pm index 4427be826..1c621049f 100644 --- a/apps/protocols/http/mode/soapcontent.pm +++ b/apps/protocols/http/mode/soapcontent.pm @@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use Time::HiRes qw(gettimeofday tv_interval); -use centreon::plugins::httplib; +use centreon::plugins::http; use XML::XPath; sub new { @@ -40,9 +40,11 @@ sub new { "data:s" => { name => 'data' }, "lookup:s@" => { name => 'lookup' }, "hostname:s" => { name => 'hostname' }, + "http-peer-addr:s" => { name => 'http_peer_addr' }, + "vhost:s" => { name => 'vhost' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, - "urlpath:s" => { name => 'url_path', default => "/" }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "ntlm" => { name => 'ntlm' }, "username:s" => { name => 'username' }, @@ -56,6 +58,9 @@ sub new { "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' }, @@ -79,6 +84,7 @@ sub new { $self->{values_string_ok} = []; $self->{values_string_warning} = []; $self->{values_string_critical} = []; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -113,31 +119,9 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "You need to specify data."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "You need to specify hostname."); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - if ((!defined($self->{option_results}->{credentials})) && (defined($self->{option_results}->{ntlm}))) { - $self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used"); - $self->{output}->option_exit(); - } - $self->{headers} = {}; - if (defined($self->{option_results}->{header})) { - foreach (@{$self->{option_results}->{header}}) { - if (/^(.*?):(.*)/) { - $self->{headers}->{$1} = $2; - } - } - } - $self->{headers}->{SOAPAction} = $self->{option_results}->{service_soap}; + + $self->{http}->set_options(%{$self->{option_results}}); + $self->{http}->add_header(key => 'SOAPAction', value => $self->{option_results}->{service_soap}); } sub load_request { @@ -257,13 +241,10 @@ sub lookup { sub run { my ($self, %options) = @_; - if (!defined($self->{option_results}->{port})) { - $self->{option_results}->{port} = centreon::plugins::httplib::get_port($self); - } $self->load_request(); my $timing0 = [gettimeofday]; - $self->{soap_response} = centreon::plugins::httplib::connect($self, headers => $self->{headers}, method => 'POST', query_form_post => $self->{soap_request}); + $self->{soap_response} = $self->{http}->request(method => 'POST', query_form_post => $self->{soap_request}); my $timeelapsed = tv_interval ($timing0, [gettimeofday]); $self->{output}->output_add(long_msg => $self->{soap_response}); @@ -390,6 +371,10 @@ HTTP OPTIONS: IP Addr/FQDN of the Webserver host +=item B<--http-peer-addr> + +Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve) + =item B<--port> Port used by Webserver @@ -454,6 +439,18 @@ Specify type of certificate (PKCS1 Set HTTP headers (Multiple option) +=item B<--unknown-status> + +Threshold warning for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300') + +=item B<--warning-status> + +Threshold warning for http response code + +=item B<--critical-status> + +Threshold critical for http response code + =back =cut diff --git a/apps/protocols/http/plugin.pm b/apps/protocols/http/plugin.pm index a5e0966ee..a9cd1079d 100644 --- a/apps/protocols/http/plugin.pm +++ b/apps/protocols/http/plugin.pm @@ -34,7 +34,7 @@ sub new { %{$self->{modes}} = ( 'expected-content' => 'apps::protocols::http::mode::expectedcontent', 'json-content' => 'apps::protocols::http::mode::jsoncontent', - 'response-time' => 'apps::protocols::http::mode::responsetime', + 'response' => 'apps::protocols::http::mode::response', 'soap-content' => 'apps::protocols::http::mode::soapcontent', ); diff --git a/apps/protocols/tcp/mode/responsetime.pm b/apps/protocols/tcp/mode/responsetime.pm index 304d5e7e4..e4194dde5 100644 --- a/apps/protocols/tcp/mode/responsetime.pm +++ b/apps/protocols/tcp/mode/responsetime.pm @@ -69,10 +69,6 @@ sub check_options { sub run { my ($self, %options) = @_; - - if (!defined($self->{option_results}->{port})) { - $self->{option_results}->{port} = centreon::plugins::httplib::get_port($self); - } my ($connection, $timing0, $timeelapsed); if (defined($self->{option_results}->{ssl})) { diff --git a/apps/protocols/udp/mode/connection.pm b/apps/protocols/udp/mode/connection.pm index f96dc1733..2228a8243 100644 --- a/apps/protocols/udp/mode/connection.pm +++ b/apps/protocols/udp/mode/connection.pm @@ -67,10 +67,6 @@ sub check_options { sub run { my ($self, %options) = @_; - if (!defined($self->{option_results}->{port})) { - $self->{option_results}->{port} = centreon::plugins::httplib::get_port($self); - } - my $icmp_sock = new IO::Socket::INET(Proto=>"icmp"); my $read_set = new IO::Select(); $read_set->add($icmp_sock); diff --git a/apps/protocols/x509/mode/validity.pm b/apps/protocols/x509/mode/validity.pm index 6c7ae201b..c4c124ebb 100644 --- a/apps/protocols/x509/mode/validity.pm +++ b/apps/protocols/x509/mode/validity.pm @@ -41,9 +41,9 @@ sub new { "validity-mode:s" => { name => 'validity_mode' }, "warning-date:s" => { name => 'warning' }, "critical-date:s" => { name => 'critical' }, - "subjectname:s" => { name => 'subjectname' }, - "issuername:s" => { name => 'issuername' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "subjectname:s" => { name => 'subjectname', default => '' }, + "issuername:s" => { name => 'issuername', default => '' }, + "timeout:s" => { name => 'timeout', default => 5 }, }); return $self; } @@ -68,11 +68,10 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Please set the port option"); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{validity_mode})) { - $self->{output}->add_option_msg(short_msg => "Please set the validity-mode option"); + if (!defined($self->{option_results}->{validity_mode}) || $self->{option_results}->{validity_mode} !~ /^expiration|subject|issuer$/) { + $self->{output}->add_option_msg(short_msg => "Please set the validity-mode option (issuer, subject or expiration)"); $self->{output}->option_exit(); } - } sub run { @@ -100,19 +99,19 @@ sub run { $self->{output}->display(); $self->{output}->exit() - }; + } #Create SSL connection Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL); eval { $ssl = Net::SSLeay::new($ctx) }; - if ($@) { + if ($@) { $self->{output}->output_add(severity => 'CRITICAL', short_msg => sprintf("%s", $!)); $self->{output}->display(); $self->{output}->exit() - }; + } eval { Net::SSLeay::set_fd($ssl, fileno($connection)) }; if ($@) { @@ -121,7 +120,7 @@ sub run { $self->{output}->display(); $self->{output}->exit() - }; + } eval { Net::SSLeay::connect($ssl) }; if ($@) { @@ -130,7 +129,7 @@ sub run { $self->{output}->display(); $self->{output}->exit() - }; + } #Retrieve Certificat $cert = Net::SSLeay::get_peer_certificate($ssl); @@ -150,12 +149,12 @@ sub run { #Subject Name } elsif ($self->{option_results}->{validity_mode} eq 'subject') { my $subject_name = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_subject_name($cert)); - if ( $subject_name =~ /$self->{option_results}->{subjectname}/mi ) { + if ($subject_name =~ /$self->{option_results}->{subjectname}/mi) { $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("Subject Name %s is present in Certificate :%s", $self->{option_results}->{subjectname}, $subject_name)); + short_msg => sprintf("Subject Name '%s' is present in Certificate: %s", $self->{option_results}->{subjectname}, $subject_name)); } else { $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Subject Name %s is not present in Certificate : %s", $self->{option_results}->{subjectname}, $subject_name)); + short_msg => sprintf("Subject Name '%s' is not present in Certificate: %s", $self->{option_results}->{subjectname}, $subject_name)); } $self->{output}->display(); @@ -164,19 +163,16 @@ sub run { #Issuer Name } elsif ($self->{option_results}->{validity_mode} eq 'issuer') { my $issuer_name = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_issuer_name($cert)); - if ( $issuer_name =~ /$self->{option_results}->{issuername}/mi ) { + if ($issuer_name =~ /$self->{option_results}->{issuername}/mi) { $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("Issuer Name %s is present in Certificate :%s", $self->{option_results}->{issuername}, $issuer_name)); + short_msg => sprintf("Issuer Name '%s' is present in Certificate: %s", $self->{option_results}->{issuername}, $issuer_name)); } else { $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Issuer Name %s is not present in Certificate : %s", $self->{option_results}->{issuername}, $issuer_name)); + short_msg => sprintf("Issuer Name '%s' is not present in Certificate: %s", $self->{option_results}->{issuername}, $issuer_name)); } $self->{output}->display(); $self->{output}->exit() - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find validity-mode '" . $self->{option_results}->{validity_mode} . "'."); - $self->{output}->option_exit(); } } } diff --git a/apps/tomcat/web/mode/applications.pm b/apps/tomcat/web/mode/applications.pm index 44aec60de..d6aafb2fb 100644 --- a/apps/tomcat/web/mode/applications.pm +++ b/apps/tomcat/web/mode/applications.pm @@ -23,7 +23,7 @@ package apps::tomcat::web::mode::applications; use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -35,12 +35,12 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, "urlpath:s" => { name => 'url_path', default => '/manager/text/list' }, "name:s" => { name => 'name' }, "regexp" => { name => 'use_regexp' }, @@ -49,7 +49,7 @@ sub new { }); $self->{result} = {}; - $self->{hostname} = undef; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -57,27 +57,15 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - + $self->{http}->set_options(%{$self->{option_results}}); } sub manage_selection { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); - while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) { + while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) { my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4); next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' && diff --git a/apps/tomcat/web/mode/listapplication.pm b/apps/tomcat/web/mode/listapplication.pm index df5233eb4..da7a45b36 100644 --- a/apps/tomcat/web/mode/listapplication.pm +++ b/apps/tomcat/web/mode/listapplication.pm @@ -23,7 +23,7 @@ package apps::tomcat::web::mode::listapplication; use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -35,12 +35,12 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "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', }, @@ -48,7 +48,7 @@ sub new { }); $self->{result} = {}; - $self->{hostname} = undef; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -56,25 +56,13 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } - + $self->{http}->set_options(%{$self->{option_results}}); } sub manage_selection { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) { my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4); diff --git a/apps/tomcat/web/mode/memory.pm b/apps/tomcat/web/mode/memory.pm index 2fb4d99e1..1a53a8189 100644 --- a/apps/tomcat/web/mode/memory.pm +++ b/apps/tomcat/web/mode/memory.pm @@ -23,7 +23,7 @@ package apps::tomcat::web::mode::memory; use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use XML::XPath; sub new { @@ -36,38 +36,26 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, "urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, }); $self->{result} = {}; - $self->{hostname} = undef; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + 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(); @@ -77,6 +65,7 @@ sub check_options { $self->{output}->option_exit(); } + $self->{http}->set_options(%{$self->{option_results}}); } my %xpath_to_check = ( @@ -88,7 +77,7 @@ my %xpath_to_check = ( sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my $port = $self->{option_results}->{port}; #EXAMPLE 1: diff --git a/apps/tomcat/web/mode/requestinfo.pm b/apps/tomcat/web/mode/requestinfo.pm index 90507542f..ca2a7f689 100644 --- a/apps/tomcat/web/mode/requestinfo.pm +++ b/apps/tomcat/web/mode/requestinfo.pm @@ -23,7 +23,7 @@ package apps::tomcat::web::mode::requestinfo; use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex); use XML::XPath; @@ -39,12 +39,12 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, "urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' }, "name:s" => { name => 'name' }, "regexp" => { name => 'use_regexp' }, @@ -62,6 +62,7 @@ sub new { $self->{result} = {}; $self->{hostname} = undef; $self->{statefile_value} = centreon::plugins::statefile->new(%options); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -69,18 +70,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } #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} . "'."); @@ -123,6 +112,8 @@ sub check_options { if (!defined($self->{hostname})) { $self->{hostname} = 'me'; } + + $self->{http}->set_options(%{$self->{option_results}}); } my %xpath_to_check = ( @@ -135,7 +126,7 @@ my %xpath_to_check = ( sub manage_selection { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my $port = $self->{option_results}->{port}; #EXAMPLE 1: @@ -207,12 +198,12 @@ sub manage_selection { }; 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(); + 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(); }; }; }; @@ -223,7 +214,7 @@ sub run { $self->manage_selection(); my $new_datas = {}; - $self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all'))); + $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'); diff --git a/apps/tomcat/web/mode/sessions.pm b/apps/tomcat/web/mode/sessions.pm index 57b52f278..e990e0063 100644 --- a/apps/tomcat/web/mode/sessions.pm +++ b/apps/tomcat/web/mode/sessions.pm @@ -23,7 +23,7 @@ package apps::tomcat::web::mode::sessions; use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -35,12 +35,12 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, "urlpath:s" => { name => 'url_path', default => '/manager/text/list' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, @@ -52,7 +52,7 @@ sub new { }); $self->{result} = {}; - $self->{hostname} = undef; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -60,18 +60,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } 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(); @@ -80,15 +68,15 @@ sub check_options { $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 = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); - while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) { + while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) { my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4); next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' && diff --git a/apps/tomcat/web/mode/threads.pm b/apps/tomcat/web/mode/threads.pm index d9d7da242..e9d6e1462 100644 --- a/apps/tomcat/web/mode/threads.pm +++ b/apps/tomcat/web/mode/threads.pm @@ -23,7 +23,7 @@ package apps::tomcat::web::mode::threads; use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use XML::XPath; use URI::Escape; @@ -37,12 +37,12 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, "urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, @@ -53,6 +53,7 @@ sub new { $self->{result} = {}; $self->{hostname} = undef; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -60,18 +61,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } 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(); @@ -81,6 +70,7 @@ sub check_options { $self->{output}->option_exit(); } + $self->{http}->set_options(%{$self->{option_results}}); } my %xpath_to_check = ( @@ -92,7 +82,7 @@ my %xpath_to_check = ( sub manage_selection { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my $port = $self->{option_results}->{port}; #EXAMPLE 1: diff --git a/apps/tomcat/web/mode/traffic.pm b/apps/tomcat/web/mode/traffic.pm index a5d770456..219286a7a 100644 --- a/apps/tomcat/web/mode/traffic.pm +++ b/apps/tomcat/web/mode/traffic.pm @@ -23,7 +23,7 @@ package apps::tomcat::web::mode::traffic; use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex); use XML::XPath; @@ -39,12 +39,12 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '8080' }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, "urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' }, "name:s" => { name => 'name' }, "regexp" => { name => 'use_regexp' }, @@ -59,6 +59,7 @@ sub new { $self->{result} = {}; $self->{hostname} = undef; $self->{statefile_value} = centreon::plugins::statefile->new(%options); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -66,18 +67,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) { - $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } if (($self->{perfdata}->threshold_validate(label => 'warning-in', value => $self->{option_results}->{warning_in})) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong warning 'in' threshold '" . $self->{option_results}->{warning_in} . "'."); $self->{output}->option_exit(); @@ -109,6 +98,8 @@ sub check_options { if (!defined($self->{hostname})) { $self->{hostname} = 'me'; } + + $self->{http}->set_options(%{$self->{option_results}}); } my %xpath_to_check = ( @@ -119,7 +110,7 @@ my %xpath_to_check = ( sub manage_selection { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my $port = $self->{option_results}->{port}; #EXAMPLE 1: @@ -207,7 +198,7 @@ sub run { $self->manage_selection(); my $new_datas = {}; - $self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all'))); + $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'); diff --git a/apps/voip/cisco/meetingplace/plugin.pm b/apps/voip/cisco/meetingplace/plugin.pm index 01eedf3e7..e00141893 100644 --- a/apps/voip/cisco/meetingplace/plugin.pm +++ b/apps/voip/cisco/meetingplace/plugin.pm @@ -32,16 +32,15 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'snmp_standard::mode::cpu', - 'memory' => 'os::windows::snmp::mode::memory', - 'storage' => 'snmp_standard::mode::storage', - 'audio-ports' => 'apps::voip::cisco::meetingplace::mode::audioports', - 'video-ports' => 'apps::voip::cisco::meetingplace::mode::videoports', - 'audio-licenses' => 'apps::voip::cisco::meetingplace::mode::audiolicenses', - 'video-licenses' => 'apps::voip::cisco::meetingplace::mode::videolicenses', - 'packet-errors' => 'snmp_standard::mode::packeterrors', - 'traffic' => 'snmp_standard::mode::traffic', - ); + 'cpu' => 'snmp_standard::mode::cpu', + 'memory' => 'os::windows::snmp::mode::memory', + 'storage' => 'snmp_standard::mode::storage', + 'audio-ports' => 'apps::voip::cisco::meetingplace::mode::audioports', + 'video-ports' => 'apps::voip::cisco::meetingplace::mode::videoports', + 'audio-licenses' => 'apps::voip::cisco::meetingplace::mode::audiolicenses', + 'video-licenses' => 'apps::voip::cisco::meetingplace::mode::videolicenses', + 'interfaces' => 'snmp_standard::mode::interfaces', + ); return $self; } diff --git a/centreon/common/cisco/standard/snmp/mode/cpu.pm b/centreon/common/cisco/standard/snmp/mode/cpu.pm index 2e8eaf6da..6ecaa5c09 100644 --- a/centreon/common/cisco/standard/snmp/mode/cpu.pm +++ b/centreon/common/cisco/standard/snmp/mode/cpu.pm @@ -86,7 +86,10 @@ sub check_table_cpu { my $cpu5sec = defined($self->{results}->{$options{entry}}->{$options{sec5} . '.' . $instance}) ? sprintf("%.2f", $self->{results}->{$options{entry}}->{$options{sec5} . '.' . $instance}) : undef; my $cpu1min = defined($self->{results}->{$options{entry}}->{$options{min1} . '.' . $instance}) ? sprintf("%.2f", $self->{results}->{$options{entry}}->{$options{min1} . '.' . $instance}) : undef; my $cpu5min = defined($self->{results}->{$options{entry}}->{$options{min5} . '.' . $instance}) ? sprintf("%.2f", $self->{results}->{$options{entry}}->{$options{min5} . '.' . $instance}) : undef; - + + # Case that it's maybe other CPU oid in table for datas. + next if (!defined($cpu5sec) && !defined($cpu1min) && !defined($cpu5min)); + $checked = 1; my @exits; push @exits, $self->{perfdata}->threshold_check(value => $cpu5sec, diff --git a/centreon/common/protocols/jmx/custom/jolokia.pm b/centreon/common/protocols/jmx/custom/jolokia.pm index 46d1a5398..9667328f5 100644 --- a/centreon/common/protocols/jmx/custom/jolokia.pm +++ b/centreon/common/protocols/jmx/custom/jolokia.pm @@ -203,7 +203,7 @@ sub get_attributes { $j < scalar(@{$options{request}->[$i]->{attributes}}); $j++, $pos++) { if ($responses[$pos]->is_error()) { # 500-599 an error. 400 is an attribute not present - if ($responses[$pos]->status() >= 500) { + if ($responses[$pos]->status() >= 500 || $responses[$pos]->status() == 401) { $self->{output}->add_option_msg(short_msg => "protocol issue: " . $responses[$pos]->error_text()); $self->{output}->option_exit(); } diff --git a/centreon/plugins/http.pm b/centreon/plugins/http.pm new file mode 100644 index 000000000..ff9b96b9e --- /dev/null +++ b/centreon/plugins/http.pm @@ -0,0 +1,282 @@ +# +# Copyright 2015 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::http; + +use strict; +use warnings; +use centreon::plugins::misc; +use LWP::UserAgent; +use HTTP::Cookies; +use URI; +use IO::Socket::SSL; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + $self->{output} = $options{output}; + $self->{ua} = undef; + $self->{options} = { + proto => 'http', + url_path => '/', + timeout => 5, + method => 'GET', + unknown_status => '%{http_code} < 200 or %{http_code} >= 300', + warning_status => undef, + critical_status => undef, + }; + $self->{add_headers} = {}; + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{options} = { %{$self->{options}} }; + foreach (keys %options) { + $self->{options}->{$_} = $options{$_} if (defined($options{$_})); + } +} + +sub add_header { + my ($self, %options) = @_; + + $self->{add_headers}->{$options{key}} = $options{value}; +} + +sub check_options { + my ($self, %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(); + } + if (!defined($options{request}->{hostname})) { + $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); + $self->{output}->option_exit(); + } + if ((defined($options{request}->{credentials})) && (!defined($options{request}->{username}) || !defined($options{request}->{password}))) { + $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); + $self->{output}->option_exit(); + } + if ((defined($options{request}->{pkcs12})) && (!defined($options{request}->{cert_file}) && !defined($options{request}->{cert_pwd}))) { + $self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used"); + $self->{output}->option_exit(); + } + + $options{request}->{port} = $self->get_port_request(); + + $options{request}->{headers} = {}; + if (defined($options{request}->{header})) { + foreach (@{$options{request}->{header}}) { + if (/^(.*?):(.*)/) { + $options{request}->{headers}->{$1} = $2; + } + } + } + foreach (keys %{$self->{add_headers}}) { + $options{request}->{headers}->{$_} = $self->{add_headers}->{$_}; + } + + foreach my $method (('get', 'post')) { + if (defined($options{request}->{$method . '_param'})) { + $self->{$method . '_params'} = {}; + foreach (@{$options{request}->{$method . '_param'}}) { + if (/^([^=]+)={0,1}(.*)$/) { + my $key = $1; + my $value = defined($2) ? $2 : 1; + if (defined($self->{$method . '_params'}->{$key})) { + if (ref($self->{$method . '_params'}->{$key}) ne 'ARRAY') { + $self->{$method . '_params'}->{$key} = [ $self->{$method . '_params'}->{$key} ]; + } + push @{$self->{$method . '_params'}->{$key}}, $value; + } else { + $self->{$method . '_params'}->{$key} = $value; + } + } + } + } + } + + foreach (('unknown_status', 'warning_status', 'critical_status')) { + if (defined($options{request}->{$_})) { + $options{request}->{$_} =~ s/%\{http_code\}/\$response->code/g; + } + } +} + +sub get_port { + my ($self, %options) = @_; + + my $port = ''; + if (defined($self->{options}->{port}) && $self->{options}->{port} ne '') { + $port = $self->{options}->{port}; + } else { + $port = 80 if ($self->{options}->{proto} eq 'http'); + $port = 443 if ($self->{options}->{proto} eq 'https'); + } + + return $port; +} + +sub get_port_request { + my ($self, %options) = @_; + + my $port = ''; + if (defined($self->{options}->{port}) && $self->{options}->{port} ne '') { + $port = $self->{options}->{port}; + } + return $port; +} + +sub request { + my ($self, %options) = @_; + + my $request_options = { %{$self->{options}} }; + foreach (keys %options) { + $request_options->{$_} = $options{$_} if (defined($options{$_})); + } + $self->check_options(request => $request_options); + + if (!defined($self->{ua})) { + $self->{ua} = LWP::UserAgent->new(keep_alive => 1, protocols_allowed => ['http', 'https'], timeout => $request_options->{timeout}); + if (defined($request_options->{cookies_file})) { + $self->{ua}->cookie_jar(HTTP::Cookies->new(file => $request_options->{cookies_file}, + autosave => 1)); + } + } + if (defined($request_options->{no_follow})) { + $self->{ua}->requests_redirectable(undef); + } else { + $self->{ua}->requests_redirectable([ 'GET', 'HEAD', 'POST' ]); + } + if (defined($request_options->{http_peer_addr})) { + push @LWP::Protocol::http::EXTRA_SOCK_OPTS, PeerAddr => $request_options->{http_peer_addr}; + } + + my ($response, $content); + my ($req, $url); + if (defined($request_options->{port}) && $request_options->{port} =~ /^[0-9]+$/) { + $url = $request_options->{proto}. "://" . $request_options->{hostname} . ':' . $request_options->{port} . $request_options->{url_path}; + } else { + $url = $request_options->{proto}. "://" . $request_options->{hostname} . $request_options->{url_path}; + } + + my $uri = URI->new($url); + if (defined($self->{get_params})) { + $uri->query_form($self->{get_params}); + } + $req = HTTP::Request->new($request_options->{method}, $uri); + + my $content_type_forced; + foreach my $key (keys %{$request_options->{headers}}) { + if ($key !~ /content-type/i) { + $req->header($key => $request_options->{headers}->{$key}); + } else { + $content_type_forced = $request_options->{headers}->{$key}; + } + } + + if ($request_options->{method} eq 'POST') { + if (defined($content_type_forced)) { + $req->content_type($content_type_forced); + $req->content($request_options->{query_form_post}); + } else { + my $uri_post = URI->new(); + if (defined($self->{post_params})) { + $uri_post->query_form($self->{post_params}); + } + $req->content_type('application/x-www-form-urlencoded'); + $req->content($uri_post->query); + } + } + + if (defined($request_options->{credentials}) && defined($request_options->{ntlm})) { + $self->{ua}->credentials($request_options->{hostname} . ':' . $request_options->{port}, '', $request_options->{username}, $request_options->{password}); + } elsif (defined($request_options->{credentials})) { + $req->authorization_basic($request_options->{username}, $request_options->{password}); + } + + if (defined($request_options->{proxyurl})) { + $self->{ua}->proxy(['http', 'https'], $request_options->{proxyurl}); + } + + if (defined($request_options->{cert_pkcs12}) && $request_options->{cert_file} ne '' && $request_options->{cert_pwd} ne '') { + eval "use Net::SSL"; die $@ if $@; + $ENV{HTTPS_PKCS12_FILE} = $request_options->{cert_file}; + $ENV{HTTPS_PKCS12_PASSWORD} = $request_options->{cert_pwd}; + } + + my $ssl_context; + if (defined($request_options->{ssl}) && $request_options->{ssl} ne '') { + $ssl_context = { SSL_version => $request_options->{ssl} }; + } + if (defined($request_options->{cert_file}) && !defined($request_options->{cert_pkcs12})) { + $ssl_context = {} if (!defined($ssl_context)); + $ssl_context->{SSL_use_cert} = 1; + $ssl_context->{SSL_cert_file} = $request_options->{cert_file}; + $ssl_context->{SSL_key_file} = $request_options->{key_file} if (defined($request_options->{key_file})); + $ssl_context->{SSL_ca_file} = $request_options->{cacert_file} if (defined($request_options->{cacert_file})); + } + + if (defined($ssl_context)) { + my $context = new IO::Socket::SSL::SSL_Context(%{$ssl_context}); + IO::Socket::SSL::set_default_context($context); + } + + $response = $self->{ua}->request($req); + + # Check response + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($request_options->{critical_status}) && $request_options->{critical_status} ne '' && + eval "$request_options->{critical_status}") { + $status = 'critical'; + } elsif (defined($request_options->{warning_status}) && $request_options->{warning_status} ne '' && + eval "$request_options->{warning_status}") { + $status = 'warning'; + } elsif (defined($request_options->{unknown_status}) && $request_options->{unknown_status} ne '' && + eval "$request_options->{unknown_status}") { + $status = 'unknown'; + } + }; + if (defined($message)) { + $self->{output}->add_option_msg(short_msg => 'filter status issue: ' . $message); + $self->{output}->option_exit(); + } + + if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $status, + short_msg => $response->status_line); + $self->{output}->display(); + $self->{output}->exit(); + } + + return $response->content; +} + +1; diff --git a/centreon/plugins/httplib.pm b/centreon/plugins/httplib.pm deleted file mode 100644 index 7600d7bd1..000000000 --- a/centreon/plugins/httplib.pm +++ /dev/null @@ -1,141 +0,0 @@ -# -# Copyright 2015 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::httplib; - -use strict; -use warnings; -use LWP::UserAgent; -use HTTP::Cookies; -use URI; -use IO::Socket::SSL; - -sub get_port { - my ($self, %options) = @_; - - my $cache_port = ''; - if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} ne '') { - $cache_port = $self->{option_results}->{port}; - } else { - $cache_port = 80 if ($self->{option_results}->{proto} eq 'http'); - $cache_port = 443 if ($self->{option_results}->{proto} eq 'https'); - } - - return $cache_port; -} - -sub connect { - my ($self, %options) = @_; - my $method = defined($options{method}) ? $options{method} : 'GET'; - my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown'; - - my $ua = LWP::UserAgent->new(keep_alive => 1, protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout}, - requests_redirectable => [ 'GET', 'HEAD', 'POST' ]); - if (defined($options{cookies_file})) { - $ua->cookie_jar(HTTP::Cookies->new(file => $options{cookies_file}, - autosave => 1)); - } - - my ($response, $content); - my ($req, $url); - if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} =~ /^[0-9]+$/) { - $url = $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname}.':'. $self->{option_results}->{port} . $self->{option_results}->{url_path}; - } else { - $url = $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname} . $self->{option_results}->{url_path}; - } - - my $uri = URI->new($url); - if (defined($options{query_form_get})) { - $uri->query_form($options{query_form_get}); - } - $req = HTTP::Request->new($method => $uri); - - my $content_type_forced; - if (defined($options{headers})) { - foreach my $key (keys %{$options{headers}}) { - if ($key !~ /content-type/i) { - $req->header($key => $options{headers}->{$key}); - } else { - $content_type_forced = $options{headers}->{$key}; - } - } - } - - if ($method eq 'POST') { - if (defined($content_type_forced)) { - $req->content_type($content_type_forced); - $req->content($options{query_form_post}); - } else { - my $uri_post = URI->new(); - if (defined($options{query_form_post})) { - $uri_post->query_form($options{query_form_post}); - } - $req->content_type('application/x-www-form-urlencoded'); - $req->content($uri_post->query); - } - } - - if (defined($self->{option_results}->{credentials}) && defined($self->{option_results}->{ntlm})) { - $ua->credentials($self->{option_results}->{hostname} . ':' . $self->{option_results}->{port}, '', $self->{option_results}->{username}, $self->{option_results}->{password}); - } elsif (defined($self->{option_results}->{credentials})) { - $req->authorization_basic($self->{option_results}->{username}, $self->{option_results}->{password}); - } - - if (defined($self->{option_results}->{proxyurl})) { - $ua->proxy(['http', 'https'], $self->{option_results}->{proxyurl}); - } - - if (defined($self->{option_results}->{cert_pkcs12}) && $self->{option_results}->{cert_file} ne '' && $self->{option_results}->{cert_pwd} ne '') { - eval "use Net::SSL"; die $@ if $@; - $ENV{HTTPS_PKCS12_FILE} = $self->{option_results}->{cert_file}; - $ENV{HTTPS_PKCS12_PASSWORD} = $self->{option_results}->{cert_pwd}; - } - - my $ssl_context; - if (defined($self->{option_results}->{ssl}) && $self->{option_results}->{ssl} ne '') { - $ssl_context = { SSL_version => $self->{option_results}->{ssl} }; - } - if (defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pkcs12})) { - $ssl_context = {} if (!defined($ssl_context)); - $ssl_context->{SSL_use_cert} = 1; - $ssl_context->{SSL_cert_file} = $self->{option_results}->{cert_file}; - $ssl_context->{SSL_key_file} = $self->{option_results}->{key_file} if (defined($self->{option_results}->{key_file})); - $ssl_context->{SSL_ca_file} = $self->{option_results}->{cacert_file} if (defined($self->{option_results}->{cacert_file})); - } - - if (defined($ssl_context)) { - my $context = new IO::Socket::SSL::SSL_Context(%{$ssl_context}); - IO::Socket::SSL::set_default_context($context); - } - - $response = $ua->request($req); - - if ($response->is_success) { - $content = $response->content; - return $content; - } - - $self->{output}->output_add(severity => $connection_exit, - short_msg => $response->status_line); - $self->{output}->display(); - $self->{output}->exit(); -} - -1; diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm index 26fc1fbfc..7139a6a68 100644 --- a/centreon/plugins/misc.pm +++ b/centreon/plugins/misc.pm @@ -318,13 +318,13 @@ sub powershell_escape { sub minimal_version { my ($version_src, $version_dst) = @_; - + # No Version. We skip if (!defined($version_src) || !defined($version_dst) || - $version_src !~ /^[0-9]+(?:\.[0-9\.])*$/ || $version_dst !~ /^[0-9x]+(?:\.[0-9x\.])*$/) { + $version_src !~ /^[0-9]+(?:\.[0-9\.]+)*$/ || $version_dst !~ /^[0-9x]+(?:\.[0-9x]+)*$/) { return 1; } - + my @version_src = split /\./, $version_src; my @versions = split /\./, $version_dst; for (my $i = 0; $i < scalar(@versions); $i++) { diff --git a/database/firebird/firebirdcmd.pm b/database/firebird/firebirdcmd.pm new file mode 100644 index 000000000..55c578c7c --- /dev/null +++ b/database/firebird/firebirdcmd.pm @@ -0,0 +1,338 @@ +# +# Copyright 2015 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::firebird::firebirdcmd; + +use strict; +use warnings; +use centreon::plugins::misc; +use Digest::MD5 qw(md5_hex); + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + # $options{options} = options object + # $options{output} = output object + # $options{exit_value} = integer + # $options{noptions} = integer + + if (!defined($options{output})) { + print "Class mysqlcmd: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Firebirdcmd: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => + { "firebird-cmd:s" => { name => 'firebird_cmd', default => '/opt/firebird/bin/isql' } + "host:s@" => { name => 'host' }, + "port:s@" => { name => 'port' }, + "username:s@" => { name => 'username' }, + "password:s@" => { name => 'password' }, + "dbname:s@" => { name => 'dbname' }, + "sql-errors-exit:s" => { name => 'sql_errors_exit', default => 'unknown' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'MYSQLCMD OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{args} = undef; + $self->{stdout} = undef; + $self->{columns} = undef; + $self->{version} = undef; + + $self->{host} = undef; + $self->{port} = undef; + $self->{dbname} = undef; + $self->{username} = undef; + $self->{password} = undef; + + return $self; +} + +# Method to manage multiples +sub set_options { + my ($self, %options) = @_; + # options{options_result} + + $self->{option_results} = $options{option_results}; +} + +# Method to manage multiples +sub set_defaults { + my ($self, %options) = @_; + # options{default} + + # Manage default value + 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) = @_; + # return 1 = ok still data_source + # return 0 = no data_source left + + $self->{host} = (defined($self->{option_results}->{host})) ? shift(@{$self->{option_results}->{host}}) : undef; + $self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : undef; + $self->{dbname} = (defined($self->{option_results}->{dbname})) ? shift(@{$self->{option_results}->{dbname}}) : undef; + $self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : undef; + $self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : undef; + $self->{sql_errors_exit} = $self->{option_results}->{sql_errors_exit}; + $self->{firebird_cmd} = $self->{option_results}->{firebird_cmd}; + + if (!defined($self->{host}) || $self->{host} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify host argument."); + $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); + } + + $self->{args} = ['--batch', '--raw', '--host', $self->{host}]; + if (defined($self->{port})) { + push @{$self->{args}}, "--port", $self->{port}; + } + if (defined($self->{username})) { + push @{$self->{args}}, "--user", $self->{username}; + } + if (defined($self->{password}) && $self->{password} ne '') { + push @{$self->{args}}, "-p" . $self->{password}; + } + if (defined($self->{dbname}) && $self->{dbnam} ne '') { + push @{$self->{args}}, "--dbname", $self->{dbname}; + } + + if (scalar(@{$self->{option_results}->{host}}) == 0) { + return 0; + } + return 1; +} + +sub is_version_minimum { + my ($self, %options) = @_; + # $options{version} = string version to check + + my @version_src = split /\./, $self->{version}; + my @versions = split /\./, $options{version}; + for (my $i = 0; $i < scalar(@versions); $i++) { + return 1 if ($versions[$i] eq 'x'); + return 1 if (!defined($version_src[$i])); + $version_src[$i] =~ /^([0-9]*)/; + next if ($versions[$i] == int($1)); + return 0 if ($versions[$i] > int($1)); + return 1 if ($versions[$i] < int($1)); + } + + return 1; +} + +sub get_id { + my ($self, %options) = @_; + + my $msg = $self->{host}; + if (defined($self->{port})) { + $msg .= ":" . $self->{port}; + } + return $msg; +} + + +sub get_unique_id4save { + my ($self, %options) = @_; + + my $msg = $self->{host}; + if (defined($self->{port})) { + $msg .= ":" . $self->{port}; + } + return md5_hex($msg); +} + +sub quote { + my $self = shift; + + return undef; +} + +sub command_execution { + my ($self, %options) = @_; + + my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick( + command => $self->{firebird_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', + short_msg => $stdout); + } + $self->{output}->display(); + $self->{output}->exit(); + } + + return ($exit_code, $stdout); +} + +# Connection initializer +sub connect { + my ($self, %options) = @_; + my $dontquit = (defined($options{dontquit}) && $options{dontquit} == 1) ? 1 : 0; + + (my $exit_code, $self->{stdout}) = $self->command_execution(request => "SHOW VERSION"); + if ($exit_code != 0) { + if ($dontquit == 0) { + $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}); + } + + my $row = $self->fetchrow_hashref(); + $self->{version} = $row->{Value}; + + return 0; +} + +sub fetchall_arrayref { + my ($self, %options) = @_; + my $array_ref = []; + + if (!defined($self->{columns})) { + $self->{stdout} =~ s/^(.*?)(\n|$)//; + @{$self->{columns}} = split(/\t/, $1); + } + foreach (split /\n/, $self->{stdout}) { + push @$array_ref, [map({ s/\\n/\x{0a}/g; s/\\t/\x{09}/g; s/\\/\x{5c}/g; $_; } split(/\t/, $_))]; + } + + return $array_ref; +} + +sub fetchrow_array { + my ($self, %options) = @_; + my @array_result = (); + + if (!defined($self->{columns})) { + $self->{stdout} =~ s/^(.*?)(\n|$)//; + @{$self->{columns}} = split(/\t/, $1); + } + if (($self->{stdout} =~ s/^(.*?)(\n|$)//)) { + push @array_result, map({ s/\\n/\x{0a}/g; s/\\t/\x{09}/g; s/\\/\x{5c}/g; $_; } split(/\t/, $1)); + } + + return @array_result; +} + +sub fetchrow_hashref { + my ($self, %options) = @_; + my $array_result = undef; + + if (!defined($self->{columns})) { + $self->{stdout} =~ s/^(.*?)(\n|$)//; + @{$self->{columns}} = split(/\t/, $1); + } + if ($self->{stdout} ne '' && $self->{stdout} =~ s/^(.*?)(\n|$)//) { + $array_result = {}; + my @values = split(/\t/, $1); + for (my $i = 0; $i < scalar(@values); $i++) { + my $value = $values[$i]; + $value =~ s/\\n/\x{0a}/g; + $value =~ s/\\t/\x{09}/g; + $value =~ s/\\/\x{5c}/g; + $array_result->{$self->{columns}[$i]} = $value; + } + } + + return $array_result; +} + +sub query { + my ($self, %options) = @_; + + $self->{columns} = undef; + (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}->option_exit(exit_litteral => $self->{sql_errors_exit}); + } + +} + +1; + +__END__ + +=head1 NAME + +mysqlcmd global + +=head1 SYNOPSIS + +mysqlcmd class + +=head1 MYSQLCMD OPTIONS + +=over 8 + +=item B<--mysql-cmd> + +mysql command (Default: '/usr/bin/mysql'). + +=item B<--host> + +Database hostname. + +=item B<--port> + +Database port. + +=item B<--username> + +Database username. + +=item B<--password> + +Database password. + +=item B<--sql-errors-exit> + +Exit code for DB Errors (default: unknown) + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/database/firebird/mode/iostats.pm b/database/firebird/mode/iostats.pm new file mode 100644 index 000000000..3d5f0f951 --- /dev/null +++ b/database/firebird/mode/iostats.pm @@ -0,0 +1,117 @@ +# +# Copyright 2015 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::firebird::mode::iostats; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use POSIX; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{sql} = sqlmode object + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + + if (!($self->{sql}->is_version_minimum(version => '1'))) { + $self->{output}->add_option_msg(short_msg => "Firebird version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); + $self->{output}->option_exit(); + } + + $self->{sql}->query(query => q{SELECT MON$PAGE_READS,MON$PAGE_WRITES FROM MON$IO_STATS WHERE MON$STAT_GROUP=0;}); + my $result = $self->{sql}->fetchall_arrayref(); + if (!defined($result)) { + $self->{output}->add_option_msg(short_msg => "Cannot get IO Stats."); + $self->{output}->option_exit(); + } + + my $page_reads = $$result[0][0]; + my $page_writes = $$result[0][1]; + + my $exit1 = $self->{perfdata}->threshold_check(value => $page_reads, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit2 = $self->{perfdata}->threshold_check(value => $page_writes, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); + + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("I/O stats : %d/%d",$page_writes, $page_reads )); + $self->{output}->perfdata_add(label => 'input', value => $page_writes); + $self->{output}->perfdata_add(label => 'output', value => $page_reads); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check MySQL uptime. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=item B<--seconds> + +Display uptime in seconds. + +=back + +=cut diff --git a/database/firebird/mode/memory.pm b/database/firebird/mode/memory.pm new file mode 100644 index 000000000..56ccc8c9a --- /dev/null +++ b/database/firebird/mode/memory.pm @@ -0,0 +1,188 @@ +# +# Copyright 2015 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::firebird::mode::memory; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use DBD::Firebird; + +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', }, + "seconds" => { name => 'seconds', }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{sql} = sqlmode object + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + + if (!($self->{sql}->is_version_minimum(version => '1'))) { + $self->{output}->add_option_msg(short_msg => "Firebird version '" . $self->{sql}->{version} . "' is not supported (need version >= '1.x')."); + $self->{output}->option_exit(); + } + + $self->{sql}->query(query => q{SELECT MON$STAT_GROUP,MON$MEMORY_ALLOCATED,MON$MEMORY_USED FROM MON$MEMORY_USAGE}); + my $result = $self->{sql}->fetchall_arrayref(); + if(!defined($result)) { + $self->{output}->add_option_msg(short_msg => "Cannot get memory."); + $self->{output}->opion_exit(); + } + + + my $mem_allocated; + my $attach_used=0; + my $prct_attach=0; + my $trans_used=0; + my $prct_trans; + my $stat_used=0; + my $prct_stat=0; + my $call_used=0; + my $prct_call=0; + my ($total_value, $total_unit)=(0,0); + my ($attach_value, $attach_unit)=(0,0); + my ($trans_value, $trans_unit)=(0,0); + my ($stat_value, $stat_unit)=(0,0); + my ($call_value, $call_unit)= (0,'B'); + + foreach my $row (@$result) { + next if (defined($self->{option_results}->{filter}) && + $$row[0] !~ /$self->{option_results}->{filter}/); + + + + if ($$row[0] == 0) { + $mem_allocated = $$row[1]; + ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $mem_allocated); + + } elsif ($$row[0] ==1) { + $attach_used = $attach_used + $$row[2]; + $prct_attach = $attach_used * 100 / $mem_allocated; + ($attach_value, $attach_unit) = $self->{perfdata}->change_bytes(value => $attach_used); + + } elsif ($$row[0] == 2) { + $trans_used = $trans_used + $$row[2]; + $prct_trans = $trans_used * 100 / $mem_allocated; + ($trans_value, $trans_unit) = $self->{perfdata}->change_bytes(value => $trans_used); + + + } elsif ($$row[0] == 3) { + $stat_used = $stat_used + $$row[2]; + $prct_stat = $stat_used * 100 / $mem_allocated; + ($stat_value, $stat_unit) = $self->{perfdata}->change_bytes(value => $stat_used); + + } elsif ($$row[0] ==4) { + $call_used = $call_used + $$row[2]; + $prct_call = $call_used * 100 / $mem_allocated; + ($call_value, $call_unit) = $self->{perfdata}->change_bytes(value => $call_used); + + } + } + my $mem_used = $attach_used + $trans_used + $stat_used + $call_used; + my $prct_used = $mem_used * 100 / $mem_allocated; + my ($used_value, $used_unit)=$self->{perfdata}->change_bytes(value => $mem_used); + + my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->perfdata_add(label => "used", unit => 'B', + value => $mem_used, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $mem_allocated, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $mem_allocated, cast_int => 1), + min => 0, max => $mem_allocated); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Memory Allocated %s, Total Used %s (%.2f%%)", + $total_value . " " . $total_unit, + $used_value . " " . $used_unit, $prct_used)); + $self->{output}->output_add(long_msg => sprintf("Attachement Used %s (%.2f%%)", + $attach_value . " " . $attach_unit, $prct_attach)); + $self->{output}->perfdata_add(label => "attachement", unit => 'B', + value => $attach_used); + $self->{output}->output_add(long_msg => sprintf("Transaction Used %s (%.2f%%)", + $trans_value . " " . $trans_unit, $prct_trans)); + $self->{output}->perfdata_add(label => "transaction", unit => 'B', + value => $trans_used); + $self->{output}->output_add(long_msg => sprintf("Statement Used %s (%.2f%%)", + $stat_value . " " . $stat_unit, $prct_stat)); + $self->{output}->perfdata_add(label => "statement", unit => 'B', + value => $stat_used); + $self->{output}->output_add(long_msg => sprintf("Call Used %s (%.2f%%)", + $call_value . " " . $call_unit, $prct_call)); + $self->{output}->perfdata_add(label => "call", unit => 'B', + value => $call_used); + + $self->{output}->display(); + $self->{output}->exit(); + + +} + +1; + +__END__ + +=head1 MODE + +Check MySQL uptime. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=item B<--seconds> + +Display uptime in seconds. + +=back + +=cut diff --git a/database/firebird/mode/queries.pm b/database/firebird/mode/queries.pm new file mode 100644 index 000000000..8a1231528 --- /dev/null +++ b/database/firebird/mode/queries.pm @@ -0,0 +1,145 @@ +# +# Copyright 2015 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::firebird::mode::queries; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; + +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', }, + }); + $self->{statefile_cache} = centreon::plugins::statefile->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->{statefile_cache}->check_options(%options); +} + +sub run { + my ($self, %options) = @_; + # $options{sql} = sqlmode object + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + $self->{sql}->query(query => q{ + SELECT MON$RECORD_SEQ_READS,MON$RECORD_INSERTS,MON$RECORD_UPDATES,MON$RECORD_DELETES,MON$RECORD_BACKOUTS,MON$RECORD_PURGES,MON$RECORD_EXPUNGES from MON$RECORD_STATS WHERE MON$STAT_GROUP=0 + }); + my $result = $self->{sql}->fetchall_arrayref(); + + if (!($self->{sql}->is_version_minimum(version => '1'))) { + $self->{output}->add_option_msg(short_msg => "Firebird version '" . $self->{sql}->{version} . "' is not supported (need version >= '1')."); + $self->{output}->option_exit(); + } + + my $new_datas = {}; + $self->{statefile_cache}->read(statefile => 'firebird_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save()); + my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp'); + $new_datas->{last_timestamp} = time(); + + if (defined($old_timestamp) && $new_datas->{last_timestamp} - $old_timestamp == 0) { + $self->{output}->add_option_msg(short_msg => "Need at least one second between two checks."); + $self->{output}->option_exit(); + } + + my @field = ("seq_reads","inserts","updates","deletes","backouts","purges","expunges"); + my $i=0; + foreach my $name (@field) { + + $new_datas->{$name} = $$result[0][$i]; + my $old_val = $self->{statefile_cache}->get(name => $name); + next if (!defined($old_val) || $$result[0][$i] < $old_val); + + my $value = int(($$result[0][$i] - $old_val) / ($new_datas->{last_timestamp} - $old_timestamp)); + if ($name ne 'seq_reads') { + $self->{output}->perfdata_add(label => $name . '_requests', + value => $value, + min => 0); + $i++; + next; + } + + 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("Total requests = %s", $value)); + $self->{output}->perfdata_add(label => 'total_requests', + value => $value, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + $i++ + } + + $self->{statefile_cache}->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 average number of queries executed. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut diff --git a/database/firebird/mode/slowqueries.pm b/database/firebird/mode/slowqueries.pm new file mode 100644 index 000000000..0c9e7bcbb --- /dev/null +++ b/database/firebird/mode/slowqueries.pm @@ -0,0 +1,139 @@ +# +# Copyright 2015 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::firebird::mode::slowqueries; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; + +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', }, + }); + $self->{statefile_cache} = centreon::plugins::statefile->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->{statefile_cache}->check_options(%options); +} + +sub run { + my ($self, %options) = @_; + # $options{sql} = sqlmode object + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + + if (!($self->{sql}->is_version_minimum(version => '1'))) { + $self->{output}->add_option_msg(short_msg => "Firebird version '" . $self->{sql}->{version} . "' is not supported (need version >= '1.x')."); + $self->{output}->option_exit(); + } + + $self->{sql}->query(query => q{SELECT COUNT(*) FROM MON$STATEMENTS INNER JOIN MON$TRANSACTIONS ON (MON$STATEMENTS.MON$ATTACHMENT_ID = MON$TRANSACTIONS.MON$ATTACHMENT_ID)}); + my $result = $self->{sql}->fetchrow_array(); + my $name='slow_query'; + if (!defined($result)) { + $self->{output}->add_option_msg(short_msg => "Cannot get slow queries."); + $self->{output}->option_exit(); + } + + + my $new_datas = {}; + $self->{statefile_cache}->read(statefile => 'firebird_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save()); + my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp'); + $new_datas->{last_timestamp} = time(); + + if (defined($old_timestamp) && $new_datas->{last_timestamp} - $old_timestamp == 0) { + $self->{output}->add_option_msg(short_msg => "Need at least one second between two checks."); + $self->{output}->option_exit(); + } + + $new_datas->{$name} = $result; + my $old_val = $self->{statefile_cache}->get(name => $name); + if (defined($old_val) && $result >= $old_val) { + my $value = sprintf("%.2f", ($result - $old_val) / ($new_datas->{last_timestamp} - $old_timestamp)); + + 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 slow queries in %d seconds (%.2f/sec)", + ($result - $old_val), ($new_datas->{last_timestamp} - $old_timestamp), $value) + ); + $self->{output}->perfdata_add(label => 'slow_queries_rate', + value => $value, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + } + + $self->{statefile_cache}->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 average number of queries detected as "slow" (per seconds). + +=over 8 + +=item B<--warning> + +Threshold warning in queries per seconds. + +=item B<--critical> + +Threshold critical in queries per seconds. + +=back + +=cut diff --git a/database/firebird/mode/users.pm b/database/firebird/mode/users.pm new file mode 100644 index 000000000..3e502f2d9 --- /dev/null +++ b/database/firebird/mode/users.pm @@ -0,0 +1,116 @@ +# +# Copyright 2015 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::firebird::mode::users; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use DBD::Firebird; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{sql} = sqlmode object + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + + if (!($self->{sql}->is_version_minimum(version => '1'))) { + $self->{output}->add_option_msg(short_msg => "firebird version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); + $self->{output}->option_exit(); + } + + $self->{sql}->query(query => q{SELECT COUNT(MON$USER) FROM MON$ATTACHMENTS}); + my $result = $self->{sql}->fetchrow_array(); + + if (!defined($result)) { + $self->{output}->add_option_msg(short_msg => "Cannot get users."); + $self->{output}->option_exit(); + } + + my $exit_code = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $msg = sprintf("%d user(s) connect to database", $result); + + $self->{output}->output_add(severity => $exit_code, + short_msg => $msg); + $self->{output}->perfdata_add(label => 'User', value => $result, + 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 MySQL uptime. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=item B<--seconds> + +Display uptime in seconds. + +=back + +=cut diff --git a/apps/kayako/sql/plugin.pm b/database/firebird/plugin.pm similarity index 50% rename from apps/kayako/sql/plugin.pm rename to database/firebird/plugin.pm index 425c70a0b..3a6f6ac4c 100644 --- a/apps/kayako/sql/plugin.pm +++ b/database/firebird/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package apps::kayako::sql::plugin; +package database::firebird::plugin; use strict; use warnings; @@ -26,20 +26,22 @@ use base qw(centreon::plugins::script_sql); sub new { my ($class, %options) = @_; - + my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( - 'list-department' => 'apps::kayako::sql::mode::listdepartment', - 'list-priority' => 'apps::kayako::sql::mode::listpriority', - 'list-staff' => 'apps::kayako::sql::mode::liststaff', - 'list-status' => 'apps::kayako::sql::mode::liststatus', - 'ticket-count' => 'apps::kayako::sql::mode::ticketcount', - ); - $self->{sql_modes}{psqlcmd} = 'database::postgres::psqlcmd'; + 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', + 'memory' => 'database::firebird::mode::memory', + 'users' => 'database::firebird::mode::users', + 'io-stats' => 'database::firebird::mode::iostats', + 'queries' => 'database::firebird::mode::queries', + 'slow-queries' => 'database::firebird::mode::slowqueries', + ); + $self->{sql_modes}{firebirdcmd} = 'database::firebird::firebirdcmd'; + return $self; } @@ -48,9 +50,9 @@ sub init { $self->{options}->add_options( arguments => { - 'host:s@' => { name => 'db_host' }, - 'port:s@' => { name => 'db_port' }, - 'database:s@' => { name => 'db_name' }, + 'host:s@' => { name => 'db_host' }, + 'port:s@' => { name => 'db_port' }, + 'database:s@' => { name => 'db_name' }, } ); $self->{options}->parse_options(); @@ -59,25 +61,21 @@ sub init { if (defined($options_result->{db_host})) { @{$self->{sqldefault}->{dbi}} = (); - @{$self->{sqldefault}->{mysqlcmd}} = (); + @{$self->{sqldefault}->{firebirdcmd}} = (); for (my $i = 0; $i < scalar(@{$options_result->{db_host}}); $i++) { - $self->{sqldefault}->{dbi}[$i] = { data_source => 'mysql:host=' . $options_result->{db_host}[$i] }; - $self->{sqldefault}->{mysqlcmd}[$i] = { host => $options_result->{db_host}[$i] }; + $self->{sqldefault}->{dbi}[$i] = { data_source => 'Firebird:host=' . $options_result->{db_host}[$i] }; + $self->{sqldefault}->{firebirdcmd}[$i] = { host => $options_result->{db_host}[$i] }; if (defined($options_result->{db_port}[$i])) { $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';port=' . $options_result->{db_port}[$i]; - $self->{sqldefault}->{mysqlcmd}[$i]->{port} = $options_result->{db_port}[$i]; + $self->{sqldefault}->{firebirdcmd}[$i]->{port} = $options_result->{db_port}[$i]; } - if (!defined($options_result->{db_name}[$i]) || $options_result->{db_name}[$i] eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify '--database' option."); - $self->{output}->option_exit(); - }else{ - $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';database=' . $options_result->{db_name}[$i]; - $self->{sqldefault}->{psqlcmd}[$i]->{dbname} = $options_result->{db_name}[$i]; - } + $options_result->{db_name}[$i] = (defined($options_result->{db_name}[$i]) && $options_result->{db_name}[$i] ne '') ? $options_result->{db_name}[$i] : 'firebird'; + $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';database=' . $options_result->{db_name}[$i]; + $self->{sqldefault}->{firebirdcmd}[$i]->{dbname} = $options_result->{db_name}[$i]; } } - $self->SUPER::init(%options); + $self->SUPER::init(%options); } 1; @@ -86,7 +84,11 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Kayako with MySQL Server. +Check Firebird Server. + +=over 8 + +You can use following options or options from 'sqlmode' directly. =item B<--host> @@ -98,7 +100,7 @@ Database Server Port. =item B<--database> -Database Name. +Path to Database. (eg:/opt/firebird/examples/empbuild/employee.fdb) =back diff --git a/docs/en/developer/guide.rst b/docs/en/developer/guide.rst index 6036acca0..75a99b12e 100644 --- a/docs/en/developer/guide.rst +++ b/docs/en/developer/guide.rst @@ -1192,7 +1192,7 @@ To use it, add the following line at the beginning of your **mode**: .. code-block:: perl - use centreon::plugins::httplib; + use centreon::plugins::http; Some options must be set in **plugin.pm**: @@ -1244,7 +1244,9 @@ We suppose these options are defined : .. code-block:: perl - my $webcontent = centreon::plugins::httplib::connect($self); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); + $self->{http}->set_options(%{$self->{option_results}}); + my $webcontent = $self->{http}->request(); print $webcontent; Output displays content of the webpage '\http://google.com/'. diff --git a/docs/en/user/guide.rst b/docs/en/user/guide.rst index 521635970..dbf6a517a 100644 --- a/docs/en/user/guide.rst +++ b/docs/en/user/guide.rst @@ -635,10 +635,10 @@ Linux Check all interface traffics in SNMP ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Warning if traffic in/out used > 80% and critical if traffic in/out used > 90%. It also skips errors from down interface (option ``--skip``): +Warning if traffic in/out used > 80% and critical if traffic in/out used > 90% : :: - $ perl centreon_plugins.pl --plugin=os::linux::snmp::plugin --mode=traffic --hostname=127.0.0.1 --snmp-version=2c --snmp-community=public --verbose --interface='.*' --name --regexp --skip --warning-in=80 --critical-in=90 --warning-out=80 --critical-out=90 + $ perl centreon_plugins.pl --plugin=os::linux::snmp::plugin --mode=interfaces --hostname=127.0.0.1 --snmp-version=2c --snmp-community=public --verbose --interface='.*' --name --add-traffic --warning-in-traffic=80 --critical-in-traffic=90 --warning-out-traffic=80 --critical-out-traffic=90 OK: All traffic are ok | 'traffic_in_lo'=126.58b/s;0.00:8000000.00;0.00:9000000.00;0;10000000 'traffic_out_lo'=126.58b/s;0.00:8000000.00;0.00:9000000.00;0;10000000 'traffic_in_eth0'=1872.00b/s;0.00:800000000.00;0.00:900000000.00;0;1000000000 'traffic_out_eth0'=266.32b/s;0.00:800000000.00;0.00:900000000.00;0;1000000000 'traffic_in_eth1'=976.65b/s;0.00:800000000.00;0.00:900000000.00;0;1000000000 'traffic_out_eth1'=1021.68b/s;0.00:800000000.00;0.00:900000000.00;0;1000000000 Interface 'lo' Traffic In : 126.58b/s (0.00 %), Out : 126.58b/s (0.00 %) Interface 'eth0' Traffic In : 1.87Kb/s (0.00 %), Out : 266.32b/s (0.00 %) diff --git a/docs/fr/developer/guide.rst b/docs/fr/developer/guide.rst index 0898fb9ed..f38b5bfaf 100644 --- a/docs/fr/developer/guide.rst +++ b/docs/fr/developer/guide.rst @@ -1191,7 +1191,7 @@ Pour l'utiliser, ajouter la ligne suivante au début de votre **mode** : .. code-block:: perl - use centreon::plugins::httplib; + use centreon::plugins::http; Certaines options doivent être spécifiées dans **plugin.pm** : @@ -1243,7 +1243,9 @@ Nous supposons que ces options sont définies : .. code-block:: perl - my $webcontent = centreon::plugins::httplib::connect($self); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); + $self->{http}->set_options(%{$self->{option_results}}); + my $webcontent = $self->{http}->request(); print $webcontent; La sortie affichera le contenu de la page web '\http://google.com/'. diff --git a/docs/fr/user/guide.rst b/docs/fr/user/guide.rst index 4cb5fc498..7ec6bc3bf 100644 --- a/docs/fr/user/guide.rst +++ b/docs/fr/user/guide.rst @@ -637,10 +637,10 @@ Linux Contrôler le trafic de toutes les interfaces en SNMP ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Dégradé si le trafic entrant/sortant utilisé > 80% et critique si le trafic entrant/sortant utilisé > 90%. L'exemple évite également les erreurs sur les interfaces déconnectées (option ``--skip``) : +Dégradé si le trafic entrant/sortant utilisé > 80% et critique si le trafic entrant/sortant utilisé > 90% : :: - $ perl centreon_plugins.pl --plugin=os::linux::snmp::plugin --mode=traffic --hostname=127.0.0.1 --snmp-version=2c --snmp-community=public --verbose --interface='.*' --name --regexp --skip --warning-in=80 --critical-in=90 --warning-out=80 --critical-out=90 + $ perl centreon_plugins.pl --plugin=os::linux::snmp::plugin --mode=interfaces --hostname=127.0.0.1 --snmp-version=2c --snmp-community=public --verbose --interface='.*' --name --add-traffic --warning-in-traffic=80 --critical-in-traffic=90 --warning-out-traffic=80 --critical-out-traffic=90 OK: All traffic are ok | 'traffic_in_lo'=126.58b/s;0.00:8000000.00;0.00:9000000.00;0;10000000 'traffic_out_lo'=126.58b/s;0.00:8000000.00;0.00:9000000.00;0;10000000 'traffic_in_eth0'=1872.00b/s;0.00:800000000.00;0.00:900000000.00;0;1000000000 'traffic_out_eth0'=266.32b/s;0.00:800000000.00;0.00:900000000.00;0;1000000000 'traffic_in_eth1'=976.65b/s;0.00:800000000.00;0.00:900000000.00;0;1000000000 'traffic_out_eth1'=1021.68b/s;0.00:800000000.00;0.00:900000000.00;0;1000000000 Interface 'lo' Traffic In : 126.58b/s (0.00 %), Out : 126.58b/s (0.00 %) Interface 'eth0' Traffic In : 1.87Kb/s (0.00 %), Out : 266.32b/s (0.00 %) diff --git a/hardware/sensors/sensormetrix/em01/web/mode/contact.pm b/hardware/sensors/sensormetrix/em01/web/mode/contact.pm index a4128abac..14cfbc495 100644 --- a/hardware/sensors/sensormetrix/em01/web/mode/contact.pm +++ b/hardware/sensors/sensormetrix/em01/web/mode/contact.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -36,7 +36,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/index.htm?eL" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -45,9 +45,10 @@ sub new { "warning" => { name => 'warning' }, "critical" => { name => 'critical' }, "closed" => { name => 'closed' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); $self->{status} = { closed => 'ok', opened => 'ok' }; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -63,20 +64,13 @@ sub check_options { $self->{status}->{$label} = 'warning'; } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my $contact; if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /([NW]).*?:/) { diff --git a/hardware/sensors/sensormetrix/em01/web/mode/flood.pm b/hardware/sensors/sensormetrix/em01/web/mode/flood.pm index e92ca9091..dcf881b31 100644 --- a/hardware/sensors/sensormetrix/em01/web/mode/flood.pm +++ b/hardware/sensors/sensormetrix/em01/web/mode/flood.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -36,8 +36,8 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, - "urlpath:s" => { name => 'url_path', default => "/" }, + "proto:s" => { name => 'proto' }, + "urlpath:s" => { name => 'url_path' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, @@ -45,9 +45,10 @@ sub new { "warning" => { name => 'warning' }, "critical" => { name => 'critical' }, "dry" => { name => 'dry' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); $self->{status} = { dry => 'ok', wet => 'ok' }; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -63,20 +64,13 @@ sub check_options { $self->{status}->{$label} = 'warning'; } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my $flood; if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /(dry|wet)/i) { diff --git a/hardware/sensors/sensormetrix/em01/web/mode/humidity.pm b/hardware/sensors/sensormetrix/em01/web/mode/humidity.pm index 36525966d..1314f296e 100644 --- a/hardware/sensors/sensormetrix/em01/web/mode/humidity.pm +++ b/hardware/sensors/sensormetrix/em01/web/mode/humidity.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -36,7 +36,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/index.htm?em" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -44,8 +44,9 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -61,20 +62,13 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my $humidity; if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /HU:\s*([0-9\.]+)/i) { diff --git a/hardware/sensors/sensormetrix/em01/web/mode/illumination.pm b/hardware/sensors/sensormetrix/em01/web/mode/illumination.pm index bef887ddd..ac6d982dd 100644 --- a/hardware/sensors/sensormetrix/em01/web/mode/illumination.pm +++ b/hardware/sensors/sensormetrix/em01/web/mode/illumination.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -36,7 +36,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/index.htm?em" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -44,8 +44,9 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -61,20 +62,13 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my $illumination; if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /IL(?:\s*:\s*|\s*)([0-9\.]+)/i) { diff --git a/hardware/sensors/sensormetrix/em01/web/mode/temperature.pm b/hardware/sensors/sensormetrix/em01/web/mode/temperature.pm index c44bd59da..12b1f56b8 100644 --- a/hardware/sensors/sensormetrix/em01/web/mode/temperature.pm +++ b/hardware/sensors/sensormetrix/em01/web/mode/temperature.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -36,7 +36,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/index.htm?em" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -44,8 +44,9 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -61,20 +62,13 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /T([CF]):\s*([0-9\.]+)/i) { $self->{output}->add_option_msg(short_msg => "Could not find temperature information."); diff --git a/hardware/sensors/sensormetrix/em01/web/mode/thermistor.pm b/hardware/sensors/sensormetrix/em01/web/mode/thermistor.pm index efcdad849..96225fc42 100644 --- a/hardware/sensors/sensormetrix/em01/web/mode/thermistor.pm +++ b/hardware/sensors/sensormetrix/em01/web/mode/thermistor.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -36,7 +36,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/index.htm?eR" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -44,8 +44,9 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -61,20 +62,13 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /R([CF])\s*([0-9\.]+)/i) { $self->{output}->add_option_msg(short_msg => "Could not find thermistor temperature information."); diff --git a/hardware/sensors/sensormetrix/em01/web/mode/voltage.pm b/hardware/sensors/sensormetrix/em01/web/mode/voltage.pm index 90efc9395..1f3a2a2b1 100644 --- a/hardware/sensors/sensormetrix/em01/web/mode/voltage.pm +++ b/hardware/sensors/sensormetrix/em01/web/mode/voltage.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; sub new { my ($class, %options) = @_; @@ -36,7 +36,7 @@ sub new { { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, + "proto:s" => { name => 'proto' }, "urlpath:s" => { name => 'url_path', default => "/index.htm?ev" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, @@ -44,8 +44,9 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, + "timeout:s" => { name => 'timeout' }, }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -61,20 +62,13 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); - $self->{output}->option_exit(); - } + $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $webcontent = centreon::plugins::httplib::connect($self); + my $webcontent = $self->{http}->request(); my $voltage; if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /CV\s*([0-9\.]+)/i) { diff --git a/hardware/server/dell/openmanage/mode/components/battery.pm b/hardware/server/dell/openmanage/mode/components/battery.pm deleted file mode 100644 index 4ecc140bf..000000000 --- a/hardware/server/dell/openmanage/mode/components/battery.pm +++ /dev/null @@ -1,86 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::battery; - -use strict; -use warnings; - -my %status = ( - 1 => ['other', 'CRITICAL'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], -); - -my %reading = ( - 1 => 'Predictive Failure', - 2 => 'Failed', - 4 => 'Presence Detected', -); - -sub check { - my ($self) = @_; - - # In MIB '10892.mib' - $self->{output}->output_add(long_msg => "Checking batteries"); - $self->{components}->{battery} = {name => 'batteries', total => 0}; - return if ($self->check_exclude('battery')); - - my $oid_batteryStatus = '.1.3.6.1.4.1.674.10892.1.600.50.1.5'; - my $oid_batteryReading = '.1.3.6.1.4.1.674.10892.1.600.50.1.6'; - my $oid_batteryLocationName = '.1.3.6.1.4.1.674.10892.1.600.50.1.7'; - - my $result = $self->{snmp}->get_table(oid => $oid_batteryStatus); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_batteryReading, $oid_batteryLocationName], - instances => [keys %$result], - instance_regexp => '(\d+\.\d+)$'); - my $result2 = $self->{snmp}->get_leef(); - return if (scalar(keys %$result2) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)\.(\d+)$/; - my ($chassis_Index, $battery_Index) = ($1, $2); - my $instance = $chassis_Index . '.' . $battery_Index; - - my $battery_status = $result->{$key}; - my $battery_reading = $result2->{$oid_batteryReading . '.' . $instance}; - my $battery_locationName = $result2->{$oid_batteryLocationName . '.' . $instance}; - - $self->{components}->{battery}->{total}++; - $self->{output}->output_add(long_msg => sprintf("battery %d status is %s, reading is %s [location: %s].", - $battery_Index, ${$status{$battery_status}}[0], $reading{$battery_reading}, - $battery_locationName - )); - - if ($battery_status != 3) { - $self->{output}->output_add(severity => ${$status{$battery_status}}[1], - short_msg => sprintf("battery %d status is %s", - $battery_Index, ${$status{$battery_status}}[0])); - } - - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/cachebattery.pm b/hardware/server/dell/openmanage/mode/components/cachebattery.pm deleted file mode 100644 index ee92e589f..000000000 --- a/hardware/server/dell/openmanage/mode/components/cachebattery.pm +++ /dev/null @@ -1,108 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::cachebattery; - -use strict; -use warnings; - -my %state = ( - 0 => 'unknown', - 1 => 'ready', - 2 => 'failed', - 6 => 'degraded', - 7 => 'reconditioning', - 9 => 'high', - 10 => 'powerLow', - 12 => 'charging', - 21 => 'missing', - 36 => 'learning', -); - -my %componentStatus = ( - 1 => ['other', 'UNKNOWN'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], -); - -my %learnState = ( - 1 => 'failed', - 2 => 'active', - 4 => 'timedOut', - 8 => 'requested', - 16 => 'idle', - 32 => 'due', -); - -my %predictedCapacity = ( - 1 => 'failed', - 2 => 'ready', - 4 => 'unknown', -); - -sub check { - my ($self) = @_; - - # In MIB '10893.mib' - $self->{output}->output_add(long_msg => "Checking cache batteries"); - $self->{components}->{cachebattery} = {name => 'cache batteries', total => 0}; - return if ($self->check_exclude('cachebattery')); - - my $oid_batteryState = '.1.3.6.1.4.1.674.10893.1.20.130.15.1.4'; - my $oid_batteryComponentStatus = '.1.3.6.1.4.1.674.10893.1.20.130.15.1.6'; - my $oid_batteryPredictedCapicity = '.1.3.6.1.4.1.674.10893.1.20.130.15.1.10'; - my $oid_batteryLearnState = '.1.3.6.1.4.1.674.10893.1.20.130.15.1.12'; - - my $result = $self->{snmp}->get_table(oid => $oid_batteryState); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_batteryComponentStatus, $oid_batteryPredictedCapicity, $oid_batteryLearnState], - instances => [keys %$result], - instance_regexp => '(\d+)$'); - my $result2 = $self->{snmp}->get_leef(); - return if (scalar(keys %$result2) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)$/; - my $battery_Index = $1; - - my $battery_State = $result->{$key}; - my $battery_ComponentStatus = $result2->{$oid_batteryComponentStatus . '.' . $battery_Index}; - my $battery_PredictedCapacity = $result2->{$oid_batteryPredictedCapicity . '.' . $battery_Index}; - my $battery_LearnState = $result2->{$oid_batteryLearnState . '.' . $battery_Index}; - - $self->{components}->{cachebattery}->{total}++; - $self->{output}->output_add(long_msg => sprintf("cache battery %d status is %s, state is %s, learn state is %s, predicted capacity is %s.", - $battery_Index, ${$componentStatus{$battery_ComponentStatus}}[0], $state{$battery_State}, - $learnState{$battery_LearnState}, $predictedCapacity{$battery_PredictedCapacity} - )); - if ($battery_ComponentStatus != 3) { - $self->{output}->output_add(severity => ${$componentStatus{$battery_ComponentStatus}}[1], - short_msg => sprintf("cache battery %d status is %s", - $battery_Index, ${$componentStatus{$battery_ComponentStatus}}[0])); - } - - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/connector.pm b/hardware/server/dell/openmanage/mode/components/connector.pm deleted file mode 100644 index 21abefa51..000000000 --- a/hardware/server/dell/openmanage/mode/components/connector.pm +++ /dev/null @@ -1,100 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::connector; - -use strict; -use warnings; - -my %state = ( - 0 => 'unknown', - 1 => 'ready', - 2 => 'failed', - 3 => 'online', - 4 => 'offline', - 6 => 'degraded', -); - -my %status = ( - 1 => ['other', 'UNKNOWN'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], -); - -my %busType = ( - 1 => 'SCSI', - 2 => 'IDE', - 3 => 'Fibre Channel', - 4 => 'SSA', - 6 => 'USB', - 7 => 'SATA', - 8 => 'SAS', -); - -sub check { - my ($self) = @_; - - # In MIB '10893.mib' - $self->{output}->output_add(long_msg => "Checking Connectors (Channels)"); - $self->{components}->{connector} = {name => 'connectors', total => 0}; - return if ($self->check_exclude('connector')); - - my $oid_channelName = '.1.3.6.1.4.1.674.10893.1.20.130.2.1.2'; - my $oid_channelState = '.1.3.6.1.4.1.674.10893.1.20.130.2.1.3'; - my $oid_channelComponentStatus = '.1.3.6.1.4.1.674.10893.1.20.130.2.1.8'; - my $oid_channelBusType = '.1.3.6.1.4.1.674.10893.1.20.130.2.1.11'; - - my $result = $self->{snmp}->get_table(oid => $oid_channelName); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_channelState, $oid_channelComponentStatus, $oid_channelBusType], - instances => [keys %$result], - instance_regexp => '(\d+)$'); - my $result2 = $self->{snmp}->get_leef(); - return if (scalar(keys %$result2) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)$/; - my $channel_Index = $1; - - my $channel_name = $result->{$key}; - my $channel_state = $result2->{$oid_channelState . '.' . $channel_Index}; - my $channel_componentStatus = $result2->{$oid_channelComponentStatus . '.' . $channel_Index}; - my $channel_busType = $result2->{$oid_channelBusType . '.' . $channel_Index}; - - $self->{components}->{connector}->{total}++; - $self->{output}->output_add(long_msg => sprintf("connector '%s' status is '%s', state is '%s' [index: %d, bus: %s].", - $channel_name, ${$status{$channel_componentStatus}}[0], $state{$channel_state}, - $channel_Index, $busType{$channel_busType} - )); - - if ($channel_componentStatus != 3) { - $self->{output}->output_add(severity => ${$status{$channel_componentStatus}}[1], - short_msg => sprintf("connector '%s' status is '%s' [index: %d, bus: %s]", - $channel_name, ${$status{$channel_componentStatus}}[0], $channel_Index, $busType{$channel_busType})); - } - - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/controller.pm b/hardware/server/dell/openmanage/mode/components/controller.pm deleted file mode 100644 index dd8b809ea..000000000 --- a/hardware/server/dell/openmanage/mode/components/controller.pm +++ /dev/null @@ -1,90 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::controller; - -use strict; -use warnings; - -my %state = ( - 0 => 'unknown', - 1 => 'ready', - 2 => 'failed', - 3 => 'online', - 4 => 'offline', - 6 => 'degraded', -); - -my %status = ( - 1 => ['other', 'UNKNOWN'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], -); - -sub check { - my ($self) = @_; - - # In MIB '10893.mib' - $self->{output}->output_add(long_msg => "Checking Controllers"); - $self->{components}->{controller} = {name => 'controllers', total => 0}; - return if ($self->check_exclude('controller')); - - my $oid_controllerName = '.1.3.6.1.4.1.674.10893.1.20.130.1.1.2'; - my $oid_controllerState = '.1.3.6.1.4.1.674.10893.1.20.130.1.1.5'; - my $oid_controllerComponentStatus = '.1.3.6.1.4.1.674.10893.1.20.130.1.1.38'; - my $oid_controllerFWVersion = '.1.3.6.1.4.1.674.10893.1.20.130.1.1.8'; - - my $result = $self->{snmp}->get_table(oid => $oid_controllerName); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_controllerState, $oid_controllerComponentStatus, $oid_controllerFWVersion], - instances => [keys %$result], - instance_regexp => '(\d+)$'); - my $result2 = $self->{snmp}->get_leef(); - return if (scalar(keys %$result2) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)$/; - my $controller_Index = $1; - - my $controller_name = $result->{$key}; - my $controller_state = $result2->{$oid_controllerState . '.' . $controller_Index}; - my $controller_componentStatus = $result2->{$oid_controllerComponentStatus . '.' . $controller_Index}; - my $controller_FWVersion = $result2->{$oid_controllerFWVersion . '.' . $controller_Index}; - - $self->{components}->{controller}->{total}++; - $self->{output}->output_add(long_msg => sprintf("controller '%s' status is '%s', state is '%s' [index: %d, firmware: %s].", - $controller_name, ${$status{$controller_componentStatus}}[0], $state{$controller_state}, - $controller_Index, $controller_FWVersion - )); - - if ($controller_componentStatus != 3) { - $self->{output}->output_add(severity => ${$status{$controller_componentStatus}}[1], - short_msg => sprintf("controller '%s' status is '%s' [index: %d]", - $controller_name, ${$status{$controller_componentStatus}}[0], $controller_Index)); - } - - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/cpu.pm b/hardware/server/dell/openmanage/mode/components/cpu.pm deleted file mode 100644 index 69f411f67..000000000 --- a/hardware/server/dell/openmanage/mode/components/cpu.pm +++ /dev/null @@ -1,107 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::cpu; - -use strict; -use warnings; - -my %status = ( - 1 => ['other', 'CRITICAL'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], -); - -my %statusState = ( - 1 => 'other', - 2 => 'unknown', - 3 => 'enabled', - 4 => 'userDisabled', - 5 => 'biosDisabled', - 6 => 'idle', -); - -my %statusReading = ( - 1 => 'internalError', - 2 => 'thermalTrip', - 32 => 'configurationError', - 128 => 'Present', - 256 => 'Disabled', - 512 => 'terminatorPresent', - 1024 => 'throttled', -); - -sub check { - my ($self) = @_; - - # In MIB '10892.mib' - $self->{output}->output_add(long_msg => "Checking Processor Units"); - $self->{components}->{cpu} = {name => 'CPUs', total => 0}; - return if ($self->check_exclude('cpu')); - - my $oid_cpuStatus = '.1.3.6.1.4.1.674.10892.1.1100.30.1.5'; - my $oid_cpuManufacturerName = '.1.3.6.1.4.1.674.10892.1.1100.30.1.8'; - my $oid_cpuStatusState = '.1.3.6.1.4.1.674.10892.1.1100.30.1.9'; - my $oid_cpuCurrentSpeed = '.1.3.6.1.4.1.674.10892.1.1100.30.1.12'; - my $oid_cpuBrandName = '.1.3.6.1.4.1.674.10892.1.1100.30.1.23'; - my $oid_cpuChassis = '.1.3.6.1.4.1.674.10892.1.1100.32.1.1'; - my $oid_cpuStatusReading = '.1.3.6.1.4.1.674.10892.1.1100.32.1.6'; - - my $result = $self->{snmp}->get_table(oid => $oid_cpuStatus); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_cpuManufacturerName, $oid_cpuStatusState, $oid_cpuCurrentSpeed, $oid_cpuBrandName, $oid_cpuChassis, $oid_cpuStatusReading], - instances => [keys %$result], - instance_regexp => '(\d+\.\d+)$'); - my $result2 = $self->{snmp}->get_leef(); - return if (scalar(keys %$result2) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)\.(\d+)$/; - my ($chassis_Index, $cpu_Index) = ($1, $2); - my $instance = $chassis_Index . '.' . $cpu_Index; - - my $cpu_Status = $result->{$key}; - my $cpu_ManufacturerName = $result2->{$oid_cpuManufacturerName . '.' . $instance}; - my $cpu_StatusState = $result2->{$oid_cpuStatusState . '.' . $instance}; - my $cpu_CurrentSpeed = $result2->{$oid_cpuCurrentSpeed . '.' . $instance}; - my $cpu_BrandName = $result2->{$oid_cpuBrandName . '.' . $instance}; - my $cpu_Chassis = $result2->{$oid_cpuChassis . '.' . $instance}; - my $cpu_StatusReading = $result2->{$oid_cpuStatusReading . '.' . $instance}; - - $self->{components}->{cpu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("cpu %d status is %s, state is %s, current speed is %d MHz [model: %s].", - $cpu_Index, ${$status{$cpu_Status}}[0], $statusState{$cpu_StatusState}, - $cpu_CurrentSpeed, $cpu_BrandName - )); - - if ($cpu_Status != 3) { - $self->{output}->output_add(severity => ${$status{$cpu_Status}}[1], - short_msg => sprintf("cpu %d status is %s", - $cpu_Index, ${$status{$cpu_Status}}[0])); - } - - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/esmlog.pm b/hardware/server/dell/openmanage/mode/components/esmlog.pm deleted file mode 100644 index 865bc72d0..000000000 --- a/hardware/server/dell/openmanage/mode/components/esmlog.pm +++ /dev/null @@ -1,58 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::esmlog; - -use strict; -use warnings; - -my %status = ( - 1 => ['other', 'CRITICAL'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], -); - -sub check { - my ($self) = @_; - - # In MIB '10892.mib' - $self->{output}->output_add(long_msg => "Checking ESM log filling"); - $self->{components}->{esmlog} = {name => 'ESM log', total => 0}; - return if ($self->check_exclude('esmlog')); - - my $oid_eventLogStatus = '.1.3.6.1.4.1.674.10892.1.200.10.1.41.1'; - my $result = $self->{snmp}->get_leef(oids => [$oid_eventLogStatus], nothing_quit => 1); - - $self->{components}->{esmlog}->{total}++; - $self->{output}->output_add(long_msg => sprintf("ESM log status is '%s'.", - ${$status{$result->{$oid_eventLogStatus}}}[0] - )); - - if ($result->{$oid_eventLogStatus} != 3) { - $self->{output}->output_add(severity => ${$status{$result->{$oid_eventLogStatus}}}[1], - short_msg => sprintf("ESM log status is '%s'", - ${$status{$result->{$oid_eventLogStatus}}}[0])); - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/fan.pm b/hardware/server/dell/openmanage/mode/components/fan.pm deleted file mode 100644 index 0e5e75245..000000000 --- a/hardware/server/dell/openmanage/mode/components/fan.pm +++ /dev/null @@ -1,83 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::fan; - -use strict; -use warnings; - -my %status = ( - 1 => ['other', 'CRITICAL'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCriticalUpper', 'WARNING'], - 5 => ['criticalUpper', 'CRITICAL'], - 6 => ['nonRecoverableUpper', 'CRITICAL'], - 7 => ['nonCriticalLower', 'WARNING'], - 8 => ['criticalLower', 'CRITICAL'], - 9 => ['nonRecoverableLower', 'CRITICAL'], - 10 => ['failed', 'CRITICAL'] - -); - -sub check { - my ($self) = @_; - - # In MIB '10892.mib' - $self->{output}->output_add(long_msg => "Checking fans"); - $self->{components}->{fan} = {name => 'fans', total => 0}; - return if ($self->check_exclude('fan')); - - my $oid_coolingDeviceStatus = '.1.3.6.1.4.1.674.10892.1.700.12.1.5'; - my $oid_coolingDeviceReading = '.1.3.6.1.4.1.674.10892.1.700.12.1.6'; - my $oid_coolingDeviceLocationName = '.1.3.6.1.4.1.674.10892.1.700.12.1.8'; - - my $result = $self->{snmp}->get_table(oid => $oid_coolingDeviceStatus); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_coolingDeviceReading, $oid_coolingDeviceLocationName], - instances => [keys %$result], - instance_regexp => '(\d+\.\d+)$'); - my $result2 = $self->{snmp}->get_leef(); - return if (scalar(keys %$result2) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)\.(\d+)$/; - my ($chassis_Index, $fan_Index) = ($1, $2); - my $instance = $chassis_Index . '.' . $fan_Index; - - my $fan_Status = $result->{$key}; - my $fan_Reading = $result2->{$oid_coolingDeviceReading . '.' . $instance}; - my $fan_LocationName = $result2->{$oid_coolingDeviceLocationName . '.' . $instance}; - - $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("fan %d status is %s, speed is %d RPM [location: %s].", - $fan_Index, ${$status{$fan_Status}}[0], $fan_Reading, - $fan_LocationName - )); - if ($fan_Status != 3) { - $self->{output}->output_add(severity => ${$status{$fan_Status}}[1], - short_msg => sprintf("fan %d status is %s", - $fan_Index, ${$status{$fan_Status}}[0])); - } - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/globalstatus.pm b/hardware/server/dell/openmanage/mode/components/globalstatus.pm deleted file mode 100644 index d66d946ef..000000000 --- a/hardware/server/dell/openmanage/mode/components/globalstatus.pm +++ /dev/null @@ -1,56 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::globalstatus; - -use strict; -use warnings; - -my %status = ( - 1 => ['other', 'CRITICAL'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], -); - -sub check { - my ($self) = @_; - - # In MIB '10892.mib' - $self->{output}->output_add(long_msg => "Checking global system status"); - return if ($self->check_exclude('globalstatus')); - - my $oid_globalSystemStatus = '.1.3.6.1.4.1.674.10892.1.200.10.1.2.1'; - my $result = $self->{snmp}->get_leef(oids => [$oid_globalSystemStatus], nothing_quit => 1); - - $self->{output}->output_add(long_msg => sprintf("Overall global status is '%s'.", - ${$status{$result->{$oid_globalSystemStatus}}}[0] - )); - - if ($result->{$oid_globalSystemStatus} != 3) { - $self->{output}->output_add(severity => ${$status{$result->{$oid_globalSystemStatus}}}[1], - short_msg => sprintf("Overall global status is '%s'", - ${$status{$result->{$oid_globalSystemStatus}}}[0])); - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/logicaldrive.pm b/hardware/server/dell/openmanage/mode/components/logicaldrive.pm deleted file mode 100644 index 9be3ad28e..000000000 --- a/hardware/server/dell/openmanage/mode/components/logicaldrive.pm +++ /dev/null @@ -1,121 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::logicaldrive; - -use strict; -use warnings; - -my %state = ( - 0 => 'unknown', - 1 => 'ready', - 2 => 'failed', - 3 => 'online', - 4 => 'offline', - 6 => 'degraded', - 15 => 'resynching', - 24 => 'rebuild', - 26 => 'formatting', - 35 => 'initializing', -); - -my %layout = ( - 1 => 'Concatened', - 2 => 'RAID-0', - 3 => 'RAID-1', - 4 => 'RAID-2', - 5 => 'RAID-3', - 6 => 'RAID-4', - 7 => 'RAID-5', - 8 => 'RAID-6', - 9 => 'RAID-7', - 10 => 'RAID-10', - 11 => 'RAID-30', - 12 => 'RAID-50', - 13 => 'Add spares', - 14 => 'Delete logical', - 15 => 'Transform logical', - 18 => 'RAID-0-plus-1 - Mylex only', - 19 => 'Concatened RAID 1', - 20 => 'Concatened RAID 5', - 21 => 'no RAID', - 22 => 'RAID Morph - Adapted only', -); - -my %componentStatus = ( - 1 => ['other', 'UNKNOWN'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], -); - -sub check { - my ($self) = @_; - - # In MIB '10893.mib' - $self->{output}->output_add(long_msg => "Checking Logical Drives"); - $self->{components}->{logicaldrive} = {name => 'logical drives', total => 0}; - return if ($self->check_exclude('logicaldrive')); - - my $oid_diskName = '.1.3.6.1.4.1.674.10893.1.20.140.1.1.2'; - my $oid_diskDeviceName = '.1.3.6.1.4.1.674.10893.1.20.140.1.1.3'; - my $oid_diskState = '.1.3.6.1.4.1.674.10893.1.20.140.1.1.4'; - my $oid_diskLengthInMB = '.1.3.6.1.4.1.674.10893.1.20.140.1.1.6'; - my $oid_diskLayout = '.1.3.6.1.4.1.674.10893.1.20.140.1.1.13'; - my $oid_diskComponentStatus = '.1.3.6.1.4.1.674.10893.1.20.140.1.1.20'; - - my $result = $self->{snmp}->get_table(oid => $oid_diskName); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_diskDeviceName, $oid_diskState, $oid_diskLengthInMB, $oid_diskLayout, $oid_diskComponentStatus], - instances => [keys %$result], - instance_regexp => '(\d+)$'); - my $result2 = $self->{snmp}->get_leef(); - return if (scalar(keys %$result2) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)$/; - my $disk_Index = $1; - - my $disk_Name = $result->{$key}; - my $disk_DeviceName = $result2->{$oid_diskDeviceName . '.' . $disk_Index}; - my $disk_State = $result2->{$oid_diskState . '.' . $disk_Index}; - my $disk_LengthInMB = $result2->{$oid_diskLengthInMB . '.' . $disk_Index}; - my $disk_Layout = $result2->{$oid_diskLayout . '.' . $disk_Index}; - my $disk_ComponentStatus = $result2->{$oid_diskComponentStatus . '.' . $disk_Index}; - - $self->{components}->{logicaldrive}->{total}++; - $self->{output}->output_add(long_msg => sprintf("logical drive %s status is %s, state is %s, layout is %s, size is %d MB [device: %s, index: %d].", - $disk_Name, ${$componentStatus{$disk_ComponentStatus}}[0], $state{$disk_State}, - $layout{$disk_Layout}, $disk_LengthInMB, $disk_DeviceName, $disk_Index - )); - - if ($disk_ComponentStatus != 3) { - $self->{output}->output_add(severity => ${$componentStatus{$disk_ComponentStatus}}[1], - short_msg => sprintf("logical drive %s status is %s [device: %s, index: %d]", - $disk_Name, ${$componentStatus{$disk_ComponentStatus}}[0], $disk_DeviceName, $disk_Index)); - } - - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/memory.pm b/hardware/server/dell/openmanage/mode/components/memory.pm deleted file mode 100644 index 9ba097120..000000000 --- a/hardware/server/dell/openmanage/mode/components/memory.pm +++ /dev/null @@ -1,91 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::memory; - -use strict; -use warnings; - -my %status = ( - 1 => ['other', 'CRITICAL'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], -); - -my %failureModes = ( - 0 => 'Not failure', - 1 => 'ECC single bit correction warning rate exceeded', - 2 => 'ECC single bit correction failure rate exceeded', - 4 => 'ECC multibit fault encountered', - 8 => 'ECC single bit correction logging disabled', - 16 => 'device disabled because of spare activation', -); - -sub check { - my ($self) = @_; - - # In MIB '10892.mib' - $self->{output}->output_add(long_msg => "Checking Memory Modules"); - $self->{components}->{memory} = {name => 'memory modules', total => 0}; - return if ($self->check_exclude('memory')); - - my $oid_memoryDeviceStatus = '.1.3.6.1.4.1.674.10892.1.1100.50.1.5'; - my $oid_memoryDeviceLocationName = '.1.3.6.1.4.1.674.10892.1.1100.50.1.8'; - my $oid_memoryDeviceSize = '.1.3.6.1.4.1.674.10892.1.1100.50.1.14'; - my $oid_memoryDeviceFailureModes = '.1.3.6.1.4.1.674.10892.1.1100.50.1.20'; - - my $result = $self->{snmp}->get_table(oid => $oid_memoryDeviceStatus); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_memoryDeviceLocationName, $oid_memoryDeviceSize, $oid_memoryDeviceFailureModes], - instances => [keys %$result], - instance_regexp => '(\d+\.\d+)$'); - my $result2 = $self->{snmp}->get_leef(); - return if (scalar(keys %$result2) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)\.(\d+)$/; - my ($chassis_Index, $memory_Index) = ($1, $2); - my $instance = $chassis_Index . '.' . $memory_Index; - - my $memory_deviceStatus = $result->{$key}; - my $memory_deviceLocationName = $result2->{$oid_memoryDeviceLocationName . '.' . $instance}; - my $memory_deviceSize = $result2->{$oid_memoryDeviceSize . '.' . $instance}; - my $memory_deviceFailureModes = $result2->{$oid_memoryDeviceFailureModes . '.' . $instance}; - - $self->{components}->{memory}->{total}++; - $self->{output}->output_add(long_msg => sprintf("memory module %d status is %s, failure mode is %s, size is %d KB [location: %s].", - $memory_Index, ${$status{$memory_deviceStatus}}[0], $failureModes{$memory_deviceFailureModes}, - $memory_deviceSize, $memory_deviceLocationName - )); - - if ($memory_deviceStatus != 3) { - $self->{output}->output_add(severity => ${$status{$memory_deviceStatus}}[1], - short_msg => sprintf("memory module %d status is %s", - $memory_Index, ${$status{$memory_deviceStatus}}[0])); - } - - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/physicaldisk.pm b/hardware/server/dell/openmanage/mode/components/physicaldisk.pm deleted file mode 100644 index 5686d611b..000000000 --- a/hardware/server/dell/openmanage/mode/components/physicaldisk.pm +++ /dev/null @@ -1,122 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::physicaldisk; - -use strict; -use warnings; - -my %state = ( - 0 => 'unknown', - 1 => 'ready', - 2 => 'failed', - 3 => 'online', - 4 => 'offline', - 6 => 'degraded', - 7 => 'recovering', - 11 => 'removed', - 15 => 'resynching', - 24 => 'rebuild', - 25 => 'noMedia', - 26 => 'formatting', - 28 => 'diagnostics', - 35 => 'initializing', -); - -my %spareState = ( - 1 => 'memberVD', - 2 => 'memberDG', - 3 => 'globalHostSpare', - 4 => 'dedicatedHostSpare', - 5 => 'notASpare', -); - -my %componentStatus = ( - 1 => ['other', 'UNKNOWN'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], -); - -my %smartAlertIndication = ( - 1 => ['no', 'OK'], - 2 => ['yes', 'WARNING'], -); - -sub check { - my ($self) = @_; - - # In MIB '10893.mib' - $self->{output}->output_add(long_msg => "Checking Physical Disks"); - $self->{components}->{physicaldisk} = {name => 'physical disks', total => 0}; - return if ($self->check_exclude('physicaldisk')); - - my $oid_diskName = '.1.3.6.1.4.1.674.10893.1.20.130.4.1.2'; - my $oid_diskState = '.1.3.6.1.4.1.674.10893.1.20.130.4.1.4'; - my $oid_diskLengthInMB = '.1.3.6.1.4.1.674.10893.1.20.130.4.1.11'; - my $oid_diskSpareState = '.1.3.6.1.4.1.674.10893.1.20.130.4.1.22'; - my $oid_diskComponentStatus = '.1.3.6.1.4.1.674.10893.1.20.130.4.1.24'; - my $oid_diskSmartAlertIndication = '.1.3.6.1.4.1.674.10893.1.20.130.4.1.31'; - - my $result = $self->{snmp}->get_table(oid => $oid_diskName); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_diskState, $oid_diskLengthInMB, $oid_diskSpareState, $oid_diskComponentStatus, $oid_diskSmartAlertIndication], - instances => [keys %$result], - instance_regexp => '(\d+\.\d+)$'); - my $result2 = $self->{snmp}->get_leef(); - return if (scalar(keys %$result2) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)\.(\d+)$/; - my ($chassis_Index, $disk_Index) = ($1, $2); - my $instance = $chassis_Index . '.' . $disk_Index; - - my $disk_Name = $result->{$key}; - my $disk_State = $result2->{$oid_diskState . '.' . $instance}; - my $disk_LengthInMB = $result2->{$oid_diskLengthInMB . '.' . $instance}; - my $disk_SpareState = $result2->{$oid_diskSpareState . '.' . $instance}; - my $disk_ComponentStatus = $result2->{$oid_diskComponentStatus . '.' . $instance}; - my $disk_SmartAlertIndication = $result2->{$oid_diskSmartAlertIndication . '.' . $instance}; - - $self->{components}->{physicaldisk}->{total}++; - $self->{output}->output_add(long_msg => sprintf("physical disk '%s' status is %s, state is %s, predictive failure alert %s, spare state is %s, size is %d MB [index: %d].", - $disk_Name, ${$componentStatus{$disk_ComponentStatus}}[0], $state{$disk_State}, ${$smartAlertIndication{$disk_SmartAlertIndication}}[0], - $spareState{$disk_SpareState}, $disk_LengthInMB, $disk_Index - )); - - if ($disk_SmartAlertIndication !=1) { - $self->{output}->output_add(severity => ${$smartAlertIndication{$disk_SmartAlertIndication}}[1], - short_msg => sprintf("physical disk '%s' has received a predictive failure alert [index: %d]", - $disk_Name, $disk_Index)); - } - - if ($disk_ComponentStatus != 3) { - $self->{output}->output_add(severity => ${$componentStatus{$disk_ComponentStatus}}[1], - short_msg => sprintf("physical disk '%s' status is %s [index: %d]", - $disk_Name, ${$componentStatus{$disk_ComponentStatus}}[0], $disk_Index)); - } - - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/psu.pm b/hardware/server/dell/openmanage/mode/components/psu.pm deleted file mode 100644 index ddffa87ea..000000000 --- a/hardware/server/dell/openmanage/mode/components/psu.pm +++ /dev/null @@ -1,111 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::psu; - -use strict; -use warnings; - -my %status = ( - 1 => ['other', 'CRITICAL'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], -); - -my %type = ( - 1 => 'other', - 2 => 'unknown', - 3 => 'Linear', - 4 => 'switching', - 5 => 'Battery', - 6 => 'UPS', - 7 => 'Converter', - 8 => 'Regulator', - 9 => 'AC', - 10 => 'DC', - 11 => 'VRM', -); - -my %state = ( - 1 => 'present', - 2 => 'failure', - 4 => 'predictiveFailure', - 8 => 'ACLost', - 16 => 'ACLostOrOutOfRange', - 32 => 'ACPresentButOutOfRange', - 64 => 'configurationError', -); - -my %ConfigurationErrorType = ( - 1 => 'vendorMismatch', - 2 => 'revisionMismatch', - 3 => 'processorMissing', -); - -sub check { - my ($self) = @_; - - # In MIB '10892.mib' - $self->{output}->output_add(long_msg => "Checking power supplies"); - $self->{components}->{psu} = {name => 'power supplies', total => 0}; - return if ($self->check_exclude('psu')); - - my $oid_powerSupplyStatus = '.1.3.6.1.4.1.674.10892.1.600.12.1.5'; - my $oid_powerSupplyType = '.1.3.6.1.4.1.674.10892.1.600.12.1.7'; - my $oid_powerSupplySensorState = '.1.3.6.1.4.1.674.10892.1.600.12.1.11'; - my $oid_powerSupplyConfigurationErrorType = '.1.3.6.1.4.1.674.10892.1.600.12.1.12'; - - my $result = $self->{snmp}->get_table(oid => $oid_powerSupplyStatus); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_powerSupplyType, $oid_powerSupplySensorState, $oid_powerSupplyConfigurationErrorType], - instances => [keys %$result], - instance_regexp => '(\d+\.\d+)$'); - my $result2 = $self->{snmp}->get_leef(); - return if (scalar(keys %$result2) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)\.(\d+)$/; - my ($chassis_Index, $psu_Index) = ($1, $2); - my $instance = $chassis_Index . '.' . $psu_Index; - - my $psu_Status = $result->{$key}; - my $psu_Type = $result2->{$oid_powerSupplyType . '.' . $instance}; - my $psu_SensorState = $result2->{$oid_powerSupplySensorState . '.' . $instance}; - my $psu_ConfigurationErrorType = $result2->{$oid_powerSupplyConfigurationErrorType . '.' . $instance}; - - $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("psu %d status is %s, state is %s [type: %s].", - $psu_Index, ${$status{$psu_Status}}[0], $state{$psu_SensorState}, - $type{$psu_Type} - )); - if ($psu_Status != 3) { - $self->{output}->output_add(severity => ${$status{$psu_Status}}[1], - short_msg => sprintf("psu %d status is %s", - $psu_Index, ${$status{$psu_Status}}[0])); - } - - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/components/temperature.pm b/hardware/server/dell/openmanage/mode/components/temperature.pm deleted file mode 100644 index fc4948fc1..000000000 --- a/hardware/server/dell/openmanage/mode/components/temperature.pm +++ /dev/null @@ -1,100 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::components::temperature; - -use strict; -use warnings; - -my %status = ( - 1 => ['other', 'CRITICAL'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCriticalUpper', 'WARNING'], - 5 => ['criticalUpper', 'CRITICAL'], - 6 => ['nonRecoverableUpper', 'CRITICAL'], - 7 => ['nonCriticalLower', 'WARNING'], - 8 => ['criticalLower', 'CRITICAL'], - 9 => ['nonRecoverableLower', 'CRITICAL'], - 10 => ['failed', 'CRITICAL'], -); - -my %type = ( - 1 => 'other', - 2 => 'unknown', - 3 => 'Ambient ESM', - 4 => 'Discrete', -); - -my %discreteReading = ( - 1 => 'good', - 2 => 'bad', -); - - -sub check { - my ($self) = @_; - - # In MIB '10892.mib' - $self->{output}->output_add(long_msg => "Checking temperature probes"); - $self->{components}->{temperature} = {name => 'temperature probes', total => 0}; - return if ($self->check_exclude('temperature')); - - my $oid_temperatureProbeStatus = '.1.3.6.1.4.1.674.10892.1.700.20.1.5'; - my $oid_temperatureProbeReading = '.1.3.6.1.4.1.674.10892.1.700.20.1.6'; - my $oid_temperatureProbeType = '.1.3.6.1.4.1.674.10892.1.700.20.1.7'; - my $oid_temperatureProbeLocationName = '.1.3.6.1.4.1.674.10892.1.700.20.1.8'; - - my $result = $self->{snmp}->get_table(oid => $oid_temperatureProbeStatus); - return if (scalar(keys %$result) <= 0); - - $self->{snmp}->load(oids => [$oid_temperatureProbeReading, $oid_temperatureProbeType, $oid_temperatureProbeLocationName], - instances => [keys %$result], - instance_regexp => '(\d+\.\d+)$'); - my $result2 = $self->{snmp}->get_leef(); - return if (scalar(keys %$result2) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)\.(\d+)$/; - my ($chassis_Index, $temperature_Index) = ($1, $2); - my $instance = $chassis_Index . '.' . $temperature_Index; - - my $temperature_Status = $result->{$key}; - my $temperature_Reading = $result2->{$oid_temperatureProbeReading . '.' . $instance}; - my $temperature_Type = $result2->{$oid_temperatureProbeType . '.' . $instance}; - my $temperature_LocationName = $result2->{$oid_temperatureProbeLocationName . '.' . $instance}; - - my $temperature_Reading2 = $temperature_Reading/10; - - $self->{components}->{temperature}->{total}++; - $self->{output}->output_add(long_msg => sprintf("temperature probe %d status is %s, temperature is %.1f °C [location: %s].", - $temperature_Index, ${$status{$temperature_Status}}[0], $temperature_Reading2, - $temperature_LocationName - )); - if ($temperature_Status != 3) { - $self->{output}->output_add(severity => ${$status{$temperature_Status}}[1], - short_msg => sprintf("temperature probe %d status is %s", - $temperature_Index, ${$status{$temperature_Status}}[0])); - } - - } -} - -1; diff --git a/hardware/server/dell/openmanage/mode/hardware.pm b/hardware/server/dell/openmanage/mode/hardware.pm deleted file mode 100644 index 1d5872b1c..000000000 --- a/hardware/server/dell/openmanage/mode/hardware.pm +++ /dev/null @@ -1,247 +0,0 @@ -# -# Copyright 2015 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::server::dell::openmanage::mode::hardware; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::misc; -use hardware::server::dell::openmanage::mode::components::globalstatus; -use hardware::server::dell::openmanage::mode::components::fan; -use hardware::server::dell::openmanage::mode::components::psu; -use hardware::server::dell::openmanage::mode::components::temperature; -use hardware::server::dell::openmanage::mode::components::cpu; -use hardware::server::dell::openmanage::mode::components::cachebattery; -use hardware::server::dell::openmanage::mode::components::memory; -use hardware::server::dell::openmanage::mode::components::physicaldisk; -use hardware::server::dell::openmanage::mode::components::logicaldrive; -use hardware::server::dell::openmanage::mode::components::esmlog; -use hardware::server::dell::openmanage::mode::components::battery; -use hardware::server::dell::openmanage::mode::components::controller; -use hardware::server::dell::openmanage::mode::components::connector; - -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' }, - }); - - $self->{product_name} = undef; - $self->{components} = {}; - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - -sub global { - my ($self, %options) = @_; - - $self->get_system_information(); - hardware::server::dell::openmanage::mode::components::globalstatus::check($self); - hardware::server::dell::openmanage::mode::components::fan::check($self); - hardware::server::dell::openmanage::mode::components::psu::check($self); - hardware::server::dell::openmanage::mode::components::temperature::check($self); - hardware::server::dell::openmanage::mode::components::cpu::check($self); - hardware::server::dell::openmanage::mode::components::cachebattery::check($self); - hardware::server::dell::openmanage::mode::components::memory::check($self); - hardware::server::dell::openmanage::mode::components::physicaldisk::check($self); - hardware::server::dell::openmanage::mode::components::logicaldrive::check($self); - hardware::server::dell::openmanage::mode::components::esmlog::check($self); - hardware::server::dell::openmanage::mode::components::battery::check($self); - hardware::server::dell::openmanage::mode::components::controller::check($self); - hardware::server::dell::openmanage::mode::components::connector::check($self); - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (keys %{$self->{components}}) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0); - $total_components += $self->{components}->{$comp}->{total}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components [%s] are ok - Product Name: %s", - $total_components, - $display_by_component, - $self->{product_name}) - ); -} - -sub globalstatus { - my %status = ( - 1 => ['other', 'CRITICAL'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['ok', 'OK'], - 4 => ['nonCritical', 'WARNING'], - 5 => ['critical', 'CRITICAL'], - 6 => ['nonRecoverable', 'CRITICAL'], - ); - - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking global system status"); - return if ($self->check_exclude('globalstatus')); - - my $oid_globalSystemStatus = '.1.3.6.1.4.1.674.10892.1.200.10.1.2.1'; - my $result = $self->{snmp}->get_leef(oids => [$oid_globalSystemStatus], nothing_quit => 1); - - $self->{output}->output_add(long_msg => sprintf("Overall global status is '%s'.", - ${$status{$result->{$oid_globalSystemStatus}}}[0] - )); - - $self->{output}->output_add(severity => ${$status{$result->{$oid_globalSystemStatus}}}[1], - short_msg => sprintf("Overall global status is '%s'", - ${$status{$result->{$oid_globalSystemStatus}}}[0])); -} - -sub component { - my ($self, %options) = @_; - - if ($self->{option_results}->{component} eq 'globalstatus') { - hardware::server::dell::openmanage::mode::components::globalstatus::check($self); - } elsif ($self->{option_results}->{component} eq 'fan') { - hardware::server::dell::openmanage::mode::components::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - hardware::server::dell::openmanage::mode::components::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'temperature') { - hardware::server::dell::openmanage::mode::components::temperature::check($self); - } elsif ($self->{option_results}->{component} eq 'cpu') { - hardware::server::dell::openmanage::mode::components::cpu::check($self); - } elsif ($self->{option_results}->{component} eq 'cachebattery') { - hardware::server::dell::openmanage::mode::components::cachebattery::check($self); - } elsif ($self->{option_results}->{component} eq 'memory') { - hardware::server::dell::openmanage::mode::components::memory::check($self); - } elsif ($self->{option_results}->{component} eq 'physicaldisk') { - hardware::server::dell::openmanage::mode::components::physicaldisk::check($self); - } elsif ($self->{option_results}->{component} eq 'logicaldrive') { - hardware::server::dell::openmanage::mode::components::logicaldrive::check($self); - } elsif ($self->{option_results}->{component} eq 'esmlog') { - hardware::server::dell::openmanage::mode::components::esmlog::check($self); - } elsif ($self->{option_results}->{component} eq 'battery') { - hardware::server::dell::openmanage::mode::components::battery::check($self); - } elsif ($self->{option_results}->{component} eq 'controller') { - hardware::server::dell::openmanage::mode::components::controller::check($self); - } elsif ($self->{option_results}->{component} eq 'connector') { - hardware::server::dell::openmanage::mode::components::connector::check($self); - } elsif ($self->{option_results}->{component} eq 'storage') { - hardware::server::dell::openmanage::mode::components::physicaldisk::check($self); - hardware::server::dell::openmanage::mode::components::logicaldrive::check($self); - hardware::server::dell::openmanage::mode::components::cachebattery::check($self); - hardware::server::dell::openmanage::mode::components::controller::check($self); - hardware::server::dell::openmanage::mode::components::connector::check($self); - hardware::server::dell::openmanage::mode::components::cachebattery::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); - $total_components += $self->{components}->{$comp}->{total}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . ' ' . $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) - ); -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - if ($self->{option_results}->{component} eq 'all') { - $self->global(); - } elsif ($self->{option_results}->{component} eq 'globalstatus') { - $self->globalstatus(); - } else { - $self->component(); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub get_system_information { - my ($self) = @_; - - # In '10892-MIB' - my $oid_chassisModelName = ".1.3.6.1.4.1.674.10892.1.300.10.1.9.1"; - - my $result = $self->{snmp}->get_leef(oids => [$oid_chassisModelName]); - - $self->{product_name} = defined($result->{$oid_chassisModelName}) ? centreon::plugins::misc::trim($result->{$oid_chassisModelName}) : 'unknown'; -} - -sub check_exclude { - my ($self, $section) = @_; - - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$section(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $section section.")); - return 1; - } - return 0; -} - -1; - -__END__ - -=head1 MODE - -Check Hardware (Global status, Fans, CPUs, Power Supplies, Temperature, Storage). - -=over 8 - -=item B<--component> - -Which component to check (Default: 'all'). -Can be: 'globalstatus', 'fan', 'cpu', 'psu', 'temperature', 'cachebattery', 'physicaldisk', 'logicaldrive', 'battery', 'controller', 'connector', 'storage'. - -=item B<--exclude> - -Exclude some parts (comma seperated list) (Example: --exclude=psu,fan). - -=back - -=cut - diff --git a/hardware/server/dell/openmanage/snmp/mode/components/battery.pm b/hardware/server/dell/openmanage/snmp/mode/components/battery.pm new file mode 100644 index 000000000..f9f4443c9 --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/battery.pm @@ -0,0 +1,83 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::battery; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCritical', + 5 => 'critical', + 6 => 'nonRecoverable', +); + +my %map_reading = ( + 1 => 'Predictive Failure', + 2 => 'Failed', + 4 => 'Presence Detected', +); + +# In MIB '10892.mib' +my $mapping = { + batteryStatus => { oid => '.1.3.6.1.4.1.674.10892.1.600.50.1.5', map => \%map_status }, + batteryReading => { oid => '.1.3.6.1.4.1.674.10892.1.600.50.1.6', map => \%map_reading }, + batteryLocationName => { oid => '.1.3.6.1.4.1.674.10892.1.600.50.1.7' }, +}; +my $oid_batteryTableEntry = '.1.3.6.1.4.1.674.10892.1.600.50.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_batteryTableEntry, start => $mapping->{batteryStatus}->{oid}, end => $mapping->{batteryLocationName}->{oid} }; +} + +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_exclude(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)); + + $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}); + 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'", + $instance, $result->{batteryStatus})); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/cachebattery.pm b/hardware/server/dell/openmanage/snmp/mode/components/cachebattery.pm new file mode 100644 index 000000000..0b74c11ca --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/cachebattery.pm @@ -0,0 +1,114 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::cachebattery; + +use strict; +use warnings; + +my %map_state = ( + 0 => 'unknown', + 1 => 'ready', + 2 => 'failed', + 6 => 'degraded', + 7 => 'reconditioning', + 9 => 'high', + 10 => 'powerLow', + 12 => 'charging', + 21 => 'missing', + 36 => 'learning', +); +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCritical', + 5 => 'critical', + 6 => 'nonRecoverable', +); +my %map_learnState = ( + 1 => 'failed', + 2 => 'active', + 4 => 'timedOut', + 8 => 'requested', + 16 => 'idle', + 32 => 'due', +); +my %map_predictedCapacity = ( + 1 => 'failed', + 2 => 'ready', + 4 => 'unknown', +); + +# In MIB 'dcstorag.mib' +my $mapping = { + batteryState => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.15.1.4', map => \%map_state }, +}; +my $mapping2 = { + batteryComponentStatus => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.15.1.6', map => \%map_status }, +}; +my $mapping3 = { + batteryPredictedCapicity => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.15.1.10', map => \%map_predictedCapacity }, +}; +my $mapping4 = { + batteryLearnState => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.15.1.12', map => \%map_learnState }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{batteryState}->{oid} }, { oid => $mapping2->{batteryComponentStatus}->{oid} }, + { oid => $mapping3->{batteryPredictedCapicity}->{oid} }, { oid => $mapping4->{batteryLearnState}->{oid} }; +} + +sub check { + my ($self) = @_; + + $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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping2->{batteryComponentStatus}->{oid}}})) { + next if ($oid !~ /^$mapping2->{batteryComponentStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{batteryState}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{batteryComponentStatus}->{oid}}, instance => $instance); + my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{$mapping3->{batteryPredictedCapicity}->{oid}}, instance => $instance); + my $result4 = $self->{snmp}->map_instance(mapping => $mapping4, results => $self->{results}->{$mapping4->{batteryLearnState}->{oid}}, instance => $instance); + $result4->{batteryLearnState} = defined($result4->{batteryLearnState}) ? $result4->{batteryLearnState} : '-'; + + next if ($self->check_exclude(section => 'cachebattery', instance => $instance)); + + $self->{components}->{cachebattery}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Cache battery '%s' status is '%s' [instance: %s, state: %s, learn state: %s, predicted capacity: %s]", + $instance, $result2->{batteryComponentStatus}, $instance, + $result->{batteryState}, $result4->{batteryLearnState}, $result3->{batteryPredictedCapicity} + )); + my $exit = $self->get_severity(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'", + $instance, $result2->{batteryComponentStatus})); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/connector.pm b/hardware/server/dell/openmanage/snmp/mode/components/connector.pm new file mode 100644 index 000000000..9a56d7d27 --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/connector.pm @@ -0,0 +1,104 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::connector; + +use strict; +use warnings; + +my %map_state = ( + 0 => 'unknown', + 1 => 'ready', + 2 => 'failed', + 3 => 'online', + 4 => 'offline', + 6 => 'degraded', +); +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCritical', + 5 => 'critical', + 6 => 'nonRecoverable', +); +my %map_busType = ( + 1 => 'SCSI', + 2 => 'IDE', + 3 => 'Fibre Channel', + 4 => 'SSA', + 6 => 'USB', + 7 => 'SATA', + 8 => 'SAS', +); + +# In MIB 'dcstorag.mib' +my $mapping = { + channelName => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.2.1.2' }, + channelState => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.2.1.3', map => \%map_state }, +}; +my $mapping2 = { + channelComponentStatus => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.2.1.8', map => \%map_status }, +}; +my $mapping3 = { + channelBusType => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.2.1.11', map => \%map_busType }, +}; +my $oid_channelEntry = '.1.3.6.1.4.1.674.10893.1.20.130.2.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_channelEntry, start => $mapping->{channelName}->{oid}, end => $mapping->{channelState}->{oid} }, + { oid => $mapping2->{channelComponentStatus}->{oid} }, + { oid => $mapping3->{channelBusType}->{oid} } ; +} + +sub check { + my ($self) = @_; + + $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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping2->{channelComponentStatus}->{oid}}})) { + next if ($oid !~ /^$mapping2->{channelComponentStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_channelEntry}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{channelComponentStatus}->{oid}}, instance => $instance); + my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{$mapping3->{channelBusType}->{oid}}, instance => $instance); + + next if ($self->check_exclude(section => 'connector', instance => $instance)); + + $self->{components}->{connector}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Connector '%s' status is '%s' [instance: %s, state: %s, bus type: %s]", + $result->{channelName}, $result2->{channelComponentStatus}, $instance, + $result->{channelState}, $result3->{channelBusType} + )); + my $exit = $self->get_severity(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'", + $result->{channelName}, $result2->{channelComponentStatus})); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/controller.pm b/hardware/server/dell/openmanage/snmp/mode/components/controller.pm new file mode 100644 index 000000000..f05e37e83 --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/controller.pm @@ -0,0 +1,96 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::controller; + +use strict; +use warnings; + +my %map_state = ( + 0 => 'unknown', + 1 => 'ready', + 2 => 'failed', + 3 => 'online', + 4 => 'offline', + 6 => 'degraded', +); +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCritical', + 5 => 'critical', + 6 => 'nonRecoverable', +); + +# In MIB 'dcstorag.mib' +my $mapping = { + controllerName => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.1.1.2' }, +}; +my $mapping2 = { + controllerComponentStatus => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.1.1.38', map => \%map_status }, +}; +my $mapping3 = { + controllerState => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.1.1.5', map => \%map_state }, +}; +my $mapping4 = { + controllerFWVersion => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.1.1.8' }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{controllerName}->{oid} }, { oid => $mapping2->{controllerComponentStatus}->{oid} }, + { oid => $mapping3->{controllerState}->{oid} }, { oid => $mapping4->{controllerFWVersion}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking controllers"); + $self->{components}->{controller} = {name => 'controllers', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'controller')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping2->{controllerComponentStatus}->{oid}}})) { + next if ($oid !~ /^$mapping2->{controllerComponentStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{controllerName}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{controllerComponentStatus}->{oid}}, instance => $instance); + 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)); + + $self->{components}->{controller}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Controller '%s' status is '%s' [instance: %s, state: %s, firmware: %s]", + $result->{controllerName}, $result2->{controllerComponentStatus}, $instance, + $result3->{controllerState}, $result4->{controllerFWVersion} + )); + my $exit = $self->get_severity(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'", + $result->{controllerName}, $result2->{controllerComponentStatus})); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/cpu.pm b/hardware/server/dell/openmanage/snmp/mode/components/cpu.pm new file mode 100644 index 000000000..2a8bce470 --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/cpu.pm @@ -0,0 +1,100 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::cpu; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCritical', + 5 => 'critical', + 6 => 'nonRecoverable', +); +my %map_statusState = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'enabled', + 4 => 'userDisabled', + 5 => 'biosDisabled', + 6 => 'idle', +); + +# In MIB '10892.mib' +my $mapping = { + processorDeviceStatus => { oid => '.1.3.6.1.4.1.674.10892.1.1100.30.1.5', map => \%map_status }, +}; +my $mapping2 = { + processorDeviceManufacturerName => { oid => '.1.3.6.1.4.1.674.10892.1.1100.30.1.8' }, + processorDeviceStatusState => { oid => '.1.3.6.1.4.1.674.10892.1.1100.30.1.9', map => \%map_statusState }, +}; +my $mapping3 = { + processorDeviceCurrentSpeed => { oid => '.1.3.6.1.4.1.674.10892.1.1100.30.1.12' }, # in mHz +}; +my $mapping4 = { + processorDeviceBrandName => { oid => '.1.3.6.1.4.1.674.10892.1.1100.30.1.23' }, +}; +my $oid_processorDeviceTableEntry = '.1.3.6.1.4.1.674.10892.1.1100.30.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{processorDeviceStatus}->{oid} }, + { oid => $oid_processorDeviceTableEntry, start => $mapping2->{processorDeviceManufacturerName}->{oid}, end => $mapping2->{processorDeviceStatusState}->{oid} }, + { oid => $mapping3->{processorDeviceCurrentSpeed}->{oid} }, { oid => $mapping4->{processorDeviceBrandName}->{oid} }; +} + +sub check { + my ($self) = @_; + + $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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{processorDeviceStatus}->{oid}}})) { + next if ($oid !~ /^$mapping->{processorDeviceStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{processorDeviceStatus}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_processorDeviceTableEntry}, instance => $instance); + 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)); + + $self->{components}->{cpu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Cpu '%s' status is '%s' [instance: %s, manufacturer name: %s, brand name: %s, state: %s, speed: %s]", + $instance, $result->{processorDeviceStatus}, $instance, + $result2->{processorDeviceManufacturerName}, $result4->{processorDeviceBrandName}, + $result2->{processorDeviceStatusState}, $result3->{processorDeviceCurrentSpeed} + )); + my $exit = $self->get_severity(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'", + $instance, $result->{processorDeviceStatus})); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/esmlog.pm b/hardware/server/dell/openmanage/snmp/mode/components/esmlog.pm new file mode 100644 index 000000000..da6ff2475 --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/esmlog.pm @@ -0,0 +1,74 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::esmlog; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCritical', + 5 => 'critical', + 6 => 'nonRecoverable', +); + +# In MIB '10892.mib' +my $mapping = { + systemStateEventLogStatus => { oid => '.1.3.6.1.4.1.674.10892.1.200.10.1.41', map => \%map_status }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{systemStateEventLogStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $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')); + + 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)); + + $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}); + 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'", + $instance, $result->{systemStateEventLogStatus})); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/fan.pm b/hardware/server/dell/openmanage/snmp/mode/components/fan.pm new file mode 100644 index 000000000..e29d6bf4f --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/fan.pm @@ -0,0 +1,101 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::fan; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCriticalUpper', + 5 => 'criticalUpper', + 6 => 'nonRecoverableUpper', + 7 => 'nonCriticalLower', + 8 => 'criticalLower', + 9 => 'nonRecoverableLower', + 10 => 'failed', +); + +# In MIB '10892.mib' +my $mapping = { + coolingDeviceStatus => { oid => '.1.3.6.1.4.1.674.10892.1.700.12.1.5', map => \%map_status }, + coolingDeviceReading => { oid => '.1.3.6.1.4.1.674.10892.1.700.12.1.6' }, +}; +my $mapping2 = { + coolingDeviceLocationName => { oid => '.1.3.6.1.4.1.674.10892.1.700.12.1.8' }, +}; +my $oid_coolingDeviceTableEntry = '.1.3.6.1.4.1.674.10892.1.700.12.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_coolingDeviceTableEntry, start => $mapping->{coolingDeviceStatus}->{oid}, end => $mapping->{coolingDeviceReading}->{oid} }, + { oid => $mapping2->{coolingDeviceLocationName}->{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_exclude(section => 'fan')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_coolingDeviceTableEntry}})) { + next if ($oid !~ /^$mapping->{coolingDeviceStatus}->{oid}\.(.*)$/); + my $instance = $1; + 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)); + + $self->{components}->{fan}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is '%s' [instance: %s, Location: %s, reading: %s]", + $instance, $result->{coolingDeviceStatus}, $instance, + $result2->{coolingDeviceLocationName}, $result->{coolingDeviceReading} + )); + my $exit = $self->get_severity(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'", + $instance, $result->{coolingDeviceStatus})); + } + + if (defined($result->{coolingDeviceReading}) && $result->{coolingDeviceReading} =~ /[0-9]/) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{coolingDeviceReading}); + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' speed is %s rpm", $instance, $result->{coolingDeviceReading})); + } + $self->{output}->perfdata_add(label => 'fan_' . $instance, unit => 'rpm', + value => $result->{coolingDeviceReading}, + warning => $warn, + critical => $crit, + min => 0 + ); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/globalstatus.pm b/hardware/server/dell/openmanage/snmp/mode/components/globalstatus.pm new file mode 100644 index 000000000..aee0ebb5d --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/globalstatus.pm @@ -0,0 +1,74 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::globalstatus; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCritical', + 5 => 'critical', + 6 => 'nonRecoverable', +); + +# In MIB '10892.mib' +my $mapping = { + globalSystemStatus => { oid => '.1.3.6.1.4.1.674.10892.1.200.10.1.2', map => \%map_status }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{globalSystemStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $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')); + + 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)); + + $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}); + 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'", + $instance, $result->{globalSystemStatus})); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/logicaldrive.pm b/hardware/server/dell/openmanage/snmp/mode/components/logicaldrive.pm new file mode 100644 index 000000000..81bb675ad --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/logicaldrive.pm @@ -0,0 +1,126 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::logicaldrive; + +use strict; +use warnings; + +my %map_state = ( + 0 => 'unknown', + 1 => 'ready', + 2 => 'failed', + 3 => 'online', + 4 => 'offline', + 6 => 'degraded', + 15 => 'resynching', + 24 => 'rebuild', + 26 => 'formatting', + 35 => 'initializing', +); +my %map_layout = ( + 1 => 'Concatened', + 2 => 'RAID-0', + 3 => 'RAID-1', + 4 => 'RAID-2', + 5 => 'RAID-3', + 6 => 'RAID-4', + 7 => 'RAID-5', + 8 => 'RAID-6', + 9 => 'RAID-7', + 10 => 'RAID-10', + 11 => 'RAID-30', + 12 => 'RAID-50', + 13 => 'Add spares', + 14 => 'Delete logical', + 15 => 'Transform logical', + 18 => 'RAID-0-plus-1 - Mylex only', + 19 => 'Concatened RAID 1', + 20 => 'Concatened RAID 5', + 21 => 'no RAID', + 22 => 'RAID Morph - Adapted only', +); +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCritical', + 5 => 'critical', + 6 => 'nonRecoverable', +); + +# In MIB 'dcstorag.mib' +my $mapping = { + virtualDiskName => { oid => '.1.3.6.1.4.1.674.10893.1.20.140.1.1.2' }, + virtualDiskDeviceName => { oid => '.1.3.6.1.4.1.674.10893.1.20.140.1.1.3' }, + virtualDiskState => { oid => '.1.3.6.1.4.1.674.10893.1.20.140.1.1.4', map => \%map_state }, +}; +my $mapping2 = { + virtualDiskLengthInMB => { oid => '.1.3.6.1.4.1.674.10893.1.20.140.1.1.6' }, +}; +my $mapping3 = { + virtualDiskLayout => { oid => '.1.3.6.1.4.1.674.10893.1.20.140.1.1.13', map => \%map_layout }, +}; +my $mapping4 = { + virtualDiskComponentStatus => { oid => '.1.3.6.1.4.1.674.10893.1.20.140.1.1.20', map => \%map_status }, +}; +my $oid_virtualDiskEntry = '.1.3.6.1.4.1.674.10893.1.20.140.1.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_virtualDiskEntry, start => $mapping->{virtualDiskName}->{oid}, end => $mapping->{virtualDiskState}->{oid} }, + { oid => $mapping2->{virtualDiskLengthInMB}->{oid} }, { oid => $mapping3->{virtualDiskLayout}->{oid} }, { oid => $mapping4->{virtualDiskComponentStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping4->{virtualDiskComponentStatus}->{oid}}})) { + next if ($oid !~ /^$mapping4->{virtualDiskComponentStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_virtualDiskEntry}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{virtualDiskLengthInMB}->{oid}}, instance => $instance); + 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)); + + $self->{components}->{logicaldrive}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Logical drive '%s' status is '%s' [instance: %s, size: %s MB, layout: %s, state: %s, device name: %s]", + $result->{virtualDiskName}, $result4->{virtualDiskComponentStatus}, $instance, + $result2->{virtualDiskLengthInMB}, $result3->{virtualDiskLayout}, + $result->{virtualDiskState}, $result->{virtualDiskDeviceName} + )); + my $exit = $self->get_severity(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'", + $result->{virtualDiskName}, $result4->{virtualDiskComponentStatus})); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/memory.pm b/hardware/server/dell/openmanage/snmp/mode/components/memory.pm new file mode 100644 index 000000000..120e2017f --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/memory.pm @@ -0,0 +1,97 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::memory; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCritical', + 5 => 'critical', + 6 => 'nonRecoverable', +); +my %map_failureModes = ( + 0 => 'Not failure', + 1 => 'ECC single bit correction warning rate exceeded', + 2 => 'ECC single bit correction failure rate exceeded', + 4 => 'ECC multibit fault encountered', + 8 => 'ECC single bit correction logging disabled', + 16 => 'device disabled because of spare activation', +); + +# In MIB '10892.mib' +my $mapping = { + memoryDeviceStatus => { oid => '.1.3.6.1.4.1.674.10892.1.1100.50.1.5', map => \%map_status }, +}; +my $mapping2 = { + memoryDeviceLocationName => { oid => '.1.3.6.1.4.1.674.10892.1.1100.50.1.8' }, +}; +my $mapping3 = { + memoryDeviceSize => { oid => '.1.3.6.1.4.1.674.10892.1.1100.50.1.14' }, +}; +my $mapping4 = { + memoryDeviceFailureModes => { oid => '.1.3.6.1.4.1.674.10892.1.1100.50.1.20', map => \%map_failureModes }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{memoryDeviceStatus}->{oid} }, { oid => $mapping2->{memoryDeviceLocationName}->{oid} }, + { oid => $mapping3->{memoryDeviceSize}->{oid} }, { oid => $mapping4->{memoryDeviceFailureModes}->{oid} }; +} + + +sub check { + my ($self) = @_; + + $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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{memoryDeviceStatus}->{oid}}})) { + next if ($oid !~ /^$mapping->{memoryDeviceStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{memoryDeviceStatus}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{memoryDeviceLocationName}->{oid}}, instance => $instance); + 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)); + + $self->{components}->{memory}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Memory module '%s' status is '%s' [instance: %s, Location: %s, Size: %s MB, Failure mode: %s]", + $instance, $result->{memoryDeviceStatus}, $instance, + $result2->{memoryDeviceLocationName}, $result3->{memoryDeviceSize}, $result4->{memoryDeviceFailureModes} + )); + my $exit = $self->get_severity(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'", + $instance, $result->{memoryDeviceStatus})); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/physicaldisk.pm b/hardware/server/dell/openmanage/snmp/mode/components/physicaldisk.pm new file mode 100644 index 000000000..b956ae89a --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/physicaldisk.pm @@ -0,0 +1,128 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::physicaldisk; + +use strict; +use warnings; + +my %map_state = ( + 0 => 'unknown', + 1 => 'ready', + 2 => 'failed', + 3 => 'online', + 4 => 'offline', + 6 => 'degraded', + 7 => 'recovering', + 11 => 'removed', + 15 => 'resynching', + 24 => 'rebuild', + 25 => 'noMedia', + 26 => 'formatting', + 28 => 'diagnostics', + 35 => 'initializing', +); +my %map_spareState = ( + 1 => 'memberVD', + 2 => 'memberDG', + 3 => 'globalHostSpare', + 4 => 'dedicatedHostSpare', + 5 => 'notASpare', +); +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCritical', + 5 => 'critical', + 6 => 'nonRecoverable', +); +my %map_smartAlertIndication = ( + 1 => 'no', + 2 => 'yes', +); + +# In MIB 'dcstorag.mib' +my $mapping = { + arrayDiskName => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.4.1.2' }, +}; +my $mapping2 = { + arrayDiskState => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.4.1.4', map => \%map_state }, +}; +my $mapping3 = { + arrayDiskSpareState => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.4.1.22', map => \%map_spareState }, +}; +my $mapping4 = { + arrayDiskComponentStatus => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.4.1.24', map => \%map_status }, +}; +my $mapping5 = { + arrayDiskSmartAlertIndication => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.4.1.31', map => \%map_smartAlertIndication }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{arrayDiskName}->{oid} }, { oid => $mapping2->{arrayDiskState}->{oid} }, + { oid => $mapping3->{arrayDiskSpareState}->{oid} }, { oid => $mapping4->{arrayDiskComponentStatus}->{oid} }, + { oid => $mapping5->{arrayDiskSmartAlertIndication}->{oid} }; +} + + +sub check { + my ($self) = @_; + + $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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping4->{arrayDiskComponentStatus}->{oid}}})) { + next if ($oid !~ /^$mapping4->{arrayDiskComponentStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{arrayDiskName}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{arrayDiskState}->{oid}}, instance => $instance); + my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{$mapping3->{arrayDiskSpareState}->{oid}}, instance => $instance); + 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)); + + $self->{components}->{physicaldisk}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Physical Disk '%s' status is '%s' [instance: %s, state: %s, spare state: %s, smart alert: %s]", + $result->{arrayDiskName}, $result4->{arrayDiskComponentStatus}, $instance, + $result2->{arrayDiskState}, $result3->{arrayDiskSpareState}, $result5->{arrayDiskSmartAlertIndication} + )); + my $exit = $self->get_severity(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'", + $result->{arrayDiskName}, $result4->{arrayDiskComponentStatus})); + } + + $exit = $self->get_severity(section => 'physicaldisk_smartalert', value => $result5->{arrayDiskSmartAlertIndication}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("physical disk '%s' has received a predictive failure alert", + $result->{arrayDiskName})); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/psu.pm b/hardware/server/dell/openmanage/snmp/mode/components/psu.pm new file mode 100644 index 000000000..276d22528 --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/psu.pm @@ -0,0 +1,131 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCritical', + 5 => 'critical', + 6 => 'nonRecoverable', +); +my %map_type = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'Linear', + 4 => 'switching', + 5 => 'Battery', + 6 => 'UPS', + 7 => 'Converter', + 8 => 'Regulator', + 9 => 'AC', + 10 => 'DC', + 11 => 'VRM', +); +my %map_state = ( + 1 => 'present', + 2 => 'failure', + 4 => 'predictiveFailure', + 8 => 'ACLost', + 16 => 'ACLostOrOutOfRange', + 32 => 'ACPresentButOutOfRange', + 64 => 'configurationError', +); +my %map_ConfigurationErrorType = ( + 1 => 'vendorMismatch', + 2 => 'revisionMismatch', + 3 => 'processorMissing', +); + +# In MIB '10892.mib' +my $mapping = { + powerSupplyStatus => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.5', map => \%map_status }, + powerSupplyOutputWatts => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.6' }, + powerSupplyType => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.7', map => \%map_type }, + powerSupplyLocationName => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.8' }, +}; +my $mapping2 = { + powerSupplySensorState => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.11', map => \%map_state }, + powerSupplyConfigurationErrorType => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.12', map => \%map_ConfigurationErrorType }, +}; +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) = @_; + + push @{$options{request}}, { oid => $oid_powerSupplyTable, start => $mapping->{powerSupplyStatus}->{oid}, end => $mapping->{powerSupplyLocationName}->{oid} }, + { oid => $oid_powerSupplyTableEntry, start => $mapping2->{powerSupplySensorState}->{oid}, end => $mapping2->{powerSupplyConfigurationErrorType}->{oid} }; +} + +sub check { + my ($self) = @_; + + $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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerSupplyTable}})) { + next if ($oid !~ /^$mapping->{powerSupplyStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_powerSupplyTable}, instance => $instance); + 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)); + + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s' [instance: %s, location: %s, type: %s, output watts: %s, state: %s, configuration error: %s]", + $instance, $result->{powerSupplyStatus}, $instance, + $result->{powerSupplyLocationName}, $result->{powerSupplyType}, $result->{powerSupplyOutputWatts}, + $result2->{powerSupplySensorState}, $result2->{powerSupplyConfigurationErrorType} + )); + my $exit = $self->get_severity(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'", + $instance, $result->{powerSupplyStatus})); + } + + if (defined($result->{powerSupplyOutputWatts}) && $result->{powerSupplyOutputWatts} =~ /[0-9]/) { + $result->{powerSupplyOutputWatts} /= 10; + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'psu.power', instance => $instance, value => $result->{powerSupplyOutputWatts}); + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' power is %s W", $instance, $result->{powerSupplyOutputWatts})); + } + $self->{output}->perfdata_add(label => 'psu_power_' . $instance, unit => 'W', + value => $result->{powerSupplyOutputWatts}, + warning => $warn, + critical => $crit, + min => 0 + ); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/components/temperature.pm b/hardware/server/dell/openmanage/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..0a3fd9de5 --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/components/temperature.pm @@ -0,0 +1,105 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::components::temperature; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'nonCriticalUpper', + 5 => 'criticalUpper', + 6 => 'nonRecoverableUpper', + 7 => 'nonCriticalLower', + 8 => 'criticalLower', + 9 => 'nonRecoverableLower', + 10 => 'failed', +); +my %map_type = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'Ambient ESM', + 4 => 'Discrete', +); + +# In MIB '10892.mib' +my $mapping = { + temperatureProbeStatus => { oid => '.1.3.6.1.4.1.674.10892.1.700.20.1.5', map => \%map_status }, + temperatureProbeReading => { oid => '.1.3.6.1.4.1.674.10892.1.700.20.1.6' }, + temperatureProbeType => { oid => '.1.3.6.1.4.1.674.10892.1.700.20.1.7', map => \%map_type }, + temperatureProbeLocationName => { oid => '.1.3.6.1.4.1.674.10892.1.700.20.1.8' }, +}; +my $oid_temperatureProbeTable = '.1.3.6.1.4.1.674.10892.1.700.20'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_temperatureProbeTable, start => $mapping->{temperatureProbeStatus}->{oid}, end => $mapping->{temperatureProbeLocationName}->{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_exclude(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)); + + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is '%s' [instance: %s, location: %s, reading: %s]", + $instance, $result->{temperatureProbeStatus}, $instance, + $result->{temperatureProbeLocationName}, $result->{temperatureProbeReading} + )); + my $exit = $self->get_severity(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'", + $instance, $result->{temperatureProbeStatus})); + } + + if (defined($result->{temperatureProbeReading}) && $result->{temperatureProbeReading} =~ /[0-9]/) { + $result->{temperatureProbeReading} /= 10; + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{temperatureProbeReading}); + + 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", $instance, $result->{temperatureProbeReading})); + } + $self->{output}->perfdata_add(label => 'temp_' . $instance, unit => 'C', + value => $result->{temperatureProbeReading}, + warning => $warn, + critical => $crit, + min => 0 + ); + } + } +} + +1; diff --git a/hardware/server/dell/openmanage/snmp/mode/hardware.pm b/hardware/server/dell/openmanage/snmp/mode/hardware.pm new file mode 100644 index 000000000..4f2b6055b --- /dev/null +++ b/hardware/server/dell/openmanage/snmp/mode/hardware.pm @@ -0,0 +1,400 @@ +# +# Copyright 2015 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::server::dell::openmanage::snmp::mode::hardware; + +use base qw(centreon::plugins::mode); + +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 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} = {}; + 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) = @_; + # $options{snmp} = snmp object + $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__ + +=head1 MODE + +Check Hardware (Global status, Fans, CPUs, Power Supplies, Temperature, Storage). + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'globalstatus', 'fan', 'cpu', 'psu', 'temperature', 'cachebattery', +'physicaldisk', 'logicaldrive', 'battery', 'controller', 'connector'. + +=item B<--exclude> + +Exclude some parts (comma seperated list) (Example: --exclude=fan,cpu) +Can also exclude specific instance: --exclude=fan#1#,cpu + +=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='temperature,CRITICAL,^(?!(ok)$)' + +=item B<--warning> + +Set warning threshold for temperature, psu.power or fan (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for temperature, psu.power or fan (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,40' + +=back + +=cut + diff --git a/hardware/server/dell/openmanage/plugin.pm b/hardware/server/dell/openmanage/snmp/plugin.pm similarity index 93% rename from hardware/server/dell/openmanage/plugin.pm rename to hardware/server/dell/openmanage/snmp/plugin.pm index 960f748ef..bf8a1dbda 100644 --- a/hardware/server/dell/openmanage/plugin.pm +++ b/hardware/server/dell/openmanage/snmp/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package hardware::server::dell::openmanage::plugin; +package hardware::server::dell::openmanage::snmp::plugin; use strict; use warnings; @@ -32,7 +32,7 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'hardware::server::dell::openmanage::mode::hardware', + 'hardware' => 'hardware::server::dell::openmanage::snmp::mode::hardware', ); return $self; diff --git a/network/alcatel/omniswitch/6850/plugin.pm b/network/alcatel/omniswitch/6850/plugin.pm index 99ecfe72a..356ead358 100644 --- a/network/alcatel/omniswitch/6850/plugin.pm +++ b/network/alcatel/omniswitch/6850/plugin.pm @@ -34,12 +34,11 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'network::alcatel::common::mode::cpu', 'hardware' => 'network::alcatel::common::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'flash-memory' => 'network::alcatel::common::mode::flashmemory', 'memory' => 'network::alcatel::common::mode::memory', - 'packet-errors' => 'snmp_standard::mode::packeterrors', 'spanning-tree' => 'snmp_standard::mode::spanningtree', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/arkoon/plugin.pm b/network/arkoon/plugin.pm index 51b4568b1..2cda06cba 100644 --- a/network/arkoon/plugin.pm +++ b/network/arkoon/plugin.pm @@ -37,9 +37,8 @@ sub new { 'swap' => 'snmp_standard::mode::swap', 'inodes' => 'snmp_standard::mode::inodes', 'processcount' => 'snmp_standard::mode::processcount', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'packet-errors' => 'snmp_standard::mode::packeterrors', - 'traffic' => 'snmp_standard::mode::traffic', 'uptime' => 'snmp_standard::mode::uptime', ); diff --git a/network/aruba/standard/snmp/plugin.pm b/network/aruba/standard/snmp/plugin.pm index ceb8648b1..eb7d82c95 100644 --- a/network/aruba/standard/snmp/plugin.pm +++ b/network/aruba/standard/snmp/plugin.pm @@ -36,9 +36,8 @@ sub new { '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', - 'packet-errors' => 'snmp_standard::mode::packeterrors', - 'traffic' => 'snmp_standard::mode::traffic', 'memory' => 'centreon::common::aruba::snmp::mode::memory', 'storage' => 'centreon::common::aruba::snmp::mode::storage', ); diff --git a/network/brocade/plugin.pm b/network/brocade/plugin.pm index 66d696b8e..0a1743275 100644 --- a/network/brocade/plugin.pm +++ b/network/brocade/plugin.pm @@ -32,10 +32,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::brocade::mode::cpu', - 'hardware' => 'network::brocade::mode::hardware', - 'memory' => 'network::brocade::mode::memory', - 'traffic' => 'snmp_standard::mode::traffic', + 'cpu' => 'network::brocade::mode::cpu', + 'hardware' => 'network::brocade::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::brocade::mode::memory', ); return $self; diff --git a/network/cisco/asa/plugin.pm b/network/cisco/asa/plugin.pm index b8fd96a8f..2aa3c2e11 100644 --- a/network/cisco/asa/plugin.pm +++ b/network/cisco/asa/plugin.pm @@ -34,11 +34,10 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'centreon::common::cisco::standard::snmp::mode::cpu', 'failover' => 'network::cisco::asa::mode::failover', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'centreon::common::cisco::standard::snmp::mode::memory', - 'packet-errors' => 'snmp_standard::mode::packeterrors', 'sessions' => 'network::cisco::asa::mode::sessions', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/cisco/ironport/snmp/plugin.pm b/network/cisco/ironport/snmp/plugin.pm index 73e8c287e..7cfce585a 100644 --- a/network/cisco/ironport/snmp/plugin.pm +++ b/network/cisco/ironport/snmp/plugin.pm @@ -34,9 +34,9 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'network::cisco::ironport::snmp::mode::cpu', 'hardware' => 'network::cisco::ironport::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'network::cisco::ironport::snmp::mode::memory', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/cisco/smallbusiness/standard/snmp/plugin.pm b/network/cisco/smallbusiness/standard/snmp/plugin.pm index 655f62016..d86c42f5f 100644 --- a/network/cisco/smallbusiness/standard/snmp/plugin.pm +++ b/network/cisco/smallbusiness/standard/snmp/plugin.pm @@ -34,10 +34,9 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'centreon::common::cisco::smallbusiness::snmp::mode::cpu', 'environment' => 'centreon::common::cisco::smallbusiness::snmp::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'packet-errors' => 'snmp_standard::mode::packeterrors', 'spanning-tree' => 'snmp_standard::mode::spanningtree', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/cisco/standard/snmp/plugin.pm b/network/cisco/standard/snmp/plugin.pm index a1923bcbb..7890a70d0 100644 --- a/network/cisco/standard/snmp/plugin.pm +++ b/network/cisco/standard/snmp/plugin.pm @@ -32,17 +32,15 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'anycast' => 'snmp_standard::mode::anycast', 'cpu' => 'centreon::common::cisco::standard::snmp::mode::cpu', 'environment' => 'centreon::common::cisco::standard::snmp::mode::environment', 'hsrp' => 'centreon::common::cisco::standard::snmp::mode::hsrp', + 'interfaces' => 'snmp_standard::mode::interfaces', 'ipsla' => 'centreon::common::cisco::standard::snmp::mode::ipsla', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'centreon::common::cisco::standard::snmp::mode::memory', - 'packet-errors' => 'snmp_standard::mode::packeterrors', 'spanning-tree' => 'snmp_standard::mode::spanningtree', 'stack' => 'centreon::common::cisco::standard::snmp::mode::stack', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/cisco/wlc/snmp/plugin.pm b/network/cisco/wlc/snmp/plugin.pm index e914a4c56..c76e60fc5 100644 --- a/network/cisco/wlc/snmp/plugin.pm +++ b/network/cisco/wlc/snmp/plugin.pm @@ -38,9 +38,9 @@ sub new { 'ap-users' => 'centreon::common::airespace::snmp::mode::apusers', 'cpu' => 'centreon::common::airespace::snmp::mode::cpu', 'hardware' => 'centreon::common::airespace::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'centreon::common::airespace::snmp::mode::memory', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/citrix/netscaler/mpx8000/plugin.pm b/network/citrix/netscaler/mpx8000/plugin.pm index 12183b270..960a164c3 100644 --- a/network/citrix/netscaler/mpx8000/plugin.pm +++ b/network/citrix/netscaler/mpx8000/plugin.pm @@ -37,11 +37,11 @@ sub new { 'storage' => 'network::citrix::netscaler::common::mode::storage', 'health' => 'network::citrix::netscaler::common::mode::health', 'ha-state' => 'network::citrix::netscaler::common::mode::hastate', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-vservers' => 'network::citrix::netscaler::common::mode::listvservers', 'vserver-status' => 'network::citrix::netscaler::common::mode::vserverstatus', 'memory' => 'network::citrix::netscaler::common::mode::memory', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/dell/6200/plugin.pm b/network/dell/6200/plugin.pm index 31e9cd77b..3e76e88a5 100644 --- a/network/dell/6200/plugin.pm +++ b/network/dell/6200/plugin.pm @@ -34,9 +34,9 @@ sub new { %{$self->{modes}} = ( 'global-status' => 'centreon::common::dell::powerconnect3000::mode::globalstatus', 'environment' => 'centreon::common::fastpath::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', 'memory' => 'centreon::common::fastpath::mode::memory', 'cpu' => 'centreon::common::fastpath::mode::cpu', - 'traffic' => 'snmp_standard::mode::traffic', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', ); diff --git a/network/dell/n4000/plugin.pm b/network/dell/n4000/plugin.pm index 26fe83ab6..de13e704c 100644 --- a/network/dell/n4000/plugin.pm +++ b/network/dell/n4000/plugin.pm @@ -34,9 +34,9 @@ sub new { %{$self->{modes}} = ( 'global-status' => 'centreon::common::dell::powerconnect3000::mode::globalstatus', 'environment' => 'centreon::common::fastpath::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', 'memory' => 'centreon::common::fastpath::mode::memory', 'cpu' => 'centreon::common::fastpath::mode::cpu', - 'traffic' => 'snmp_standard::mode::traffic', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', ); diff --git a/network/dlink/dgs3100/snmp/plugin.pm b/network/dlink/dgs3100/snmp/plugin.pm index 610408605..cc4836f62 100644 --- a/network/dlink/dgs3100/snmp/plugin.pm +++ b/network/dlink/dgs3100/snmp/plugin.pm @@ -34,8 +34,8 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'network::dlink::dgs3100::snmp::mode::cpu', 'hardware' => 'network::dlink::dgs3100::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/dlink/standard/snmp/plugin.pm b/network/dlink/standard/snmp/plugin.pm index 5d1dae640..ade75917d 100644 --- a/network/dlink/standard/snmp/plugin.pm +++ b/network/dlink/standard/snmp/plugin.pm @@ -34,8 +34,8 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'network::dlink::standard::snmp::mode::cpu', 'hardware' => 'network::dlink::standard::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/extreme/snmp/plugin.pm b/network/extreme/snmp/plugin.pm index 90f84e6a2..4c2441ef5 100644 --- a/network/extreme/snmp/plugin.pm +++ b/network/extreme/snmp/plugin.pm @@ -34,10 +34,10 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'network::extreme::snmp::mode::cpu', 'hardware' => 'network::extreme::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'network::extreme::snmp::mode::memory', 'stack' => 'network::extreme::snmp::mode::stack', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/f5/bigip/mode/poolstatus.pm b/network/f5/bigip/mode/poolstatus.pm index 7740de461..4c0787f54 100644 --- a/network/f5/bigip/mode/poolstatus.pm +++ b/network/f5/bigip/mode/poolstatus.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use centreon::plugins::values; my $thresholds = { pool => [ diff --git a/network/fortinet/fortigate/plugin.pm b/network/fortinet/fortigate/plugin.pm index 907b04635..ec7970c82 100644 --- a/network/fortinet/fortigate/plugin.pm +++ b/network/fortinet/fortigate/plugin.pm @@ -36,11 +36,11 @@ sub new { 'cpu' => 'centreon::common::fortinet::fortigate::mode::cpu', 'disk' => 'centreon::common::fortinet::fortigate::mode::disk', 'hardware' => 'centreon::common::fortinet::fortigate::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'ips-stats' => 'centreon::common::fortinet::fortigate::mode::ipsstats', 'list-virtualdomains' => 'centreon::common::fortinet::fortigate::mode::listvirtualdomains', 'memory' => 'centreon::common::fortinet::fortigate::mode::memory', 'sessions' => 'centreon::common::fortinet::fortigate::mode::sessions', - 'traffic' => 'snmp_standard::mode::traffic', 'virus' => 'centreon::common::fortinet::fortigate::mode::virus', ); diff --git a/network/h3c/snmp/plugin.pm b/network/h3c/snmp/plugin.pm index b6d4f67ed..9c9fcd65b 100644 --- a/network/h3c/snmp/plugin.pm +++ b/network/h3c/snmp/plugin.pm @@ -34,9 +34,9 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'network::h3c::snmp::mode::cpu', 'hardware' => 'network::h3c::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'network::h3c::snmp::mode::memory', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/hirschmann/standard/snmp/plugin.pm b/network/hirschmann/standard/snmp/plugin.pm index 0289a32d1..6a35b8220 100644 --- a/network/hirschmann/standard/snmp/plugin.pm +++ b/network/hirschmann/standard/snmp/plugin.pm @@ -34,10 +34,10 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'network::hirschmann::standard::snmp::mode::cpu', 'hardware' => 'network::hirschmann::standard::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'network::hirschmann::standard::snmp::mode::memory', 'processcount' => 'network::hirschmann::standard::snmp::mode::processcount', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/hp/procurve/plugin.pm b/network/hp/procurve/plugin.pm index 5c2382b02..c8f4132eb 100644 --- a/network/hp/procurve/plugin.pm +++ b/network/hp/procurve/plugin.pm @@ -34,10 +34,9 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'network::hp::procurve::mode::cpu', 'environment' => 'network::hp::procurve::mode::environment', - 'memory' => 'network::hp::procurve::mode::memory', - 'packet-errors' => 'snmp_standard::mode::packeterrors', - 'traffic' => 'snmp_standard::mode::traffic', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::hp::procurve::mode::memory', ); return $self; diff --git a/network/juniper/ex/plugin.pm b/network/juniper/ex/plugin.pm index 8bc837ca4..83887f372 100644 --- a/network/juniper/ex/plugin.pm +++ b/network/juniper/ex/plugin.pm @@ -35,7 +35,7 @@ sub new { '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 - 'traffic' => 'snmp_standard::mode::traffic', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', 'storage' => 'snmp_standard::mode::storage', diff --git a/network/juniper/mag/plugin.pm b/network/juniper/mag/plugin.pm index 8a853423a..afefe878e 100644 --- a/network/juniper/mag/plugin.pm +++ b/network/juniper/mag/plugin.pm @@ -34,11 +34,12 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'network::juniper::common::ive::mode::cpu', 'disk' => 'network::juniper::common::ive::mode::disk', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'logfile' => 'network::juniper::common::ive::mode::logfile', 'users' => 'network::juniper::common::ive::mode::users', 'memory' => 'snmp_standard::mode::memory', 'swap' => 'snmp_standard::mode::swap', - 'traffic' => 'snmp_standard::mode::traffic', 'blade-temperature' => 'network::juniper::mag::mode::bladetemperature', ); diff --git a/network/juniper/mseries/plugin.pm b/network/juniper/mseries/plugin.pm index ab4ee4035..a45395f36 100644 --- a/network/juniper/mseries/plugin.pm +++ b/network/juniper/mseries/plugin.pm @@ -35,7 +35,7 @@ sub new { '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 - 'traffic' => 'snmp_standard::mode::traffic', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', 'storage' => 'snmp_standard::mode::storage', diff --git a/network/juniper/sa/plugin.pm b/network/juniper/sa/plugin.pm index cd2ece925..5cbd1cb6b 100644 --- a/network/juniper/sa/plugin.pm +++ b/network/juniper/sa/plugin.pm @@ -37,9 +37,10 @@ sub new { 'disk' => 'network::juniper::common::ive::mode::disk', 'logfile' => 'network::juniper::common::ive::mode::logfile', 'users' => 'network::juniper::common::ive::mode::users', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'snmp_standard::mode::memory', 'swap' => 'snmp_standard::mode::swap', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/juniper/srx/plugin.pm b/network/juniper/srx/plugin.pm index ebb37b9bf..4b6eb3b09 100644 --- a/network/juniper/srx/plugin.pm +++ b/network/juniper/srx/plugin.pm @@ -39,7 +39,7 @@ sub new { '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', - 'traffic' => 'snmp_standard::mode::traffic', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', 'storage' => 'snmp_standard::mode::storage', diff --git a/network/juniper/ssg/plugin.pm b/network/juniper/ssg/plugin.pm index f95d2104c..bd4f9f759 100644 --- a/network/juniper/ssg/plugin.pm +++ b/network/juniper/ssg/plugin.pm @@ -32,12 +32,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::juniper::common::screenos::mode::cpu', - 'memory' => 'network::juniper::common::screenos::mode::memory', - 'sessions' => 'network::juniper::common::screenos::mode::sessions', - 'hardware' => 'network::juniper::common::screenos::mode::hardware', - 'traffic' => 'snmp_standard::mode::traffic', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'cpu' => 'network::juniper::common::screenos::mode::cpu', + 'memory' => 'network::juniper::common::screenos::mode::memory', + 'sessions' => 'network::juniper::common::screenos::mode::sessions', + 'hardware' => 'network::juniper::common::screenos::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', ); return $self; diff --git a/network/netasq/snmp/plugin.pm b/network/netasq/snmp/plugin.pm index eba8bf06f..e79cbd440 100644 --- a/network/netasq/snmp/plugin.pm +++ b/network/netasq/snmp/plugin.pm @@ -34,12 +34,13 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'snmp_standard::mode::cpu', 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'load' => 'snmp_standard::mode::loadaverage', 'ha-status' => 'network::netasq::snmp::mode::hastatus', 'memory' => 'snmp_standard::mode::memory', 'storage' => 'snmp_standard::mode::storage', 'swap' => 'snmp_standard::mode::swap', - 'traffic' => 'snmp_standard::mode::traffic', 'vpn-status' => 'network::netasq::snmp::mode::vpnstatus', ); diff --git a/network/oneaccess/snmp/plugin.pm b/network/oneaccess/snmp/plugin.pm index 944ce698a..23d0a2ee5 100644 --- a/network/oneaccess/snmp/plugin.pm +++ b/network/oneaccess/snmp/plugin.pm @@ -33,9 +33,9 @@ sub new { $self->{version} = '0.5'; %{$self->{modes}} = ( 'cpu' => 'network::oneaccess::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'network::oneaccess::snmp::mode::memory', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/paloalto/snmp/plugin.pm b/network/paloalto/snmp/plugin.pm index 1b763c8bd..9b0365d2d 100644 --- a/network/paloalto/snmp/plugin.pm +++ b/network/paloalto/snmp/plugin.pm @@ -34,10 +34,9 @@ sub new { %{$self->{modes}} = ( 'cluster-status' => 'network::paloalto::snmp::mode::clusterstatus', 'cpu' => 'snmp_standard::mode::cpu', - 'traffic' => 'snmp_standard::mode::traffic', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'hardware' => 'snmp_standard::mode::hardwaredevice', - 'packet-errors' => 'snmp_standard::mode::packeterrors', 'panorama' => 'network::paloalto::snmp::mode::panorama', 'sessions' => 'network::paloalto::snmp::mode::sessions', ); diff --git a/network/redback/snmp/plugin.pm b/network/redback/snmp/plugin.pm index d15189f09..bde6e4636 100644 --- a/network/redback/snmp/plugin.pm +++ b/network/redback/snmp/plugin.pm @@ -35,10 +35,9 @@ sub new { 'cpu' => 'network::redback::snmp::mode::cpu', 'disk-usage' => 'network::redback::snmp::mode::disk', 'hardware' => 'network::redback::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'network::redback::snmp::mode::memory', - 'packet-errors' => 'snmp_standard::mode::packeterrors', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/network/ruggedcom/plugin.pm b/network/ruggedcom/plugin.pm index 8c2395e6b..d387ef2d4 100644 --- a/network/ruggedcom/plugin.pm +++ b/network/ruggedcom/plugin.pm @@ -34,9 +34,9 @@ sub new { %{$self->{modes}} = ( 'errors' => 'network::ruggedcom::mode::errors', 'hardware' => 'network::ruggedcom::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'memory' => 'network::ruggedcom::mode::memory', 'temperature' => 'network::ruggedcom::mode::temperature', - 'traffic' => 'snmp_standard::mode::traffic', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', ); diff --git a/network/stonesoft/snmp/plugin.pm b/network/stonesoft/snmp/plugin.pm index 9b52e9092..7a1458a7f 100644 --- a/network/stonesoft/snmp/plugin.pm +++ b/network/stonesoft/snmp/plugin.pm @@ -35,12 +35,12 @@ sub new { 'memory' => 'network::stonesoft::snmp::mode::memory', 'cpu' => 'network::stonesoft::snmp::mode::cpu', 'connections' => 'network::stonesoft::snmp::mode::connections', + 'interfaces' => 'snmp_standard::mode::interfaces', 'storage' => 'network::stonesoft::snmp::mode::storage', 'cluster-state' => 'network::stonesoft::snmp::mode::clusterstate', 'cluster-load' => 'network::stonesoft::snmp::mode::clusterload', 'rejected-packets' => 'network::stonesoft::snmp::mode::rejectedpackets', 'dropped-packets' => 'network::stonesoft::snmp::mode::droppedpackets', - 'traffic' => 'snmp_standard::mode::traffic', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', ); diff --git a/os/aix/snmp/plugin.pm b/os/aix/snmp/plugin.pm index 8075e3a52..a1895b17d 100644 --- a/os/aix/snmp/plugin.pm +++ b/os/aix/snmp/plugin.pm @@ -33,12 +33,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( 'cpu' => 'snmp_standard::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', 'processcount' => 'snmp_standard::mode::processcount', 'storage' => 'snmp_standard::mode::storage', 'swap' => 'os::aix::snmp::mode::swap', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/os/freebsd/snmp/plugin.pm b/os/freebsd/snmp/plugin.pm index a3d57c874..1ec8e033d 100644 --- a/os/freebsd/snmp/plugin.pm +++ b/os/freebsd/snmp/plugin.pm @@ -37,17 +37,16 @@ sub new { 'diskio' => 'snmp_standard::mode::diskio', 'disk-usage' => 'snmp_standard::mode::diskusage', 'inodes' => 'snmp_standard::mode::inodes', + 'interfaces' => 'snmp_standard::mode::interfaces', 'load' => 'snmp_standard::mode::loadaverage', 'list-diskspath' => 'snmp_standard::mode::listdiskspath', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', 'memory' => 'snmp_standard::mode::memory', - 'packet-errors' => 'snmp_standard::mode::packeterrors', 'processcount' => 'snmp_standard::mode::processcount', 'storage' => 'snmp_standard::mode::storage', 'swap' => 'snmp_standard::mode::swap', 'tcpcon' => 'snmp_standard::mode::tcpcon', - 'traffic' => 'snmp_standard::mode::traffic', 'uptime' => 'snmp_standard::mode::uptime', ); diff --git a/os/linux/snmp/plugin.pm b/os/linux/snmp/plugin.pm index 28a46d173..14d619403 100644 --- a/os/linux/snmp/plugin.pm +++ b/os/linux/snmp/plugin.pm @@ -37,18 +37,17 @@ sub new { 'diskio' => 'snmp_standard::mode::diskio', 'disk-usage' => 'snmp_standard::mode::diskusage', 'inodes' => 'snmp_standard::mode::inodes', + 'interfaces' => 'snmp_standard::mode::interfaces', 'load' => 'snmp_standard::mode::loadaverage', 'list-diskspath' => 'snmp_standard::mode::listdiskspath', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', 'memory' => 'snmp_standard::mode::memory', - 'packet-errors' => 'snmp_standard::mode::packeterrors', 'processcount' => 'snmp_standard::mode::processcount', 'storage' => 'snmp_standard::mode::storage', 'swap' => 'snmp_standard::mode::swap', 'time' => 'snmp_standard::mode::ntp', 'tcpcon' => 'snmp_standard::mode::tcpcon', - 'traffic' => 'snmp_standard::mode::traffic', 'uptime' => 'snmp_standard::mode::uptime', ); diff --git a/os/solaris/snmp/plugin.pm b/os/solaris/snmp/plugin.pm index cd82800b9..b01ba6b1c 100644 --- a/os/solaris/snmp/plugin.pm +++ b/os/solaris/snmp/plugin.pm @@ -34,13 +34,12 @@ sub new { %{$self->{modes}} = ( 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', 'load' => 'snmp_standard::mode::loadaverage', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', - 'packet-errors' => 'snmp_standard::mode::packeterrors', 'processcount' => 'snmp_standard::mode::processcount', 'storage' => 'snmp_standard::mode::storage', 'tcpcon' => 'snmp_standard::mode::tcpcon', - 'traffic' => 'snmp_standard::mode::traffic', 'uptime' => 'snmp_standard::mode::uptime', ); diff --git a/os/windows/snmp/plugin.pm b/os/windows/snmp/plugin.pm index 1147560ce..820182370 100644 --- a/os/windows/snmp/plugin.pm +++ b/os/windows/snmp/plugin.pm @@ -32,18 +32,16 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'anycast' => 'snmp_standard::mode::anycast', 'cpu' => 'snmp_standard::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', 'memory' => 'os::windows::snmp::mode::memory', - 'packet-errors' => 'snmp_standard::mode::packeterrors', 'processcount' => 'snmp_standard::mode::processcount', 'service' => 'os::windows::snmp::mode::service', 'storage' => 'snmp_standard::mode::storage', 'swap' => 'os::windows::snmp::mode::swap', 'time' => 'snmp_standard::mode::ntp', - 'traffic' => 'snmp_standard::mode::traffic', 'uptime' => 'snmp_standard::mode::uptime', ); diff --git a/snmp_standard/mode/anycast.pm b/snmp_standard/mode/anycast.pm deleted file mode 100644 index c4921b9b9..000000000 --- a/snmp_standard/mode/anycast.pm +++ /dev/null @@ -1,522 +0,0 @@ -# -# Copyright 2015 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::anycast; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::statefile; -use Digest::MD5 qw(md5_hex); -use centreon::plugins::values; - -my $maps_counters = { - 'status' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'opstatus' }, { name => 'admstatus' }, - ], - closure_custom_calc => \&custom_status_calc, - closure_custom_output => \&custom_status_output, - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&custom_threshold_output, - } - }, - 'in-ucast' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode' }, { name => 'opstatus' }, { name => 'admstatus' } - ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'iucast', total_ref1 => 'ibcast', total_ref2 => 'imcast' }, - output_template => 'In Ucast : %.2f %%', output_error_template => 'In Ucast : %s', - output_use => 'iucast_prct', threshold_use => 'iucast_prct', - perfdatas => [ - { value => 'iucast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - 'in-bcast' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode' }, { name => 'opstatus' }, { name => 'admstatus' } - ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'ibcast', total_ref1 => 'iucast', total_ref2 => 'imcast' }, - output_template => 'In Bcast : %.2f %%', output_error_template => 'In Bcast : %s', - output_use => 'ibcast_prct', threshold_use => 'ibcast_prct', - perfdatas => [ - { value => 'ibcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - 'in-mcast' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode' }, { name => 'opstatus' }, { name => 'admstatus' } - ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'imcast', total_ref1 => 'iucast', total_ref2 => 'ibcast' }, - output_template => 'In Mcast : %.2f %%', output_error_template => 'In Mcast : %s', - output_use => 'imcast_prct', threshold_use => 'imcast_prct', - perfdatas => [ - { value => 'imcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - 'out-ucast' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'oucast', diff => 1 }, { name => 'omcast', diff => 1 }, { name => 'obcast', diff => 1 }, { name => 'display' }, { name => 'mode' }, { name => 'opstatus' }, { name => 'admstatus' } - ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'oucast', total_ref1 => 'omcast', total_ref2 => 'obcast' }, - output_template => 'Out Ucast : %.2f %%', output_error_template => 'Out Ucast : %s', - output_use => 'oucast_prct', threshold_use => 'oucast_prct', - perfdatas => [ - { value => 'oucast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - 'out-bcast' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'oucast', diff => 1 }, { name => 'omcast', diff => 1 }, { name => 'obcast', diff => 1 }, { name => 'display' }, { name => 'mode' }, { name => 'opstatus' }, { name => 'admstatus' } - ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'obcast', total_ref1 => 'omcast', total_ref2 => 'oucast' }, - output_template => 'Out Bcast : %.2f %%', output_error_template => 'Out Bcast : %s', - output_use => 'obcast_prct', threshold_use => 'obcast_prct', - perfdatas => [ - { value => 'obcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - 'out-mcast' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'oucast', diff => 1 }, { name => 'omcast', diff => 1 }, { name => 'obcast', diff => 1 }, { name => 'display' }, { name => 'mode' }, { name => 'opstatus' }, { name => 'admstatus' } - ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'omcast', total_ref1 => 'oucast', total_ref2 => 'obcast' }, - output_template => 'Out Mcast : %.2f %%', output_error_template => 'Out Mcast : %s', - output_use => 'omcast_prct', threshold_use => 'omcast_prct', - perfdatas => [ - { value => 'omcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, -}; - -my $skip_option; -my @operstatus = ("up", "down", "testing", "unknown", "dormant", "notPresent", "lowerLayerDown"); - -sub custom_threshold_output { - my ($self, %options) = @_; - my $status = 'ok'; - - if ($operstatus[$self->{result_values}->{opstatus} - 1] ne "up") { - if (defined($skip_option)) { - return $status; - } - if (!defined($self->{result_values}->{admstatus}) || $operstatus[$self->{result_values}->{admstatus} - 1] eq 'up') { - $status = 'critical'; - } - } - - return $status; -} - -sub custom_status_output { - my ($self, %options) = @_; - my $msg = 'Status : '; - - if ($operstatus[$self->{result_values}->{opstatus} - 1] ne "up") { - if (defined($skip_option)) { - $msg .= 'skipped'; - return $msg; - } - if (!defined($self->{result_values}->{admstatus}) || $operstatus[$self->{result_values}->{admstatus} - 1] eq 'up') { - $msg .= 'not ready (' . $operstatus[$self->{result_values}->{admstatus} - 1] . ')'; - } else { - $msg .= 'not ready (normal state)'; - } - } else { - $msg .= 'up'; - } - - 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'}; - return 0; -} - -sub custom_cast_calc { - my ($self, %options) = @_; - - if ($operstatus[$options{new_datas}->{$self->{instance} . '_opstatus'} - 1] ne "up") { - $self->{error_msg} = "skipped"; - return -2; - } - - my $diff_cast = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); - my $total = $diff_cast - + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}}) - + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}}); - if ($options{new_datas}->{$self->{instance} . '_mode'} ne $options{old_datas}->{$self->{instance} . '_mode'}) { - $self->{error_msg} = "buffer creation"; - return -2; - } - if ($total == 0) { - $self->{error_msg} = "skipped"; - return -2; - } - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{$options{extra_options}->{label_ref} . '_prct'} = $diff_cast * 100 / $total; - return 0; -} - -my %oids_iftable = ( - 'ifdesc' => '.1.3.6.1.2.1.2.2.1.2', - 'ifalias' => '.1.3.6.1.2.1.31.1.1.1.18', - 'ifname' => '.1.3.6.1.2.1.31.1.1.1.1' -); - -my $oid_ifAdminStatus = '.1.3.6.1.2.1.2.2.1.7'; -my $oid_ifOperStatus = '.1.3.6.1.2.1.2.2.1.8'; - -my $oid_ifXEntry = '.1.3.6.1.2.1.31.1.1.1'; - -# 32bits -my $oid_ifInUcastPkts = '.1.3.6.1.2.1.2.2.1.11'; -my $oid_ifInBroadcastPkts = '.1.3.6.1.2.1.31.1.1.1.3'; -my $oid_ifInMulticastPkts = '.1.3.6.1.2.1.31.1.1.1.2'; -my $oid_ifOutUcastPkts = '.1.3.6.1.2.1.2.2.1.17'; -my $oid_ifOutMulticastPkts = '.1.3.6.1.2.1.31.1.1.1.4'; -my $oid_ifOutBroadcastPkts = '.1.3.6.1.2.1.31.1.1.1.5'; - -# 64 bits -my $oid_ifHCInUcastPkts = '.1.3.6.1.2.1.31.1.1.1.7'; -my $oid_ifHCInMulticastPkts = '.1.3.6.1.2.1.31.1.1.1.8'; -my $oid_ifHCInBroadcastPkts = '.1.3.6.1.2.1.31.1.1.1.9'; -my $oid_ifHCOutUcastPkts = '.1.3.6.1.2.1.31.1.1.1.11'; -my $oid_ifHCOutMulticastPkts = '.1.3.6.1.2.1.31.1.1.1.12'; -my $oid_ifHCOutBroadcastPkts = '.1.3.6.1.2.1.31.1.1.1.13'; - -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 => - { - "name" => { name => 'use_name' }, - "interface:s" => { name => 'interface' }, - "skip" => { name => 'skip' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - "oid-filter:s" => { name => 'oid_filter', default => 'ifname'}, - "oid-display:s" => { name => 'oid_display', default => 'ifname'}, - "display-transform-src:s" => { name => 'display_transform_src' }, - "display-transform-dst:s" => { name => 'display_transform_dst' }, - }); - - $self->{interface_selected} = {}; - $self->{statefile_value} = centreon::plugins::statefile->new(%options); - - foreach (keys %{$maps_counters}) { - $options{options}->add_options(arguments => { - 'warning-' . $_ . ':s' => { name => 'warning-' . $_ }, - 'critical-' . $_ . ':s' => { name => 'critical-' . $_ }, - }); - my $class = $maps_counters->{$_}->{class}; - $maps_counters->{$_}->{obj} = $class->new(statefile => $self->{statefile_value}, - output => $self->{output}, perfdata => $self->{perfdata}, - label => $_); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); - } - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - $self->{option_results}->{oid_filter} = lc($self->{option_results}->{oid_filter}); - if ($self->{option_results}->{oid_filter} !~ /^(ifdesc|ifalias|ifname)$/) { - $self->{output}->add_option_msg(short_msg => "Unsupported --oid-filter option."); - $self->{output}->option_exit(); - } - $self->{option_results}->{oid_display} = lc($self->{option_results}->{oid_display}); - if ($self->{option_results}->{oid_display} !~ /^(ifdesc|ifalias|ifname)$/) { - $self->{output}->add_option_msg(short_msg => "Unsupported --oid-display option."); - $self->{output}->option_exit(); - } - - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); - } - - $skip_option = $self->{option_results}->{skip}; - $self->{statefile_value}->check_options(%options); -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - $self->{snmp_port} = $self->{snmp}->get_port(); - - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{interface_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All interfaces are ok.'); - } - $self->{new_datas} = {}; - $self->{statefile_value}->read(statefile => "snmpstandard_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{interface}) ? md5_hex($self->{option_results}->{interface}) : md5_hex('all'))); - $self->{new_datas}->{last_timestamp} = time(); - - foreach my $id (sort keys %{$self->{interface_selected}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->set(instance => $id); - - my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{interface_selected}->{$id}, - new_datas => $self->{new_datas}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); - push @exits, $exit2; - - my $output = $maps_counters->{$_}->{obj}->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "Interface '" . $self->{interface_selected}->{$id}->{display} . "' $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "Interface '" . $self->{interface_selected}->{$id}->{display} . "' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "Interface '" . $self->{interface_selected}->{$id}->{display} . "' $long_msg"); - } - } - - $self->{statefile_value}->write(data => $self->{new_datas}); - $self->{output}->display(); - $self->{output}->exit(); -} - -sub get_display_value { - my ($self, %options) = @_; - my $value = $options{value}; - - if (defined($self->{option_results}->{display_transform_src})) { - $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; - } - return $value; -} - -sub add_result { - my ($self, %options) = @_; - - $self->{interface_selected}->{$options{instance}} = {}; - $self->{interface_selected}->{$options{instance}}->{display} = $self->get_display_value(value => $self->{results}->{$oids_iftable{$self->{option_results}->{oid_display}}}->{$oids_iftable{$self->{option_results}->{oid_display}} . '.' . $options{instance}}); - - $self->{interface_selected}->{$options{instance}}->{opstatus} = $self->{results}->{$oid_ifOperStatus}->{$oid_ifOperStatus . '.' . $options{instance}}; - $self->{interface_selected}->{$options{instance}}->{admstatus} = $self->{results}->{$oid_ifAdminStatus}->{$oid_ifAdminStatus . '.' . $options{instance}}; - $self->{interface_selected}->{$options{instance}}->{mode} = 32; - $self->{interface_selected}->{$options{instance}}->{iucast} = $self->{results}->{$oid_ifInUcastPkts}->{$oid_ifInUcastPkts . '.' . $options{instance}}; - $self->{interface_selected}->{$options{instance}}->{ibcast} = defined($self->{results}->{$oid_ifXEntry}->{$oid_ifInBroadcastPkts . '.' . $options{instance}}) ? $self->{results}->{$oid_ifXEntry}->{$oid_ifInBroadcastPkts . '.' . $options{instance}} : 0; - $self->{interface_selected}->{$options{instance}}->{imcast} = defined($self->{results}->{$oid_ifXEntry}->{$oid_ifInMulticastPkts . '.' . $options{instance}}) ? $self->{results}->{$oid_ifXEntry}->{$oid_ifInMulticastPkts . '.' . $options{instance}} : 0; - $self->{interface_selected}->{$options{instance}}->{oucast} = $self->{results}->{$oid_ifOutUcastPkts}->{$oid_ifOutUcastPkts . '.' . $options{instance}}; - $self->{interface_selected}->{$options{instance}}->{omcast} = defined($self->{results}->{$oid_ifXEntry}->{$oid_ifOutMulticastPkts . '.' . $options{instance}}) ? $self->{results}->{$oid_ifXEntry}->{$oid_ifOutMulticastPkts . '.' . $options{instance}} : 0; - $self->{interface_selected}->{$options{instance}}->{obcast} = defined($self->{results}->{$oid_ifXEntry}->{$oid_ifOutBroadcastPkts . '.' . $options{instance}}) ? $self->{results}->{$oid_ifXEntry}->{$oid_ifOutBroadcastPkts . '.' . $options{instance}} : 0; - if (!$self->{snmp}->is_snmpv1()) { - my $iucast = $self->{results}->{$oid_ifXEntry}->{"${oid_ifHCInUcastPkts}.$options{instance}"}; - if (defined($iucast) && $iucast =~ /[1-9]/) { - $self->{interface_selected}->{$options{instance}}->{iucast} = $iucast; - $self->{interface_selected}->{$options{instance}}->{imcast} = defined($self->{results}->{$oid_ifXEntry}->{$oid_ifHCInMulticastPkts . '.' . $options{instance}}) ? $self->{results}->{$oid_ifXEntry}->{$oid_ifHCInMulticastPkts . '.' . $options{instance}} : 0; - $self->{interface_selected}->{$options{instance}}->{ibcast} = defined($self->{results}->{$oid_ifXEntry}->{$oid_ifHCInBroadcastPkts . '.' . $options{instance}}) ? $self->{results}->{$oid_ifXEntry}->{$oid_ifHCInBroadcastPkts . '.' . $options{instance}} : 0; - $self->{interface_selected}->{$options{instance}}->{oucast} = $self->{results}->{$oid_ifXEntry}->{$oid_ifHCOutUcastPkts . '.' . $options{instance}}; - $self->{interface_selected}->{$options{instance}}->{omcast} = defined($self->{results}->{$oid_ifXEntry}->{$oid_ifHCOutMulticastPkts . '.' . $options{instance}}) ? $self->{results}->{$oid_ifXEntry}->{$oid_ifHCOutMulticastPkts . '.' . $options{instance}} : 0; - $self->{interface_selected}->{$options{instance}}->{obcast} = defined($self->{results}->{$oid_ifXEntry}->{$oid_ifHCOutBroadcastPkts . '.' . $options{instance}}) ? $self->{results}->{$oid_ifXEntry}->{$oid_ifHCOutBroadcastPkts . '.' . $options{instance}} : 0; - $self->{interface_selected}->{$options{instance}}->{mode} = 64; - } - } -} - -sub manage_selection { - my ($self, %options) = @_; - - my @extra_names = (); - my $start_xtable = $oid_ifInMulticastPkts; - my $end_xtable = $oid_ifOutBroadcastPkts; - if (!$self->{snmp}->is_snmpv1()) { - $end_xtable = $oid_ifHCOutBroadcastPkts; - } - if ($self->{option_results}->{oid_filter} eq 'ifname' || $self->{option_results}->{oid_display} eq 'ifname') { - push @extra_names, { oid => $oids_iftable{ifname} }; - } - if ($self->{option_results}->{oid_filter} eq 'ifalias' || $self->{option_results}->{oid_display} eq 'ifalias') { - push @extra_names, { oid => $oids_iftable{ifalias} }; - } - if ($self->{option_results}->{oid_filter} eq 'ifdesc' || $self->{option_results}->{oid_display} eq 'ifdesc') { - push @extra_names, { oid => $oids_iftable{ifdesc} }; - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_ifXEntry, start => $start_xtable, end => , $end_xtable}, - { oid => $oid_ifAdminStatus }, - { oid => $oid_ifOperStatus }, - { oid => $oid_ifInUcastPkts }, - { oid => $oid_ifOutUcastPkts }, - @extra_names - ], - , nothing_quit => 1); - - if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) { - if (!defined($self->{results}->{$oids_iftable{$self->{option_results}->{oid_display}}}->{$oids_iftable{$self->{option_results}->{oid_display}} . '.' . $self->{option_results}->{interface}})) { - $self->{output}->add_option_msg(short_msg => "No interface found for id '" . $self->{option_results}->{interface} . "'."); - $self->{output}->option_exit(); - } - $self->add_result(instance => $self->{option_results}->{interface}); - } else { - foreach my $oid (keys %{$self->{results}->{$oids_iftable{$self->{option_results}->{oid_filter}}}}) { - $oid =~ /\.(\d+)$/; - my $instance = $1; - my $filter_name = $self->{results}->{$oids_iftable{$self->{option_results}->{oid_filter}}}->{$oid}; - if (!defined($self->{option_results}->{interface})) { - $self->add_result(instance => $instance); - next; - } - if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/i) { - $self->add_result(instance => $instance); - } - if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/) { - $self->add_result(instance => $instance); - } - if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{interface}) { - $self->add_result(instance => $instance); - } - } - - if (scalar(keys %{$self->{interface_selected}}) <= 0) { - if (defined($self->{option_results}->{interface})) { - $self->{output}->add_option_msg(short_msg => "No interface found for name '" . $self->{option_results}->{interface} . "'."); - } else { - $self->{output}->add_option_msg(short_msg => "No interface found."); - } - $self->{output}->option_exit(); - } - } -} - -1; - -__END__ - -=head1 MODE - -Check interface unicast, broadcast and multicast usage. - -=over 8 - -=item B<--warning-*> - -Threshold warning (in percent). -Can be: 'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast'. - -=item B<--critical-*> - -Threshold critical (in percent). -Can be: 'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast'. - -=item B<--interface> - -Set the interface (number expected) ex: 1, 2,... (empty means 'check all interface'). - -=item B<--name> - -Allows to use interface name with option --interface instead of interface oid index. - -=item B<--regexp> - -Allows to use regexp to filter interfaces (with option --name). - -=item B<--regexp-isensitive> - -Allows to use regexp non case-sensitive (with --regexp). - -=item B<--skip> - -Skip errors on interface status. - -=item B<--oid-filter> - -Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName). - -=item B<--oid-display> - -Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName). - -=item B<--display-transform-src> - -Regexp src to transform display value. (security risk!!!) - -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) - -=back - -=cut diff --git a/snmp_standard/mode/diskio.pm b/snmp_standard/mode/diskio.pm index 4c7f8a113..76d1c1746 100644 --- a/snmp_standard/mode/diskio.pm +++ b/snmp_standard/mode/diskio.pm @@ -29,60 +29,94 @@ use Digest::MD5 qw(md5_hex); use centreon::plugins::values; my $maps_counters = { - read => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'read', diff => 1 }, { name => 'display' }, - ], - per_second => 1, - output_template => 'Read I/O : %s %s/s', output_error_template => "Read I/O : %s", - output_change_bytes => 1, - perfdatas => [ - { value => 'read_per_second', template => '%d', - unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - write => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'write', diff => 1 }, { name => 'display' }, - ], - per_second => 1, - output_template => 'Write I/O : %s %s/s', output_error_template => "Write I/O : %s", - output_change_bytes => 1, - perfdatas => [ - { value => 'write_per_second', template => '%d', - unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - 'read-iops' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'read_iops', diff => 1 }, { name => 'display' }, - ], - per_second => 1, - output_template => 'Read IOPs : %.2f', output_error_template => "Read IOPs : %s", - perfdatas => [ - { value => 'read_iops_per_second', template => '%.2f', - unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - 'write-iops' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'write_iops', diff => 1 }, { name => 'display' }, - ], - per_second => 1, - output_template => 'Write IOPs : %.2f', output_error_template => "Write IOPs : %s", - perfdatas => [ - { value => 'write_iops_per_second', template => '%.2f', - unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, + disk => { + '000_read' => { set => { + key_values => [ { name => 'read', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'Read I/O : %s %s/s', output_error_template => "Read I/O : %s", + output_change_bytes => 1, + perfdatas => [ + { label => 'read', value => 'read_per_second', template => '%d', + unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + '001_write' => { set => { + key_values => [ { name => 'write', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'Write I/O : %s %s/s', output_error_template => "Write I/O : %s", + output_change_bytes => 1, + perfdatas => [ + { label => 'write', value => 'write_per_second', template => '%d', + unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + '002_read-iops' => { set => { + key_values => [ { name => 'read_iops', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'Read IOPs : %.2f', output_error_template => "Read IOPs : %s", + perfdatas => [ + { label => 'read_iops', value => 'read_iops_per_second', template => '%.2f', + unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + '003_write-iops' => { set => { + key_values => [ { name => 'write_iops', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'Write IOPs : %.2f', output_error_template => "Write IOPs : %s", + perfdatas => [ + { label => 'write_iops', value => 'write_iops_per_second', template => '%.2f', + unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + }, + total => { + '000_total-read' => { set => { + key_values => [ { name => 'total_read', diff => 1 } ], + per_second => 1, + output_template => 'Read I/O : %s %s/s', output_error_template => "Read I/O : %s", + output_change_bytes => 1, + perfdatas => [ + { label => 'total_read', value => 'total_read_per_second', template => '%d', + unit => 'B/s', min => 0 }, + ], + } + }, + '001_total-write' => { set => { + key_values => [ { name => 'total_write', diff => 1 } ], + per_second => 1, + output_template => 'Write I/O : %s %s/s', output_error_template => "Write I/O : %s", + output_change_bytes => 1, + perfdatas => [ + { label => 'total_write', value => 'total_write_per_second', template => '%d', + unit => 'B/s', min => 0 }, + ], + } + }, + '002_total-read-iops' => { set => { + key_values => [ { name => 'total_read_iops', diff => 1 } ], + per_second => 1, + output_template => 'Read IOPs : %.2f', output_error_template => "Read IOPs : %s", + perfdatas => [ + { label => 'total_read_iops', value => 'total_read_iops_per_second', template => '%.2f', + unit => 'iops', min => 0 }, + ], + } + }, + '003_total-write-iops' => { set => { + key_values => [ { name => 'total_write_iops', diff => 1 } ], + per_second => 1, + output_template => 'Write IOPs : %.2f', output_error_template => "Write IOPs : %s", + perfdatas => [ + { label => 'total_write_iops', value => 'total_write_iops_per_second', template => '%.2f', + unit => 'iops', min => 0 }, + ], + } + }, + }, }; my $oid_diskIODevice = '.1.3.6.1.4.1.2021.13.15.1.1.2'; @@ -108,16 +142,20 @@ sub new { $self->{device_id_selected} = {}; $self->{statefile_value} = centreon::plugins::statefile->new(%options); - foreach (keys %{$maps_counters}) { - $options{options}->add_options(arguments => { - 'warning-' . $_ . ':s' => { name => 'warning-' . $_ }, - 'critical-' . $_ . ':s' => { name => 'critical-' . $_ }, - }); - my $class = $maps_counters->{$_}->{class}; - $maps_counters->{$_}->{obj} = $class->new(statefile => $self->{statefile_value}, - output => $self->{output}, perfdata => $self->{perfdata}, - label => $_); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); + foreach my $key (('total', 'disk')) { + foreach (keys %{$maps_counters->{$key}}) { + my ($id, $name) = split /_/; + if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $name . ':s' => { name => 'warning-' . $name }, + 'critical-' . $name . ':s' => { name => 'critical-' . $name }, + }); + } + $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value}, + output => $self->{output}, perfdata => $self->{perfdata}, + label => $name); + $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); + } } return $self; @@ -127,13 +165,57 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); + foreach my $key (('total', 'disk')) { + foreach (keys %{$maps_counters->{$key}}) { + $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); + } } $self->{statefile_value}->check_options(%options); } +sub check_total { + my ($self, %options) = @_; + + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits = (); + foreach (sort keys %{$maps_counters->{total}}) { + my $obj = $maps_counters->{total}->{$_}->{obj}; + $obj->set(instance => 'global'); + + my ($value_check) = $obj->execute(values => $self->{global}, + new_datas => $self->{new_datas}); + + if ($value_check != 0) { + $long_msg .= $long_msg_append . $obj->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $obj->threshold_check(); + push @exits, $exit2; + + my $output = $obj->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $obj->perfdata(); + } + + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => "Total $short_msg" + ); + } else { + $self->{output}->output_add(short_msg => "Total $long_msg"); + } +} + sub run { my ($self, %options) = @_; # $options{snmp} = snmp object @@ -147,6 +229,10 @@ sub run { } $self->manage_selection(); + + $self->{new_datas} = {}; + $self->{statefile_value}->read(statefile => "snmpstandard_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{device}) ? md5_hex($self->{option_results}->{device}) : md5_hex('all'))); + $self->{new_datas}->{last_timestamp} = time(); my $multiple = 1; if (scalar(keys %{$self->{device_id_selected}}) == 1) { @@ -154,31 +240,30 @@ sub run { } if ($multiple == 1) { + $self->check_total(); $self->{output}->output_add(severity => 'OK', short_msg => 'All devices are ok.'); } - $self->{new_datas} = {}; - $self->{statefile_value}->read(statefile => "snmpstandard_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{device}) ? md5_hex($self->{option_results}->{device}) : md5_hex('all'))); - $self->{new_datas}->{last_timestamp} = time(); foreach my $id (sort keys %{$self->{device_id_selected}}) { my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); my @exits; - foreach (sort keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->set(instance => $id); + foreach (sort keys %{$maps_counters->{disk}}) { + my $obj = $maps_counters->{disk}->{$_}->{obj}; - my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{device_id_selected}->{$id}, - new_datas => $self->{new_datas}); + $obj->set(instance => $id); + my ($value_check) = $obj->execute(values => $self->{device_id_selected}->{$id}, + new_datas => $self->{new_datas}); if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); + $long_msg .= $long_msg_append . $obj->output_error(); $long_msg_append = ', '; next; } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); + my $exit2 = $obj->threshold_check(); push @exits, $exit2; - my $output = $maps_counters->{$_}->{obj}->output(); + my $output = $obj->output(); $long_msg .= $long_msg_append . $output; $long_msg_append = ', '; @@ -187,7 +272,7 @@ sub run { $short_msg_append = ', '; } - $maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple); + $obj->perfdata(extra_instance => $multiple); } $self->{output}->output_add(long_msg => "Device '" . $self->{device_id_selected}->{$id}->{display} . "' $long_msg"); @@ -211,19 +296,30 @@ sub run { sub add_result { my ($self, %options) = @_; - $self->{device_id_selected}->{$options{instance}} = {}; + $self->{device_id_selected}->{$options{instance}} = { read => undef, write => undef, read_iops => undef, write_iops => undef }; $self->{device_id_selected}->{$options{instance}}->{display} = $self->{results}->{$oid_diskIODevice}->{$oid_diskIODevice . '.' . $options{instance}}; - $self->{device_id_selected}->{$options{instance}}->{read} = (defined($self->{results}->{$oid_diskIONReadX}->{$oid_diskIONReadX . '.' . $options{instance}}) && $self->{results}->{$oid_diskIONReadX}->{$oid_diskIONReadX . '.' . $options{instance}} != 0) ? - $self->{results}->{$oid_diskIONReadX}->{$oid_diskIONReadX . '.' . $options{instance}} : 0; - $self->{device_id_selected}->{$options{instance}}->{write} = (defined($self->{results}->{$oid_diskIONWrittenX}->{$oid_diskIONWrittenX . '.' . $options{instance}}) && $self->{results}->{$oid_diskIONWrittenX}->{$oid_diskIONWrittenX . '.' . $options{instance}} != 0) ? - $self->{results}->{$oid_diskIONWrittenX}->{$oid_diskIONWrittenX . '.' . $options{instance}} : undef; - $self->{device_id_selected}->{$options{instance}}->{read_iops} = $self->{results}->{$oid_diskIOReads}->{$oid_diskIOReads . '.' . $options{instance}}; - $self->{device_id_selected}->{$options{instance}}->{write_iops} = $self->{results}->{$oid_diskIOWrites}->{$oid_diskIOWrites . '.' . $options{instance}}; + if (defined($self->{results}->{$oid_diskIONReadX}->{$oid_diskIONReadX . '.' . $options{instance}}) && $self->{results}->{$oid_diskIONReadX}->{$oid_diskIONReadX . '.' . $options{instance}} != 0) { + $self->{device_id_selected}->{$options{instance}}->{read} = $self->{results}->{$oid_diskIONReadX}->{$oid_diskIONReadX . '.' . $options{instance}}; + $self->{global}->{total_read} += $self->{device_id_selected}->{$options{instance}}->{read}; + } + if (defined($self->{results}->{$oid_diskIONWrittenX}->{$oid_diskIONWrittenX . '.' . $options{instance}}) && $self->{results}->{$oid_diskIONWrittenX}->{$oid_diskIONWrittenX . '.' . $options{instance}} != 0) { + $self->{device_id_selected}->{$options{instance}}->{write} = $self->{results}->{$oid_diskIONWrittenX}->{$oid_diskIONWrittenX . '.' . $options{instance}}; + $self->{global}->{total_write} += $self->{device_id_selected}->{$options{instance}}->{write}; + } + if (defined($self->{results}->{$oid_diskIOReads}->{$oid_diskIOReads . '.' . $options{instance}}) && $self->{results}->{$oid_diskIOReads}->{$oid_diskIOReads . '.' . $options{instance}} != 0) { + $self->{device_id_selected}->{$options{instance}}->{read_iops} = $self->{results}->{$oid_diskIOReads}->{$oid_diskIOReads . '.' . $options{instance}}; + $self->{global}->{total_read_iops} += $self->{device_id_selected}->{$options{instance}}->{read_iops}; + } + if (defined($self->{results}->{$oid_diskIOWrites}->{$oid_diskIOWrites . '.' . $options{instance}}) && $self->{results}->{$oid_diskIOWrites}->{$oid_diskIOWrites . '.' . $options{instance}} != 0) { + $self->{device_id_selected}->{$options{instance}}->{write_iops} = $self->{results}->{$oid_diskIOWrites}->{$oid_diskIOWrites . '.' . $options{instance}}; + $self->{global}->{total_write_iops} += $self->{device_id_selected}->{$options{instance}}->{write_iops}; + } } sub manage_selection { my ($self, %options) = @_; + $self->{global} = { total_read => 0, total_write => 0, total_read_iops => 0, total_write_iops => 0 }; $self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_diskIODevice }, { oid => $oid_diskIOReads }, @@ -303,12 +399,14 @@ Check read/write I/O disks (bytes per secondes, IOPs). =item B<--warning-*> Threshold warning. -Can be: 'read', 'write', 'read-iops', 'write-iops'. +Can be: 'read', 'write', 'read-iops', 'write-iops', +'total-read', 'total-write', 'total-read-iops', 'total-write-iops'. =item B<--critical-*> Threshold critical. -Can be: 'read', 'write', 'read-iops', 'write-iops'. +Can be: 'read', 'write', 'read-iops', 'write-iops', +'total-read', 'total-write', 'total-read-iops', 'total-write-iops'. =item B<--device> diff --git a/snmp_standard/mode/interfaces.pm b/snmp_standard/mode/interfaces.pm new file mode 100644 index 000000000..e2a25ca0f --- /dev/null +++ b/snmp_standard/mode/interfaces.pm @@ -0,0 +1,1119 @@ +# +# Copyright 2015 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::interfaces; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::values; +use centreon::plugins::statefile; +use Digest::MD5 qw(md5_hex); + +my $instance_mode; + +######################### +# Calc functions +######################### +sub custom_threshold_output { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + my $msg = 'Status : ' . $self->{result_values}->{opstatus} . ' (admin: ' . $self->{result_values}->{admstatus} . ')'; + + 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'}; + return 0; +} + +sub custom_cast_calc { + my ($self, %options) = @_; + + my $diff_cast = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); + my $total = $diff_cast + + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}}) + + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}}); + if ($options{new_datas}->{$self->{instance} . '_mode_cast'} ne $options{old_datas}->{$self->{instance} . '_mode_cast'}) { + $self->{error_msg} = "buffer creation"; + return -2; + } + if ($total == 0) { + $self->{error_msg} = "skipped"; + return -2; + } + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{$options{extra_options}->{label_ref} . '_prct'} = $diff_cast * 100 / $total; + return 0; +} + +############## +# Traffic +sub custom_traffic_perfdata { + my ($self, %options) = @_; + + my $extra_label = ''; + if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { + $extra_label .= '_' . $self->{result_values}->{display}; + } + if (defined($instance_mode->{option_results}->{nagvis_perfdata})) { + $self->{result_values}->{traffic_per_seconds} /= 8; + $self->{result_values}->{speed} /= 8; + } + + my ($warning, $critical); + if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); + } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); + } + + if (defined($instance_mode->{option_results}->{nagvis_perfdata})) { + $self->{output}->perfdata_add(label => $self->{result_values}->{label} . $extra_label, + value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), + warning => $warning, + critical => $critical, + min => 0, max => $self->{result_values}->{speed}); + } else { + $self->{output}->perfdata_add(label => 'traffic_' . $self->{result_values}->{label} . $extra_label, unit => 'b/s', + value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), + warning => $warning, + critical => $critical, + min => 0, max => $self->{result_values}->{speed}); + } +} + +sub custom_traffic_threshold { + my ($self, %options) = @_; + + my $exit = 'ok'; + if ($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->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + } + return $exit; +} + +sub custom_traffic_output { + my ($self, %options) = @_; + + my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1); + my $msg = sprintf("Traffic %s : %s/s (%s)", + ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit, + defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'); + return $msg; +} + +sub custom_traffic_calc { + my ($self, %options) = @_; + + if ($options{new_datas}->{$self->{instance} . '_mode_traffic'} ne $options{old_datas}->{$self->{instance} . '_mode_traffic'}) { + $self->{error_msg} = "buffer creation"; + return -2; + } + + my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); + if ($diff_traffic == 0) { + $self->{error_msg} = "skipped"; + return -2; + } + + $self->{result_values}->{traffic_per_seconds} = $diff_traffic / $options{delta_time}; + if (defined($options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}) && + $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}} > 0) { + $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic_per_seconds} * 100 / $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; + $self->{result_values}->{speed} = $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; + } + + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +############## +# Errors +sub custom_errors_perfdata { + my ($self, %options) = @_; + + my $extra_label = ''; + if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { + $extra_label .= '_' . $self->{result_values}->{display}; + } + if ($instance_mode->{option_results}->{units_errors} eq '%') { + $self->{output}->perfdata_add(label => 'packets_' . $self->{result_values}->{label2} . '_' . $self->{result_values}->{label1} . $extra_label, unit => '%', + value => sprintf("%.2f", $self->{result_values}->{prct}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}), + min => 0, max => 100); + } else { + $self->{output}->perfdata_add(label => 'packets_' . $self->{result_values}->{label2} . '_' . $self->{result_values}->{label1} . $extra_label, + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}), + min => 0, max => $self->{result_values}->{total}); + } +} + +sub custom_errors_threshold { + my ($self, %options) = @_; + + my $exit = 'ok'; + if ($instance_mode->{option_results}->{units_errors} eq '%') { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + } else { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + } + return $exit; +} + +sub custom_errors_output { + my ($self, %options) = @_; + + my $msg = sprintf("Packets %s %s : %.2f%% (%s)", + ucfirst($self->{result_values}->{label1}), ucfirst($self->{result_values}->{label2}), + $self->{result_values}->{prct}, $self->{result_values}->{used}); + return $msg; +} + +sub custom_errors_calc { + my ($self, %options) = @_; + + if ($options{new_datas}->{$self->{instance} . '_mode_cast'} ne $options{old_datas}->{$self->{instance} . '_mode_cast'}) { + $self->{error_msg} = "buffer creation"; + return -2; + } + + my $diff = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref1} . $options{extra_options}->{label_ref2}} - + $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref1} . $options{extra_options}->{label_ref2}}); + my $total = ($options{new_datas}->{$self->{instance} . '_total_' . $options{extra_options}->{label_ref1} . '_packets'} - + $options{old_datas}->{$self->{instance} . '_total_' . $options{extra_options}->{label_ref1} . '_packets'}); + if ($total == 0) { + $self->{error_msg} = "skipped"; + return -2; + } + + $self->{result_values}->{prct} = $diff * 100 / $total; + $self->{result_values}->{used} = $diff; + $self->{result_values}->{total} = $total; + $self->{result_values}->{label1} = $options{extra_options}->{label_ref1}; + $self->{result_values}->{label2} = $options{extra_options}->{label_ref2}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +######################### +# OIDs mapping functions +######################### +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters} = { + int => { + '000_status' => { filter => 'add_status', threshold => 0, + set => { + key_values => $self->set_key_values_status(), + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + '010_in-traffic' => { filter => 'add_traffic', + set => { + key_values => $self->set_key_values_in_traffic(), + 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'), output_error_template => 'Traffic In : %s', + closure_custom_perfdata => $self->can('custom_traffic_perfdata'), + closure_custom_threshold_check => $self->can('custom_traffic_threshold'), + } + }, + '011_out-traffic' => { filter => 'add_traffic', + set => { + key_values => $self->set_key_values_out_traffic(), + 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'), output_error_template => 'Traffic Out : %s', + closure_custom_perfdata => $self->can('custom_traffic_perfdata'), + closure_custom_threshold_check => $self->can('custom_traffic_threshold'), + } + }, + '020_in-discard' => { filter => 'add_errors', + set => { + key_values => [ { name => 'indiscard', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], + closure_custom_calc => \&custom_errors_calc, closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'discard' }, + closure_custom_output => \&custom_errors_output, output_error_template => 'Packets In Discard : %s', + closure_custom_perfdata => \&custom_errors_perfdata, + closure_custom_threshold_check => \&custom_errors_threshold, + } + }, + '021_in-error' => { filter => 'add_errors', + set => { + key_values => [ { name => 'inerror', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], + closure_custom_calc => \&custom_errors_calc, closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'error' }, + closure_custom_output => \&custom_errors_output, output_error_template => 'Packets In Error : %s', + closure_custom_perfdata => \&custom_errors_perfdata, + closure_custom_threshold_check => \&custom_errors_threshold, + } + }, + '022_out-discard' => { filter => 'add_errors', + set => { + key_values => [ { name => 'outdiscard', diff => 1 }, { name => 'total_out_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], + closure_custom_calc => \&custom_errors_calc, closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'discard' }, + closure_custom_output => \&custom_errors_output, output_error_template => 'Packets Out Discard : %s', + closure_custom_perfdata => \&custom_errors_perfdata, + closure_custom_threshold_check => \&custom_errors_threshold, + } + }, + '023_out-error' => { filter => 'add_errors', + set => { + key_values => [ { name => 'outerror', diff => 1 }, { name => 'total_out_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], + closure_custom_calc => \&custom_errors_calc, closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'error' }, + closure_custom_output => \&custom_errors_output, output_error_template => 'Packets Out Error : %s', + closure_custom_perfdata => \&custom_errors_perfdata, + closure_custom_threshold_check => \&custom_errors_threshold, + } + }, + '030_in-ucast' => { filter => 'add_cast', + set => { + key_values => [ { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], + closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'iucast', total_ref1 => 'ibcast', total_ref2 => 'imcast' }, + output_template => 'In Ucast : %.2f %%', output_error_template => 'In Ucast : %s', + output_use => 'iucast_prct', threshold_use => 'iucast_prct', + perfdatas => [ + { value => 'iucast_prct', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + '031_in-bcast' => { filter => 'add_cast', + set => { + key_values => [ { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], + closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'ibcast', total_ref1 => 'iucast', total_ref2 => 'imcast' }, + output_template => 'In Bcast : %.2f %%', output_error_template => 'In Bcast : %s', + output_use => 'ibcast_prct', threshold_use => 'ibcast_prct', + perfdatas => [ + { value => 'ibcast_prct', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + '032_in-mcast' => { filter => 'add_cast', + set => { + key_values => [ { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], + closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'imcast', total_ref1 => 'iucast', total_ref2 => 'ibcast' }, + output_template => 'In Mcast : %.2f %%', output_error_template => 'In Mcast : %s', + output_use => 'imcast_prct', threshold_use => 'imcast_prct', + perfdatas => [ + { value => 'imcast_prct', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + '033_out-ucast' => { filter => 'add_cast', + set => { + key_values => [ { name => 'oucast', diff => 1 }, { name => 'omcast', diff => 1 }, { name => 'obcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], + closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'oucast', total_ref1 => 'omcast', total_ref2 => 'obcast' }, + output_template => 'Out Ucast : %.2f %%', output_error_template => 'Out Ucast : %s', + output_use => 'oucast_prct', threshold_use => 'oucast_prct', + perfdatas => [ + { value => 'oucast_prct', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + '034_out-bcast' => { filter => 'add_cast', + set => { + key_values => [ { name => 'oucast', diff => 1 }, { name => 'omcast', diff => 1 }, { name => 'obcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], + closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'obcast', total_ref1 => 'omcast', total_ref2 => 'oucast' }, + output_template => 'Out Bcast : %.2f %%', output_error_template => 'Out Bcast : %s', + output_use => 'obcast_prct', threshold_use => 'obcast_prct', + perfdatas => [ + { value => 'obcast_prct', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + '035_out-mcast' => { filter => 'add_cast', + set => { + key_values => [ { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], + closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'ibcast', total_ref1 => 'iucast', total_ref2 => 'imcast' }, + output_template => 'In Bcast : %.2f %%', output_error_template => 'In Bcast : %s', + output_use => 'ibcast_prct', threshold_use => 'ibcast_prct', + perfdatas => [ + { value => 'ibcast_prct', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + }}; +} + +sub set_key_values_status { + my ($self, %options) = @_; + + return [ { name => 'opstatus' }, { name => 'admstatus' } ]; +} + +sub set_key_values_in_traffic { + my ($self, %options) = @_; + + return [ { name => 'in', diff => 1 }, { name => 'speed_in'}, { name => 'display' }, { name => 'mode_traffic' } ]; +} + +sub set_key_values_out_traffic { + my ($self, %options) = @_; + + return [ { name => 'out', diff => 1 }, { name => 'speed_out'}, { name => 'display' }, { name => 'mode_traffic' } ]; +} + +sub set_instance { + my ($self, %options) = @_; + + $instance_mode = $self; +} + +sub set_oids_label { + my ($self, %options) = @_; + + $self->{oids_label} = { + 'ifdesc' => '.1.3.6.1.2.1.2.2.1.2', + 'ifalias' => '.1.3.6.1.2.1.31.1.1.1.18', + 'ifname' => '.1.3.6.1.2.1.31.1.1.1.1', + }; +} + +sub set_oids_status { + my ($self, %options) = @_; + + $self->{oid_adminstatus} = '.1.3.6.1.2.1.2.2.1.7'; + $self->{oid_adminstatus_mapping} = { + 1 => 'up', 2 => 'down', 3 => 'testing', 4 => 'unknown', 5 => 'dormant', 6 => 'notPresent', 7 => 'lowerLayerDown', + }; + $self->{oid_opstatus} = '.1.3.6.1.2.1.2.2.1.8'; + $self->{oid_opstatus_mapping} = { + 1 => 'up', 2 => 'down', 3 => 'testing', 4 => 'unknown', 5 => 'dormant', 6 => 'notPresent', 7 => 'lowerLayerDown', + }; +} + +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'; +} + +sub set_oids_traffic { + my ($self, %options) = @_; + + $self->{oid_speed32} = '.1.3.6.1.2.1.2.2.1.5'; # in b/s + $self->{oid_in32} = '.1.3.6.1.2.1.2.2.1.10'; # in B + $self->{oid_out32} = '.1.3.6.1.2.1.2.2.1.16'; # in B + $self->{oid_speed64} = '.1.3.6.1.2.1.31.1.1.1.15'; # need multiple by '1000000' + $self->{oid_in64} = '.1.3.6.1.2.1.31.1.1.1.6'; # in B + $self->{oid_out64} = '.1.3.6.1.2.1.31.1.1.1.10'; # in B +} + +sub set_oids_cast { + my ($self, %options) = @_; + + # 32bits + $self->{oid_ifInUcastPkts} = '.1.3.6.1.2.1.2.2.1.11'; + $self->{oid_ifInBroadcastPkts} = '.1.3.6.1.2.1.31.1.1.1.3'; + $self->{oid_ifInMulticastPkts} = '.1.3.6.1.2.1.31.1.1.1.2'; + $self->{oid_ifOutUcastPkts} = '.1.3.6.1.2.1.2.2.1.17'; + $self->{oid_ifOutMulticastPkts} = '.1.3.6.1.2.1.31.1.1.1.4'; + $self->{oid_ifOutBroadcastPkts} = '.1.3.6.1.2.1.31.1.1.1.5'; + + # 64 bits + $self->{oid_ifHCInUcastPkts} = '.1.3.6.1.2.1.31.1.1.1.7'; + $self->{oid_ifHCInMulticastPkts} = '.1.3.6.1.2.1.31.1.1.1.8'; + $self->{oid_ifHCInBroadcastPkts} = '.1.3.6.1.2.1.31.1.1.1.9'; + $self->{oid_ifHCOutUcastPkts} = '.1.3.6.1.2.1.31.1.1.1.11'; + $self->{oid_ifHCOutMulticastPkts} = '.1.3.6.1.2.1.31.1.1.1.12'; + $self->{oid_ifHCOutBroadcastPkts} = '.1.3.6.1.2.1.31.1.1.1.13'; +} + +sub check_oids_label { + my ($self, %options) = @_; + + foreach (('oid_filter', 'oid_display')) { + $self->{option_results}->{$_} = lc($self->{option_results}->{$_}) if (defined($self->{option_results}->{$_})); + if (!defined($self->{oids_label}->{$self->{option_results}->{$_}})) { + my $label = $_; + $label =~ s/_/-/g; + $self->{output}->add_option_msg(short_msg => "Unsupported oid in --" . $label . " option."); + $self->{output}->option_exit(); + } + } + + + if (defined($self->{option_results}->{oid_extra_display})) { + $self->{option_results}->{oid_extra_display} = lc($self->{option_results}->{oid_extra_display}); + if (!defined($self->{oids_label}->{$self->{option_results}->{oid_extra_display}})) { + $self->{output}->add_option_msg(short_msg => "Unsupported oid in --oid-extra-display option."); + $self->{output}->option_exit(); + } + } +} + +sub default_warning_status { + my ($self, %options) = @_; + + return ''; +} + +sub default_critical_status { + my ($self, %options) = @_; + + return '%{admstatus} eq "up" and %{opstatus} ne "up"'; +} + +sub default_oid_filter_name { + my ($self, %options) = @_; + + return 'ifname'; +} + +sub default_oid_display_name { + my ($self, %options) = @_; + + return 'ifname'; +} + +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 => + { + "add-status" => { name => 'add_status' }, + "add-traffic" => { name => 'add_traffic' }, + "add-errors" => { name => 'add_errors' }, + "add-cast" => { name => 'add_cast' }, + "warning-status:s" => { name => 'warning_status', default => $self->default_warning_status() }, + "critical-status:s" => { name => 'critical_status', default => $self->default_critical_status() }, + "oid-filter:s" => { name => 'oid_filter', default => $self->default_oid_filter_name() }, + "oid-display:s" => { name => 'oid_display', default => $self->default_oid_display_name() }, + "oid-extra-display:s" => { name => 'oid_extra_display' }, + "interface:s" => { name => 'interface' }, + "name" => { name => 'use_name' }, + "units-traffic:s" => { name => 'units_traffic', default => '%' }, + "units-errors:s" => { name => 'units_errors', default => '%' }, + "speed:s" => { name => 'speed' }, + "speed-in:s" => { name => 'speed_in' }, + "speed-out:s" => { name => 'speed_out' }, + "display-transform-src:s" => { name => 'display_transform_src' }, + "display-transform-dst:s" => { name => 'display_transform_dst' }, + "show-cache" => { name => 'show_cache' }, + "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, + "nagvis-perfdata" => { name => 'nagvis_perfdata' }, + }); + $self->{statefile_value} = centreon::plugins::statefile->new(%options); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + $self->set_counters(); + + foreach my $key (('int')) { + foreach (keys %{$self->{maps_counters}->{$key}}) { + my ($id, $name) = split /_/; + if (!defined($self->{maps_counters}->{$key}->{$_}->{threshold}) || $self->{maps_counters}->{$key}->{$_}->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $name . ':s' => { name => 'warning-' . $name }, + 'critical-' . $name . ':s' => { name => 'critical-' . $name }, + }); + } + $self->{maps_counters}->{$key}->{$_}->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value}, + output => $self->{output}, perfdata => $self->{perfdata}, + label => $name); + $self->{maps_counters}->{$key}->{$_}->{obj}->set(%{$self->{maps_counters}->{$key}->{$_}->{set}}); + } + } + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + foreach my $key (('int')) { + foreach (keys %{$self->{maps_counters}->{$key}}) { + $self->{maps_counters}->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); + } + } + + $self->set_oids_label(); + $self->check_oids_label(); + + $self->set_instance(); + $self->{statefile_cache}->check_options(%options); + $self->{statefile_value}->check_options(%options); + + if (defined($self->{option_results}->{add_traffic}) && + (!defined($self->{option_results}->{units_traffic}) || $self->{option_results}->{units_traffic} !~ /^(%|b\/s)$/)) { + $self->{output}->add_option_msg(short_msg => "Wrong option --units-traffic."); + $self->{output}->option_exit(); + } + if (defined($self->{option_results}->{add_errors}) && + (!defined($self->{option_results}->{units_errors}) || $self->{option_results}->{units_errors} !~ /^(%|absolute)$/)) { + $self->{output}->add_option_msg(short_msg => "Wrong option --units-errors."); + $self->{output}->option_exit(); + } + + $self->{get_speed} = 0; + if ((!defined($self->{option_results}->{speed}) || $self->{option_results}->{speed} eq '') && + ((!defined($self->{option_results}->{speed_in}) || $self->{option_results}->{speed_in} eq '') || + (!defined($self->{option_results}->{speed_out}) || $self->{option_results}->{speed_out} eq ''))) { + $self->{get_speed} = 1; + } + + # If no options, we set status + if (!defined($self->{option_results}->{add_status}) && !defined($self->{option_results}->{add_traffic}) && + !defined($self->{option_results}->{add_errors}) && !defined($self->{option_results}->{add_cast})) { + $self->{option_results}->{add_status} = 1; + } + $self->{checking} = ''; + foreach (('add_status', 'add_errors', 'add_traffic', 'add_cast')) { + if (defined($self->{option_results}->{$_})) { + $self->{checking} .= $_; + } + } + + $self->change_macros(); +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + $self->{hostname} = $self->{snmp}->get_hostname(); + $self->{snmp_port} = $self->{snmp}->get_port(); + + $self->get_informations(); + + my $multiple = 1; + if (scalar(keys %{$self->{interface_selected}}) == 1) { + $multiple = 0; + } + + if ($multiple == 1) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'All interfaces are ok'); + } + + $self->{new_datas} = {}; + $self->{statefile_value}->read(statefile => "snmpstandard_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{interface}) ? md5_hex($self->{option_results}->{interface}) : md5_hex('all')) . '_' . + md5_hex($self->{checking})); + $self->{new_datas}->{last_timestamp} = time(); + + foreach my $id (sort keys %{$self->{interface_selected}}) { + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits = (); + foreach (sort keys %{$self->{maps_counters}->{int}}) { + my $obj = $self->{maps_counters}->{int}->{$_}->{obj}; + next if (!defined($self->{option_results}->{$self->{maps_counters}->{int}->{$_}->{filter}})); + $obj->set(instance => $id); + + my ($value_check) = $obj->execute(values => $self->{interface_selected}->{$id}, + new_datas => $self->{new_datas}); + + if ($value_check != 0) { + $long_msg .= $long_msg_append . $obj->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $obj->threshold_check(); + push @exits, $exit2; + + my $output = $obj->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $obj->perfdata(extra_instance => $multiple); + } + + $self->{output}->output_add(long_msg => "Interface '" . $self->{interface_selected}->{$id}->{display} . "'$self->{interface_selected}->{$id}->{extra_display} $long_msg"); + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => "Inteface '" . $self->{interface_selected}->{$id}->{display} . "'$self->{interface_selected}->{$id}->{extra_display} $short_msg" + ); + } + + if ($multiple == 0) { + $self->{output}->output_add(short_msg => "Interface '" . $self->{interface_selected}->{$id}->{display} . "'$self->{interface_selected}->{$id}->{extra_display} $long_msg"); + } + } + + $self->{statefile_value}->write(data => $self->{new_datas}); + $self->{output}->display(); + $self->{output}->exit(); +} + +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 get_display_value { + my ($self, %options) = @_; + my $value = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_display} . "_" . $options{id}); + + if (defined($self->{option_results}->{display_transform_src})) { + $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); + eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + } + return $value; +} + +sub check_oids_options_change { + my ($self, %options) = @_; + + my ($regexp, $regexp_append) = ('', ''); + foreach (('oid_display', 'oid_filter', 'oid_extra_display')) { + if (my $value = $self->{statefile_cache}->get(name => $_)) { + $regexp .= $regexp_append . $value; + $regexp_append = '|'; + } + } + foreach (('oid_display', 'oid_filter', 'oid_extra_display')) { + if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} !~ /^($regexp)$/i) { + return 1; + } + } + return 0; +} + +sub reload_cache { + my ($self) = @_; + my $datas = {}; + + $datas->{oid_filter} = $self->{option_results}->{oid_filter}; + $datas->{oid_display} = $self->{option_results}->{oid_display}; + $datas->{oid_extra_display} = $self->{option_results}->{oid_extra_display}; + $datas->{last_timestamp} = time(); + $datas->{all_ids} = []; + + my $snmp_get = [ + { oid => $self->{oids_label}->{$self->{option_results}->{oid_filter}} }, + ]; + if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display}) { + push @{$snmp_get}, { oid => $self->{oids_label}->{$self->{option_results}->{oid_display}} }; + } + if (defined($self->{option_results}->{oid_extra_display}) && $self->{option_results}->{oid_extra_display} ne $self->{option_results}->{oid_display} && + $self->{option_results}->{oid_extra_display} ne $self->{option_results}->{oid_filter}) { + push @{$snmp_get}, { oid => $self->{oids_label}->{$self->{option_results}->{oid_extra_display}} }; + } + + my $result = $self->{snmp}->get_multiple_table(oids => $snmp_get); + foreach ($self->{snmp}->oid_lex_sort(keys %{$result->{$self->{oids_label}->{$self->{option_results}->{oid_filter}}}})) { + /\.([0-9]+)$/; + push @{$datas->{all_ids}}, $1; + $datas->{$self->{option_results}->{oid_filter} . "_" . $1} = $self->{output}->to_utf8($result->{$self->{oids_label}->{$self->{option_results}->{oid_filter}}}->{$_}); + } + + if (scalar(@{$datas->{all_ids}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "Can't construct cache..."); + $self->{output}->option_exit(); + } + + if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display}) { + foreach ($self->{snmp}->oid_lex_sort(keys %{$result->{$self->{oids_label}->{$self->{option_results}->{oid_display}}}})) { + /\.([0-9]+)$/; + $datas->{$self->{option_results}->{oid_display} . "_" . $1} = $self->{output}->to_utf8($result->{$self->{oids_label}->{$self->{option_results}->{oid_display}}}->{$_}); + } + } + if (defined($self->{option_results}->{oid_extra_display}) && $self->{option_results}->{oid_extra_display} ne $self->{option_results}->{oid_display} && + $self->{option_results}->{oid_extra_display} ne $self->{option_results}->{oid_filter}) { + foreach ($self->{snmp}->oid_lex_sort(keys %{$result->{$self->{oids_label}->{$self->{option_results}->{oid_extra_display}}}})) { + /\.([0-9]+)$/; + $datas->{$self->{option_results}->{oid_extra_display} . "_" . $1} = $self->{output}->to_utf8($result->{$self->{oids_label}->{$self->{option_results}->{oid_extra_display}}}->{$_}); + } + } + + $self->{statefile_cache}->write(data => $datas); +} + +sub add_selected_interface { + my ($self, %options) = @_; + + $self->{interface_selected}->{$options{id}} = { display => $self->get_display_value(id => $options{id}), extra_display => '' }; + if (defined($self->{option_results}->{oid_extra_display})) { + $self->{interface_selected}->{$options{id}}->{extra_display} = ' [ ' . $self->{statefile_cache}->get(name => $self->{option_results}->{oid_extra_display} . "_" . $options{id}) . ' ]'; + } +} + +sub get_selection { + my ($self, %options) = @_; + + # init cache file + my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_snmpstandard_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); + if (defined($self->{option_results}->{show_cache})) { + $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content()); + $self->{output}->option_exit(); + } + + $self->{interface_selected} = {}; + my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); + + if ($has_cache_file == 0 || $self->check_oids_options_change() || + !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) { + $self->reload_cache(); + $self->{statefile_cache}->read(); + } + + my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); + if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) { + foreach (@{$all_ids}) { + if ($self->{option_results}->{interface} =~ /(^|\s|,)$_(\s*,|$)/) { + $self->add_selected_interface(id => $_); + } + } + } else { + foreach (@{$all_ids}) { + my $filter_name = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_filter} . "_" . $_); + next if (!defined($filter_name)); + if (!defined($self->{option_results}->{interface})) { + $self->add_selected_interface(id => $_); + next; + } + if ($filter_name =~ /$self->{option_results}->{interface}/) { + $self->add_selected_interface(id => $_); + } + } + } + + if (scalar(keys %{$self->{interface_selected}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No entry found (maybe you should reload cache file)"); + $self->{output}->option_exit(); + } +} + +sub load_status { + my ($self, %options) = @_; + + $self->set_oids_status(); + $self->{snmp}->load(oids => [$self->{oid_adminstatus}, $self->{oid_opstatus}], instances => $self->{array_interface_selected}); +} + +sub load_traffic { + my ($self, %options) = @_; + + $self->set_oids_traffic(); + $self->{snmp}->load(oids => [$self->{oid_in32}, $self->{oid_out32}], instances => $self->{array_interface_selected}); + if ($self->{get_speed} == 1) { + $self->{snmp}->load(oids => [$self->{oid_speed32}], instances => $self->{array_interface_selected}); + } + if (!$self->{snmp}->is_snmpv1()) { + $self->{snmp}->load(oids => [$self->{oid_in64}, $self->{oid_out64}], instances => $self->{array_interface_selected}); + if ($self->{get_speed} == 1) { + $self->{snmp}->load(oids => [$self->{oid_speed64}], instances => $self->{array_interface_selected}); + } + } +} + +sub load_errors { + my ($self, %options) = @_; + + $self->set_oids_errors(); + $self->{snmp}->load(oids => [$self->{oid_ifInDiscards}, $self->{oid_ifInErrors}, + $self->{oid_ifOutDiscards}, $self->{oid_ifOutErrors}], instances => $self->{array_interface_selected}); +} + +sub load_cast { + my ($self, %options) = @_; + + $self->set_oids_cast(); + $self->{snmp}->load(oids => [$self->{oid_ifInUcastPkts}, $self->{oid_ifInBroadcastPkts}, $self->{oid_ifInMulticastPkts}, + $self->{oid_ifOutUcastPkts}, $self->{oid_ifOutMulticastPkts}, $self->{oid_ifOutBroadcastPkts}], + instances => $self->{array_interface_selected}); + if (!$self->{snmp}->is_snmpv1()) { + $self->{snmp}->load(oids => [$self->{oid_ifHCInUcastPkts}, $self->{oid_ifHCInMulticastPkts}, $self->{oid_ifHCInBroadcastPkts}, + $self->{oid_ifHCOutUcastPkts}, $self->{oid_ifHCOutMulticastPkts}, $self->{oid_ifHCOutBroadcastPkts}], + instances => $self->{array_interface_selected}); + } +} + +sub get_informations { + my ($self, %options) = @_; + + $self->get_selection(); + $self->{array_interface_selected} = [keys %{$self->{interface_selected}}]; + $self->load_status() if (defined($self->{option_results}->{add_status})); + $self->load_errors() if (defined($self->{option_results}->{add_errors})); + $self->load_traffic() if (defined($self->{option_results}->{add_traffic})); + $self->load_cast() if (defined($self->{option_results}->{add_cast}) || defined($self->{option_results}->{add_errors})); + + $self->{results} = $self->{snmp}->get_leef(); + + foreach (@{$self->{array_interface_selected}}) { + $self->add_result_status(instance => $_) if (defined($self->{option_results}->{add_status})); + $self->add_result_traffic(instance => $_) if (defined($self->{option_results}->{add_traffic})); + $self->add_result_cast(instance => $_) if (defined($self->{option_results}->{add_cast}) || defined($self->{option_results}->{add_errors})); + $self->add_result_errors(instance => $_) if (defined($self->{option_results}->{add_errors})); + } +} + +sub add_result_status { + my ($self, %options) = @_; + + $self->{interface_selected}->{$options{instance}}->{opstatus} = $self->{oid_opstatus_mapping}->{$self->{results}->{$self->{oid_opstatus} . '.' . $options{instance}}}; + $self->{interface_selected}->{$options{instance}}->{admstatus} = $self->{oid_adminstatus_mapping}->{$self->{results}->{$self->{oid_adminstatus} . '.' . $options{instance}}}; +} + +sub add_result_errors { + my ($self, %options) = @_; + + $self->{interface_selected}->{$options{instance}}->{indiscard} = $self->{results}->{$self->{oid_ifInDiscards} . '.' . $options{instance}}; + $self->{interface_selected}->{$options{instance}}->{inerror} = $self->{results}->{$self->{oid_ifInErrors} . '.' . $options{instance}}; + $self->{interface_selected}->{$options{instance}}->{outdiscard} = $self->{results}->{$self->{oid_ifOutDiscards} . '.' . $options{instance}}; + $self->{interface_selected}->{$options{instance}}->{outerror} = $self->{results}->{$self->{oid_ifOutErrors} . '.' . $options{instance}}; +} + +sub add_result_traffic { + my ($self, %options) = @_; + + $self->{interface_selected}->{$options{instance}}->{mode_traffic} = 32; + $self->{interface_selected}->{$options{instance}}->{in} = $self->{results}->{$self->{oid_in32} . '.' . $options{instance}}; + $self->{interface_selected}->{$options{instance}}->{out} = $self->{results}->{$self->{oid_out32} . '.' . $options{instance}}; + if (!$self->{snmp}->is_snmpv1()) { + if (defined($self->{results}->{$self->{oid_in64} . '.' . $options{instance}}) && $self->{results}->{$self->{oid_in64} . '.' . $options{instance}} ne '' && + $self->{results}->{$self->{oid_in64} . '.' . $options{instance}} != 0) { + $self->{interface_selected}->{$options{instance}}->{mode_traffic} = 64; + $self->{interface_selected}->{$options{instance}}->{in} = $self->{results}->{$self->{oid_in64} . '.' . $options{instance}}; + $self->{interface_selected}->{$options{instance}}->{out} = $self->{results}->{$self->{oid_out64} . '.' . $options{instance}}; + } + } + $self->{interface_selected}->{$options{instance}}->{in} *= 8; + $self->{interface_selected}->{$options{instance}}->{out} *= 8; + + $self->{interface_selected}->{$options{instance}}->{speed_in} = 0; + $self->{interface_selected}->{$options{instance}}->{speed_out} = 0; + if ($self->{get_speed} == 0) { + if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') { + $self->{interface_selected}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed} * 1000000; + $self->{interface_selected}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed} * 1000000; + } + $self->{interface_selected}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne ''); + $self->{interface_selected}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne ''); + } else { + my $interface_speed = 0; + if (defined($self->{results}->{$self->{oid_speed64} . "." . $options{instance}}) && $self->{results}->{$self->{oid_speed64} . "." . $options{instance}} ne '') { + $interface_speed = $self->{results}->{$self->{oid_speed64} . "." . $options{instance}} * 1000000; + # If 0, we put the 32 bits + if ($interface_speed == 0) { + $interface_speed = $self->{results}->{$self->{oid_speed32} . "." . $options{instance}}; + } + } else { + $interface_speed = $self->{results}->{$self->{oid_speed32} . "." . $options{instance}}; + } + + $self->{interface_selected}->{$options{instance}}->{speed_in} = $interface_speed; + $self->{interface_selected}->{$options{instance}}->{speed_out} = $interface_speed; + $self->{interface_selected}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne ''); + $self->{interface_selected}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne ''); + } +} + +sub add_result_cast { + my ($self, %options) = @_; + + $self->{interface_selected}->{$options{instance}}->{mode_cast} = 32; + $self->{interface_selected}->{$options{instance}}->{iucast} = $self->{results}->{$self->{oid_ifInUcastPkts} . '.' . $options{instance}}; + $self->{interface_selected}->{$options{instance}}->{ibcast} = defined($self->{results}->{$self->{oid_ifInBroadcastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifInBroadcastPkts} . '.' . $options{instance}} : 0; + $self->{interface_selected}->{$options{instance}}->{imcast} = defined($self->{results}->{$self->{oid_ifInMulticastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifInMulticastPkts} . '.' . $options{instance}} : 0; + $self->{interface_selected}->{$options{instance}}->{oucast} = $self->{results}->{$self->{oid_ifOutUcastPkts} . '.' . $options{instance}}; + $self->{interface_selected}->{$options{instance}}->{omcast} = defined($self->{results}->{$self->{oid_ifOutMulticastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifOutMulticastPkts} . '.' . $options{instance}} : 0; + $self->{interface_selected}->{$options{instance}}->{obcast} = defined($self->{results}->{$self->{oid_ifOutBroadcastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifOutBroadcastPkts} . '.' . $options{instance}} : 0; + if (!$self->{snmp}->is_snmpv1()) { + my $iucast = $self->{results}->{$self->{oid_ifHCInUcastPkts} . '.' . $options{instance}}; + if (defined($iucast) && $iucast =~ /[1-9]/) { + $self->{interface_selected}->{$options{instance}}->{iucast} = $iucast; + $self->{interface_selected}->{$options{instance}}->{imcast} = defined($self->{results}->{$self->{oid_ifHCInMulticastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCInMulticastPkts} . '.' . $options{instance}} : 0; + $self->{interface_selected}->{$options{instance}}->{ibcast} = defined($self->{results}->{$self->{oid_ifHCInBroadcastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCInBroadcastPkts} . '.' . $options{instance}} : 0; + $self->{interface_selected}->{$options{instance}}->{oucast} = $self->{results}->{$self->{oid_ifHCOutUcastPkts} . '.' . $options{instance}}; + $self->{interface_selected}->{$options{instance}}->{omcast} = defined($self->{results}->{$self->{oid_ifHCOutMulticastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCOutMulticastPkts} . '.' . $options{instance}} : 0; + $self->{interface_selected}->{$options{instance}}->{obcast} = defined($self->{results}->{$self->{oid_ifHCOutBroadcastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCOutBroadcastPkts} . '.' . $options{instance}} : 0; + $self->{interface_selected}->{$options{instance}}->{mode_cast} = 64; + } + } + + $self->{interface_selected}->{$options{instance}}->{total_in_packets} = $self->{interface_selected}->{$options{instance}}->{iucast} + $self->{interface_selected}->{$options{instance}}->{imcast} + $self->{interface_selected}->{$options{instance}}->{ibcast}; + $self->{interface_selected}->{$options{instance}}->{total_out_packets} = $self->{interface_selected}->{$options{instance}}->{oucast} + $self->{interface_selected}->{$options{instance}}->{omcast} + $self->{interface_selected}->{$options{instance}}->{obcast}; +} + +1; + +__END__ + +=head1 MODE + +Check interfaces. + +=over 8 + +=item B<--add-status> + +Check interface status (By default if no --add-* option is set). + +=item B<--add-traffic> + +Check interface traffic. + +=item B<--add-errors> + +Check interface errors. + +=item B<--add-cast> + +Check interface cast. + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). +Can used special variables like: %{admstatus}, %{opstatus}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%). + +=item B<--critical-*> + +Threshold critical. +Can be: 'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%). + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). + +=item B<--units-errors> + +Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). + +=item B<--nagvis-perfdata> + +Display traffic perfdata to be compatible with nagvis widget. + +=item B<--interface> + +Set the interface (number expected) ex: 1,2,... (empty means 'check all interface'). + +=item B<--name> + +Allows to use interface name with option --interface instead of interface oid index (Can be a regexp) + +=item B<--speed> + +Set interface speed for incoming/outgoing traffic (in Mb). + +=item B<--speed-in> + +Set interface speed for incoming traffic (in Mb). + +=item B<--speed-out> + +Set interface speed for outgoing traffic (in Mb). + +=item B<--reload-cache-time> + +Time in seconds before reloading cache file (default: 180). + +=item B<--oid-filter> + +Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName). + +=item B<--oid-display> + +Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName). + +=item B<--oid-extra-display> + +Add an OID to display. + +=item B<--display-transform-src> + +Regexp src to transform display value. + +=item B<--display-transform-dst> + +Regexp dst to transform display value. + +=item B<--show-cache> + +Display cache interface datas. + +=back + +=cut diff --git a/snmp_standard/mode/listinterfaces.pm b/snmp_standard/mode/listinterfaces.pm index ea7aef6b5..91ea303d1 100644 --- a/snmp_standard/mode/listinterfaces.pm +++ b/snmp_standard/mode/listinterfaces.pm @@ -91,7 +91,8 @@ sub run { foreach (sort @{$self->{interface_id_selected}}) { my $display_value = $self->get_display_value(id => $_); - my $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' ? ($result->{$oid_speed64 . "." . $_}) : (int($result->{$oid_speed32 . "." . $_} / 1000 / 1000))); + my $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' && $result->{$oid_speed64 . "." . $_} != 0 ? + ($result->{$oid_speed64 . "." . $_}) : (sprintf("%g", $result->{$oid_speed32 . "." . $_} / 1000 / 1000))); if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') { $interface_speed = $self->{option_results}->{speed}; } @@ -223,7 +224,8 @@ sub disco_show { foreach (sort @{$self->{interface_id_selected}}) { my $display_value = $self->get_display_value(id => $_); - my $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' ? ($result->{$oid_speed64 . "." . $_}) : (int($result->{$oid_speed32 . "." . $_} / 1000 / 1000))); + my $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' && $result->{$oid_speed64 . "." . $_} != 0 ? + ($result->{$oid_speed64 . "." . $_}) : (sprintf("%g", $result->{$oid_speed32 . "." . $_} / 1000 / 1000))); if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') { $interface_speed = $self->{option_results}->{speed}; } diff --git a/snmp_standard/mode/memory.pm b/snmp_standard/mode/memory.pm index 0954f275d..cf86277aa 100644 --- a/snmp_standard/mode/memory.pm +++ b/snmp_standard/mode/memory.pm @@ -107,13 +107,15 @@ sub run { my $prct_used = $nobuf_used * 100 / $total_size; my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); my ($nobuf_value, $nobuf_unit) = $self->{perfdata}->change_bytes(value => $nobuf_used); my ($buffer_value, $buffer_unit) = $self->{perfdata}->change_bytes(value => $buffer_used); my ($cached_value, $cached_unit) = $self->{perfdata}->change_bytes(value => $cached_used); my ($shared_value, $shared_unit) = $self->{perfdata}->change_bytes(value => $shared_used); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Ram used (-buffers/cache) %s (%.2f%%), Buffer: %s, Cached: %s, Shared: %s", + short_msg => sprintf("Ram Total: %s, Used (-buffers/cache): %s (%.2f%%), Buffer: %s, Cached: %s, Shared: %s", + $total_value . " " . $total_unit, $nobuf_value . " " . $nobuf_unit, $prct_used, $buffer_value . " " . $buffer_unit, $cached_value . " " . $cached_unit, diff --git a/snmp_standard/mode/packeterrors.pm b/snmp_standard/mode/packeterrors.pm deleted file mode 100644 index cf8fdee9d..000000000 --- a/snmp_standard/mode/packeterrors.pm +++ /dev/null @@ -1,506 +0,0 @@ -# -# Copyright 2015 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::packeterrors; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::statefile; -use Digest::MD5 qw(md5_hex); - -my @operstatus = ("up", "down", "testing", "unknown", "dormant", "notPresent", "lowerLayerDown"); -my %oids_iftable = ( - 'ifdesc' => '.1.3.6.1.2.1.2.2.1.2', - 'ifalias' => '.1.3.6.1.2.1.31.1.1.1.18', - 'ifname' => '.1.3.6.1.2.1.31.1.1.1.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 => - { - "warning-in-discard:s" => { name => 'warning_in_discard' }, - "critical-in-discard:s" => { name => 'critical_in_discard' }, - "warning-out-discard:s" => { name => 'warning_out_discard' }, - "critical-out-discard:s" => { name => 'critical_out_discard' }, - "warning-in-error:s" => { name => 'warning_in_error' }, - "critical-in-error:s" => { name => 'critical_in_error' }, - "warning-out-error:s" => { name => 'warning_out_error' }, - "critical-out-error:s" => { name => 'critical_out_error' }, - "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, - "name" => { name => 'use_name' }, - "interface:s" => { name => 'interface' }, - "skip" => { name => 'skip' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - "oid-filter:s" => { name => 'oid_filter', default => 'ifname'}, - "oid-display:s" => { name => 'oid_display', default => 'ifname'}, - "display-transform-src:s" => { name => 'display_transform_src' }, - "display-transform-dst:s" => { name => 'display_transform_dst' }, - "show-cache" => { name => 'show_cache' }, - }); - - $self->{interface_id_selected} = []; - $self->{statefile_cache} = centreon::plugins::statefile->new(%options); - $self->{statefile_value} = centreon::plugins::statefile->new(%options); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach my $label (('warning_in_discard', 'critical_in_discard', 'warning_out_discard', 'critical_out_discard', - 'warning_in_error', 'critical_in_error', 'warning_out_error', 'critical_out_error')) { - my ($label_opt) = $label; - $label_opt =~ tr/_/-/; - if (($self->{perfdata}->threshold_validate(label => $label_opt, value => $self->{option_results}->{$label})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong " . $label_opt . " threshold '" . $self->{option_results}->{$label} . "'."); - $self->{output}->option_exit(); - } - } - - $self->{option_results}->{oid_filter} = lc($self->{option_results}->{oid_filter}); - if ($self->{option_results}->{oid_filter} !~ /^(ifdesc|ifalias|ifname)$/) { - $self->{output}->add_option_msg(short_msg => "Unsupported --oid-filter option."); - $self->{output}->option_exit(); - } - $self->{option_results}->{oid_display} = lc($self->{option_results}->{oid_display}); - if ($self->{option_results}->{oid_display} !~ /^(ifdesc|ifalias|ifname)$/) { - $self->{output}->add_option_msg(short_msg => "Unsupported --oid-display option."); - $self->{output}->option_exit(); - } - - $self->{statefile_cache}->check_options(%options); - $self->{statefile_value}->check_options(%options); -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - $self->{snmp_port} = $self->{snmp}->get_port(); - - $self->manage_selection(); - - my $oid_adminstatus = '.1.3.6.1.2.1.2.2.1.7'; - my $oid_operstatus = '.1.3.6.1.2.1.2.2.1.8'; - - # 32bits - my $oid_ifInUcastPkts = '.1.3.6.1.2.1.2.2.1.11'; - my $oid_ifInBroadcastPkts = '.1.3.6.1.2.1.31.1.1.1.3'; - my $oid_ifInMulticastPkts = '.1.3.6.1.2.1.31.1.1.1.2'; - my $oid_ifOutUcastPkts = '.1.3.6.1.2.1.2.2.1.17'; - my $oid_ifOutMulticastPkts = '.1.3.6.1.2.1.31.1.1.1.4'; - my $oid_ifOutBroadcastPkts = '.1.3.6.1.2.1.31.1.1.1.5'; - - # 64 bits - my $oid_ifHCInUcastPkts = '.1.3.6.1.2.1.31.1.1.1.7'; - my $oid_ifHCInMulticastPkts = '.1.3.6.1.2.1.31.1.1.1.8'; - my $oid_ifHCInBroadcastPkts = '.1.3.6.1.2.1.31.1.1.1.9'; - my $oid_ifHCOutUcastPkts = '.1.3.6.1.2.1.31.1.1.1.11'; - my $oid_ifHCOutMulticastPkts = '.1.3.6.1.2.1.31.1.1.1.12'; - my $oid_ifHCOutBroadcastPkts = '.1.3.6.1.2.1.31.1.1.1.13'; - - # 'discard' 'error' only 32 bits - my $oid_ifInDiscards = '.1.3.6.1.2.1.2.2.1.13'; - my $oid_ifInErrors = '.1.3.6.1.2.1.2.2.1.14'; - my $oid_ifOutDiscards = '.1.3.6.1.2.1.2.2.1.19'; - my $oid_ifOutErrors = '.1.3.6.1.2.1.2.2.1.20'; - - my $new_datas = {}; - $self->{statefile_value}->read(statefile => "snmpstandard_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{interface}) ? md5_hex($self->{option_results}->{interface}) : md5_hex('all'))); - - foreach (@{$self->{interface_id_selected}}) { - $self->{snmp}->load(oids => [$oid_adminstatus . "." . $_, $oid_operstatus . "." . $_, - $oid_ifInUcastPkts . "." . $_, $oid_ifInBroadcastPkts . "." . $_, $oid_ifInMulticastPkts . "." . $_, - $oid_ifOutUcastPkts . "." . $_, $oid_ifOutMulticastPkts . "." . $_, $oid_ifOutBroadcastPkts . "." . $_, - $oid_ifInDiscards . "." . $_, $oid_ifInErrors . "." . $_, - $oid_ifOutDiscards . "." . $_, $oid_ifOutErrors . "." . $_]); - if (!$self->{snmp}->is_snmpv1()) { - $self->{snmp}->load(oids => [$oid_ifHCInUcastPkts . "." . $_, $oid_ifHCInMulticastPkts . "." . $_, $oid_ifHCInMulticastPkts . "." . $_, - $oid_ifHCOutUcastPkts . "." . $_, $oid_ifHCOutMulticastPkts . "." . $_, $oid_ifHCOutBroadcastPkts . "." . $_]); - } - } - - my $result = $self->{snmp}->get_leef(nothing_quit => 1); - $new_datas->{last_timestamp} = time(); - my $buffer_creation = 0; - my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); - - - if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All interfaces are ok.'); - } - - foreach (sort @{$self->{interface_id_selected}}) { - my $display_value = $self->get_display_value(id => $_); - - if ($operstatus[$result->{$oid_operstatus . "." . $_} - 1] ne "up") { - if (!defined($self->{option_results}->{skip}) && (!defined($result->{$oid_adminstatus . "." . $_}) || $operstatus[$result->{$oid_adminstatus . "." . $_} - 1] eq 'up') ) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "Interface '" . $display_value . "' is not ready: " . $operstatus[$result->{$oid_operstatus . "." . $_} - 1]); - } else { - # Avoid empty message - if (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Interface '" . $display_value . "' is not up (normal state)"); - } - $self->{output}->output_add(long_msg => "Skip interface '" . $display_value . "'."); - } - next; - } - - ################# - # New values - ################# - my $old_mode = $self->{statefile_value}->get(name => 'mode_' . $_); - $new_datas->{'mode_' . $_} = '32'; - $new_datas->{'in_discard_' . $_} = $result->{$oid_ifInDiscards . "." . $_}; - $new_datas->{'in_error_' . $_} = $result->{$oid_ifInErrors . "." . $_}; - $new_datas->{'out_discard_' . $_} = $result->{$oid_ifOutDiscards . "." . $_}; - $new_datas->{'out_error_' . $_} = $result->{$oid_ifOutErrors . "." . $_}; - - $new_datas->{'in_ucast_' . $_} = $result->{$oid_ifInUcastPkts . "." . $_}; - $new_datas->{'in_bcast_' . $_} = defined($result->{$oid_ifInBroadcastPkts . "." . $_}) ? $result->{$oid_ifInBroadcastPkts . "." . $_} : 0; - $new_datas->{'in_mcast_' . $_} = defined($result->{$oid_ifInMulticastPkts . "." . $_}) ? $result->{$oid_ifInMulticastPkts . "." . $_} : 0; - $new_datas->{'out_ucast_' . $_} = $result->{$oid_ifOutUcastPkts . "." . $_}; - $new_datas->{'out_bcast_' . $_} = defined($result->{$oid_ifOutMulticastPkts . "." . $_}) ? $result->{$oid_ifOutMulticastPkts . "." . $_} : 0; - $new_datas->{'out_mcast_' . $_} = defined($result->{$oid_ifOutBroadcastPkts . "." . $_}) ? $result->{$oid_ifOutBroadcastPkts . "." . $_} : 0; - - if (defined($result->{$oid_ifHCInUcastPkts . "." . $_}) && $result->{$oid_ifHCInUcastPkts . "." . $_} ne '' && $result->{$oid_ifHCInUcastPkts . "." . $_} != 0) { - $new_datas->{'in_ucast_' . $_} = $result->{$oid_ifHCInUcastPkts . "." . $_}; - $new_datas->{'in_mcast_' . $_} = defined($result->{$oid_ifHCInMulticastPkts . "." . $_}) ? $result->{$oid_ifHCInMulticastPkts . "." . $_} : 0; - $new_datas->{'in_bcast_' . $_} = defined($result->{$oid_ifHCInBroadcastPkts . "." . $_}) ? $result->{$oid_ifHCInBroadcastPkts . "." . $_} : 0; - $new_datas->{'out_ucast_' . $_} = $result->{$oid_ifHCOutUcastPkts . "." . $_}; - $new_datas->{'out_mcast_' . $_} = defined($result->{$oid_ifHCOutMulticastPkts . "." . $_}) ? $result->{$oid_ifHCOutMulticastPkts . "." . $_} : 0; - $new_datas->{'out_bcast_' . $_} = defined($result->{$oid_ifHCOutBroadcastPkts . "." . $_}) ? $result->{$oid_ifHCOutBroadcastPkts . "." . $_} : 0; - $new_datas->{'mode_' . $_} = '64'; - } - - # We change mode. need to recreate a buffer - if (!defined($old_timestamp) || !defined($old_mode) || $new_datas->{'mode_' . $_} ne $old_mode) { - $buffer_creation = 1; - next; - } - - ################# - # Old values - ################# - my @getting = ('in_ucast', 'in_bcast', 'in_mcast', 'out_ucast', 'out_bcast', 'out_mcast', - 'in_discard', 'in_error', 'out_discard', 'out_error'); - my $old_datas = {}; - foreach my $key (@getting) { - $old_datas->{$key} = $self->{statefile_value}->get(name => $key . '_' . $_); - if (!defined($old_datas->{$key}) || $new_datas->{$key . '_' . $_} < $old_datas->{$key}) { - # We set 0. Has reboot. - $old_datas->{$key} = 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 $total_in_packets = ($new_datas->{'in_ucast_' . $_} - $old_datas->{in_ucast}) + ($new_datas->{'in_bcast_' . $_} - $old_datas->{in_bcast}) + ($new_datas->{'in_mcast_' . $_} - $old_datas->{in_mcast}); - my $total_out_packets = ($new_datas->{'out_ucast_' . $_} - $old_datas->{out_ucast}) + ($new_datas->{'out_bcast_' . $_} - $old_datas->{out_bcast}) + ($new_datas->{'out_mcast_' . $_} - $old_datas->{out_mcast}); - - my $delta_in_discard = defined($new_datas->{'in_discard_' . $_}) ? ($new_datas->{'in_discard_' . $_} - $old_datas->{in_discard}) : 0; - my $delta_in_error = defined($new_datas->{'in_error_' . $_}) ? ($new_datas->{'in_error_' . $_} - $old_datas->{in_error}) : 0; - my $delta_out_discard = defined($new_datas->{'out_discard_' . $_}) ? ($new_datas->{'out_discard_' . $_} - $old_datas->{out_discard}) : 0; - my $delta_out_error = defined($new_datas->{'out_error_' . $_}) ? ($new_datas->{'out_error_' . $_} - $old_datas->{out_error}) : 0; - - my $in_discard_absolute_per_sec = $delta_in_discard / $time_delta; - my $in_error_absolute_per_sec = $delta_in_error / $time_delta; - my $out_discard_absolute_per_sec = $delta_out_discard / $time_delta; - my $out_error_absolute_per_sec = $delta_out_error / $time_delta; - my $in_discard_prct = sprintf("%.2f", ($total_in_packets == 0) ? 0 : $delta_in_discard * 100 / $total_in_packets); - my $in_error_prct = sprintf("%.2f", ($total_in_packets == 0) ? 0 : $delta_in_error * 100 / $total_in_packets); - my $out_discard_prct = sprintf("%.2f", ($total_out_packets == 0) ? 0 : $delta_out_discard * 100 / $total_out_packets); - my $out_error_prct = sprintf("%.2f", ($total_out_packets == 0) ? 0 : $delta_out_error * 100 / $total_out_packets); - - ########### - # Manage Output - ########### - my $exit1 = $self->{perfdata}->threshold_check(value => $in_discard_prct, threshold => [ { label => 'critical-in-discard', 'exit_litteral' => 'critical' }, { label => 'warning-in-discard', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $in_error_prct, threshold => [ { label => 'critical-in-error', 'exit_litteral' => 'critical' }, { label => 'warning-in-error', exit_litteral => 'warning' } ]); - my $exit3 = $self->{perfdata}->threshold_check(value => $out_discard_prct, threshold => [ { label => 'critical-out-discard', 'exit_litteral' => 'critical' }, { label => 'warning-out-discard', exit_litteral => 'warning' } ]); - my $exit4 = $self->{perfdata}->threshold_check(value => $out_error_prct, threshold => [ { label => 'critical-out-error', 'exit_litteral' => 'critical' }, { label => 'warning-out-error', exit_litteral => 'warning' } ]); - - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4 ]); - $self->{output}->output_add(long_msg => sprintf("Interface '%s' Packets In Discard : %s, In Error : %s, Out Discard: %s, Out Error: %s", $display_value, - defined($new_datas->{'in_discard_' . $_}) ? $in_discard_prct . ' % (' . $delta_in_discard . ')' : 'unknown', - defined($new_datas->{'in_error_' . $_}) ? $in_error_prct . ' % (' . $delta_in_error . ')' : 'unknown', - defined($new_datas->{'out_discard_' . $_}) ? $out_discard_prct . ' % (' . $delta_out_discard . ')' : 'unknown', - defined($new_datas->{'out_error_' . $_}) ? $out_error_prct . ' % (' . $delta_out_error . ')' : 'unknown' - )); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Interface '%s' Packets In Discard : %s, In Error : %s, Out Discard: %s, Out Error: %s", $display_value, - defined($new_datas->{'in_discard_' . $_}) ? $in_discard_prct . ' % (' . $delta_in_discard . ')' : 'unknown', - defined($new_datas->{'in_error_' . $_}) ? $in_error_prct . ' % (' . $delta_in_error . ')' : 'unknown', - defined($new_datas->{'out_discard_' . $_}) ? $out_discard_prct . ' % (' . $delta_out_discard . ')' : 'unknown', - defined($new_datas->{'out_error_' . $_}) ? $out_error_prct . ' % (' . $delta_out_error . ')' : 'unknown' - )); - } - - my $extra_label = ''; - $extra_label = '_' . $display_value if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp})); - if (defined($new_datas->{'in_discard_' . $_})) { - $self->{output}->perfdata_add(label => 'packets_discard_in' . $extra_label, unit => '%', - value => $in_discard_prct, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in-discard'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in-discard'), - min => 0, max => 100); - } - if (defined($new_datas->{'in_error_' . $_})) { - $self->{output}->perfdata_add(label => 'packets_error_in' . $extra_label, unit => '%', - value => $in_error_prct, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in-error'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in-error'), - min => 0, max => 100); - } - if (defined($new_datas->{'out_discard_' . $_})) { - $self->{output}->perfdata_add(label => 'packets_discard_out' . $extra_label, unit => '%', - value => $out_discard_prct, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out-discard'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out-discard'), - min => 0, max => 100); - } - if (defined($new_datas->{'out_error_' . $_})) { - $self->{output}->perfdata_add(label => 'packets_error_out' . $extra_label, unit => '%', - value => $out_error_prct, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out-error'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out-error'), - min => 0, max => 100); - } - } - - $self->{statefile_value}->write(data => $new_datas); - if ($buffer_creation == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub get_display_value { - my ($self, %options) = @_; - my $value = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_display} . "_" . $options{id}); - - if (defined($self->{option_results}->{display_transform_src})) { - $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; - } - return $value; -} - -sub reload_cache { - my ($self) = @_; - my $datas = {}; - - $datas->{oid_filter} = $self->{option_results}->{oid_filter}; - $datas->{oid_display} = $self->{option_results}->{oid_display}; - $datas->{last_timestamp} = time(); - $datas->{all_ids} = []; - my $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_filter}}); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /\.([0-9]+)$/); - push @{$datas->{all_ids}}, $1; - $datas->{$self->{option_results}->{oid_filter} . "_" . $1} = $self->{output}->to_utf8($result->{$key}); - } - - if (scalar(@{$datas->{all_ids}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "Can't construct cache..."); - $self->{output}->option_exit(); - } - - if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display}) { - $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_display}}); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /\.([0-9]+)$/); - $datas->{$self->{option_results}->{oid_display} . "_" . $1} = $self->{output}->to_utf8($result->{$key}); - } - } - - $self->{statefile_cache}->write(data => $datas); -} - -sub manage_selection { - my ($self, %options) = @_; - - # init cache file - my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_snmpstandard_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); - if (defined($self->{option_results}->{show_cache})) { - $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content()); - $self->{output}->option_exit(); - } - - my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); - my $oid_display = $self->{statefile_cache}->get(name => 'oid_display'); - my $oid_filter = $self->{statefile_cache}->get(name => 'oid_filter'); - if ($has_cache_file == 0 || - ($self->{option_results}->{oid_display} !~ /^($oid_display|$oid_filter)$/i || $self->{option_results}->{oid_filter} !~ /^($oid_display|$oid_filter)$/i) || - !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) { - $self->reload_cache(); - $self->{statefile_cache}->read(); - } - - my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); - if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) { - # get by ID - push @{$self->{interface_id_selected}}, $self->{option_results}->{interface}; - my $name = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_display} . "_" . $self->{option_results}->{interface}); - if (!defined($name)) { - $self->{output}->add_option_msg(short_msg => "No interface found for id '" . $self->{option_results}->{interface} . "'."); - $self->{output}->option_exit(); - } - } else { - foreach my $i (@{$all_ids}) { - my $filter_name = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_filter} . "_" . $i); - next if (!defined($filter_name)); - if (!defined($self->{option_results}->{interface})) { - push @{$self->{interface_id_selected}}, $i; - next; - } - if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/i) { - push @{$self->{interface_id_selected}}, $i; - } - if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/) { - push @{$self->{interface_id_selected}}, $i; - } - if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{interface}) { - push @{$self->{interface_id_selected}}, $i; - } - } - - if (scalar(@{$self->{interface_id_selected}}) <= 0) { - if (defined($self->{option_results}->{interface})) { - $self->{output}->add_option_msg(short_msg => "No interface found for name '" . $self->{option_results}->{interface} . "' (maybe you should reload cache file)."); - } else { - $self->{output}->add_option_msg(short_msg => "No interface found (maybe you should reload cache file)."); - } - $self->{output}->option_exit(); - } - } -} - -1; - -__END__ - -=head1 MODE - -=over 8 - -=item B<--warning-in-discard> - -Threshold warning in percent for 'in' discard packets. - -=item B<--critical-in-discard> - -Threshold critical in percent for 'in' discard packets. - -=item B<--warning-out-discard> - -Threshold warning in percent for 'out' discard packets. - -=item B<--critical-out-discard> - -Threshold critical in percent for 'out' discard packets. - -=item B<--warning-in-error> - -Threshold warning in percent for 'in' error packets. - -=item B<--critical-in-error> - -Threshold critical in percent for 'in' error packets. - -=item B<--warning-out-error> - -Threshold warning in percent for 'out' error packets. - -=item B<--critical-out-error> - -Threshold critical in percent for 'out' error packets. - -=item B<--interface> - -Set the interface (number expected) ex: 1, 2,... (empty means 'check all interface'). - -=item B<--name> - -Allows to use interface name with option --interface instead of interface oid index. - -=item B<--regexp> - -Allows to use regexp to filter interfaces (with option --name). - -=item B<--regexp-isensitive> - -Allows to use regexp non case-sensitive (with --regexp). - -=item B<--skip> - -Skip errors on interface status. - -=item B<--reload-cache-time> - -Time in seconds before reloading cache file (default: 180). - -=item B<--oid-filter> - -Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName). - -=item B<--oid-display> - -Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName). - -=item B<--display-transform-src> - -Regexp src to transform display value. (security risk!!!) - -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) - -=item B<--show-cache> - -Display cache interface datas. - -=back - -=cut diff --git a/snmp_standard/mode/traffic.pm b/snmp_standard/mode/traffic.pm deleted file mode 100644 index 676f3fde8..000000000 --- a/snmp_standard/mode/traffic.pm +++ /dev/null @@ -1,507 +0,0 @@ -# -# Copyright 2015 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::traffic; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::statefile; -use Digest::MD5 qw(md5_hex); - -my @operstatus = ("up", "down", "testing", "unknown", "dormant", "notPresent", "lowerLayerDown"); -my %oids_iftable = ( - 'ifdesc' => '.1.3.6.1.2.1.2.2.1.2', - 'ifalias' => '.1.3.6.1.2.1.31.1.1.1.18', - 'ifname' => '.1.3.6.1.2.1.31.1.1.1.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 => - { - "warning-in:s" => { name => 'warning_in' }, - "critical-in:s" => { name => 'critical_in' }, - "warning-out:s" => { name => 'warning_out' }, - "critical-out:s" => { name => 'critical_out' }, - "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, - "name" => { name => 'use_name' }, - "interface:s" => { name => 'interface' }, - "speed:s" => { name => 'speed' }, - "speed-in:s" => { name => 'speed_in' }, - "speed-out:s" => { name => 'speed_out' }, - "skip" => { name => 'skip' }, - "skip-speed0" => { name => 'skip_speed0' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - "oid-filter:s" => { name => 'oid_filter', default => 'ifname'}, - "oid-display:s" => { name => 'oid_display', default => 'ifname'}, - "display-transform-src:s" => { name => 'display_transform_src' }, - "display-transform-dst:s" => { name => 'display_transform_dst' }, - "show-cache" => { name => 'show_cache' }, - }); - - $self->{interface_id_selected} = []; - $self->{get_speed} = 0; - $self->{statefile_cache} = centreon::plugins::statefile->new(%options); - $self->{statefile_value} = centreon::plugins::statefile->new(%options); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning-in', value => $self->{option_results}->{warning_in})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning 'in' threshold '" . $self->{option_results}->{warning_in} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-in', value => $self->{option_results}->{critical_in})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical 'in' threshold '" . $self->{option_results}->{critical_in} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warning-out', value => $self->{option_results}->{warning_out})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning 'out' threshold '" . $self->{option_results}->{warning_out} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-out', value => $self->{option_results}->{critical_out})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical 'out' threshold '" . $self->{option_results}->{critical_out} . "'."); - $self->{output}->option_exit(); - } - $self->{option_results}->{oid_filter} = lc($self->{option_results}->{oid_filter}); - if ($self->{option_results}->{oid_filter} !~ /^(ifdesc|ifalias|ifname)$/) { - $self->{output}->add_option_msg(short_msg => "Unsupported --oid-filter option."); - $self->{output}->option_exit(); - } - $self->{option_results}->{oid_display} = lc($self->{option_results}->{oid_display}); - if ($self->{option_results}->{oid_display} !~ /^(ifdesc|ifalias|ifname)$/) { - $self->{output}->add_option_msg(short_msg => "Unsupported --oid-display option."); - $self->{output}->option_exit(); - } - if ((!defined($self->{option_results}->{speed}) || $self->{option_results}->{speed} eq '') && - ((!defined($self->{option_results}->{speed_in}) || $self->{option_results}->{speed_in} eq '') || - (!defined($self->{option_results}->{speed_out}) || $self->{option_results}->{speed_out} eq ''))) { - $self->{get_speed} = 1; - } - - $self->{statefile_cache}->check_options(%options); - $self->{statefile_value}->check_options(%options); -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - $self->{snmp_port} = $self->{snmp}->get_port(); - - $self->manage_selection(); - - my $oid_adminstatus = '.1.3.6.1.2.1.2.2.1.7'; - my $oid_operstatus = '.1.3.6.1.2.1.2.2.1.8'; - my $oid_speed32 = '.1.3.6.1.2.1.2.2.1.5'; # in b/s - my $oid_in32 = '.1.3.6.1.2.1.2.2.1.10'; # in B - my $oid_out32 = '.1.3.6.1.2.1.2.2.1.16'; # in B - my $oid_speed64 = '.1.3.6.1.2.1.31.1.1.1.15'; # need multiple by '1000000' - my $oid_in64 = '.1.3.6.1.2.1.31.1.1.1.6'; # in B - my $oid_out64 = '.1.3.6.1.2.1.31.1.1.1.10'; # in B - - my $new_datas = {}; - $self->{statefile_value}->read(statefile => "snmpstandard_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{interface}) ? md5_hex($self->{option_results}->{interface}) : md5_hex('all'))); - - foreach (@{$self->{interface_id_selected}}) { - $self->{snmp}->load(oids => [$oid_adminstatus . "." . $_, $oid_operstatus . "." . $_, $oid_in32 . "." . $_, $oid_out32 . "." . $_]); - if ($self->{get_speed} == 1) { - $self->{snmp}->load(oids => [$oid_speed32 . "." . $_]); - } - if (!$self->{snmp}->is_snmpv1()) { - $self->{snmp}->load(oids => [$oid_in64 . "." . $_, $oid_out64 . "." . $_]); - if ($self->{get_speed} == 1) { - $self->{snmp}->load(oids => [$oid_speed64 . "." . $_]); - } - } - } - - my $result = $self->{snmp}->get_leef(); - $new_datas->{last_timestamp} = time(); - my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); - my $buffer_creation = 0; - if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All traffic are ok'); - } - - foreach (sort @{$self->{interface_id_selected}}) { - my $display_value = $self->get_display_value(id => $_); - - if ($operstatus[$result->{$oid_operstatus . "." . $_} - 1] ne "up") { - if (!defined($self->{option_results}->{skip}) && (!defined($result->{$oid_adminstatus . "." . $_}) || $operstatus[$result->{$oid_adminstatus . "." . $_} - 1] eq 'up') ) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "Interface '" . $display_value . "' is not ready: " . $operstatus[$result->{$oid_operstatus . "." . $_} - 1]); - } else { - # Avoid getting "buffer creation..." alone - if (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Interface '" . $display_value . "' is not up (normal state)"); - } - $self->{output}->output_add(long_msg => "Skip interface '" . $display_value . "'."); - } - next; - } - - # Manage interface speed - my ($interface_speed_in, $interface_speed_out); - - if ($self->{get_speed} == 0) { - if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') { - $interface_speed_in = $self->{option_results}->{speed} * 1000000; - $interface_speed_out = $self->{option_results}->{speed} * 1000000; - } - $interface_speed_in = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne ''); - $interface_speed_out = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne ''); - } else { - if ((!defined($result->{$oid_speed32 . "." . $_}) || $result->{$oid_speed32 . "." . $_} !~ /^[0-9]+$/) && - (!defined($result->{$oid_speed64 . "." . $_}) || $result->{$oid_speed64 . "." . $_} !~ /^[0-9]+$/)) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Interface '" . $display_value . "' Speed is null or incorrect. You should force the value with --speed option"); - next; - } - my $interface_speed; - - if (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '') { - $interface_speed = $result->{$oid_speed64 . "." . $_} * 1000000; - # If 0, we put the 32 bits - if ($interface_speed == 0) { - $interface_speed = $result->{$oid_speed32 . "." . $_}; - } - } else { - $interface_speed = $result->{$oid_speed32 . "." . $_}; - } - if (!defined($interface_speed) || $interface_speed == 0) { - if (!defined($self->{option_results}->{skip_speed0})) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Interface '" . $display_value . "' Speed is 0. You should force the value with --speed option"); - } else { - $self->{output}->output_add(long_msg => "Skip interface '" . $display_value . "' (speed is 0)."); - } - next; - } - $interface_speed_in = $interface_speed; - $interface_speed_out = $interface_speed; - $interface_speed_in = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne ''); - $interface_speed_out = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne ''); - } - - my $old_mode = $self->{statefile_value}->get(name => 'mode_' . $_); - $new_datas->{'mode_' . $_} = '32'; - - $new_datas->{'in_' . $_} = $result->{$oid_in32 . "." . $_}; - if (defined($result->{$oid_in64 . "." . $_}) && $result->{$oid_in64 . "." . $_} ne '' && $result->{$oid_in64 . "." . $_} != 0) { - $new_datas->{'in_' . $_} = $result->{$oid_in64 . "." . $_}; - $new_datas->{'mode_' . $_} = '64'; - } - $new_datas->{'out_' . $_} = $result->{$oid_out32 . "." . $_}; - if (defined($result->{$oid_out64 . "." . $_}) && $result->{$oid_out64 . "." . $_} ne '' && $result->{$oid_out64 . "." . $_} != 0) { - $new_datas->{'out_' . $_} = $result->{$oid_out64 . "." . $_}; - $new_datas->{'mode_' . $_} = '64'; - } - - # Check if there is no values. Can happen :) - if (!defined($new_datas->{'out_' . $_}) || !defined($new_datas->{'in_' . $_})) { - # Avoid empty message - if (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Interface '" . $display_value . "' is up"); - } - $self->{output}->output_add(long_msg => "Skip interface '" . $display_value . "': bytes values are missing."); - next; - } - $new_datas->{'out_' . $_} *= 8; - $new_datas->{'in_' . $_} *= 8; - - # We change mode. need to recreate a buffer - if (!defined($old_mode) || $new_datas->{'mode_' . $_} ne $old_mode) { - $buffer_creation = 1; - next; - } - - my $old_in = $self->{statefile_value}->get(name => 'in_' . $_); - my $old_out = $self->{statefile_value}->get(name => 'out_' . $_); - if (!defined($old_in) || !defined($old_out)) { - $buffer_creation = 1; - next; - } - - if ($new_datas->{'in_' . $_} < $old_in) { - # We set 0. Has reboot. - $old_in = 0; - } - if ($new_datas->{'out_' . $_} < $old_out) { - # We set 0. Has reboot. - $old_out = 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 $in_absolute_per_sec = ($new_datas->{'in_' . $_} - $old_in) / $time_delta; - my $out_absolute_per_sec = ($new_datas->{'out_' . $_} - $old_out) / $time_delta; - my $in_prct = $in_absolute_per_sec * 100 / $interface_speed_in; - my $out_prct = $out_absolute_per_sec * 100 / $interface_speed_out; - - ########### - # Manage Output - ########### - my $exit1 = $self->{perfdata}->threshold_check(value => $in_prct, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $out_prct, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]); - - my ($in_value, $in_unit) = $self->{perfdata}->change_bytes(value => $in_absolute_per_sec, network => 1); - my ($out_value, $out_unit) = $self->{perfdata}->change_bytes(value => $out_absolute_per_sec, network => 1); - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); - $self->{output}->output_add(long_msg => sprintf("Interface '%s' Traffic In : %s/s (%.2f %%), Out : %s/s (%.2f %%) ", $display_value, - $in_value . $in_unit, $in_prct, - $out_value . $out_unit, $out_prct)); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Interface '%s' Traffic In : %s/s (%.2f %%), Out : %s/s (%.2f %%) ", $display_value, - $in_value . $in_unit, $in_prct, - $out_value . $out_unit, $out_prct)); - } - - my $extra_label = ''; - $extra_label = '_' . $display_value if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp})); - $self->{output}->perfdata_add(label => 'traffic_in' . $extra_label, unit => 'b/s', - value => sprintf("%.2f", $in_absolute_per_sec), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in', total => $interface_speed_in), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in', total => $interface_speed_in), - min => 0, max => $interface_speed_in); - $self->{output}->perfdata_add(label => 'traffic_out' . $extra_label, unit => 'b/s', - value => sprintf("%.2f", $out_absolute_per_sec), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out', total => $interface_speed_out), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out', total => $interface_speed_out), - min => 0, max => $interface_speed_out); - } - - $self->{statefile_value}->write(data => $new_datas); - if ($buffer_creation == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub get_display_value { - my ($self, %options) = @_; - my $value = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_display} . "_" . $options{id}); - - if (defined($self->{option_results}->{display_transform_src})) { - $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; - } - return $value; -} - -sub reload_cache { - my ($self) = @_; - my $datas = {}; - - $datas->{oid_filter} = $self->{option_results}->{oid_filter}; - $datas->{oid_display} = $self->{option_results}->{oid_display}; - $datas->{last_timestamp} = time(); - $datas->{all_ids} = []; - my $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_filter}}); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /\.([0-9]+)$/); - push @{$datas->{all_ids}}, $1; - $datas->{$self->{option_results}->{oid_filter} . "_" . $1} = $self->{output}->to_utf8($result->{$key}); - } - - if (scalar(@{$datas->{all_ids}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "Can't construct cache..."); - $self->{output}->option_exit(); - } - - if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display}) { - $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_display}}); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /\.([0-9]+)$/); - $datas->{$self->{option_results}->{oid_display} . "_" . $1} = $self->{output}->to_utf8($result->{$key}); - } - } - - $self->{statefile_cache}->write(data => $datas); -} - -sub manage_selection { - my ($self, %options) = @_; - - # init cache file - my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_snmpstandard_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); - if (defined($self->{option_results}->{show_cache})) { - $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content()); - $self->{output}->option_exit(); - } - - my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); - my $oid_display = $self->{statefile_cache}->get(name => 'oid_display'); - my $oid_filter = $self->{statefile_cache}->get(name => 'oid_filter'); - if ($has_cache_file == 0 || - ($self->{option_results}->{oid_display} !~ /^($oid_display|$oid_filter)$/i || $self->{option_results}->{oid_filter} !~ /^($oid_display|$oid_filter)$/i) || - !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) { - $self->reload_cache(); - $self->{statefile_cache}->read(); - } - - my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); - if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) { - # get by ID - push @{$self->{interface_id_selected}}, $self->{option_results}->{interface}; - my $name = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_display} . "_" . $self->{option_results}->{interface}); - if (!defined($name)) { - $self->{output}->add_option_msg(short_msg => "No interface found for id '" . $self->{option_results}->{interface} . "'."); - $self->{output}->option_exit(); - } - } else { - foreach my $i (@{$all_ids}) { - my $filter_name = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_filter} . "_" . $i); - next if (!defined($filter_name)); - if (!defined($self->{option_results}->{interface})) { - push @{$self->{interface_id_selected}}, $i; - next; - } - if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/i) { - push @{$self->{interface_id_selected}}, $i; - } - if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/) { - push @{$self->{interface_id_selected}}, $i; - } - if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{interface}) { - push @{$self->{interface_id_selected}}, $i; - } - } - - if (scalar(@{$self->{interface_id_selected}}) <= 0) { - if (defined($self->{option_results}->{interface})) { - $self->{output}->add_option_msg(short_msg => "No interface found for name '" . $self->{option_results}->{interface} . "' (maybe you should reload cache file)."); - } else { - $self->{output}->add_option_msg(short_msg => "No interface found (maybe you should reload cache file)."); - } - $self->{output}->option_exit(); - } - } -} - -1; - -__END__ - -=head1 MODE - -=over 8 - -=item B<--warning-in> - -Threshold warning in percent for 'in' traffic. - -=item B<--critical-in> - -Threshold critical in percent for 'in' traffic. - -=item B<--warning-out> - -Threshold warning in percent for 'out' traffic. - -=item B<--critical-out> - -Threshold critical in percent for 'out' traffic. - -=item B<--interface> - -Set the interface (number expected) ex: 1, 2,... (empty means 'check all interface'). - -=item B<--name> - -Allows to use interface name with option --interface instead of interface oid index. - -=item B<--regexp> - -Allows to use regexp to filter interfaces (with option --name). - -=item B<--regexp-isensitive> - -Allows to use regexp non case-sensitive (with --regexp). - -=item B<--speed> - -Set interface speed for incoming/outgoing traffic (in Mb). - -=item B<--speed-in> - -Set interface speed for incoming traffic (in Mb). - -=item B<--speed-out> - -Set interface speed for outgoing traffic (in Mb). - -=item B<--skip> - -Skip errors on interface status. - -=item B<--skip-speed0> - -Skip errors on interface with speed 0. - -=item B<--reload-cache-time> - -Time in seconds before reloading cache file (default: 180). - -=item B<--oid-filter> - -Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName). - -=item B<--oid-display> - -Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName). - -=item B<--display-transform-src> - -Regexp src to transform display value. (security risk!!!) - -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) - -=item B<--show-cache> - -Display cache interface datas. - -=back - -=cut diff --git a/storage/dell/equallogic/snmp/plugin.pm b/storage/dell/equallogic/snmp/plugin.pm index bb9deadbe..ee4b3ee21 100644 --- a/storage/dell/equallogic/snmp/plugin.pm +++ b/storage/dell/equallogic/snmp/plugin.pm @@ -35,9 +35,9 @@ sub new { 'array-stats' => 'storage::dell::equallogic::snmp::mode::arraystats', 'disk-usage' => 'storage::dell::equallogic::snmp::mode::diskusage', 'hardware' => 'storage::dell::equallogic::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'pool-usage' => 'storage::dell::equallogic::snmp::mode::poolusage', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/storage/hp/msa2000/snmp/plugin.pm b/storage/hp/msa2000/snmp/plugin.pm index f98d05602..ab9ae08f9 100644 --- a/storage/hp/msa2000/snmp/plugin.pm +++ b/storage/hp/msa2000/snmp/plugin.pm @@ -33,8 +33,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( 'hardware' => 'snmp_standard::mode::hardwarefibrealliance', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/storage/hp/p2000/xmlapi/custom.pm b/storage/hp/p2000/xmlapi/custom.pm index d4b514414..dfe430abd 100644 --- a/storage/hp/p2000/xmlapi/custom.pm +++ b/storage/hp/p2000/xmlapi/custom.pm @@ -22,7 +22,7 @@ package storage::hp::p2000::xmlapi::custom; use strict; use warnings; -use centreon::plugins::httplib; +use centreon::plugins::http; use XML::XPath; use Digest::MD5 qw(md5_hex); @@ -108,7 +108,7 @@ sub check_options { $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}}) : '/api/'; $self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? shift(@{$self->{option_results}->{proxyurl}}) : undef; - + if (!defined($self->{hostname})) { $self->{output}->add_option_msg(short_msg => "Need to specify hostname option."); $self->{output}->option_exit(); @@ -129,8 +129,6 @@ sub build_options_for_httplib { my ($self, %options) = @_; $self->{option_results}->{hostname} = $self->{hostname}; - $self->{option_results}->{username} = $self->{username}; - $self->{option_results}->{password} = $self->{password}; $self->{option_results}->{timeout} = $self->{timeout}; $self->{option_results}->{port} = $self->{port}; $self->{option_results}->{proto} = $self->{proto}; @@ -179,9 +177,8 @@ sub DESTROY { my $self = shift; if ($self->{logon} == 1) { - $self->{option_results}->{url_path} = $self->{url_path} . 'exit'; - centreon::plugins::httplib::connect($self, - headers => {dataType => 'api', sessionKey => $self->{session_id} }); + $self->{http}->request(url_path => $self->{url_path} . 'exit', + header => ['dataType: api', 'sessionKey: ' . $self->{session_id}]); } } @@ -191,9 +188,8 @@ sub get_infos { my $cmd = $options{cmd}; $cmd =~ s/ /\//g; - $self->{option_results}->{url_path} = $self->{url_path} . $cmd; - my $response = centreon::plugins::httplib::connect($self, - headers => {dataType => 'api', sessionKey => $self->{session_id} }); + my $response =$self->{http}->request(url_path => $self->{url_path} . $cmd, + header => ['dataType: api', 'sessionKey: '. $self->{session_id}]); eval { $xpath = XML::XPath->new(xml => $response); @@ -232,11 +228,12 @@ sub login { my ($self, %options) = @_; $self->build_options_for_httplib(); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); + $self->{http}->set_options(%{$self->{option_results}}); # Login First my $md5_hash = md5_hex($self->{username} . '_' . $self->{password}); - $self->{option_results}->{url_path} = $self->{url_path} . 'login/' . $md5_hash; - my $response = centreon::plugins::httplib::connect($self); + my $response = $self->{http}->request(url_path => $self->{url_path} . 'login/' . $md5_hash); $self->check_login(content => $response); } diff --git a/storage/panzura/snmp/plugin.pm b/storage/panzura/snmp/plugin.pm index b6f26887a..849b66464 100644 --- a/storage/panzura/snmp/plugin.pm +++ b/storage/panzura/snmp/plugin.pm @@ -38,14 +38,13 @@ sub new { 'disk-usage-cloud' => 'snmp_standard::mode::diskusage', 'disk-usage-local' => 'storage::panzura::snmp::mode::diskusagelocal', 'load' => 'snmp_standard::mode::loadaverage', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-diskspath' => 'snmp_standard::mode::listdiskspath', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', 'memory' => 'storage::panzura::snmp::mode::memory', - 'packet-errors' => 'snmp_standard::mode::packeterrors', 'ratios' => 'storage::panzura::snmp::mode::ratios', 'swap' => 'snmp_standard::mode::swap', - 'traffic' => 'snmp_standard::mode::traffic', ); return $self; diff --git a/storage/qnap/snmp/plugin.pm b/storage/qnap/snmp/plugin.pm index 723215274..47d4bc1e6 100644 --- a/storage/qnap/snmp/plugin.pm +++ b/storage/qnap/snmp/plugin.pm @@ -34,11 +34,11 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'snmp_standard::mode::cpu', 'hardware' => 'storage::qnap::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', 'memory' => 'storage::qnap::snmp::mode::memory', 'storage' => 'snmp_standard::mode::storage', - 'traffic' => 'snmp_standard::mode::traffic', 'volume-usage' => 'storage::qnap::snmp::mode::volumeusage', ); diff --git a/storage/synology/snmp/plugin.pm b/storage/synology/snmp/plugin.pm index ad88ddcf8..dc118f5c5 100644 --- a/storage/synology/snmp/plugin.pm +++ b/storage/synology/snmp/plugin.pm @@ -35,8 +35,8 @@ sub new { 'components' => 'storage::synology::snmp::mode::components', 'temperature' => 'storage::synology::snmp::mode::temperature', 'ups' => 'storage::synology::snmp::mode::ups', - 'traffic' => 'snmp_standard::mode::traffic', 'cpu' => 'snmp_standard::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', 'memory' => 'snmp_standard::mode::memory', 'load' => 'snmp_standard::mode::loadaverage', 'storage' => 'snmp_standard::mode::storage',