Source
xxxxxxxxxx
<?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/>.
**/
require_once dirname(__FILE__).'/../include/CIntegrationTest.php';
/**
* Test suite for testing changing rank of trigger-based events/problems
*
* @required-components server
* @configurationDataProvider serverConfigurationProvider
* @backup hosts,items,triggers,task,task_data,acknowledges,event_symptom,events,problem
*/
class testEventsCauseAndSymptoms extends CIntegrationTest {
private static $hostid;
private static $trigger_ids = [];
private static $event_ids = [];
private static $cause_events_test_scriptid;
private static $symptom_events_test_scriptid;
const HOST_NAME = 'host cause and symptoms';
const TRAPPER_ITEM_NAME_PREFIX = 'Trapper item ';
const TRAPPER_ITEM_KEY_PREFIX = 'trap';
const EVENT_CAUSE_MACRO_TEMPLATE = 'Macros to test: {EVENT.NAME}|{EVENT.ID}|{EVENT.CAUSE.NAME}|{EVENT.CAUSE.ID}|{EVENT.CAUSE.SOURCE}|{EVENT.CAUSE.OBJECT}|{EVENT.CAUSE.VALUE}';
const EVENT_SYMPTOMS_MACRO_TEMPLATE = '{EVENT.SYMPTOMS}';
const TEST_CAUSE_EVENTS_SCRIPT_NAME = 'script test cause events';
const TEST_SYMPTOM_EVENTS_SCRIPT_NAME = 'script test symptom events';
const EVENT_COUNT = 5;
const EVENT_START = 1;
private function expandMacros($in_str, $event_n, $cause_n = null) {
$replacements = [
'{EVENT.NAME}' => 'Trigger trap '.$event_n,
'{EVENT.ID}' => $this->eventNumToId($event_n)
];
if (null != $cause_n) {
$replacements = array_merge($replacements, [
'{EVENT.CAUSE.NAME}' => 'Trigger trap '.$cause_n,
'{EVENT.CAUSE.ID}' => $this->eventNumToId($cause_n),
'{EVENT.CAUSE.SOURCE}' => EVENT_SOURCE_TRIGGERS,
'{EVENT.CAUSE.OBJECT}' => EVENT_OBJECT_TRIGGER,
'{EVENT.CAUSE.VALUE}' => self::EVENT_START
]);
}
else {
$replacements = array_merge($replacements, [
'{EVENT.CAUSE.NAME}' => '*UNKNOWN*',
'{EVENT.CAUSE.ID}' => '*UNKNOWN*',
'{EVENT.CAUSE.SOURCE}' => '*UNKNOWN*',
'{EVENT.CAUSE.OBJECT}' => '*UNKNOWN*',
'{EVENT.CAUSE.VALUE}' => '*UNKNOWN*'
]);
}
$from = [];
$to = [];
foreach ($replacements as $key => $value) {
$from[] = $key;
$to[] = $value;
}
return str_replace($from, $to, $in_str);
}
private function eventNumToId($num) {
if (!is_int($num) && !is_array($num)) {
throw new Exception("Test error: eventNumToId() arguments must be int or array, got '%s'",
gettype($num));
}
if (is_array($num)) {
$a = [];
foreach ($num as $n)
$a[] = $this->eventNumToId($n);
return $a;
}