-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path018-Open3-WLC-AIR-CT5500.pl
245 lines (197 loc) · 5.88 KB
/
018-Open3-WLC-AIR-CT5500.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/perl
our $VERSION = 2020.040101;
our $MANUAL = <<__MANUAL__;
NAME: WLC-HELLO - Cisco Wireless Lan Controller - access example
FILE: wlc-hello.pl
DESCRIPTION:
... xwlc shows details
USAGE:
wlc-hello.pl --run
PARAMETERS:
--run - running in produnction mode
--test - running in test mode
--help - this page
SEE ALSO:
https://github.com/ondrej-duras/
VERSION: ${VERSION}
__MANUAL__
use Socket;
use IPC::Open3;
use Data::Dumper;
use PWA;
our $MODE_DEBUG = ".*";
sub xdebug($) {
my $MSG=shift;
return unless $MODE_DEBUG;
print $MSG;
}
sub xchomp(@) {
my @ARRAY=@_;
return map { $A=$_;
chomp $A;
sprintf("%s",$A);
} @ARRAY;
}
sub xresolve($;$) {
my ($PAR1,$PAR2)=@_;
my ($DEVIP,$HNAME);
# handling input parameters
if(length($PAR2)) {
($DEVIP,$HNAME) = ($PAR1,$PAR2);
xdebug "#: '${PAR1}' '${PAR2}' '${DEVIP}' '${HNAME}'\n";
} else {
if($PAR1 =~ /^[0-9]+(\.[0-9]+){3}$/) {
$DEVIP=$PAR1; $HNAME='';
} else {
$HNAME=$PAR1; $DEVIP='';
}
}
# resolving IP from FQDN via DNS
unless($DEVIP) {
$HNAME = uc $HNAME;
if( my $DAT = gethostbyname($HNAME)) {
$DEVIP = inet_ntoa($DAT);
} else { $DEVIP=""; }
xdebug "#: HNAME '${HNAME}' -> DEVIP '${DEVIP}'\n";
}
# resolving FQDN based on PTR of DEVIP via DNS
unless($HNAME) {
my $DAT=inet_aton($DEVIP);
$FQDN=gethostbyaddr($DAT,AF_INET);
$HNAME = $FQDN;
$HNAME =~ s/\..*//;
$HNAME = uc $HNAME;
xdebug "#: DEVIP '${DEVIP}' -> FQDN '${FQDN}' -> HNAME '${HNAME}'\n";
}
return ($DEVIP,$HNAME);
}
sub xcommand($$$;$) {
my ($HOST,$CLASS,$COMMAND,$TYPE)=@_;
my ($DEVIP,$HNAME) = xresolve($HOST);
my ($pid,$fh_in,$fh_out,$fh_err);
my @OUTE; # errors
my @OUTA; # output
# Connecting to Device
print "HNAME ${HNAME} (${DEVIP}) connect\n";
#use IPC::Open2;
#$pid=open2($fh_out,$fh_in,"sshpass -p " .pwaPassword("user")." ssh -tt "
$pid=open3($fh_in,$fh_out,$fh_err,"sshpass -p " .pwaPassword("user")." ssh -tt "
. " -o StrictHostKeyChecking=no"
. " -o PubKeyAuthentication=no"
. " -l ".pwaLogin("user")." ${DEVIP}");
unless($pid) {
print STDERR "#! ERROR: ${HNAME}($DEVIP) connection failed !\n";
next;
}
# Operation on Device
sleep(2);
if($TYPE eq "no-more") {
print $fh_in "${COMMAND}\n";
print $fh_in "exit\n";
print $fh_in "exit\n";
print $fh_in "exit\n";
} else { # generic TYPE
print $fh_in "terminal length 0\n";
print $fh_in "${COMMAND}\n";
print $fh_in "exit\n";
print $fh_in "exit\n";
print $fh_in "exit\n";
}
close $fh_in;
# Handling potential Errors
@OUTE=<$fh_err>;
if( scalar(@OUTE) ) {
@OUTE =~ map { $A=$_;
$A =~ s/^/${DEVIP};${HNAME};ERR;${A}/;
sprintf("%s\n",$A);
} @OUTE;
} else { @OUTE=(); }
close $fh_err;
# Handling Output from Device
@OUTA=<$fh_out>;
#@OUTA = grep { !/^\s*\*via/} @OUTA;
#@OUTA = grep { !/^'/} @OUTA;
#@OUTA = grep { !/^\s*$/} @OUTA;
#$VRF = "GRT";
if( scalar(@OUTA) ) {
@OUTA = map { $A=$_;
chomp $A;
$A = "${DEVIP};${HNAME};${CLASS};${A}\n";
sprintf("%s",$A);
} @OUTA;
} else { @OUTA=(); }
close $fh_out;
# Dispatching PID from list of processes and writing outputs
waitpid($pid,0);
push @OUTA,@OUTE; # join OUTE(errors) at the end of OUTA(output)
return @OUTA;
}
sub xwlc($$$;$) {
my ($HOST,$CLASS,$COMMAND,$TYPE)=@_;
my ($DEVIP,$HNAME) = xresolve($HOST);
my ($pid,$fh_in,$fh_out,$fh_err);
my @OUTE; # errors
my @OUTA; # output
unless($HNAME) { $HNAME=$DEVIP; }
# Connecting to Device
print "HNAME ${HNAME} (${DEVIP}) connect\n";
#use IPC::Open2;
#$pid=open2($fh_out,$fh_in,"sshpass -p " .pwaPassword("wifi")." ssh -tt "
$pid=open3($fh_in,$fh_out,$fh_err," ssh -tt "
. " -o StrictHostKeyChecking=no"
. " -o PubKeyAuthentication=no"
. " -l ".pwaLogin("wifi")." ${DEVIP}");
unless($pid) {
print STDERR "#! ERROR: ${HNAME}($DEVIP) connection failed !\n";
next;
}
# Operation on Device
sleep(2);
print $fh_in pwaLogin("wifi") ."\n";
print $fh_in pwaPassword("wifi") ."\n";
print $fh_in "config paging disable\n";
print $fh_in "${COMMAND}\n";
print $fh_in "logout\n";
print $fh_in "n\n";
print $fh_in "n\n";
close $fh_in;
# Handling potential Errors
@OUTE=<$fh_err>;
if( scalar(@OUTE) ) {
@OUTE =~ map { $A=$_;
$A =~ s/^/${DEVIP};${HNAME};ERR;${A}/;
sprintf("%s\n",$A);
} @OUTE;
} else { @OUTE=(); }
close $fh_err;
# Handling Output from Device
@OUTA=<$fh_out>;
#@OUTA = grep { !/^\s*\*via/} @OUTA;
#@OUTA = grep { !/^'/} @OUTA;
#@OUTA = grep { !/^\s*$/} @OUTA;
#$VRF = "GRT";
if( scalar(@OUTA) ) {
@OUTA = map { $A=$_;
chomp $A;
$A = "${DEVIP};${HNAME};${CLASS};${A}\n";
sprintf("%s",$A);
} @OUTA;
} else { @OUTA=(); }
close $fh_out;
# Dispatching PID from list of processes and writing outputs
waitpid($pid,0);
push @OUTA,@OUTE; # join OUTE(errors) at the end of OUTA(output)
return @OUTA;
}
#print Dumper xresolve('','q-005-xx-rs-70');
#print Dumper xresolve('10.1.1.1','');
#print Dumper xresolve('q-005-xx-rs-70');
#print Dumper xresolve('10.2.1.1');
#print Dumper xchomp xcommand('q-005-xx-rs-70','IF_UPLINKS',"show ip int brief vrf all");
#print xcommand('q-005-xx-rs-70','RAW_IF_FOREIGN','show running interface | section nel997\.');
#print xcommand('q-005-xx-rr-70','RAW_IF_LOCAL','show startup | section interface nel97\.');
#print xcommand('q-005-xx-rs-70','RAW_RT_FOREIGN','show ip route vrf all');
#print xcommand('q-005-xx-rr-70','RAW_RT_LOCAL','show ip route vrf *');
print xwlc('10.1.1.1','RAW_AP_SUMMARY','show ap summary');
#> update prepare for profile WIFI
# --- end ---