Source
<?php declare(strict_types = 0);
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
class CControllerServiceCreate extends CController {
protected function init(): void {
$this->setPostContentType(self::POST_CONTENT_TYPE_JSON);
}
protected function checkInput(): bool {
$fields = [
'name' => 'required|db services.name|not_empty',
'parent_serviceids' => 'array_db services.serviceid',
'problem_tags' => 'array',
'sortorder' => 'required|db services.sortorder|ge 0|le 999',
'algorithm' => 'required|db services.algorithm|in '.implode(',', [ZBX_SERVICE_STATUS_CALC_SET_OK, ZBX_SERVICE_STATUS_CALC_MOST_CRITICAL_ALL, ZBX_SERVICE_STATUS_CALC_MOST_CRITICAL_ONE]),
'description' => 'db services.description',
'advanced_configuration' => 'in 1',
'status_rules' => 'array',
'propagation_rule' => 'in '.implode(',', array_keys(CServiceHelper::getStatusPropagationNames())),
'propagation_value_number' => 'int32',
'propagation_value_status' => 'int32',
'weight' => 'string',
'tags' => 'array',
'child_serviceids' => 'array_db services.serviceid'
];
$ret = $this->validateInput($fields);
if ($ret && $this->hasInput('advanced_configuration')) {
$fields = [
'propagation_rule' => 'required'
];
if ($this->getInput('weight', '') !== '') {
$fields['weight'] = 'int32|ge 0|le 1000000';
}
$validator = new CNewValidator(array_intersect_key($this->getInputAll(), $fields), $fields);
foreach ($validator->getAllErrors() as $error) {
info($error);
}
$ret = !$validator->isErrorFatal() && !$validator->isError();