Ad Widget

Collapse

Cutting Preprocessing output with Regular expression. Invalid discovery rule value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • f1g2
    Junior Member
    • Jul 2020
    • 5

    #1

    Cutting Preprocessing output with Regular expression. Invalid discovery rule value

    Dear community! I would be grateful if you could help me with my Discovery rule problem.

    My aim is to create network interface items with a discovery rule (SNMP agent type) with a name got with come string transformation. The initial interface name (got from IF-MIB::ifDescr) is to long and have some useless information in the left part.

    For example: I would like to convert "Avaya Inc., G450 Media Gateway 10/100/1000BaseTx Port 10/5" to "10/100/1000BaseTx Port 10/5". The left part "Avaya Inc., G450 Media Gateway" have to be cutted.

    What I had done?
    Discovery rules --> Preprocessing --> Preprocessing steps --> Regular expression:
    Parameters: Gateway([\s\S]*)
    Output: /1
    The result of Test is apsolutely what I axpected. But when I apply discovery I got next error message:
    "Invalid discovery rule value: cannot parse as a valid JSON object: invalid object format, expected opening character '{' or '[' at: ', SW Version 36.18.30","{#IFSPEED}":"0","{#IFADMST}":"1","{#IFA DMOPST}":"1"},{"{#SNMPINDEX}":"167774723","{#IFNO} ":"167774723","{#IFDES}":"Avaya Inc.,"

    Maybe I'm trying to go the wrong way? How could I cut a part of OID's output before it will be used to create an Item from an item prototype?

    Thank you.

    Regards,
    f1g2

    Here snmpwalk output of discovering OIDs:
    IF-MIB::ifDescr.16777216 = STRING: Avaya Inc., G450 Media Gateway, SW Version 36.18.30
    IF-MIB::ifDescr.167774723 = STRING: Avaya Inc., G450 Media Gateway, 10/100Base-Tx, FastEthernet 10/3
    IF-MIB::ifDescr.167774724 = STRING: Avaya Inc., G450 Media Gateway, 10/100Base-Tx, FastEthernet 10/4
    IF-MIB::ifDescr.211841025 = STRING: Avaya Inc., G450 Media Gateway, Vlan, Vlan 1
    IF-MIB::ifDescr.251660805 = STRING: Avaya Inc., G450 Media Gateway 10/100/1000BaseTx Port 10/5
    IF-MIB::ifDescr.251660806 = STRING: Avaya Inc., G450 Media Gateway 10/100/1000BaseTx Port 10/6
    IF-MIB::ifDescr.268438024 = STRING: Avaya Inc., G450 Media Gateway, Console port, Console-Modem
    IF-MIB::ifDescr.788531712 = STRING: Avaya Inc., G450 Media Gateway, USB port, USB-Modem
    IF-MIB::ifDescr.855640576 = STRING: Avaya Inc., G450 Media Gateway, PPP Session, USB-Modem
    IF-MIB::ifDescr.855640584 = STRING: Avaya Inc., G450 Media Gateway, PPP Session, Console
    IF-MIB::ifDescr.872417792 = STRING: Avaya Inc., G450 Media Gateway, External USB Modem, USB-Modem
    IF-MIB::ifDescr.872417800 = STRING: Avaya Inc., G450 Media Gateway, External serial Modem, Console
    IF-MIB::ifDescr.889195019 = STRING: Avaya Inc., G450 Media Gateway, 10/100Base-Tx, Services

    Click image for larger version

Name:	01.JPG
Views:	1264
Size:	49.2 KB
ID:	405000
    Click image for larger version

Name:	02.JPG
Views:	1097
Size:	80.6 KB
ID:	405001

    Click image for larger version

Name:	03.JPG
Views:	1076
Size:	79.9 KB
ID:	405002

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

    #2
    You get an error because preprocessing affects the entire received json, not one of the elements. After conversion, you get a string that is no longer filled with json.

    Comment


    • f1g2
      f1g2 commented
      Editing a comment
      Thank you for your reply, Hamardaban! So, is there way to convert a string value gotten from snmp before it will be used for item creation?
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #3
    There is a way, but it is not easy - use all the power of JS in preprocessing to convert json as you need.

    Comment


    • f1g2
      f1g2 commented
      Editing a comment
      Thank you! I will try.

    • f1g2
      f1g2 commented
      Editing a comment
      Could you take a look at my reply..
  • f1g2
    Junior Member
    • Jul 2020
    • 5

    #4
    I had written the next JS. The test item processing gives a right result, but generated items are still without changes. There are no errors while Discovery process,

    var uselessstring = "Avaya Inc., G450 Media Gateway, "
    if (value.includes(uselessstring) == true) {
    return value.replace(uselessstring, "");
    }
    else {
    return value;
    }


    Click image for larger version

Name:	02.JPG
Views:	1091
Size:	62.5 KB
ID:	405059

    Comment

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

      #5
      Normal solution! Of course not universal....
      The main thing is that it works as it should. :-)

      Comment


      • f1g2
        f1g2 commented
        Editing a comment
        >The main thing is that it works as it should.
        The main problem it doesn't work. The test is OK, but generated items are still without changes... as if there is no JS in preprocessing. ((
    • Hamardaban
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • May 2019
      • 2713

      #6
      You are testing preprocessing on a single substring, but you need to test it on the whole json! It is possible that the structure is damaged again during processing.

      Comment

      Working...