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
|
|
1579
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
16
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
17
|
1
|
|
|
1
|
|
14
|
use v5.10.1; |
|
1
|
|
|
|
|
3
|
|
18
|
1
|
|
|
1
|
|
481
|
use POSIX; |
|
1
|
|
|
|
|
6176
|
|
|
1
|
|
|
|
|
7
|
|
19
|
1
|
|
|
1
|
|
2866
|
use Net::NTP; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
20
|
1
|
|
|
1
|
|
5
|
use Lazy::Utils; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
93
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
5
|
use Zabbix::Check; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
126
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
BEGIN |
26
|
|
|
|
|
|
|
{ |
27
|
1
|
|
|
1
|
|
9
|
require Exporter; |
28
|
1
|
|
|
|
|
4
|
our $VERSION = '1.11'; |
29
|
1
|
|
|
|
|
17
|
our @ISA = qw(Exporter); |
30
|
1
|
|
|
|
|
4
|
our @EXPORT = qw(_epoch _zone _ntp_offset); |
31
|
1
|
|
|
|
|
284
|
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__ |