Zabbix Documentation 2.2

3.04.04.45.0 (current)| In development:5.2 (devel)| Unsupported:1.82.02.22.43.23.44.2Guidelines

User Tools

Site Tools


manual:api

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
manual:api [2014/12/16 19:39]
richlv [Authentication] fix typo; thanks to ihre for reporting
manual:api [2016/11/24 12:24]
iivs added information on how to update multiple items and triggers
Line 161: Line 161:
  
 <note tip>The ''​item.create''​ method as well as other create methods can also accept arrays of objects and create multiple items with one API call.</​note>​ <note tip>The ''​item.create''​ method as well as other create methods can also accept arrays of objects and create multiple items with one API call.</​note>​
 +
 +=== Creating multiple triggers ===
 +
 +So if create methods accept arrays, we can add multiple [[manual:​api:​reference:​trigger:​object|triggers]] like so:
 +
 +<code js>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​method":​ "​trigger.create",​
 +    "​params":​ [
 +        {
 +            "​description":​ "​Processor load is too high on {HOST.NAME}",​
 +            "​expression":​ "​{Linux server:​system.cpu.load[percpu,​avg1].last()}>​5",​
 +        },
 +        {
 +            "​description":​ "Too many processes on {HOST.NAME}",​
 +            "​expression":​ "​{Linux server:​proc.num[].avg(5m)}>​300",​
 +        }
 +    ],
 +    "​auth":​ "​0424bd59b807674191e7d77572075f33",​
 +    "​id":​ 4
 +}
 +</​code>​
 +
 +A successful response will contain the IDs of the newly created triggers:
 +<code js>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​result":​ {
 +        "​triggerids":​ [
 +            "​17369",​
 +            "​17370"​
 +        ]
 +    },
 +    "​id":​ 4
 +}
 +</​code>​
 +
 +=== Updating an item ===
 +
 +Enable an item, that is, set its status to "​0":​
 +
 +<code js>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​method":​ "​item.update",​
 +    "​params":​ {
 +        "​itemid":​ "​10092",​
 +        "​status":​ 0
 +    },
 +    "​auth":​ "​0424bd59b807674191e7d77572075f33",​
 +    "​id":​ 5
 +}
 +</​code>​
 +
 +A successful response will contain the ID of the updated item:
 +<code js>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​result":​ {
 +        "​itemids":​ [
 +            "​10092"​
 +        ]
 +    },
 +    "​id":​ 5
 +}
 +</​code>​
 +
 +<note tip>The ''​item.update''​ method as well as other update methods can also accept arrays of objects and update multiple items with one API call.</​note>​
 +
 +=== Updating multiple triggers ===
 +
 +Enable multiple triggers, that is, set their status to 0:
 +<code js>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​method":​ "​trigger.update",​
 +    "​params":​ [
 +        {
 +            "​triggerid":​ "​13938",​
 +            "​status":​ 0
 +        },
 +        {
 +            "​triggerid":​ "​13939",​
 +            "​status":​ 0
 +        }
 +    ],
 +    "​auth":​ "​0424bd59b807674191e7d77572075f33",​
 +    "​id":​ 6
 +}
 +</​code>​
 +
 +A successful response will contain the IDs of the updated triggers:
 +<code js>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​result":​ {
 +        "​triggerids":​ [
 +            "​13938",​
 +            "​13939"​
 +        ]
 +    },
 +    "​id":​ 6
 +}
 +</​code>​
 +
 +<note tip>This is the preferred method of updating. Some API methods like ''​host.massupdate''​ allow to write more simple code, but it's not recommended to use those methods, since they will be removed in the future releases.</​note>​
 +
 === Error handling === === Error handling ===
  
Line 182: Line 290:
         ]         ]
     },     },
-    "​id": ​3,+    "​id": ​7,
     "​auth":​ "​0424bd59b807674191e7d77572075f33"​     "​auth":​ "​0424bd59b807674191e7d77572075f33"​
 } }
Line 197: Line 305:
         "​data":​ "No groups for host \"​Linux server\"​."​         "​data":​ "No groups for host \"​Linux server\"​."​
     },     },
-    "​id": ​3+    "​id": ​7
 } }
 </​code>​ </​code>​