<?php declare(strict_types = 0);
class CControllerTriggerUpdate extends CController {
protected function init(): void {
$this->setPostContentType(self::POST_CONTENT_TYPE_JSON);
}
protected function checkInput(): bool {
$fields = [
'triggerid' => 'fatal|required|db triggers.triggerid',
'name' => 'required|db triggers.description|not_empty',
'event_name' => 'db triggers.event_name',
'opdata' => 'db triggers.opdata',
'priority' => 'required|db triggers.priority|in 0,1,2,3,4,5',
'expression' => 'required|string|not_empty',
'recovery_mode' => 'db triggers.recovery_mode|in '.implode(',', [ZBX_RECOVERY_MODE_EXPRESSION, ZBX_RECOVERY_MODE_RECOVERY_EXPRESSION, ZBX_RECOVERY_MODE_NONE]),
'recovery_expression' => 'string',
'type' => 'db triggers.type|in 0,1',
'correlation_mode' => 'db triggers.correlation_mode|in '.implode(',', [ZBX_TRIGGER_CORRELATION_NONE, ZBX_TRIGGER_CORRELATION_TAG]),
'correlation_tag' => 'db triggers.correlation_tag',
'manual_close' => 'db triggers.manual_close|in '.implode(',',[ZBX_TRIGGER_MANUAL_CLOSE_NOT_ALLOWED, ZBX_TRIGGER_MANUAL_CLOSE_ALLOWED]),
'url_name' => 'required|db triggers.url_name',
'url' => 'required|db triggers.url',
'description' => 'required|db triggers.comments',
'status' => 'db triggers.status|in '.TRIGGER_STATUS_ENABLED,
'tags' => 'array',
'dependencies' => 'array',
'hostid' => 'db hosts.hostid',
'context' => 'in '.implode(',', ['host', 'template'])
];
$ret = $this->validateInput($fields);
if (!$ret) {
$this->setResponse(
(new CControllerResponseData(['main_block' => json_encode([
'error' => [
'title' => _('Cannot update trigger'),
'messages' => array_column(get_and_clear_messages(), 'message')
]
])]))->disableView()
);
}
return $ret;
}
protected function checkPermissions(): bool {
if ($this->getInput('hostid') && !isWritableHostTemplates([$this->getInput('hostid')])) {
return false;
}
return $this->getInput('context') === 'host'
? $this->checkAccess(CRoleHelper::UI_CONFIGURATION_HOSTS)
: $this->checkAccess(CRoleHelper::UI_CONFIGURATION_TEMPLATES);
}
protected function doAction(): void {
$db_triggers = API::Trigger()->get([
'output' => ['triggerid', 'templateid', 'flags', 'url_name', 'url', 'priority', 'comments', 'status'],
'selectTags' => ['tag', 'value'],
'triggerids' => $this->getInput('triggerid')
]);
$db_trigger = $db_triggers ? reset($db_triggers) : null;
$trigger = [
'triggerid' => $this->getInput('triggerid')
];
if ($db_trigger && $db_trigger['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
if ($db_trigger['templateid'] == 0) {
$trigger += [
'description' => $this->getInput('name'),
'event_name' => $this->getInput('event_name', ''),
'opdata' => $this->getInput('opdata', ''),