line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::SNMP::Sensor; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
51621
|
use strict; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
30
|
|
9
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
619
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
95569
|
|
|
1
|
|
|
|
|
372
|
|
12
|
1
|
|
|
1
|
|
488
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
807
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Cisco::SNMP::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Cisco::SNMP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################## |
19
|
|
|
|
|
|
|
# Start Public Module |
20
|
|
|
|
|
|
|
################################################## |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _sensOID { |
23
|
0
|
|
|
0
|
|
0
|
return '1.3.6.1.4.1.9.9.91.1.1.1.1'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub sensOIDs { |
27
|
2
|
|
|
2
|
1
|
11
|
return qw(Type Scale Precision Value Status ValueTimeStamp |
28
|
|
|
|
|
|
|
ValueUpdateRate EntityId); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub sensor_info { |
32
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
33
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my %ret; |
38
|
|
|
|
|
|
|
my $OIDS; |
39
|
0
|
|
|
|
|
|
my @SENSKEYS = sensOIDs(); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# -1 because last key (EntityId) isn't an OID; rather, added |
42
|
0
|
|
|
|
|
|
for my $oid ( 0 .. $#SENSKEYS - 1 ) { |
43
|
0
|
|
|
|
|
|
( $OIDS, $ret{$SENSKEYS[$oid]} ) |
44
|
|
|
|
|
|
|
= Cisco::SNMP::_snmpwalk( $session, |
45
|
|
|
|
|
|
|
_sensOID() . '.' . ( $oid + 1 ) ); |
46
|
0
|
0
|
|
|
|
|
if ( not defined $ret{$SENSKEYS[$oid]} ) { |
47
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR |
48
|
|
|
|
|
|
|
= "Cannot get sensor `$SENSKEYS[$oid]' info"; |
49
|
0
|
|
|
|
|
|
return undef; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# need to record entity index |
54
|
0
|
|
|
|
|
|
for ( @{$OIDS} ) { |
|
0
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# split the OID at dots |
57
|
0
|
|
|
|
|
|
my @entId = split /\./, $_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# take the last value, which is the entity Index equal to value returned |
60
|
0
|
|
|
|
|
|
push @{$ret{$SENSKEYS[$#SENSKEYS]}}, $entId[$#entId]; |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my %SensType = ( |
64
|
|
|
|
|
|
|
1 => 'other', |
65
|
|
|
|
|
|
|
2 => 'unknown', |
66
|
|
|
|
|
|
|
3 => 'voltsAC', |
67
|
|
|
|
|
|
|
4 => 'voltsDC', |
68
|
|
|
|
|
|
|
5 => 'amperes', |
69
|
|
|
|
|
|
|
6 => 'watts', |
70
|
|
|
|
|
|
|
7 => 'hertz', |
71
|
|
|
|
|
|
|
8 => 'celsius', |
72
|
|
|
|
|
|
|
9 => 'percentRH', |
73
|
|
|
|
|
|
|
10 => 'rpm', |
74
|
|
|
|
|
|
|
11 => 'cmm', |
75
|
|
|
|
|
|
|
12 => 'truthvalue', |
76
|
|
|
|
|
|
|
13 => 'specialEnum', |
77
|
|
|
|
|
|
|
14 => 'dBm' |
78
|
|
|
|
|
|
|
); |
79
|
0
|
|
|
|
|
|
my %SensScale = ( |
80
|
|
|
|
|
|
|
1 => 'yocto', |
81
|
|
|
|
|
|
|
2 => 'zepto', |
82
|
|
|
|
|
|
|
3 => 'atto', |
83
|
|
|
|
|
|
|
4 => 'femto', |
84
|
|
|
|
|
|
|
5 => 'pico', |
85
|
|
|
|
|
|
|
6 => 'nano', |
86
|
|
|
|
|
|
|
7 => 'micro', |
87
|
|
|
|
|
|
|
8 => 'milli', |
88
|
|
|
|
|
|
|
9 => 'units', |
89
|
|
|
|
|
|
|
10 => 'kilo', |
90
|
|
|
|
|
|
|
11 => 'mega', |
91
|
|
|
|
|
|
|
12 => 'giga', |
92
|
|
|
|
|
|
|
13 => 'tera', |
93
|
|
|
|
|
|
|
14 => 'exa', |
94
|
|
|
|
|
|
|
15 => 'peta', |
95
|
|
|
|
|
|
|
16 => 'zetta', |
96
|
|
|
|
|
|
|
17 => 'yotta' |
97
|
|
|
|
|
|
|
); |
98
|
0
|
|
|
|
|
|
my %SensStatus = ( |
99
|
|
|
|
|
|
|
1 => 'ok', |
100
|
|
|
|
|
|
|
2 => 'unavailable', |
101
|
|
|
|
|
|
|
3 => 'nonoperational' |
102
|
|
|
|
|
|
|
); |
103
|
0
|
|
|
|
|
|
my %SensInfo; |
104
|
0
|
|
|
|
|
|
for my $sens ( 0 .. $#{$ret{$SENSKEYS[0]}} ) { |
|
0
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my %SensInfoHash; |
106
|
0
|
|
|
|
|
|
for ( 0 .. $#SENSKEYS ) { |
107
|
0
|
0
|
|
|
|
|
if ( $_ == 0 ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$SensInfoHash{$SENSKEYS[$_]} |
109
|
|
|
|
|
|
|
= exists( $SensType{$ret{$SENSKEYS[$_]}->[$sens]} ) |
110
|
|
|
|
|
|
|
? $SensType{$ret{$SENSKEYS[$_]}->[$sens]} |
111
|
0
|
0
|
|
|
|
|
: $ret{$SENSKEYS[$_]}->[$sens]; |
112
|
|
|
|
|
|
|
} elsif ( $_ == 1 ) { |
113
|
|
|
|
|
|
|
$SensInfoHash{$SENSKEYS[$_]} |
114
|
|
|
|
|
|
|
= exists( $SensScale{$ret{$SENSKEYS[$_]}->[$sens]} ) |
115
|
|
|
|
|
|
|
? $SensScale{$ret{$SENSKEYS[$_]}->[$sens]} |
116
|
0
|
0
|
|
|
|
|
: $ret{$SENSKEYS[$_]}->[$sens]; |
117
|
|
|
|
|
|
|
} elsif ( $_ == 4 ) { |
118
|
|
|
|
|
|
|
$SensInfoHash{$SENSKEYS[$_]} |
119
|
|
|
|
|
|
|
= exists( $SensStatus{$ret{$SENSKEYS[$_]}->[$sens]} ) |
120
|
|
|
|
|
|
|
? $SensStatus{$ret{$SENSKEYS[$_]}->[$sens]} |
121
|
0
|
0
|
|
|
|
|
: $ret{$SENSKEYS[$_]}->[$sens]; |
122
|
|
|
|
|
|
|
} else { |
123
|
0
|
|
|
|
|
|
$SensInfoHash{$SENSKEYS[$_]} = $ret{$SENSKEYS[$_]}->[$sens]; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
0
|
|
|
|
|
|
$SensInfo{$ret{$SENSKEYS[$#SENSKEYS]}->[$sens]} = \%SensInfoHash; |
127
|
|
|
|
|
|
|
} |
128
|
0
|
|
|
|
|
|
return bless \%SensInfo, $class; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
for ( sensOIDs() ) { |
132
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_hash_1( 'sens', $_ ); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
1
|
|
10
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
229
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# get_ direct |
138
|
|
|
|
|
|
|
my @OIDS = sensOIDs(); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# -1 because last key (EntityId) isn't an OID; rather, added |
141
|
|
|
|
|
|
|
for my $o ( 0 .. $#OIDS - 1 ) { |
142
|
|
|
|
|
|
|
*{"get_sens" . $OIDS[$o]} = sub { |
143
|
0
|
|
|
0
|
|
|
my $self = shift; |
144
|
0
|
|
|
|
|
|
my ($val) = @_; |
145
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
if ( not defined $val ) { $val = 0 } |
|
0
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
my $s = $self->session; |
148
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
149
|
|
|
|
|
|
|
varbindlist => [_sensOID() . '.' . ( $o + 1 ) . '.' . $val] ); |
150
|
0
|
|
|
|
|
|
return $r->{_sensOID() . '.' . ( $o + 1 ) . '.' . $val}; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
################################################## |
155
|
|
|
|
|
|
|
# End Public Module |
156
|
|
|
|
|
|
|
################################################## |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
__END__ |