Source
xxxxxxxxxx
* @param int $problem_options['time_from'] (optional) The time starting from which the problems were created.
<?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/>.
**/
/**
* Add color style and blinking to an object like CSpan or CDiv depending on trigger status.
* Settings and colors are kept in 'config' database table.
*
* @param mixed $object object like CSpan, CDiv, etc.
* @param int $triggerValue TRIGGER_VALUE_FALSE or TRIGGER_VALUE_TRUE
* @param int $triggerLastChange
* @param bool $isAcknowledged
*/
function addTriggerValueStyle($object, $triggerValue, $triggerLastChange, $isAcknowledged) {
$color_class = null;
$blinks = null;
// Color class for text and blinking depends on trigger value and whether event is acknowledged.
if ($triggerValue == TRIGGER_VALUE_TRUE && !$isAcknowledged) {
$color_class = ZBX_STYLE_PROBLEM_UNACK_FG;
$blinks = CSettingsHelper::get(CSettingsHelper::PROBLEM_UNACK_STYLE);
}
elseif ($triggerValue == TRIGGER_VALUE_TRUE && $isAcknowledged) {
$color_class = ZBX_STYLE_PROBLEM_ACK_FG;
$blinks = CSettingsHelper::get(CSettingsHelper::PROBLEM_ACK_STYLE);
}
elseif ($triggerValue == TRIGGER_VALUE_FALSE && !$isAcknowledged) {
$color_class = ZBX_STYLE_OK_UNACK_FG;
$blinks = CSettingsHelper::get(CSettingsHelper::OK_UNACK_STYLE);
}
elseif ($triggerValue == TRIGGER_VALUE_FALSE && $isAcknowledged) {
$color_class = ZBX_STYLE_OK_ACK_FG;
$blinks = CSettingsHelper::get(CSettingsHelper::OK_ACK_STYLE);
}
if ($color_class != null && $blinks != null) {
$object->addClass($color_class);
// blinking
$timeSinceLastChange = time() - $triggerLastChange;
$blink_period = timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::BLINK_PERIOD));
if ($blinks && $timeSinceLastChange < $blink_period) {
$object->addClass('js-blink'); // elements with this class will blink
$object->setAttribute('data-time-to-blink', $blink_period - $timeSinceLastChange);
}
}
else {
$object->addClass(ZBX_STYLE_GREY);
}
}
function trigger_value2str($value = null) {
$triggerValues = [
TRIGGER_VALUE_FALSE => _('OK'),
TRIGGER_VALUE_TRUE => _('PROBLEM')
];
if ($value === null) {
return $triggerValues;
}
elseif (isset($triggerValues[$value])) {
return $triggerValues[$value];
}
return _('Unknown');
}
function get_trigger_by_triggerid($triggerid) {
$db_trigger = DBfetch(DBselect('SELECT t.* FROM triggers t WHERE t.triggerid='.zbx_dbstr($triggerid)));
if (!empty($db_trigger)) {
return $db_trigger;
}
error(_s('No trigger with trigger ID "%1$s".', $triggerid));
return false;
}
function get_triggers_by_hostid($hostid) {