Ad Widget

Collapse

How do I reference an item value to replace a macro value via usermacro.update?

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J0nas
    Junior Member
    • Oct 2020
    • 2

    #1

    How do I reference an item value to replace a macro value via usermacro.update?

    Hello,
    I'm trying to monitor the number of ongoing calls on our telephone system. This value can be accessed via the phone systems api, which I can in fact do and display on a map. The problem is, after a set amount of time the cookie used to authenticate zabbix with the api expires, so I had to find a solution to keep the cookie updated. I did some reading and settled on this scenario:

    -An item that collects the current cookie
    -A macro that will contain the cookie, collected by the item
    -A trigger that checks if the token has changed
    -An action that will run a http post request against the Zabbix api with the method "usermacro.update", which will update the macro with the current value of the cookie item

    The request works as so far as that I can in fact edit the macro value but I'm not sure about the syntax I have to use which will reference the latest value of my cookie item.

    The request I'm using:

    {"jsonrpc":"2.0",
    "method":"usermacro.update",
    "id":1,
    "auth":"$Key",
    "params":{
    "hostmacroid": "783",
    "value": "???"
    }
    }

    ------------------
    My item is called "ApiCookieCollector", the key is called "api.cookie.collector", and the itemid is "32563" (if that matters) but I couldn't think of any combination of these things with ".last()" or whatever to get it to work. It will always output plain text instead of the item value. Is what I'm trying to do even possible?

    Can anyone provide me with the correct syntax to use the item value?
    I hope I could make myself clear.

    ty


  • Answer selected by J0nas at 03-05-2022, 10:11.
    cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    Ah... long wires... So you want an api query, that will return last value of the first item .. collect a cookie value into item value -> runs script to set macro value (if item value changes) and all the time run another item, which uses that macro?

    item.get and lastvalue parameter holds latest value... https://www.zabbix.com/documentation...rence/item/get
    Or history.get if you want more than last...

    Comment

    • cyber
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2006
      • 4807

      #2
      I dont get it... you are updating a macro, why you want to update item also? You need hostid also there, as hostmacro update requires it... https://www.zabbix.com/documentation...ermacro/object
      If your item uses a macro, then it will be resolved at that moment, when item needs it... it you change macro value between 2 uses, then item will get different values for macro... you dont need to update any item over api...

      Comment


      • J0nas
        J0nas commented
        Editing a comment
        First http agent collects newest cookie from phone system api login page-> new cookie replaces old cookie as macro value -> macro value is used as cookie in !second! http agent item -> second item connects to phone system api status page

        I can't access http://phonesystem/api/systemstatus page without having the auth cookie first, which I have to get via http://phonesystem/api/login
    • cyber
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2006
      • 4807

      #3
      Ah... long wires... So you want an api query, that will return last value of the first item .. collect a cookie value into item value -> runs script to set macro value (if item value changes) and all the time run another item, which uses that macro?

      item.get and lastvalue parameter holds latest value... https://www.zabbix.com/documentation...rence/item/get
      Or history.get if you want more than last...

      Comment

      Working...