line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix::Check::Time; |
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Zabbix::Check::Systemd - Zabbix check for system time |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
version 1.10 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Zabbix check for system time |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.time.epoch,/usr/bin/perl -MZabbix::Check::Time -e_epoch |
15
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.time.zone,/usr/bin/perl -MZabbix::Check::Time -e_zone |
16
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.time.ntp_offset[*],/usr/bin/perl -MZabbix::Check::Time -e_ntp_offset -- $1 $2 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head3 epoch |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
gets system time epoch in seconds |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head3 zone |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
gets system time zone, eg: +0200 |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head3 ntp_offset $1 $2 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
gets system time difference by NTP server |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$1: I |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$2: I |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
1
|
|
|
1
|
|
749
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
36
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
37
|
1
|
|
|
1
|
|
6
|
no warnings qw(qw utf8); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
38
|
1
|
|
|
1
|
|
12
|
use v5.14; |
|
1
|
|
|
|
|
3
|
|
39
|
1
|
|
|
1
|
|
6
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
40
|
1
|
|
|
1
|
|
33
|
use POSIX; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
41
|
1
|
|
|
1
|
|
1970
|
use Net::NTP; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
42
|
1
|
|
|
1
|
|
3
|
use Lazy::Utils; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
52
|
|
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
1
|
|
4
|
use Zabbix::Check; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
141
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
BEGIN |
48
|
|
|
|
|
|
|
{ |
49
|
1
|
|
|
1
|
|
4
|
require Exporter; |
50
|
|
|
|
|
|
|
# set the version for version checking |
51
|
1
|
|
|
|
|
2
|
our $VERSION = '1.10'; |
52
|
|
|
|
|
|
|
# Inherit from Exporter to export functions and variables |
53
|
1
|
|
|
|
|
8
|
our @ISA = qw(Exporter); |
54
|
|
|
|
|
|
|
# Functions and variables which are exported by default |
55
|
1
|
|
|
|
|
2
|
our @EXPORT = qw(_epoch _zone _ntp_offset); |
56
|
|
|
|
|
|
|
# Functions and variables which can be optionally exported |
57
|
1
|
|
|
|
|
209
|
our @EXPORT_OK = qw(); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _epoch |
62
|
|
|
|
|
|
|
{ |
63
|
0
|
|
|
0
|
|
|
my $result = time(); |
64
|
0
|
|
|
|
|
|
print $result; |
65
|
0
|
|
|
|
|
|
return $result; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _zone |
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
0
|
|
|
my $result = strftime("%z", gmtime()); |
71
|
0
|
|
|
|
|
|
print $result; |
72
|
0
|
|
|
|
|
|
return $result; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _ntp_offset |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
0
|
|
|
my ($server, $port) = map(zbxDecode($_), @ARGV); |
78
|
0
|
0
|
|
|
|
|
$server = "pool.ntp.org" unless $server; |
79
|
0
|
|
|
|
|
|
my $result = ""; |
80
|
0
|
|
|
|
|
|
my %ntp; |
81
|
0
|
|
|
|
|
|
for (1..5) |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
|
|
|
|
|
eval { %ntp = get_ntp_response($server, $port) }; |
|
0
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
$result = sprintf("%.3f", $ntp{Offset}) if defined $ntp{Offset}; |
85
|
0
|
0
|
|
|
|
|
last unless $result eq ""; |
86
|
0
|
|
|
|
|
|
sleep(1); |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
print $result; |
89
|
0
|
|
|
|
|
|
return $result; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
__END__ |