Debian Codegraph @

src/hardware/devices/gorgy/ntpserver/snmp/mode/globalstatus.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::gorgy::ntpserver::snmp::mode::globalstatus;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
29
30 sub custom_sync_status_output {
31 my ($self, %options) = @_;
32
33 my $msg = 'Current synchronization status : ' . $self->{result_values}->{sync_status};
34 return $msg;
35 }
36
37 sub custom_timebase_status_output {
38 my ($self, %options) = @_;
39
40 my $msg = 'Internal time base status : ' . $self->{result_values}->{timebase_status};
41 return $msg;
42 }
43
44 sub custom_status_calc {
45 my ($self, %options) = @_;
46
47 $self->{result_values}->{$options{extra_options}->{label_ref}} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}};
48 $self->{result_values}->{label} = $options{extra_options}->{label_ref};
49 return 0;
50 }
51
52 sub set_counters {
53 my ($self, %options) = @_;
54
55 $self->{maps_counters_type} = [
56 { name => 'global', type => 0, message_separator => ' - ' }
57 ];
58
59 $self->{maps_counters}->{global} = [
60 { label => 'sync-status', threshold => 0, set => {
61 key_values => [ { name => 'sync_status' } ],
62 closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => 'sync_status' },
63 closure_custom_output => $self->can('custom_sync_status_output'),
64 closure_custom_perfdata => sub { return 0; },
65 closure_custom_threshold_check => \&catalog_status_threshold,
66 }
67 },
68 { label => 'timebase-status', threshold => 0, set => {
69 key_values => [ { name => 'timebase_status' } ],
70 closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => 'timebase_status' },
71 closure_custom_output => $self->can('custom_timebase_status_output'),
72 closure_custom_perfdata => sub { return 0; },
73 closure_custom_threshold_check => \&catalog_status_threshold,
74 }
75 },
76 { label => 'ntp-requests', set => {
77 key_values => [ { name => 'ntp_requests', diff => 1 } ],
78 output_template => 'Number of ntp requests : %s',
79 perfdatas => [
80 { label => 'ntp_requests', value => 'ntp_requests', template => '%s',
81 min => 0 },
82 ],
83 }
84 },
85 ];
86 }
87
88 sub new {
89 my ($class, %options) = @_;
90 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
91 bless $self, $class;
92
93 $options{options}->add_options(arguments => {
94 'warning-sync-status:s' => { name => 'warning_sync_status', default => '%{sync_status} =~ /Running with autonomy|Free running/i' },
95 'critical-sync-status:s' => { name => 'critical_sync_status', default => '%{sync_status} =~ /Server locked|Never synchronized|Server not synchronized/i' },
96 'warning-timebase-status:s' => { name => 'warning_timebase_status', default => '%{timebase_status} =~ /^(?!(XO|XO OK|TCXO Precision < 2usec|OCXO Precision < 1usec)$)/i' },
97 'critical-timebase-status:s' => { name => 'critical_timebase_status', default => '%{timebase_status} =~ /^XO$/i' },
98 });
99
100 return $self;
101 }
102
103 sub check_options {
104 my ($self, %options) = @_;
105 $self->SUPER::check_options(%options);
106
107 $self->change_macros(macros => ['warning_sync_status', 'critical_sync_status', 'warning_timebase_status', 'critical_timebase_status']);
108 }
109
110 # timeBaseState values:
111 # XO Warming up...
112 # XO OK
113 # TCXO
114 # TCXO Precision > 25usec
115 # 2usec < TCXO Precision < 25usec
116 # TCXO Precision < 2usec
117 # OCXO Warming up...
118 # OCXO Precision > 20usec
119 # 1usec < OCXO Precision < 20usec
120 # OCXO Precision < 1usec
121 # XO
122
123 # currentSyncState values:
124 # Server locked
125 # Free running
126 # Never synchronized
127 # Server synchronized
128 # Running with autonomy
129 # Server not synchronized
130 # Computing synchronization
131
132 my $mapping = {
133 currentSyncState => { oid => '.1.3.6.1.4.1.8955.1.8.1.10' },
134 timeBaseState => { oid => '.1.3.6.1.4.1.8955.1.8.1.12' },
135 powerDownFlags => { oid => '.1.3.6.1.4.1.8955.1.8.1.20' },
136 ntpRequestsNumber => { oid => '.1.3.6.1.4.1.8955.1.8.2.3' },
137 };
138
139 sub manage_selection {
140 my ($self, %options) = @_;
141
142 my $snmp_result = $options{snmp}->get_leef(
143 oids => [
144 $mapping->{currentSyncState}->{oid} . '.0',
145 $mapping->{timeBaseState}->{oid} . '.0',
146 $mapping->{ntpRequestsNumber}->{oid} . '.0'
147 ],
148 nothing_quit => 1
149 );
150 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0');
151 $self->{global} = {
152 sync_status => $result->{currentSyncState},
153 timebase_status => $result->{timeBaseState},
154 ntp_requests => $result->{ntpRequestsNumber}
155 };
156
157 $self->{cache_name} = "gorgy_ntpserver_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
158 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
159 }
160
161 1;
162
163 __END__
164
165 =head1 MODE
166
167 Check ntp server status.
168
169 =over 8
170
171 =item B<--filter-counters>
172
173 Only display some counters (regexp can be used).
174 Example: --filter-counters='^sync-status$'
175
176 =item B<--warning-sync-status>
177
178 Define the conditions to match for the status to be WARNING (default: '%{sync_status} =~ /Running with autonomy|Free running/i').
179 You can use the following variables: %{sync_status}
180
181 =item B<--critical-sync-status>
182
183 Define the conditions to match for the status to be CRITICAL (default: '%{sync_status} =~ /Server locked|Never synchronized|Server not synchronized/i').
184 You can use the following variables: %{sync_status}
185
186 =item B<--warning-timebase-status>
187
188 Define the conditions to match for the status to be WARNING (default: '%{timebase_status} =~ /^(?!(XO|XO OK|TCXO Precision < 2usec|OCXO Precision < 1usec)$)/i').
189 You can use the following variables: %{timebase_status}
190
191 =item B<--critical-timebase-status>
192
193 Define the conditions to match for the status to be CRITICAL (default: '%{timebase_status} =~ /^XO$/i').
194 You can use the following variables: %{timebase_status}
195
196 =item B<--warning-*>
197
198 Warning threshold.
199 Can be: 'ntp-requests'.
200
201 =item B<--critical-*>
202
203 Critical threshold.
204 Can be: 'ntp-requests'.
205
206 =back
207
208 =cut