Debian Codegraph @

src/hardware/ups/apc/snmp/mode/ntp.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::ups::apc::snmp::mode::ntp;
22
23 use base qw(snmp_standard::mode::ntp);
24
25 use strict;
26 use warnings;
27 use Date::Parse;
28
29 sub new {
30 my ($class, %options) = @_;
31 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
32 bless $self, $class;
33
34 return $self;
35 }
36
37 sub get_target_time {
38 my ($self, %options) = @_;
39
40 my $oid_mconfigClockDate = '.1.3.6.1.4.1.318.2.1.6.1.0';
41 my $oid_mconfigClockTime = '.1.3.6.1.4.1.318.2.1.6.2.0';
42 my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_mconfigClockDate, $oid_mconfigClockTime ], nothing_quit => 1);
43
44 my $epoch = Date::Parse::str2time($snmp_result->{$oid_mconfigClockDate} . ' ' . $snmp_result->{$oid_mconfigClockTime});
45 return $self->get_from_epoch(date => $epoch);
46 }
47
48 1;
49
50 __END__
51
52 =head1 MODE
53
54 Check time offset of server with ntp server. Use local time if ntp-host option is not set.
55 SNMP gives a date with second precision (no milliseconds). Time precision is not very accurate.
56 Use threshold with (+-) 2 seconds offset (minimum).
57
58 =over 8
59
60 =item B<--warning-offset>
61
62 Time offset warning threshold (in seconds).
63
64 =item B<--critical-offset>
65
66 Time offset critical Threshold (in seconds).
67
68 =item B<--ntp-hostname>
69
70 Set the ntp hostname (if not set, localtime is used).
71
72 =item B<--ntp-port>
73
74 Set the ntp port (default: 123).
75
76 =item B<--timezone>
77
78 Set the timezone of distant server. For Windows, you need to set it.
79 Can use format: 'Europe/London' or '+0100'.
80
81 =back
82
83 =cut