line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::GLPlugin::SNMP::TableItem; |
2
|
|
|
|
|
|
|
our @ISA = qw(Monitoring::GLPlugin::SNMP::CSF Monitoring::GLPlugin::TableItem Monitoring::GLPlugin::SNMP); |
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
38
|
|
|
2
|
|
|
|
|
1985
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub ensure_index { |
6
|
0
|
|
|
0
|
0
|
|
my ($self, $key) = @_; |
7
|
0
|
|
0
|
|
|
|
$self->{$key} ||= $self->{flat_indices}; |
8
|
|
|
|
|
|
|
} |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub unhex_ip { |
11
|
0
|
|
|
0
|
0
|
|
my ($self, $value) = @_; |
12
|
0
|
0
|
0
|
|
|
|
if ($value && $value =~ /^0x(\w{8})/) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
13
|
0
|
|
|
|
|
|
$value = join(".", unpack "C*", pack "H*", $1); |
14
|
|
|
|
|
|
|
} elsif ($value && $value =~ /^0x(\w{2} \w{2} \w{2} \w{2})/) { |
15
|
0
|
|
|
|
|
|
$value = $1; |
16
|
0
|
|
|
|
|
|
$value =~ s/ //g; |
17
|
0
|
|
|
|
|
|
$value = join(".", unpack "C*", pack "H*", $value); |
18
|
|
|
|
|
|
|
} elsif ($value && $value =~ /^([A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2})/i) { |
19
|
0
|
|
|
|
|
|
$value = $1; |
20
|
0
|
|
|
|
|
|
$value =~ s/ //g; |
21
|
0
|
|
|
|
|
|
$value = join(".", unpack "C*", pack "H*", $value); |
22
|
|
|
|
|
|
|
} elsif ($value && unpack("H8", $value) =~ /(\w{2})(\w{2})(\w{2})(\w{2})/) { |
23
|
0
|
|
|
|
|
|
$value = join(".", map { hex($_) } ($1, $2, $3, $4)); |
|
0
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
} |
25
|
0
|
|
|
|
|
|
return $value; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _compact_v6 { |
29
|
0
|
|
|
0
|
|
|
my ($self, $addr) = @_; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my @o = split /:/, $addr; |
32
|
0
|
0
|
0
|
|
|
|
return $addr unless @o and grep { $_ =~ m/^0+$/ } @o; |
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my @candidates = (); |
35
|
0
|
|
|
|
|
|
my $start = undef; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
for my $i (0 .. $#o) { |
38
|
0
|
0
|
|
|
|
|
if (defined $start) { |
39
|
0
|
0
|
|
|
|
|
if ($o[$i] !~ m/^0+$/) { |
40
|
0
|
|
|
|
|
|
push @candidates, [ $start, $i - $start ]; |
41
|
0
|
|
|
|
|
|
$start = undef; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} else { |
44
|
0
|
0
|
|
|
|
|
$start = $i if $o[$i] =~ m/^0+$/; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
push @candidates, [$start, 8 - $start] if defined $start; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $l = (sort { $b->[1] <=> $a->[1] } @candidates)[0]; |
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
return $addr unless defined $l; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
$addr = $l->[0] == 0 ? '' : join ':', @o[0 .. $l->[0] - 1]; |
55
|
0
|
|
|
|
|
|
$addr .= '::'; |
56
|
0
|
|
|
|
|
|
$addr .= join ':', @o[$l->[0] + $l->[1] .. $#o]; |
57
|
0
|
|
|
|
|
|
$addr =~ s/(^|:)0{1,3}/$1/g; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return $addr; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub unhex_ipv6 { |
63
|
0
|
|
|
0
|
0
|
|
my ($self, $value) = @_; |
64
|
0
|
0
|
0
|
|
|
|
if ($value && $value =~ /^0x(\w{32})/) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$value = join(":", unpack "C*", pack "H*", $1); |
66
|
|
|
|
|
|
|
} elsif ($value && $value =~ /^0x(\w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2})/) { |
67
|
0
|
|
|
|
|
|
$value = $1; |
68
|
0
|
|
|
|
|
|
$value =~ s/ //g; |
69
|
0
|
|
|
|
|
|
$value = join(":", unpack "C*", pack "H*", $value); |
70
|
|
|
|
|
|
|
} elsif ($value && $value =~ /^([A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2})/i) { |
71
|
0
|
|
|
|
|
|
$value = $1; |
72
|
0
|
|
|
|
|
|
$value =~ s/ //g; |
73
|
0
|
|
|
|
|
|
$value = join(":", unpack "C*", pack "H*", $value); |
74
|
|
|
|
|
|
|
} elsif ($value && unpack("H32", $value) =~ /(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})/) { |
75
|
0
|
|
|
|
|
|
$value = join(":", $1, $2, $3, $4, $5, $6, $7, $8); |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
return $self->_compact_v6($value); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub unhex_mac { |
81
|
0
|
|
|
0
|
0
|
|
my ($self, $value) = @_; |
82
|
0
|
0
|
0
|
|
|
|
if ($value && $value =~ /^0x(\w{12})/) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
83
|
0
|
|
|
|
|
|
$value = join(".", unpack "C*", pack "H*", $1); |
84
|
|
|
|
|
|
|
} elsif ($value && $value =~ /^0x(\w{2}\s*\w{2}\s*\w{2}\s*\w{2}\s*\w{2}\s*\w{2})/) { |
85
|
0
|
|
|
|
|
|
$value = $1; |
86
|
0
|
|
|
|
|
|
$value =~ s/ //g; |
87
|
0
|
|
|
|
|
|
$value = join(":", unpack "C*", pack "H*", $value); |
88
|
|
|
|
|
|
|
} elsif ($value && unpack("H12", $value) =~ /(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})/) { |
89
|
0
|
|
|
|
|
|
$value = join(":", map { hex($_) } ($1, $2, $3, $4, $5, $6)); |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
return $value; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub unhex_octet_string { |
95
|
0
|
|
|
0
|
0
|
|
my ($self, $value) = @_; |
96
|
0
|
|
|
|
|
|
my $original = $value; |
97
|
0
|
|
|
|
|
|
$value =~ s/ //g; |
98
|
0
|
0
|
0
|
|
|
|
if ($value && $value =~ /^0x([0-9a-zA-Z]+)$/) { |
|
|
0
|
0
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$value = join("", unpack "A*", pack "H*", $1); |
100
|
|
|
|
|
|
|
} elsif ($value && $value =~ /^([0-9a-zA-Z]+)$/) { |
101
|
0
|
|
|
|
|
|
$value = join("", unpack "A*", pack "H*", $1); |
102
|
|
|
|
|
|
|
} else { |
103
|
0
|
|
|
|
|
|
$value = $original; |
104
|
|
|
|
|
|
|
} |
105
|
0
|
|
|
|
|
|
return $value; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |