Ad Widget

Collapse

Extract item value from strings (snmpwalk)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RobinH
    Member
    • Jul 2023
    • 55

    #1

    Extract item value from strings (snmpwalk)

    Hello!

    I am trying to extract values ​​from a router's LAN interface and which devices are connected.
    I have then tried to find different ways to do it with SNMP and what I find that does it is an snmpwalk and created an item that collects the values, but they come as several longer strings and it is only the part that contains the IP address that I am interested in.
    The number of devices may vary and the IP-adresses may also change because of DHCP.

    Result:
    .1.3.6.1.4.1.39699.123.3.2.2.2.1.2.1 = STRING: "10.0.89.100"
    .1.3.6.1.4.1.39699.123.3.2.2.2.1.2.2 = STRING: "10.0.89.149"

    Anyone who knows and knows how to proceed to clear everything except the IP address?​ ​


    Click image for larger version

Name:	image.png
Views:	1465
Size:	19.0 KB
ID:	468494

    Click image for larger version

Name:	image.png
Views:	1383
Size:	44.7 KB
ID:	468495


  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    I think it needs to be done using preprocessing
    The problem is that you have data on several lines - you can't process it just like
    that with regex, but there is an "SNMP walk to JSON" that will turn your strings into json - and then a direct path to its processing.
    You can pull out the necessary data in JS.
    What exactly do you want to do next​ - i dont know.

    Comment

    • RobinH
      Member
      • Jul 2023
      • 55

      #3
      Thank you for the reply!

      I created a SNMP walk to JSON and get this instead now:

      [{"{#SNMPINDEX}":"2","{#IFDESCR}":"10.0.89.149"},{" {#SNMPINDEX}":"1","{#IFDESCR}":"10.0.89.100"}]

      Is it possible from this kind of string?

      Comment

      • SanMonitor
        Member
        • Aug 2022
        • 48

        #4
        Originally posted by RobinH
        Thank you for the reply!

        I created a SNMP walk to JSON and get this instead now:

        [{"{#SNMPINDEX}":"2","{#IFDESCR}":"10.0.89.149"} ,{" {#SNMPINDEX}":"1","{#IFDESCR}":"10.0.89.100"}]

        Is it possible from this kind of string?
        Hey Robin,
        since you have multiple IP's in your JSON, you'll have to use a discovery rule to create an item for each IP.
        Here the Zabbix documentation 4 Discovery of SNMP OIDs (zabbix.com)​ to set this up.

        Comment

        • RobinH
          Member
          • Jul 2023
          • 55

          #5
          Hey, thank you for the reply!

          I have created a discovery rule that makes it look like this (I have added the MAC-adresses):

          [{"{#SNMPINDEX}":"1","{#IFDESCR}":"D8:EC:E5:C0:4 3:C 6","{#IFTYPE}":"10.0.89.100"},{"{#SNMPINDEX}":" 2", "{#IFDESCR}":"00:90:E8:60:15:38","{#IFTYPE}":" 10.0 .89.149"}]

          What do I do next?
          Im very new to Zabbix.​

          Comment

          • RobinH
            Member
            • Jul 2023
            • 55

            #6
            I have created Item prorotypes which looks like they work but in the item lists the collected values have the status "Not supported".
            But Zabbix has found all of them and created items?
            Click image for larger version

Name:	image.png
Views:	1351
Size:	14.9 KB
ID:	468571

            Comment

            • Hamardaban
              Senior Member
              Zabbix Certified SpecialistZabbix Certified Professional
              • May 2019
              • 2713

              #7
              Originally posted by RobinH
              I created a SNMP walk to JSON and get this instead now:

              [{"{#SNMPINDEX}":"2","{#IFDESCR}":"10.0.89.149"} ,{" {#SNMPINDEX}":"1","{#IFDESCR}":"10.0.89.100"}]

              Is it possible from this kind of string?
              Make JS priprocessing step with code
              Code:
              var inrow_string = ''
              var separator = ' '
              var val_obj = JSON.parse(value);  
              inrow_string = val_obj.reduce(function(accumulator, currentValue) {
                return accumulator["{#IFDESCR}"] + separator + currentValue["{#IFDESCR}"]
              });
              return inrow_string;​

              Comment

              • RobinH
                Member
                • Jul 2023
                • 55

                #8
                It doesnt seem to work.
                Zabbix return "SyntaxError: invalid token (line 7)" when I test it​

                Comment

                • Hamardaban
                  Senior Member
                  Zabbix Certified SpecialistZabbix Certified Professional
                  • May 2019
                  • 2713

                  #9
                  Zabbix 6.4.2 - its work!

                  OPT1:

                  Click image for larger version

Name:	изображение.png
Views:	1337
Size:	28.0 KB
ID:	468646

                  OR OPT2:


                  Click image for larger version

Name:	изображение.png
Views:	1347
Size:	25.5 KB
ID:	468645

                  The same result:


                  Click image for larger version

Name:	изображение.png
Views:	1347
Size:	28.0 KB
ID:	468644

                  Comment

                  • RobinH
                    Member
                    • Jul 2023
                    • 55

                    #10
                    Hey, thank you!
                    It worked when erased the first line

                    Comment

                    Working...