Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / network / ubiquiti_airos_ @ 9154029b

Historique | Voir | Annoter | Télécharger (15 ko)

1
#!/usr/bin/perl
2
###############################################################################
3
#
4
#Multigraph munin plugin to monitor Ubiquiti AirOS devices various parameters.
5
#
6
#To use this plugin, copy it to the munin's plugin directory (eg. /usr/share/munin/plugins) 
7
#under the name "ubiquiti_airos_". Don't change this filename! Follow these steps:
8
#
9
#1. Give names to your devices, in fqdn style. Like "apo.wlan" or  "cli.wlan". To make the
10
#   system understand that, in your /etc/hosts file, add to localhost these names which corespond 
11
#    to your devices:
12
#   127.0.0.1              localhost       apo.wlan        cli.wlan
13
#   Don't be fooled by 127.0.0.1, this is the localhost IP address, since munin will handle
14
#   them as virtual nodes!
15
#
16
#2. Then symlink it to munin's configured plugins directory (eg. /etc/munin/plugins) with names
17
#   according to the devices you wish to monitor, eg:
18
#   ubiquiti_airos_apo.wlan
19
#   ubiquiti_airos_cli.wlan
20
#
21
#   Important: make sure to use the same names in your symlinks and other config places!
22
#
23
#3. In /etc/munin/plugin-conf.d/munin-node add the following, to be able to contact
24
#   those devices via telnet (obviously replacing these with your own data):
25
#
26
#   [ubiquiti_airos_apo.wlan]
27
#   env.Name AccessPoint
28
#   env.Host 192.168.2.2
29
#   env.TelnetPort 23
30
#   env.TelnetUser foobar
31
#   env.TelnetPass raboof
32
#
33
#   [ubiquiti_airos_cli.wlan]
34
#   env.Name Client
35
#   env.Host 192.168.2.3
36
#   env.TelnetPort 23
37
#   env.TelnetUser foobar
38
#   env.TelnetPass raboof
39
#
40
#4. In /etc/munin/munin.conf add them as new virtual nodes:
41
#
42
#   [apo.wlan]
43
#       address 127.0.0.1
44
#
45
#   [cli.wlan]
46
#       address 127.0.0.1
47
#
48
#5. Restart the munin node by 'service munin-node restart'.
49
#
50
#   If all went well, after 5 minutes or so you should have two additional nodes listed 
51
#   on the Web Interface of munin.
52
#
53
#Plugin based on aramsey's script, which is based on a MicroTik plugin, see for more info see this link:
54
#http://community.ubnt.com/t5/NanoStation-and-Loco-Devices/SNMP-data-for-NF-dBm/m-p/39070/highlight/true#M11372
55
#
56
#Tested & working with munin v.2.0.14 and AirOS v5.5.4.
57
#Created in 2013 by robi
58
#
59
###############################################################################
60
use diagnostics;
61
use Net::Telnet;
62
use strict;
63
use warnings;
64
##############################################################################
65
## Retrieve environmental variables
66
my $Name = $ENV{'Name'};
67
my $Host = $ENV{'Host'};
68
my $TelnetPort = $ENV{'TelnetPort'};
69
my $TelnetUser = $ENV{'TelnetUser'};
70
my $TelnetPass = $ENV{'TelnetPass'};
71
my $graph_period = "second";
72
###############################################################################
73
## Determine Hostname
74
my $Hostname = undef;
75
$0 =~ /ubiquiti_airos_(.+)*$/;
76
unless ($Hostname = $1) {
77
  exit 2;
78
}
79
###############################################################################
80
## Initiate Telnet Session
81
my $MT = Net::Telnet->new(Host    => $Host,
82
                                 Port    => $TelnetPort,
83
                                 Prompt  => '/ $/',
84
                                 Timeout => 30);
85

    
86
###############################################################################
87
## Configuration
88
if(exists $ARGV[0] and $ARGV[0] eq "config") {
89
  print "multigraph airos_load\n";
90
  print "host_name " . $Hostname . "\n";
91
  print "graph_args --base 1000 -l 0 \n";
92
  print "graph_title Load average\n";
93
  print "graph_vlabel load\n";
94
  print "graph_category system\n";
95
  print "graph_scale no\n";
96
  print "load.label load\n";
97
  print "graph_info The load average of " . $Name . " describes how many processes are in the run-queue (scheduled to run 'immediately').\n";
98
  print "load.info 5 minute load average\n";
99
  print "\n";
100

    
101
  print "multigraph airos_uptime\n";
102
  print "host_name " . $Hostname . "\n";
103
  print "graph_args --base 1000 -l 0 \n";
104
  print "graph_title Uptime\n";
105
  print "graph_vlabel uptime in days\n";
106
  print "graph_category system\n";
107
  print "graph_scale no\n";
108
  print "uptime.label uptime\n";
109
  print "uptime.draw AREA\n";
110
  print "graph_info This graph shows how many days have passed since the bootup of " . $Name . ".\n";
111
  print "\n";
112

    
113
  print "multigraph airos_airmax\n";
114
  print "host_name " . $Hostname . "\n";
115
  print "graph_args -l 0 --lower-limit 0 --upper-limit 100\n";
116
  print "graph_title AirMAX Quality and Capacity\n";
117
  print "graph_vlabel %\n";
118
  print "graph_category radio\n";
119
  print "graph_info This graph shows the AirMAX Quality and AirMAX Capacity of " . $Name . ".\n";
120
  print "graph_scale no\n";
121
  print "amc.label AirMAX Capacity\n";
122
  print "amq.label AirMAX Quality\n";
123
  print "\n";
124

    
125
  print "multigraph airos_wconn\n";
126
  print "host_name " . $Hostname . "\n";
127
  print "graph_title WLAN connections\n";
128
  print "graph_category network\n";
129
  print "graph_info This graph shows the number of wireless connections to the wlan interface of " . $Name . ".\n";
130
  print "graph_scale no\n";
131
  print "conn.label Connections\n";
132
  print "\n";
133

    
134
  print "multigraph airos_errl\n";
135
  print "graph_order errlrcvd errltrans\n";
136
  print "graph_args --base 1000\n";
137
  print "graph_period " . $graph_period . "\n";
138
  print "graph_vlabel packets in (-) / out (+) per " . $graph_period . "\n";
139
  print "graph_info This graph shows the amount of errors on the LAN network interface of " . $Name . ".\n";
140
  print "errlrcvd.label errors\n";
141
  print "errlrcvd.type COUNTER\n";
142
  print "errlrcvd.graph no\n";
143
  print "errlrcvd.warning 1\n";
144
  print "errltrans.label errors\n";
145
  print "errltrans.type COUNTER\n";
146
  print "errltrans.negative errlrcvd\n";
147
  print "errltrans.warning 1\n";
148
  print "host_name " . $Hostname . "\n";
149
  print "graph_title LAN errors\n";
150
  print "graph_category network\n";
151
  print "\n";
152

    
153
  print "multigraph airos_errw\n";
154
  print "graph_order errwrcvd errwtrans\n";
155
  print "graph_args --base 1000\n";
156
  print "graph_period " . $graph_period . "\n";
157
  print "graph_vlabel packets in (-) / out (+) per " . $graph_period . "\n";
158
  print "graph_info This graph shows the amount of errors on the WLAN network interface of " . $Name . ".\n";
159
  print "errwrcvd.label errors\n";
160
  print "errwrcvd.type COUNTER\n";
161
  print "errwrcvd.graph no\n";
162
  print "errwrcvd.warning 1\n";
163
  print "errwtrans.label errors\n";
164
  print "errwtrans.type COUNTER\n";
165
  print "errwtrans.negative errwrcvd\n";
166
  print "errwtrans.warning 1\n";
167
  print "host_name " . $Hostname . "\n";
168
  print "graph_title WLAN errors\n";
169
  print "graph_category network\n";
170
  print "\n";
171

    
172
  print "multigraph airos_trfl\n";
173
  print "graph_order trfldown trflup\n";
174
  print "graph_args --base 1000\n";
175
  print "graph_period " . $graph_period . "\n";
176
  print "graph_vlabel bits in (-) / out (+) per " . $graph_period . "\n";
177
  print "graph_info This graph shows the traffic of the LAN network interface of " . $Name . ".\n";
178
  print "trfldown.label received\n";
179
  print "trfldown.type DERIVE\n";
180
  print "trfldown.graph no\n";
181
  print "trfldown.cdef trfldown,8,*\n";
182
  print "trfldown.min 0\n";
183
  print "trflup.label bps\n";
184
  print "trflup.type DERIVE\n";
185
  print "trflup.negative trfldown\n";
186
  print "trflup.cdef trflup,8,*\n";
187
  print "trflup.min 0\n";
188
  print "host_name " . $Hostname . "\n";
189
  print "graph_title LAN traffic\n";
190
  print "graph_category network\n";
191
  print "\n";
192

    
193
  print "multigraph airos_trfw\n";
194
  print "graph_order down up\n";
195
  print "graph_args --base 1000\n";
196
  print "graph_period " . $graph_period . "\n";
197
  print "graph_vlabel bits in (-) / out (+) per " . $graph_period . "\n";
198
  print "graph_info This graph shows the traffic of the WLAN network interface of " . $Name . ".\n";
199
  print "trfwdown.label received\n";
200
  print "trfwdown.type DERIVE\n";
201
  print "trfwdown.graph no\n";
202
  print "trfwdown.cdef trfwdown,8,*\n";
203
  print "trfwdown.min 0\n";
204
  print "trfwup.label bps\n";
205
  print "trfwup.type DERIVE\n";
206
  print "trfwup.negative trfwdown\n";
207
  print "trfwup.cdef trfwup,8,*\n";
208
  print "trfwup.min 0\n";
209
  print "host_name " . $Hostname . "\n";
210
  print "graph_title WLAN traffic\n";
211
  print "graph_category network\n";
212
  print "\n";
213

    
214
  print "multigraph airos_freq\n";
215
  print "host_name " . $Hostname . "\n";
216
  print "graph_args -l 0 --units-exponent 0 --lower-limit 5100 --upper-limit 5800\n";
217
  print "graph_title Frequency\n";
218
  print "graph_vlabel MHz\n";
219
  print "graph_category radio\n";
220
  print "graph_info This graph shows the operating frequency of the wireless interface of " . $Name . ".\n";
221
  print "graph_scale no\n";
222
  print "freq.label MHz\n";
223
  print "\n";
224

    
225
  print "multigraph airos_mem\n";
226
  print "host_name " . $Hostname . "\n";
227
  print "graph_args -l 0 \n";
228
  print "graph_title Memory usage\n";
229
  print "graph_vlabel kB\n";
230
  print "graph_category system\n";
231
  print "graph_info This graph shows the device memory usage status of " . $Name . ".\n";
232
  print "memTotal.label Total\n";
233
  print "memFree.label Free\n";
234
  print "memBuffers.label Buffers\n";
235
  print "\n";
236

    
237
  print "multigraph airos_ccq\n";
238
  print "host_name " . $Hostname . "\n";
239
  print "graph_args -l 0 --lower-limit 0 --upper-limit 100\n";
240
  print "graph_title Client Connection Quality\n";
241
  print "graph_vlabel %\n";
242
  print "graph_category radio\n";
243
  print "graph_info This graph shows the Client Connection Quality value of " . $Name . ".\n";
244
  print "graph_scale no\n";
245
  print "txccq.label Transmit CCQ\n";
246
  print "\n";
247

    
248
  print "multigraph airos_ack\n";
249
  print "host_name " . $Hostname . "\n";
250
  print "graph_title ACK timeout\n";
251
  print "graph_vlabel us\n";
252
  print "graph_category radio\n";
253
  print "graph_info This graph shows the ACK (Acknowledgement) timeout value of " . $Name . ".\n";
254
  print "acttimeout.label ACK Timeout\n";
255
  print "\n";
256

    
257
  print "multigraph airos_dbm\n";
258
  print "host_name " . $Hostname . "\n";
259
  print "graph_title Signal levels\n";
260
  print "graph_vlabel dBm\n";
261
  print "graph_category radio\n";
262
  print "graph_info This graph shows the radio signal levels of " . $Name . ".\n";
263
  print "txsignal.label Signal Strength\n";
264
  print "noisefloor.label Noise Floor\n";
265
  print "\n";
266

    
267
  print "multigraph airos_wrate\n";
268
  print "graph_order rxrate txrate\n";
269
  print "graph_args -l 0 --lower-limit -300 --upper-limit 300\n";
270
  print "graph_period " . $graph_period . "\n";
271
  print "graph_vlabel RX (-) / TX (+) Mbps\n";
272
  print "graph_info This graph shows the wireless link connection speed of " . $Name . ".\n";
273
  print "rxrate.label RX/TX Rate\n";
274
  print "rxrate.graph no\n";
275
#  print "rxrate.min 0\n";
276
  print "txrate.label Mbps\n";
277
  print "txrate.negative rxrate\n";
278
#  print "txrate.min 0\n";
279
  print "host_name " . $Hostname . "\n";
280
  print "graph_category radio\n";
281
  print "graph_title Wireless link speed\n";
282
  print "\n";
283

    
284
  exit;
285
}
286

    
287
###############################################################################
288
## Execution
289
if (!defined($MT->login($TelnetUser, $TelnetPass))) {
290
  die "Croaking: $MT->error";
291
} else {
292
  my @OutLoad = $MT->cmd("cat /proc/loadavg\n");
293
  my ($load) = undef;
294
  foreach my $Line (@OutLoad) {
295
      if ($Line !~ /XM.v/ && $Line =~ m/(\d+)/) {
296
      		$load = substr($Line, 0,4);
297
    	}
298
  }
299
  my @OutUpt = $MT->cmd("cat /proc/uptime\n");
300
  my ($uptime) = undef;
301
  foreach my $Line (@OutUpt) {
302
    if ($Line !~ /XM.v/ && $Line =~ m/(\d+)/) {
303
      $uptime = $1 / 86400;
304
    }
305
  }
306
  my @OutMca = $MT->cmd("ubntbox mca-status\n");
307
  my ($amc, $amq, $conn, $mt, $mf, $mb, $errlrcvd, $errltrans, $errwrcvd, $errwtrans, $trflup, $trfldown, $trfwup, $trfwdown, $freq, $txccq, $acttimeout, $txsignal, $noisefloor, $txrate, $rxrate) = undef;
308
  foreach my $Line (@OutMca) {
309
    if ($Line =~ /wlanRxErrors/ && $Line =~ m/(.\d+)/) {
310
        $errwrcvd = substr($Line, 13);
311
    }
312
    if ($Line =~ /wlanTxErrors/ && $Line =~ m/(.\d+)/) {
313
        $errwtrans = substr($Line, 13);
314
    }
315
    if ($Line =~ /lanRxErrors/ && $Line !~ /wlan/ && $Line =~ m/(.\d+)/) {
316
        $errlrcvd = substr($Line, 12);
317
    }
318
    if ($Line =~ /lanTxErrors/ && $Line !~ /wlan/ && $Line =~ m/(.\d+)/) {
319
        $errltrans = substr($Line, 12);
320
    }
321
    if ($Line =~ /wlanPollingCapacity/ && $Line =~ m/(.\d+)/) {
322
        $amc = substr($Line, 20);
323
    }
324
    if ($Line =~ /wlanPollingQuality/ && $Line =~ m/(.\d+)/) {
325
        $amq = substr($Line, 19);
326
    }
327
    if ($Line =~ /wlanConnections/ && $Line =~ m/(.\d+)/) {
328
        $conn = substr($Line, 16);
329
    }
330
    if ($Line =~ /lanRxBytes/ && $Line !~ /wlan/ && $Line =~ m/(.\d+)/) {
331
        $trfldown = substr($Line, 11);
332
    }
333
    if ($Line =~ /lanTxBytes/ && $Line !~ /wlan/ && $Line =~ m/(.\d+)/) {
334
        $trflup = substr($Line, 11);
335
    }
336
    if ($Line =~ /wlanRxBytes/ && $Line =~ m/(.\d+)/) {
337
        $trfwdown = substr($Line, 12);
338
    }
339
    if ($Line =~ /wlanTxBytes/ && $Line =~ m/(.\d+)/) {
340
        $trfwup = substr($Line, 12);
341
    }
342
    if ($Line =~ /freq/ && $Line =~ m/(.\d+)/) {
343
        $freq = substr($Line, 5);
344
    }
345
    if ($Line =~ /memTotal/ && $Line =~ m/(\d+)/) {
346
      $mt = $1;
347
    }
348
    if ($Line =~ /memFree/ && $Line =~ m/(\d+)/) {
349
      $mf = $1;
350
    }
351
    if ($Line =~ /memBuffers/ && $Line =~ m/(\d+)/) {
352
      $mb = $1;
353
    }
354
    if (($Line =~ /ccq/ && $Line !~ /overall-tx-ccq/) && $Line =~ m/(\d+)/) {
355
      $txccq = $1 / 10;
356
    }
357
    if ($Line =~ /signal/ && $Line =~ m/(.\d+)/) {
358
      $txsignal = $1;
359
    }
360
    if ($Line =~ /noise/ && $Line =~ m/(.\d+)/) {
361
      $noisefloor = $1;
362
    }
363
    if ($Line =~ /ackTimeout/ && $Line =~ m/(\d+)/) {
364
      $acttimeout = $1;
365
    }
366
    if ($Line =~ /wlanTxRate/ && $Line =~ m/(\d+)/) {
367
      $txrate = $1;
368
    }
369
    if ($Line =~ /wlanRxRate/ && $Line =~ m/(\d+)/) {
370
      $rxrate = $1;
371
    }
372

    
373
  }
374

    
375
  print "multigraph airos_wrate\n";
376
  print "txrate.value " . $txrate . "\n";
377
  print "rxrate.value " . $rxrate . "\n";
378
  print "\n";
379

    
380
  print "multigraph airos_ccq\n";
381
  print "txccq.value " . $txccq . "\n";
382
  print "\n";
383

    
384
  print "multigraph airos_ack\n";
385
  print "acttimeout.value " . $acttimeout . "\n";
386
  print "\n";
387

    
388
  print "multigraph airos_dbm\n";
389
  print "txsignal.value " . $txsignal . "\n";
390
  print "noisefloor.value " . $noisefloor . "\n";
391
  print "\n";
392

    
393
  print "multigraph airos_mem\n";
394
  print "memTotal.value " . $mt . "\n";
395
  print "memFree.value " . $mf . "\n";
396
  print "memBuffers.value " . $mb . "\n";
397
  print "\n";
398

    
399
  print "multigraph airos_freq\n";
400
  print "freq.value " . $freq;# . "\n";
401
  print "\n";
402

    
403
  print "multigraph airos_trfw\n";
404
  print "trfwup.value " . $trfwup;# . "\n";
405
  print "trfwdown.value " . $trfwdown;# . "\n";
406
  print "\n";
407

    
408
  print "multigraph airos_trfl\n";
409
  print "trflup.value " . $trflup;# . "\n";
410
  print "trfldown.value " . $trfldown;# . "\n";
411
  print "\n";
412

    
413
  print "multigraph airos_errw\n";
414
  print "errwrcvd.value " . $errwrcvd;# . "\n";
415
  print "errwtrans.value " . $errwtrans;# . "\n";
416
  print "\n";
417

    
418
  print "multigraph airos_errl\n";
419
  print "errlrcvd.value " . $errlrcvd;# . "\n";
420
  print "errltrans.value " . $errltrans;# . "\n";
421
  print "\n";
422

    
423
  print "multigraph airos_airmax\n";
424
  print "amc.value " . $amc;# . "\n";
425
  print "amq.value " . $amq;# . "\n";
426
  print "\n";
427

    
428
  print "multigraph airos_wconn\n";
429
  print "conn.value " . $conn;# . "\n";
430
  print "\n";
431

    
432
  print "multigraph airos_load\n";
433
  print "load.value " . $load . "\n";
434
  print "\n";
435

    
436
  print "multigraph airos_uptime\n";
437
  print "uptime.value " . $uptime . "\n";
438
  print "\n";
439

    
440
  exit;
441
}