1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2018 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 CScreenEvents extends CScreenBase {
/**
* Process screen.
*
* @return CDiv (screen inside container)
*/
public function get() {
$config = select_config();
$table = (new CTableInfo())->setHeader([_('Time'), _('Recovery time'), _('Host'), _('Description'), _('Value'),
_('Severity')
]);
$triggers = API::Trigger()->get([
'output' => [],
'selectHosts' => ['hostid', 'name'],
'skipDependent' => true,
'monitored' => true,
'sortfield' => 'lastchange',
'sortorder' => ZBX_SORT_DOWN,
'limit' => $this->screenitem['elements'],
'preservekeys' => true
]);
$events = API::Event()->get([
'output' => ['eventid', 'r_eventid', 'objectid', 'clock', 'ns', 'name', 'acknowledged', 'severity'],
'select_acknowledges' => ['action'],
'source' => EVENT_SOURCE_TRIGGERS,
'object' => EVENT_OBJECT_TRIGGER,
'value' => TRIGGER_VALUE_TRUE,
'objectids' => array_keys($triggers),
'sortfield' => ['clock', 'eventid'],
'sortorder' => ZBX_SORT_DOWN,
'limit' => $this->screenitem['elements']
]);
$sort_clock = [];
$sort_event = [];
foreach ($events as $key => $event) {
if (!array_key_exists($event['objectid'], $triggers)) {
continue;
}
$events[$key]['host'] = reset($triggers[$event['objectid']]['hosts']);
$sort_clock[$key] = $event['clock'];
$sort_event[$key] = $event['eventid'];
}
array_multisort($sort_clock, SORT_DESC, $sort_event, SORT_DESC, $events);
if ($events) {
$r_eventids = [];
foreach ($events as $event) {
$r_eventids[$event['r_eventid']] = true;
}
unset($r_eventids[0]);
$r_events = $r_eventids
? API::Event()->get([
'output' => ['clock'],
'source' => EVENT_SOURCE_TRIGGERS,
'object' => EVENT_OBJECT_TRIGGER,
'eventids' => array_keys($r_eventids),
'preservekeys' => true
])
: [];
foreach ($events as &$event) {
if (array_key_exists($event['r_eventid'], $r_events)) {
$event['r_clock'] = $r_events[$event['r_eventid']]['clock'];
}
else {
$event['r_clock'] = 0;
}
}
unset($event);
}
foreach ($events as $event) {
$host = $event['host'];
if ($event['r_eventid'] == 0) {
$in_closing = false;
foreach ($event['acknowledges'] as $acknowledge) {
if (($acknowledge['action'] & ZBX_PROBLEM_UPDATE_CLOSE) == ZBX_PROBLEM_UPDATE_CLOSE) {
$in_closing = true;
break;
}
}
$value = $in_closing ? TRIGGER_VALUE_FALSE : TRIGGER_VALUE_TRUE;
$value_str = $in_closing ? _('CLOSING') : _('PROBLEM');
$value_clock = $in_closing ? time() : $event['clock'];
}
else {
$value = TRIGGER_VALUE_FALSE;
$value_str = _('RESOLVED');
$value_clock = $event['r_clock'];
}
$statusSpan = new CSpan($value_str);
// Add colors span depending on configuration and trigger parameters.
addTriggerValueStyle($statusSpan, $value, $event['clock'], $event['acknowledged'] == EVENT_ACKNOWLEDGED);
$table->addRow([
zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']),
($event['r_eventid'] == 0) ? '' : zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['r_clock']),
$host['name'],
new CLink(
$event['name'],
'tr_events.php?triggerid='.$event['objectid'].'&eventid='.$event['eventid']
),
$statusSpan,
getSeverityCell($event['severity'], $config)
]);
}
$footer = (new CList())
->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))
->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT);
return $this->getOutput((new CUiWidget(uniqid(), [$table, $footer]))->setHeader(_('History of events')));
}
}
|