line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPM; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21554
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
48
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION="1.51"; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
885
|
use IO::Socket; |
|
1
|
|
|
|
|
29021
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
2091
|
use Net::SNMP; |
|
1
|
|
|
|
|
82971
|
|
|
1
|
|
|
|
|
168
|
|
11
|
1
|
|
|
1
|
|
1109
|
use Net::Address::IP::Local; |
|
1
|
|
|
|
|
11612
|
|
|
1
|
|
|
|
|
37
|
|
12
|
1
|
|
|
1
|
|
1371
|
use Net::Ping; |
|
1
|
|
|
|
|
31902
|
|
|
1
|
|
|
|
|
85
|
|
13
|
1
|
|
|
1
|
|
953
|
use Net::SMTP_auth; |
|
1
|
|
|
|
|
29426
|
|
|
1
|
|
|
|
|
64
|
|
14
|
1
|
|
|
1
|
|
1316
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
54601
|
|
|
1
|
|
|
|
|
31
|
|
15
|
1
|
|
|
1
|
|
421
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new{ |
19
|
|
|
|
|
|
|
my $class=shift; |
20
|
|
|
|
|
|
|
my $self={@_}; |
21
|
|
|
|
|
|
|
bless($self, $class); |
22
|
|
|
|
|
|
|
$self->_init; |
23
|
|
|
|
|
|
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _init{ |
27
|
|
|
|
|
|
|
my $self=shift; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if (defined ($self->{-config})){$self->{config}=$self->{-config};} |
30
|
|
|
|
|
|
|
else{ $self->{config}='config.xml';} |
31
|
|
|
|
|
|
|
$self->{xml}=XMLin($self->{config},('forcearray',['device','range'])); |
32
|
|
|
|
|
|
|
$self->{url}=$self->{xml}->{call}.'?login='.$self->{xml}->{id}->{user}.'&nppas='.$self->{xml}->{id}->{pass}; |
33
|
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub saveconfig{ |
37
|
|
|
|
|
|
|
my $self=shift; |
38
|
|
|
|
|
|
|
my $out=XML::Simple::XMLout($self->{xml},('keeproot',1,xmldecl=>'')) || die "can't XMLout: $!"; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
open (OUTFILE, '>'.$self->{config}) || die "can't open output file: $!"; |
41
|
|
|
|
|
|
|
binmode(OUTFILE, ":utf8"); |
42
|
|
|
|
|
|
|
print OUTFILE $out; |
43
|
|
|
|
|
|
|
close OUTFILE; |
44
|
|
|
|
|
|
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub request |
48
|
|
|
|
|
|
|
# Make an SNMP request to read any OID (i.e Serial and Model) |
49
|
|
|
|
|
|
|
{ |
50
|
|
|
|
|
|
|
my $self=shift; |
51
|
|
|
|
|
|
|
my $oid=shift; |
52
|
|
|
|
|
|
|
my %properties=@_; # rest of params by hash |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $type='none'; |
55
|
|
|
|
|
|
|
$type=$properties{'-type'} if defined $properties{'-type'}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $session=Net::SNMP->session(-hostname=>$self->{target}); |
58
|
|
|
|
|
|
|
if (!defined($session)) {return "TimeOut";} |
59
|
|
|
|
|
|
|
my $result = $session->get_request( varbindlist => [$oid]); |
60
|
|
|
|
|
|
|
$session->close; |
61
|
|
|
|
|
|
|
if(!defined($result->{$oid})){return "UnknownOID";} |
62
|
|
|
|
|
|
|
else{ |
63
|
|
|
|
|
|
|
if($type eq 'MAC') |
64
|
|
|
|
|
|
|
{ |
65
|
|
|
|
|
|
|
$result->{$oid}=~s/\A0x//; |
66
|
|
|
|
|
|
|
$result->{$oid}=~s/.{2}/$&:/g; |
67
|
|
|
|
|
|
|
$result->{$oid}=~s/:\Z//; |
68
|
|
|
|
|
|
|
return uc($result->{$oid}); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
elsif($type eq 'SN') |
71
|
|
|
|
|
|
|
{ |
72
|
|
|
|
|
|
|
if(length($result->{$oid})<5){return "UnknownOID";} |
73
|
|
|
|
|
|
|
elsif($result->{$oid}=~/X{5,}/){return "UnknownOID";} |
74
|
|
|
|
|
|
|
else{ |
75
|
|
|
|
|
|
|
if($result->{$oid}=~/0x.*/){$result->{$oid}=_hex2ascii($result->{$oid});} |
76
|
|
|
|
|
|
|
$result->{$oid}=~s/\W*//g; |
77
|
|
|
|
|
|
|
return $result->{$oid}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else{ |
81
|
|
|
|
|
|
|
if($result->{$oid}=~/0x.*/){$result->{$oid}=_hex2ascii($result->{$oid});} |
82
|
|
|
|
|
|
|
return $result->{$oid}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub requesttable |
88
|
|
|
|
|
|
|
# Make an SNMP walk request |
89
|
|
|
|
|
|
|
{ |
90
|
|
|
|
|
|
|
my $self=shift; |
91
|
|
|
|
|
|
|
my $baseoid=shift; |
92
|
|
|
|
|
|
|
# Start a sesion connect to the host |
93
|
|
|
|
|
|
|
my $session=Net::SNMP->session(-hostname=>$self->{target}); |
94
|
|
|
|
|
|
|
if (!defined($session)) {return "TimeOut";} |
95
|
|
|
|
|
|
|
# make a get-request |
96
|
|
|
|
|
|
|
my $result = $session->get_table(-baseoid=>$baseoid); |
97
|
|
|
|
|
|
|
my $values=$session->var_bind_list; |
98
|
|
|
|
|
|
|
my @koids = keys(%{$values}); |
99
|
|
|
|
|
|
|
my $string=''; |
100
|
|
|
|
|
|
|
foreach my $v(@koids) |
101
|
|
|
|
|
|
|
{ |
102
|
|
|
|
|
|
|
$string.=$result->{$v}.'. '; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
$session->close; |
105
|
|
|
|
|
|
|
if($result) |
106
|
|
|
|
|
|
|
{ |
107
|
|
|
|
|
|
|
return $string; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else |
110
|
|
|
|
|
|
|
{ |
111
|
|
|
|
|
|
|
return "UnkownObject"; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _osocket |
116
|
|
|
|
|
|
|
# Open a socket on the 9100 port looking for JetDirects |
117
|
|
|
|
|
|
|
{ |
118
|
|
|
|
|
|
|
my $self=shift; |
119
|
|
|
|
|
|
|
my $sock = new IO::Socket::INET ( |
120
|
|
|
|
|
|
|
PeerAddr => $self->{target}, |
121
|
|
|
|
|
|
|
PeerPort => '9100', |
122
|
|
|
|
|
|
|
Proto => 'tcp', |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
if(!defined $sock){return -1;} |
125
|
|
|
|
|
|
|
else {close($sock);return 1} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _ping |
129
|
|
|
|
|
|
|
# Check by ping |
130
|
|
|
|
|
|
|
{ |
131
|
|
|
|
|
|
|
my $self=shift; |
132
|
|
|
|
|
|
|
my $ping = Net::Ping->new(); |
133
|
|
|
|
|
|
|
#return $ping->ping($self->{target},1); |
134
|
|
|
|
|
|
|
return $ping->ping($self->{target}); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _hex2ascii |
138
|
|
|
|
|
|
|
# Translate Hex to Ascii removing 0x0115 HP character |
139
|
|
|
|
|
|
|
{ |
140
|
|
|
|
|
|
|
my $str=shift||return; |
141
|
|
|
|
|
|
|
$str=~s/0x0115//; |
142
|
|
|
|
|
|
|
$str=~s/([a-fA-F0-9]{2})/chr(hex $1)/eg; |
143
|
|
|
|
|
|
|
$str=~s/\A0x.{2}//; |
144
|
|
|
|
|
|
|
#And eliminate Non Printable Chars |
145
|
|
|
|
|
|
|
my @chars = split(//,$str); |
146
|
|
|
|
|
|
|
$str=""; |
147
|
|
|
|
|
|
|
foreach my $ch (@chars){ |
148
|
|
|
|
|
|
|
if ((ord($ch) > 31) && (ord($ch) < 127)){ $str .= $ch; } |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
return $str; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub checkip |
154
|
|
|
|
|
|
|
# Check socket and its snmp for specific IP |
155
|
|
|
|
|
|
|
{ |
156
|
|
|
|
|
|
|
my $self=shift; |
157
|
|
|
|
|
|
|
my $ping=shift; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
if($self->_ping) |
160
|
|
|
|
|
|
|
{ |
161
|
|
|
|
|
|
|
# If we find the 9100 open, then... |
162
|
|
|
|
|
|
|
if($self->_osocket>0){ |
163
|
|
|
|
|
|
|
my ($sn,$trace)=$self->_getsn; |
164
|
|
|
|
|
|
|
return $sn; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
# else {print "Ping but not socket\n";return 0;} |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
# else {print "No ping\n"; return 0;} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub _getsn |
172
|
|
|
|
|
|
|
# Try to identify the SN using the standard OIDs |
173
|
|
|
|
|
|
|
{ |
174
|
|
|
|
|
|
|
my $self=shift; |
175
|
|
|
|
|
|
|
my $value='U_O'; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.4.1.11.2.3.9.4.2.1.1.3.3.0',-type=>'SN')) ne 'UnknownOID'){return $value,'1-';} |
178
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.5.1.1.17.1',-type=>'SN')) ne 'UnknownOID'){return $value,'2-';} |
179
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.1248.1.2.2.1.1.1.5.1',-type=>'SN')) ne 'UnknownOID'){return $value,'3-';} |
180
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.1347.43.5.1.1.28.1',-type=>'SN')) ne 'UnknownOID'){return $value,'4-';} |
181
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.2001.1.1.1.1.11.1.10.45.0',-type=>'SN')) ne 'UnknownOID'){return $value,'5-';} |
182
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.23.2.32.4.3.0',-type=>'SN')) ne 'UnknownOID'){return $value,'6-';} |
183
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.253.8.53.3.2.1.3.1',-type=>'SN')) ne 'UnknownOID'){return $value,'7-';} |
184
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.1.4.0',-type=>'SN')) ne 'UnknownOID'){return $value,'8-';} |
185
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.6.1.1.7.1',-type=>'SN')) ne 'UnknownOID'){return $value,'9-';} |
186
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.641.2.1.2.1.6.1',-type=>'SN')) ne 'UnknownOID'){return $value,'10-';} |
187
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.2435.2.3.9.4.2.1.5.5.1.0',-type=>'SN')) ne 'UnknownOID'){return $value,'11-';} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.2.2.1.6.1',-type=>'MAC')) ne 'UnknownOID'){return $value,'12-';} |
190
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.2.2.1.6.2',-type=>'MAC')) ne 'UnknownOID'){return $value,'13-';} |
191
|
|
|
|
|
|
|
return $value,'X-'; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub getgeneric |
195
|
|
|
|
|
|
|
{ |
196
|
|
|
|
|
|
|
my $self=shift; |
197
|
|
|
|
|
|
|
my $host; # structure to store the results (if any) |
198
|
|
|
|
|
|
|
my $value=''; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
($host->{SN},$host->{TRACE})=$self->_getsn; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
$host->{TOTAL}='U_O'; |
203
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.10.2.1.4.1.1')) ne 'UnknownOID'){$host->{TOTAL}=$value;$host->{TRACE}.='20-';} |
204
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.641.2.1.5.1.0')) ne 'UnknownOID'){$host->{TOTAL}=$value;$host->{TRACE}.='21-';} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
$host->{COLOR}='U_O'; |
207
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.2.7.0')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='31-';} |
208
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.1248.1.2.2.27.1.1.4.1.1')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='32-';} |
209
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.1347.42.2.2.1.1.3.1.2')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='33-';} |
210
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.253.8.53.13.2.1.6.1.20.33')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='34-';} |
211
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.19.5.1.9.12')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='35-';} |
212
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.19.5.1.9.13')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='36-';} |
213
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.19.5.1.9.21')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='37-';} |
214
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.19.5.1.9.5')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='38-';} |
215
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.3.2.3.2.1.4.128.1')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='39-';} |
216
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.641.2.1.5.3.0')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='40-';} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.10.2.1.4.1.1')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='41-';} |
219
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.641.2.1.5.1.0')) ne 'UnknownOID'){$host->{COLOR}=$value;$host->{TRACE}.='42-';} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
$host->{MC1}='100'; |
222
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.1')) ne 'UnknownOID'){$host->{MC1}=$value;$host->{TRACE}.='50-';} |
223
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.2001.1.1.1.1.100.3.1.1.4.1')) ne 'UnknownOID'){$host->{MC1}=$value;$host->{TRACE}.='51-';} |
224
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.20.2.2.1.9.2.3')) ne 'UnknownOID'){$host->{MC1}=$value;$host->{TRACE}.='52-';} |
225
|
|
|
|
|
|
|
if($host->{MC1}==0){$host->{MC1}=100;} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
$host->{CC1}='U_O'; |
228
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.1')) ne 'UnknownOID'){$host->{CC1}=$value;$host->{TRACE}.='60-';} |
229
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.2001.1.1.1.1.100.3.1.1.3.1')) ne 'UnknownOID'){$host->{CC1}=$value;$host->{TRACE}.='61-';} |
230
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.253.8.53.20.2.1.7.2.1.4.20.3')) ne 'UnknownOID'){$host->{CC1}=$value;$host->{TRACE}.='62-';} |
231
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.1')) ne 'UnknownOID'){$host->{CC1}=$value;$host->{TRACE}.='63-';} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
$host->{MC2}='100'; |
234
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.2')) ne 'UnknownOID'){$host->{MC2}=$value;$host->{TRACE}.='70-';} |
235
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.2001.1.1.1.1.100.3.1.1.4.2')) ne 'UnknownOID'){$host->{MC2}=$value;$host->{TRACE}.='71-';} |
236
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.20.2.2.1.9.2.3')) ne 'UnknownOID'){$host->{MC2}=$value;$host->{TRACE}.='72-';} |
237
|
|
|
|
|
|
|
if($host->{MC2}==0){$host->{MC2}=100;} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
$host->{CC2}='U_O'; |
240
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.2')) ne 'UnknownOID'){$host->{CC2}=$value;$host->{TRACE}.='80-';} |
241
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.2001.1.1.1.1.100.3.1.1.3.2')) ne 'UnknownOID'){$host->{CC2}=$value;$host->{TRACE}.='81-';} |
242
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.253.8.53.20.2.1.7.2.1.1.20.3')) ne 'UnknownOID'){$host->{CC2}=$value;$host->{TRACE}.='82-';} |
243
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.2')) ne 'UnknownOID'){$host->{CC2}=$value;$host->{TRACE}.='83-';} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
$host->{MC3}='100'; |
246
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.3')) ne 'UnknownOID'){$host->{MC3}=$value;$host->{TRACE}.='90-';} |
247
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.2001.1.1.1.1.100.3.1.1.4.3')) ne 'UnknownOID'){$host->{MC3}=$value;$host->{TRACE}.='91-';} |
248
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.20.2.2.1.9.2.3')) ne 'UnknownOID'){$host->{MC3}=$value;$host->{TRACE}.='92-';} |
249
|
|
|
|
|
|
|
if($host->{MC3}==0){$host->{MC3}=100;} |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
$host->{CC3}='U_O'; |
252
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.3')) ne 'UnknownOID'){$host->{CC3}=$value;$host->{TRACE}.='100-';} |
253
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.2001.1.1.1.1.100.3.1.1.3.3')) ne 'UnknownOID'){$host->{CC3}=$value;$host->{TRACE}.='101-';} |
254
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.253.8.53.20.2.1.7.2.1.2.20.3')) ne 'UnknownOID'){$host->{CC3}=$value;$host->{TRACE}.='102-';} |
255
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.3')) ne 'UnknownOID'){$host->{CC3}=$value;$host->{TRACE}.='103-';} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
$host->{MC4}='100'; |
258
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.4')) ne 'UnknownOID'){$host->{MC4}=$value;$host->{TRACE}.='110-';} |
259
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.2001.1.1.1.1.100.3.1.1.4.4')) ne 'UnknownOID'){$host->{MC4}=$value;$host->{TRACE}.='111-';} |
260
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.20.2.2.1.9.2.3')) ne 'UnknownOID'){$host->{MC4}=$value;$host->{TRACE}.='112-';} |
261
|
|
|
|
|
|
|
if($host->{MC4}==0){$host->{MC4}=100;} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
$host->{CC4}='U_O'; |
264
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.4')) ne 'UnknownOID'){$host->{CC4}=$value;$host->{TRACE}.='120-';} |
265
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.2001.1.1.1.1.100.3.1.1.3.4')) ne 'UnknownOID'){$host->{CC4}=$value;$host->{TRACE}.='121-';} |
266
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.253.8.53.20.2.1.7.2.1.3.20.3')) ne 'UnknownOID'){$host->{CC4}=$value;$host->{TRACE}.='122-';} |
267
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.4')) ne 'UnknownOID'){$host->{CC4}=$value;$host->{TRACE}.='123-';} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
$host->{MC5}='100'; |
270
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.5')) ne 'UnknownOID'){$host->{MC5}=$value;$host->{TRACE}.='130-';} |
271
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.8')) ne 'UnknownOID'){$host->{MC5}=$value;$host->{TRACE}.='131-';} |
272
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.11')) ne 'UnknownOID'){$host->{MC5}=$value;$host->{TRACE}.='132-';} |
273
|
|
|
|
|
|
|
if($host->{MC5}==0){$host->{MC5}=100;} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
$host->{CC5}='U_O'; |
276
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.5')) ne 'UnknownOID'){$host->{CC5}=$value;$host->{TRACE}.='140-';} |
277
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.8')) ne 'UnknownOID'){$host->{CC5}=$value;$host->{TRACE}.='141-';} |
278
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.11')) ne 'UnknownOID'){$host->{CC5}=$value;$host->{TRACE}.='142-';} |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
$host->{MC6}='100'; |
281
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.6')) ne 'UnknownOID'){$host->{MC6}=$value;$host->{TRACE}.='150-';} |
282
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.9')) ne 'UnknownOID'){$host->{MC6}=$value;$host->{TRACE}.='151-';} |
283
|
|
|
|
|
|
|
if($host->{MC6}==0){$host->{MC6}=100;} |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
$host->{CC6}='U_O'; |
286
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.6')) ne 'UnknownOID'){$host->{CC6}=$value;$host->{TRACE}.='160-';} |
287
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.9')) ne 'UnknownOID'){$host->{CC6}=$value;$host->{TRACE}.='161-';} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
$host->{MC7}='100'; |
290
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.7')) ne 'UnknownOID'){$host->{MC7}=$value;$host->{TRACE}.='170-';} |
291
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.10')) ne 'UnknownOID'){$host->{MC7}=$value;$host->{TRACE}.='171-';} |
292
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.8.1.11')) ne 'UnknownOID'){$host->{MC7}=$value;$host->{TRACE}.='172-';} |
293
|
|
|
|
|
|
|
if($host->{MC7}==0){$host->{MC7}=100;} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
$host->{CC7}='U_O'; |
296
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.7')) ne 'UnknownOID'){$host->{CC7}=$value;$host->{TRACE}.='180-';} |
297
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.10')) ne 'UnknownOID'){$host->{CC7}=$value;$host->{TRACE}.='181-';} |
298
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.43.11.1.1.9.1.11')) ne 'UnknownOID'){$host->{CC7}=$value;$host->{TRACE}.='182-';} |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
$host->{MODEL}='U_O'; |
301
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.25.3.2.1.3.1')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='190-';} |
302
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.2.1.1.1.0')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='192-';} |
303
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.11.2.3.9.4.2.1.1.3.2.0')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='192-';} |
304
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.1347.43.5.1.1.1.1')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='193-';} |
305
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.2001.1.3.1.1.10.1.0')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='194-';} |
306
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.23.2.32.4.2.0')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='195-';} |
307
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.253.8.53.3.2.1.2.1')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='196-';} |
308
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.236.11.5.1.1.1.0')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='197-';} |
309
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.1602.1.1.1.1.0')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='198-';} |
310
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.1347.43.5.1.1.1.1')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='199-';} |
311
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.1.1.1.0')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='200-';} |
312
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.7.2.2.3.0')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='201-';} |
313
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.641.2.1.2.1.2.1')) ne 'UnknownOID'){$host->{MODEL}=$value;$host->{TRACE}.='202-';} |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
$host->{FIRMWARE}='U_O'; |
316
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.4.1.11.2.3.9.4.2.1.1.3.6.0')) ne 'UnknownOID'){$host->{FIRMWARE}=$value;$host->{TRACE}.='210-';} |
317
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.1248.1.2.2.2.1.1.2.1.3')) ne 'UnknownOID'){$host->{FIRMWARE}=$value;$host->{TRACE}.='211-';} |
318
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.1248.1.2.2.2.1.1.2.1.4')) ne 'UnknownOID'){$host->{FIRMWARE}=$value;$host->{TRACE}.='212-';} |
319
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.1347.43.5.4.1.5.1.1')) ne 'UnknownOID'){$host->{FIRMWARE}=$value;$host->{TRACE}.='213-';} |
320
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.367.3.2.1.6.1.1.4.1')) ne 'UnknownOID'){$host->{FIRMWARE}=$value;$host->{TRACE}.='214-';} |
321
|
|
|
|
|
|
|
elsif(($value=$self->request('.1.3.6.1.4.1.641.1.1.1.0')) ne 'UnknownOID'){$host->{FIRMWARE}=$value;$host->{TRACE}.='215-';} |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
$host->{DISPLAY1}=$host->{DISPLAY2}=$host->{DISPLAY3}=$host->{DISPLAY4}=''; |
324
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.16.5.1.2.1.1')) ne 'UnknownOID'){$host->{DISPLAY1}=$value;$host->{TRACE}.='220-';} |
325
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.16.5.1.2.1.2')) ne 'UnknownOID'){$host->{DISPLAY2}=$value;$host->{TRACE}.='221-';} |
326
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.16.5.1.2.1.3')) ne 'UnknownOID'){$host->{DISPLAY3}=$value;$host->{TRACE}.='222-';} |
327
|
|
|
|
|
|
|
if(($value=$self->request('.1.3.6.1.2.1.43.16.5.1.2.1.4')) ne 'UnknownOID'){$host->{DISPLAY4}=$value;$host->{TRACE}.='223-';} |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
$host->{RESPONSE}='&L1='.$host->{SN}.'&L2='.$host->{TOTAL}.'&L3='.$host->{COLOR}.'&L4='.$host->{MC1}. |
330
|
|
|
|
|
|
|
'&L5='.$host->{CC1}.'&L6='.$host->{MC2}.'&L7='.$host->{CC2}.'&L8='.$host->{MC3}. |
331
|
|
|
|
|
|
|
'&L9='.$host->{CC3}.'&L10='.$host->{MC4}.'&L11='.$host->{CC4}.'&L12='.$host->{MC5}. |
332
|
|
|
|
|
|
|
'&L13='.$host->{CC5}.'&L14='.$host->{MC6}.'&L15='.$host->{CC6}.'&L16='.$host->{MC7}. |
333
|
|
|
|
|
|
|
'&L17='.$host->{CC7}.'&L18='.$host->{MODEL}.'&L19='.$self->{target}.'&L20='.$host->{FIRMWARE}. |
334
|
|
|
|
|
|
|
'&L21='.$host->{DISPLAY1}.'&L22='.$host->{DISPLAY2}.'&L23='.$host->{DISPLAY3}. |
335
|
|
|
|
|
|
|
'&L24='.$host->{DISPLAY4}.'&L90='.$host->{TRACE}; |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
return $host; |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
sub getmodel |
341
|
|
|
|
|
|
|
{ |
342
|
|
|
|
|
|
|
my $self=shift; |
343
|
|
|
|
|
|
|
my $answer=shift; |
344
|
|
|
|
|
|
|
my $host; |
345
|
|
|
|
|
|
|
my $i=0; |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
$answer=~s/OK:OIDL#//; |
348
|
|
|
|
|
|
|
$host->{RESPONSE}='&'; |
349
|
|
|
|
|
|
|
my @codes=split("#",$answer); |
350
|
|
|
|
|
|
|
foreach my $code(@codes) |
351
|
|
|
|
|
|
|
{ |
352
|
|
|
|
|
|
|
$i++; |
353
|
|
|
|
|
|
|
$code=~/\!\!/; |
354
|
|
|
|
|
|
|
my $counterid=$`; |
355
|
|
|
|
|
|
|
my $oid=$'; |
356
|
|
|
|
|
|
|
$counterid=~s/\AC/L/; # adapt Color to Legal |
357
|
|
|
|
|
|
|
$counterid=~s/\AB/L/; # adapt Black to Legal |
358
|
|
|
|
|
|
|
$counterid=~s/\AG/L/; # adapt Generic to Legal |
359
|
|
|
|
|
|
|
if($oid=~/\AMAC/) |
360
|
|
|
|
|
|
|
{ |
361
|
|
|
|
|
|
|
$oid=~s/\AMAC//; |
362
|
|
|
|
|
|
|
$host->{RESPONSE}.=$counterid.'='.$self->request($oid,-type=>'MAC').'&'; |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
else{ |
365
|
|
|
|
|
|
|
$host->{RESPONSE}.=$counterid.'='.$self->request($oid).'&'; |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
} |
368
|
|
|
|
|
|
|
return $host; |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
sub listandcall |
372
|
|
|
|
|
|
|
{ |
373
|
|
|
|
|
|
|
my $self=shift; |
374
|
|
|
|
|
|
|
my %properties=@_; # rest of params by hash |
375
|
|
|
|
|
|
|
my $browser = LWP::UserAgent->new; |
376
|
|
|
|
|
|
|
if($self->{xml}->{proxy} ne '') |
377
|
|
|
|
|
|
|
{ |
378
|
|
|
|
|
|
|
$browser->proxy(['http'],$self->{xml}->{proxy}); |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
elsif($self->{xml}->{proxy} eq 'auto') |
381
|
|
|
|
|
|
|
{ |
382
|
|
|
|
|
|
|
$browser->env_proxy; |
383
|
|
|
|
|
|
|
} |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
my $printers=0; |
386
|
|
|
|
|
|
|
my $verbose=0; |
387
|
|
|
|
|
|
|
$verbose=$properties{'-verbose'} if defined $properties{'-verbose'}; |
388
|
|
|
|
|
|
|
print "Proxy: $self->{xml}->{proxy}\n" if ($verbose && $self->{xml}->{proxy} ne ''); |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
my $devices=$self->{xml}->{devices}->{device}; |
391
|
|
|
|
|
|
|
foreach my $device(@$devices) |
392
|
|
|
|
|
|
|
{ |
393
|
|
|
|
|
|
|
$self->{target}=$device->{ip}; |
394
|
|
|
|
|
|
|
print "Checking $self->{target}\n" if $verbose; |
395
|
|
|
|
|
|
|
if(my $sn=$self->checkip) |
396
|
|
|
|
|
|
|
{ |
397
|
|
|
|
|
|
|
$printers++; |
398
|
|
|
|
|
|
|
print "Printer found: $sn\n" if $verbose; |
399
|
|
|
|
|
|
|
print "Connecting... " if $verbose; |
400
|
|
|
|
|
|
|
my $response = $browser->get($self->{url}.'&devid='.$sn); |
401
|
|
|
|
|
|
|
if($response->is_success) |
402
|
|
|
|
|
|
|
{ |
403
|
|
|
|
|
|
|
print "OK\n" if $verbose; |
404
|
|
|
|
|
|
|
my $answer=$response->decoded_content; |
405
|
|
|
|
|
|
|
if($answer eq 'OK:GEN') |
406
|
|
|
|
|
|
|
{ |
407
|
|
|
|
|
|
|
print "No defined model, using Generics.\n" if $verbose; |
408
|
|
|
|
|
|
|
if(my $host=$self->getgeneric) |
409
|
|
|
|
|
|
|
{ |
410
|
|
|
|
|
|
|
print "Sending data\n" if $verbose; |
411
|
|
|
|
|
|
|
my $a=$browser->get($self->{url}.'&devid='.$sn.'&devread=1'.$host->{RESPONSE}); |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
else |
414
|
|
|
|
|
|
|
{ |
415
|
|
|
|
|
|
|
print "Error during the data validation.\n" if $verbose; |
416
|
|
|
|
|
|
|
return "ERROR: data validation failure"; |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
} |
419
|
|
|
|
|
|
|
elsif($answer=~/OK:OIDL#.*/) |
420
|
|
|
|
|
|
|
{ |
421
|
|
|
|
|
|
|
print "Model identified\n" if $verbose; |
422
|
|
|
|
|
|
|
my $host=$self->getmodel($answer); |
423
|
|
|
|
|
|
|
$browser->get($self->{url}.'&devid='.$sn.'&devread=1'.$host->{RESPONSE}); |
424
|
|
|
|
|
|
|
} |
425
|
|
|
|
|
|
|
elsif($answer=~/OK:MR#.*/) |
426
|
|
|
|
|
|
|
{ |
427
|
|
|
|
|
|
|
print "Maximun number of readings per day achieved.\n" if $verbose; |
428
|
|
|
|
|
|
|
return "ERROR: Maximun number of readings per day achieved"; |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
elsif($answer=~/OK:UP#.*/) |
431
|
|
|
|
|
|
|
{ |
432
|
|
|
|
|
|
|
print "Error, please verify yor configuration.\n" if $verbose; |
433
|
|
|
|
|
|
|
return "ERROR: configuration fault"; |
434
|
|
|
|
|
|
|
} |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
else |
437
|
|
|
|
|
|
|
{ |
438
|
|
|
|
|
|
|
print "Connection failed!\n" if $verbose; |
439
|
|
|
|
|
|
|
return "ERROR: connection failed"; |
440
|
|
|
|
|
|
|
} |
441
|
|
|
|
|
|
|
} |
442
|
|
|
|
|
|
|
} |
443
|
|
|
|
|
|
|
print "$printers Printer(s) monitorized\n" if $verbose; |
444
|
|
|
|
|
|
|
return "OK $printers"; |
445
|
|
|
|
|
|
|
} |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
sub discoverandcall |
448
|
|
|
|
|
|
|
{ |
449
|
|
|
|
|
|
|
my $self=shift; |
450
|
|
|
|
|
|
|
my %properties=@_; # rest of params by hash |
451
|
|
|
|
|
|
|
my $browser = LWP::UserAgent->new; |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
if($self->{xml}->{proxy} ne '') |
454
|
|
|
|
|
|
|
{ |
455
|
|
|
|
|
|
|
$browser->proxy(['http'],$self->{xml}->{proxy}); |
456
|
|
|
|
|
|
|
} |
457
|
|
|
|
|
|
|
elsif($self->{xml}->{proxy} eq 'auto') |
458
|
|
|
|
|
|
|
{ |
459
|
|
|
|
|
|
|
$browser->env_proxy; |
460
|
|
|
|
|
|
|
} |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
my $printers=0; |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
my $verbose=0; |
465
|
|
|
|
|
|
|
$verbose=$properties{'-verbose'} if defined $properties{'-verbose'}; |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
print "Proxy: $self->{xml}->{proxy}\n" if ($verbose && $self->{xml}->{proxy} ne ''); |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
my $devices=$self->{xml}->{devices}->{device}; |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
my $ranges=$self->{xml}->{range}; |
472
|
|
|
|
|
|
|
foreach my $range(@$ranges) |
473
|
|
|
|
|
|
|
{ |
474
|
|
|
|
|
|
|
if ($range->{lan} eq '') |
475
|
|
|
|
|
|
|
{ |
476
|
|
|
|
|
|
|
my $testip=eval{$self->{address}=Net::Address::IP::Local->public}; |
477
|
|
|
|
|
|
|
if($@){$self->{address}='127.0.0.1';} |
478
|
|
|
|
|
|
|
} |
479
|
|
|
|
|
|
|
else |
480
|
|
|
|
|
|
|
{ |
481
|
|
|
|
|
|
|
$self->{address}=$range->{lan}; |
482
|
|
|
|
|
|
|
} |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
$self->{net}=$self->{address}; |
485
|
|
|
|
|
|
|
$self->{net}=~s/\.\d*\Z//; # extract net from address |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
my $init=1; |
488
|
|
|
|
|
|
|
my $end=254; |
489
|
|
|
|
|
|
|
$init=$range->{from} if defined $range->{from}; |
490
|
|
|
|
|
|
|
$end=$range->{to} if defined $range->{to}; |
491
|
|
|
|
|
|
|
print "Discovering LAN: $self->{net} [$init - $end] \n" if $verbose; |
492
|
|
|
|
|
|
|
for (my $i=$init;$i<=$end;$i++) |
493
|
|
|
|
|
|
|
{ |
494
|
|
|
|
|
|
|
$self->{target}=$self->{net}.'.'.$i; |
495
|
|
|
|
|
|
|
print "Checking $self->{target}\n" if $verbose; |
496
|
|
|
|
|
|
|
if(my $sn=$self->checkip) |
497
|
|
|
|
|
|
|
{ |
498
|
|
|
|
|
|
|
$printers++; |
499
|
|
|
|
|
|
|
print "Printer found: $sn\n" if $verbose; |
500
|
|
|
|
|
|
|
my $response = $browser->get($self->{url}.'&devid='.$sn); |
501
|
|
|
|
|
|
|
if($response->is_success) |
502
|
|
|
|
|
|
|
{ |
503
|
|
|
|
|
|
|
my $answer=$response->decoded_content; |
504
|
|
|
|
|
|
|
if($answer eq 'OK:GEN') |
505
|
|
|
|
|
|
|
{ |
506
|
|
|
|
|
|
|
print "No model identified, using Generics.\n" if $verbose; |
507
|
|
|
|
|
|
|
if(my $host=$self->getgeneric) |
508
|
|
|
|
|
|
|
{ |
509
|
|
|
|
|
|
|
my $a=$browser->get($self->{url}.'&devid='.$sn.'&devread=1'.$host->{RESPONSE}); |
510
|
|
|
|
|
|
|
print "Sending data.\n" if $verbose; |
511
|
|
|
|
|
|
|
} |
512
|
|
|
|
|
|
|
else |
513
|
|
|
|
|
|
|
{ |
514
|
|
|
|
|
|
|
print "Error during the data validation.\n" if $verbose; |
515
|
|
|
|
|
|
|
return "ERROR: data validation failure"; |
516
|
|
|
|
|
|
|
} |
517
|
|
|
|
|
|
|
} |
518
|
|
|
|
|
|
|
elsif($answer=~/OK:OIDL#.*/) |
519
|
|
|
|
|
|
|
{ |
520
|
|
|
|
|
|
|
print "Model identified.\n" if $verbose; |
521
|
|
|
|
|
|
|
my $host=$self->getmodel($answer); |
522
|
|
|
|
|
|
|
$browser->get($self->{url}.'&devid='.$sn.'&devread=1'.$host->{RESPONSE}); |
523
|
|
|
|
|
|
|
} |
524
|
|
|
|
|
|
|
elsif($answer=~/OK:MR#.*/) |
525
|
|
|
|
|
|
|
{ |
526
|
|
|
|
|
|
|
print "Maximum number of readings per day achieved.\n" if $verbose; |
527
|
|
|
|
|
|
|
return "ERROR: maximum number of readings per day achieved"; |
528
|
|
|
|
|
|
|
} |
529
|
|
|
|
|
|
|
elsif($answer=~/OK:UP#.*/) |
530
|
|
|
|
|
|
|
{ |
531
|
|
|
|
|
|
|
print "Error, please verify yor configuration.\n" if $verbose; |
532
|
|
|
|
|
|
|
return "ERROR: configuration fault"; |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
} |
535
|
|
|
|
|
|
|
else |
536
|
|
|
|
|
|
|
{ |
537
|
|
|
|
|
|
|
print "Connection failed!\n" if $verbose; |
538
|
|
|
|
|
|
|
return "ERROR: connection failed"; |
539
|
|
|
|
|
|
|
} |
540
|
|
|
|
|
|
|
} |
541
|
|
|
|
|
|
|
} |
542
|
|
|
|
|
|
|
} |
543
|
|
|
|
|
|
|
print "$printers Printer(s) monitorized\n"; |
544
|
|
|
|
|
|
|
return "OK $printers"; |
545
|
|
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
sub listandmail |
548
|
|
|
|
|
|
|
{ |
549
|
|
|
|
|
|
|
my $self=shift; |
550
|
|
|
|
|
|
|
my %properties=@_; # rest of params by hash |
551
|
|
|
|
|
|
|
my $verbose=0; |
552
|
|
|
|
|
|
|
$verbose=$properties{'-verbose'} if defined $properties{'-verbose'}; |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
my $printers=0; |
555
|
|
|
|
|
|
|
my $user=$self->{xml}->{mail}->{user}; |
556
|
|
|
|
|
|
|
my $pass=$self->{xml}->{mail}->{pass}; |
557
|
|
|
|
|
|
|
my $server=$self->{xml}->{mail}->{smtp}; |
558
|
|
|
|
|
|
|
my $to=$self->{xml}->{mail}->{to}; |
559
|
|
|
|
|
|
|
my $body_mail = "Mail sent by CPM - list\n\n#####\n"; |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
my $devices=$self->{xml}->{devices}->{device}; |
562
|
|
|
|
|
|
|
foreach my $device(@$devices) |
563
|
|
|
|
|
|
|
{ |
564
|
|
|
|
|
|
|
$self->{target}=$device->{ip}; |
565
|
|
|
|
|
|
|
print "Checking $self->{target}\n" if $verbose; |
566
|
|
|
|
|
|
|
$printers++; |
567
|
|
|
|
|
|
|
print "Printer located\n" if $verbose; |
568
|
|
|
|
|
|
|
$body_mail.="\n\nDEVICE ".$device->{number}.": ".$self->{xml}->{id}->{user}."\n"; |
569
|
|
|
|
|
|
|
my $oids=$device->{oid};print "\n"; |
570
|
|
|
|
|
|
|
my @keys=keys(%$oids); |
571
|
|
|
|
|
|
|
foreach my $oid(@keys) |
572
|
|
|
|
|
|
|
{ |
573
|
|
|
|
|
|
|
my $translate='Y'; |
574
|
|
|
|
|
|
|
my $walk='N'; |
575
|
|
|
|
|
|
|
if($oids->{$oid}->{content}=~/\AMAC.*/) |
576
|
|
|
|
|
|
|
{ |
577
|
|
|
|
|
|
|
$translate='N'; |
578
|
|
|
|
|
|
|
} |
579
|
|
|
|
|
|
|
if($oids->{$oid}->{content}=~/\AW.*/) |
580
|
|
|
|
|
|
|
{ |
581
|
|
|
|
|
|
|
$walk='Y'; |
582
|
|
|
|
|
|
|
} |
583
|
|
|
|
|
|
|
# filter any non OID |
584
|
|
|
|
|
|
|
$oids->{$oid}->{content}=~/..*/;$oids->{$oid}->{content}=$&; |
585
|
|
|
|
|
|
|
my $snmp; |
586
|
|
|
|
|
|
|
if($walk eq 'Y') |
587
|
|
|
|
|
|
|
{ |
588
|
|
|
|
|
|
|
$snmp=$self->requesttable($oids->{$oid}->{content}); |
589
|
|
|
|
|
|
|
} |
590
|
|
|
|
|
|
|
else |
591
|
|
|
|
|
|
|
{ |
592
|
|
|
|
|
|
|
$snmp=$self->request($oids->{$oid}->{content}); |
593
|
|
|
|
|
|
|
} |
594
|
|
|
|
|
|
|
if($translate eq 'N') |
595
|
|
|
|
|
|
|
{ |
596
|
|
|
|
|
|
|
$snmp=~s/0x//; # remove 0x00 |
597
|
|
|
|
|
|
|
$snmp=~s/.{2}/$&\:/g; # add the : every two digits |
598
|
|
|
|
|
|
|
$snmp=~s/:\Z//; # remove the last : |
599
|
|
|
|
|
|
|
$snmp=uc($snmp); # convert to capital letters |
600
|
|
|
|
|
|
|
} |
601
|
|
|
|
|
|
|
$body_mail.=" ".$oid.": ".$snmp."\n"; |
602
|
|
|
|
|
|
|
} |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
#Send the email |
605
|
|
|
|
|
|
|
print "Composing email..." if $verbose; |
606
|
|
|
|
|
|
|
my $smtp=Net::SMTP_auth->new($server); |
607
|
|
|
|
|
|
|
$smtp->auth('LOGIN',$user,$pass); |
608
|
|
|
|
|
|
|
$smtp->mail($user); |
609
|
|
|
|
|
|
|
$smtp->to($to); |
610
|
|
|
|
|
|
|
$smtp->data(); |
611
|
|
|
|
|
|
|
$smtp->datasend("Subject: CPM $self->{xml}->{id}->{user}\n"); |
612
|
|
|
|
|
|
|
$smtp->datasend("To: $to\n"); |
613
|
|
|
|
|
|
|
$smtp->datasend("From: MyPrinterCloud\n"); |
614
|
|
|
|
|
|
|
$smtp->datasend($body_mail); |
615
|
|
|
|
|
|
|
$smtp->dataend; |
616
|
|
|
|
|
|
|
$smtp->quit; |
617
|
|
|
|
|
|
|
print "Sent!\n" if $verbose ; |
618
|
|
|
|
|
|
|
return "OK $printers"; |
619
|
|
|
|
|
|
|
} |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
sub discoverandmail |
622
|
|
|
|
|
|
|
{ |
623
|
|
|
|
|
|
|
my $self=shift; |
624
|
|
|
|
|
|
|
my %properties=@_; # rest of params by hash |
625
|
|
|
|
|
|
|
my $verbose=0; |
626
|
|
|
|
|
|
|
$verbose=$properties{'-verbose'} if defined $properties{'-verbose'}; |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
my $printers=0; |
629
|
|
|
|
|
|
|
my $user=$self->{xml}->{mail}->{user}; |
630
|
|
|
|
|
|
|
my $pass=$self->{xml}->{mail}->{pass}; |
631
|
|
|
|
|
|
|
my $server=$self->{xml}->{mail}->{smtp}; |
632
|
|
|
|
|
|
|
my $to=$self->{xml}->{mail}->{to}; |
633
|
|
|
|
|
|
|
my $body_mail = "Mail sent by CPM - list\n\n#####\n"; |
634
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
my $ranges=$self->{xml}->{range}; |
636
|
|
|
|
|
|
|
foreach my $range(@$ranges) |
637
|
|
|
|
|
|
|
{ |
638
|
|
|
|
|
|
|
if ($range->{lan} eq '') |
639
|
|
|
|
|
|
|
{ |
640
|
|
|
|
|
|
|
my $testip=eval{$self->{address}=Net::Address::IP::Local->public}; |
641
|
|
|
|
|
|
|
if($@){$self->{address}='127.0.0.1';} |
642
|
|
|
|
|
|
|
} |
643
|
|
|
|
|
|
|
else |
644
|
|
|
|
|
|
|
{ |
645
|
|
|
|
|
|
|
$self->{address}=$range->{lan}; |
646
|
|
|
|
|
|
|
} |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
$self->{net}=$self->{address}; |
649
|
|
|
|
|
|
|
$self->{net}=~s/\.\d*\Z//; # extract net from address |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
my $init=1; |
652
|
|
|
|
|
|
|
my $end=254; |
653
|
|
|
|
|
|
|
$init=$range->{from} if defined $range->{from}; |
654
|
|
|
|
|
|
|
$end=$range->{to} if defined $range->{to}; |
655
|
|
|
|
|
|
|
for (my $i=$init;$i<=$end;$i++) |
656
|
|
|
|
|
|
|
{ |
657
|
|
|
|
|
|
|
$self->{target}=$self->{net}.'.'.$i; |
658
|
|
|
|
|
|
|
print "Checking $self->{target}\n" if $verbose; |
659
|
|
|
|
|
|
|
if(my $sn=$self->checkip) |
660
|
|
|
|
|
|
|
{ |
661
|
|
|
|
|
|
|
$printers++; |
662
|
|
|
|
|
|
|
print "Printer found: $sn\n" if $verbose; |
663
|
|
|
|
|
|
|
$body_mail.="\n\nDEVICE $printers: ".$self->{xml}->{id}->{user}."\n"; |
664
|
|
|
|
|
|
|
my $host=$self->getgeneric; |
665
|
|
|
|
|
|
|
$body_mail.=$host->{RESPONSE}."\n"; |
666
|
|
|
|
|
|
|
} |
667
|
|
|
|
|
|
|
} |
668
|
|
|
|
|
|
|
} |
669
|
|
|
|
|
|
|
#Send the email |
670
|
|
|
|
|
|
|
print "Composing email..." if $verbose; |
671
|
|
|
|
|
|
|
my $smtp=Net::SMTP_auth->new($server); |
672
|
|
|
|
|
|
|
$smtp->auth('LOGIN',$user,$pass); |
673
|
|
|
|
|
|
|
$smtp->mail($user); |
674
|
|
|
|
|
|
|
$smtp->to($to); |
675
|
|
|
|
|
|
|
$smtp->data(); |
676
|
|
|
|
|
|
|
$smtp->datasend("Subject: CPM $self->{xml}->{id}->{user}\n"); |
677
|
|
|
|
|
|
|
$smtp->datasend("To: $to\n"); |
678
|
|
|
|
|
|
|
$smtp->datasend("From: MyPrinterCloud\n"); |
679
|
|
|
|
|
|
|
$smtp->datasend($body_mail); |
680
|
|
|
|
|
|
|
$smtp->dataend; |
681
|
|
|
|
|
|
|
$smtp->quit; |
682
|
|
|
|
|
|
|
print "Sent!\n" if $verbose ; |
683
|
|
|
|
|
|
|
return "OK $printers"; |
684
|
|
|
|
|
|
|
} |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
sub auto |
687
|
|
|
|
|
|
|
{ |
688
|
|
|
|
|
|
|
my $self=shift; |
689
|
|
|
|
|
|
|
my %properties=@_; # rest of params by hash |
690
|
|
|
|
|
|
|
my $verbose=0; |
691
|
|
|
|
|
|
|
$verbose=$properties{'-verbose'} if defined $properties{'-verbose'}; |
692
|
|
|
|
|
|
|
if($self->{xml}->{id}->{comm} eq 'call') |
693
|
|
|
|
|
|
|
{ |
694
|
|
|
|
|
|
|
print "Using CALL" if $verbose; |
695
|
|
|
|
|
|
|
if($self->{xml}->{id}->{mode} eq 'list') |
696
|
|
|
|
|
|
|
{ |
697
|
|
|
|
|
|
|
print " with a LIST\n" if $verbose; |
698
|
|
|
|
|
|
|
return $self->listandcall(-verbose=>$verbose); |
699
|
|
|
|
|
|
|
} |
700
|
|
|
|
|
|
|
else |
701
|
|
|
|
|
|
|
{ |
702
|
|
|
|
|
|
|
print " and DISCOVERING\n" if $verbose; |
703
|
|
|
|
|
|
|
return $self->discoverandcall(-verbose=>$verbose); |
704
|
|
|
|
|
|
|
} |
705
|
|
|
|
|
|
|
} |
706
|
|
|
|
|
|
|
else |
707
|
|
|
|
|
|
|
{ |
708
|
|
|
|
|
|
|
if($self->{xml}->{id}->{mode} ne 'list') |
709
|
|
|
|
|
|
|
{ |
710
|
|
|
|
|
|
|
print "Discover and Email\n" if $verbose; |
711
|
|
|
|
|
|
|
return $self->discoverandmail(-verbose=>$verbose); |
712
|
|
|
|
|
|
|
} |
713
|
|
|
|
|
|
|
else |
714
|
|
|
|
|
|
|
{ |
715
|
|
|
|
|
|
|
print "Using SMTP-auth from a fixed list and OIDs\n" if $verbose; |
716
|
|
|
|
|
|
|
return $self->listandmail(-verbose=>$verbose); |
717
|
|
|
|
|
|
|
} |
718
|
|
|
|
|
|
|
} |
719
|
|
|
|
|
|
|
} |
720
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
1; |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
__END__ |