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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2019 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 CScreenActions extends CScreenBase {
/**
* Process screen.
*
* @return CDiv (screen inside container)
*/
public function get() {
$sortfield = 'clock';
$sortorder = ZBX_SORT_DOWN;
switch ($this->screenitem['sort_triggers']) {
case SCREEN_SORT_TRIGGERS_TIME_ASC:
$sortfield = 'clock';
$sortorder = ZBX_SORT_UP;
break;
case SCREEN_SORT_TRIGGERS_TIME_DESC:
$sortfield = 'clock';
$sortorder = ZBX_SORT_DOWN;
break;
case SCREEN_SORT_TRIGGERS_TYPE_ASC:
$sortfield = 'description';
$sortorder = ZBX_SORT_UP;
break;
case SCREEN_SORT_TRIGGERS_TYPE_DESC:
$sortfield = 'description';
$sortorder = ZBX_SORT_DOWN;
break;
case SCREEN_SORT_TRIGGERS_STATUS_ASC:
$sortfield = 'status';
$sortorder = ZBX_SORT_UP;
break;
case SCREEN_SORT_TRIGGERS_STATUS_DESC:
$sortfield = 'status';
$sortorder = ZBX_SORT_DOWN;
break;
case SCREEN_SORT_TRIGGERS_RECIPIENT_ASC:
$sortfield = 'sendto';
$sortorder = ZBX_SORT_UP;
break;
case SCREEN_SORT_TRIGGERS_RECIPIENT_DESC:
$sortfield = 'sendto';
$sortorder = ZBX_SORT_DOWN;
break;
}
$sql = 'SELECT a.alertid,a.clock,a.sendto,a.subject,a.message,a.status,a.retries,a.error,'.
'a.userid,a.actionid,a.mediatypeid,mt.description,mt.maxattempts'.
' FROM events e,alerts a'.
' LEFT JOIN media_type mt ON mt.mediatypeid=a.mediatypeid'.
' WHERE e.eventid=a.eventid'.
' AND alerttype='.ALERT_TYPE_MESSAGE;
if (CWebUser::getType() != USER_TYPE_SUPER_ADMIN) {
$userid = CWebUser::$data['userid'];
$userGroups = getUserGroupsByUserId($userid);
$sql .= ' AND EXISTS ('.
'SELECT NULL'.
' FROM functions f,items i,hosts_groups hgg'.
' JOIN rights r'.
' ON r.id=hgg.groupid'.
' AND '.dbConditionInt('r.groupid', $userGroups).
' WHERE e.objectid=f.triggerid'.
' AND f.itemid=i.itemid'.
' AND i.hostid=hgg.hostid'.
' GROUP BY f.triggerid'.
' HAVING MIN(r.permission)>'.PERM_DENY.
')';
}
$sql .= ' ORDER BY '.$sortfield.' '.$sortorder;
$alerts = DBfetchArray(DBselect($sql, $this->screenitem['elements']));
order_result($alerts, $sortfield, $sortorder);
$userids = [];
foreach ($alerts as $alert) {
if ($alert['userid'] != 0) {
$userids[$alert['userid']] = true;
}
}
if ($userids) {
$dbUsers = API::User()->get([
'output' => ['userid', 'alias', 'name', 'surname'],
'userids' => array_keys($userids),
'preservekeys' => true
]);
}
// indicator of sort field
$sort_div = (new CSpan())->addClass(($sortorder === ZBX_SORT_DOWN) ? ZBX_STYLE_ARROW_DOWN : ZBX_STYLE_ARROW_UP);
// create alert table
$table = (new CTableInfo())
->setHeader([
($sortfield === 'clock') ? [('Time'), $sort_div] : _('Time'),
_('Action'),
($sortfield === 'description') ? [_('Type'), $sort_div] : _('Type'),
($sortfield === 'sendto') ? [_('Recipient'), $sort_div] : _('Recipient'),
_('Message'),
($sortfield === 'status') ? [_('Status'), $sort_div] : _('Status'),
_('Info')
]);
$actions = API::Action()->get([
'output' => ['actionid', 'name'],
'actionids' => array_unique(zbx_objectValues($alerts, 'actionid')),
'preservekeys' => true
]);
foreach ($alerts as $alert) {
if ($alert['status'] == ALERT_STATUS_SENT) {
$status = (new CSpan(_('Sent')))->addClass(ZBX_STYLE_GREEN);
}
elseif ($alert['status'] == ALERT_STATUS_NOT_SENT || $alert['status'] == ALERT_STATUS_NEW) {
$status = (new CSpan([
_('In progress').':',
BR(),
_n('%1$s retry left', '%1$s retries left', $alert['maxattempts'] - $alert['retries'])])
)
->addClass(ZBX_STYLE_YELLOW);
}
else {
$status = (new CSpan(_('Failed')))->addClass(ZBX_STYLE_RED);
}
$recipient = ($alert['userid'] != 0 && array_key_exists($alert['userid'], $dbUsers))
? [bold(getUserFullname($dbUsers[$alert['userid']])), BR(), zbx_nl2br($alert['sendto'])]
: zbx_nl2br($alert['sendto']);
$info_icons = [];
if ($alert['error'] !== '') {
$info_icons[] = makeErrorIcon($alert['error']);
}
$table->addRow([
zbx_date2str(DATE_TIME_FORMAT_SECONDS, $alert['clock']),
array_key_exists($alert['actionid'], $actions) ? $actions[$alert['actionid']]['name'] : '',
$alert['mediatypeid'] == 0 ? '' : $alert['description'],
$recipient,
[bold($alert['subject']), BR(), BR(), zbx_nl2br($alert['message'])],
$status,
makeInformationList($info_icons)
]);
}
$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(_('Action log')));
}
}
|