Source
<?php declare(strict_types = 0);
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
class CControllerSlaCreate extends CControllerSlaCreateUpdate {
/**
* @var array
*/
private $schedule = [];
protected function init(): void {
$this->setPostContentType(self::POST_CONTENT_TYPE_JSON);
}
protected function checkInput(): bool {
$fields = [
'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 ($ret) {
if ($this->getInput('schedule_mode') == CSlaHelper::SCHEDULE_MODE_CUSTOM) {
try {
$this->schedule = self::validateCustomSchedule($this->getInput('schedule_enabled', []),
$this->getInput('schedule_periods', [])
);
}
catch (InvalidArgumentException $e) {
info($e->getMessage());
$ret = false;
}
}
}
if (!$ret) {
$this->setResponse(
new CControllerResponseData(['main_block' => json_encode([
'error' => [