task.create

Description

object task.create(object **task**)

This method allows to create a new task (such as collect diagnostic data or check items or low-level discovery rules without config reload).

Starting from Zabbix version 5.0.5, task.create accepts array of task objects object/array **tasks**, allowing to create multiple tasks in single request.

Parameters

(object) A task to create.

The method accepts the following parameters. Please use this format for Zabbix versions before 5.0.5 only.

ParameterTypeDescription
type
(required)
integerTask type.

Possible values:
6 - Check now.
itemids
(required)
string/arrayIDs of items and low-level discovery rules.

Please be aware that starting from Zabbix version 5.0.5, request format has changed:

ParameterTypeDescription
type
(required)
integerTask type.

Possible values:
1 - Diagnostic information;
6 - Check now.
request
(required)
objectTask request object according to the task type. Correct format of request object is described in Task object section.
proxy_hostidintegerProxy about which Diagnostic information task will collect data.

Ignored for Check now tasks.

Note that ‘Check now’ tasks can be created for the following types of items/discovery rules:

  • Zabbix agent

  • SNMPv1/v2/v3 agent

  • Simple check

  • Internal check

  • Aggregate check

  • External check

  • Database monitor

  • HTTP agent

  • IPMI agent

  • SSH agent

  • TELNET agent

  • Calculated check

  • JMX agent

Return values

(object) Returns an object containing the IDs of the created tasks under the taskids property. One task is created for each item and low-level discovery rule. The order of the returned IDs matches the order of the passed itemids or task objects passed as array.

Examples

Creating a task

Create a task check now for two items. One is an item, the other is a low-level discovery rule.

Request for Zabbix versions before 5.0.5:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "task.create",
  4. "params": {
  5. "type": "6",
  6. "itemids": [
  7. "10092",
  8. "10093"
  9. ],
  10. },
  11. "auth": "700ca65537074ec963db7efabda78259",
  12. "id": 1
  13. }

Same request for Zabbix versions starting from 5.0.5:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "task.create",
  4. "params": [
  5. {
  6. "type": "6",
  7. "request": {
  8. "itemid": "10092"
  9. }
  10. },
  11. {
  12. "type": "6",
  13. "request": {
  14. "itemid": "10093"
  15. }
  16. }
  17. ],
  18. "auth": "700ca65537074ec963db7efabda78259",
  19. "id": 1
  20. }

Response is similar for both example requests:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "taskids": [
  5. "1",
  6. "2"
  7. ]
  8. },
  9. "id": 1
  10. }

Create a task diagnostic information task. Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "task.create",
  4. "params": [
  5. {
  6. "type": "1",
  7. "request": {
  8. "alerting": {
  9. "stats": [
  10. "alerts"
  11. ],
  12. "top": {
  13. "media.alerts": 10
  14. }
  15. },
  16. "lld": {
  17. "stats": "extend",
  18. "top": {
  19. "values": 5
  20. }
  21. }
  22. },
  23. "proxy_hostid": 0
  24. }
  25. ],
  26. "auth": "700ca65537074ec963db7efabda78259",
  27. "id": 2
  28. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "taskids": [
  5. "3"
  6. ]
  7. },
  8. "id": 2
  9. }

See also

Source

CTask::create() in ui/include/classes/api/services/CTask.php.