$triggerDescription[] = new CLink(CHtml::encode($realHost['name']), 'triggers.php?hostid=' . $realHost['hostid'], 'unknown'); $triggerDescription[] = ':'; } } $trigger['hosts'] = zbx_toHash($trigger['hosts'], 'hostid'); if ($trigger['flags'] == ZBX_FLAG_DISCOVERY_CREATED) { $triggerDescription[] = new CSpan(CHtml::encode($trigger['description'])); } else { $triggerDescription[] = new CLink(CHtml::encode($trigger['description']), 'triggers.php?form=update&hostid=' . key($trigger['hosts']) . '&triggerid=' . $trigger['triggerid']); } if ($trigger['state'] == TRIGGER_STATE_UNKNOWN) { $trigger['error'] = ''; } $trigger['items'] = zbx_toHash($trigger['items'], 'itemid'); $trigger['functions'] = zbx_toHash($trigger['functions'], 'functionid'); $triggerHintTable->addRow(array(getSeverityCell($trigger['priority']), $triggerDescription, triggerExpression($trigger, true), new CSpan(triggerIndicator($trigger['status'], $trigger['state']), triggerIndicatorStyle($trigger['status'], $trigger['state'])))); $item['triggers'][$num] = $trigger; } unset($trigger); if (!empty($item['triggers'])) { $triggerInfo = new CSpan(_('Triggers'), 'link_menu'); $triggerInfo->setHint($triggerHintTable); $triggerInfo = array($triggerInfo); $triggerInfo[] = ' (' . count($item['triggers']) . ')'; $triggerHintTable = array(); } else { $triggerInfo = SPACE; } // if item type is 'Log' we must show log menu if (in_array($item['value_type'], array(ITEM_VALUE_TYPE_LOG, ITEM_VALUE_TYPE_STR, ITEM_VALUE_TYPE_TEXT))) { $triggers = array();
if ($data['showInfoColumn']) { if ($trigger['status'] == TRIGGER_STATUS_ENABLED && !zbx_empty($trigger['error'])) { $info = new CDiv(SPACE, 'status_icon iconerror'); $info->setHint($trigger['error'], 'on'); } else { $info = ''; } } else { $info = null; } // status $status = ''; if (!empty($this->data['parent_discoveryid'])) { $status = new CLink(triggerIndicator($trigger['status']), 'trigger_prototypes.php?' . 'action=' . ($trigger['status'] == TRIGGER_STATUS_DISABLED ? 'triggerprototype.massenable' : 'triggerprototype.massdisable') . '&hostid=' . $this->data['hostid'] . '&g_triggerid=' . $triggerid . '&parent_discoveryid=' . $this->data['parent_discoveryid'], triggerIndicatorStyle($trigger['status'])); } else { $status = new CLink(triggerIndicator($trigger['status'], $trigger['state']), 'triggers.php?' . 'action=' . ($trigger['status'] == TRIGGER_STATUS_DISABLED ? 'trigger.massenable' : 'trigger.massdisable') . '&hostid=' . $this->data['hostid'] . '&g_triggerid=' . $triggerid, triggerIndicatorStyle($trigger['status'], $trigger['state'])); } // hosts $hosts = null; if (empty($this->data['hostid'])) { foreach ($trigger['hosts'] as $hostid => $host) { if (!empty($hosts)) { $hosts[] = ', '; } $hosts[] = $host['name']; } } // checkbox $checkBox = new CCheckBox('g_triggerid[' . $triggerid . ']', null, null, $triggerid); $checkBox->setEnabled(empty($trigger['discoveryRule'])); $triggersTable->addRow(array($checkBox, getSeverityCell($trigger['priority']), $hosts, $description, new CCol(triggerExpression($trigger, true), 'trigger-expression'), $status, $info));
$js_action = 'addValue(' . zbx_jsvalue($reference) . ', ' . zbx_jsvalue($trigger['triggerid']) . ', ' . $parentId . ');'; } else { $values = array($dstfld1 => $trigger[$srcfld1], $dstfld2 => $trigger[$srcfld2]); if (isset($srcfld3)) { $values[$dstfld3] = $trigger[$srcfld3]; } $js_action = 'addValues(' . zbx_jsvalue($dstfrm) . ', ' . zbx_jsvalue($values) . '); return false;'; } $description->setAttribute('onclick', $js_action . ' jQuery(this).removeAttr("onclick");'); if (count($trigger['dependencies']) > 0) { $description = array($description, BR(), bold(_('Depends on')), BR()); foreach ($trigger['dependencies'] as $dependentTrigger) { $description[] = array(CMacrosResolverHelper::resolveTriggerName($dependentTrigger), BR()); } } $table->addRow(array($multiselect ? new CCheckBox('triggers[' . zbx_jsValue($trigger[$srcfld1]) . ']', null, null, $trigger['triggerid']) : null, $description, getSeverityCell($trigger['priority']), new CSpan(triggerIndicator($trigger['status'], $trigger['state']), triggerIndicatorStyle($trigger['status'], $trigger['state'])))); // made to save memory usage if ($multiselect) { $jsTriggers[$trigger['triggerid']] = array('id' => $trigger['triggerid'], 'name' => $trigger['description'], 'prefix' => get_node_name_by_elid($trigger['triggerid'], null, NAME_DELIMITER), 'triggerid' => $trigger['triggerid'], 'description' => $trigger['description'], 'expression' => $trigger['expression'], 'priority' => $trigger['priority'], 'status' => $trigger['status'], 'host' => $trigger['hostname']); } } if ($multiselect) { $button = new CButton('select', _('Select'), "addSelectedValues('triggers', " . zbx_jsvalue($reference) . ', ' . $parentId . ');'); $table->setFooter(new CCol($button, 'right')); insert_js('var popupReference = ' . zbx_jsValue($jsTriggers, true) . ';'); } zbx_add_post_js('chkbxRange.pageGoName = "triggers";'); $form->addItem($table); $form->show(); } elseif ($srctbl == 'items') { $form = new CForm();
} } $description[] = new CLink(CHtml::encode($trigger['description']), 'trigger_prototypes.php?' . 'form=update' . '&parent_discoveryid=' . $this->data['parent_discoveryid'] . '&triggerid=' . $triggerid); if ($trigger['dependencies']) { $description[] = [BR(), bold(_('Depends on') . ':')]; $triggerDependencies = []; foreach ($trigger['dependencies'] as $dependency) { $depTrigger = $data['dependencyTriggers'][$dependency['triggerid']]; $depTriggerDescription = CHtml::encode(implode(', ', zbx_objectValues($depTrigger['hosts'], 'name')) . NAME_DELIMITER . $depTrigger['description']); if ($depTrigger['flags'] == ZBX_FLAG_DISCOVERY_PROTOTYPE) { $triggerDependencies[] = (new CLink($depTriggerDescription, 'trigger_prototypes.php?form=update' . url_param('parent_discoveryid') . '&triggerid=' . $depTrigger['triggerid']))->addClass(triggerIndicatorStyle($depTrigger['status'])); } elseif ($depTrigger['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) { $triggerDependencies[] = (new CLink($depTriggerDescription, 'triggers.php?form=update&triggerid=' . $depTrigger['triggerid']))->addClass(triggerIndicatorStyle($depTrigger['status'])); } $triggerDependencies[] = BR(); } array_pop($triggerDependencies); $description = array_merge($description, [(new CDiv($triggerDependencies))->addClass('dependencies')]); } // status $status = (new CLink(triggerIndicator($trigger['status']), 'trigger_prototypes.php?' . 'action=' . ($trigger['status'] == TRIGGER_STATUS_DISABLED ? 'triggerprototype.massenable' : 'triggerprototype.massdisable') . '&g_triggerid=' . $triggerid . '&parent_discoveryid=' . $this->data['parent_discoveryid']))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(triggerIndicatorStyle($trigger['status']))->addSID(); // checkbox $checkBox = new CCheckBox('g_triggerid[' . $triggerid . ']', $triggerid); $triggersTable->addRow([$checkBox, getSeverityCell($trigger['priority'], $this->data['config']), $description, $trigger['expression'], $status]); } zbx_add_post_js('cookie.prefix = "' . $this->data['parent_discoveryid'] . '";'); // append table to form $triggersForm->addItem([$triggersTable, $this->data['paging'], new CActionButtonList('action', 'g_triggerid', ['triggerprototype.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected trigger prototypes?')], 'triggerprototype.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected trigger prototypes?')], 'triggerprototype.massupdateform' => ['name' => _('Mass update')], 'triggerprototype.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected trigger prototypes?')]], $this->data['parent_discoveryid'])]); // append form to widget $widget->addItem($triggersForm); return $widget;
} array_pop($triggerDependencies); $description = array_merge($description, [(new CDiv($triggerDependencies))->addClass('dependencies')]); } // info if ($this->data['showInfoColumn']) { if ($trigger['status'] == TRIGGER_STATUS_ENABLED && $trigger['error']) { $info = makeErrorIcon($trigger['error']); } else { $info = ''; } } else { $info = null; } // status $status = (new CLink(triggerIndicator($trigger['status'], $trigger['state']), 'triggers.php?' . 'action=' . ($trigger['status'] == TRIGGER_STATUS_DISABLED ? 'trigger.massenable' : 'trigger.massdisable') . '&hostid=' . $this->data['hostid'] . '&g_triggerid=' . $triggerid))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(triggerIndicatorStyle($trigger['status'], $trigger['state']))->addSID(); // hosts $hosts = null; if ($this->data['hostid'] == 0) { foreach ($trigger['hosts'] as $hostid => $host) { if (!empty($hosts)) { $hosts[] = ', '; } $hosts[] = $host['name']; } } // checkbox $checkBox = (new CCheckBox('g_triggerid[' . $triggerid . ']', $triggerid))->setEnabled(empty($trigger['discoveryRule'])); $triggersTable->addRow([$checkBox, getSeverityCell($trigger['priority'], $this->data['config']), $hosts, $description, $trigger['expression'], $status, $info]); } zbx_add_post_js('cookie.prefix = "' . $this->data['hostid'] . '";');
if (isset($srcfld3)) { $values[$dstfld3] = $trigger[$srcfld3]; } $js_action = 'addValues(' . zbx_jsvalue($dstfrm) . ', ' . zbx_jsvalue($values) . '); return false;'; } $description->onClick($js_action . ' jQuery(this).removeAttr("onclick");'); if ($trigger['dependencies']) { $description = [$description, BR(), bold(_('Depends on')), BR()]; $dependencies = CMacrosResolverHelper::resolveTriggerNames(zbx_toHash($trigger['dependencies'], 'triggerid')); foreach ($dependencies as $dependency) { $description[] = $dependency['description']; $description[] = BR(); } array_pop($description); } $table->addRow([$multiselect ? new CCheckBox('triggers[' . zbx_jsValue($trigger[$srcfld1]) . ']', $trigger['triggerid']) : null, $description, getSeverityCell($trigger['priority'], $config), (new CSpan(triggerIndicator($trigger['status'], $trigger['state'])))->addClass(triggerIndicatorStyle($trigger['status'], $trigger['state']))]); // made to save memory usage if ($multiselect) { $jsTriggers[$trigger['triggerid']] = ['id' => $trigger['triggerid'], 'name' => $trigger['description'], 'triggerid' => $trigger['triggerid'], 'description' => $trigger['description'], 'expression' => $trigger['expression'], 'priority' => $trigger['priority'], 'status' => $trigger['status'], 'host' => $trigger['hostname']]; } } if ($multiselect) { $table->setFooter(new CCol((new CButton('select', _('Select')))->onClick("addSelectedValues('triggers', " . zbx_jsvalue($reference) . ', ' . $parentId . ');'))); insert_js('var popupReference = ' . zbx_jsValue($jsTriggers, true) . ';'); } $form->addItem($table); $widget->addItem($form)->show(); } elseif ($srctbl === 'items' || $srctbl === 'item_prototypes') { $form = (new CForm())->setName('itemform')->setId('items'); $itemPrototypesPopup = $srctbl === 'item_prototypes'; $table = (new CTableInfo())->setHeader([$pageFilter->hostsAll ? _('Host') : null, $multiselect ? (new CColHeader((new CCheckBox('all_items'))->onClick("javascript: checkAll('" . $form->getName() . "', 'all_items', 'items');")))->addClass(ZBX_STYLE_CELL_WIDTH) : null, _('Name'), _('Key'), _('Type'), _('Type of information'), _('Status')]);