line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::SNMP::Memory; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
21932
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
54
|
|
9
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
1617
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
117206
|
|
|
1
|
|
|
|
|
588
|
|
12
|
1
|
|
|
1
|
|
937
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
620
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Cisco::SNMP::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Cisco::SNMP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################## |
19
|
|
|
|
|
|
|
# Start Public Module |
20
|
|
|
|
|
|
|
################################################## |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _memOID { |
23
|
0
|
|
|
0
|
|
0
|
return '1.3.6.1.4.1.9.9.48.1.1.1' |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub memOIDs { |
27
|
2
|
|
|
2
|
1
|
10
|
return qw(Name Alternate Valid Used Free LargestFree Total) |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub memory_info { |
31
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
32
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my %ret; |
37
|
0
|
|
|
|
|
|
my @MEMKEYS = memOIDs(); |
38
|
|
|
|
|
|
|
# -1 because last key (Total) isn't an OID; rather, calculated from 2 other OIDs |
39
|
0
|
|
|
|
|
|
for my $oid (0..$#MEMKEYS-1) { |
40
|
0
|
|
|
|
|
|
$ret{$MEMKEYS[$oid]} = Cisco::SNMP::_snmpwalk($session, _memOID() . '.' . ($oid+2)); |
41
|
0
|
0
|
|
|
|
|
if (!defined $ret{$MEMKEYS[$oid]}) { |
42
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get memory `$MEMKEYS[$oid]' info"; |
43
|
|
|
|
|
|
|
return undef |
44
|
0
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my @MemInfo; |
48
|
0
|
|
|
|
|
|
for my $mem (0..$#{$ret{$MEMKEYS[0]}}) { |
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my %MemInfoHash; |
50
|
0
|
|
|
|
|
|
for (0..$#MEMKEYS) { |
51
|
0
|
0
|
|
|
|
|
if ($_ == 2) { |
|
|
0
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
$MemInfoHash{$MEMKEYS[$_]} = ($ret{$MEMKEYS[$_]}->[$mem] == 1) ? 'TRUE' : 'FALSE' |
53
|
|
|
|
|
|
|
} elsif ($_ == 6) { |
54
|
0
|
|
|
|
|
|
$MemInfoHash{$MEMKEYS[$_]} = $ret{$MEMKEYS[3]}->[$mem] + $ret{$MEMKEYS[4]}->[$mem] |
55
|
|
|
|
|
|
|
} else { |
56
|
0
|
|
|
|
|
|
$MemInfoHash{$MEMKEYS[$_]} = $ret{$MEMKEYS[$_]}->[$mem] |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
push @MemInfo, \%MemInfoHash |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
return bless \@MemInfo, $class |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
for (memOIDs()) { |
65
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_array_1('mem', $_) |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
253
|
|
69
|
|
|
|
|
|
|
# get_ direct |
70
|
|
|
|
|
|
|
my @OIDS = memOIDs(); |
71
|
|
|
|
|
|
|
# -1 because last key (Total) isn't an OID; rather, calculated from 2 other OIDs |
72
|
|
|
|
|
|
|
for my $o (0..$#OIDS-1) { |
73
|
|
|
|
|
|
|
*{"get_mem" . $OIDS[$o]} = sub { |
74
|
0
|
|
|
0
|
|
|
my $self = shift; |
75
|
0
|
|
|
|
|
|
my ($val) = @_; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = 0 } |
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $s = $self->session; |
79
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
80
|
|
|
|
|
|
|
varbindlist => [_memOID() . '.' . ($o+2) . '.' . $val] |
81
|
|
|
|
|
|
|
); |
82
|
0
|
|
|
|
|
|
return $r->{_memOID() . '.' . ($o+2) . '.' . $val} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
################################################## |
87
|
|
|
|
|
|
|
# End Public Module |
88
|
|
|
|
|
|
|
################################################## |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |