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
|
|
74914
|
use strict; |
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
37
|
|
9
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
703
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
60537
|
|
|
1
|
|
|
|
|
277
|
|
12
|
1
|
|
|
1
|
|
350
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
340
|
|
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
|
4
|
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
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# -1 because last key (Total) isn't an OID; rather, calculated from 2 other OIDs |
40
|
0
|
|
|
|
|
|
for my $oid ( 0 .. $#MEMKEYS - 1 ) { |
41
|
0
|
|
|
|
|
|
$ret{$MEMKEYS[$oid]} = Cisco::SNMP::_snmpwalk( $session, |
42
|
|
|
|
|
|
|
_memOID() . '.' . ( $oid + 2 ) ); |
43
|
0
|
0
|
|
|
|
|
if ( not defined $ret{$MEMKEYS[$oid]} ) { |
44
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR |
45
|
|
|
|
|
|
|
= "Cannot get memory `$MEMKEYS[$oid]' info"; |
46
|
0
|
|
|
|
|
|
return undef; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my @MemInfo; |
51
|
0
|
|
|
|
|
|
for my $mem ( 0 .. $#{$ret{$MEMKEYS[0]}} ) { |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my %MemInfoHash; |
53
|
0
|
|
|
|
|
|
for ( 0 .. $#MEMKEYS ) { |
54
|
0
|
0
|
|
|
|
|
if ( $_ == 2 ) { |
|
|
0
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$MemInfoHash{$MEMKEYS[$_]} |
56
|
0
|
0
|
|
|
|
|
= ( $ret{$MEMKEYS[$_]}->[$mem] == 1 ) ? 'TRUE' : 'FALSE'; |
57
|
|
|
|
|
|
|
} elsif ( $_ == 6 ) { |
58
|
|
|
|
|
|
|
$MemInfoHash{$MEMKEYS[$_]} |
59
|
0
|
|
|
|
|
|
= $ret{$MEMKEYS[3]}->[$mem] + $ret{$MEMKEYS[4]}->[$mem]; |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
|
|
|
|
|
$MemInfoHash{$MEMKEYS[$_]} = $ret{$MEMKEYS[$_]}->[$mem]; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
push @MemInfo, \%MemInfoHash; |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
return bless \@MemInfo, $class; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
for ( memOIDs() ) { |
70
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_array_1( 'mem', $_ ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
153
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# get_ direct |
76
|
|
|
|
|
|
|
my @OIDS = memOIDs(); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# -1 because last key (Total) isn't an OID; rather, calculated from 2 other OIDs |
79
|
|
|
|
|
|
|
for my $o ( 0 .. $#OIDS - 1 ) { |
80
|
|
|
|
|
|
|
*{"get_mem" . $OIDS[$o]} = sub { |
81
|
0
|
|
|
0
|
|
|
my $self = shift; |
82
|
0
|
|
|
|
|
|
my ($val) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if ( not defined $val ) { $val = 0 } |
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $s = $self->session; |
86
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
87
|
|
|
|
|
|
|
varbindlist => [_memOID() . '.' . ( $o + 2 ) . '.' . $val] ); |
88
|
0
|
|
|
|
|
|
return $r->{_memOID() . '.' . ( $o + 2 ) . '.' . $val}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
################################################## |
93
|
|
|
|
|
|
|
# End Public Module |
94
|
|
|
|
|
|
|
################################################## |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |