1# /usr/bin/perl -w
2
3use strict;
4no warnings qw(once);
5
6if ( ! grep /BEGIN/, keys %Monitoring::GLPlugin::) {
7  eval {
8    require Monitoring::GLPlugin;
9    require Monitoring::GLPlugin::SNMP;
10    require Monitoring::GLPlugin::UPNP;
11  };
12  if ($@) {
13    printf "UNKNOWN - module Monitoring::GLPlugin was not found. Either build a standalone version of this plugin or set PERL5LIB\n";
14    printf "%s\n", $@;
15    exit 3;
16  }
17}
18
19my $plugin = Classes::Device->new(
20    shortname => '',
21    usage => 'Usage: %s [ -v|--verbose ] [ -t <timeout> ] '.
22        '--mode <what-to-do> '.
23        '--hostname <network-component> --community <snmp-community>'.
24        '  ...]',
25    version => '$Revision: #PACKAGE_VERSION# $',
26    blurb => 'This plugin checks various parameters of network components ',
27    url => 'http://labs.consol.de/nagios/check_nwc_health',
28    timeout => 60,
29    plugin => $Monitoring::GLPlugin::pluginname,
30);
31$plugin->add_mode(
32    internal => 'device::hardware::health',
33    spec => 'hardware-health',
34    alias => undef,
35    help => 'Check the status of environmental equipment (fans, temperatures, power)',
36);
37$plugin->add_mode(
38    internal => 'device::hardware::load',
39    spec => 'cpu-load',
40    alias => ['cpu-usage'],
41    help => 'Check the CPU load of the device',
42);
43$plugin->add_mode(
44    internal => 'device::hardware::memory',
45    spec => 'memory-usage',
46    alias => undef,
47    help => 'Check the memory usage of the device',
48);
49$plugin->add_mode(
50    internal => 'device::disk::usage',
51    spec => 'disk-usage',
52    alias => undef,
53    help => 'Check the disk usage of the device',
54);
55$plugin->add_mode(
56    internal => 'device::interfaces::usage',
57    spec => 'interface-usage',
58    alias => undef,
59    help => 'Check the utilization of interfaces',
60);
61$plugin->add_mode(
62    internal => 'device::interfaces::errors',
63    spec => 'interface-errors',
64    alias => undef,
65    help => 'Check the error-rate of interfaces (without discards)',
66);
67$plugin->add_mode(
68    internal => 'device::interfaces::discards',
69    spec => 'interface-discards',
70    alias => undef,
71    help => 'Check the discard-rate of interfaces',
72);
73$plugin->add_mode(
74    internal => 'device::interfaces::operstatus',
75    spec => 'interface-status',
76    alias => undef,
77    help => 'Check the status of interfaces (oper/admin)',
78);
79$plugin->add_mode(
80    internal => 'device::interfaces::duplex',
81    spec => 'interface-duplex',
82    alias => undef,
83    help => 'Check if interfaces operate in duplex mode',
84);
85$plugin->add_mode(
86    internal => 'device::interfaces::complete',
87    spec => 'interface-health',
88    alias => undef,
89    help => 'Check everything interface',
90);
91$plugin->add_mode(
92    internal => 'device::interfaces::nat::sessions::count',
93    spec => 'interface-nat-count-sessions',
94    alias => undef,
95    help => 'Count the number of nat sessions',
96);
97$plugin->add_mode(
98    internal => 'device::interfaces::nat::rejects',
99    spec => 'interface-nat-rejects',
100    alias => undef,
101    help => 'Count the number of nat sessions rejected due to lack of resources',
102);
103$plugin->add_mode(
104    internal => 'device::interfaces::list',
105    spec => 'list-interfaces',
106    alias => undef,
107    help => 'Show the interfaces of the device and update the name cache',
108);
109$plugin->add_mode(
110    internal => 'device::interfaces::listdetail',
111    spec => 'list-interfaces-detail',
112    alias => undef,
113    help => 'Show the interfaces of the device and some details',
114);
115$plugin->add_mode(
116    internal => 'device::interfaces::availability',
117    spec => 'interface-availability',
118    alias => undef,
119    help => 'Show the availability (oper != up) of interfaces',
120);
121$plugin->add_mode(
122    internal => 'device::interfaces::aggregation::availability',
123    spec => 'link-aggregation-availability',
124    alias => undef,
125    help => 'Check the percentage of up interfaces in a link aggregation',
126);
127$plugin->add_mode(
128    internal => 'device::interfaces::ifstack::status',
129    spec => 'interface-stack-status',
130    alias => undef,
131    help => 'Check the status of interface sublayers (mostly layer 2)',
132);
133$plugin->add_mode(
134    internal => 'device::interfaces::ifstack::availability',
135    spec => 'interface-stack-availability',
136    alias => undef,
137    help => 'Check the percentage of available sublayer interfaces',
138);
139$plugin->add_mode(
140    internal => 'device::interfaces::etherstats',
141    spec => 'interface-etherstats',
142    alias => undef,
143    help => 'Check the ethernet statistics of interfaces',
144);
145$plugin->add_mode(
146    internal => 'device::interfaces::uptime',
147    spec => 'interface-uptime',
148    alias => undef,
149    help => 'Check state changes of interfaces',
150);
151$plugin->add_mode(
152    internal => 'device::interfaces::portsecurity',
153    spec => 'interface-security',
154    alias => undef,
155    help => 'Check interfaces for security violations',
156);
157$plugin->add_mode(
158    internal => 'device::routes::list',
159    spec => 'list-routes',
160    alias => undef,
161    help => 'Show the configured routes',
162    help => 'Check the percentage of up interfaces in a link aggregation',
163);
164$plugin->add_mode(
165    internal => 'device::routes::exists',
166    spec => 'route-exists',
167    alias => undef,
168    help => 'Check if a route exists. (--name is the dest, --name2 check also the next hop)',
169);
170$plugin->add_mode(
171    internal => 'device::routes::count',
172    spec => 'count-routes',
173    alias => undef,
174    help => 'Count the routes. (--name is the dest, --name2 is the hop)',
175);
176$plugin->add_mode(
177    internal => 'device::vpn::status',
178    spec => 'vpn-status',
179    alias => undef,
180    help => 'Check the status of vpns (up/down)',
181);
182$plugin->add_mode(
183    internal => 'device::vpn::sessions',
184    spec => 'vpn-sessions',
185    alias => undef,
186    help => 'Check the number of vpn sessions (users, errors)',
187);
188$plugin->add_mode(
189    internal => 'device::fcinterfaces::usage',
190    spec => 'fc-interface-usage',
191    alias => undef,
192    help => 'Check the utilization of fibrechannel interfaces',
193);
194$plugin->add_mode(
195    internal => 'device::fcinterfaces::errors',
196    spec => 'fc-interface-errors',
197    alias => undef,
198    help => 'Check the error-rate of fibrechannel interfaces',
199);
200$plugin->add_mode(
201    internal => 'device::fcinterfaces::discards',
202    spec => 'fc-interface-discards',
203    alias => undef,
204    help => 'Check the discard-rate of interfaces',
205);
206$plugin->add_mode(
207    internal => 'device::fcinterfaces::operstatus',
208    spec => 'fc-interface-status',
209    alias => undef,
210    help => 'Check the status of interfaces (oper/admin)',
211);
212$plugin->add_mode(
213    internal => 'device::fcinterfaces::complete',
214    spec => 'fc-interface-health',
215    alias => undef,
216    help => 'Check everything interface',
217);
218$plugin->add_mode(
219    internal => 'device::fcinterfaces::list',
220    spec => 'fc-list-interfaces',
221    alias => undef,
222    help => 'Show the fcal interfaces of the device and update the name cache',
223);
224$plugin->add_mode(
225    internal => 'device::shinken::interface',
226    spec => 'create-shinken-service',
227    alias => undef,
228    help => 'Create a Shinken service definition',
229);
230$plugin->add_mode(
231    internal => 'device::hsrp::state',
232    spec => 'hsrp-state',
233    alias => undef,
234    help => 'Check the state in a HSRP group',
235);
236$plugin->add_mode(
237    internal => 'device::hsrp::failover',
238    spec => 'hsrp-failover',
239    alias => undef,
240    help => 'Check if a HSRP group\'s nodes have changed their roles',
241);
242$plugin->add_mode(
243    internal => 'device::hsrp::list',
244    spec => 'list-hsrp-groups',
245    alias => undef,
246    help => 'Show the HSRP groups configured on this device',
247);
248$plugin->add_mode(
249    internal => 'device::vrrp::state',
250    spec => 'vrrp-state',
251    alias => undef,
252    help => 'Check the state in a VRRP group',
253);
254$plugin->add_mode(
255    internal => 'device::vrrp::failover',
256    spec => 'vrrp-failover',
257    alias => undef,
258    help => 'Check if a VRRP group\'s nodes have changed their roles',
259);
260$plugin->add_mode(
261    internal => 'device::vrrp::list',
262    spec => 'list-vrrp-groups',
263    alias => undef,
264    help => 'Show the VRRP groups configured on this device',
265);
266$plugin->add_mode(
267    internal => 'device::bgp::peer::status',
268    spec => 'bgp-peer-status',
269    alias => undef,
270    help => 'Check status of BGP peers',
271);
272$plugin->add_mode(
273    internal => 'device::bgp::peer::count',
274    spec => 'count-bgp-peers',
275    alias => undef,
276    help => 'Count the number of BGP peers',
277);
278$plugin->add_mode(
279    internal => 'device::bgp::peer::watch',
280    spec => 'watch-bgp-peers',
281    alias => undef,
282    help => 'Watch BGP peers appear and disappear',
283);
284$plugin->add_mode(
285    internal => 'device::bgp::peer::list',
286    spec => 'list-bgp-peers',
287    alias => undef,
288    help => 'Show BGP peers known to this device',
289);
290$plugin->add_mode(
291    internal => 'device::bgp::prefix::count',
292    spec => 'count-bgp-prefixes',
293    alias => undef,
294    help => 'Count the number of BGP prefixes (for specific peer with --name)',
295);
296$plugin->add_mode(
297    internal => 'device::ospf::neighbor::status',
298    spec => 'ospf-neighbor-status',
299    alias => undef,
300    help => 'Check status of OSPF neighbors',
301);
302$plugin->add_mode(
303    internal => 'device::ospf::neighbor::watch',
304    spec => 'watch-ospf-neighbors',
305    alias => undef,
306    help => 'Watch OSPF neighbors appear and disappear',
307);
308$plugin->add_mode(
309    internal => 'device::ospf::neighbor::list',
310    spec => 'list-ospf-neighbors',
311    alias => undef,
312    help => 'Show OSPF neighbors',
313);
314$plugin->add_mode(
315    internal => 'device::eigrp::peer::count',
316    spec => 'count-eigrp-peers',
317    alias => undef,
318    help => 'Count the number of EIGRP peers',
319);
320$plugin->add_mode(
321    internal => 'device::eigrp::peer::status',
322    spec => 'eigrp-peer-status',
323    alias => undef,
324    help => 'Check status (existance) of EIGRP peers',
325);
326$plugin->add_mode(
327    internal => 'device::eigrp::peer::watch',
328    spec => 'watch-eigrp-peers',
329    alias => undef,
330    help => 'Watch EIGRP peers appear and disappear',
331);
332$plugin->add_mode(
333    internal => 'device::eigrp::peer::list',
334    spec => 'list-eigrp-peers',
335    alias => undef,
336    help => 'Show EIGRP peers',
337);
338$plugin->add_mode(
339    internal => 'device::ha::status',
340    spec => 'ha-status',
341    alias => undef,
342    help => 'Check the status of a clustered setup',
343);
344$plugin->add_mode(
345    internal => 'device::ha::role',
346    spec => 'ha-role',
347    alias => undef,
348    help => 'Check the role in a ha group',
349);
350$plugin->add_mode(
351    internal => 'device::svn::status',
352    spec => 'svn-status',
353    alias => undef,
354    help => 'Check the status of the svn subsystem',
355);
356$plugin->add_mode(
357    internal => 'device::mngmt::status',
358    spec => 'mngmt-status',
359    alias => undef,
360    help => 'Check the status of the management subsystem',
361);
362$plugin->add_mode(
363    internal => 'device::process::status',
364    spec => 'process-status',
365    alias => undef,
366    help => 'Check the status of the running processes'
367);
368$plugin->add_mode(
369    internal => 'device::fw::policy::installed',
370    spec => 'fw-policy',
371    alias => undef,
372    help => 'Check the installed firewall policy',
373);
374$plugin->add_mode(
375    internal => 'device::fw::policy::connections',
376    spec => 'fw-connections',
377    alias => undef,
378    help => 'Check the number of firewall policy connections',
379);
380$plugin->add_mode(
381    internal => 'device::lb::session::usage',
382    spec => 'session-usage',
383    alias => undef,
384    help => 'Check the session limits of a load balancer',
385);
386$plugin->add_mode(
387    internal => 'device::security',
388    spec => 'security-status',
389    alias => undef,
390    help => 'Check if there are security-relevant incidents',
391);
392$plugin->add_mode(
393    internal => 'device::lb::pool::completeness',
394    spec => 'pool-completeness',
395    alias => undef,
396    help => 'Check the members of a load balancer pool',
397);
398$plugin->add_mode(
399    internal => 'device::lb::pool::connections',
400    spec => 'pool-connections',
401    alias => undef,
402    help => 'Check the number of connections of a load balancer pool',
403);
404$plugin->add_mode(
405    internal => 'device::lb::pool::complections',
406    spec => 'pool-complections',
407    alias => undef,
408    help => 'Check the members and connections of a load balancer pool',
409);
410$plugin->add_mode(
411    internal => 'device::wideip::status',
412    spec => 'wideip-status',
413    alias => undef,
414    help => 'Check the status of F5 Wide IPs',
415);
416$plugin->add_mode(
417    internal => 'device::lb::pool::list',
418    spec => 'list-pools',
419    alias => undef,
420    help => 'List load balancer pools',
421);
422$plugin->add_mode(
423    internal => 'device::vip::list',
424    spec => 'list-vips',
425    alias => undef,
426    help => 'List load balancer vips',
427);
428$plugin->add_mode(
429    internal => 'device::vip::watch',
430    spec => 'watch-vips',
431    alias => undef,
432    help => 'Watch load balancer vips',
433);
434$plugin->add_mode(
435    internal => 'device::vip::watch',
436    spec => 'watch-vips',
437    alias => undef,
438    help => 'Watch load balancer vips',
439);
440$plugin->add_mode(
441    internal => 'device::vip::connect',
442    spec => 'connect-vips',
443    alias => ['connected-vips'],
444    help => 'Check connectivity with load balancer vips',
445);
446$plugin->add_mode(
447    internal => 'device::licenses::validate',
448    spec => 'check-licenses',
449    alias => undef,
450    help => 'Check the installed licences/keys',
451);
452$plugin->add_mode(
453    internal => 'device::users::count',
454    spec => 'count-users',
455    help => 'Count the (connected) users/sessions',
456);
457$plugin->add_mode(
458    internal => 'device::config::status',
459    spec => 'check-config',
460    alias => undef,
461    help => 'Check the status of configs (cisco, unsaved config changes)',
462);
463$plugin->add_mode(
464    internal => 'device::connections::check',
465    spec => 'check-connections',
466    alias => undef,
467    help => 'Check the quality of connections',
468);
469$plugin->add_mode(
470    internal => 'device::connections::count',
471    spec => 'count-connections',
472    alias => ['count-connections-client', 'count-connections-server', 'count-sessions'],
473    help => 'Check the number of connections/sessions (-client, -server is possible)',
474);
475$plugin->add_mode(
476    internal => 'device::cisco::fex::watch',
477    spec => 'watch-fexes',
478    alias => undef,
479    help => 'Check if FEXes appear and disappear (use --lookup)',
480);
481$plugin->add_mode(
482    internal => 'device::hardware::chassis::health',
483    spec => 'chassis-hardware-health',
484    alias => undef,
485    help => 'Check the status of stacked switches and chassis, count modules and ports',
486);
487$plugin->add_mode(
488    internal => 'device::wlan::aps::status',
489    spec => 'accesspoint-status',
490    alias => undef,
491    help => 'Check the status of access points',
492);
493$plugin->add_mode(
494    internal => 'device::wlan::aps::count',
495    spec => 'count-accesspoints',
496    alias => undef,
497    help => 'Check if the number of access points is within a certain range',
498);
499$plugin->add_mode(
500    internal => 'device::wlan::aps::watch',
501    spec => 'watch-accesspoints',
502    alias => undef,
503    help => 'Check if access points appear and disappear (use --lookup)',
504);
505$plugin->add_mode(
506    internal => 'device::wlan::aps::clients',
507    spec => 'count-accesspoint-clients',
508    alias => undef,
509    help => 'Check if the number of access point clients is within a certain range',
510);
511$plugin->add_mode(
512    internal => 'device::wlan::aps::list',
513    spec => 'list-accesspoints',
514    alias => undef,
515    help => 'List access points managed by this device',
516);
517$plugin->add_mode(
518    internal => 'device::phone::cmstatus',
519    spec => 'phone-cm-status',
520    alias => undef,
521    help => 'Check if the callmanager is up',
522);
523$plugin->add_mode(
524    internal => 'device::phone::status',
525    spec => 'phone-status',
526    alias => undef,
527    help => 'Check the number of registered/unregistered/rejected phones',
528);
529$plugin->add_mode(
530    internal => 'device::smarthome::device::list',
531    spec => 'list-smart-home-devices',
532    alias => undef,
533    help => 'List Fritz!DECT 200 plugs managed by this device',
534);
535$plugin->add_mode(
536    internal => 'device::smarthome::device::status',
537    spec => 'smart-home-device-status',
538    alias => undef,
539    help => 'Check if a Fritz!DECT 200 plug is on (or Comet DECT)',
540);
541$plugin->add_mode(
542    internal => 'device::smarthome::device::energy',
543    spec => 'smart-home-device-energy',
544    alias => undef,
545    help => 'Show the current power consumption of a Fritz!DECT 200 plug',
546);
547$plugin->add_mode(
548    internal => 'device::smarthome::device::consumption',
549    spec => 'smart-home-device-consumption',
550    alias => undef,
551    help => 'Show the cumulated power consumption of a Fritz!DECT 200 plug',
552);
553$plugin->add_mode(
554    internal => 'device::smarthome::device::temperature',
555    spec => 'smart-home-device-temperature',
556    alias => undef,
557    help => 'Show the temperature measured by a Fritz! compatible device',
558);
559$plugin->add_default_modes();
560$plugin->add_snmp_modes();
561$plugin->add_snmp_args();
562$plugin->add_default_args();
563$plugin->mod_arg("name",
564    help => "--name
565   The name of an interface (ifDescr) or pool or ...",
566);
567$plugin->add_arg(
568    spec => 'alias=s',
569    help => "--alias
570   The alias name of a 64bit-interface (ifAlias)",
571    required => 0,
572);
573$plugin->add_arg(
574    spec => 'ifspeedin=i',
575    help => "--ifspeedin
576   Override the ifspeed oid of an interface (only inbound)",
577    required => 0,
578);
579$plugin->add_arg(
580    spec => 'ifspeedout=i',
581    help => "--ifspeedout
582   Override the ifspeed oid of an interface (only outbound)",
583    required => 0,
584);
585$plugin->add_arg(
586    spec => 'ifspeed=i',
587    help => "--ifspeed
588   Override the ifspeed oid of an interface",
589    required => 0,
590);
591$plugin->add_arg(
592    spec => 'role=s',
593    help => "--role
594   The role of this device in a hsrp group (active/standby/listen)",
595    required => 0,
596);
597$plugin->add_arg(
598    spec => 'nosensors',
599    help => "--nosensors
600   Skip tables with voltage/current sensors (Nexus)",
601    required => 0,
602    hidden => 1,
603);
604
605$plugin->getopts();
606$plugin->classify();
607$plugin->validate_args();
608
609if (! $plugin->check_messages()) {
610  $plugin->init();
611  if (! $plugin->check_messages()) {
612    $plugin->add_ok($plugin->get_summary())
613        if $plugin->get_summary();
614    $plugin->add_ok($plugin->get_extendedinfo(" "))
615        if $plugin->get_extendedinfo();
616  }
617} elsif ($plugin->opts->snmpwalk && $plugin->opts->offline) {
618  ;
619} else {
620  ;
621}
622my ($code, $message) = $plugin->opts->multiline ?
623    $plugin->check_messages(join => "\n", join_all => ', ') :
624    $plugin->check_messages(join => ', ', join_all => ', ');
625$message .= sprintf "\n%s\n", $plugin->get_info("\n")
626    if $plugin->opts->verbose >= 1;
627
628$plugin->nagios_exit($code, $message);
629