Ad Widget

Collapse

Executing snmptrap.sh ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • monolithic
    Junior Member
    • May 2009
    • 21

    #1

    Executing snmptrap.sh ?

    Hey everyone,

    Spent the entire weekend frustrated with that, thought i'd post this. I've looked at several threads regarding this and there a few customized snmptrap.sh scripts but those threads were relatively old, so i'm not sure if the new script that came with 1.6.4 worked out of the box.

    Here is what i've done.

    This is my /etc/snmptrapd.conf:
    traphandle default /bin/bash /usr/local/sbin/snmptrap.sh
    ignoreauthfailure 1
    logoption f /var/log/snmpd2.log
    disableAuthorization yes



    This is my /usr/local/sbin/snmptrap.sh:

    ZABBIX_SERVER="127.0.0.1";
    ZABBIX_PORT="10051";

    ZABBIX_SENDER="/usr/local/sbin/zabbix_sender";

    KEY="snmptraps";
    HOST="snmptraps";

    # END OF CONFIGURATION

    read hostname
    read ip
    read uptime
    read oid
    read address
    read community
    read enterprise

    oid=`echo $oid|cut -f2 -d' '`
    address=`echo $address|cut -f2 -d' '`
    community=`echo $community|cut -f2 -d' '`
    enterprise=`echo $enterprise|cut -f2 -d' '`

    oid=`echo $oid|cut -f11 -d'.'`
    community=`echo $community|cut -f2 -d'"'`

    str="$hostname $address $community $enterprise $oid"

    $ZABBIX_SENDER $ZABBIX_SERVER $ZABBIX_PORT $HOST $KEY "$str"




    My host in zabbix is setup as the following:
    Name: snmptraps
    IP Address: 0.0.0.0
    Connect to: IP Address
    Zabbix agent port: 10051
    Status: Monitored


    I then created an item under this host:
    Description: test
    Type: Zabbix trapper
    Key: snmptraps
    Type of information: Character
    Status: Active




    I then executed snmptrapd with this command:
    #/usr/local/sbin/snmptrapd -C -c /etc/snmptrapd.conf -Lf /var/log/net-snmptrapd.conf

    I'm tailing /var/log/net-snmptrapd.conf as well as /var/log/snmpd2.log and /tmp/zabbix_server for any errors.

    I then issue a test snmp command to make sure that the snmptrap is receving the info:
    #snmptrap -v1 -cpublic localhost .1.3.6.1.6.3.1.1.5.2 0 0 "" "" .1.3.6.1.4.1 s "hello"

    Both my log files get logged with this "2009-06-08 12:07:35 0.0.0.0(via UDP: [0.0.0.0]->[127.0.0.1]:-21909) TRAP, SNMP v1, community public
    SNMPv2-MIB::warmStart Cold Start Trap (0) Uptime: 3 days, 22:53:21.68
    SNMPv2-SMI::enterprises = STRING: "hello"



    I then check the overview for my snmptraps host and nothing shows. I suspect that it is either not executing the snmptraps.sh script or there is an issue with my configuration. So snmptrapd is working but i'm not sure if it is executing that script. Is there any way I can determine if it is indeed launching the script or if the problem lies with somwhere in the script? I am on Solaris 10 BTW.

    Can anyone point me in the right direction here, I've been looking at this stuff for a very long time. Everything above is copied and pasted. I don't think there are any misconfigs but i'm sure there is somewhere.

    I really appreciate the help and support from this forum! Thanks in advanced!!!
  • monolithic
    Junior Member
    • May 2009
    • 21

    #2
    I've done some more investigating.

    I was able to get the the zabbix_sender to manually work by entering the following command:
    #/usr/local/sbin/zabbix_sender -v -z 127.0.0.1 -p 10051 -s snmptraps -k snmptraps -o "test trap manual"

    It then shows:
    Info from server: "Processes 1 Failed 0 Total 1 Seconds spent 0.005504"
    sent: 1; skipped: 0; total: 1

    I then go to look at my snmptraps host, it shows up!

    I then go to run the script manually:
    #/usr/local/sbin/snmptrap.sh
    (it stays blank)
    i type:
    hostname=testhost
    ip=127.0.0.1
    oid=.3.3.4.2.1.3.5
    address=192.168.0.1
    community=public
    and then it says
    usage: zabbix_sender [-Vhv] {[-zpsI] -ko | [-zpI] -i <file>} [-c <file>]

    I take it there is an error in the snmptraps.sh script then? If anyone would be so kind as to pointing me in the right direction? Thanks again!!!

    Comment

    • monolithic
      Junior Member
      • May 2009
      • 21

      #3
      hey everyone,

      can someone please push me in the right direction?

      I have modified my snmptrap.sh script to the following:
      #!/bin/bash

      ZABBIX_SERVER="127.0.0.1";
      ZABBIX_PORT="10051";

      ZABBIX_SENDER="/usr/local/sbin/zabbix_sender";
      ZABBIX_HOSTSFILE="/usr/local/sbin/zabbixhosts";

      KEY="snmptrap";

      DEFAULTHOST="Default_Trapper";

      read hostname
      read ip
      read uptime
      read oid
      read var1
      read var2
      read var3

      oid=`echo $oid|cut -f2 -d' '`

      ZABBIX_HOST=`grep "[$hostname]" $ZABBIX_HOSTSFILE`

      if [ $? -eq 0 ]; then
      hostname=`echo "$ZABBIX_HOST" | cut -f2 -d]` else
      hostname="$DEFAULTHOST"
      fi

      str="$oid $var1 $var2 $var3"
      echo " " > /tmp/snmptrapzabbix.log
      echo $ZABBIX_SERVER "ZABBIX_SERVER" >> /tmp/snmptrapzabbix.log
      echo $hostname "HOSTNAME" >> /tmp/snmptrapzabbix.log
      echo $KEY "KEY" >> /tmp/snmptrapzabbix.log
      echo $str >> /tmp/snmptrapzabbix.log
      result=`$ZABBIX_SENDER -z $ZABBIX_SERVER -p $ZABBIX_PORT -s $hostname -k $KEY -o
      "$str"`



      My /usr/local/sbin/zabbixhosts file is the following:
      [192.168.2.202]esx1-ilo
      [192.168.2.5]switch1


      I have hosts for esx1-ilo as well as switch1 and items with snmptrap and zabbix trapper.

      i also have a Default_Trapper host setup with the same key.

      I tail the /tmp/snmptrapzabbix.log file and when i do tests from the localhost (zabbix) server, it sends it right to the Default_trapper which is good.

      However when i execute an snmptrap from switch1 or esx1-ilo they also go to the Default_trapper.

      Can someone tell me what i am missing???????

      I run this command: grep (hostname)( i have tired IP address as well) /usr/local/sbin/zabbixhosts | cut -f2 -d] and it always gives me the correct hostname, so i'm missing something somewhere.

      Can anyone lend me a helping hand! I apolgize if I am redundant, but I've been working on this project for 3 weeks and this is the final step to complete the monitoring in my environment. Thanks again for any help that any can provide!!!

      Comment

      • monolithic
        Junior Member
        • May 2009
        • 21

        #4
        So it looks like the hostname is not being read correctly.

        If I send a test locally from the zabbix box, the hostname shows as localhost

        However if I send from other esx1-ilo and switch1 the hostname appears as the IP address in my log file.

        So for some reason the hostname is only reading the IP address. I have modified the snmptrap.sh to a bunch of different things to try and manipulate it to show as the hostname and not the IP address.

        Anyone know how I can see or tell or trick the hostname to actually be the real hostname so I don't have to use IP addresses for my hosts in the zabbix frontend?

        Any help at all would be greatly appreciated!! Thanks again!!

        Comment

        • richlv
          Senior Member
          Zabbix Certified Trainer
          Zabbix Certified SpecialistZabbix Certified Professional
          • Oct 2005
          • 3112

          #5
          well, you have to decide what exactly do you want to do.
          you can send all snmptraps to a single host, 'snmptraps' or whatever you call it. in this case you don't need any lookups or anything else.
          you can send data to individual hosts, but then you need some kind of mapping - you can use an external mapping (maybe dns based, maybe an arbitrary list based), or you can try to hook into the zabbix db.

          if you send data to individual hosts, in most cases you'd have to create snmp items to receive data in, otherwise sent traps can be discarded.

          sending to single host is the easiest and least resources intensive, so you could start by getting that to work.
          Zabbix 3.0 Network Monitoring book

          Comment

          • exkg
            Senior Member
            Zabbix Certified Trainer
            Zabbix Certified Specialist
            • Mar 2007
            • 718

            #6
            ...my 2 cents ...

            You can search for 'snmptrap.pl' in ZABBIX forum .. for us was the best way to get snmptraps in ZABBIX.



            []ss,
            Luciano
            --
            Luciano Alves
            www.zabbix.com
            Brazil | México | Argentina | Colômbia | Chile
            Zabbix Performance Tuning

            Comment

            Working...