Ad Widget

Collapse

Link down control on ports using SNMPTRAP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • efrain02
    Banned
    • Apr 2011
    • 81

    #1

    Link down control on ports using SNMPTRAP

    In order to know if a port is down you need to use snmptrap, for this you need to do the installation explained on the wiki:

    Code:
    http://www.zabbix.com/wiki/howto/monitor/snmp/snmptraps
    We are going to use the next script. The script work by:
    • Searching the name and id of the host in the data base using the ip.
    • Using the id, search for the description of the item, in wich the latest value is the port down.
    • Building the name of a key that will add the trap as follows key = “<item_with_last_value_as_port>_linkDown”
    • If it doesn’t find the ip, it will add the snmptrap to the default host named snmptraps.
    • If it finds the ip, but doesn’t find the item, it will save the trap on the default host named snmptraps.

    Code:
    #!/bin/bash
    #
    
    ZABBIX_SERVER="localhost";
    ZABBIX_PORT="10051";
    ZABBIX_SENDER="/usr/local/bin/zabbix_sender";
    KEY2="_"
    KEY3="linkDown"
    KEY="snmptraps";
    HOST="snmptraps";
    # END OF CONFIGURATION
    
    read hostname
    read ip
    read uptime
    read oid
    read address
    read community
    read enterprise
    
    address=`echo $address|cut -f2 -d' '`
    enterprise=`echo $enterprise|cut -f2 -d' '`
    oid=`echo $oid|cut -f11 -d'.'`
    community=`echo $community|cut -f2 -d'"'`
    
    $zabbixuser=”MyUser”
    $zabbixpass=”MyPass”
    ZABBIXHOSTID=$(echo "select hostid, host from zabbix.hosts where ip=\"$hostname\" order by 'hostid' limit 1;" | mysql -N -u $zabbixuser –p$zabbixpass zabbix)
    
    ZABBIXID=$(echo $ZABBIXHOSTID | cut -d" " -f1)
    ZABBIXHOST=$(echo $ZABBIXHOSTID | cut -d" " -f2-)
    [[ "$ZABBIXHOST" ]] && {
    TRAPOID=$(echo $oid | cut -d: -f3)
    	ZABBIXITEM=$(echo "select description from zabbix.items where hostid=\"$ZABBIXID\" AND lastvalue=\"$community\" order by 'hostid' limit 1;" | mysql -N -u $zabbixuser –p$zabbixpass zabbix)
    
    	if [ "$ZABBIXITEM" ]; then
                KEY="$ZABBIXITEM$KEY2$KEY3"
                HOST=$ZABBIXHOST
            fi
    
    	ZABBIXITEM=$(echo "select key_ from zabbix.items where	key_=\"$TRAPOID\" and hostid=\"$ZABBIXID\";" | mysql -N -u $zabbixuser –p$zabbixpass zabbix)
    	if [ "$ZABBIXITEM" ]; then
    	    KEY=$ZABBIXITEM
    	fi
    	    HOST=$ZABBIXHOST
    }
    str="$hostname $address $community $enterprise $oid"
    
    $ZABBIX_SENDER -z $ZABBIX_SERVER -p $ZABBIX_PORT -s $HOST -k $KEY -o "$str"
    Once you do all that, you need to create the follow items on the Template SNMPv2:

    Default key to snmptraps:

    Key to check if a port is down (you need to create this for every ifDescr):

    Trigger of the link down:
Working...