Source
<?php
/*
** 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 containing methods for operations with map elements.
*
* @return mixed
*/
abstract class CMapElement extends CApiService {
protected function checkSelementInput(&$selements, $method) {
$create = ($method === 'createSelements');
$update = ($method === 'updateSelements');
$element_types = [SYSMAP_ELEMENT_TYPE_HOST, SYSMAP_ELEMENT_TYPE_MAP, SYSMAP_ELEMENT_TYPE_TRIGGER,
SYSMAP_ELEMENT_TYPE_HOST_GROUP, SYSMAP_ELEMENT_TYPE_IMAGE
];
$elementtype_validator = new CLimitedSetValidator(['values' => $element_types]);
if ($update) {
$db_selements = $this->fetchSelementsByIds(zbx_objectValues($selements, 'selementid'));
$selements = $this->extendFromObjects(zbx_toHash($selements, 'selementid'), $db_selements, ['elementtype', 'elements']);
}
foreach ($selements as &$selement) {
if (!is_array($selement)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect arguments passed to function.'));
}
if ($create) {
// Check required parameters.
$missing_keys = array_diff(['sysmapid', 'elementtype', 'iconid_off'], array_keys($selement));
if ($missing_keys) {
self::exception(ZBX_API_ERROR_PARAMETERS,
_s('Map element is missing parameters: %1$s', implode(', ', $missing_keys))
);
}
}
if (array_key_exists('urls', $selement)) {
$url_validate_options = ['allow_user_macro' => false];
if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
$url_validate_options['allow_inventory_macro'] = INVENTORY_URL_MACRO_HOST;