Ad Widget

Collapse

Assign Item Value to Macro

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ysus
    Senior Member
    • Mar 2016
    • 100

    #1

    Assign Item Value to Macro

    Hello Zabbix experts,

    Maybe someone faced similar problem before and could advise what I can do.
    We have 3 identical servers with different IP addresses (kind of cluster) where each server has full information about other two. I built Zabbix host pointing to the first node IP and using discovery rule to pull information about others. However, those servers must be taken offline for maintenance so when first node is down I lose all metrics.

    I’ve built simple “script item” which checks IP availability and need to pass this information to other “HTTP agent” items. I know it is not possible to pass value of one item to another item and tried to assign first item value either to host {$ALIVE} macro or to {INVENTORY.LOCATION} field. No errors from Javascript but it looks like macro values actually did not change.

    Click image for larger version  Name:	image.png Views:	0 Size:	16.0 KB ID:	507969

    Code:
    var obj = JSON.parse(value);
    
    try {
    var request2 = new HttpRequest();
    request2.get("http://172.26.24.33/........");
    var result2 = "good33";
    obj.is_alive = "172.26.24.33";
    obj.location = "172.26.24.33";
    return result2 + obj.is_alive + obj.location;
    } catch (error) {
    var result2 = "bad33";
    }
    
    try { <next node> }.....

    Question: are host macros immutable and could be set only manually?
    Or maybe there is an alternative solution of passing values between items via some temporary variable on the host level?

    Also found 2 feature requests related this issue but they are unresolved for many years.



    https://support.zabbix.com/browse/ZBXNEXT-9059



    Thanks,
  • Kos
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Aug 2015
    • 3404

    #2
    The only known for me (ugly, but working) method of passing some item's value to use it in some another item, is to modify some user macro via Zabbix API (for example in preprocessing script of the first item) and then use this macro somewhere in the second item.

    Ugly because:
    • the preprocessing of the first item depends on the Zabbix API (performance and availability). As an optimization step, this preprocessing can compare the new value with the current value of this macro, and then only call the API if they differ;
    • the macro change should be picked up by Zabbix Server, i.e. it can be not immediate, but only in 1 minute (after configuration cache refreshing);
    • for using Zabbix API you need some permissions; i.e. you need to have some user with enough rights, generate token for this user and then use this token for authentication in your preprocessing code (this token, however, itself can be contained in another user macro - for example, secret macro).

    Comment

    • ysus
      Senior Member
      • Mar 2016
      • 100

      #3
      Thanks Kos and sorry for late reply.
      I do not think this solution is ugly, just tested it in demo lab and it works like a charm!
      • Performance is not an issue, I’m running script only once a minute and since one of 3 hosts is always alive it takes no more than 10 seconds for JavaScript to get the status of the 3rd one in case first 2 are dead. But just in case I put timeout of 15 seconds explicitly.
      • 1-minute update is perfectly fine
      • I’ve created new role with minimum permissions and store API token in secret macro as per your recommendations.
      Will close this topic now and thanks again for pointing me in the right direction. Hope in new Zabbix versions this could be achieved with built-in mechanisms.

      Click image for larger version

Name:	image.png
Views:	44
Size:	45.8 KB
ID:	509144

      Comment

      Working...