Ad Widget

Collapse

Change SNMP LLD values

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • derdeagle
    Junior Member
    • Dec 2016
    • 5

    #1

    Change SNMP LLD values

    When using LLD via SNMP a JSON like the following is returned (modified because the log didn't show the full string).

    Code:
    [
        {
          "{#SNMPINDEX}":"14",
          "{#FAN}":"temperature"
       },
       {
          "{#SNMPINDEX}":"17",
          "{#FAN}":"cpu-temperature"
       },
       {
          "{#SNMPINDEX}":"20",
          "{#FAN}":"fan1-speed"
       },
       {
          "{#SNMPINDEX}":"21",
          "{#FAN}":"fan2-speed"
       },
       {
          "{#SNMPINDEX}":"22",
          "{#FAN}":"fan3-speed"
       },
       {
          "{#SNMPINDEX}":"23",
          "{#FAN}":"fan4-speed"
       }
    ]​
    I only want the fans to be returned, so I added a filter filtering "{#FAN} = ^fan[0-9]+-speed$". That work's as expected.
    What I could not achieve by trying out myself or search on the forum etc. was changing the name from e.g. "fan1-speed" to "Fan 1".
    How can I change those LLD macro values?

    Thanks in advance.
  • Answer selected by derdeagle at 28-10-2022, 19:42.
    markfree
    Senior Member
    • Apr 2019
    • 868

    There's a catch with item keys.
    Note, that commas are not allowed in unquoted item key parameters, so the parameter containing a macro function has to be quoted. The backslash (\) character should be used to escape double quotes inside the parameter.
    Try it like this:
    Code:
    fan.speed["fan{{#FAN}.regsub(\"fan([0-9]+)-speed\",\1)}"]
    Do you really find it necessary to extract the fan number to use it at the key parameter? Wouldn't the macro value itself be enough?
    Last edited by markfree; 28-10-2022, 18:49.

    Comment

    • markfree
      Senior Member
      • Apr 2019
      • 868

      #2
      Macro functions could be helpful for your discovery.

      What if you tried something like this?
      Code:
      {{#FAN}.regsub("fan([0-9]+)-speed",\1)}
      In my testing, I managed to extract the number from an LLD macro value and use it in the name field.
      Click image for larger version

Name:	image.png
Views:	346
Size:	3.3 KB
ID:	453529


      Click image for larger version

Name:	image.png
Views:	332
Size:	1.4 KB
ID:	453530​​

      Comment

      • derdeagle
        Junior Member
        • Dec 2016
        • 5

        #3
        Your suggested way indeed works for the name but unfortunately not for the key.
        I was able to set the name to the following value:
        Code:
        Fan {{#FAN}.regsub("fan([0-9]+)-speed",\1)} speed
        If I now want to set the key to the following value I get the error message afterwards:
        Code:
        fan.speed[fan{{#FAN}.regsub("fan([0-9]+)-speed",\1)}]
        Invalid key "fan.speed[fan{{#FAN}.regsub("fan([0-9]+)-speed",\1)}]" for item prototype "Fan {{#FAN}.regsub("fan([0-9]+)-speed",\1)} speed" on "Template Mikrotik CCR2116-12G-4Splus": incorrect syntax near "+)-speed",\1)}]".
        According to the fine manual the macro function should also work in the key.

        Btw. I am using version 6.0.9 if that is of interest.

        Comment

        • markfree
          Senior Member
          • Apr 2019
          • 868

          #4
          There's a catch with item keys.
          Note, that commas are not allowed in unquoted item key parameters, so the parameter containing a macro function has to be quoted. The backslash (\) character should be used to escape double quotes inside the parameter.
          Try it like this:
          Code:
          fan.speed["fan{{#FAN}.regsub(\"fan([0-9]+)-speed\",\1)}"]
          Do you really find it necessary to extract the fan number to use it at the key parameter? Wouldn't the macro value itself be enough?
          Last edited by markfree; 28-10-2022, 18:49.

          Comment

          • Markku
            Senior Member
            Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
            • Sep 2018
            • 1782

            #5
            Originally posted by markfree
            Do you really find it necessary to extract the fan number to use it at the key parameter? Wouldn't the macro value itself be enough?
            I would definitely keep the original string that was present in the discovery data, that will help hugely when someone looks at the items and the discovery data later. Just my 2 cents

            Markku

            Comment

            • derdeagle
              Junior Member
              • Dec 2016
              • 5

              #6
              That is now working as intended, thank you very much.

              Originally posted by markfree
              There's a catch with item keys.
              [...]
              Do you really find it necessary to extract the fan number to use it at the key parameter? Wouldn't the macro value itself be enough?
              It is not necessary at all and both if you are 100% right. This should not be done in general. As this is solely for me privately let's just declare it as learning Nevertheless I do think about just using the value (fan1-speed) as the key as this will be unique, too.

              Comment

              Working...