From 1f679a268f02d47916b07083fef2a75828f2cc20 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Thu, 17 Oct 2019 15:08:21 +0200 Subject: [PATCH 01/11] add debug in aws cli custom mode --- cloud/aws/custom/awscli.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cloud/aws/custom/awscli.pm b/cloud/aws/custom/awscli.pm index 28278f81a..9e19db096 100644 --- a/cloud/aws/custom/awscli.pm +++ b/cloud/aws/custom/awscli.pm @@ -127,8 +127,11 @@ sub check_options { sub execute { my ($self, %options) = @_; + + my $cmd_options = $options{cmd_options}; + $cmd_options .= " --debug" if ($self->{output}->is_debug()); - $self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $options{cmd_options} . "'", debug => 1); + $self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $cmd_options . "'", debug => 1); my ($response) = centreon::plugins::misc::execute( output => $self->{output}, @@ -136,8 +139,8 @@ sub execute { sudo => $self->{option_results}->{sudo}, command => $self->{option_results}->{command}, command_path => $self->{option_results}->{command_path}, - command_options => $options{cmd_options}, - redirect_stderr => 0 + command_options => $cmd_options, + redirect_stderr => 1 ); my $raw_results; From 147fe02bc64241567598352cf1f7a456443566ee Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 17 Oct 2019 16:35:01 +0200 Subject: [PATCH 02/11] enhance indent --- apps/activedirectory/local/plugin.pm | 8 ++++---- apps/activedirectory/wsman/plugin.pm | 4 ++-- apps/backup/netbackup/local/plugin.pm | 14 +++++++------- apps/backup/quadstor/local/plugin.pm | 10 +++++----- apps/backup/tsm/local/plugin.pm | 12 ++++++------ apps/bluemind/plugin.pm | 4 ++-- apps/centreon/map4/jmx/plugin.pm | 12 ++++++------ apps/cisco/cms/restapi/plugin.pm | 13 +++++++------ apps/cisco/ise/restapi/plugin.pm | 5 +++-- apps/exchange/2010/local/plugin.pm | 22 ++++++++++----------- apps/iis/local/plugin.pm | 10 +++++----- apps/iis/wsman/plugin.pm | 6 +++--- apps/inin/ig/snmp/plugin.pm | 6 +++--- apps/inin/mediaserver/snmp/plugin.pm | 12 ++++++------ apps/java/solr/jmx/plugin.pm | 6 +++--- apps/lotus/snmp/plugin.pm | 12 ++++++------ apps/pacemaker/local/plugin.pm | 8 ++++---- apps/proxmox/ve/restapi/plugin.pm | 16 +++++++-------- apps/pvx/restapi/plugin.pm | 10 +++++----- apps/sendmail/snmp/plugin.pm | 4 ++-- apps/slack/restapi/plugin.pm | 7 ++++--- apps/tomcat/jmx/plugin.pm | 28 +++++++++++++-------------- apps/video/openheadend/snmp/plugin.pm | 6 +++--- apps/video/zixi/restapi/plugin.pm | 14 +++++++------- apps/vmware/wsman/plugin.pm | 4 ++-- apps/voip/asterisk/ami/plugin.pm | 8 ++++---- storage/lenovo/sseries/snmp/plugin.pm | 8 ++++---- 27 files changed, 136 insertions(+), 133 deletions(-) diff --git a/apps/activedirectory/local/plugin.pm b/apps/activedirectory/local/plugin.pm index 4dfeaa910..322f649e8 100644 --- a/apps/activedirectory/local/plugin.pm +++ b/apps/activedirectory/local/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'dcdiag' => 'apps::activedirectory::local::mode::dcdiag', - 'dfsr-backlog' => 'apps::activedirectory::local::mode::dfsrbacklog', - 'netdom' => 'apps::activedirectory::local::mode::netdom', - ); + 'dcdiag' => 'apps::activedirectory::local::mode::dcdiag', + 'dfsr-backlog' => 'apps::activedirectory::local::mode::dfsrbacklog', + 'netdom' => 'apps::activedirectory::local::mode::netdom', + ); return $self; } diff --git a/apps/activedirectory/wsman/plugin.pm b/apps/activedirectory/wsman/plugin.pm index 0cb9803c1..cd2257af6 100644 --- a/apps/activedirectory/wsman/plugin.pm +++ b/apps/activedirectory/wsman/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'dcdiag' => 'apps::activedirectory::wsman::mode::dcdiag', - ); + 'dcdiag' => 'apps::activedirectory::wsman::mode::dcdiag', + ); return $self; } diff --git a/apps/backup/netbackup/local/plugin.pm b/apps/backup/netbackup/local/plugin.pm index 5d770d97a..72a1d551c 100644 --- a/apps/backup/netbackup/local/plugin.pm +++ b/apps/backup/netbackup/local/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'dedup-status' => 'apps::backup::netbackup::local::mode::dedupstatus', - 'drive-cleaning' => 'apps::backup::netbackup::local::mode::drivecleaning', - 'drive-status' => 'apps::backup::netbackup::local::mode::drivestatus', - 'job-status' => 'apps::backup::netbackup::local::mode::jobstatus', - 'list-policies' => 'apps::backup::netbackup::local::mode::listpolicies', - 'tape-usage' => 'apps::backup::netbackup::local::mode::tapeusage', - ); + 'dedup-status' => 'apps::backup::netbackup::local::mode::dedupstatus', + 'drive-cleaning' => 'apps::backup::netbackup::local::mode::drivecleaning', + 'drive-status' => 'apps::backup::netbackup::local::mode::drivestatus', + 'job-status' => 'apps::backup::netbackup::local::mode::jobstatus', + 'list-policies' => 'apps::backup::netbackup::local::mode::listpolicies', + 'tape-usage' => 'apps::backup::netbackup::local::mode::tapeusage', + ); return $self; } diff --git a/apps/backup/quadstor/local/plugin.pm b/apps/backup/quadstor/local/plugin.pm index 80ea1f14a..21ee923f7 100644 --- a/apps/backup/quadstor/local/plugin.pm +++ b/apps/backup/quadstor/local/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'list-vtl' => 'apps::backup::quadstor::local::mode::listvtl', - 'vtl-disk-usage' => 'apps::backup::quadstor::local::mode::vtldiskusage', - 'vtl-job-status' => 'apps::backup::quadstor::local::mode::vtljobstatus', - 'vtl-tape-usage' => 'apps::backup::quadstor::local::mode::vtltapeusage', - ); + 'list-vtl' => 'apps::backup::quadstor::local::mode::listvtl', + 'vtl-disk-usage' => 'apps::backup::quadstor::local::mode::vtldiskusage', + 'vtl-job-status' => 'apps::backup::quadstor::local::mode::vtljobstatus', + 'vtl-tape-usage' => 'apps::backup::quadstor::local::mode::vtltapeusage', + ); return $self; } diff --git a/apps/backup/tsm/local/plugin.pm b/apps/backup/tsm/local/plugin.pm index 676de3aca..6d3eaf2da 100644 --- a/apps/backup/tsm/local/plugin.pm +++ b/apps/backup/tsm/local/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'actlog' => 'apps::backup::tsm::local::mode::actlog', - 'drives' => 'apps::backup::tsm::local::mode::drives', - 'nodes' => 'apps::backup::tsm::local::mode::nodes', - 'sessions' => 'apps::backup::tsm::local::mode::sessions', - 'volumes' => 'apps::backup::tsm::local::mode::volumes', - ); + 'actlog' => 'apps::backup::tsm::local::mode::actlog', + 'drives' => 'apps::backup::tsm::local::mode::drives', + 'nodes' => 'apps::backup::tsm::local::mode::nodes', + 'sessions' => 'apps::backup::tsm::local::mode::sessions', + 'volumes' => 'apps::backup::tsm::local::mode::volumes', + ); $self->{custom_modes}{api} = 'apps::backup::tsm::local::custom::api'; return $self; diff --git a/apps/bluemind/plugin.pm b/apps/bluemind/plugin.pm index 7916a40a6..2df1d911e 100644 --- a/apps/bluemind/plugin.pm +++ b/apps/bluemind/plugin.pm @@ -32,8 +32,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'incoming' => 'apps::bluemind::mode::incoming', - ); + 'incoming' => 'apps::bluemind::mode::incoming', + ); return $self; } diff --git a/apps/centreon/map4/jmx/plugin.pm b/apps/centreon/map4/jmx/plugin.pm index b1609ad02..ce629d7fb 100644 --- a/apps/centreon/map4/jmx/plugin.pm +++ b/apps/centreon/map4/jmx/plugin.pm @@ -30,12 +30,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'gates' => 'apps::centreon::map4::jmx::mode::gates', - 'elements' => 'apps::centreon::map4::jmx::mode::elements', - 'sessions' => 'apps::centreon::map4::jmx::mode::sessions', - 'event-queue' => 'apps::centreon::map4::jmx::mode::eventqueue', - 'event-statistics' => 'apps::centreon::map4::jmx::mode::eventstatistics', - ); + 'elements' => 'apps::centreon::map4::jmx::mode::elements', + 'event-queue' => 'apps::centreon::map4::jmx::mode::eventqueue', + 'event-statistics' => 'apps::centreon::map4::jmx::mode::eventstatistics', + 'gates' => 'apps::centreon::map4::jmx::mode::gates', + 'sessions' => 'apps::centreon::map4::jmx::mode::sessions', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/apps/cisco/cms/restapi/plugin.pm b/apps/cisco/cms/restapi/plugin.pm index 05a23dbd1..eb4f9d196 100644 --- a/apps/cisco/cms/restapi/plugin.pm +++ b/apps/cisco/cms/restapi/plugin.pm @@ -31,12 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'alarms' => 'apps::cisco::cms::restapi::mode::alarms', - 'calls' => 'apps::cisco::cms::restapi::mode::calls', - 'database-status' => 'apps::cisco::cms::restapi::mode::databasestatus', - 'licenses' => 'apps::cisco::cms::restapi::mode::licenses', - 'system-status' => 'apps::cisco::cms::restapi::mode::systemstatus', - ); + 'alarms' => 'apps::cisco::cms::restapi::mode::alarms', + 'calls' => 'apps::cisco::cms::restapi::mode::calls', + 'database-status' => 'apps::cisco::cms::restapi::mode::databasestatus', + 'licenses' => 'apps::cisco::cms::restapi::mode::licenses', + 'system-status' => 'apps::cisco::cms::restapi::mode::systemstatus', + ); + $self->{custom_modes}{xmlapi} = 'apps::cisco::cms::restapi::custom::xmlapi'; return $self; } diff --git a/apps/cisco/ise/restapi/plugin.pm b/apps/cisco/ise/restapi/plugin.pm index 4606acfa6..b039e11d1 100644 --- a/apps/cisco/ise/restapi/plugin.pm +++ b/apps/cisco/ise/restapi/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'session' => 'apps::cisco::ise::restapi::mode::session', - ); + 'session' => 'apps::cisco::ise::restapi::mode::session', + ); + $self->{custom_modes}{xmlapi} = 'apps::cisco::ise::restapi::custom::xmlapi'; return $self; } diff --git a/apps/exchange/2010/local/plugin.pm b/apps/exchange/2010/local/plugin.pm index af508920d..b615a9866 100644 --- a/apps/exchange/2010/local/plugin.pm +++ b/apps/exchange/2010/local/plugin.pm @@ -31,17 +31,17 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'activesync-mailbox' => 'apps::exchange::2010::local::mode::activesyncmailbox', - 'databases' => 'apps::exchange::2010::local::mode::databases', - 'list-databases' => 'apps::exchange::2010::local::mode::listdatabases', - 'imap-mailbox' => 'apps::exchange::2010::local::mode::imapmailbox', - 'mapi-mailbox' => 'apps::exchange::2010::local::mode::mapimailbox', - 'outlook-webservices' => 'apps::exchange::2010::local::mode::outlookwebservices', - 'owa-mailbox' => 'apps::exchange::2010::local::mode::owamailbox', - 'queues' => 'apps::exchange::2010::local::mode::queues', - 'replication-health' => 'apps::exchange::2010::local::mode::replicationhealth', - 'services' => 'apps::exchange::2010::local::mode::services', - ); + 'activesync-mailbox' => 'apps::exchange::2010::local::mode::activesyncmailbox', + 'databases' => 'apps::exchange::2010::local::mode::databases', + 'list-databases' => 'apps::exchange::2010::local::mode::listdatabases', + 'imap-mailbox' => 'apps::exchange::2010::local::mode::imapmailbox', + 'mapi-mailbox' => 'apps::exchange::2010::local::mode::mapimailbox', + 'outlook-webservices' => 'apps::exchange::2010::local::mode::outlookwebservices', + 'owa-mailbox' => 'apps::exchange::2010::local::mode::owamailbox', + 'queues' => 'apps::exchange::2010::local::mode::queues', + 'replication-health' => 'apps::exchange::2010::local::mode::replicationhealth', + 'services' => 'apps::exchange::2010::local::mode::services', + ); return $self; } diff --git a/apps/iis/local/plugin.pm b/apps/iis/local/plugin.pm index dba179f14..4009bb655 100644 --- a/apps/iis/local/plugin.pm +++ b/apps/iis/local/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'applicationpool-state' => 'apps::iis::local::mode::applicationpoolstate', - 'list-applicationpools' => 'apps::iis::local::mode::listapplicationpools', - 'list-sites' => 'apps::iis::local::mode::listsites', - 'webservice-statistics' => 'apps::iis::local::mode::webservicestatistics', - ); + 'applicationpool-state' => 'apps::iis::local::mode::applicationpoolstate', + 'list-applicationpools' => 'apps::iis::local::mode::listapplicationpools', + 'list-sites' => 'apps::iis::local::mode::listsites', + 'webservice-statistics' => 'apps::iis::local::mode::webservicestatistics', + ); return $self; } diff --git a/apps/iis/wsman/plugin.pm b/apps/iis/wsman/plugin.pm index fbd3518e9..ade957f2d 100644 --- a/apps/iis/wsman/plugin.pm +++ b/apps/iis/wsman/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'applicationpool-state' => 'apps::iis::wsman::mode::applicationpoolstate', - 'list-applicationpools' => 'apps::iis::wsman::mode::listapplicationpools', - ); + 'applicationpool-state' => 'apps::iis::wsman::mode::applicationpoolstate', + 'list-applicationpools' => 'apps::iis::wsman::mode::listapplicationpools', + ); return $self; } diff --git a/apps/inin/ig/snmp/plugin.pm b/apps/inin/ig/snmp/plugin.pm index 630674bee..be88168e1 100644 --- a/apps/inin/ig/snmp/plugin.pm +++ b/apps/inin/ig/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'span-usage' => 'apps::inin::ig::snmp::mode::spanusage', - 'stats' => 'apps::inin::ig::snmp::mode::stats', - ); + 'span-usage' => 'apps::inin::ig::snmp::mode::spanusage', + 'stats' => 'apps::inin::ig::snmp::mode::stats', + ); return $self; } diff --git a/apps/inin/mediaserver/snmp/plugin.pm b/apps/inin/mediaserver/snmp/plugin.pm index 981a0bf80..44de72221 100644 --- a/apps/inin/mediaserver/snmp/plugin.pm +++ b/apps/inin/mediaserver/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'audioengine-usage' => 'apps::inin::mediaserver::snmp::mode::audioengineusage', - 'cmdsrv-usage' => 'apps::inin::mediaserver::snmp::mode::cmdsrvusage', - 'disk-usage' => 'apps::inin::mediaserver::snmp::mode::diskusage', - 'component' => 'apps::inin::mediaserver::snmp::mode::component', - 'memory-usage' => 'apps::inin::mediaserver::snmp::mode::memoryusage', - ); + 'audioengine-usage' => 'apps::inin::mediaserver::snmp::mode::audioengineusage', + 'cmdsrv-usage' => 'apps::inin::mediaserver::snmp::mode::cmdsrvusage', + 'component' => 'apps::inin::mediaserver::snmp::mode::component', + 'disk-usage' => 'apps::inin::mediaserver::snmp::mode::diskusage', + 'memory-usage' => 'apps::inin::mediaserver::snmp::mode::memoryusage', + ); return $self; } diff --git a/apps/java/solr/jmx/plugin.pm b/apps/java/solr/jmx/plugin.pm index 4ce5fae10..297ee88a6 100644 --- a/apps/java/solr/jmx/plugin.pm +++ b/apps/java/solr/jmx/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cache-usage' => 'apps::java::solr::jmx::mode::cacheusage', - 'request-handler-usage' => 'apps::java::solr::jmx::mode::requesthandlerusage', - ); + 'cache-usage' => 'apps::java::solr::jmx::mode::cacheusage', + 'request-handler-usage' => 'apps::java::solr::jmx::mode::requesthandlerusage', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/apps/lotus/snmp/plugin.pm b/apps/lotus/snmp/plugin.pm index 357b55da6..b4934b952 100644 --- a/apps/lotus/snmp/plugin.pm +++ b/apps/lotus/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'mail-state' => 'apps::lotus::snmp::mode::mailstate', - 'mail-time' => 'apps::lotus::snmp::mode::mailtime', - 'server-availability' => 'apps::lotus::snmp::mode::serveravailability', - 'user-sessions' => 'apps::lotus::snmp::mode::usersessions', - 'server-transactions' => 'apps::lotus::snmp::mode::servertransactions', - ); + 'mail-state' => 'apps::lotus::snmp::mode::mailstate', + 'mail-time' => 'apps::lotus::snmp::mode::mailtime', + 'server-availability' => 'apps::lotus::snmp::mode::serveravailability', + 'server-transactions' => 'apps::lotus::snmp::mode::servertransactions', + 'user-sessions' => 'apps::lotus::snmp::mode::usersessions', + ); return $self; } diff --git a/apps/pacemaker/local/plugin.pm b/apps/pacemaker/local/plugin.pm index c9a1dfee3..b3b61e86b 100644 --- a/apps/pacemaker/local/plugin.pm +++ b/apps/pacemaker/local/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'crm' => 'apps::pacemaker::local::mode::crm', - 'constraints' => 'apps::pacemaker::local::mode::constraints', - 'clustat' => 'apps::pacemaker::local::mode::clustat', - ); + 'clustat' => 'apps::pacemaker::local::mode::clustat', + 'constraints' => 'apps::pacemaker::local::mode::constraints', + 'crm' => 'apps::pacemaker::local::mode::crm', + ); return $self; } diff --git a/apps/proxmox/ve/restapi/plugin.pm b/apps/proxmox/ve/restapi/plugin.pm index 75daac2e5..ea6a62d64 100644 --- a/apps/proxmox/ve/restapi/plugin.pm +++ b/apps/proxmox/ve/restapi/plugin.pm @@ -32,14 +32,14 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'list-nodes' => 'apps::proxmox::ve::restapi::mode::listnodes', - 'list-storages' => 'apps::proxmox::ve::restapi::mode::liststorages', - 'list-vms' => 'apps::proxmox::ve::restapi::mode::listvms', - 'storage-usage' => 'apps::proxmox::ve::restapi::mode::storageusage', - 'node-usage' => 'apps::proxmox::ve::restapi::mode::nodeusage', - 'version' => 'apps::proxmox::ve::restapi::mode::version', - 'vm-usage' => 'apps::proxmox::ve::restapi::mode::vmusage', - ); + 'list-nodes' => 'apps::proxmox::ve::restapi::mode::listnodes', + 'list-storages' => 'apps::proxmox::ve::restapi::mode::liststorages', + 'list-vms' => 'apps::proxmox::ve::restapi::mode::listvms', + 'node-usage' => 'apps::proxmox::ve::restapi::mode::nodeusage', + 'storage-usage' => 'apps::proxmox::ve::restapi::mode::storageusage', + 'version' => 'apps::proxmox::ve::restapi::mode::version', + 'vm-usage' => 'apps::proxmox::ve::restapi::mode::vmusage', + ); $self->{custom_modes}{api} = 'apps::proxmox::ve::restapi::custom::api'; return $self; diff --git a/apps/pvx/restapi/plugin.pm b/apps/pvx/restapi/plugin.pm index 5dde4b243..ab82d76ac 100644 --- a/apps/pvx/restapi/plugin.pm +++ b/apps/pvx/restapi/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'http-hits' => 'apps::pvx::restapi::mode::httphits', - 'network-connection' => 'apps::pvx::restapi::mode::networkconnection', - 'network-user-experience' => 'apps::pvx::restapi::mode::networkuserexperience', - 'network-traffic' => 'apps::pvx::restapi::mode::networktraffic', - ); + 'http-hits' => 'apps::pvx::restapi::mode::httphits', + 'network-connection' => 'apps::pvx::restapi::mode::networkconnection', + 'network-user-experience' => 'apps::pvx::restapi::mode::networkuserexperience', + 'network-traffic' => 'apps::pvx::restapi::mode::networktraffic', + ); $self->{custom_modes}{api} = 'apps::pvx::restapi::custom::api'; return $self; diff --git a/apps/sendmail/snmp/plugin.pm b/apps/sendmail/snmp/plugin.pm index 14aef636d..5de75e305 100644 --- a/apps/sendmail/snmp/plugin.pm +++ b/apps/sendmail/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'mta-usage' => 'snmp_standard::mode::mtausage', - ); + 'mta-usage' => 'snmp_standard::mode::mtausage', + ); return $self; } diff --git a/apps/slack/restapi/plugin.pm b/apps/slack/restapi/plugin.pm index 92058157c..02f315816 100644 --- a/apps/slack/restapi/plugin.pm +++ b/apps/slack/restapi/plugin.pm @@ -31,9 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'count-channels' => 'apps::slack::restapi::mode::countchannels', - 'count-members' => 'apps::slack::restapi::mode::countmembers', - ); + 'count-channels' => 'apps::slack::restapi::mode::countchannels', + 'count-members' => 'apps::slack::restapi::mode::countmembers', + ); + $self->{custom_modes}{restapi} = 'apps::slack::restapi::custom::api'; return $self; } diff --git a/apps/tomcat/jmx/plugin.pm b/apps/tomcat/jmx/plugin.pm index 380f19f44..2cc6c0c01 100644 --- a/apps/tomcat/jmx/plugin.pm +++ b/apps/tomcat/jmx/plugin.pm @@ -31,20 +31,20 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'class-count' => 'centreon::common::jvm::mode::classcount', - 'connector-usage' => 'apps::tomcat::jmx::mode::connectorusage', - 'cpu-load' => 'centreon::common::jvm::mode::cpuload', - 'datasource-usage' => 'apps::tomcat::jmx::mode::datasourceusage', - 'fd-usage' => 'centreon::common::jvm::mode::fdusage', - 'gc-usage' => 'centreon::common::jvm::mode::gcusage', - 'list-datasources' => 'apps::tomcat::jmx::mode::listdatasources', - 'list-webapps' => 'apps::tomcat::jmx::mode::listwebapps', - 'load-average' => 'centreon::common::jvm::mode::loadaverage', - 'memory' => 'centreon::common::jvm::mode::memory', - 'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed', - 'threads' => 'centreon::common::jvm::mode::threads', - 'webapps-sessions' => 'apps::tomcat::jmx::mode::webappssessions', - ); + 'class-count' => 'centreon::common::jvm::mode::classcount', + 'connector-usage' => 'apps::tomcat::jmx::mode::connectorusage', + 'cpu-load' => 'centreon::common::jvm::mode::cpuload', + 'datasource-usage' => 'apps::tomcat::jmx::mode::datasourceusage', + 'fd-usage' => 'centreon::common::jvm::mode::fdusage', + 'gc-usage' => 'centreon::common::jvm::mode::gcusage', + 'list-datasources' => 'apps::tomcat::jmx::mode::listdatasources', + 'list-webapps' => 'apps::tomcat::jmx::mode::listwebapps', + 'load-average' => 'centreon::common::jvm::mode::loadaverage', + 'memory' => 'centreon::common::jvm::mode::memory', + 'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed', + 'threads' => 'centreon::common::jvm::mode::threads', + 'webapps-sessions' => 'apps::tomcat::jmx::mode::webappssessions', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/apps/video/openheadend/snmp/plugin.pm b/apps/video/openheadend/snmp/plugin.pm index 3728c1a2f..55df773c9 100644 --- a/apps/video/openheadend/snmp/plugin.pm +++ b/apps/video/openheadend/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'node-usage' => 'apps::video::openheadend::snmp::mode::nodeusage', - 'operation-status' => 'apps::video::openheadend::snmp::mode::operationstatus', - ); + 'node-usage' => 'apps::video::openheadend::snmp::mode::nodeusage', + 'operation-status' => 'apps::video::openheadend::snmp::mode::operationstatus', + ); return $self; } diff --git a/apps/video/zixi/restapi/plugin.pm b/apps/video/zixi/restapi/plugin.pm index 8229410fd..a03862d1c 100644 --- a/apps/video/zixi/restapi/plugin.pm +++ b/apps/video/zixi/restapi/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'broadcaster-input-usage' => 'apps::video::zixi::restapi::mode::broadcasterinputusage', - 'broadcaster-license-usage' => 'apps::video::zixi::restapi::mode::broadcasterlicenseusage', - 'broadcaster-output-usage' => 'apps::video::zixi::restapi::mode::broadcasteroutputusage', - 'broadcaster-system-usage' => 'apps::video::zixi::restapi::mode::broadcastersystemusage', - 'feeder-input-usage' => 'apps::video::zixi::restapi::mode::feederinputusage', - 'feeder-output-usage' => 'apps::video::zixi::restapi::mode::feederoutputusage', - ); + 'broadcaster-input-usage' => 'apps::video::zixi::restapi::mode::broadcasterinputusage', + 'broadcaster-license-usage' => 'apps::video::zixi::restapi::mode::broadcasterlicenseusage', + 'broadcaster-output-usage' => 'apps::video::zixi::restapi::mode::broadcasteroutputusage', + 'broadcaster-system-usage' => 'apps::video::zixi::restapi::mode::broadcastersystemusage', + 'feeder-input-usage' => 'apps::video::zixi::restapi::mode::feederinputusage', + 'feeder-output-usage' => 'apps::video::zixi::restapi::mode::feederoutputusage', + ); $self->{custom_modes}{api} = 'apps::video::zixi::restapi::custom::api'; return $self; diff --git a/apps/vmware/wsman/plugin.pm b/apps/vmware/wsman/plugin.pm index 4ed4d07d0..1aec5946a 100644 --- a/apps/vmware/wsman/plugin.pm +++ b/apps/vmware/wsman/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'hardware' => 'apps::vmware::wsman::mode::hardware', - ); + 'hardware' => 'apps::vmware::wsman::mode::hardware', + ); return $self; } diff --git a/apps/voip/asterisk/ami/plugin.pm b/apps/voip/asterisk/ami/plugin.pm index 877a02e69..baa265eba 100644 --- a/apps/voip/asterisk/ami/plugin.pm +++ b/apps/voip/asterisk/ami/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'channel-usage' => 'apps::voip::asterisk::ami::mode::channelusage', - 'dahdi-status' => 'apps::voip::asterisk::ami::mode::dahdistatus', - 'sip-peers-usage' => 'apps::voip::asterisk::ami::mode::sippeersusage', - ); + 'channel-usage' => 'apps::voip::asterisk::ami::mode::channelusage', + 'dahdi-status' => 'apps::voip::asterisk::ami::mode::dahdistatus', + 'sip-peers-usage' => 'apps::voip::asterisk::ami::mode::sippeersusage', + ); $self->{custom_modes}{api} = 'apps::voip::asterisk::ami::custom::api'; return $self; diff --git a/storage/lenovo/sseries/snmp/plugin.pm b/storage/lenovo/sseries/snmp/plugin.pm index 1c05af4c4..2d747a99b 100644 --- a/storage/lenovo/sseries/snmp/plugin.pm +++ b/storage/lenovo/sseries/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'snmp_standard::mode::hardwarefibrealliance', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'hardware' => 'snmp_standard::mode::hardwarefibrealliance', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); return $self; } From 4ae61e56148e863e7796c13066c3886379697843 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Thu, 17 Oct 2019 16:56:28 +0200 Subject: [PATCH 03/11] enh quotes --- apps/automation/ansible/cli/custom/cli.pm | 20 +++++++++---------- apps/automation/ansible/cli/mode/discovery.pm | 4 ++-- .../ansible/tower/custom/towercli.pm | 18 ++++++++--------- .../ansible/tower/mode/discovery.pm | 6 +++--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/apps/automation/ansible/cli/custom/cli.pm b/apps/automation/ansible/cli/custom/cli.pm index 508a9a09d..ea795df48 100644 --- a/apps/automation/ansible/cli/custom/cli.pm +++ b/apps/automation/ansible/cli/custom/cli.pm @@ -40,16 +40,16 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 50 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '' }, + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1); diff --git a/apps/automation/ansible/cli/mode/discovery.pm b/apps/automation/ansible/cli/mode/discovery.pm index e57db4735..b530b585b 100644 --- a/apps/automation/ansible/cli/mode/discovery.pm +++ b/apps/automation/ansible/cli/mode/discovery.pm @@ -32,8 +32,8 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "host-pattern:s" => { name => 'host_pattern', default => 'all' }, - "prettify" => { name => 'prettify' }, + 'host-pattern:s' => { name => 'host_pattern', default => 'all' }, + 'prettify' => { name => 'prettify' }, }); return $self; diff --git a/apps/automation/ansible/tower/custom/towercli.pm b/apps/automation/ansible/tower/custom/towercli.pm index e9765447c..cb802f56c 100644 --- a/apps/automation/ansible/tower/custom/towercli.pm +++ b/apps/automation/ansible/tower/custom/towercli.pm @@ -40,15 +40,15 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "host:s" => { name => 'host' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout', default => 50 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'tower-cli' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '' }, - "proxyurl:s" => { name => 'proxyurl' }, + 'host:s' => { name => 'host' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'tower-cli' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '' }, + 'proxyurl:s' => { name => 'proxyurl' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'TOWERCLI OPTIONS', once => 1); diff --git a/apps/automation/ansible/tower/mode/discovery.pm b/apps/automation/ansible/tower/mode/discovery.pm index 4a8a8ce37..c761582f4 100644 --- a/apps/automation/ansible/tower/mode/discovery.pm +++ b/apps/automation/ansible/tower/mode/discovery.pm @@ -32,9 +32,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "group" => { name => 'group' }, - "inventory" => { name => 'inventory' }, - "prettify" => { name => 'prettify' }, + 'group' => { name => 'group' }, + 'inventory' => { name => 'inventory' }, + 'prettify' => { name => 'prettify' }, }); return $self; From 08b3c39e3bed09c6fe385088a176953608c45f37 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Thu, 17 Oct 2019 18:12:17 +0200 Subject: [PATCH 04/11] handle error in ansible cli --- apps/automation/ansible/cli/custom/cli.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/automation/ansible/cli/custom/cli.pm b/apps/automation/ansible/cli/custom/cli.pm index ea795df48..c55438bde 100644 --- a/apps/automation/ansible/cli/custom/cli.pm +++ b/apps/automation/ansible/cli/custom/cli.pm @@ -99,7 +99,8 @@ sub execute { sudo => $self->{option_results}->{sudo}, command => $self->{option_results}->{command}, command_path => $self->{option_results}->{command_path}, - command_options => $options{cmd_options} + command_options => $options{cmd_options}, + no_errors => { 4 => 1 } ); my $raw_results; From 8fcdece968b8cc0c2ff665902cc4f10fd4a66b1b Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Fri, 18 Oct 2019 10:49:44 +0200 Subject: [PATCH 05/11] better handle aws cli debug --- cloud/aws/custom/awscli.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/aws/custom/awscli.pm b/cloud/aws/custom/awscli.pm index 9e19db096..b72f5e346 100644 --- a/cloud/aws/custom/awscli.pm +++ b/cloud/aws/custom/awscli.pm @@ -140,7 +140,7 @@ sub execute { command => $self->{option_results}->{command}, command_path => $self->{option_results}->{command_path}, command_options => $cmd_options, - redirect_stderr => 1 + redirect_stderr => ($self->{output}->is_debug()) ? 0 : 1 ); my $raw_results; From 8c9c9bb866007886c9a55f556d744bdfb156afbc Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Fri, 18 Oct 2019 14:14:12 +0200 Subject: [PATCH 06/11] enh(plugin): test ntp_new.pm --- snmp_standard/mode/ntp_new.pm | 170 ++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 snmp_standard/mode/ntp_new.pm diff --git a/snmp_standard/mode/ntp_new.pm b/snmp_standard/mode/ntp_new.pm new file mode 100644 index 000000000..91b8e207e --- /dev/null +++ b/snmp_standard/mode/ntp_new.pm @@ -0,0 +1,170 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package snmp_standard::mode::ntp_new; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use DateTime; +use Data::Dumper; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'offset', type => 0 } + ]; + + $self->{maps_counters}->{offset} = [ + { label => 'offset', nlabel => 'time.offset.seconds', set => { + key_values => [ { name => 'offset' } ], + output_template => 'Offset: %d second(s)', + perfdatas => [ + { label => 'offset', value => 'offset_absolute', template => '%d', unit => 's' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => + { + "ntp-hostname:s" => { name => 'ntp_hostname' }, + "ntp-port:s" => { name => 'ntp_port', default => 123 }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "timezone:s" => { name => 'timezone' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (defined($self->{option_results}->{ntp_hostname})) { + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Net::NTP', + error_msg => "Cannot load module 'Net::NTP'."); + } +} + +sub manage_selection { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + $self->{offset} = {}; + + my ($ref_time, $distant_time); + my $oid_hrSystemDate = '.1.3.6.1.2.1.25.1.2.0'; + my $result = $self->{snmp}->get_leef(oids => [ $oid_hrSystemDate ], nothing_quit => 1); + if (defined($self->{option_results}->{ntp_hostname}) && $self->{option_results}->{ntp_hostname} ne '') { + my %ntp; + + eval { + %ntp = Net::NTP::get_ntp_response($self->{option_results}->{ntp_hostname}, $self->{option_results}->{ntp_port}); + }; + if ($@) { + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => "Couldn't connect to ntp server: " . $@); + $self->{output}->display(); + $self->{output}->exit(); + } + + $ref_time = $ntp{'Transmit Timestamp'}; + } else { + $ref_time = time(); + } + + my @remote_date = unpack 'n C6 a C2', $result->{$oid_hrSystemDate}; + my $timezone = 'UTC'; + if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { + $timezone = $self->{option_results}->{timezone}; + } elsif (defined($remote_date[9])) { + $timezone = sprintf("%s%02d%02d", $remote_date[7], $remote_date[8], $remote_date[9]); # format +0630 + } + + my $tz = centreon::plugins::misc::set_timezone(name => $timezone); + my $dt = DateTime->new( + year => $remote_date[0], + month => $remote_date[1], + day => $remote_date[2], + hour => $remote_date[3], + minute => $remote_date[4], + second => $remote_date[5], + %$tz + ); + $distant_time = $dt->epoch; + + my $offset = $distant_time - $ref_time; + my $remote_date_formated = sprintf("Local Time : %02d-%02d-%02dT%02d:%02d:%02d (%s)", $remote_date[0], $remote_date[1], $remote_date[2], + $remote_date[3], $remote_date[4], $remote_date[5], $timezone); + + + $self->{output}->output_add(short_msg => $remote_date_formated); + + my $formated_offset = sprintf("%d", $offset); + + $self->{offset} = { offset => $formated_offset, display => 0 }; + #print Dumper($self); +} + +1; + +__END__ + +=head1 MODE + +Check time offset of server with ntp server. Use local time if ntp-host option is not set. +SNMP gives a date with second precision (no milliseconds). Time precision is not very accurate. +Use threshold with (+-) 2 seconds offset (minimum). + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=item B<--ntp-hostname> + +Set the ntp hostname (if not set, localtime is used). + +=item B<--ntp-port> + +Set the ntp port (Default: 123). + +=item B<--timezone> + +Set the timezone of distant server. For Windows, you need to set it. +Can use format: 'Europe/London' or '+0100'. + +=back + +=cut From 5674c8c0bdadd8439a383ad1e08dc1e4bf4a132a Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Fri, 18 Oct 2019 17:49:18 +0200 Subject: [PATCH 07/11] enh(plugin): refacto/centreon.plugins.metrics snmp_standard/mode/ntp.pm --- snmp_standard/mode/ntp.pm | 78 +++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/snmp_standard/mode/ntp.pm b/snmp_standard/mode/ntp.pm index e4c40a6e7..b3893c021 100644 --- a/snmp_standard/mode/ntp.pm +++ b/snmp_standard/mode/ntp.pm @@ -20,13 +20,32 @@ package snmp_standard::mode::ntp; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::misc; use DateTime; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'offset', type => 0 } + ]; + + $self->{maps_counters}->{offset} = [ + { label => 'offset', nlabel => 'time.offset.seconds', set => { + key_values => [ { name => 'offset' } ], + output_template => 'Offset: %d second(s)', + perfdatas => [ + { label => 'offset', value => 'offset_absolute', template => '%d', unit => 's' }, + ], + } + }, + ]; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -36,34 +55,25 @@ sub new { { "ntp-hostname:s" => { name => 'ntp_hostname' }, "ntp-port:s" => { name => 'ntp_port', default => 123 }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, "timezone:s" => { name => 'timezone' }, }); 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(); - } - if (defined($self->{option_results}->{ntp_hostname})) { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (defined($self->{option_results}->{ntp_hostname})) { centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Net::NTP', - error_msg => "Cannot load module 'Net::NTP'."); + error_msg => "Cannot load module 'Net::NTP'."); } } -sub run { +sub manage_selection { my ($self, %options) = @_; $self->{snmp} = $options{snmp}; + $self->{offset} = {}; my ($ref_time, $distant_time); my $oid_hrSystemDate = '.1.3.6.1.2.1.25.1.2.0'; @@ -104,25 +114,21 @@ sub run { second => $remote_date[5], %$tz ); + $distant_time = $dt->epoch; - my $diff = $distant_time - $ref_time; - my $remote_date_formated = sprintf("%02d-%02d-%02dT%02d:%02d:%02d (%s)", $remote_date[0], $remote_date[1], $remote_date[2], + my $offset = $distant_time - $ref_time; + my $remote_date_formated = sprintf("Local Time : %02d-%02d-%02dT%02d:%02d:%02d (%s)", $remote_date[0], $remote_date[1], $remote_date[2], $remote_date[3], $remote_date[4], $remote_date[5], $timezone); + - my $exit = $self->{perfdata}->threshold_check(value => $diff, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Time offset %d second(s) : %s", $diff, $remote_date_formated)); - - $self->{output}->perfdata_add(label => 'offset', unit => 's', - value => sprintf("%d", $diff), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - ); - - $self->{output}->display(); - $self->{output}->exit(); + my $formated_offset = sprintf("%d", $offset); + + $self->{offset} = { + offset => $formated_offset, + display => 0 }; + + $self->{output}->add_option_msg(short_msg => $remote_date_formated); } 1; @@ -137,13 +143,13 @@ Use threshold with (+-) 2 seconds offset (minimum). =over 8 -=item B<--warning> +=item B<--warning-offset> -Threshold warning. +Time offset warning threshold (in seconds). -=item B<--critical> +=item B<--critical-offset> -Threshold critical. +Time offset critical Threshold (in seconds). =item B<--ntp-hostname> From f7b5b6a8bdba07f2f8e04f6b31cd82c553f7c3d3 Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Fri, 18 Oct 2019 17:58:55 +0200 Subject: [PATCH 08/11] enh(plugin): refacto/centreon.plugins.metrics snmp_standard/mode/ntp.pm --- snmp_standard/mode/ntp_new.pm | 170 ---------------------------------- 1 file changed, 170 deletions(-) delete mode 100644 snmp_standard/mode/ntp_new.pm diff --git a/snmp_standard/mode/ntp_new.pm b/snmp_standard/mode/ntp_new.pm deleted file mode 100644 index 91b8e207e..000000000 --- a/snmp_standard/mode/ntp_new.pm +++ /dev/null @@ -1,170 +0,0 @@ -# -# Copyright 2019 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package snmp_standard::mode::ntp_new; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use centreon::plugins::misc; -use DateTime; -use Data::Dumper; - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'offset', type => 0 } - ]; - - $self->{maps_counters}->{offset} = [ - { label => 'offset', nlabel => 'time.offset.seconds', set => { - key_values => [ { name => 'offset' } ], - output_template => 'Offset: %d second(s)', - perfdatas => [ - { label => 'offset', value => 'offset_absolute', template => '%d', unit => 's' }, - ], - } - }, - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "ntp-hostname:s" => { name => 'ntp_hostname' }, - "ntp-port:s" => { name => 'ntp_port', default => 123 }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "timezone:s" => { name => 'timezone' }, - }); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{ntp_hostname})) { - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Net::NTP', - error_msg => "Cannot load module 'Net::NTP'."); - } -} - -sub manage_selection { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{offset} = {}; - - my ($ref_time, $distant_time); - my $oid_hrSystemDate = '.1.3.6.1.2.1.25.1.2.0'; - my $result = $self->{snmp}->get_leef(oids => [ $oid_hrSystemDate ], nothing_quit => 1); - if (defined($self->{option_results}->{ntp_hostname}) && $self->{option_results}->{ntp_hostname} ne '') { - my %ntp; - - eval { - %ntp = Net::NTP::get_ntp_response($self->{option_results}->{ntp_hostname}, $self->{option_results}->{ntp_port}); - }; - if ($@) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Couldn't connect to ntp server: " . $@); - $self->{output}->display(); - $self->{output}->exit(); - } - - $ref_time = $ntp{'Transmit Timestamp'}; - } else { - $ref_time = time(); - } - - my @remote_date = unpack 'n C6 a C2', $result->{$oid_hrSystemDate}; - my $timezone = 'UTC'; - if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { - $timezone = $self->{option_results}->{timezone}; - } elsif (defined($remote_date[9])) { - $timezone = sprintf("%s%02d%02d", $remote_date[7], $remote_date[8], $remote_date[9]); # format +0630 - } - - my $tz = centreon::plugins::misc::set_timezone(name => $timezone); - my $dt = DateTime->new( - year => $remote_date[0], - month => $remote_date[1], - day => $remote_date[2], - hour => $remote_date[3], - minute => $remote_date[4], - second => $remote_date[5], - %$tz - ); - $distant_time = $dt->epoch; - - my $offset = $distant_time - $ref_time; - my $remote_date_formated = sprintf("Local Time : %02d-%02d-%02dT%02d:%02d:%02d (%s)", $remote_date[0], $remote_date[1], $remote_date[2], - $remote_date[3], $remote_date[4], $remote_date[5], $timezone); - - - $self->{output}->output_add(short_msg => $remote_date_formated); - - my $formated_offset = sprintf("%d", $offset); - - $self->{offset} = { offset => $formated_offset, display => 0 }; - #print Dumper($self); -} - -1; - -__END__ - -=head1 MODE - -Check time offset of server with ntp server. Use local time if ntp-host option is not set. -SNMP gives a date with second precision (no milliseconds). Time precision is not very accurate. -Use threshold with (+-) 2 seconds offset (minimum). - -=over 8 - -=item B<--warning> - -Threshold warning. - -=item B<--critical> - -Threshold critical. - -=item B<--ntp-hostname> - -Set the ntp hostname (if not set, localtime is used). - -=item B<--ntp-port> - -Set the ntp port (Default: 123). - -=item B<--timezone> - -Set the timezone of distant server. For Windows, you need to set it. -Can use format: 'Europe/London' or '+0100'. - -=back - -=cut From 7d2066fe24359ef2c5f294af45eeb177bc577002 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Fri, 18 Oct 2019 18:39:59 +0200 Subject: [PATCH 09/11] divide elb plugin into 3 subplugins --- cloud/aws/elb/application/mode/connections.pm | 235 ++++++++++++++++ cloud/aws/elb/application/mode/discovery.pm | 111 ++++++++ cloud/aws/elb/application/mode/httpcodes.pm | 250 ++++++++++++++++++ .../aws/elb/application/mode/targetshealth.pm | 223 ++++++++++++++++ cloud/aws/elb/application/plugin.pm | 53 ++++ cloud/aws/elb/{ => classic}/mode/discovery.pm | 6 +- cloud/aws/elb/{ => classic}/mode/httpcodes.pm | 14 +- .../elb/{ => classic}/mode/performances.pm | 14 +- cloud/aws/elb/{ => classic}/mode/queues.pm | 16 +- .../elb/{ => classic}/mode/targetshealth.pm | 12 +- cloud/aws/elb/classic/plugin.pm | 54 ++++ cloud/aws/elb/network/mode/discovery.pm | 111 ++++++++ cloud/aws/elb/network/mode/targetshealth.pm | 223 ++++++++++++++++ cloud/aws/elb/{ => network}/plugin.pm | 11 +- 14 files changed, 1285 insertions(+), 48 deletions(-) create mode 100644 cloud/aws/elb/application/mode/connections.pm create mode 100644 cloud/aws/elb/application/mode/discovery.pm create mode 100644 cloud/aws/elb/application/mode/httpcodes.pm create mode 100644 cloud/aws/elb/application/mode/targetshealth.pm create mode 100644 cloud/aws/elb/application/plugin.pm rename cloud/aws/elb/{ => classic}/mode/discovery.pm (96%) rename cloud/aws/elb/{ => classic}/mode/httpcodes.pm (96%) rename cloud/aws/elb/{ => classic}/mode/performances.pm (96%) rename cloud/aws/elb/{ => classic}/mode/queues.pm (94%) rename cloud/aws/elb/{ => classic}/mode/targetshealth.pm (96%) create mode 100644 cloud/aws/elb/classic/plugin.pm create mode 100644 cloud/aws/elb/network/mode/discovery.pm create mode 100644 cloud/aws/elb/network/mode/targetshealth.pm rename cloud/aws/elb/{ => network}/plugin.pm (73%) diff --git a/cloud/aws/elb/application/mode/connections.pm b/cloud/aws/elb/application/mode/connections.pm new file mode 100644 index 000000000..f0f105464 --- /dev/null +++ b/cloud/aws/elb/application/mode/connections.pm @@ -0,0 +1,235 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::application::mode::connections; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'ActiveConnectionCount' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Active Connection', + 'label' => 'connection-active', + 'nlabel' => 'elb.connection.active.count', + }, + 'NewConnectionCount' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'New Connection', + 'label' => 'connection-new', + 'nlabel' => 'elb.connection.new.count', + }, + 'RejectedConnectionCount' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Rejected Connection', + 'label' => 'connection-rejected', + 'nlabel' => 'elb.rejected.new.count', + }, + 'TargetConnectionErrorCount' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Target Connection Error', + 'label' => 'target-connection-error', + 'nlabel' => 'elb.target.connection.error.count', + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "ELB '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + "statistic:s@" => { name => 'statistic' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{name}) || $self->{option_results}->{name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --name option."); + $self->{output}->option_exit(); + } + + foreach my $instance (@{$self->{option_results}->{name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Sum']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + push @{$self->{aws_dimensions}}, { Name => 'LoadBalancer', Value => $instance }; + if (defined($self->{option_results}->{availability_zone}) && $self->{option_results}->{availability_zone} ne '') { + push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; + } + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/ApplicationELB', + dimensions => $self->{aws_dimensions}, + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Application ELB connections metrics. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::elb::application::plugin --custommode=paws --mode=connections +--region='eu-west-1' --name='app/AppProd/7c8ecfbd1093c5bd' --critical-connection-rejected='10' --verbose + +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-cloudwatch-metrics.html' for more informations. + +Default statistic: 'sum' / Most usefull statistics: 'sum'. + +=over 8 + +=item B<--name> + +Set the instance name (Required) (Can be multiple). + +=item B<--availability-zone> + +Add Availability Zone dimension. + +=item B<--filter-metric> + +Filter metrics (Can be: ActiveConnectionCount', 'NewConnectionCount', +'RejectedConnectionCount', 'TargetConnectionErrorCount') +(Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds warning (Can be: 'connection-active', 'connection-new', +'connection-rejected', 'target-connection-error'). + +=back + +=cut diff --git a/cloud/aws/elb/application/mode/discovery.pm b/cloud/aws/elb/application/mode/discovery.pm new file mode 100644 index 000000000..54ee9a644 --- /dev/null +++ b/cloud/aws/elb/application/mode/discovery.pm @@ -0,0 +1,111 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::application::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $load_balancers = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 'elbv2', + command => 'describe-load-balancers' + ); + + foreach my $load_balancer (@{$load_balancers->{LoadBalancers}}) { + next if (!defined($load_balancer->{LoadBalancerArn}) || $load_balancer->{Type} ne 'application'); + my %elb; + $elb{type} = "application"; + $elb{name} = $1 if ($load_balancer->{LoadBalancerArn} =~ /arn:aws:elasticloadbalancing:.*:loadbalancer\/(.*)/); + $elb{dns_name} = $load_balancer->{DNSName}; + $elb{availability_zones} = $load_balancer->{AvailabilityZones}; + $elb{vpc_id} = $load_balancer->{VpcId}; + $elb{security_groups} = $load_balancer->{SecurityGroups}; + $elb{state} = $load_balancer->{State}->{Code}; + push @disco_data, \%elb; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Application ELB discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/cloud/aws/elb/application/mode/httpcodes.pm b/cloud/aws/elb/application/mode/httpcodes.pm new file mode 100644 index 000000000..c7a7ec7a4 --- /dev/null +++ b/cloud/aws/elb/application/mode/httpcodes.pm @@ -0,0 +1,250 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::application::mode::httpcodes; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'HTTPCode_Target_2XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Target HTTP 2XXs', + 'label' => 'httpcode-target-2xx', + 'nlabel' => 'elb.httpcode.target.2xx.count', + }, + 'HTTPCode_Target_3XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Target HTTP 3XXs', + 'label' => 'httpcode-target-3xx', + 'nlabel' => 'elb.httpcode.target.3xx.count', + }, + 'HTTPCode_Target_4XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Target HTTP 4XXs', + 'label' => 'httpcode-target-4xx', + 'nlabel' => 'elb.httpcode.target.4xx.count', + }, + 'HTTPCode_Target_5XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Target HTTP 5XXs', + 'label' => 'httpcode-target-5xx', + 'nlabel' => 'elb.httpcode.target.5xx.count', + }, + 'HTTPCode_ELB_3XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'ELB HTTP 3XXs', + 'label' => 'httpcode-elb-3xx', + 'nlabel' => 'elb.httpcode.elb.3xx.count', + }, + 'HTTPCode_ELB_4XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'ELB HTTP 4XXs', + 'label' => 'httpcode-elb-4xx', + 'nlabel' => 'elb.httpcode.elb.4xx.count', + }, + 'HTTP_Redirect_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'HTTP Redirect', + 'label' => 'http-redirect', + 'nlabel' => 'elb.http.redirect.count', + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "ELB '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{name}) || $self->{option_results}->{name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --name option."); + $self->{output}->option_exit(); + } + + foreach my $instance (@{$self->{option_results}->{name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Sum']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + push @{$self->{aws_dimensions}}, { Name => 'LoadBalancer', Value => $instance }; + if (defined($self->{option_results}->{availability_zone}) && $self->{option_results}->{availability_zone} ne '') { + push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; + } + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/ApplicationELB', + dimensions => $self->{aws_dimensions}, + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Application ELB HTTP codes metrics. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::elb::application::plugin --custommode=paws --mode=http-codes +--region='eu-west-1' --name='app/AppProd/7c8ecfbd1093c5bd' --critical-httpcode-target-4xx='10' --verbose + +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-cloudwatch-metrics.html' for more informations. + +Default statistic: 'sum' / Most usefull statistics: 'sum'. + +=over 8 + +=item B<--name> + +Set the instance name (Required) (Can be multiple). + +=item B<--availability-zone> + +Add Availability Zone dimension. + +=item B<--filter-metric> + +Filter metrics (Can be: 'HTTPCode_Target_2XX_Count', 'HTTPCode_Target_3XX_Count', +'HTTPCode_Target_4XX_Count', 'HTTPCode_Target_5XX_Count', 'HTTPCode_ELB_3XX_Count', +'HTTPCode_ELB_4XX_Count', 'HTTP_Redirect_Count') +(Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds warning (Can be: 'httpcode-target-2xx', 'httpcode-target-3xx', 'httpcode-target-4xx', +'httpcode-target-5xx', 'httpcode-elb-3xx', 'httpcode-elb-4xx', 'http-redirect') + +=back + +=cut diff --git a/cloud/aws/elb/application/mode/targetshealth.pm b/cloud/aws/elb/application/mode/targetshealth.pm new file mode 100644 index 000000000..bdd9f0ffb --- /dev/null +++ b/cloud/aws/elb/application/mode/targetshealth.pm @@ -0,0 +1,223 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::application::mode::targetshealth; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'HealthyHostCount' => { + 'output' => 'Healthy Hosts', + 'label' => 'healthyhostcount', + 'nlabel' => 'elb.healthyhostcount.count', + }, + 'UnHealthyHostCount' => { + 'output' => 'Unhealthy Hosts', + 'label' => 'unhealthyhostcount', + 'nlabel' => 'elb.unhealthyhostcount.count', + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "ELB '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + "statistic:s@" => { name => 'statistic' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{name}) || $self->{option_results}->{name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --name option."); + $self->{output}->option_exit(); + } + + foreach my $instance (@{$self->{option_results}->{name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Average']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + push @{$self->{aws_dimensions}}, { Name => 'LoadBalancer', Value => $instance }; + if (defined($self->{option_results}->{availability_zone}) && $self->{option_results}->{availability_zone} ne '') { + push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; + } + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/ApplicationELB', + dimensions => $self->{aws_dimensions}, + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Application ELB targets health. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::elb::application::plugin --custommode=paws --mode=targets-health +--region='eu-west-1' --name='app/AppProd/7c8ecfbd1093c5bd' --critical-unhealthyhostcount='10' --verbose + +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-cloudwatch-metrics.html' for more informations. + +Default statistic: 'average' / Most usefull statistics: 'average', 'minimum', 'maximum'. + +=over 8 + +=item B<--name> + +Set the instance name (Required) (Can be multiple). + +=item B<--availability-zone> + +Add Availability Zone dimension. + +=item B<--filter-metric> + +Filter metrics (Can be: 'HealthyHostCount', 'UnHealthyHostCount') +(Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds warning (Can be: 'healthyhostcount', 'unhealthyhostcount'). + +=back + +=cut diff --git a/cloud/aws/elb/application/plugin.pm b/cloud/aws/elb/application/plugin.pm new file mode 100644 index 000000000..24279ae82 --- /dev/null +++ b/cloud/aws/elb/application/plugin.pm @@ -0,0 +1,53 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::application::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + %{ $self->{modes} } = ( + 'connections' => 'cloud::aws::elb::application::mode::connections', + 'discovery' => 'cloud::aws::elb::application::mode::discovery', + 'http-codes' => 'cloud::aws::elb::application::mode::httpcodes', + 'targets-health' => 'cloud::aws::elb::application::mode::targetshealth', + ); + + $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; + $self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Amazon Application Elastic Load Balancing (Amazon Application ELB). + +=cut diff --git a/cloud/aws/elb/mode/discovery.pm b/cloud/aws/elb/classic/mode/discovery.pm similarity index 96% rename from cloud/aws/elb/mode/discovery.pm rename to cloud/aws/elb/classic/mode/discovery.pm index bdb54d4bb..21c551943 100644 --- a/cloud/aws/elb/mode/discovery.pm +++ b/cloud/aws/elb/classic/mode/discovery.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::aws::elb::mode::discovery; +package cloud::aws::elb::classic::mode::discovery; use base qw(centreon::plugins::mode); @@ -60,7 +60,7 @@ sub run { foreach my $load_balancer (@{$load_balancers->{LoadBalancerDescriptions}}) { next if (!defined($load_balancer->{LoadBalancerName})); my %elb; - $elb{type} = "elb"; + $elb{type} = "classic"; $elb{name} = $load_balancer->{LoadBalancerName}; $elb{dns_name} = $load_balancer->{DNSName}; $elb{availability_zones} = $load_balancer->{AvailabilityZones}; @@ -99,7 +99,7 @@ __END__ =head1 MODE -ELB discovery. +Classic ELB discovery. =over 8 diff --git a/cloud/aws/elb/mode/httpcodes.pm b/cloud/aws/elb/classic/mode/httpcodes.pm similarity index 96% rename from cloud/aws/elb/mode/httpcodes.pm rename to cloud/aws/elb/classic/mode/httpcodes.pm index 7e6c91a46..39449871a 100644 --- a/cloud/aws/elb/mode/httpcodes.pm +++ b/cloud/aws/elb/classic/mode/httpcodes.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::aws::elb::mode::httpcodes; +package cloud::aws::elb::classic::mode::httpcodes; use base qw(centreon::plugins::templates::counter); @@ -234,10 +234,10 @@ __END__ =head1 MODE -Check ELB http codes. +Check Classic ELB HTTP codes metrics. Example: -perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=http-codes --region='eu-west-1' +perl centreon_plugins.pl --plugin=cloud::aws::elb::classic::plugin --custommode=paws --mode=http-codes --region='eu-west-1' --type='loadbalancer' --name='elb-www-fr' --critical-httpcode-backend-4xx='10' --verbose See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. @@ -264,18 +264,12 @@ Filter metrics (Can be: 'HTTPCode_Backend_2XX', 'HTTPCode_Backend_3XX', 'HTTPCod 'HTTPCode_Backend_5XX', 'HTTPCode_ELB_4XX', 'HTTPCode_ELB_5XX', 'BackendConnectionErrors') (Can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> Thresholds warning (Can be: 'httpcode-backend-2xx', 'httpcode-backend-3xx', 'httpcode-backend-4xx', 'httpcode-backend-5xx', 'httpcode-elb-4xx', 'httpcode-elb-5xx', 'backendconnectionerrors') -=item B<--critical-*> - -Thresholds critical (Can be: 'httpcode-backend-2xx', 'httpcode-backend-3xx', -'httpcode-backend-4xx', 'httpcode-backend-5xx', 'httpcode-elb-4xx', -'httpcode-elb-5xx', 'backendconnectionerrors') - =back =cut diff --git a/cloud/aws/elb/mode/performances.pm b/cloud/aws/elb/classic/mode/performances.pm similarity index 96% rename from cloud/aws/elb/mode/performances.pm rename to cloud/aws/elb/classic/mode/performances.pm index 1ba00b2b6..43dfb4dd6 100644 --- a/cloud/aws/elb/mode/performances.pm +++ b/cloud/aws/elb/classic/mode/performances.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::aws::elb::mode::performances; +package cloud::aws::elb::classic::mode::performances; use base qw(centreon::plugins::templates::counter); @@ -209,11 +209,11 @@ __END__ =head1 MODE -Check ELB performances. +Check Classic ELB performances. Example: -perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=performances --region='eu-west-1' ---type='loadbalancer' --name='elb-www-fr' --critical-requestcount='10' --verbose +perl centreon_plugins.pl --plugin=cloud::aws::elb::classic::plugin --custommode=paws --mode=performances +--region='eu-west-1' --type='loadbalancer' --name='elb-www-fr' --critical-requestcount='10' --verbose See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. @@ -238,14 +238,10 @@ Add Availability Zone dimension (only with --type='loadbalancer'). Filter metrics (Can be: 'RequestCount', 'Latency') (Can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> Thresholds warning (Can be: 'requestcount', 'latency'). -=item B<--critical-*> - -Thresholds critical (Can be: 'requestcount', 'latency'). - =back =cut diff --git a/cloud/aws/elb/mode/queues.pm b/cloud/aws/elb/classic/mode/queues.pm similarity index 94% rename from cloud/aws/elb/mode/queues.pm rename to cloud/aws/elb/classic/mode/queues.pm index a2c94ba65..1f3b1a5cd 100644 --- a/cloud/aws/elb/mode/queues.pm +++ b/cloud/aws/elb/classic/mode/queues.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::aws::elb::mode::queues; +package cloud::aws::elb::classic::mode::queues; use base qw(centreon::plugins::templates::counter); @@ -210,10 +210,10 @@ __END__ =head1 MODE -Check ELB surge queue. +Check Classic ELB surge queue. Example: -perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=queues --region='eu-west-1' +perl centreon_plugins.pl --plugin=cloud::aws::elb::classic::plugin --custommode=paws --mode=queues --region='eu-west-1' --type='loadbalancer' --name='elb-www-fr' --critical-spillovercount-sum='10' --verbose See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. @@ -239,15 +239,9 @@ Add Availability Zone dimension (only with --type='loadbalancer'). Filter metrics (Can be: 'SpilloverCount', 'SurgeQueueLength') (Can be a regexp). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-*> B<--critical-*> -Thresholds warning ($metric$ can be: 'spillovercount', 'surgequeuelength', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). - -=item B<--critical-$metric$-$statistic$> - -Thresholds critical ($metric$ can be: 'spillovercount', 'surgequeuelength', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning (Can be: 'spillovercount', 'surgequeuelength'). =back diff --git a/cloud/aws/elb/mode/targetshealth.pm b/cloud/aws/elb/classic/mode/targetshealth.pm similarity index 96% rename from cloud/aws/elb/mode/targetshealth.pm rename to cloud/aws/elb/classic/mode/targetshealth.pm index 517e174a7..2c4b69fc4 100644 --- a/cloud/aws/elb/mode/targetshealth.pm +++ b/cloud/aws/elb/classic/mode/targetshealth.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::aws::elb::mode::targetshealth; +package cloud::aws::elb::classic::mode::targetshealth; use base qw(centreon::plugins::templates::counter); @@ -210,10 +210,10 @@ __END__ =head1 MODE -Check ELB instances health. +Check Classic ELB instances health. Example: -perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=instancehealth --region='eu-west-1' +perl centreon_plugins.pl --plugin=cloud::aws::elb::classic::plugin --custommode=paws --mode=instancehealth --region='eu-west-1' --type='loadbalancer' --name='elb-www-fr' --critical-healthyhostcount='10' --verbose See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. @@ -239,14 +239,10 @@ Add Availability Zone dimension (only with --type='loadbalancer'). Filter metrics (Can be: 'HealthyHostCount', 'UnHealthyHostCount') (Can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> Thresholds warning (Can be: 'healthyhostcount', 'unhealthyhostcount'). -=item B<--critical-*> - -Thresholds critical (Can be: 'healthyhostcount', 'unhealthyhostcount'). - =back =cut diff --git a/cloud/aws/elb/classic/plugin.pm b/cloud/aws/elb/classic/plugin.pm new file mode 100644 index 000000000..b068306f7 --- /dev/null +++ b/cloud/aws/elb/classic/plugin.pm @@ -0,0 +1,54 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::classic::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + %{ $self->{modes} } = ( + 'discovery' => 'cloud::aws::elb::classic::mode::discovery', + 'http-codes' => 'cloud::aws::elb::classic::mode::httpcodes', + 'performances' => 'cloud::aws::elb::classic::mode::performances', + 'queues' => 'cloud::aws::elb::classic::mode::queues', + 'targets-health' => 'cloud::aws::elb::classic::mode::targetshealth', + ); + + $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; + $self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Amazon Classic Elastic Load Balancing (Amazon Classic ELB). + +=cut diff --git a/cloud/aws/elb/network/mode/discovery.pm b/cloud/aws/elb/network/mode/discovery.pm new file mode 100644 index 000000000..75ef93b7d --- /dev/null +++ b/cloud/aws/elb/network/mode/discovery.pm @@ -0,0 +1,111 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::network::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $load_balancers = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 'elbv2', + command => 'describe-load-balancers' + ); + + foreach my $load_balancer (@{$load_balancers->{LoadBalancers}}) { + next if (!defined($load_balancer->{LoadBalancerArn}) || $load_balancer->{Type} ne 'network'); + my %elb; + $elb{type} = "network"; + $elb{name} = $1 if ($load_balancer->{LoadBalancerArn} =~ /arn:aws:elasticloadbalancing:.*:loadbalancer\/(.*)/); + $elb{dns_name} = $load_balancer->{DNSName}; + $elb{availability_zones} = $load_balancer->{AvailabilityZones}; + $elb{vpc_id} = $load_balancer->{VpcId}; + $elb{security_groups} = $load_balancer->{SecurityGroups}; + $elb{state} = $load_balancer->{State}->{Code}; + push @disco_data, \%elb; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Network ELB discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/cloud/aws/elb/network/mode/targetshealth.pm b/cloud/aws/elb/network/mode/targetshealth.pm new file mode 100644 index 000000000..14924f2ce --- /dev/null +++ b/cloud/aws/elb/network/mode/targetshealth.pm @@ -0,0 +1,223 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::network::mode::targetshealth; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'HealthyHostCount' => { + 'output' => 'Healthy Hosts', + 'label' => 'healthyhostcount', + 'nlabel' => 'elb.healthyhostcount.count', + }, + 'UnHealthyHostCount' => { + 'output' => 'Unhealthy Hosts', + 'label' => 'unhealthyhostcount', + 'nlabel' => 'elb.unhealthyhostcount.count', + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "ELB '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + "statistic:s@" => { name => 'statistic' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{name}) || $self->{option_results}->{name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --name option."); + $self->{output}->option_exit(); + } + + foreach my $instance (@{$self->{option_results}->{name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Average']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + push @{$self->{aws_dimensions}}, { Name => 'LoadBalancer', Value => $instance }; + if (defined($self->{option_results}->{availability_zone}) && $self->{option_results}->{availability_zone} ne '') { + push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; + } + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/ApplicationELB', + dimensions => $self->{aws_dimensions}, + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Network ELB targets health. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::elb::network::plugin --custommode=paws --mode=targets-health +--region='eu-west-1' --name='net/NetProd/7c8ecfbd1093c5bd' --critical-unhealthyhostcount='10' --verbose + +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-cloudwatch-metrics.html' for more informations. + +Default statistic: 'average' / Most usefull statistics: 'average', 'minimum', 'maximum'. + +=over 8 + +=item B<--name> + +Set the instance name (Required) (Can be multiple). + +=item B<--availability-zone> + +Add Availability Zone dimension. + +=item B<--filter-metric> + +Filter metrics (Can be: 'HealthyHostCount', 'UnHealthyHostCount') +(Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds warning (Can be: 'healthyhostcount', 'unhealthyhostcount'). + +=back + +=cut diff --git a/cloud/aws/elb/plugin.pm b/cloud/aws/elb/network/plugin.pm similarity index 73% rename from cloud/aws/elb/plugin.pm rename to cloud/aws/elb/network/plugin.pm index 9d234ee98..85e0de8aa 100644 --- a/cloud/aws/elb/plugin.pm +++ b/cloud/aws/elb/network/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::aws::elb::plugin; +package cloud::aws::elb::network::plugin; use strict; use warnings; @@ -31,11 +31,8 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'discovery' => 'cloud::aws::elb::mode::discovery', - 'http-codes' => 'cloud::aws::elb::mode::httpcodes', - 'performances' => 'cloud::aws::elb::mode::performances', - 'queues' => 'cloud::aws::elb::mode::queues', - 'targets-health' => 'cloud::aws::elb::mode::targetshealth', + 'discovery' => 'cloud::aws::elb::network::mode::discovery', + 'targets-health' => 'cloud::aws::elb::network::mode::targetshealth', ); $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; @@ -49,6 +46,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Amazon Elastic Load Balancing (Amazon ELB). +Check Amazon Network Elastic Load Balancing (Amazon Network ELB). =cut From c2510e70ff69827151b76a1220f79be7328a8018 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 21 Oct 2019 09:18:50 +0200 Subject: [PATCH 10/11] enhance ntp snmp --- snmp_standard/mode/ntp.pm | 75 +++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/snmp_standard/mode/ntp.pm b/snmp_standard/mode/ntp.pm index b3893c021..40bf43219 100644 --- a/snmp_standard/mode/ntp.pm +++ b/snmp_standard/mode/ntp.pm @@ -27,6 +27,16 @@ use warnings; use centreon::plugins::misc; use DateTime; +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'Time offset %d second(s): %s', + $self->{result_values}->{offset_absolute}, + $self->{result_values}->{date_absolute} + ); +} + sub set_counters { my ($self, %options) = @_; @@ -36,12 +46,12 @@ sub set_counters { $self->{maps_counters}->{offset} = [ { label => 'offset', nlabel => 'time.offset.seconds', set => { - key_values => [ { name => 'offset' } ], - output_template => 'Offset: %d second(s)', + key_values => [ { name => 'offset' }, { name => 'date' } ], + closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ { label => 'offset', value => 'offset_absolute', template => '%d', unit => 's' }, ], - } + } }, ]; } @@ -51,33 +61,34 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "ntp-hostname:s" => { name => 'ntp_hostname' }, - "ntp-port:s" => { name => 'ntp_port', default => 123 }, - "timezone:s" => { name => 'timezone' }, - }); + $options{options}->add_options(arguments => { + 'ntp-hostname:s' => { name => 'ntp_hostname' }, + 'ntp-port:s' => { name => 'ntp_port', default => 123 }, + 'timezone:s' => { name => 'timezone' }, + }); + return $self; } sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); + my ($self, %options) = @_; + $self->SUPER::check_options(%options); - if (defined($self->{option_results}->{ntp_hostname})) { - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Net::NTP', - error_msg => "Cannot load module 'Net::NTP'."); + if (defined($self->{option_results}->{ntp_hostname})) { + centreon::plugins::misc::mymodule_load( + output => $self->{output}, module => 'Net::NTP', + error_msg => "Cannot load module 'Net::NTP'." + ); } } sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; $self->{offset} = {}; my ($ref_time, $distant_time); my $oid_hrSystemDate = '.1.3.6.1.2.1.25.1.2.0'; - my $result = $self->{snmp}->get_leef(oids => [ $oid_hrSystemDate ], nothing_quit => 1); + my $result = $options{snmp}->get_leef(oids => [ $oid_hrSystemDate ], nothing_quit => 1); if (defined($self->{option_results}->{ntp_hostname}) && $self->{option_results}->{ntp_hostname} ne '') { my %ntp; @@ -85,8 +96,10 @@ sub manage_selection { %ntp = Net::NTP::get_ntp_response($self->{option_results}->{ntp_hostname}, $self->{option_results}->{ntp_port}); }; if ($@) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Couldn't connect to ntp server: " . $@); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Couldn't connect to ntp server: " . $@ + ); $self->{output}->display(); $self->{output}->exit(); } @@ -95,7 +108,7 @@ sub manage_selection { } else { $ref_time = time(); } - + my @remote_date = unpack 'n C6 a C2', $result->{$oid_hrSystemDate}; my $timezone = 'UTC'; if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { @@ -103,7 +116,7 @@ sub manage_selection { } elsif (defined($remote_date[9])) { $timezone = sprintf("%s%02d%02d", $remote_date[7], $remote_date[8], $remote_date[9]); # format +0630 } - + my $tz = centreon::plugins::misc::set_timezone(name => $timezone); my $dt = DateTime->new( year => $remote_date[0], @@ -114,21 +127,21 @@ sub manage_selection { second => $remote_date[5], %$tz ); - $distant_time = $dt->epoch; - + my $offset = $distant_time - $ref_time; - my $remote_date_formated = sprintf("Local Time : %02d-%02d-%02dT%02d:%02d:%02d (%s)", $remote_date[0], $remote_date[1], $remote_date[2], - $remote_date[3], $remote_date[4], $remote_date[5], $timezone); - - + my $remote_date_formated = sprintf( + 'Local Time : %02d-%02d-%02dT%02d:%02d:%02d (%s)', + $remote_date[0], $remote_date[1], $remote_date[2], + $remote_date[3], $remote_date[4], $remote_date[5], $timezone + ); + my $formated_offset = sprintf("%d", $offset); - + $self->{offset} = { - offset => $formated_offset, - display => 0 }; - - $self->{output}->add_option_msg(short_msg => $remote_date_formated); + offset => $formated_offset, + date => $remote_date_formated, + }; } 1; From dc924a1788f6ea4bb3444bc4784771c04f76fd9c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 21 Oct 2019 09:41:51 +0200 Subject: [PATCH 11/11] Fix #1682 --- .../standard/snmp/mode/components/fan.pm | 31 ++++++++++++------- .../standard/snmp/mode/components/module.pm | 6 ++-- .../standard/snmp/mode/components/physical.pm | 6 ++-- .../standard/snmp/mode/components/psu.pm | 12 +++---- .../snmp/mode/components/temperature.pm | 20 +++++++----- .../standard/snmp/mode/components/voltage.pm | 6 ++-- .../cisco/standard/snmp/mode/environment.pm | 4 +++ 7 files changed, 50 insertions(+), 35 deletions(-) diff --git a/centreon/common/cisco/standard/snmp/mode/components/fan.pm b/centreon/common/cisco/standard/snmp/mode/components/fan.pm index 1eaef0d0a..8f777a8c2 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/fan.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/fan.pm @@ -63,16 +63,19 @@ sub check_fan_envmon { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonFanStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance, name => $result->{ciscoEnvMonFanStatusDescr})); next if ($result->{ciscoEnvMonFanState} =~ /not present/i && - $self->absent_problem(section => 'fan', instance => $instance)); + $self->absent_problem(section => 'fan', instance => $instance, name => $result->{ciscoEnvMonFanStatusDescr})); $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s [instance: %s].", - $result->{ciscoEnvMonFanStatusDescr}, $result->{ciscoEnvMonFanState}, - $instance - )); - my $exit = $self->get_severity(section => 'fan', value => $result->{ciscoEnvMonFanState}); + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is %s [instance: %s].", + $result->{ciscoEnvMonFanStatusDescr}, $result->{ciscoEnvMonFanState}, + $instance + ) + ); + my $exit = $self->get_severity(section => 'fan', instance => $instance, value => $result->{ciscoEnvMonFanState}); 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", @@ -94,12 +97,16 @@ sub check_fan_entity { my $fan_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFanTrayOperStatus}, instance => $instance); - next if ($self->check_filter(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance, name => $fan_descr)); $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is %s [instance: %s]", - $fan_descr, $result->{cefcFanTrayOperStatus}, $instance)); - my $exit = $self->get_severity(section => 'fan', value => $result->{cefcFanTrayOperStatus}); + $self->{output}->output_add( + long_msg => sprintf( + "Fan '%s' status is %s [instance: %s]", + $fan_descr, $result->{cefcFanTrayOperStatus}, $instance + ) + ); + my $exit = $self->get_severity(section => 'fan', instance => $instance, value => $result->{cefcFanTrayOperStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Fan '%s/%s' status is %s", $fan_descr, $instance, $result->{cefcFanTrayOperStatus})); @@ -118,4 +125,4 @@ sub check { check_fan_entity($self); } -1; \ No newline at end of file +1; diff --git a/centreon/common/cisco/standard/snmp/mode/components/module.pm b/centreon/common/cisco/standard/snmp/mode/components/module.pm index 43fef20fb..21c29c480 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/module.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/module.pm @@ -79,12 +79,12 @@ sub check { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcModuleOperStatus}, instance => $instance); my $module_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; - next if ($self->check_filter(section => 'module', instance => $instance)); + next if ($self->check_filter(section => 'module', instance => $instance, name => $module_descr)); $self->{components}->{module}->{total}++; $self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s]", $module_descr, $result->{cefcModuleOperStatus}, $instance)); - my $exit = $self->get_severity(section => 'module', value => $result->{cefcModuleOperStatus}); + my $exit = $self->get_severity(section => 'module', instance => $instance, value => $result->{cefcModuleOperStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Module '%s/%s' status is %s", $module_descr, @@ -93,4 +93,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon/common/cisco/standard/snmp/mode/components/physical.pm b/centreon/common/cisco/standard/snmp/mode/components/physical.pm index 2f0b461a9..232ef1064 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/physical.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/physical.pm @@ -61,12 +61,12 @@ sub check { next; } - next if ($self->check_filter(section => 'physical', instance => $instance)); + next if ($self->check_filter(section => 'physical', instance => $instance, name => $physical_descr)); $self->{components}->{physical}->{total}++; $self->{output}->output_add(long_msg => sprintf("Physical '%s' status is %s [instance: %s]", $physical_descr, $result->{cefcPhysicalStatus}, $instance)); - my $exit = $self->get_severity(section => 'physical', value => $result->{cefcPhysicalStatus}); + my $exit = $self->get_severity(section => 'physical', instance => $instance, value => $result->{cefcPhysicalStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Physical '%s/%s' status is %s", $physical_descr, @@ -75,4 +75,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon/common/cisco/standard/snmp/mode/components/psu.pm b/centreon/common/cisco/standard/snmp/mode/components/psu.pm index 41db1f1a9..2405a2c43 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/psu.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/psu.pm @@ -79,16 +79,16 @@ sub check_psu_envmon { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonSupplyStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance, name => $result->{ciscoEnvMonSupplyStatusDescr})); next if ($result->{ciscoEnvMonSupplyState} =~ /not present/i && - $self->absent_problem(section => 'psu', instance => $instance)); + $self->absent_problem(section => 'psu', instance => $instance, name => $result->{ciscoEnvMonSupplyStatusDescr})); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s [instance: %s] [source: %s]", $result->{ciscoEnvMonSupplyStatusDescr}, $result->{ciscoEnvMonSupplyState}, $instance, $result->{ciscoEnvMonSupplySource} )); - my $exit = $self->get_severity(section => 'psu', value => $result->{ciscoEnvMonSupplyState}); + my $exit = $self->get_severity(section => 'psu', instance => $instance, value => $result->{ciscoEnvMonSupplyState}); 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", @@ -110,12 +110,12 @@ sub check_psu_entity { my $psu_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFRUPowerOperStatus}, instance => $instance); - next if ($self->check_filter(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance, name => $psu_descr)); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s [instance: %s]", $psu_descr, $result->{cefcFRUPowerOperStatus}, $instance)); - my $exit = $self->get_severity(section => 'psu', value => $result->{cefcFRUPowerOperStatus}); + my $exit = $self->get_severity(section => 'psu', instance => $instance, value => $result->{cefcFRUPowerOperStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Power supply '%s/%s' status is %s", $psu_descr, $instance, $result->{cefcFRUPowerOperStatus})); @@ -134,4 +134,4 @@ sub check { check_psu_entity($self); } -1; \ No newline at end of file +1; diff --git a/centreon/common/cisco/standard/snmp/mode/components/temperature.pm b/centreon/common/cisco/standard/snmp/mode/components/temperature.pm index d11131280..25b4e9a2f 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/temperature.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/temperature.pm @@ -59,22 +59,26 @@ sub check { my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonTemperatureStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance, name => $result->{ciscoEnvMonTemperatureStatusDescr})); $self->{components}->{temperature}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is %s [instance: %s] [value: %s C]", - $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState}, - $instance, defined($result->{ciscoEnvMonTemperatureStatusValue}) ? $result->{ciscoEnvMonTemperatureStatusValue} : '-')); - my $exit = $self->get_severity(section => 'temperature', value => $result->{ciscoEnvMonTemperatureState}); + $self->{output}->output_add( + long_msg => sprintf( + "Temperature '%s' status is %s [instance: %s] [value: %s C]", + $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState}, + $instance, defined($result->{ciscoEnvMonTemperatureStatusValue}) ? $result->{ciscoEnvMonTemperatureStatusValue} : '-' + ) + ); + my $exit = $self->get_severity(section => 'temperature', instance => $instance, value => $result->{ciscoEnvMonTemperatureState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Temperature '%s' status is %s", $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState})); } - + next if (!defined($result->{ciscoEnvMonTemperatureStatusValue})); - - my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{ciscoEnvMonTemperatureStatusValue}); + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, name => $result->{ciscoEnvMonTemperatureStatusDescr}, value => $result->{ciscoEnvMonTemperatureStatusValue}); if ($checked == 0) { my $warn_th = undef; my $crit_th = '~:' . $result->{ciscoEnvMonTemperatureThreshold}; diff --git a/centreon/common/cisco/standard/snmp/mode/components/voltage.pm b/centreon/common/cisco/standard/snmp/mode/components/voltage.pm index 16d3fa907..c70825cdd 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/voltage.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/voltage.pm @@ -60,13 +60,13 @@ sub check { my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonVoltageStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'voltage', instance => $instance)); + next if ($self->check_filter(section => 'voltage', instance => $instance, name => $result->{ciscoEnvMonVoltageStatusDescr})); $self->{components}->{voltage}->{total}++; $self->{output}->output_add(long_msg => sprintf("Voltage '%s' status is %s [instance: %s] [value: %s C]", $result->{ciscoEnvMonVoltageStatusDescr}, $result->{ciscoEnvMonVoltageState}, $instance, $result->{ciscoEnvMonVoltageStatusValue})); - my $exit = $self->get_severity(section => 'voltage', value => $result->{ciscoEnvMonVoltageState}); + my $exit = $self->get_severity(section => 'voltage', instance => $instance, value => $result->{ciscoEnvMonVoltageState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Voltage '%s' status is %s", @@ -74,7 +74,7 @@ sub check { } $result->{ciscoEnvMonVoltageStatusValue} = $result->{ciscoEnvMonVoltageStatusValue} / 1000; - my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{ciscoEnvMonVoltageStatusValue}); + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, name => $result->{ciscoEnvMonVoltageStatusDescr}, value => $result->{ciscoEnvMonVoltageStatusValue}); if ($checked == 0) { my $warn_th = undef; my $crit_th = ((defined($result->{ciscoEnvMonVoltageThresholdLow}) && $result->{ciscoEnvMonVoltageThresholdLow} =~ /\d/) ? sprintf("%.3f", $result->{ciscoEnvMonVoltageThresholdLow} / 1000) : 0) . ':' . diff --git a/centreon/common/cisco/standard/snmp/mode/environment.pm b/centreon/common/cisco/standard/snmp/mode/environment.pm index c97f6ba1a..515d5a4e8 100644 --- a/centreon/common/cisco/standard/snmp/mode/environment.pm +++ b/centreon/common/cisco/standard/snmp/mode/environment.pm @@ -164,6 +164,10 @@ Can be: 'fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor'. Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) Can also exclude specific instance: --filter=fan,1 +=item B<--add-name-instance> + +Add literal description for instance value (used in filter, absent-problem and threshold options). + =item B<--absent-problem> Return an error if an entity is not 'present' (default is skipping) (comma seperated list)