#!/usr/local/bin/ksh93 # Copyright Florian Heigl(2008) # availability / other licences upon request. i refuse to think about it now. # no warranties. # Syntax to be # nagswitch -n -g [-i $naghostname.cfg # set up generic services (ping, uptime) echo "define service{ use generic-service host_name $naghostname service_description PING service_description PING check_command check_ping!200.0,20%!600.0,60% normal_check_interval 5 retry_check_interval 1 }" >> $naghostname.cfg #set up specific services (ssh, http[s], telnet, snmp) # set up services for each port (link state, bandwidth) # to be added: # these will all be needed to make this script actually useful, as in # reducing false positives # * error counters # * full duplex / autoneg (must be adjustable to full-duplex manual for # people still living in '90s, UNLESS gigabit link) # * bandwidth monitoring right now uses random values for fast ethernet, # need to find a query link speed to get those right # * also, need to set up according to admin/oper states: # op down at scan: no notifications # admin down at scan: no active checks # id of switchport padded with two zeroes, not yet according to port number # this isnt real padding, obviously. wc -c on number of ports should # do though, but i.e. vlan ports (1026++ on my switch) should be excluded typeset -Z02 idpad for id in $( $SNMPWCMD $naghostname_ip IF-MIB::ifIndex | awk '{print $NF}' ) do ifType="$( $SNMPCMD $naghostname_ip IF-MIB::ifType.$id | awk '{print $NF}' | cut -f1 -d\( )" if [ "X${ifType}" = "XethernetCsmacd" ] || [ "X${ifType}" = "XgigabitEthernet" ] then idpad="$id" # i wonder if anyone work prefer the ifName supplied names (1/10...) # geeks probably yes, monitoring people probably not. # echo "define service{ use generic-service host_name $naghostname service_description Port $idpad Link Status check_command check_snmp!-C public -o ifOperStatus.$id -r 1 -m RFC1213-MIB } define service{ use generic-service host_name $naghostname service_description Port $idpad Bandwidth Usage check_command check_local_mrtgtraf!/usr/local/www/mrtg/${naghostname_ip}_${id}.log!AVG!1000000,1000000!5000000,5000000!10 } define servicedependency{ host_name $naghostname service_description Port $idpad Link Status dependent_host_name $naghostname dependent_service_description Port $idpad Bandwidth Usage execution_failure_criteria w,c,u notification_failure_criteria w,c,u }" >> $naghostname.cfg if [ $id = 1 ] then all_port_services="Port $idpad Link Status, Port $idpad Bandwidth Usage" else all_port_services="${all_port_services},Port $idpad Link Status, Port $idpad Bandwidth Usage" fi fi done echo "define servicedependency{ host_name $naghostname service_description PING dependent_host_name $naghostname dependent_service_description $all_port_services execution_failure_criteria w,c,u notification_failure_criteria w,c,u }" >> $naghostname.cfg