+ add plugin gorgy ntp server snmp
This commit is contained in:
parent
7081ea59ca
commit
9b61ac8ee2
|
@ -0,0 +1,243 @@
|
|||
#
|
||||
# Copyright 2016 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 hardware::devices::gorgy::ntpserver::snmp::mode::globalstatus;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $instance_mode;
|
||||
|
||||
sub custom_status_threshold {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'ok';
|
||||
my $message;
|
||||
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($instance_mode->{option_results}->{'critical_' . $self->{result_values}->{label}}) && $instance_mode->{option_results}->{'critical_' . $self->{result_values}->{label}} ne '' &&
|
||||
eval "$instance_mode->{option_results}->{'critical_' . $self->{result_values}->{label}}") {
|
||||
$status = 'critical';
|
||||
} elsif (defined($instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label}}) && $instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label}} ne '' &&
|
||||
eval "$instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label}}") {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
sub custom_sync_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = 'Current synchronization status : ' . $self->{result_values}->{sync_status};
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_timebase_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = 'Internal time base status : ' . $self->{result_values}->{timebase_status};
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{$options{extra_options}->{label_ref}} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}};
|
||||
$self->{result_values}->{label} = $options{extra_options}->{label_ref};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, message_separator => ' - ' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'sync-status', threshold => 0, set => {
|
||||
key_values => [ { name => 'sync_status' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => 'sync_status' },
|
||||
closure_custom_output => $self->can('custom_sync_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
||||
}
|
||||
},
|
||||
{ label => 'timebase-status', threshold => 0, set => {
|
||||
key_values => [ { name => 'timebase_status' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => 'timebase_status' },
|
||||
closure_custom_output => $self->can('custom_timebase_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
||||
}
|
||||
},
|
||||
{ label => 'ntp-requests', set => {
|
||||
key_values => [ { name => 'ntp_requests', diff => 1 } ],
|
||||
output_template => 'Number of ntp requests : %s',
|
||||
perfdatas => [
|
||||
{ label => 'ntp_requests', value => 'ntp_requests_absolute', template => '%s',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning-sync-status:s" => { name => 'warning_sync_status', default => '%{sync_status} =~ /Running with autonomy|Free running/i' },
|
||||
"critical-sync-status:s" => { name => 'critical_sync_status', default => '%{sync_status} =~ /Server locked|Never synchronized|Server not synchronized/i' },
|
||||
"warning-timebase-status:s" => { name => 'warning_timebase_status', default => '%{timebase_status} =~ /^(?!(XO|XO OK|TCXO Precision < 2usec|OCXO Precision < 1usec)$)/i' },
|
||||
"critical-timebase-status:s" => { name => 'critical_timebase_status', default => '%{timebase_status} =~ /^XO$/i' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$instance_mode = $self;
|
||||
$self->change_macros();
|
||||
}
|
||||
|
||||
sub change_macros {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (('warning_sync_status', 'critical_sync_status', 'warning_timebase_status', 'critical_timebase_status')) {
|
||||
if (defined($self->{option_results}->{$_})) {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# timeBaseState values:
|
||||
# XO Warming up...
|
||||
# XO OK
|
||||
# TCXO
|
||||
# TCXO Precision > 25usec
|
||||
# 2usec < TCXO Precision < 25usec
|
||||
# TCXO Precision < 2usec
|
||||
# OCXO Warming up...
|
||||
# OCXO Precision > 20usec
|
||||
# 1usec < OCXO Precision < 20usec
|
||||
# OCXO Precision < 1usec
|
||||
# XO
|
||||
|
||||
# currentSyncState values:
|
||||
# Server locked
|
||||
# Free running
|
||||
# Never synchronized
|
||||
# Server synchronized
|
||||
# Running with autonomy
|
||||
# Server not synchronized
|
||||
# Computing synchronization
|
||||
|
||||
my $mapping = {
|
||||
currentSyncState => { oid => '.1.3.6.1.4.1.8955.1.8.1.10' },
|
||||
timeBaseState => { oid => '.1.3.6.1.4.1.8955.1.8.1.12' },
|
||||
powerDownFlags => { oid => '.1.3.6.1.4.1.8955.1.8.1.20' },
|
||||
ntpRequestsNumber => { oid => '.1.3.6.1.4.1.8955.1.8.2.3' },
|
||||
};
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $snmp_result = $options{snmp}->get_leef(oids => [
|
||||
$mapping->{currentSyncState}->{oid} . '.0',
|
||||
$mapping->{timeBaseState}->{oid} . '.0',
|
||||
$mapping->{powerDownFlags}->{oid} . '.0',
|
||||
$mapping->{ntpRequestsNumber}->{oid} . '.0',
|
||||
],
|
||||
nothing_quit => 1);
|
||||
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0');
|
||||
$self->{global} = { sync_status => $result->{currentSyncState},
|
||||
timebase_status => $result->{timeBaseState},
|
||||
ntp_requests => $result->{ntpRequestsNumber} };
|
||||
|
||||
$self->{cache_name} = "gorgy_ntpserver_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check ntp server status.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='^sync-status$'
|
||||
|
||||
=item B<--warning-sync-status>
|
||||
|
||||
Set warning threshold for status (Default: '%{sync_status} =~ /Running with autonomy|Free running/i').
|
||||
Can used special variables like: %{sync_status}
|
||||
|
||||
=item B<--critical-sync-status>
|
||||
|
||||
Set critical threshold for status (Default: '%{sync_status} =~ /Server locked|Never synchronized|Server not synchronized/i').
|
||||
Can used special variables like: %{sync_status}
|
||||
|
||||
=item B<--warning-timebase-status>
|
||||
|
||||
Set warning threshold for status (Default: '%{timebase_status} =~ /^(?!(XO|XO OK|TCXO Precision < 2usec|OCXO Precision < 1usec)$)/i').
|
||||
Can used special variables like: %{timebase_status}
|
||||
|
||||
=item B<--critical-timebase-status>
|
||||
|
||||
Set critical threshold for status (Default: '%{timebase_status} =~ /^XO$/i').
|
||||
Can used special variables like: %{timebase_status}
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'ntp-requests'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'ntp-requests'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,50 @@
|
|||
#
|
||||
# Copyright 2016 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 hardware::devices::gorgy::ntpserver::snmp::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_snmp);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
'global-status' => 'hardware::devices::gorgy::ntpserver::snmp::mode::globalstatus',
|
||||
'interfaces' => 'snmp_standard::mode::interfaces',
|
||||
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Gorgy ntp servers in SNMP.
|
||||
|
||||
=cut
|
Loading…
Reference in New Issue