All pastes #1214960 Raw Edit

darkfader

public text v1 · immutable
#1214960 ·published 2008-09-30 18:42 UTC
rendered paste body
#!/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 <switch name> [-i <switch ip address] -c "Description String"# Variables#naghostname="vendor-model-num"	# switch hostname as used by nagios##numports=16			# number of switchports# will be enumerated via snmp, unless specified# there are a few pieces that would not work with the switch being unreachable# needs to some consideration# also it seems some switches allow for per-vlan statistics and other stuff# that will be shown as interfaces and need to be filtered, probably via# iftype##naghostname_ip="192.168."	# our resolver mustn't be right so allow explicit ip for the mrtg base # filename.  later, if  not supplied, assume we're in default land and # nslookup it.naghostname="msu1800-1"	naghostname_ip="192.168.10.35"	#numports=$(/usr/local/bin/snmpget -c public -v 1 $naghostname_ip IF-MIB::ifNumber.0 | awk '{print $4}')numports=26nagdescr="Nortel Metro Ethernet Services Unit 1800"#naghostname="lcs-gs9420-1"#naghostname_ip="192.168.10.36"#numports=$(/usr/local/bin/snmpget -c public -v 1 $naghostname_ip IF-MIB::ifNumber.0 | awk '{print $4}')#nagdescr="Longshine GS9420"SNMPCMD="snmpget -c public -v 1"SNMPWCMD="snmpwalk -c public -v 1"echo "define host{        use             generic-switch        host_name       $naghostname        alias           $nagdescr        address         $naghostname_ip        hostgroups      switches        }" > $naghostname.cfgecho "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 thoughtypeset -Z02 idpadfor 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" ]thenidpad="$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.cfgif [ $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"fifidoneecho "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