Ad Widget

Collapse

SNMP LLD item names on a router

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nixdummy
    Junior Member
    • Mar 2013
    • 13

    #1

    SNMP LLD item names on a router

    Hello everyone!

    I need help in creating a correct item name with corresponding IP address for a router. My intention is to auto add a "pinger" for each router interface with corresponding name, like this:
    - ping_ISP1 (icmpping[1.1.1.1]), ping_ISP2 (icmpping[2.2.2.2]), ping_BRIDGE0 (icmpping[10.0.50.1])

    Here's what I did:

    - made a template with SNMP LLD discovery:
    Name: FACE_NAME_ADDR
    Type: SNMPv2 agent
    Key: ifAddr
    SNMP OID: discovery[{#FAD},.1.3.6.1.2.1.4.20.1.1, {#FIX},.1.3.6.1.2.1.4.20.1.2, {#FNA}, IF-MIB::ifDescr]

    - inside the discovery rule, there are two item prototypes:
    first:
    Name: ping_{#FIX}
    Type: Simple check
    Key: icmpping[{#FAD}]
    Type of information: Numeric (unsigned)

    second:
    Name: name_{#FIX}
    Type: SNMPv2 agent
    Key: name.[{#FIX}]
    SNMP OID: .1.3.6.1.2.1.2.2.1.2.{#FIX}
    Type of information: Text

    In that way it works ok - but that's not what I need. The described rule creates 3 pingers and 3 name-items:

    ping_1 (icmpping[1.1.1.1])
    ping_3 (icmpping[2.2.2.2])
    ping_8 (icmpping[10.0.70.1])

    name_1 {value is ISP1}
    name_3 {value is ISP2}
    name_8 {value is BRIDGE0}

    What I need is a combination of those two items.
    I tried:
    - changing the second prototype to name_{#FNA}
    - changing discovery rule to discovery[{#FAD},.1.3.6.1.2.1.4.20.1.1, {#FIX},.1.3.6.1.2.1.4.20.1.2, {#FNA}, .1.3.6.1.2.1.2.2.1.2.{#FIX}]
    - using standard {#SNMPINDEX} macro
    - searching ZabbixExchange
    - searching this forum
    with no result.

    Is there a way to solve this? Or maybe an interactive way to resolve macro values?
  • berthawatts
    Junior Member
    • Apr 2019
    • 1

    #2
    Can I do this on 192-168-1-1 IP?
    Last edited by berthawatts; 15-06-2019, 19:42.

    Comment

    • nixdummy
      Junior Member
      • Mar 2013
      • 13

      #3
      Although it's not the answer I searched - yes, you can do it on "192.168.1.1".

      Here's how it works.
      You add a host in your zabbix instance somehow (I do it automatically by reception of a certain SNMP trap). A host should have at least one IP address (default interface), and if you want to interact with it over SNMP, an additional "SNMP address" (SNMP interface) - that's where you put your "192.168.1.1" in. Be sure that your device runs an SNMP-agent and "listens" for requests on that address.

      After the host is added and configured, you can do a "deep scan" of it. It is called "Low Level Discovery" or LLD. I use SNMP LLD to find all interface names and addresses of a router.

      In the "discovery" tab of yor host, you should create a new "discovery rule". Beside a name and type (SNMP) of this rule, the most important is to tell zabbix what you're looking for.

      I know that interface names are beyond the "IF-MIB::ifDescr" variable (.1.3.6.1.2.1.2.2.1.2 - OID), same about addresses - "IP-MIB::ipAddrEntry" (.1.3.6.1.2.1.4.20.1.1) and interface numbers to which the addresses are assigned "IP-MIB::ipAdEntIfIndex" (.1.3.6.1.2.1.4.20.1.2). So my discovery rule walks all these variables and stores the obtained values in corresponding "MACROS": {#FNA} - names, {#FAD} - addresses, {#FIX} - index-of-interface-with-this-address (sorry for the long name).
      In the rule it looks like this:

      discovery[{#FAD},.1.3.6.1.2.1.4.20.1.1, {#FIX},.1.3.6.1.2.1.4.20.1.2, {#FNA}, IF-MIB::ifDescr]

      After the discovery is done, you can auto-create items on this host to watch. It is done in the "item prototypes" section of the discovery rule. For testing I made two item prototypes - one is a "pinger", another is "interface-name".
      In an item prototype you can use the stored values from the discovery - so the "pinger" prototype has the name "ping_{index-of-interface}", and checks the {address-of-interface} for availability.

      But don't need "pingers" named ping_1, ping_2, ping_8. I need ping_WAN, ping_LAN, ping_L2TP1. Based on the names (NOT NUMBERS!) I'll create triggers.
      The names will be every time the same, but the indexes may vary.

      I already made a custom discovery with a python script - but that's not right.
      Should'nt there be a zabbix feature to do this, or is it another boring "FEATURE REQUEST"?

      Comment


      • Randomiser
        Randomiser commented
        Editing a comment
        Hello . can share the discovery script
    • nixdummy
      Junior Member
      • Mar 2013
      • 13

      #4
      (To Randomiser) Here you go:

      #!/usr/bin/python
      from pyzabbix import ZabbixAPI
      import netsnmp
      import sys
      import time

      ZABBIX_SERVER = 'http://localhost/api_jsonrpc.php'
      z = ZabbixAPI(ZABBIX_SERVER)
      z.session.verify = False
      z.login('USERNAME', 'PASSWORD')

      # Get the address from zabbix: custom.discovery[{HOST.IP}]
      SaIP = sys.argv[1]

      # Get INDEXES of interfaces with corresponding IP addresses in the OIDs
      OID = ".1.3.6.1.2.1.4.20.1.2"
      Vars = netsnmp.VarList(netsnmp.Varbind(OID))
      sess = netsnmp.Session(Version = 2, DestHost = SaIP, Community = 'public')
      sess.walk(Vars)

      # Any custom discovery should return a JSON output starting with '{"data":
      # followed by an array of parameters ['']
      # the "item.val" has the index, and "item.iid" the ip address of a single interface
      json = ['{"data":[']
      for item in Vars:
      name = netsnmp.snmpget('.1.3.6.1.2.1.2.2.1.2.'+item.val, Version=2, DestHost=SaIP, Community='public')[0]
      json.append('{"{#IFNAME}":"'+name+'","{#IFADDRESS} ":"'+item.iid+'"},')

      # JSON ready - printing it
      json.append('{}]}')
      for i in json:
      print(i)

      # after printing it we want to stop the discovery
      # getting "hid" - the 'hostid' by IP address
      # getting "did" - the 'discoveryid' (itemid) bound to this host
      hid=z.hostinterface.get(filter={'ip':SaIP})[0]['hostid']
      did=z.discoveryrule.get(filter={'hostid':hid})[0]['itemid']

      # disabling discovery
      z.discoveryrule.update({'itemid':did,'status':'1'} )

      Comment

      • nixdummy
        Junior Member
        • Mar 2013
        • 13

        #5
        To make it work you should put it in '/usr/local/share/zabbix/externalscripts', use discovery type - external check, key - your_script_name[{HOST.IP}]

        Comment

        • jonsbtran
          Banned
          • Sep 2019
          • 2

          #6
          Originally posted by berthawatts
          Can I do this on 192.168.1.1 IP?
          192.168.1.1 ? website ? Router admin panel man
          Last edited by jonsbtran; 15-09-2019, 03:02.

          Comment

          Working...