Ad Widget

Collapse

Zabbix 6.0: Item containing number of Instances of text within a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wolfsbane2k
    Member
    • Nov 2022
    • 48

    #1

    Zabbix 6.0: Item containing number of Instances of text within a string

    Hi.

    I'm trying to count the number of JSON objects that are returned from a query where their name contains a specific string, and trying to do it in a cleanish way for the Zabbix Operator so that I'm not ending up with loads of misc items underneath it.

    I can't seem to get it working at all; and i'm pretty sure that it's my Regex that's failing, but not 100% sure, so thought i'd ask here!

    Sample:

    [
    {"Name": "Alpha, Beta, Gamma", "Param": "1,3,99,128,512"},
    {"Name": "Beta", "Param":"56,59"},
    {"Name": "Kilo, Phi", "Param": "17,109,123"},
    {"Name": "Omega, Gamma, Phi", "Param": "78"},
    {"Name": "Zeta", "Param": "91,561"}
    ]

    In this instance, i've got TotalObjects as an Host.Item, which is preprocessed using JSONPath to $.length(), which correctly reports 5

    But i also want to get :
    Total number of objects where name contains Beta
    Total number of objects where name contains Phi.

    Is there an easy/recommended way to do this? I don't need any of the details of the Parameters, just the names themselves, and the string i'm looking for won't appear anywhere else in each object other than the name, so I could just count the number of instances of each "Alpha" etc string.

    I've not yet delved into creating custom user javascript etc macro functions, and would prefer not to if i can help it!

    Thanks in advance!​
  • Piotrekzielony
    Junior Member
    • Oct 2021
    • 17

    #2
    You can have calculated item (or 2 in this case)
    And if you hook "master item with jason" to it you can count directly from if using function (as last value or for period/value count):
    count(/host/key,(sec|#num)<:time shift>,<operator>,<pattern>)
    so you can put it into graph for each of them if this is what you need and that would be the easiest way unless you don't want graph but for something else

    https://www.zabbix.com/documentation.../history#count
    Last edited by Piotrekzielony; 13-06-2023, 22:45.

    Comment

    • Semiadmin
      Senior Member
      • Oct 2014
      • 1625

      #3
      For example:
      $.[?(@.Name =~ "Beta")].Name.length()

      Comment

      Working...