From 1489326501e752b90fe4027e005d7649dcc28a91 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 2 Sep 2020 11:19:57 +0200 Subject: [PATCH] Cisco tc (#2182) * add compatibility for cisco TC --- centreon/plugins/backend/http/curl.pm | 3 +- .../devices/cisco/ces/restapi/custom/api.pm | 47 +++++++------- .../devices/cisco/ces/restapi/mode/callsrt.pm | 2 +- .../cisco/ces/restapi/mode/callssummary.pm | 2 +- .../cisco/ces/restapi/mode/certificates.pm | 2 +- .../cisco/ces/restapi/mode/components.pm | 7 +++ .../cisco/ces/restapi/mode/components/ad.pm | 2 + .../cisco/ces/restapi/mode/components/aic.pm | 24 ++++--- .../cisco/ces/restapi/mode/components/aoc.pm | 3 + .../ces/restapi/mode/components/camera.pm | 25 ++++++-- .../ces/restapi/mode/components/software.pm | 18 ++++-- .../restapi/mode/components/temperature.pm | 40 ++++++++++-- .../cisco/ces/restapi/mode/components/vis.pm | 10 ++- .../cisco/ces/restapi/mode/diagnostics.pm | 62 +++++++++++++------ .../cisco/ces/restapi/mode/peripherals.pm | 2 +- .../cisco/ces/restapi/mode/sessions.pm | 2 +- hardware/devices/cisco/ces/restapi/plugin.pm | 6 +- 17 files changed, 175 insertions(+), 82 deletions(-) diff --git a/centreon/plugins/backend/http/curl.pm b/centreon/plugins/backend/http/curl.pm index 9ab8cf2d1..51b09ecfc 100644 --- a/centreon/plugins/backend/http/curl.pm +++ b/centreon/plugins/backend/http/curl.pm @@ -158,6 +158,7 @@ sub set_method { my ($self, %options) = @_; $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_CUSTOMREQUEST'), parameter => undef); + $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POSTFIELDS'), parameter => undef); $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_HTTPGET'), parameter => 1); if ($options{request}->{method} eq 'GET') { @@ -318,7 +319,7 @@ sub request { my $headers = []; my $content_type_forced = 0; foreach my $key (keys %{$options{request}->{headers}}) { - push @$headers, $key . ':' . $options{request}->{headers}->{$key}; + push @$headers, $key . ':' . (defined($options{request}->{headers}->{$key}) ? $options{request}->{headers}->{$key} : ''); if ($key =~ /content-type/i) { $content_type_forced = 1; } diff --git a/hardware/devices/cisco/ces/restapi/custom/api.pm b/hardware/devices/cisco/ces/restapi/custom/api.pm index 6e7693bcf..8d6898aa4 100644 --- a/hardware/devices/cisco/ces/restapi/custom/api.pm +++ b/hardware/devices/cisco/ces/restapi/custom/api.pm @@ -50,7 +50,8 @@ sub new { 'proto:s' => { name => 'proto' }, 'api-username:s' => { name => 'api_username' }, 'api-password:s' => { name => 'api_password' }, - 'timeout:s' => { name => 'timeout', default => 30 } + 'timeout:s' => { name => 'timeout', default => 30 }, + 'no-session' => { name => 'no_session' } }); } @@ -74,27 +75,28 @@ sub set_defaults {} sub check_options { my ($self, %options) = @_; - $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30; - $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : undef; - $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : undef; + $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : ''; + $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : ''; + $self->{no_session} = (defined($self->{option_results}->{no_session})) ? 1 : 0; - if (!defined($self->{hostname}) || $self->{hostname} eq '') { + if ($self->{hostname} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); $self->{output}->option_exit(); } - if (!defined($self->{api_username}) || $self->{api_username} eq '') { + if ($self->{api_username} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); $self->{output}->option_exit(); } - if (!defined($self->{api_password}) || $self->{api_password} eq '') { + if ($self->{api_password} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option."); $self->{output}->option_exit(); } - $self->{cache}->check_options(option_results => $self->{option_results}); + $self->{cache}->check_options(option_results => $self->{option_results}) if ($self->{no_session} == 0); return 0; } @@ -105,6 +107,12 @@ sub build_options_for_httplib { $self->{option_results}->{port} = $self->{port}; $self->{option_results}->{proto} = $self->{proto}; $self->{option_results}->{timeout} = $self->{timeout}; + if ($self->{no_session} == 1) { + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{api_username}; + $self->{option_results}->{password} = $self->{api_password}; + } } sub settings { @@ -116,21 +124,6 @@ sub settings { $self->{http}->set_options(%{$self->{option_results}}); } -sub json_decode { - my ($self, %options) = @_; - - my $decoded; - eval { - $decoded = JSON::XS->new->utf8->decode($options{content}); - }; - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); - $self->{output}->option_exit(); - } - - return $decoded; -} - sub clean_session_cookie { my ($self, %options) = @_; @@ -179,7 +172,7 @@ sub request_api { my ($self, %options) = @_; $self->settings(); - if (!defined($self->{session_cookie})) { + if ($self->{no_session} == 0 && !defined($self->{session_cookie})) { $self->authenticate(statefile => $self->{cache}); } @@ -189,7 +182,7 @@ sub request_api { ); # Maybe there is an issue with the session_cookie. So we retry. - if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) { + if ($self->{no_session} == 0 && ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300)) { $self->clean_session_cookie(statefile => $self->{cache}); $self->authenticate(statefile => $self->{cache}); $content = $self->{http}->request( @@ -251,6 +244,10 @@ Set password. Threshold for HTTP timeout (Default: '30'). +=item B<--no-session> + +To be used for legacy version (before CE 8.0). + =back =cut diff --git a/hardware/devices/cisco/ces/restapi/mode/callsrt.pm b/hardware/devices/cisco/ces/restapi/mode/callsrt.pm index 76722af64..0176edd85 100644 --- a/hardware/devices/cisco/ces/restapi/mode/callsrt.pm +++ b/hardware/devices/cisco/ces/restapi/mode/callsrt.pm @@ -221,7 +221,7 @@ __END__ =head1 MODE -Check call channels in real-time. +Check call channels in real-time (since CE 8.3) =over 8 diff --git a/hardware/devices/cisco/ces/restapi/mode/callssummary.pm b/hardware/devices/cisco/ces/restapi/mode/callssummary.pm index 0f49228c3..6d78955db 100644 --- a/hardware/devices/cisco/ces/restapi/mode/callssummary.pm +++ b/hardware/devices/cisco/ces/restapi/mode/callssummary.pm @@ -207,7 +207,7 @@ __END__ =head1 MODE -Check call history. +Check call history (since TC 6.3) =over 8 diff --git a/hardware/devices/cisco/ces/restapi/mode/certificates.pm b/hardware/devices/cisco/ces/restapi/mode/certificates.pm index dbc93f3de..e9f7065d1 100644 --- a/hardware/devices/cisco/ces/restapi/mode/certificates.pm +++ b/hardware/devices/cisco/ces/restapi/mode/certificates.pm @@ -119,7 +119,7 @@ __END__ =head1 MODE -Check certificates validity. +Check certificates validity (since CE 9.2) =over 8 diff --git a/hardware/devices/cisco/ces/restapi/mode/components.pm b/hardware/devices/cisco/ces/restapi/mode/components.pm index 5315c5551..8ee72b503 100644 --- a/hardware/devices/cisco/ces/restapi/mode/components.pm +++ b/hardware/devices/cisco/ces/restapi/mode/components.pm @@ -44,6 +44,7 @@ sub set_system { ['Unknown', 'UNKNOWN'] ], temperature => [ + ['n/a', 'OK'], ['Normal', 'OK'], ['.*', 'CRITICAL'] ], @@ -55,6 +56,7 @@ sub set_system { ['Succeeded', 'OK'] ], software_urgency => [ + ['n/a', 'OK'], ['Low', 'OK'], ['Medium', 'OK'], ['Critical', 'CRITICAL'] @@ -116,6 +118,11 @@ sub execute_custom { url_path => '/status.xml', ForceArray => ['Microphone', 'HDMI', 'Line', 'InternalSpeaker', 'Camera', 'Connector', 'Source'] ); + + my $system_version = 'unknown'; + $system_version = $self->{results}->{version} if (defined($self->{results}->{version})); + + $self->{output}->output_add(long_msg => 'system version: ' . $system_version); } 1; diff --git a/hardware/devices/cisco/ces/restapi/mode/components/ad.pm b/hardware/devices/cisco/ces/restapi/mode/components/ad.pm index 2854a0387..227f57887 100644 --- a/hardware/devices/cisco/ces/restapi/mode/components/ad.pm +++ b/hardware/devices/cisco/ces/restapi/mode/components/ad.pm @@ -55,11 +55,13 @@ sub check { $self->{components}->{ad} = { name => 'audio devices', total => 0, skip => 0 }; return if ($self->check_filter(section => 'ad')); + # since CE 9.8 check_ad( $self, entry => $self->{results}->{Audio}->{Devices}->{HandsetUSB}, instance => 'handsetUSB' ); + # since CE 9.8 check_ad( $self, entry => $self->{results}->{Audio}->{Devices}->{HeadsetUSB}, diff --git a/hardware/devices/cisco/ces/restapi/mode/components/aic.pm b/hardware/devices/cisco/ces/restapi/mode/components/aic.pm index 5b3c42771..1f1e54490 100644 --- a/hardware/devices/cisco/ces/restapi/mode/components/aic.pm +++ b/hardware/devices/cisco/ces/restapi/mode/components/aic.pm @@ -23,13 +23,23 @@ package hardware::devices::cisco::ces::restapi::mode::components::aic; use strict; use warnings; +# +# +# 0 +# +# +# 0 +# +# + sub check_aic { my ($self, %options) = @_; foreach (@{$options{entry}->{ $options{element} }}) { my $instance = $options{element} . ':' . $_->{item}; - next if (!defined($_->{ConnectionStatus}) && !defined($_->{EcReferenceDelay})); + my $ec_reference_delay = ref($_->{EcReferenceDelay}) eq 'HASH' ? $_->{EcReferenceDelay}->{content} : $_->{EcReferenceDelay}; + next if (!defined($_->{ConnectionStatus}) && !defined($ec_reference_delay)); next if ($self->check_filter(section => 'aic', instance => $instance)); $self->{components}->{aic}->{total}++; @@ -40,7 +50,7 @@ sub check_aic { $instance, defined($_->{ConnectionStatus}) ? $_->{ConnectionStatus} : 'n/a', $instance, - defined($_->{EcReferenceDelay}) ? $_->{EcReferenceDelay} : '-' + defined($ec_reference_delay) ? $ec_reference_delay : '-' ) ); @@ -54,15 +64,15 @@ sub check_aic { } } - if (defined($_->{EcReferenceDelay})) { - my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'aiclatency', instance => $instance, value => $_->{EcReferenceDelay}); + if (defined($ec_reference_delay)) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'aiclatency', instance => $instance, value => $ec_reference_delay); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add( severity => $exit, short_msg => sprintf( "audio input connector '%s' latency is %s ms", - $instance, $_->{EcReferenceDelay} + $instance, $ec_reference_delay ) ); } @@ -70,9 +80,9 @@ sub check_aic { unit => 'ms', nlabel => 'component.audio.input.connector.latency.milliseconds', instances => [$options{element}, $_->{item}], - value => $_->{EcReferenceDelay}, + value => $ec_reference_delay, warning => $warn, - critical => $crit, + critical => $crit ); } } diff --git a/hardware/devices/cisco/ces/restapi/mode/components/aoc.pm b/hardware/devices/cisco/ces/restapi/mode/components/aoc.pm index cda5c3e4d..4cf86ad22 100644 --- a/hardware/devices/cisco/ces/restapi/mode/components/aoc.pm +++ b/hardware/devices/cisco/ces/restapi/mode/components/aoc.pm @@ -85,18 +85,21 @@ sub check { $self->{components}->{aoc} = { name => 'audio output connectors', total => 0, skip => 0 }; return if ($self->check_filter(section => 'aoc')); + # since CE 9.4 check_aoc( $self, entry => $self->{results}->{Audio}->{Output}->{Connectors}, element => 'HDMI', instance => 'item' ); + # since CE 9.4 check_aoc( $self, entry => $self->{results}->{Audio}->{Output}->{Connectors}, element => 'InternalSpeaker', instance => 'item' ); + # since CE 8.1 check_aoc( $self, entry => $self->{results}->{Audio}->{Output}->{Connectors}, diff --git a/hardware/devices/cisco/ces/restapi/mode/components/camera.pm b/hardware/devices/cisco/ces/restapi/mode/components/camera.pm index 4954e2a1d..a02d2b385 100644 --- a/hardware/devices/cisco/ces/restapi/mode/components/camera.pm +++ b/hardware/devices/cisco/ces/restapi/mode/components/camera.pm @@ -23,6 +23,15 @@ package hardware::devices::cisco::ces::restapi::mode::components::camera; use strict; use warnings; +# +# +# ptzf +# +# True +# ... +# +# + sub check { my ($self) = @_; @@ -30,28 +39,32 @@ sub check { $self->{components}->{camera} = { name => 'cameras', total => 0, skip => 0 }; return if ($self->check_filter(section => 'camera')); - return if (!defined($self->{results}->{Cameras}->{Camera})); + my $cameras = defined($self->{results}->{Cameras}->{Camera}) ? $self->{results}->{Cameras}->{Camera} : $self->{results}->{Camera}; - foreach (@{$self->{results}->{Cameras}->{Camera}}) { + return if (!$cameras); + + foreach (@$cameras) { my $instance = $_->{item}; next if ($self->check_filter(section => 'camera', instance => $instance)); $self->{components}->{camera}->{total}++; + my $connected = ref($_->{Connected}) eq 'HASH' ? $_->{Connected}->{content} : $_->{Connected}; + $self->{output}->output_add( long_msg => sprintf( "camera '%s' connection status is '%s' [instance: %s]", $instance, - $_->{Connected}, - $instance, + $connected, + $instance ) ); - my $exit = $self->get_severity(label => 'connected', section => 'camera.status', value => $_->{Connected}); + my $exit = $self->get_severity(label => 'connected', section => 'camera.status', value => $connected); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add( severity => $exit, - short_msg => sprintf("camera '%s' connection status is '%s'", $instance, $_->{Connected}) + short_msg => sprintf("camera '%s' connection status is '%s'", $instance, $connected) ); } } diff --git a/hardware/devices/cisco/ces/restapi/mode/components/software.pm b/hardware/devices/cisco/ces/restapi/mode/components/software.pm index 5ea356b8f..d6011b68e 100644 --- a/hardware/devices/cisco/ces/restapi/mode/components/software.pm +++ b/hardware/devices/cisco/ces/restapi/mode/components/software.pm @@ -36,29 +36,35 @@ sub check { return if ($self->check_filter(section => 'software', instance => $instance)); $self->{components}->{software}->{total}++; + my $status = ref($self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Status}) eq 'HASH' ? + $self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Status}->{content} : $self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Status}; + my $urgency = ref($self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Urgency}) eq 'HASH' ? + $self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Urgency}->{content} : $self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Urgency}; + $urgency = 'n/a' if (!defined($urgency)); + $self->{output}->output_add( long_msg => sprintf( "software '%s' status is '%s' [instance: %s, urgency: %s]", $instance, - $self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Status}, + $status, $instance, - $self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Urgency} + $urgency ) ); - my $exit = $self->get_severity(section => 'software_status', value => $self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Status}); + my $exit = $self->get_severity(section => 'software_status', value => $status); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add( severity => $exit, - short_msg => sprintf("software '%s' status is '%s'", $instance, $self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Status}) + short_msg => sprintf("software '%s' status is '%s'", $instance, $status) ); } - $exit = $self->get_severity(section => 'software_urgency', value => $self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Urgency}); + $exit = $self->get_severity(section => 'software_urgency', value => $urgency); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add( severity => $exit, - short_msg => sprintf("software '%s' urgency is '%s'", $instance, $self->{results}->{Provisioning}->{Software}->{UpgradeStatus}->{Urgency}) + short_msg => sprintf("software '%s' urgency is '%s'", $instance, $urgency) ); } } diff --git a/hardware/devices/cisco/ces/restapi/mode/components/temperature.pm b/hardware/devices/cisco/ces/restapi/mode/components/temperature.pm index 65f1948b3..7396a8494 100644 --- a/hardware/devices/cisco/ces/restapi/mode/components/temperature.pm +++ b/hardware/devices/cisco/ces/restapi/mode/components/temperature.pm @@ -30,7 +30,12 @@ sub check { $self->{components}->{temperature} = { name => 'temperature', total => 0, skip => 0 } ; return if ($self->check_filter(section => 'temperature')); - return if (!defined($self->{results}->{SystemUnit}->{Hardware}->{Monitoring}->{Temperature})); + my $temp_status = $self->{results}->{SystemUnit}->{Hardware}->{Monitoring}->{Temperature}->{Status}; + $temp_status = 'n/a' if (!defined($temp_status)); + my $temp_value = ref($self->{results}->{SystemUnit}->{Hardware}->{Temperature}) eq 'HASH' ? + $self->{results}->{SystemUnit}->{Hardware}->{Temperature}->{content} : undef; + + return if (!defined($temp_status) && !defined($temp_value)); my $instance = 1; return if ($self->check_filter(section => 'temperature', instance => $instance)); @@ -38,20 +43,43 @@ sub check { $self->{output}->output_add( long_msg => sprintf( - "temperature '%s' status is '%s' [instance: %s]", + "temperature '%s' status is '%s' [instance: %s, value: %s]", $instance, - $self->{results}->{SystemUnit}->{Hardware}->{Monitoring}->{Temperature}->{Status}, - $instance + $temp_status, + $instance, + defined($temp_value) ? $temp_value : '-' ) ); - my $exit = $self->get_severity(section => 'temperature', value => $self->{results}->{SystemUnit}->{Hardware}->{Monitoring}->{Temperature}->{Status}); + my $exit = $self->get_severity(section => 'temperature', value => $temp_status); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add( severity => $exit, - short_msg => sprintf("temperarture '%s' status is '%s'", $instance, $self->{results}->{SystemUnit}->{Hardware}->{Monitoring}->{Temperature}) + short_msg => sprintf("temperature '%s' status is '%s'", $instance, $temp_status) ); } + + return if (!defined($temp_value)); + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $temp_value); + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "temperature '%s' is %s C", + $instance, $temp_value + ) + ); + } + $self->{output}->perfdata_add( + unit => 'C', + nlabel => 'component.hardware.temperature.celsius', + instances => 'system', + value => $temp_value, + warning => $warn, + critical => $crit + ); } 1; diff --git a/hardware/devices/cisco/ces/restapi/mode/components/vis.pm b/hardware/devices/cisco/ces/restapi/mode/components/vis.pm index 3e495c0da..d36620301 100644 --- a/hardware/devices/cisco/ces/restapi/mode/components/vis.pm +++ b/hardware/devices/cisco/ces/restapi/mode/components/vis.pm @@ -38,20 +38,24 @@ sub check { next if ($self->check_filter(section => 'vis', instance => $instance)); $self->{components}->{vis}->{total}++; + my $format_status = defined($_->{Resolution}->{FormatStatus}) && ref($_->{Resolution}->{FormatStatus}) eq 'HASH' ? + $_->{Resolution}->{FormatStatus}->{content} : + $_->{FormatStatus}; + $self->{output}->output_add( long_msg => sprintf( "video input source '%s' format status is '%s' [instance: %s]", $instance, - $_->{FormatStatus}, + $format_status, $instance ) ); - my $exit = $self->get_severity(section => 'format_status', value => $_->{FormatStatus}); + my $exit = $self->get_severity(section => 'format_status', value => $format_status); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add( severity => $exit, - short_msg => sprintf("video input source '%s' format status is '%s'", $instance, $_->{FormatStatus}) + short_msg => sprintf("video input source '%s' format status is '%s'", $instance, $format_status) ); } } diff --git a/hardware/devices/cisco/ces/restapi/mode/diagnostics.pm b/hardware/devices/cisco/ces/restapi/mode/diagnostics.pm index 516370e1d..3e311b0e4 100644 --- a/hardware/devices/cisco/ces/restapi/mode/diagnostics.pm +++ b/hardware/devices/cisco/ces/restapi/mode/diagnostics.pm @@ -39,15 +39,6 @@ sub custom_status_output { ); } -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{description} = $options{new_datas}->{$self->{instance} . '_Description'}; - $self->{result_values}->{level} = $options{new_datas}->{$self->{instance} . '_Level'}; - $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_Type'}; - return 0; -} - sub set_counters { my ($self, %options) = @_; @@ -59,8 +50,7 @@ sub set_counters { $self->{maps_counters}->{alarm} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'Description' }, { name => 'Level' }, { name => 'Type' } ], - closure_custom_calc => $self->can('custom_status_calc'), + key_values => [ { name => 'description' }, { name => 'level' }, { name => 'type' } ], closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, closure_custom_threshold_check => \&catalog_status_threshold @@ -75,9 +65,10 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-msg:s' => { name => 'filter_msg' }, - 'warning-status:s' => { name => 'warning_status', default => '%{level} =~ /warning|minor/i' }, - 'critical-status:s' => { name => 'critical_status', default => '%{level} =~ /critical|major/i' } + 'filter-msg:s' => { name => 'filter_msg' }, + 'legacy-tc' => { name => 'legacy_tc' }, + 'warning-status:s' => { name => 'warning_status', default => '%{level} =~ /warning|minor/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{level} =~ /critical|major/i' } }); return $self; @@ -90,25 +81,50 @@ sub check_options { $self->change_macros(macros => ['warning_status', 'critical_status']); } +# +# +# +# System is in standby mode. +# Skipped +# +# SelectedVideoInputSourceConnected +# +# +# + sub manage_selection { my ($self, %options) = @_; - $self->{alarms}->{global} = { alarm => {} }; + my $post = 'Alerts'; + my $label = 'DiagnosticsRunResult'; + if (defined($self->{option_results}->{legacy_tc})) { + $post = 'Alerts'; + $label = 'DiagnosticsResult'; + } my $result = $options{custom}->request_api( method => 'POST', url_path => '/putxml', - query_form_post => 'Alerts', + query_form_post => $post, ForceArray => ['Message'] ); - foreach (@{$result->{DiagnosticsRunResult}->{Message}}) { + $self->{alarms}->{global} = { alarm => {} }; + foreach (@{$result->{$label}->{Message}}) { + my $description = ref($_->{Description}) eq 'HASH' ? $_->{Description}->{content} : $_->{Description}; + my $level = ref($_->{Level}) eq 'HASH' ? $_->{Level}->{content} : $_->{Level}; + my $type = ref($_->{Type}) eq 'HASH' ? $_->{Type}->{content} : $_->{Type}; + if (defined($self->{option_results}->{filter_msg}) && $self->{option_results}->{filter_msg} ne '' && - $_->{Description} !~ /$self->{option_results}->{filter_msg}/) { - $self->{output}->output_add(long_msg => "skipping '" . $_->{Description} . "': no matching filter.", debug => 1); + $description !~ /$self->{option_results}->{filter_msg}/) { + $self->{output}->output_add(long_msg => "skipping '" . $description . "': no matching filter.", debug => 1); next; } - $self->{alarms}->{global}->{alarm}->{$_->{item}} = $_; + $self->{alarms}->{global}->{alarm}->{ $_->{item} } = { + description => $description, + level => $level, + type => $type + }; } } @@ -119,6 +135,8 @@ __END__ =head1 MODE Check diagnostic messages. +Since TC 6.0: SystemUnit Diagnostics Run (use --legacy-tc option) +Since CE 8.0: Diagnostics Run =over 8 @@ -126,6 +144,10 @@ Check diagnostic messages. Filter by message (can be a regexp). +=item B<--legacy-tc> + +Use old legacy command. + =item B<--warning-status> Set warning threshold for status (Default: '%{level} =~ /warning|minor/i') diff --git a/hardware/devices/cisco/ces/restapi/mode/peripherals.pm b/hardware/devices/cisco/ces/restapi/mode/peripherals.pm index fd72283aa..557644c21 100644 --- a/hardware/devices/cisco/ces/restapi/mode/peripherals.pm +++ b/hardware/devices/cisco/ces/restapi/mode/peripherals.pm @@ -108,7 +108,7 @@ __END__ =head1 MODE -Check peripherals device connected. +Check peripherals device connected (since TC 7.2). =over 8 diff --git a/hardware/devices/cisco/ces/restapi/mode/sessions.pm b/hardware/devices/cisco/ces/restapi/mode/sessions.pm index 76570640c..f5b004d03 100644 --- a/hardware/devices/cisco/ces/restapi/mode/sessions.pm +++ b/hardware/devices/cisco/ces/restapi/mode/sessions.pm @@ -89,7 +89,7 @@ __END__ =head1 MODE -Check sessions. +Check sessions (since CE 8.2) =over 8 diff --git a/hardware/devices/cisco/ces/restapi/plugin.pm b/hardware/devices/cisco/ces/restapi/plugin.pm index 5c5e16955..6ad3cd935 100644 --- a/hardware/devices/cisco/ces/restapi/plugin.pm +++ b/hardware/devices/cisco/ces/restapi/plugin.pm @@ -31,7 +31,7 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( + $self->{modes}} = { 'components' => 'hardware::devices::cisco::ces::restapi::mode::components', 'calls-summary' => 'hardware::devices::cisco::ces::restapi::mode::callssummary', 'calls-rt' => 'hardware::devices::cisco::ces::restapi::mode::callsrt', @@ -39,9 +39,9 @@ sub new { 'diagnostics' => 'hardware::devices::cisco::ces::restapi::mode::diagnostics', 'peripherals' => 'hardware::devices::cisco::ces::restapi::mode::peripherals', 'sessions' => 'hardware::devices::cisco::ces::restapi::mode::sessions' - ); + }; - $self->{custom_modes}{api} = 'hardware::devices::cisco::ces::restapi::custom::api'; + $self->{custom_modes}->{api} = 'hardware::devices::cisco::ces::restapi::custom::api'; return $self; }