Debian Codegraph @

src/hardware/devices/masterclock/ntp100gps/snmp/mode/ntpperformance.pm

raw
1 #
2 # Copyright 2024 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package hardware::devices::masterclock::ntp100gps::snmp::mode::ntpperformance;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = sprintf("Leap : '%s'",
33 $self->{result_values}->{leap});
34
35 return $msg;
36 }
37
38 sub custom_status_calc {
39 my ($self, %options) = @_;
40
41 $self->{result_values}->{leap} = $options{new_datas}->{$self->{instance} . '_leap'};
42
43 return 0;
44 }
45
46 sub set_counters {
47 my ($self, %options) = @_;
48
49 $self->{maps_counters_type} = [
50 { name => 'global', type => 0 },
51 ];
52
53 $self->{maps_counters}->{global} = [
54 { label => 'status', set => {
55 key_values => [ { name => 'leap' } ],
56 closure_custom_calc => $self->can('custom_status_calc'),
57 closure_custom_output => $self->can('custom_status_output'),
58 closure_custom_perfdata => sub { return 0; },
59 closure_custom_threshold_check => \&catalog_status_threshold,
60 }
61 },
62 { label => 'stratum-level', set => {
63 key_values => [ { name => 'stratum_level' } ],
64 output_template => 'Stratum level : %d',
65 perfdatas => [
66 { label => 'stratum_level', value => 'stratum_level', template => '%d',
67 min => 0, max => 16 },
68 ],
69 }
70 },
71 { label => 'precision', set => {
72 key_values => [ { name => 'precision' } ],
73 output_template => 'Precision : %s seconds',
74 perfdatas => [
75 { label => 'precision', value => 'precision', template => '%s',
76 min => 0, unit => "seconds" },
77 ],
78 }
79 },
80 { label => 'poll-interval', set => {
81 key_values => [ { name => 'poll_interval' } ],
82 output_template => 'Poll interval : %d seconds',
83 perfdatas => [
84 { label => 'poll_interval', value => 'poll_interval', template => '%d',
85 min => 0, unit => "seconds" },
86 ],
87 }
88 },
89 ];
90 }
91
92 sub new {
93 my ($class, %options) = @_;
94 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
95 bless $self, $class;
96
97 $options{options}->add_options(arguments =>
98 {
99 "warning-status:s" => { name => 'warning_status', default => '%{health} !~ /No leap second today/' },
100 "critical-status:s" => { name => 'critical_status', default => '' },
101 });
102
103 return $self;
104 }
105
106 sub check_options {
107 my ($self, %options) = @_;
108 $self->SUPER::check_options(%options);
109
110 $self->change_macros(macros => ['warning_status', 'critical_status']);
111 }
112
113 sub manage_selection {
114 my ($self, %options) = @_;
115
116 my $oid_ntp_leap_id = ".1.3.6.1.4.1.45561.1.1.1.4.0";
117 my $oid_ntp_stratum_level = ".1.3.6.1.4.1.45561.1.1.1.5.0";
118 my $oid_ntp_precision = ".1.3.6.1.4.1.45561.1.1.1.6.0";
119 my $oid_ntp_poll_interval = ".1.3.6.1.4.1.45561.1.1.1.11.0";
120
121 my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_ntp_leap_id, $oid_ntp_stratum_level, $oid_ntp_precision, $oid_ntp_poll_interval ]);
122
123 $self->{global} = {
124 leap => $snmp_result->{$oid_ntp_leap_id},
125 stratum_level => $snmp_result->{$oid_ntp_stratum_level},
126 precision => (2 ** $snmp_result->{$oid_ntp_precision}),
127 poll_interval => $snmp_result->{$oid_ntp_poll_interval},
128 };
129 }
130
131 1;
132
133 __END__
134
135 =head1 MODE
136
137 Check NTP performances
138
139 =over 8
140
141 =item B<--warning-status>
142
143 Define the conditions to match for the status to be WARNING (default: '%{health} !~ /No leap second today/')
144 You can use the following variables: %{leap}
145
146 =item B<--critical-status>
147
148 Define the conditions to match for the status to be CRITICAL (default: '')
149 You can use the following variables: %{health}
150
151 =item B<--warning-*>
152
153 Warning threshold. Can be : 'stratum-level', 'precision', 'poll-interval'
154
155 =item B<--critical-*>
156
157 Critical threshold. Can be : 'stratum-level', 'precision', 'poll-interval'
158
159 =back
160
161 =cut