| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::MadEye::Util; |
|
2
|
2
|
|
|
2
|
|
13
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
83
|
|
|
3
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
85
|
|
|
4
|
2
|
|
|
2
|
|
14
|
use base qw/Exporter/; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
229
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw/timeout get_schema_from_pod context snmp_session/; |
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
4102
|
use Sys::Syslog qw/:DEFAULT/; |
|
|
2
|
|
|
|
|
51865
|
|
|
|
2
|
|
|
|
|
530
|
|
|
9
|
2
|
|
|
2
|
|
2809
|
use Pod::POM (); |
|
|
2
|
|
|
|
|
76815
|
|
|
|
2
|
|
|
|
|
54
|
|
|
10
|
2
|
|
|
2
|
|
20
|
use List::Util qw/first/; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
222
|
|
|
11
|
2
|
|
|
2
|
|
11
|
use YAML (); |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
36
|
|
|
12
|
2
|
|
|
2
|
|
2328
|
use Time::HiRes qw/gettimeofday/; |
|
|
2
|
|
|
|
|
3859
|
|
|
|
2
|
|
|
|
|
9
|
|
|
13
|
2
|
|
|
2
|
|
3202
|
use Net::SNMP; |
|
|
2
|
|
|
|
|
168698
|
|
|
|
2
|
|
|
|
|
1528
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
0
|
|
|
0
|
0
|
0
|
sub context () { App::MadEye->context } ## no critic. |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub timeout($$&) { ## no critic. |
|
18
|
0
|
|
|
0
|
0
|
0
|
my ( $secs, $msg, $code ) = @_; |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
0
|
context->log(debug => "run timer: '$msg', $secs");; |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
my $last_alarm = 0; |
|
23
|
0
|
|
|
|
|
0
|
my $err; |
|
24
|
0
|
|
|
|
|
0
|
eval { |
|
25
|
0
|
|
|
0
|
|
0
|
local $SIG{ALRM} = sub { die "Time out error: $msg" }; |
|
|
0
|
|
|
|
|
0
|
|
|
26
|
0
|
|
|
|
|
0
|
$last_alarm = alarm $secs; |
|
27
|
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
my $start_time = gettimeofday(); |
|
29
|
0
|
|
|
|
|
0
|
$code->(); |
|
30
|
0
|
|
|
|
|
0
|
context->log('debug' => "stopwatch: " . (gettimeofday() - $start_time)); |
|
31
|
|
|
|
|
|
|
}; |
|
32
|
0
|
0
|
|
|
|
0
|
if ($@) { |
|
33
|
0
|
|
|
|
|
0
|
$err = $@; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
context->log('error' => $err); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
0
|
|
|
|
|
0
|
alarm $last_alarm; # restore |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
return $err; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_schema_from_pod { |
|
43
|
2
|
|
|
2
|
0
|
5
|
my $target = shift; |
|
44
|
2
|
|
33
|
|
|
12
|
my $proto = ref $target || $target; |
|
45
|
|
|
|
|
|
|
|
|
46
|
2
|
|
|
|
|
21
|
my $parser = Pod::POM->new; |
|
47
|
2
|
|
|
|
|
74
|
my $pom = $parser->parse(Class::Inspector->resolved_filename($proto)); |
|
48
|
2
|
50
|
|
4
|
|
4044
|
if (my $schema_node = first { $_->title eq 'SCHEMA' } $pom->head1) { |
|
|
4
|
|
|
|
|
227
|
|
|
49
|
2
|
|
|
|
|
122
|
my $schema_content = $schema_node->content; |
|
50
|
2
|
|
|
|
|
32
|
$schema_content =~ s/^ //gm; |
|
51
|
2
|
|
|
|
|
107
|
my $schema = YAML::Load($schema_content); |
|
52
|
2
|
|
|
|
|
39572
|
return $schema; |
|
53
|
|
|
|
|
|
|
} else { |
|
54
|
0
|
|
|
|
|
|
return; # 404 schema not found. |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub snmp_session { |
|
59
|
0
|
|
|
0
|
0
|
|
my ($agent, $host, $callback, ) = @_; |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
my $community = $agent->config->{config}->{community} or die "missing community"; |
|
62
|
0
|
|
0
|
|
|
|
my $port = $agent->config->{config}->{port} || 161; |
|
63
|
0
|
|
0
|
|
|
|
my $timeout = $agent->config->{config}->{timeout} || 10; |
|
64
|
0
|
|
0
|
|
|
|
my $retries = $agent->config->{config}->{retries} || 1; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my ($session, $error) = Net::SNMP->session( |
|
67
|
|
|
|
|
|
|
-hostname => $host, |
|
68
|
|
|
|
|
|
|
-community => $community, |
|
69
|
|
|
|
|
|
|
-port => $port, |
|
70
|
|
|
|
|
|
|
-timeout => $timeout, |
|
71
|
|
|
|
|
|
|
-retries => $retries, |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if (not defined($session)) { |
|
75
|
0
|
|
|
|
|
|
die "ERROR: $error.\n"; |
|
76
|
|
|
|
|
|
|
} else { |
|
77
|
0
|
|
|
|
|
|
my $response = $callback->($session); |
|
78
|
0
|
|
|
|
|
|
$session->close(); |
|
79
|
0
|
|
|
|
|
|
return $response; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |