/usr/share/zabbix/triggers.php is in zabbix-frontend-php 1:2.4.7+dfsg-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | <?php
/*
** Zabbix
** Copyright (C) 2001-2015 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.
**/
require_once dirname(__FILE__).'/include/config.inc.php';
require_once dirname(__FILE__).'/include/hosts.inc.php';
require_once dirname(__FILE__).'/include/triggers.inc.php';
require_once dirname(__FILE__).'/include/forms.inc.php';
$page['title'] = _('Configuration of triggers');
$page['file'] = 'triggers.php';
$page['hist_arg'] = array('hostid', 'groupid');
require_once dirname(__FILE__).'/include/page_header.php';
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields = array(
'groupid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null),
'hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null),
'triggerid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '(isset({form}) && ({form} == "update"))'),
'copy_type' => array(T_ZBX_INT, O_OPT, P_SYS, IN(array(COPY_TYPE_TO_HOST, COPY_TYPE_TO_TEMPLATE, COPY_TYPE_TO_HOST_GROUP)), 'isset({copy})'),
'copy_mode' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0'), null),
'type' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null),
'description' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({add}) || isset({update})', _('Name')),
'expression' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({add}) || isset({update})', _('Expression')),
'priority' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2,3,4,5'), 'isset({add}) || isset({update})'),
'comments' => array(T_ZBX_STR, O_OPT, null, null, 'isset({add}) || isset({update})'),
'url' => array(T_ZBX_STR, O_OPT, null, null, 'isset({add}) || isset({update})'),
'status' => array(T_ZBX_STR, O_OPT, null, null, null),
'input_method' => array(T_ZBX_INT, O_OPT, null, NOT_EMPTY, 'isset({toggle_input_method})'),
'expr_temp' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, '(isset({add_expression}) || isset({and_expression}) || isset({or_expression}) || isset({replace_expression}))', _('Expression')),
'expr_target_single' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, '(isset({and_expression}) || isset({or_expression}) || isset({replace_expression}))'),
'dependencies' => array(T_ZBX_INT, O_OPT, null, DB_ID, null),
'new_dependency' => array(T_ZBX_INT, O_OPT, null, DB_ID.'{}>0', 'isset({add_dependency})'),
'g_triggerid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null),
'copy_targetid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null),
'copy_groupid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({copy}) && (isset({copy_type}) && {copy_type} == 0)'),
'showdisabled' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), null),
'visible' => array(T_ZBX_STR, O_OPT, null, null, null),
// actions
'action' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT,
IN('"trigger.masscopyto","trigger.massdelete","trigger.massdisable",'.
'"trigger.massenable","trigger.massupdate","trigger.massupdateform"'
),
null
),
'toggle_input_method' =>array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'add_expression' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'and_expression' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'or_expression' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'replace_expression' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'remove_expression' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'test_expression' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'add_dependency' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'group_enable' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'group_disable' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'group_delete' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'copy' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'clone' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'add' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'update' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'massupdate' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'delete' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null),
'cancel' => array(T_ZBX_STR, O_OPT, P_SYS, null, null),
'form' => array(T_ZBX_STR, O_OPT, P_SYS, null, null),
'form_refresh' => array(T_ZBX_INT, O_OPT, null, null, null),
// sort and sortorder
'sort' => array(T_ZBX_STR, O_OPT, P_SYS, IN('"description","priority","status"'), null),
'sortorder' => array(T_ZBX_STR, O_OPT, P_SYS, IN('"'.ZBX_SORT_DOWN.'","'.ZBX_SORT_UP.'"'), null)
);
$_REQUEST['showdisabled'] = getRequest('showdisabled', CProfile::get('web.triggers.showdisabled', 1));
check_fields($fields);
$_REQUEST['status'] = isset($_REQUEST['status']) ? TRIGGER_STATUS_ENABLED : TRIGGER_STATUS_DISABLED;
$_REQUEST['type'] = isset($_REQUEST['type']) ? TRIGGER_MULT_EVENT_ENABLED : TRIGGER_MULT_EVENT_DISABLED;
// Validate permissions to single trigger.
$triggerId = getRequest('triggerid');
if ($triggerId !== null) {
$trigger = API::Trigger()->get(array(
'triggerids' => array($triggerId),
'output' => array('triggerid'),
'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL),
'editable' => true
));
if (!$trigger) {
access_deny();
}
}
// Validate permissions to a group of triggers for mass enable/disable actions.
$triggerIds = getRequest('g_triggerid', array());
$triggerIds = zbx_toArray($triggerIds);
if ($triggerIds && !API::Trigger()->isWritable($triggerIds)) {
access_deny();
}
// Validate permissions to host.
if (getRequest('hostid') && !API::Host()->isWritable(array($_REQUEST['hostid']))) {
access_deny();
}
/*
* Actions
*/
$exprAction = null;
if (isset($_REQUEST['add_expression'])) {
$_REQUEST['expression'] = $_REQUEST['expr_temp'];
$_REQUEST['expr_temp'] = '';
}
elseif (isset($_REQUEST['and_expression'])) {
$exprAction = 'and';
}
elseif (isset($_REQUEST['or_expression'])) {
$exprAction = 'or';
}
elseif (isset($_REQUEST['replace_expression'])) {
$exprAction = 'r';
}
elseif (getRequest('remove_expression')) {
$exprAction = 'R';
$_REQUEST['expr_target_single'] = $_REQUEST['remove_expression'];
}
elseif (isset($_REQUEST['clone']) && isset($_REQUEST['triggerid'])) {
unset($_REQUEST['triggerid']);
$_REQUEST['form'] = 'clone';
}
elseif (hasRequest('add') || hasRequest('update')) {
$trigger = array(
'expression' => getRequest('expression'),
'description' => getRequest('description'),
'priority' => getRequest('priority'),
'status' => getRequest('status'),
'type' => getRequest('type'),
'comments' => getRequest('comments'),
'url' => getRequest('url'),
'dependencies' => zbx_toObject(getRequest('dependencies', array()), 'triggerid')
);
if (hasRequest('update')) {
// update only changed fields
$oldTrigger = API::Trigger()->get(array(
'triggerids' => getRequest('triggerid'),
'output' => API_OUTPUT_EXTEND,
'selectDependencies' => array('triggerid')
));
if (!$oldTrigger) {
access_deny();
}
$oldTrigger = reset($oldTrigger);
$oldTrigger['dependencies'] = zbx_toHash(zbx_objectValues($oldTrigger['dependencies'], 'triggerid'));
$newDependencies = $trigger['dependencies'];
$oldDependencies = $oldTrigger['dependencies'];
unset($trigger['dependencies']);
unset($oldTrigger['dependencies']);
$triggerToUpdate = array_diff_assoc($trigger, $oldTrigger);
$triggerToUpdate['triggerid'] = getRequest('triggerid');
// dependencies
$updateDepencencies = false;
if (count($newDependencies) != count($oldDependencies)) {
$updateDepencencies = true;
}
else {
foreach ($newDependencies as $dependency) {
if (!isset($oldDependencies[$dependency['triggerid']])) {
$updateDepencencies = true;
}
}
}
if ($updateDepencencies) {
$triggerToUpdate['dependencies'] = $newDependencies;
}
$result = API::Trigger()->update($triggerToUpdate);
show_messages($result, _('Trigger updated'), _('Cannot update trigger'));
}
else {
$result = API::Trigger()->create($trigger);
show_messages($result, _('Trigger added'), _('Cannot add trigger'));
}
if ($result) {
unset($_REQUEST['form']);
uncheckTableRows(getRequest('hostid'));
}
}
elseif (isset($_REQUEST['delete']) && isset($_REQUEST['triggerid'])) {
DBstart();
$result = API::Trigger()->delete(array(getRequest('triggerid')));
$result = DBend($result);
if ($result) {
unset($_REQUEST['form'], $_REQUEST['triggerid']);
uncheckTableRows(getRequest('hostid'));
}
show_messages($result, _('Trigger deleted'), _('Cannot delete trigger'));
}
elseif (isset($_REQUEST['add_dependency']) && isset($_REQUEST['new_dependency'])) {
if (!isset($_REQUEST['dependencies'])) {
$_REQUEST['dependencies'] = array();
}
foreach ($_REQUEST['new_dependency'] as $triggerid) {
if (!uint_in_array($triggerid, $_REQUEST['dependencies'])) {
array_push($_REQUEST['dependencies'], $triggerid);
}
}
}
elseif (hasRequest('action') && getRequest('action') == 'trigger.massupdate' && hasRequest('massupdate') && hasRequest('g_triggerid')) {
$visible = getRequest('visible', array());
// update triggers
$triggersToUpdate = array();
foreach (getRequest('g_triggerid') as $triggerid) {
$trigger = array('triggerid' => $triggerid);
if (isset($visible['priority'])) {
$trigger['priority'] = getRequest('priority');
}
if (isset($visible['dependencies'])) {
$trigger['dependencies'] = zbx_toObject(getRequest('dependencies', array()), 'triggerid');
}
$triggersToUpdate[] = $trigger;
}
DBstart();
$result = API::Trigger()->update($triggersToUpdate);
$result = DBend($result);
if ($result) {
unset($_REQUEST['form'], $_REQUEST['g_triggerid']);
uncheckTableRows(getRequest('hostid'));
}
show_messages($result, _('Trigger updated'), _('Cannot update trigger'));
}
elseif (hasRequest('action') && str_in_array(getRequest('action'), array('trigger.massenable', 'trigger.massdisable')) && hasRequest('g_triggerid')) {
$enable = (getRequest('action') == 'trigger.massenable');
$status = $enable ? TRIGGER_STATUS_ENABLED : TRIGGER_STATUS_DISABLED;
$update = array();
// get requested triggers with permission check
$dbTriggers = API::Trigger()->get(array(
'output' => array('triggerid', 'status'),
'triggerids' => getRequest('g_triggerid'),
'editable' => true
));
if ($dbTriggers) {
foreach ($dbTriggers as $dbTrigger) {
$update[] = array(
'triggerid' => $dbTrigger['triggerid'],
'status' => $status
);
}
$result = API::Trigger()->update($update);
}
else {
$result = true;
}
$updated = count($update);
$messageSuccess = $enable
? _n('Trigger enabled', 'Triggers enabled', $updated)
: _n('Trigger disabled', 'Triggers disabled', $updated);
$messageFailed = $enable
? _n('Cannot enable trigger', 'Cannot enable triggers', $updated)
: _n('Cannot disable trigger', 'Cannot disable triggers', $updated);
if ($result) {
uncheckTableRows(getRequest('hostid'));
unset($_REQUEST['g_triggerid']);
}
show_messages($result, $messageSuccess, $messageFailed);
}
elseif (hasRequest('action') && getRequest('action') == 'trigger.masscopyto' && hasRequest('copy') && hasRequest('g_triggerid')) {
if (hasRequest('copy_targetid') && getRequest('copy_targetid') > 0 && hasRequest('copy_type')) {
// hosts or templates
if (getRequest('copy_type') == COPY_TYPE_TO_HOST || getRequest('copy_type') == COPY_TYPE_TO_TEMPLATE) {
$hosts_ids = getRequest('copy_targetid');
}
// host groups
else {
$hosts_ids = array();
$group_ids = getRequest('copy_targetid');
$db_hosts = DBselect(
'SELECT DISTINCT h.hostid'.
' FROM hosts h,hosts_groups hg'.
' WHERE h.hostid=hg.hostid'.
' AND '.dbConditionInt('hg.groupid', $group_ids)
);
while ($db_host = DBfetch($db_hosts)) {
$hosts_ids[] = $db_host['hostid'];
}
}
DBstart();
$result = copyTriggersToHosts(getRequest('g_triggerid'), $hosts_ids, getRequest('hostid'));
$result = DBend($result);
if ($result) {
uncheckTableRows(getRequest('hostid'));
unset($_REQUEST['g_triggerid']);
}
show_messages($result, _('Trigger added'), _('Cannot add trigger'));
}
else {
show_error_message(_('No target selected'));
}
}
elseif (hasRequest('action') && getRequest('action') == 'trigger.massdelete' && hasRequest('g_triggerid')) {
$result = API::Trigger()->delete(getRequest('g_triggerid'));
if ($result) {
uncheckTableRows(getRequest('hostid'));
}
show_messages($result, _('Triggers deleted'), _('Cannot delete triggers'));
}
/*
* Display
*/
if (hasRequest('action') && getRequest('action') == 'trigger.massupdateform' && hasRequest('g_triggerid')) {
$data = getTriggerMassupdateFormData();
$data['action'] = 'trigger.massupdate';
$triggersView = new CView('configuration.triggers.massupdate', $data);
$triggersView->render();
$triggersView->show();
}
elseif (isset($_REQUEST['form'])) {
$triggersView = new CView('configuration.triggers.edit', getTriggerFormData($exprAction));
$triggersView->render();
$triggersView->show();
}
elseif (hasRequest('action') && getRequest('action') == 'trigger.masscopyto' && hasRequest('g_triggerid')) {
$data = getCopyElementsFormData('g_triggerid', _('CONFIGURATION OF TRIGGERS'));
$data['action'] = 'trigger.masscopyto';
$triggersView = new CView('configuration.copy.elements', $data);
$triggersView->render();
$triggersView->show();
}
else {
$sortField = getRequest('sort', CProfile::get('web.'.$page['file'].'.sort', 'description'));
$sortOrder = getRequest('sortorder', CProfile::get('web.'.$page['file'].'.sortorder', ZBX_SORT_UP));
CProfile::update('web.'.$page['file'].'.sort', $sortField, PROFILE_TYPE_STR);
CProfile::update('web.'.$page['file'].'.sortorder', $sortOrder, PROFILE_TYPE_STR);
$data = array(
'showdisabled' => getRequest('showdisabled', 1),
'parent_discoveryid' => null,
'triggers' => array(),
'sort' => $sortField,
'sortorder' => $sortOrder
);
CProfile::update('web.triggers.showdisabled', $data['showdisabled'], PROFILE_TYPE_INT);
$data['pageFilter'] = new CPageFilter(array(
'groups' => array('with_hosts_and_templates' => true, 'editable' => true),
'hosts' => array('templated_hosts' => true, 'editable' => true),
'triggers' => array('editable' => true),
'groupid' => getRequest('groupid'),
'hostid' => getRequest('hostid')
));
$data['groupid'] = $data['pageFilter']->groupid;
$data['hostid'] = $data['pageFilter']->hostid;
// get triggers
if ($data['pageFilter']->hostsSelected) {
$options = array(
'editable' => true,
'sortfield' => $sortField,
'limit' => $config['search_limit'] + 1
);
if ($sortField === 'status') {
$options['output'] = array('triggerid', 'status', 'state');
}
else {
$options['output'] = array('triggerid', $sortField);
}
if (empty($data['showdisabled'])) {
$options['filter']['status'] = TRIGGER_STATUS_ENABLED;
}
if ($data['pageFilter']->hostid > 0) {
$options['hostids'] = $data['pageFilter']->hostid;
}
elseif ($data['pageFilter']->groupid > 0) {
$options['groupids'] = $data['pageFilter']->groupid;
}
$data['triggers'] = API::Trigger()->get($options);
}
$_REQUEST['hostid'] = getRequest('hostid', $data['pageFilter']->hostid);
// sort for paging
if ($sortField === 'status') {
orderTriggersByStatus($data['triggers'], $sortOrder);
}
else {
order_result($data['triggers'], $sortField, $sortOrder);
}
// paging
$data['paging'] = getPagingLine($data['triggers'], $sortOrder);
$data['triggers'] = API::Trigger()->get(array(
'triggerids' => zbx_objectValues($data['triggers'], 'triggerid'),
'output' => API_OUTPUT_EXTEND,
'selectHosts' => API_OUTPUT_EXTEND,
'selectItems' => array('itemid', 'hostid', 'key_', 'type', 'flags', 'status'),
'selectFunctions' => API_OUTPUT_EXTEND,
'selectDependencies' => array('triggerid', 'description'),
'selectDiscoveryRule' => API_OUTPUT_EXTEND
));
// sort for displaying full results
if ($sortField === 'status') {
orderTriggersByStatus($data['triggers'], $sortOrder);
}
else {
order_result($data['triggers'], $sortField, $sortOrder);
}
$dependencyIds = array();
foreach ($data['triggers'] as $trigger) {
foreach ($trigger['dependencies'] as $depTrigger) {
$dependencyIds[$depTrigger['triggerid']] = $depTrigger['triggerid'];
}
}
$dependencyTriggers = array();
if ($dependencyIds) {
$dependencyTriggers = API::Trigger()->get(array(
'triggerids' => $dependencyIds,
'output' => array('triggerid', 'flags', 'description', 'status'),
'selectHosts' => array('hostid', 'name'),
'preservekeys' => true
));
// sort dependencies
foreach ($data['triggers'] as &$trigger) {
if (count($trigger['dependencies']) > 1) {
order_result($trigger['dependencies'], 'description', ZBX_SORT_UP);
}
}
unset($trigger);
// sort dependency trigger hosts
foreach ($dependencyTriggers as &$trigger) {
if (count($dependencyTriggers[$trigger['triggerid']]['hosts']) > 1) {
order_result($dependencyTriggers[$trigger['triggerid']]['hosts'], 'name', ZBX_SORT_UP);
}
}
unset($trigger);
}
$data['dependencyTriggers'] = $dependencyTriggers;
// get real hosts
$data['realHosts'] = getParentHostsByTriggers($data['triggers']);
// determine, show or not column of errors
if ($data['hostid'] > 0) {
$data['showInfoColumn'] = (bool) API::Host()->get(array(
'hostids' => $data['hostid'],
'output' => array('status')
));
}
else {
$data['showInfoColumn'] = true;
}
// render view
$triggersView = new CView('configuration.triggers.list', $data);
$triggersView->render();
$triggersView->show();
}
require_once dirname(__FILE__).'/include/page_footer.php';
|