Ad Widget

Collapse

Update host profile fields using SNMP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • generix
    Junior Member
    • Sep 2011
    • 9

    #1

    Update host profile fields using SNMP

    We needed the ability to sync SNMP data fields into host profile (and extended profile).
    The problem was solved using a template and the following external script.
    Actually it is quite simple but I can imagine some others will face similar tasks.

    Attached there's a readme file with further information.

    Code:
    #!/bin/bash
    
    LOG=/tmp/snmp2hostprofile.log
    dbuser=zabbix
    dbpass=password
    dbname=zabbix
    dbhost=localhost
    
    OIFS=$IFS
    IFS=","
    
    declare -a args=($*)
    
    IFS=$OIFS
    
    if [ ${#args[*]} -eq 5 ]; then
        snmpcmd="snmpget ${args[1]} ${args[0]} ${args[2]}"
        snmpoutput=` eval ${snmpcmd} `
        tmp1="${snmpoutput#* = }"
        value=${tmp1#*: }
        profiletype="hosts_"${args[3]}
        profilefield=${args[4]}
        hostip=${args[0]}
        mysql --user=${dbuser} --password=${dbpass} --database=${dbname} -h ${dbhost} -e "INSERT INTO hosts_profiles (hostid, ${profilefield}) VALUES ((SELECT hostid FROM hosts WHERE ip = '${hostip}'), '${value}') ON DUPLICATE KEY UPDATE ${profilefield}='${value}';"
    fi
    
    echo ${value}
    Attached Files
    Last edited by generix; 26-09-2011, 13:42.
  • JitseH
    Junior Member
    • Oct 2011
    • 9

    #2
    Thanks for sharing this script.
    It works excellent for the standard profile.
    Before it is usable for the extended profile there must be a little correction at the query:

    Code:
    INSERT INTO [U]${profiletype}[/U] ...
    Instead of

    Code:
    INSERT INTO hosts_profiles ...

    Comment

    • generix
      Junior Member
      • Sep 2011
      • 9

      #3
      You are right.
      My bad.

      But actually it needs to be:
      Code:
      INSERT INTO ${profiletype}
      You'll find the current version attached.
      Attached Files

      Comment

      • youtube
        Junior Member
        • Oct 2011
        • 3

        #4
        that's nice script, i learning so much from that script
        Originally posted by generix
        We needed the ability to sync SNMP data fields into host profile (and extended profile).
        The problem was solved using a template and the following external script.
        Actually it is quite simple but I can imagine some others will face similar tasks.

        Attached there's a readme file with further information.

        Code:
        #!/bin/bash
        
        LOG=/tmp/snmp2hostprofile.log
        dbuser=zabbix
        dbpass=password
        dbname=zabbix
        dbhost=localhost
        
        OIFS=$IFS
        IFS=","
        
        declare -a args=($*)
        
        IFS=$OIFS
        
        if [ ${#args[*]} -eq 5 ]; then
            snmpcmd="snmpget ${args[1]} ${args[0]} ${args[2]}"
            snmpoutput=` eval ${snmpcmd} `
            tmp1="${snmpoutput#* = }"
            value=${tmp1#*: }
            profiletype="hosts_"${args[3]}
            profilefield=${args[4]}
            hostip=${args[0]}
            mysql --user=${dbuser} --password=${dbpass} --database=${dbname} -h ${dbhost} -e "INSERT INTO hosts_profiles (hostid, ${profilefield}) VALUES ((SELECT hostid FROM hosts WHERE ip = '${hostip}'), '${value}') ON DUPLICATE KEY UPDATE ${profilefield}='${value}';"
        fi
        
        echo ${value}

        Comment

        • generix
          Junior Member
          • Sep 2011
          • 9

          #5
          Version 2.0

          The script is now working under Zabbix 2.0.
          Note also the changed template.
          Attached Files
          Last edited by generix; 12-09-2012, 16:44. Reason: Just ignore this post. This feature is built into Zabbix Version 2.0.

          Comment

          Working...