Source
* @param int $problem_options['time_from'] (optional) The time starting from which the problems were created.
<?php
/*
** Zabbix
** 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 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.
**/
/**
* 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('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));