diff --git a/packaging/centreon-plugin-Hardware-Devices-Video-Appeartv-Snmp/deb.json b/packaging/centreon-plugin-Hardware-Devices-Video-Appeartv-Snmp/deb.json new file mode 100644 index 0000000000..663aaacebf --- /dev/null +++ b/packaging/centreon-plugin-Hardware-Devices-Video-Appeartv-Snmp/deb.json @@ -0,0 +1,5 @@ +{ + "dependencies": [ + "libsnmp-perl" + ] +} \ No newline at end of file diff --git a/packaging/centreon-plugin-Hardware-Devices-Video-Appeartv-Snmp/pkg.json b/packaging/centreon-plugin-Hardware-Devices-Video-Appeartv-Snmp/pkg.json new file mode 100644 index 0000000000..616908ac45 --- /dev/null +++ b/packaging/centreon-plugin-Hardware-Devices-Video-Appeartv-Snmp/pkg.json @@ -0,0 +1,10 @@ +{ + "pkg_name": "centreon-plugin-Hardware-Devices-Video-Appeartv-Snmp", + "pkg_summary": "Centreon Plugin to monitor Appear TV using SNMP", + "plugin_name": "centreon_video_appeartv_snmp.pl", + "files": [ + "centreon/plugins/script_snmp.pm", + "centreon/plugins/snmp.pm", + "hardware/devices/video/appeartv/snmp/" + ] +} diff --git a/packaging/centreon-plugin-Hardware-Devices-Video-Appeartv-Snmp/rpm.json b/packaging/centreon-plugin-Hardware-Devices-Video-Appeartv-Snmp/rpm.json new file mode 100644 index 0000000000..418a331fce --- /dev/null +++ b/packaging/centreon-plugin-Hardware-Devices-Video-Appeartv-Snmp/rpm.json @@ -0,0 +1,5 @@ +{ + "dependencies": [ + "perl(SNMP)" + ] +} \ No newline at end of file diff --git a/src/hardware/devices/video/appeartv/snmp/mode/alarms.pm b/src/hardware/devices/video/appeartv/snmp/mode/alarms.pm index fc682e0002..30cd192736 100644 --- a/src/hardware/devices/video/appeartv/snmp/mode/alarms.pm +++ b/src/hardware/devices/video/appeartv/snmp/mode/alarms.pm @@ -30,15 +30,15 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - + my $msg = sprintf("alarm [severity: %s] [source: %s] [text: %s] %s", $self->{result_values}->{severity}, - $self->{result_values}->{source}, $self->{result_values}->{text}, $self->{result_values}->{generation_time}); + $self->{result_values}->{source}, $self->{result_values}->{text}, $self->{result_values}->{generation_time}); return $msg; } sub custom_status_calc { my ($self, %options) = @_; - + $self->{result_values}->{source} = $options{new_datas}->{$self->{instance} . '_msgSourceName'}; $self->{result_values}->{text} = $options{new_datas}->{$self->{instance} . '_msgText'}; $self->{result_values}->{severity} = $options{new_datas}->{$self->{instance} . '_msgSeverity'}; @@ -47,24 +47,25 @@ sub custom_status_calc { return 0; } - sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ - { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, - group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] + { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, + group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] } ]; - + $self->{maps_counters}->{alarm} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'msgSourceName' }, { name => 'msgText' }, { name => 'since' }, { name => 'msgSeverity' }, { name => 'msgGenerationTime' } ], - closure_custom_calc => $self->can('custom_status_calc'), - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, - } + { label => 'status', + threshold => 0, + set => { + key_values => [ { name => 'msgSourceName' }, { name => 'msgText' }, { name => 'since' }, { name => 'msgSeverity' }, { name => 'msgGenerationTime' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } }, ]; } @@ -73,16 +74,16 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => - { - "filter-msg:s" => { name => 'filter_msg' }, - "warning-status:s" => { name => 'warning_status', default => '%{severity} =~ /minor|warning/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{severity} =~ /critical|major/i' }, - "memory" => { name => 'memory' }, - }); - - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Date::Parse', + { + "filter-msg:s" => { name => 'filter_msg' }, + "warning-status:s" => { name => 'warning_status', default => '%{severity} =~ /minor|warning/i' }, + "critical-status:s" => { name => 'critical_status', default => '%{severity} =~ /critical|major/i' }, + "memory" => { name => 'memory' }, + }); + + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Date::Parse', error_msg => "Cannot load module 'Date::Parse'."); $self->{statefile_cache} = centreon::plugins::statefile->new(%options); return $self; @@ -92,70 +93,76 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(macros => ['warning_status', 'critical_status']); + $self->change_macros(macros => [ 'warning_status', 'critical_status' ]); if (defined($self->{option_results}->{memory})) { $self->{statefile_cache}->check_options(%options); } } -my %map_severity = (0 => 'indeterminate', 1 => 'critical', 2 => 'major', 3 => 'minor', - 4 => 'warning', 5 => 'cleared', 6 => 'notify'); +my %map_severity = (0 => 'indeterminate', + 1 => 'critical', + 2 => 'major', + 3 => 'minor', + 4 => 'warning', + 5 => 'cleared', + 6 => 'notify'); my $mapping = { - msgSourceName => { oid => '.1.3.6.1.4.1.23916.3.1.4.1.3' }, - msgText => { oid => '.1.3.6.1.4.1.23916.3.1.4.1.4' }, - msgGenerationTime => { oid => '.1.3.6.1.4.1.23916.3.1.4.1.6' }, # 2016-12-16 14:49:18 - msgSeverity => { oid => '.1.3.6.1.4.1.23916.3.1.4.1.13', map => \%map_severity }, + msgSourceName => { oid => '.1.3.6.1.4.1.23916.3.1.4.1.3' }, + msgText => { oid => '.1.3.6.1.4.1.23916.3.1.4.1.4' }, + msgGenerationTime => { oid => '.1.3.6.1.4.1.23916.3.1.4.1.6' }, # 2016-12-16 14:49:18 + msgSeverity => { oid => '.1.3.6.1.4.1.23916.3.1.4.1.13', map => \%map_severity }, }; sub manage_selection { my ($self, %options) = @_; $self->{alarms}->{global} = { alarm => {} }; - my $snmp_result = $options{snmp}->get_multiple_table(oids => [ - { oid => $mapping->{msgSourceName}->{oid} }, - { oid => $mapping->{msgText}->{oid} }, - { oid => $mapping->{msgGenerationTime}->{oid} }, - { oid => $mapping->{msgSeverity}->{oid} }, - ], return_type => 1); + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + { oid => $mapping->{msgSourceName}->{oid} }, + { oid => $mapping->{msgText}->{oid} }, + { oid => $mapping->{msgGenerationTime}->{oid} }, + { oid => $mapping->{msgSeverity}->{oid} }, + ], + return_type => 1); my $last_time; if (defined($self->{option_results}->{memory})) { - $self->{statefile_cache}->read(statefile => "cache_appeartv_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port(). '_' . $self->{mode}); + $self->{statefile_cache}->read(statefile => "cache_appeartv_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode}); $last_time = $self->{statefile_cache}->get(name => 'last_time'); } - + my ($i, $current_time) = (1, time()); foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{msgSeverity}->{oid}\.(.*)$/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - + my $create_time = Date::Parse::str2time($result->{msgGenerationTime}); if (!defined($create_time)) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Can't Parse date '" . $result->{msgGenerationTime} . "'"); + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => "Can't Parse date '" . $result->{msgGenerationTime} . "'"); next; } - + next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $create_time); if (defined($self->{option_results}->{filter_msg}) && $self->{option_results}->{filter_msg} ne '' && $result->{msgText} !~ /$self->{option_results}->{filter_msg}/) { $self->{output}->output_add(long_msg => "skipping '" . $result->{msgText} . "': no matching filter.", debug => 1); next; } - + my $diff_time = $current_time - $create_time; - + $self->{alarms}->{global}->{alarm}->{$i} = { %$result, since => $diff_time }; $i++; } - + if (defined($self->{option_results}->{memory})) { $self->{statefile_cache}->write(data => { last_time => $current_time }); } } - + 1; __END__ @@ -166,21 +173,21 @@ Check alarms. =over 8 -=item B<--filter-msg> +=item C<--filter-msg> Filter by message (can be a regexp). -=item B<--warning-status> +=item C<--warning-status> Define the conditions to match for the status to be WARNING (default: '%{severity} =~ /minor|warning/i') You can use the following variables: %{severity}, %{text}, %{source}, %{since} -=item B<--critical-status> +=item C<--critical-status> Define the conditions to match for the status to be CRITICAL (default: '%{severity} =~ /critical|major/i'). You can use the following variables: %{severity}, %{text}, %{source}, %{since} -=item B<--memory> +=item C<--memory> Only check new alarms. diff --git a/src/hardware/devices/video/appeartv/snmp/plugin.pm b/src/hardware/devices/video/appeartv/snmp/plugin.pm index 865f54e199..7cbeb18cf3 100644 --- a/src/hardware/devices/video/appeartv/snmp/plugin.pm +++ b/src/hardware/devices/video/appeartv/snmp/plugin.pm @@ -28,10 +28,10 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $self->{version} = '0.1'; %{$self->{modes}} = ( - 'alarms' => 'hardware::devices::video::appeartv::snmp::mode::alarms', + 'alarms' => 'hardware::devices::video::appeartv::snmp::mode::alarms', ); return $self; @@ -43,6 +43,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check AppeartTV in SNMP. +Check AppearTV in SNMP. =cut diff --git a/tests/hardware/devices/video/appeartv/snmp/alarms.robot b/tests/hardware/devices/video/appeartv/snmp/alarms.robot new file mode 100644 index 0000000000..dc396ac1f6 --- /dev/null +++ b/tests/hardware/devices/video/appeartv/snmp/alarms.robot @@ -0,0 +1,36 @@ +*** Settings *** +Documentation Hardware Video Appeartv Alarms + +Resource ${CURDIR}${/}..${/}..${/}..${/}..${/}..${/}resources/import.resource + +Suite Setup Ctn Generic Suite Setup +Test Timeout 120s + + +*** Variables *** +${CMD} ${CENTREON_PLUGINS} +... --plugin=hardware::devices::video::appeartv::snmp::plugin +... --mode=alarms +... --hostname=${HOSTNAME} +... --snmp-port=${SNMPPORT} +... --snmp-community=hardware/devices/video/appeartv/snmp/appeartv + +*** Test Cases *** +AppearTV Alarms ${tc} + [Documentation] Hardware Video AppeartTV Alarms + [Tags] hardware appeartv alarms + ${command} Catenate + ... ${CMD} + ... ${extraoptions} + + Ctn Run Command And Check Result As Strings ${command} ${expected_result} + + Examples: tc extraoptions expected_result -- + ... 1 ${EMPTY} WARNING: 1 problem(s) detected | 'alerts'=1;;;0; + ... 2 --warning-status='\\\%{severity} =~ /minor/i' WARNING: 1 problem(s) detected | 'alerts'=1;;;0; + ... 3 --critical-status='\\\%{severity} =~ /critical|major|minor/i' CRITICAL: 1 problem(s) detected | 'alerts'=1;;;0; + ... 4 --filter-msg='Error' OK: 0 problem(s) detected | 'alerts'=0;;;0; + ... 5 --filter-msg='Disconnected' WARNING: 1 problem(s) detected | 'alerts'=1;;;0; + ... 6 --filter-msg='Disconnected' --critical-status='\\\%{severity} =~ /minor/i' CRITICAL: 1 problem(s) detected | 'alerts'=1;;;0; + ... 7 --memory WARNING: 1 problem(s) detected | 'alerts'=1;;;0; + ... 8 --memory OK: 0 problem(s) detected | 'alerts'=0;;;0; diff --git a/tests/hardware/devices/video/appeartv/snmp/appeartv.snmpwalk b/tests/hardware/devices/video/appeartv/snmp/appeartv.snmpwalk new file mode 100644 index 0000000000..428fbb9874 --- /dev/null +++ b/tests/hardware/devices/video/appeartv/snmp/appeartv.snmpwalk @@ -0,0 +1,4 @@ +.1.3.6.1.4.1.23916.3.1.4.1.3.0 = STRING: "Alarm 1" +.1.3.6.1.4.1.23916.3.1.4.1.4.0 = STRING: "Disconnected sound" +.1.3.6.1.4.1.23916.3.1.4.1.6.0 = STRING: "2024-09-16 14:49:18" +.1.3.6.1.4.1.23916.3.1.4.1.13.0 = INTEGER: 3 diff --git a/tests/resources/spellcheck/stopwords.txt b/tests/resources/spellcheck/stopwords.txt index 3ce5d83fd5..93238bd685 100644 --- a/tests/resources/spellcheck/stopwords.txt +++ b/tests/resources/spellcheck/stopwords.txt @@ -21,6 +21,7 @@ api.meraki.com --api-token --api-username --api-version +AppearTV ASAM Avigilon Avocent