Ad Widget

Collapse

calculated value for using multiple hosts in template

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lmgray
    Junior Member
    • Jun 2017
    • 6

    #1

    calculated value for using multiple hosts in template

    I'm trying to monitor web services on a large number of servers using zabbix proxies in different cloud datacenters to get stats from multiple geographic locations. For each server, I've created multiple hosts e.g.: zabtest-via-proxy1, zabtest-via-proxy2, zabtest-via-proxy3, etc. and placing the hosts behind zabbix proxies. This is working well in that I'm getting the desired stats, but for the purposes of triggers/alerts, I'm trying to create a virtual host which aggregates stats and only alerts if all the proxies agree the web service is unresponsive. I manually created a virtual host with a calculated value like this:

    Code:
    Name: failcount
    Key: webservice.failcount
    Formula:
    last("zabtest-via-proxy1:web.test.fail[Webservice]") + 
    last("zabtest-via-proxy2:web.test.fail[Webservice]") +
    last("zabtest-via-proxy3:web.test.fail[Webservice]")
    This works great -- I get a synthesized item which is the count of proxies that see the web service as unresponsive! So far so good, but when I tried to scale this by templating the formula above -- I'm stumped... My thought was to try to use macros like this:

    Code:
    Name: failcount
    Key: webservice.failcount
    Formula:
    last("{HOST.HOST}-via-proxy1:web.test.fail[Webservice]") + 
    last("{HOST.HOST}-via-proxy2:web.test.fail[Webservice]") +
    last("{HOST.HOST}-via-proxy3:web.test.fail[Webservice]")
    ...but neither HOST macros nor user macros seem to work in the key part of functions in formulae. I get errors like this showing the macro isn't expanded:

    Cannot evaluate function "last()": item "zabtest:{$HOSTVIAPROXY1}:web.test.fail[Webservice]" does not exist.
    Reading that macros *do* work in parameters, I tried creating a parameter on each of the hosts like this:

    Code:
    Name: down
    Key: webservice.downcount
    Formula:
    last("down[{HOST.HOST}-via-proxy1]")
    This creates a "down" key as expect:

    Code:
    down[zabtest-via-proxy1]
    But when I try to reference the "down" item from the hosts using a calculated value on the virtual host using e.g.

    Code:
    last("down[zabtest-via-proxy1]")
    I run into a slightly different error:
    Cannot evaluate function "last()": item "zabtest:down[zabtest-via-proxy1]" does not exist.
    One way I could do this would be to create a host group for each of the web servers and use aggregate checks on the group, but... I have upwards of 300 servers to monitor and 300 host groups seems messy...

    So, I'm stumped and would appreciate any ideas/experience using macros in templates to enable calculated items on multiple hosts -- or any other scheme to accomplish "host:item aggregation without using host groups".
  • Akansha123
    Member
    • Jun 2016
    • 54

    #2
    The reason for the key which you have configured is not working is mentioned below
    "User macros in the formula will be expanded if used to reference a function parameter or a constant.User macros will NOT be expanded if referencing a function, host name, item key, item key parameter or operator."

    It is not possible to mention variable hostname in template for calculated item.

    Comment

    • jonxor
      Junior Member
      • Jun 2016
      • 24

      #3
      I'm just curious if you or anyone ever found some other workaround to this? I have a similar situation where I have about 745 hosts in pairs. I need to alert based on the sum of an item from each host in a pair.
      Making 320 host groups is not what I want to do, because it would make my host group drop-down menu become a mess.

      Comment

      • lmgray
        Junior Member
        • Jun 2017
        • 6

        #4
        We did in fact end up making (hundreds of) host groups -- I scripted the onboarding of new hosts and baked it into our automation so no human has to do it. Doiing it programatically, 3 or 300 -- not a problem... (but yes, host group dropdown is not pretty now).
        It's not pretty, but that approach did in fact work -- others have gone on to leverage the host groups for other aggregations etc. Not pretty, but it works... YMMV and all that. DM me and I'll share the scripts
        if you decide to go that route...
        Last edited by lmgray; 17-09-2018, 22:32.

        Comment

        Working...