'type' => ['type' => API_INT32, 'flags' => API_REQUIRED, 'in' => implode(',', [ZBX_TM_DATA_TYPE_DIAGINFO, ZBX_TM_DATA_TYPE_PROXYIDS, ZBX_TM_TASK_CHECK_NOW])],
class CTask extends CApiService {
public const ACCESS_RULES = [
'get' => ['min_user_type' => USER_TYPE_SUPER_ADMIN],
'create' => ['min_user_type' => USER_TYPE_SUPER_ADMIN]
protected $tableName = 'task';
protected $tableAlias = 't';
protected $sortColumns = ['taskid'];
private $item_cache = [];
const RESULT_STATUS_ERROR = -1;
public function get(array $options): array {
if (self::$userData['type'] != USER_TYPE_SUPER_ADMIN) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.'));
$output_fields = ['taskid', 'type', 'status', 'clock', 'ttl', 'proxyid', 'request', 'result'];
$api_input_rules = ['type' => API_OBJECT, 'fields' => [
'taskids' => ['type' => API_IDS, 'flags' => API_NORMALIZE | API_ALLOW_NULL, 'default' => null],
'output' => ['type' => API_OUTPUT, 'in' => implode(',', $output_fields), 'default' => API_OUTPUT_EXTEND],
'preservekeys' => ['type' => API_BOOLEAN, 'default' => false]
if (!CApiInputValidator::validate($api_input_rules, $options, '/', $error)) {
self::exception(ZBX_API_ERROR_PARAMETERS, $error);
'sortorder' => ZBX_SORT_DOWN,
'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT)
'select' => ['task' => 't.taskid'],
'from' => ['task' => 'task t'],
'type' => 't.type='.ZBX_TM_TASK_DATA
if ($options['taskids'] !== null) {
$sql_parts['where']['taskid'] = dbConditionInt('t.taskid', $options['taskids']);
$sql_parts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sql_parts);
$sql_parts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sql_parts);
$result = DBselect($this->createSelectQueryFromParts($sql_parts), $options['limit']);