From 858366e1b27fa0b222b448f978d9a119f540815f Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 11 May 2020 14:51:11 +0200 Subject: [PATCH] update timelink --- .../timelinkmicro/tms6001/snmp/mode/alarm.pm | 104 ------------------ .../timelinkmicro/tms6001/snmp/mode/alarms.pm | 87 +++++++++++++++ .../tms6001/snmp/mode/antenna.pm | 95 +++++++++++----- .../tms6001/snmp/mode/frequency.pm | 86 ++++++--------- .../timelinkmicro/tms6001/snmp/mode/gnss.pm | 86 ++++++++++----- .../tms6001/snmp/mode/satellites.pm | 87 ++++++--------- .../timelinkmicro/tms6001/snmp/mode/time.pm | 85 ++++++-------- .../timelinkmicro/tms6001/snmp/plugin.pm | 17 ++- 8 files changed, 323 insertions(+), 324 deletions(-) delete mode 100644 hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm create mode 100644 hardware/devices/timelinkmicro/tms6001/snmp/mode/alarms.pm diff --git a/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm b/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm deleted file mode 100644 index 3f236e7d1..000000000 --- a/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm +++ /dev/null @@ -1,104 +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. -# -# Authors : Thomas Gourdin thomas.gourdin@gmail.com - -package hardware::devices::timelinkmicro::tms6001::snmp::mode::alarm; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.3.3.0'; - - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - my $exit = $self->{perfdata}->threshold_check(value => $value, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("There is %s alarm(s).", $value)); - - $self->{output}->perfdata_add(label => 'value', unit => undef, - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => undef, max => undef); - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check number of alarms - -=over 8 - -=item B<--warning> - -Threshold warning. - -=item B<--critical> - -Threshold critical. - -=back - -=cut diff --git a/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarms.pm b/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarms.pm new file mode 100644 index 000000000..d89a21330 --- /dev/null +++ b/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarms.pm @@ -0,0 +1,87 @@ +# +# Copyright 2020 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. +# +# Authors : Thomas Gourdin thomas.gourdin@gmail.com + +package hardware::devices::timelinkmicro::tms6001::snmp::mode::alarms; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'alarms.total.count', set => { + key_values => [ { name => 'alarms_count' } ], + output_template => 'current number of alarms: %s', + perfdatas => [ + { value => 'alarms_count_absolute', template => '%s', min => 0 } + ] + } + } + ]; +} + +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 => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_infoAlarmsCount = '.1.3.6.1.4.1.22641.100.3.3.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_infoAlarmsCount ], nothing_quit => 1); + + $self->{global} = { + alarms_count => $snmp_result->{$oid_infoAlarmsCount} + }; +} + +1; + +__END__ + +=head1 MODE + +Check alarms. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total'. + +=back + +=cut diff --git a/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm b/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm index e548c2920..ea0a94a19 100644 --- a/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm +++ b/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm @@ -1,5 +1,5 @@ # -# Copyright 2019 Centreon (http://www.centreon.com/) +# Copyright 2020 Centreon (http://www.centreon.com/) # # Centreon is a full-fledged industry-strength solution that meets # the needs in IT infrastructure and application monitoring for @@ -21,53 +21,73 @@ package hardware::devices::timelinkmicro::tms6001::snmp::mode::antenna; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return 'antenna status: ' . $self->{result_values}->{status}; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + } + ]; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /shorted/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /notConnected/i' } + }); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); } -sub run { +my $mapping_status = { + C => 'connected', + S => 'shorted/poweroff', + N => 'notConnected' +}; + +sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.4.1.4.0'; + my $oid_tsGNSSAntenna = '.1.3.6.1.4.1.22641.100.4.1.4.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_tsGNSSAntenna ], nothing_quit => 1); - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - if ($value eq 'C') { - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("Antenna is connected")); - } elsif ($value eq 'S') { - $self->{output}->output_add(severity => 'WARNING', - short_msg => sprintf("Antenna is shorted or powered off")); - } elsif ($value eq 'N') { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Antenna is not connected")); - } - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { + status => $mapping_status->{ $snmp_result->{$oid_tsGNSSAntenna} } + }; } 1; @@ -76,10 +96,25 @@ __END__ =head1 MODE -Check antenna status +Check antenna. =over 8 +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /shorted/i'). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /notConnected/i'). +Can used special variables like: %{status} + =back =cut diff --git a/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm b/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm index e443c5a7d..11072dd37 100644 --- a/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm +++ b/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm @@ -1,5 +1,5 @@ # -# Copyright 2019 Centreon (http://www.centreon.com/) +# Copyright 2020 Centreon (http://www.centreon.com/) # # Centreon is a full-fledged industry-strength solution that meets # the needs in IT infrastructure and application monitoring for @@ -21,65 +21,52 @@ package hardware::devices::timelinkmicro::tms6001::snmp::mode::frequency; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'frequency-quality', nlabel => 'generation.frequency.quality.count', set => { + key_values => [ { name => 'qual_frequency' } ], + output_template => 'quality of frequency generation: %s', + perfdatas => [ + { value => 'qual_frequency_absolute', template => '%s' } + ] + } + } + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + + $options{options}->add_options(arguments => { + }); return $self; } -sub check_options { +sub manage_selection { 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(); - } - + my $oid_infoQualFreq = '.1.3.6.1.4.1.22641.100.3.6.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_infoQualFreq ], nothing_quit => 1); + + $self->{global} = { + qual_frequency => $snmp_result->{$oid_infoQualFreq} + }; } -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.3.6.0'; - - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - my $exit = $self->{perfdata}->threshold_check(value => $value, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Quality of frequency generation is %s.", $value)); - - $self->{output}->perfdata_add(label => 'value', unit => undef, - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => undef, max => undef); - - $self->{output}->display(); - $self->{output}->exit(); -} 1; @@ -91,13 +78,10 @@ Check quality of frequency generation =over 8 -=item B<--warning> +=item B<--warning-*> B<--critical-*> -Threshold warning. - -=item B<--critical> - -Threshold critical. +Thresholds. +Can be: 'frequency-quality'. =back diff --git a/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm b/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm index 666fff461..db5c06768 100644 --- a/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm +++ b/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm @@ -1,5 +1,5 @@ # -# Copyright 2019 Centreon (http://www.centreon.com/) +# Copyright 2020 Centreon (http://www.centreon.com/) # # Centreon is a full-fledged industry-strength solution that meets # the needs in IT infrastructure and application monitoring for @@ -21,50 +21,67 @@ package hardware::devices::timelinkmicro::tms6001::snmp::mode::gnss; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return 'GNSS status: ' . $self->{result_values}->{status}; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + } + ]; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /nominal/i' } + }); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); } -sub run { +sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.4.1.2.0'; + my $oid_tsGNSSStatus = '.1.3.6.1.4.1.22641.100.4.1.2.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_tsGNSSStatus ], nothing_quit => 1); - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - if ($value eq 'Nominal') { - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("GNSS status is $value")); - } else { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("GNSS status is $value")); - } - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { + status => lc($snmp_result->{$oid_tsGNSSStatus}) + }; } 1; @@ -73,10 +90,25 @@ __END__ =head1 MODE -Check GNSS state +Check GNSS. =over 8 +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /nominal/i'). +Can used special variables like: %{status} + =back =cut diff --git a/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm b/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm index 51635f0d2..533a72e85 100644 --- a/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm +++ b/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm @@ -1,5 +1,5 @@ # -# Copyright 2019 Centreon (http://www.centreon.com/) +# Copyright 2020 Centreon (http://www.centreon.com/) # # Centreon is a full-fledged industry-strength solution that meets # the needs in IT infrastructure and application monitoring for @@ -21,64 +21,50 @@ package hardware::devices::timelinkmicro::tms6001::snmp::mode::satellites; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'seen', nlabel => 'satellites.seen.count', set => { + key_values => [ { name => 'sat_count' } ], + output_template => 'current number of satellites seen: %s', + perfdatas => [ + { value => 'sat_count_absolute', template => '%s', min => 0 } + ] + } + } + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + + $options{options}->add_options(arguments => { + }); return $self; } -sub check_options { +sub manage_selection { 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(); - } - -} + my $oid_tsGNSSSatCount = '.1.3.6.1.4.1.22641.100.4.1.8.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_tsGNSSSatCount ], nothing_quit => 1); -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.4.1.8.0'; - - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - my $exit = $self->{perfdata}->threshold_check(value => $value, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Number of satellites seen is %s.", $value)); - - $self->{output}->perfdata_add(label => 'value', unit => undef, - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => undef, max => undef); - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { + sat_count => $snmp_result->{$oid_tsGNSSSatCount} + }; } 1; @@ -87,17 +73,14 @@ __END__ =head1 MODE -Check number of satellites seen +Check satellites. =over 8 -=item B<--warning> +=item B<--warning-*> B<--critical-*> -Threshold warning. - -=item B<--critical> - -Threshold critical. +Thresholds. +Can be: 'seen'. =back diff --git a/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm b/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm index f061e0294..c9c5b06f8 100644 --- a/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm +++ b/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm @@ -21,64 +21,50 @@ package hardware::devices::timelinkmicro::tms6001::snmp::mode::time; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'time-quality', nlabel => 'generation.time.quality.count', set => { + key_values => [ { name => 'qual_time' } ], + output_template => 'quality of time generation: %s', + perfdatas => [ + { value => 'qual_time_absolute', template => '%s' } + ] + } + } + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + + $options{options}->add_options(arguments => { + }); return $self; } -sub check_options { +sub manage_selection { 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(); - } - -} + my $oid_infoQualTime = '.1.3.6.1.4.1.22641.100.3.5.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_infoQualTime ], nothing_quit => 1); -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.3.5.0'; - - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - my $exit = $self->{perfdata}->threshold_check(value => $value, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Quality of time generation is %s.", $value)); - - $self->{output}->perfdata_add(label => 'value', unit => undef, - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => undef, max => undef); - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { + qual_time => $snmp_result->{$oid_infoQualTime} + }; } 1; @@ -87,17 +73,14 @@ __END__ =head1 MODE -Check quality of time generation +Check quality of time generation. =over 8 -=item B<--warning> +=item B<--warning-*> B<--critical-*> -Threshold warning. - -=item B<--critical> - -Threshold critical. +Thresholds. +Can be: 'time-quality'. =back diff --git a/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm b/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm index 799f11780..b4bda3092 100644 --- a/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm +++ b/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm @@ -31,15 +31,14 @@ sub new { bless $self, $class; $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'frequency' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::frequency', - 'time' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::time', - 'satellites' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::satellites', - 'antenna' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::antenna', - 'gnss' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::gnss', - 'alarms' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::alarm', - - ); + $self->{modes} = { + 'alarms' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::alarms', + 'antenna' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::antenna', + 'frequency' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::frequency', + 'gnss' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::gnss', + 'satellites' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::satellites', + 'time' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::time' + }; return $self; }