feat(appeartv) - package AppearTV connector (#5313)

Co-authored-by: omercier <32134301+omercier@users.noreply.github.com>

REFS: CTOR-797
This commit is contained in:
sdepassio 2024-12-05 14:28:26 +01:00 committed by GitHub
parent 651095a4ea
commit 55409b71fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 122 additions and 54 deletions

View File

@ -0,0 +1,5 @@
{
"dependencies": [
"libsnmp-perl"
]
}

View File

@ -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/"
]
}

View File

@ -0,0 +1,5 @@
{
"dependencies": [
"perl(SNMP)"
]
}

View File

@ -30,15 +30,15 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("alarm [severity: %s] [source: %s] [text: %s] %s", $self->{result_values}->{severity}, 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; return $msg;
} }
sub custom_status_calc { sub custom_status_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{source} = $options{new_datas}->{$self->{instance} . '_msgSourceName'}; $self->{result_values}->{source} = $options{new_datas}->{$self->{instance} . '_msgSourceName'};
$self->{result_values}->{text} = $options{new_datas}->{$self->{instance} . '_msgText'}; $self->{result_values}->{text} = $options{new_datas}->{$self->{instance} . '_msgText'};
$self->{result_values}->{severity} = $options{new_datas}->{$self->{instance} . '_msgSeverity'}; $self->{result_values}->{severity} = $options{new_datas}->{$self->{instance} . '_msgSeverity'};
@ -47,24 +47,25 @@ sub custom_status_calc {
return 0; return 0;
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 },
group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ]
} }
]; ];
$self->{maps_counters}->{alarm} = [ $self->{maps_counters}->{alarm} = [
{ label => 'status', threshold => 0, set => { { label => 'status',
key_values => [ { name => 'msgSourceName' }, { name => 'msgText' }, { name => 'since' }, { name => 'msgSeverity' }, { name => 'msgGenerationTime' } ], threshold => 0,
closure_custom_calc => $self->can('custom_status_calc'), set => {
closure_custom_output => $self->can('custom_status_output'), key_values => [ { name => 'msgSourceName' }, { name => 'msgText' }, { name => 'since' }, { name => 'msgSeverity' }, { name => 'msgGenerationTime' } ],
closure_custom_perfdata => sub { return 0; }, closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_threshold_check => \&catalog_status_threshold, 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 ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"filter-msg:s" => { name => 'filter_msg' }, "filter-msg:s" => { name => 'filter_msg' },
"warning-status:s" => { name => 'warning_status', default => '%{severity} =~ /minor|warning/i' }, "warning-status:s" => { name => 'warning_status', default => '%{severity} =~ /minor|warning/i' },
"critical-status:s" => { name => 'critical_status', default => '%{severity} =~ /critical|major/i' }, "critical-status:s" => { name => 'critical_status', default => '%{severity} =~ /critical|major/i' },
"memory" => { name => 'memory' }, "memory" => { name => 'memory' },
}); });
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Date::Parse', centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Date::Parse',
error_msg => "Cannot load module 'Date::Parse'."); error_msg => "Cannot load module 'Date::Parse'.");
$self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self; return $self;
@ -92,70 +93,76 @@ sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::check_options(%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})) { if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->check_options(%options); $self->{statefile_cache}->check_options(%options);
} }
} }
my %map_severity = (0 => 'indeterminate', 1 => 'critical', 2 => 'major', 3 => 'minor', my %map_severity = (0 => 'indeterminate',
4 => 'warning', 5 => 'cleared', 6 => 'notify'); 1 => 'critical',
2 => 'major',
3 => 'minor',
4 => 'warning',
5 => 'cleared',
6 => 'notify');
my $mapping = { my $mapping = {
msgSourceName => { oid => '.1.3.6.1.4.1.23916.3.1.4.1.3' }, 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' }, 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 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 }, msgSeverity => { oid => '.1.3.6.1.4.1.23916.3.1.4.1.13', map => \%map_severity },
}; };
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{alarms}->{global} = { alarm => {} }; $self->{alarms}->{global} = { alarm => {} };
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ my $snmp_result = $options{snmp}->get_multiple_table(oids => [
{ oid => $mapping->{msgSourceName}->{oid} }, { oid => $mapping->{msgSourceName}->{oid} },
{ oid => $mapping->{msgText}->{oid} }, { oid => $mapping->{msgText}->{oid} },
{ oid => $mapping->{msgGenerationTime}->{oid} }, { oid => $mapping->{msgGenerationTime}->{oid} },
{ oid => $mapping->{msgSeverity}->{oid} }, { oid => $mapping->{msgSeverity}->{oid} },
], return_type => 1); ],
return_type => 1);
my $last_time; my $last_time;
if (defined($self->{option_results}->{memory})) { 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'); $last_time = $self->{statefile_cache}->get(name => 'last_time');
} }
my ($i, $current_time) = (1, time()); my ($i, $current_time) = (1, time());
foreach my $oid (keys %{$snmp_result}) { foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping->{msgSeverity}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{msgSeverity}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
my $create_time = Date::Parse::str2time($result->{msgGenerationTime}); my $create_time = Date::Parse::str2time($result->{msgGenerationTime});
if (!defined($create_time)) { if (!defined($create_time)) {
$self->{output}->output_add(severity => 'UNKNOWN', $self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't Parse date '" . $result->{msgGenerationTime} . "'"); short_msg => "Can't Parse date '" . $result->{msgGenerationTime} . "'");
next; next;
} }
next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $create_time); 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 '' && if (defined($self->{option_results}->{filter_msg}) && $self->{option_results}->{filter_msg} ne '' &&
$result->{msgText} !~ /$self->{option_results}->{filter_msg}/) { $result->{msgText} !~ /$self->{option_results}->{filter_msg}/) {
$self->{output}->output_add(long_msg => "skipping '" . $result->{msgText} . "': no matching filter.", debug => 1); $self->{output}->output_add(long_msg => "skipping '" . $result->{msgText} . "': no matching filter.", debug => 1);
next; next;
} }
my $diff_time = $current_time - $create_time; my $diff_time = $current_time - $create_time;
$self->{alarms}->{global}->{alarm}->{$i} = { %$result, since => $diff_time }; $self->{alarms}->{global}->{alarm}->{$i} = { %$result, since => $diff_time };
$i++; $i++;
} }
if (defined($self->{option_results}->{memory})) { if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->write(data => { last_time => $current_time }); $self->{statefile_cache}->write(data => { last_time => $current_time });
} }
} }
1; 1;
__END__ __END__
@ -166,21 +173,21 @@ Check alarms.
=over 8 =over 8
=item B<--filter-msg> =item C<--filter-msg>
Filter by message (can be a regexp). 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') 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} 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'). 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} You can use the following variables: %{severity}, %{text}, %{source}, %{since}
=item B<--memory> =item C<--memory>
Only check new alarms. Only check new alarms.

View File

@ -28,10 +28,10 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{version} = '0.1';
%{$self->{modes}} = ( %{$self->{modes}} = (
'alarms' => 'hardware::devices::video::appeartv::snmp::mode::alarms', 'alarms' => 'hardware::devices::video::appeartv::snmp::mode::alarms',
); );
return $self; return $self;
@ -43,6 +43,6 @@ __END__
=head1 PLUGIN DESCRIPTION =head1 PLUGIN DESCRIPTION
Check AppeartTV in SNMP. Check AppearTV in SNMP.
=cut =cut

View File

@ -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;

View File

@ -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

View File

@ -21,6 +21,7 @@ api.meraki.com
--api-token --api-token
--api-username --api-username
--api-version --api-version
AppearTV
ASAM ASAM
Avigilon Avigilon
Avocent Avocent