Debian Codegraph @

src/hardware/devices/camera/hikvision/snmp/mode/time.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::camera::hikvision::snmp::mode::time;
22
23 use base qw(snmp_standard::mode::ntp);
24
25 use strict;
26 use warnings;
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
31 bless $self, $class;
32
33 return $self;
34 }
35
36 sub get_target_time {
37 my ($self, %options) = @_;
38
39 my $oid_sysTime = '.1.3.6.1.4.1.39165.1.19.0';
40 my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_sysTime ], nothing_quit => 1);
41
42 # format: "2019-11-18 20:13:17"
43 if ($snmp_result->{$oid_sysTime} !~ /^(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)/) {
44 $self->{output}->add_option_msg(short_msg => 'cannot parse date format: ' . $snmp_result->{$oid_sysTime});
45 $self->{output}->option_exit();
46 }
47
48 my $remote_date = [$1, $2, $3, $4, $5, $6];
49
50 my $timezone = 'UTC';
51 if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') {
52 $timezone = $self->{option_results}->{timezone};
53 }
54
55 my $tz = centreon::plugins::misc::set_timezone(name => $timezone);
56 my $dt = DateTime->new(
57 year => $remote_date->[0],
58 month => $remote_date->[1],
59 day => $remote_date->[2],
60 hour => $remote_date->[3],
61 minute => $remote_date->[4],
62 second => $remote_date->[5],
63 %$tz
64 );
65
66 return ($dt->epoch, $remote_date, $timezone);
67 }
68
69 1;
70
71 __END__
72
73 =head1 MODE
74
75 Check time offset of server with ntp server. Use local time if ntp-host option is not set.
76 SNMP gives a date with second precision (no milliseconds). Time precision is not very accurate.
77 Use threshold with (+-) 2 seconds offset (minimum).
78
79 =over 8
80
81 =item B<--warning-offset>
82
83 Time offset warning threshold (in seconds).
84
85 =item B<--critical-offset>
86
87 Time offset critical Threshold (in seconds).
88
89 =item B<--ntp-hostname>
90
91 Set the ntp hostname (if not set, localtime is used).
92
93 =item B<--ntp-port>
94
95 Set the ntp port (default: 123).
96
97 =item B<--timezone>
98
99 Set the timezone of distant server. For Windows, you need to set it.
100 Can use format: 'Europe/London' or '+0100'.
101
102 =back
103
104 =cut