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.11 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Zabbix check for system time |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
1
|
|
|
1
|
|
824
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
16
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
17
|
1
|
|
|
1
|
|
9
|
use v5.10.1; |
|
1
|
|
|
|
|
3
|
|
18
|
1
|
|
|
1
|
|
327
|
use POSIX; |
|
1
|
|
|
|
|
5135
|
|
|
1
|
|
|
|
|
5
|
|
19
|
1
|
|
|
1
|
|
3251
|
use Net::NTP; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
72
|
|
20
|
1
|
|
|
1
|
|
10
|
use Lazy::Utils; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
147
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
9
|
use Zabbix::Check; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
150
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
BEGIN |
26
|
|
|
|
|
|
|
{ |
27
|
1
|
|
|
1
|
|
10
|
require Exporter; |
28
|
1
|
|
|
|
|
3
|
our $VERSION = '1.11'; |
29
|
1
|
|
|
|
|
15
|
our @ISA = qw(Exporter); |
30
|
1
|
|
|
|
|
4
|
our @EXPORT = qw(_epoch _zone _ntp_offset); |
31
|
1
|
|
|
|
|
261
|
our @EXPORT_OK = qw(); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _epoch |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
0
|
|
|
my $result = time(); |
38
|
0
|
|
|
|
|
|
print $result; |
39
|
0
|
|
|
|
|
|
return $result; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _zone |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
0
|
|
|
my $result = strftime("%z", gmtime()); |
45
|
0
|
|
|
|
|
|
print $result; |
46
|
0
|
|
|
|
|
|
return $result; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _ntp_offset |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
0
|
|
|
my ($server, $port) = map(zbx_decode($_), @ARGV); |
52
|
0
|
0
|
|
|
|
|
$server = "pool.ntp.org" unless $server; |
53
|
0
|
|
|
|
|
|
my $result = ""; |
54
|
0
|
|
|
|
|
|
my %ntp; |
55
|
0
|
|
|
|
|
|
for (1..5) |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
|
|
|
eval { %ntp = get_ntp_response($server, $port) }; |
|
0
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
$result = sprintf("%.3f", $ntp{Offset}) if defined $ntp{Offset}; |
59
|
0
|
0
|
|
|
|
|
last unless $result eq ""; |
60
|
0
|
|
|
|
|
|
sleep(1); |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
print $result; |
63
|
0
|
|
|
|
|
|
return $result; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
__END__ |