Ad Widget

Collapse

zabbixSNMP-creator.py

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • steki
    Junior Member
    • Mar 2008
    • 9

    #1

    zabbixSNMP-creator.py

    Hello,

    i had to use many SNMP devices and i hated doing all stuff manually (adding items...) so i created this small stupid script for that job. Not perfect but worked for me so enjoy

    -------- From File -----------
    after snmpwalking some device with
    snmpwalk -On -v2c -c public 192.168.1.1 > device_name.oids
    start this program with next syntax:
    zabbixSNMP-creator.py device.oids snmp_community_string
    ---------------------
    device_name.xxx syntax is used for key generation so be warned
    that all zabbix keys will be in form of device_name.ifOperStatus.1 and so on
    ---------------------
    Attached Files
  • tekknokrat
    Senior Member
    • Sep 2008
    • 140

    #2
    I am getting output with your script but then it ends with an error message of your script:
    Traceback (most recent call last):
    File "./zabbixSNMP-creator.py", line 147, in <module>
    modName, symName, suffix = mibViewController.getNodeLocation(pysnmp.proto.rfc 1902.ObjectName(oidlocal))
    File "/var/lib/python-support/python2.5/pyasn1/v1/type/base.py", line 63, in __init__
    value = self.prettyIn(value)
    File "/var/lib/python-support/python2.5/pyasn1/v1/type/univ.py", line 307, in prettyIn
    (str(value), self.__class__.__name__, why)
    pyasn1.error.PyAsn1Error: Malformed Object ID "
    at ObjectName: invalid literal for long() with base 10: '"\n'

    Comment

    • steki
      Junior Member
      • Mar 2008
      • 9

      #3
      Hi tekknokrat,

      after checking on my system (linux snmpd) it returned me same error as it happened to you reason was as that quotation mark letter on line itself
      (as debug is saying to you with: at ObjectName: invalid literal for long() with base 10: '"\n' )
      so quick fix would be to check in you "something.oids" for " as first letter
      like this for instance grep -n ^\" mygreatpc.oids will give you exact line(s) where
      it went wrong, so just fix that line(s) and it should work perfectly

      example problem:
      Code:
      .1.3.6.1.2.1.16.1.1.1.1.2 = INTEGER: 2
      .1.3.6.1.2.1.16.1.1.1.1.3 = INTEGER: 3
      .1.3.6.1.2.1.25.1.1.0 = Timeticks: (1809920) 5:01:39.20
      .1.3.6.1.2.1.25.1.2.0 = STRING: 2009-3-13,22:6:38.0,+1:0
      .1.3.6.1.2.1.25.1.3.0 = INTEGER: 1536
      .1.3.6.1.2.1.25.1.4.0 = STRING: "root=/dev/vg/lv_root splash=silent ga=0x31a
      "
      .1.3.6.1.2.1.25.1.5.0 = Gauge32: 1
      .1.3.6.1.2.1.25.1.6.0 = Gauge32: 163
      .1.3.6.1.2.1.25.1.7.0 = INTEGER: 0

      and just please patch it with code bellow as it was failing if it is missing
      Code:
      --- zabbixSNMP-creator.py-old   2008-09-23 13:59:31.000000000 +0200
      +++ zabbixSNMP-creator.py       2009-03-13 22:13:22.000000000 +0100
      @@ -212,6 +212,10 @@
             valuetype = 3
           elif re.compile("Float").match(valuetype):
             valuetype = 0
      +    elif re.compile("Ipv6AddressIfIdentifierTC").match(valuetype): # just guessing this is ok...
      +      valuetype = 3
      +    elif re.compile("InetZoneIndex").match(valuetype): # just guessing this is ok...
      +      valuetype = 3
           else:
               raise UnboundLocalError("Should NOT be here - UNKNOWN TYPE RETURNED\n\n valuetype=%s\noid=%s" % (valuetype,oidlocal))

      Comment

      • tekknokrat
        Senior Member
        • Sep 2008
        • 140

        #4
        hi steki,

        When i look in the oid file the line which causes garbage is this.

        .1.3.6.1.2.1.25.1.4.0 = STRING: "BOOT_IMAGE=vmlinuz initrd=rootfs rw root=/dev/ram0 init=/etc/preinit console=ttyS0,38400 console=tty0
        "
        Seems that snmpwalk outputs the latter quote on a newline. After joining this the creator script runs fine. Thanks

        Comment

        • steki
          Junior Member
          • Mar 2008
          • 9

          #5
          New version of zabbixSNMP-creator

          ================================================== ===
          - New things are configurable snmp version, auth , priv passhprases and
          snmp security level
          - Updated script to use new xml layout
          ================================================== ===
          Script can be downloaded from: http://github.com/bmanojlovic/zabbixSNMP-creator

          zabbixSNMP-creator is python script with you can create
          Zabbix items template in xml format which then can be imported
          into system without manual work of creating items

          Necessary tools are:
          libsmi >= 0.4.8 and
          pysnmp >=pysnmp-4.1.10

          How to use it:

          First step is to create input file with use of snmpwalk utility

          snmpwalk -On -c public -v1 192.168.1.1 . > router.oids

          This will create "source" file for this script with all "walked" elements
          Please review this file for possible errors as some of values returned from
          snmp can be multiline - fix it to be single line.

          After that just follow script help

          ------------------------

          Code:
          Usage: zabbixsnmp_creator.py [options]
          
          Options:
            --version             show program's version number and exit
            -h, --help            show this help message and exit
            -i FILENAME, --input-file=FILENAME
                                  File containing snmpwalked device 'oids=result'
           mapped
                                  values
            -o FILENAME, --output-file=FILENAME
                                  Output file where zabbix template will be written
            -v, --verbose         very long names for items
            -s SNMP_VERSION, --snmp-version=SNMP_VERSION
                                  don't print status messages to stdout
            -c public, --community=public
                                  don't print status messages to stdout
            -l SNMP_SECURITY_LEVEL, --snmp-security-level=SNMP_SECURITY_LEVEL
                                  SNMPv3 security level
            -n SNMP_SECURITY_NAME, --snmp-security-name=SNMP_SECURITY_NAME
                                  SNMPv3 security name
            -a SNMP_AUTH_PASSPHRASE, --snmp-auth-passphrase=SNMP_AUTH_PASSPHRASE
                                  SNMPv3 auth passphrase
            -p SNMP_PRIV_PASSPHRASE, --snmp-priv-passphrase=SNMP_PRIV_PASSPHRASE
                                  SNMPv3 priv passphrase
          Last edited by steki; 26-03-2010, 19:52. Reason: Add url to sript

          Comment

          • ufocek
            Senior Member
            • Aug 2006
            • 161

            #6
            Hi,

            I have a problem with generating a template for ZABBIX using your
            script, when I try generate a zabbix template xml from my oids I get
            some error:

            ./zabbixsnmp_creator.py -v -s1 -c1 -i hp1.oids -o HP-2510-48.xml
            Traceback (most recent call last):
            File "./zabbixsnmp_creator.py", line 264, in <module>
            raise UnboundLocalError("Should NOT be here - UNKNOWN TYPE
            RETURNED\n\n valuetype=%s\noid=%s" % (valuetype,oidlocal))
            UnboundLocalError: Should NOT be here - UNKNOWN TYPE RETURNED

            valuetype=OwnerString()
            oid=.1.3.6.1.2.1.16.1.1.1.20.1

            I have the same error if I create snmp version 1 or 2

            Comment

            Working...