Ad Widget

Collapse

Zabbix API - How identify web scenarios in triggers by ID

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dheuvels
    Junior Member
    • Nov 2021
    • 2

    #1

    Zabbix API - How identify web scenarios in triggers by ID

    Hello,

    we are using triggers on web scenarios created via the API. To deduce which web scenario is referenced in a certain trigger, I would like to evaluate the IDs referenced by the trigger functions.

    For example, I have a trigger using the `last` function on a `web.test.fail` item.
    Code:
    % cat <<_EOF_ |curl -s ${Z_API} -H "Content-Type: application/json-rpc" --data @- |jq '.result[].functions'
    {"jsonrpc": "2.0", "method": "trigger.get", "params": {"triggerids": "65617", "selectFunctions": "extend"}, "auth": "${z_token}", "id": ${z_id}}
    _EOF_
    [
    {
    "functionid": "135301",
    "itemid": "147450",
    "triggerid": "65617",
    "parameter": "$",
    "function": "last"
    }
    ]
    So this would mean the `web.test.fail` of this web scenario has ID "147450".
    But the `item.get` API doesn't return anything, when I search for that ID:
    Code:
    % cat <<_EOF_ |curl -s ${Z_API} -H "Content-Type: application/json-rpc" --data @- |jq '.result'
    {"jsonrpc": "2.0", "method": "item.get", "params": {"itemids": "147450"}, "auth": "${z_token}", "id": ${z_id}}
    _EOF_
    []
    The `httptestid` of the web scenario object (`httptest`) is something completely else and it doesn't have the notion of an `itemid`.

    How can the web scenario referenced by the trigger be deduced?
    Maybe I'm missing it, but this doesn't seem to be possible.

    Thanks in advance,
    Dirk


  • dheuvels
    Junior Member
    • Nov 2021
    • 2

    #2
    Recently worked with Web scenarios again and found the solution for my problem.
    The item.get() method has a flag webitems, which must be set explicitly, to include webitems in the results.

    So my call
    Code:
    % cat <<_EOF_ |curl -s ${Z_API} -H "Content-Type: application/json-rpc" --data @- |jq '.result'
    {"jsonrpc": "2.0", "method": "item.get", "params": {"itemids": "147450"}, "auth": "${z_token}", "id": ${z_id}}
    _EOF_
    should have been
    Code:
    % cat <<_EOF_ |curl -s ${Z_API} -H "Content-Type: application/json-rpc" --data @- |jq '.result'
    {"jsonrpc": "2.0", "method": "item.get", "params": {"itemids": "147450", "webitems": true}, "auth": "${z_token}", "id": ${z_id}}
    _EOF_
    [
    {
    "itemid": "62528",
    "type": "9",
    "snmp_oid": "",
    "hostid": "10422",
    (..)
    However such a flag only makes sense when doing an an unspecific search like "return items that belong to the given hosts". When requesting a specific ID, like I did, the webitems flag should be ignored to my mind.

    Regards,
    Dirk
    Last edited by dheuvels; 16-06-2022, 11:32.

    Comment

    Working...