[comment]: # ({c9bc126a-c9bc126a})
# task.create

[comment]: # ({/c9bc126a-c9bc126a})

[comment]: # ({9a39d714-0e3179d3})
### 描述

`object task.create(object/array tasks)`

此方法允许create新任务（例如收集诊断数据
或检查监控项或无需重新加载配置的低级发现规则）。

::: noteclassic
此方法仅适用于*超级管理员*用户类型。
调用该方法的权限可以在用户角色设置中撤销。参见
[User
roles](/manual/web_interface/frontend_sections/users/user_roles)
获取更多信息。

:::

[comment]: # ({/9a39d714-0e3179d3})

[comment]: # ({8628e056-2574c234})
### 参数

`(object/array)` 一个用于create的任务.

该方法接受具有[任务对象](object#任务对象)的任务.

请注意'立即执行'任务只能为以下类型的监控项/发现规则创建:

-   Zabbix agent
-   SNMPv1/v2/v3 agent
-   简单检查
-   内部检查
-   外部检查
-   数据库监控
-   HTTP agent
-   IPMI agent
-   SSH agent
-   TELNET agent
-   计算检查
-   JMX agent
-   依赖监控项

[comment]: # ({/8628e056-2574c234})

[comment]: # ({ab87ce2a-ab87ce2a})
### 返回值

`(object)` 返回一个包含所创建任务ID的object
存储在`taskids`属性下。每个监控项和
低级发现规则都会创建一个任务。返回的ID顺序与
传入的`itemids`顺序相匹配。

[comment]: # ({/ab87ce2a-ab87ce2a})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({69ebf78a-5c5fa6f1})
#### 创建任务

为两个监控项创建任务`Execute now`。一个是监控项，另一个是低级发现规则。

[执行请求](/manual/api#执行请求):

```json
{
    "jsonrpc": "2.0",
    "method": "task.create",
    "params": [
        {
            "type": 6,
            "request": {
                "itemid": "10092"
            }
        },
        {
            "type": 6,
            "request": {
                "itemid": "10093"
            }
        }
    ],
    "id": 1
}
```
响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "taskids": [
            "1",
            "2"
        ]
    },
    "id": 1
}
```
为两个proxies创建任务`Refresh proxy configuration`。

[执行请求](/manual/api#执行请求):

```json
{
    "jsonrpc": "2.0",
    "method": "task.create",
    "params": [
        {
            "type": 2,
            "request": {
                "proxyids": ["10459", "10460"]
            }
        }
    ],
    "id": 1
}
```
响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "taskids": [
            "1"
        ]
    },
    "id": 1
}
```
创建任务`diagnostic information`。

[执行请求](/manual/api#执行请求):

```json
{
    "jsonrpc": "2.0",
    "method": "task.create",
    "params": [
        {
            "type": 1,
            "request": {
                "alerting": {
                    "stats": [
                        "alerts"
                    ],
                    "top": {
                        "media.alerts": 10
                    }
                },
                "lld": {
                    "stats": "extend",
                    "top": {
                        "values": 5
                    }
                }
            },
            "proxyid": 0
        }
    ],
    "id": 1
}
```
响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "taskids": [
            "3"
        ]
    },
    "id": 1
}
```

[comment]: # ({/69ebf78a-5c5fa6f1})

[comment]: # ({58f08e8d-d87c906b})
### 另请参阅

-   [Task](/manual/api/reference/task/object)
-   ['立即执行'请求 object](/manual/api/reference/task/object#execute-now-request-object)
-   [诊断信息请求对象](/manual/api/reference/task/object#诊断信息请求对象)
-   [统计请求对象](/manual/api/reference/task/object#统计请求对象)

[comment]: # ({/58f08e8d-d87c906b})

[comment]: # ({be350bd3-be350bd3})
### 来源

CTask::create() 位于 *ui/include/classes/api/services/CTask.php* 文件中.

[comment]: # ({/be350bd3-be350bd3})
