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
|
|
67371
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
9
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
653
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
64168
|
|
|
1
|
|
|
|
|
300
|
|
12
|
1
|
|
|
1
|
|
529
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
847
|
|
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
|
10
|
return qw(Type Scale Precision Value Status ValueTimeStamp ValueUpdateRate EntityId) |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub sensor_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
|
|
|
|
|
|
|
my $OIDS; |
38
|
0
|
|
|
|
|
|
my @SENSKEYS = sensOIDs(); |
39
|
|
|
|
|
|
|
# -1 because last key (EntityId) isn't an OID; rather, added |
40
|
0
|
|
|
|
|
|
for my $oid (0..$#SENSKEYS-1) { |
41
|
0
|
|
|
|
|
|
($OIDS, $ret{$SENSKEYS[$oid]}) = Cisco::SNMP::_snmpwalk($session, _sensOID() . '.' . ($oid+1)); |
42
|
0
|
0
|
|
|
|
|
if (!defined $ret{$SENSKEYS[$oid]}) { |
43
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get sensor `$SENSKEYS[$oid]' info"; |
44
|
|
|
|
|
|
|
return undef |
45
|
0
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
# need to record entity index |
48
|
0
|
|
|
|
|
|
for (@{$OIDS}) { |
|
0
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# split the OID at dots |
50
|
0
|
|
|
|
|
|
my @entId = split /\./, $_; |
51
|
|
|
|
|
|
|
# take the last value, which is the entity Index equal to value returned |
52
|
0
|
|
|
|
|
|
push @{$ret{$SENSKEYS[$#SENSKEYS]}}, $entId[$#entId] |
|
0
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my %SensType = ( |
56
|
|
|
|
|
|
|
1 => 'other', |
57
|
|
|
|
|
|
|
2 => 'unknown', |
58
|
|
|
|
|
|
|
3 => 'voltsAC', |
59
|
|
|
|
|
|
|
4 => 'voltsDC', |
60
|
|
|
|
|
|
|
5 => 'amperes', |
61
|
|
|
|
|
|
|
6 => 'watts', |
62
|
|
|
|
|
|
|
7 => 'hertz', |
63
|
|
|
|
|
|
|
8 => 'celsius', |
64
|
|
|
|
|
|
|
9 => 'percentRH', |
65
|
|
|
|
|
|
|
10 => 'rpm', |
66
|
|
|
|
|
|
|
11 => 'cmm', |
67
|
|
|
|
|
|
|
12 => 'truthvalue', |
68
|
|
|
|
|
|
|
13 => 'specialEnum', |
69
|
|
|
|
|
|
|
14 => 'dBm' |
70
|
|
|
|
|
|
|
); |
71
|
0
|
|
|
|
|
|
my %SensScale = ( |
72
|
|
|
|
|
|
|
1 => 'yocto', |
73
|
|
|
|
|
|
|
2 => 'zepto', |
74
|
|
|
|
|
|
|
3 => 'atto', |
75
|
|
|
|
|
|
|
4 => 'femto', |
76
|
|
|
|
|
|
|
5 => 'pico', |
77
|
|
|
|
|
|
|
6 => 'nano', |
78
|
|
|
|
|
|
|
7 => 'micro', |
79
|
|
|
|
|
|
|
8 => 'milli', |
80
|
|
|
|
|
|
|
9 => 'units', |
81
|
|
|
|
|
|
|
10 => 'kilo', |
82
|
|
|
|
|
|
|
11 => 'mega', |
83
|
|
|
|
|
|
|
12 => 'giga', |
84
|
|
|
|
|
|
|
13 => 'tera', |
85
|
|
|
|
|
|
|
14 => 'exa', |
86
|
|
|
|
|
|
|
15 => 'peta', |
87
|
|
|
|
|
|
|
16 => 'zetta', |
88
|
|
|
|
|
|
|
17 => 'yotta' |
89
|
|
|
|
|
|
|
); |
90
|
0
|
|
|
|
|
|
my %SensStatus = ( |
91
|
|
|
|
|
|
|
1 => 'ok', |
92
|
|
|
|
|
|
|
2 => 'unavailable', |
93
|
|
|
|
|
|
|
3 => 'nonoperational' |
94
|
|
|
|
|
|
|
); |
95
|
0
|
|
|
|
|
|
my %SensInfo; |
96
|
0
|
|
|
|
|
|
for my $sens (0..$#{$ret{$SENSKEYS[0]}}) { |
|
0
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my %SensInfoHash; |
98
|
0
|
|
|
|
|
|
for (0..$#SENSKEYS) { |
99
|
0
|
0
|
|
|
|
|
if ($_ == 0) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
$SensInfoHash{$SENSKEYS[$_]} = exists($SensType{$ret{$SENSKEYS[$_]}->[$sens]}) ? $SensType{$ret{$SENSKEYS[$_]}->[$sens]} : $ret{$SENSKEYS[$_]}->[$sens] |
101
|
|
|
|
|
|
|
} elsif ($_ == 1) { |
102
|
0
|
0
|
|
|
|
|
$SensInfoHash{$SENSKEYS[$_]} = exists($SensScale{$ret{$SENSKEYS[$_]}->[$sens]}) ? $SensScale{$ret{$SENSKEYS[$_]}->[$sens]} : $ret{$SENSKEYS[$_]}->[$sens] |
103
|
|
|
|
|
|
|
} elsif ($_ == 4) { |
104
|
0
|
0
|
|
|
|
|
$SensInfoHash{$SENSKEYS[$_]} = exists($SensStatus{$ret{$SENSKEYS[$_]}->[$sens]}) ? $SensStatus{$ret{$SENSKEYS[$_]}->[$sens]} : $ret{$SENSKEYS[$_]}->[$sens] |
105
|
|
|
|
|
|
|
} else { |
106
|
0
|
|
|
|
|
|
$SensInfoHash{$SENSKEYS[$_]} = $ret{$SENSKEYS[$_]}->[$sens] |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
|
$SensInfo{$ret{$SENSKEYS[$#SENSKEYS]}->[$sens]} = \%SensInfoHash |
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
|
return bless \%SensInfo, $class |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
for (sensOIDs()) { |
115
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_hash_1('sens', $_) |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
1
|
|
11
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
305
|
|
119
|
|
|
|
|
|
|
# get_ direct |
120
|
|
|
|
|
|
|
my @OIDS = sensOIDs(); |
121
|
|
|
|
|
|
|
# -1 because last key (EntityId) isn't an OID; rather, added |
122
|
|
|
|
|
|
|
for my $o (0..$#OIDS-1) { |
123
|
|
|
|
|
|
|
*{"get_sens" . $OIDS[$o]} = sub { |
124
|
0
|
|
|
0
|
|
|
my $self = shift; |
125
|
0
|
|
|
|
|
|
my ($val) = @_; |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = 0 } |
|
0
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $s = $self->session; |
129
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
130
|
|
|
|
|
|
|
varbindlist => [_sensOID() . '.' . ($o+1) . '.' . $val] |
131
|
|
|
|
|
|
|
); |
132
|
0
|
|
|
|
|
|
return $r->{_sensOID() . '.' . ($o+1) . '.' . $val} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
################################################## |
137
|
|
|
|
|
|
|
# End Public Module |
138
|
|
|
|
|
|
|
################################################## |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
__END__ |