Ad Widget

Collapse

How to create a calculated item based on tagged items with different keys?

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • FlyNet
    Junior Member
    • Aug 2024
    • 4

    #1

    How to create a calculated item based on tagged items with different keys?

    English isn't my native language.
    I'm working on creating monitoring for a small ISP. The OLTs send us the data of each modem and they each have their own unique key. I need to make a calculated item that collects the data of groups of them based on the tags they have. For example: group1-modem-[username1], group1-modem-[username2], group1-modem-[username3], etc.
    I already set it up so that it detects the group and tags them accordingly, but when I try to make a calculated item it won't allow me to use a wild card for the item key.

    Code:
    avg_foreach(/OLT/*?[tag="Group:259" and tag="Status:Potency"])
    I'm I going about this the wrong way? Is there some alternative way for Zabbix to automatically group items with different keys into a single reading? Otherwise we would have to manually create and update triggers and items to monitor everything.
  • Answer selected by FlyNet at 14-08-2024, 18:07.
    FlyNet
    Junior Member
    • Aug 2024
    • 4

    For anyone who stumbles across this some day, I found the solution to what I needed. How to create an item that collects the data from several keys automatically based on tags.
    First, in discovery - item prototype create an expression that assigns a tag based on a formula. In my case I needed it to detect the group number in the description data. So I used this formula:
    Code:
    {{#DESCRIPTION}.regsub("^([0-9]+)", \1)}
    So each item created by the discovery rule would have "Group: number" as a tag. This formula extracts (.regsub) from #DESCRIPTION any number ("^([0-9]+)") and sets it as the tag.

    Second, create a calculated item. What I was doing wrong before was not using avg first.
    Code:
    avg(last_foreach(/host/*?[tag="Group:[I]number[/I]" and tag="Status:Potency"]))
    This will take the average of the last measurement for each item. The key is replaced with a wildcard * so it looks for any of the keys in the host, then you specify after ? what tags or groups you want to limit the search to. In this case it looks for the tag of the group and also potency, so it only makes an average of the items that measure the signal potency of every modem.

    Using variations of this method you can make all sorts of groupings. I'm an amateur so there could be easier ways to do this, but this worked.

    Comment

    • FlyNet
      Junior Member
      • Aug 2024
      • 4

      #2
      For anyone who stumbles across this some day, I found the solution to what I needed. How to create an item that collects the data from several keys automatically based on tags.
      First, in discovery - item prototype create an expression that assigns a tag based on a formula. In my case I needed it to detect the group number in the description data. So I used this formula:
      Code:
      {{#DESCRIPTION}.regsub("^([0-9]+)", \1)}
      So each item created by the discovery rule would have "Group: number" as a tag. This formula extracts (.regsub) from #DESCRIPTION any number ("^([0-9]+)") and sets it as the tag.

      Second, create a calculated item. What I was doing wrong before was not using avg first.
      Code:
      avg(last_foreach(/host/*?[tag="Group:[I]number[/I]" and tag="Status:Potency"]))
      This will take the average of the last measurement for each item. The key is replaced with a wildcard * so it looks for any of the keys in the host, then you specify after ? what tags or groups you want to limit the search to. In this case it looks for the tag of the group and also potency, so it only makes an average of the items that measure the signal potency of every modem.

      Using variations of this method you can make all sorts of groupings. I'm an amateur so there could be easier ways to do this, but this worked.

      Comment

      Working...