<?php declare(strict_types = 0);
class CControllerSlaCreate extends CControllerSlaCreateUpdate {
protected function init(): void {
$this->setPostContentType(self::POST_CONTENT_TYPE_JSON);
protected function checkInput(): bool {
'name' => 'required|string|not_empty',
'slo' => 'required|string|not_empty',
'period' => 'required|in '.implode(',', [ZBX_SLA_PERIOD_DAILY, ZBX_SLA_PERIOD_WEEKLY, ZBX_SLA_PERIOD_MONTHLY, ZBX_SLA_PERIOD_QUARTERLY, ZBX_SLA_PERIOD_ANNUALLY]),
'timezone' => 'required|in '.implode(',', array_merge([ZBX_DEFAULT_TIMEZONE], array_keys(CTimezoneHelper::getList()))),
'schedule_mode' => 'required|in '.implode(',', [CSlaHelper::SCHEDULE_MODE_24X7, CSlaHelper::SCHEDULE_MODE_CUSTOM]),
'schedule_enabled' => 'array',
'schedule_periods' => 'array',
'effective_date' => 'required|abs_date',
'service_tags' => 'required|array',
'description' => 'required|string',
'status' => 'in '.ZBX_SLA_STATUS_ENABLED,
'excluded_downtimes' => 'array'
$ret = $this->validateInput($fields);
if ($this->getInput('schedule_mode') == CSlaHelper::SCHEDULE_MODE_CUSTOM) {
$this->schedule = self::validateCustomSchedule($this->getInput('schedule_enabled', []),
$this->getInput('schedule_periods', [])
catch (InvalidArgumentException $e) {
new CControllerResponseData(['main_block' => json_encode([
'title' => _('Cannot create SLA'),
'messages' => array_column(get_and_clear_messages(), 'message')
protected function checkPermissions(): bool {
return $this->checkAccess(CRoleHelper::UI_SERVICES_SLA)
&& $this->checkAccess(CRoleHelper::ACTIONS_MANAGE_SLA);
protected function doAction(): void {
$parser = new CAbsoluteTimeParser();
$parser->parse($this->getInput('effective_date'));
$effective_date = $parser
->getDateTime(true, new DateTimeZone('UTC'))
'effective_date' => $effective_date,
'status' => $this->hasInput('status') ? ZBX_SLA_STATUS_ENABLED : ZBX_SLA_STATUS_DISABLED,