#!/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 [-i $naghostname.cfg 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 # id of switchport padded with zeroes according to port number # this isnt real padding yet, obviously. wc -c on numports will do though typeset -Z02 idpad for id in $( /usr/local/bin/snmpwalk -c public -v 1 $naghostname_ip IF-MIB::ifIndex | awk '{print $NF}' ) do ifType="$(snmpget -c public -v 1 192.168.10.35 IF-MIB::ifType.$id | awk '{print $NF}' | cut -f1 -d\( )" if [ "X${ifType}" = "XethernetCsmacd" ] || [ "X${ifType}" = "XgigabitEthernet" ] then idpad="$id" 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