Source
'recovery_mode' => ['type' => API_INT32, 'in' => implode(',', [ZBX_RECOVERY_MODE_EXPRESSION, ZBX_RECOVERY_MODE_RECOVERY_EXPRESSION, ZBX_RECOVERY_MODE_NONE]), 'default' => DB::getDefault('triggers', 'recovery_mode')],
<?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/>.
**/
/**
* Class containing common methods for operations with triggers.
*/
abstract class CTriggerGeneral extends CApiService {
protected const FLAGS = null;
/**
* @abstract
*
* @param array $options
*
* @return array
*/
abstract public function get(array $options = []);
/**
* Prepares and returns an array of child triggers, inherited from triggers $tpl_triggers on the given hosts.
*
* @param array $tpl_triggers
* @param string $tpl_triggers[<tnum>]['triggerid']
*/
private function prepareInheritedTriggers(array $tpl_triggers, ?array $hostids = null, ?array &$ins_triggers = null,
?array &$upd_triggers = null, ?array &$db_triggers = null) {
$ins_triggers = [];
$upd_triggers = [];
$db_triggers = [];
$result = DBselect(
'SELECT DISTINCT t.triggerid,h.hostid'.
' FROM triggers t,functions f,items i,hosts h'.
' WHERE t.triggerid=f.triggerid'.
' AND f.itemid=i.itemid'.
' AND i.hostid=h.hostid'.
' AND '.dbConditionInt('t.triggerid', zbx_objectValues($tpl_triggers, 'triggerid')).
' AND '.dbConditionInt('h.status', [HOST_STATUS_TEMPLATE])
);
$tpl_hostids_by_triggerid = [];
$tpl_hostids = [];
while ($row = DBfetch($result)) {
$tpl_hostids_by_triggerid[$row['triggerid']][] = $row['hostid'];
$tpl_hostids[$row['hostid']] = true;
}
// Unset host-level triggers.
foreach ($tpl_triggers as $tnum => $tpl_trigger) {
if (!array_key_exists($tpl_trigger['triggerid'], $tpl_hostids_by_triggerid)) {
unset($tpl_triggers[$tnum]);
}
}
if (!$tpl_triggers) {
// Nothing to inherit, just exit.
return;
}
$hosts_by_tpl_hostid = self::getLinkedHosts(array_keys($tpl_hostids), $hostids);
$chd_triggers_tpl = $this->getHostTriggersByTemplateId(array_keys($tpl_hostids_by_triggerid), $hostids);
$tpl_triggers_by_description = [];
// Preparing list of missing triggers on linked hosts.
foreach ($tpl_triggers as $tpl_trigger) {
$hostids = [];
foreach ($tpl_hostids_by_triggerid[$tpl_trigger['triggerid']] as $tpl_hostid) {
if (array_key_exists($tpl_hostid, $hosts_by_tpl_hostid)) {
foreach ($hosts_by_tpl_hostid[$tpl_hostid] as $host) {
if (array_key_exists($host['hostid'], $chd_triggers_tpl)
&& array_key_exists($tpl_trigger['triggerid'], $chd_triggers_tpl[$host['hostid']])) {
continue;
}
$hostids[$host['hostid']] = true;