Source
['if' => ['field' => '2', 'in' => implode(',', [ZBX_PREPROC_PROMETHEUS_FUNCTION])], 'type' => API_STRING_UTF8, 'flags' => API_REQUIRED, 'in' => implode(',', [ZBX_PREPROC_PROMETHEUS_SUM, ZBX_PREPROC_PROMETHEUS_MIN, ZBX_PREPROC_PROMETHEUS_MAX, ZBX_PREPROC_PROMETHEUS_AVG, ZBX_PREPROC_PROMETHEUS_COUNT])]
<?php
/*
** 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/>.
**/
/**
* API validator
*/
class CApiInputValidator {
/**
* Base validation function.
*
* @param array $rule validation rule
* @param mixed $data import data
* @param string $path data path (for error reporting)
* @param string $error
*
* @return bool
*/
public static function validate(array $rule, &$data, $path, &$error) {
$error = '';
return self::validateData($rule, $data, $path, $error)
&& self::validateDataUniqueness($rule, $data, $path, $error);
}
/**
* Base uniqueness validation function.
*
* @param array $rule validation rule
* @param mixed $data import data
* @param string $path data path (for error reporting)
* @param string $error
*
* @return bool
*/
public static function validateUniqueness(array $rule, $data, $path, &$error) {
$error = '';
return self::validateDataUniqueness($rule, $data, $path, $error);
}
/**
* Base data validation function.
*
* @param array $rule
* @param mixed $data
* @param string $path
* @param string $error
*
* @return bool
*/
private static function validateData($rule, &$data, $path, &$error) {
switch ($rule['type']) {
case API_CALC_FORMULA:
return self::validateCalcFormula($rule, $data, $path, $error);
case API_COLOR:
return self::validateColor($rule, $data, $path, $error);
case API_COLORS:
return self::validateColors($rule, $data, $path, $error);
case API_COND_FORMULA:
return self::validateCondFormula($rule, $data, $path, $error);
case API_COND_FORMULAID:
return self::validateCondFormulaId($rule, $data, $path, $error);
case API_STRING_UTF8:
return self::validateStringUtf8($rule, $data, $path, $error);
case API_ESCAPED_STRING_UTF8:
return self::validateEscapedStringUtf8($rule, $data, $path, $error);
case API_STRINGS_UTF8:
return self::validateStringsUtf8($rule, $data, $path, $error);
case API_INT32: