Ad Widget

Collapse

Help with JSON file and Discovery Rule

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • redpeppers
    Junior Member
    • Dec 2015
    • 8

    #1

    Help with JSON file and Discovery Rule

    I am having issues with discovery item being created. I am using the discovery rule that is looking at a external script to find specific interface OID index numbers. The items are not getting created and I am not sure why. There are not errors in the logs or on the GUI. Please excuse the ignorance as this is my first attempt at creating a script. All help is appreciated.

    I have created a file that contains the output of an snmpwalk ifDesc index...

    I have then created a php script that outputs the results after filtering based on a regex....

    ################################
    #!/usr/bin/php
    <?php

    function parse_snmp_data($line) {
    $snmp_info = [];

    if (preg_match_all('/\.(\d+) "?([^"\r\n]*)/', $line, $matches)) {
    foreach ($matches[1] as $key => $match) {
    $snmp_info['{#SNMPINDEX}'] = trim($match);
    }

    if (isset($matches[2]) && $matches[2]) {
    $snmp_info['{#SNMPVALUE}'] = trim($matches[2][0]);
    }
    }

    if (count($snmp_info) == 2) {
    return $snmp_info;
    }
    }

    $output = ['data' => []];
    $handle = fopen("snmpwalk.txt", "r");
    if ($handle) {
    $i = 0;
    while (($line = fgets($handle)) !== false) {
    if (strstr(strtolower($line), 'pon') && !strstr(strtolower($line), 'ont')) {
    $output['data'][$i] = parse_snmp_data($line);
    $i++;
    }
    }

    fclose($handle);

    print json_encode($output);
    } else {
    echo "Error opening file";
    }
    ################################################

    When testing the php script from the CLI everything works fine...

    [bash#]./parsesnmpwalkfile.discovery
    {"data":[{"{#SNMPINDEX}":"1600001","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 16, Pon: 1"},{"{#SNMPINDEX}":"1600002","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 16, Pon: 2"},{"{#SNMPINDEX}":"1600003","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 16, Pon: 3"},{"{#SNMPINDEX}":"1600004","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 16, Pon: 4"},{"{#SNMPINDEX}":"1700001","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 17, Pon: 1"},{"{#SNMPINDEX}":"1700002","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 17, Pon: 2"},{"{#SNMPINDEX}":"1700003","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 17, Pon: 3"},{"{#SNMPINDEX}":"1700004","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 17, Pon: 4"},{"{#SNMPINDEX}":"1700005","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 17, Pon: 5"},{"{#SNMPINDEX}":"1700006","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 17, Pon: 6"},{"{#SNMPINDEX}":"1700007","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 17, Pon: 7"},{"{#SNMPINDEX}":"1700008","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 17, Pon: 8"},{"{#SNMPINDEX}":"1800001","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 18, Pon: 1"},{"{#SNMPINDEX}":"1800002","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 18, Pon: 2"},{"{#SNMPINDEX}":"1800003","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 18, Pon: 3"},{"{#SNMPINDEX}":"1800004","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 18, Pon: 4"},{"{#SNMPINDEX}":"1800005","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 18, Pon: 5"},{"{#SNMPINDEX}":"1800006","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 18, Pon: 6"},{"{#SNMPINDEX}":"1800007","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 18, Pon: 7"},{"{#SNMPINDEX}":"1800008","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 18, Pon: 8"},{"{#SNMPINDEX}":"2000001","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 20, Pon: 1"},{"{#SNMPINDEX}":"2000002","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 20, Pon: 2"},{"{#SNMPINDEX}":"2000003","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 20, Pon: 3"},{"{#SNMPINDEX}":"2000004","{#SNMPVALUE}":"= STRING: Shelf: 1, Slot: 20, Pon: 4"}]}

    I then created a Discovery Rule on the GUI with the fields...

    NAME: Dis Test php snmp w/ regex
    TYPE: External Check
    KEY: parsesnmpwalkfile.discovery
    UPDATE INTERVAL: 1m

    I then created a Discovery Item under the Discovery Rule...

    NAME: Interface Operational Status - {#SNMPVALUE}
    TYPE: SNMPv2 agent
    KEY: test.ifOperationalStats.[{#SNMPINDEX}]
    SNMP OID: IF-MIB::ifOperStatus.{#SNMPINDEX}
    SNMP COMMUNITY: {$SNMP_COMMUNITY}
    PORT:
    TYPE OF INFORMATION: Character
    UPDATE INTERVAL: 1m
    HSP: 90d


  • kloczek
    Senior Member
    • Jun 2006
    • 1771

    #2
    Why are you using custom php script to sample SNMP data if zabbix has native SNMP support with SNMP discovery OOTB?
    http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
    https://kloczek.wordpress.com/
    zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
    My zabbix templates https://github.com/kloczek/zabbix-templates

    Comment

    • redpeppers
      Junior Member
      • Dec 2015
      • 8

      #3
      Because the ifDesc index of the particular host which I am snmpwaking is extremely large. There is 70+ of this type of device I must monitor. I am worried about scalability.

      Comment

      • kloczek
        Senior Member
        • Jun 2006
        • 1771

        #4
        Originally posted by redpeppers
        Because the ifDesc index of the particular host which I am snmpwaking is extremely large. There is 70+ of this type of device I must monitor. I am worried about scalability.
        Moment. So do you think that your php script which is using libsnmp is more saleable than the same library usage written straight in C?
        http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
        https://kloczek.wordpress.com/
        zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
        My zabbix templates https://github.com/kloczek/zabbix-templates

        Comment

        • redpeppers
          Junior Member
          • Dec 2015
          • 8

          #5
          I ended up going a different route and just calling against a different OID index that contained the info I could use to reference the item prototypes I needed. Thanks for the reply.

          Comment

          Working...