function getSeverityCell($severity, $text = null, $force_normal = false) { if ($text === null) { $text = CHtml::encode(getSeverityCaption($severity)); } return new CCol($text, getSeverityStyle($severity, !$force_normal)); }
/** * @param string $options['id'] * @param string $options['name'] * @param int $options['value'] */ public function __construct(array $options = array()) { parent::__construct('div', 'yes'); $this->attr('id', isset($options['id']) ? $options['id'] : zbx_formatDomId($options['name'])); $this->addClass('jqueryinputset control-severity'); if (!isset($options['value'])) { $options['value'] = TRIGGER_SEVERITY_NOT_CLASSIFIED; } $items = array(); $jsIds = ''; $jsLabels = ''; foreach (getSeverityCaption() as $severity => $caption) { $items[] = new CRadioButton($options['name'], $severity, null, $options['name'] . '_' . $severity, $options['value'] == $severity); $css = getSeverityStyle($severity); $label = new CLabel($caption, $options['name'] . '_' . $severity, $options['name'] . '_label_' . $severity); $label->attr('data-severity', $severity); $label->attr('data-severity-style', $css); if ($options['value'] == $severity) { $label->attr('aria-pressed', 'true'); $label->addClass($css); } else { $label->attr('aria-pressed', 'false'); } $items[] = $label; $jsIds .= ', #' . $options['name'] . '_' . $severity; $jsLabels .= ', #' . $options['name'] . '_label_' . $severity; } if ($jsIds) { $jsIds = substr($jsIds, 2); $jsLabels = substr($jsLabels, 2); } $this->addItem($items); insert_js(' jQuery("' . $jsLabels . '").mouseenter(function() { jQuery("' . $jsLabels . '").each(function() { var obj = jQuery(this); if (obj.attr("aria-pressed") == "false") { obj.removeClass("ui-state-hover " + obj.data("severityStyle")); } }); var obj = jQuery(this); obj.addClass(obj.data("severityStyle")); }) .mouseleave(function() { jQuery("#' . $this->getAttribute('id') . ' [aria-pressed=\\"true\\"]").trigger("mouseenter"); }); jQuery("' . $jsIds . '").change(function() { jQuery("#' . $this->getAttribute('id') . ' [aria-pressed=\\"true\\"]").trigger("mouseenter"); });', true); }
/** * Returns a column object for the given row and field. Add additional service tree related formatting. * * @param $rowId * @param $colName * * @return CCol */ protected function makeCol($rowId, $colName) { $class = null; if ($colName == 'status' && zbx_is_int($this->tree[$rowId][$colName]) && $this->tree[$rowId]['id'] > 0) { $status = $this->tree[$rowId][$colName]; // do not show the severity for information and unclassified triggers if (in_array($status, array(TRIGGER_SEVERITY_INFORMATION, TRIGGER_SEVERITY_NOT_CLASSIFIED))) { $this->tree[$rowId][$colName] = new CSpan(_('OK'), 'green'); } else { $this->tree[$rowId][$colName] = getSeverityCaption($status); $class = getSeverityStyle($status); } } $col = parent::makeCol($rowId, $colName); $col->addClass($class); return $col; }
if ($this->data['grpswitch']) { $dashconfFormList->addRow(_('Show selected groups'), new CMultiSelect(array('name' => 'groupids[]', 'objectName' => 'hostGroup', 'data' => $this->data['groups'], 'disabled' => !$this->data['isFilterEnable'], 'popup' => array('parameters' => 'srctbl=host_groups&dstfrm=' . $dashconfForm->getName() . '&dstfld1=groupids_' . '&srcfld1=groupid&multiselect=1', 'width' => 450, 'height' => 450)))); $dashconfFormList->addRow(_('Hide selected groups'), new CMultiSelect(array('name' => 'hidegroupids[]', 'objectName' => 'hostGroup', 'data' => $this->data['hideGroups'], 'disabled' => !$this->data['isFilterEnable'], 'popup' => array('parameters' => 'srctbl=host_groups&dstfrm=' . $dashconfForm->getName() . '&dstfld1=hidegroupids_' . '&srcfld1=groupid&multiselect=1', 'width' => 450, 'height' => 450)))); } // append host in maintenance checkbox to form list $maintenanceCheckBox = new CCheckBox('maintenance', $this->data['maintenance'], null, '1'); if (!$this->data['isFilterEnable']) { $maintenanceCheckBox->setAttribute('disabled', 'disabled'); } $dashconfFormList->addRow(_('Hosts'), array($maintenanceCheckBox, _('Show hosts in maintenance'))); // append trigger severities to form list $severities = array(); foreach ($this->data['severities'] as $severity) { $serverityCheckBox = new CCheckBox('trgSeverity[' . $severity . ']', isset($this->data['severity'][$severity]), '', 1); $serverityCheckBox->setEnabled($this->data['isFilterEnable']); $severities[] = array($serverityCheckBox, getSeverityCaption($severity)); $severities[] = BR(); } array_pop($severities); $dashconfFormList->addRow(_('Triggers with severity'), $severities); // append problem display to form list $extAckComboBox = new CComboBox('extAck', $this->data['extAck']); $extAckComboBox->addItems(array(EXTACK_OPTION_ALL => _('All'), EXTACK_OPTION_BOTH => _('Separated'), EXTACK_OPTION_UNACK => _('Unacknowledged only'))); $extAckComboBox->setEnabled($this->data['isFilterEnable'] && $this->data['config']['event_ack_enable']); if (!$this->data['config']['event_ack_enable']) { $extAckComboBox->setAttribute('title', _('Event acknowledging disabled')); } $dashconfFormList->addRow(_('Problem display'), $extAckComboBox); // create tab $dashconfTab = new CTabView(); $dashconfTab->addTab('dashconfTab', _('Filter'), $dashconfFormList);
function getUserForm($userid, $profile = 0) { global $ZBX_LOCALES; global $USER_DETAILS; $config = select_config(); $frm_title = S_USER; if (isset($userid)) { /* if(bccomp($userid,$USER_DETAILS['userid'])==0) $profile = 1;*/ $options = array('userids' => $userid, 'output' => API_OUTPUT_EXTEND); if ($profile) { $options['nodeids'] = id2nodeid($userid); } $users = CUser::get($options); $user = reset($users); $frm_title = S_USER . ' "' . $user['alias'] . '"'; } if (isset($userid) && (!isset($_REQUEST['form_refresh']) || isset($_REQUEST['register']))) { $alias = $user['alias']; $name = $user['name']; $surname = $user['surname']; $password = null; $password1 = null; $password2 = null; $url = $user['url']; $autologin = $user['autologin']; $autologout = $user['autologout']; $lang = $user['lang']; $theme = $user['theme']; $refresh = $user['refresh']; $rows_per_page = $user['rows_per_page']; $user_type = $user['type']; if ($autologout > 0) { $_REQUEST['autologout'] = $autologout; } $user_groups = array(); $user_medias = array(); $options = array('userids' => $userid, 'output' => API_OUTPUT_SHORTEN); $user_groups = CUserGroup::get($options); $user_groups = zbx_objectValues($user_groups, 'usrgrpid'); $user_groups = zbx_toHash($user_groups); $db_medias = DBselect('SELECT m.* FROM media m WHERE m.userid=' . $userid); while ($db_media = DBfetch($db_medias)) { $user_medias[] = array('mediaid' => $db_media['mediaid'], 'mediatypeid' => $db_media['mediatypeid'], 'period' => $db_media['period'], 'sendto' => $db_media['sendto'], 'severity' => $db_media['severity'], 'active' => $db_media['active']); } $messages = getMessageSettings(); } else { $alias = get_request('alias', ''); $name = get_request('name', ''); $surname = get_request('surname', ''); $password = null; $password1 = get_request('password1', ''); $password2 = get_request('password2', ''); $url = get_request('url', ''); $autologin = get_request('autologin', 0); $autologout = get_request('autologout', 90); $lang = get_request('lang', 'en_gb'); $theme = get_request('theme', 'default.css'); $refresh = get_request('refresh', 30); $rows_per_page = get_request('rows_per_page', 50); $user_type = get_request('user_type', USER_TYPE_ZABBIX_USER); $user_groups = get_request('user_groups', array()); $change_password = get_request('change_password', null); $user_medias = get_request('user_medias', array()); $messages = get_request('messages', array()); if (!isset($messages['enabled'])) { $messages['enabled'] = 0; } if (!isset($messages['sounds.recovery'])) { $messages['sounds.recovery'] = 0; } if (!isset($messages['triggers.recovery'])) { $messages['triggers.recovery'] = 0; } if (!isset($messages['triggers.severities'])) { $messages['triggers.severities'] = array(); } $pMsgs = getMessageSettings(); $messages = array_merge($pMsgs, $messages); } if ($autologin || !isset($_REQUEST['autologout'])) { $autologout = 0; } else { if (isset($_REQUEST['autologout']) && $autologout < 90) { $autologout = 90; } } $perm_details = get_request('perm_details', 0); $media_types = array(); $media_type_ids = array(); foreach ($user_medias as $one_media) { $media_type_ids[$one_media['mediatypeid']] = 1; } if (count($media_type_ids) > 0) { $sql = 'SELECT mt.mediatypeid, mt.description ' . ' FROM media_type mt ' . ' WHERE mt.mediatypeid IN (' . implode(',', array_keys($media_type_ids)) . ')'; $db_media_types = DBselect($sql); while ($db_media_type = DBfetch($db_media_types)) { $media_types[$db_media_type['mediatypeid']] = $db_media_type['description']; } } $frmUser = new CFormTable($frm_title); $frmUser->setName('user_form'); $frmUser->setHelp('web.users.php'); $frmUser->addVar('config', get_request('config', 0)); if (isset($userid)) { $frmUser->addVar('userid', $userid); } if ($profile == 0) { $frmUser->addRow(S_ALIAS, new CTextBox('alias', $alias, 40)); $frmUser->addRow(S_NAME, new CTextBox('name', $name, 40)); $frmUser->addRow(S_SURNAME, new CTextBox('surname', $surname, 40)); } $auth_type = isset($userid) ? get_user_system_auth($userid) : $config['authentication_type']; if (ZBX_AUTH_INTERNAL == $auth_type) { if (!isset($userid) || isset($change_password)) { $frmUser->addRow(S_PASSWORD, new CPassBox('password1', $password1, 20)); $frmUser->addRow(S_PASSWORD_ONCE_AGAIN, new CPassBox('password2', $password2, 20)); if (isset($change_password)) { $frmUser->addVar('change_password', $change_password); } } else { $passwd_but = new CButton('change_password', S_CHANGE_PASSWORD); if ($alias == ZBX_GUEST_USER) { $passwd_but->setAttribute('disabled', 'disabled'); } $frmUser->addRow(S_PASSWORD, $passwd_but); } } if ($profile == 0) { $frmUser->addVar('user_groups', $user_groups); if (isset($userid) && bccomp($USER_DETAILS['userid'], $userid) == 0) { $frmUser->addVar('user_type', $user_type); } else { $cmbUserType = new CComboBox('user_type', $user_type, $perm_details ? 'submit();' : null); $cmbUserType->addItem(USER_TYPE_ZABBIX_USER, user_type2str(USER_TYPE_ZABBIX_USER)); $cmbUserType->addItem(USER_TYPE_ZABBIX_ADMIN, user_type2str(USER_TYPE_ZABBIX_ADMIN)); $cmbUserType->addItem(USER_TYPE_SUPER_ADMIN, user_type2str(USER_TYPE_SUPER_ADMIN)); $frmUser->addRow(S_USER_TYPE, $cmbUserType); } $lstGroups = new CListBox('user_groups_to_del[]', null, 10); $lstGroups->attributes['style'] = 'width: 320px'; $options = array('usrgrpids' => $user_groups, 'output' => API_OUTPUT_EXTEND); $groups = CUserGroup::get($options); order_result($groups, 'name'); foreach ($groups as $num => $group) { $lstGroups->addItem($group['usrgrpid'], $group['name']); } $frmUser->addRow(S_GROUPS, array($lstGroups, BR(), new CButton('add_group', S_ADD, 'return PopUp("popup_usrgrp.php?dstfrm=' . $frmUser->getName() . '&list_name=user_groups_to_del[]&var_name=user_groups",450, 450);'), SPACE, count($user_groups) > 0 ? new CButton('del_user_group', S_DELETE_SELECTED) : null)); } $cmbLang = new CComboBox('lang', $lang); foreach ($ZBX_LOCALES as $loc_id => $loc_name) { $cmbLang->addItem($loc_id, $loc_name); } $frmUser->addRow(S_LANGUAGE, $cmbLang); $cmbTheme = new CComboBox('theme', $theme); $cmbTheme->addItem(ZBX_DEFAULT_CSS, S_SYSTEM_DEFAULT); $cmbTheme->addItem('css_ob.css', S_ORIGINAL_BLUE); $cmbTheme->addItem('css_bb.css', S_BLACK_AND_BLUE); $cmbTheme->addItem('css_od.css', S_DARK_ORANGE); $frmUser->addRow(S_THEME, $cmbTheme); $script = "javascript:\n\t\t\tvar autologout_visible = document.getElementById('autologout_visible');\n\t\t\tvar autologout = document.getElementById('autologout');\n\t\t\tif(this.checked){\n\t\t\t\tif(autologout_visible.checked){\n\t\t\t\t\tautologout_visible.checked = false;\n\t\t\t\t\tautologout_visible.onclick();\n\t\t\t\t}\n\t\t\t\tautologout_visible.disabled = true;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tautologout_visible.disabled = false;\n\t\t\t}"; $chkbx_autologin = new CCheckBox("autologin", $autologin, $script, 1); $chkbx_autologin->setAttribute('autocomplete', 'off'); $frmUser->addRow(S_AUTO_LOGIN, $chkbx_autologin); $script = "javascript: var autologout = document.getElementById('autologout');\n\t\t\t\t\tif(this.checked) autologout.disabled = false;\n\t\t\t\t\telse autologout.disabled = true;"; $autologoutCheckBox = new CCheckBox('autologout_visible', $autologout == 0 ? 'no' : 'yes', $script); $autologoutTextBox = new CNumericBox("autologout", $autologout == 0 ? '90' : $autologout, 4); // if autologout is disabled if ($autologout == 0) { $autologoutTextBox->setAttribute('disabled', 'disabled'); } if ($autologin != 0) { $autologoutCheckBox->setAttribute('disabled', 'disabled'); } $frmUser->addRow(S_AUTO_LOGOUT, array($autologoutCheckBox, $autologoutTextBox)); $frmUser->addRow(S_SCREEN_REFRESH, new CNumericBox('refresh', $refresh, 4)); $frmUser->addRow(S_ROWS_PER_PAGE, new CNumericBox('rows_per_page', $rows_per_page, 6)); $frmUser->addRow(S_URL_AFTER_LOGIN, new CTextBox("url", $url, 50)); //view Media Settings for users above "User" +++ if (uint_in_array($USER_DETAILS['type'], array(USER_TYPE_ZABBIX_ADMIN, USER_TYPE_SUPER_ADMIN))) { $frmUser->addVar('user_medias', $user_medias); $media_table = new CTableInfo(S_NO_MEDIA_DEFINED); foreach ($user_medias as $id => $one_media) { if (!isset($one_media['active']) || $one_media['active'] == 0) { $status = new CLink(S_ENABLED, '#', 'enabled'); $status->onClick('return create_var("' . $frmUser->getName() . '","disable_media",' . $id . ', true);'); } else { $status = new CLink(S_DISABLED, '#', 'disabled'); $status->onClick('return create_var("' . $frmUser->getName() . '","enable_media",' . $id . ', true);'); } $media_url = '?dstfrm=' . $frmUser->getName() . '&media=' . $id . '&mediatypeid=' . $one_media['mediatypeid'] . '&sendto=' . urlencode($one_media['sendto']) . '&period=' . $one_media['period'] . '&severity=' . $one_media['severity'] . '&active=' . $one_media['active']; $media_table->addRow(array(new CCheckBox('user_medias_to_del[' . $id . ']', null, null, $id), new CSpan($media_types[$one_media['mediatypeid']], 'nowrap'), new CSpan($one_media['sendto'], 'nowrap'), new CSpan($one_media['period'], 'nowrap'), media_severity2str($one_media['severity']), $status, new CButton('edit_media', S_EDIT, 'javascript: return PopUp("popup_media.php' . $media_url . '",550,400);'))); } $frmUser->addRow(S_MEDIA, array($media_table, new CButton('add_media', S_ADD, 'javascript: return PopUp("popup_media.php?dstfrm=' . $frmUser->getName() . '",550,400);'), SPACE, count($user_medias) > 0 ? new CButton('del_user_media', S_DELETE_SELECTED) : null)); } if (0 == $profile) { $frmUser->addVar('perm_details', $perm_details); $link = new CSpan($perm_details ? S_HIDE : S_SHOW, 'link'); $link->onClick("return create_var('" . $frmUser->getName() . "','perm_details'," . ($perm_details ? 0 : 1) . ", true);"); $resources_list = array(S_RIGHTS_OF_RESOURCES, SPACE . '(', $link, ')'); $frmUser->addSpanRow($resources_list, 'right_header'); if ($perm_details) { $group_ids = array_values($user_groups); if (count($group_ids) == 0) { $group_ids = array(-1); } $db_rights = DBselect('SELECT * FROM rights r WHERE ' . DBcondition('r.groupid', $group_ids)); $tmp_perm = array(); while ($db_right = DBfetch($db_rights)) { if (isset($tmp_perm[$db_right['id']])) { $tmp_perm[$db_right['id']] = min($tmp_perm[$db_right['id']], $db_right['permission']); } else { $tmp_perm[$db_right['id']] = $db_right['permission']; } } $user_rights = array(); foreach ($tmp_perm as $id => $perm) { array_push($user_rights, array('id' => $id, 'permission' => $perm)); } //SDI($user_rights); //SDI($user_type); $frmUser->addSpanRow(get_rights_of_elements_table($user_rights, $user_type)); } } if ($profile) { $msgVisibility = array('1' => array('messages[timeout]', 'messages[sounds.repeat]', 'messages[sounds.recovery]', 'messages[triggers.recovery]', 'timeout_row', 'repeat_row', 'triggers_row')); $frmUser->addRow(S_GUI_MESSAGING, new CCheckBox('messages[enabled]', $messages['enabled'], null, 1)); $newRow = $frmUser->addRow(S_MESSAGE_TIMEOUT . SPACE . '(' . S_SECONDS_SMALL . ')', new CNumericBox("messages[timeout]", $messages['timeout'], 5)); $newRow->setAttribute('id', 'timeout_row'); $repeatSound = new CComboBox('messages[sounds.repeat]', $messages['sounds.repeat'], 'javascript: if(IE) submit();'); $repeatSound->setAttribute('id', 'messages[sounds.repeat]'); $repeatSound->addItem(1, S_ONCE); $repeatSound->addItem(10, '10 ' . S_SECONDS); $repeatSound->addItem(-1, S_MESSAGE_TIMEOUT); $newRow = $frmUser->addRow(S_PLAY_SOUND, $repeatSound); $newRow->setAttribute('id', 'repeat_row'); // trigger sounds $severities = array(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_INFORMATION, TRIGGER_SEVERITY_WARNING, TRIGGER_SEVERITY_AVERAGE, TRIGGER_SEVERITY_HIGH, TRIGGER_SEVERITY_DISASTER); $zbxSounds = getSounds(); $triggers = new CTable('', 'invisible'); $soundList = new CComboBox('messages[sounds.recovery]', $messages['sounds.recovery']); foreach ($zbxSounds as $filename => $file) { $soundList->addItem($file, $filename); } $resolved = array(new CCheckBox('messages[triggers.recovery]', $messages['triggers.recovery'], null, 1), S_RECOVERY, $soundList, new CButton('start', S_PLAY, "javascript: testUserSound('messages[sounds.recovery]');", false), new CButton('stop', S_STOP, 'javascript: AudioList.stopAll();', false)); $triggers->addRow($resolved); foreach ($severities as $snum => $severity) { $soundList = new CComboBox('messages[sounds.' . $severity . ']', $messages['sounds.' . $severity]); foreach ($zbxSounds as $filename => $file) { $soundList->addItem($file, $filename); } $triggers->addRow(array(new CCheckBox('messages[triggers.severities][' . $severity . ']', isset($messages['triggers.severities'][$severity]), null, 1), getSeverityCaption($severity), $soundList, new CButton('start', S_PLAY, "javascript: testUserSound('messages[sounds." . $severity . "]');", false), new CButton('stop', S_STOP, 'javascript: AudioList.stopAll();', false))); zbx_subarray_push($msgVisibility, 1, 'messages[triggers.severities][' . $severity . ']'); zbx_subarray_push($msgVisibility, 1, 'messages[sounds.' . $severity . ']'); } $newRow = $frmUser->addRow(S_TRIGGER_SEVERITY, $triggers); $newRow->setAttribute('id', 'triggers_row'); zbx_add_post_js("var userMessageSwitcher = new CViewSwitcher('messages[enabled]', 'click', " . zbx_jsvalue($msgVisibility, true) . ");"); } $frmUser->addItemToBottomRow(new CButton('save', S_SAVE)); if (isset($userid) && $profile == 0) { $frmUser->addItemToBottomRow(SPACE); $delete_b = new CButtonDelete(S_DELETE_SELECTED_USER_Q, url_param("form") . url_param("config") . url_param("userid")); if (bccomp($USER_DETAILS['userid'], $userid) == 0) { $delete_b->setAttribute('disabled', 'disabled'); } $frmUser->addItemToBottomRow($delete_b); } $frmUser->addItemToBottomRow(SPACE); $frmUser->addItemToBottomRow(new CButtonCancel(url_param("config"))); return $frmUser; }
} //HOSTS // SPACE added to extend CB width in Chrome $cbMain = new CCheckBox('maintenance', $maintenance, null, '1'); if (!$filterEnable) { $cbMain->setAttribute('disabled', 'disabled'); } $dashForm->addRow(S_HOSTS, array($cbMain, S_SHOW_HOSTS_IN_MAINTENANCE)); // Trigger $severity = zbx_toHash($severity); $trgSeverities = array(); $severities = array(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_INFORMATION, TRIGGER_SEVERITY_WARNING, TRIGGER_SEVERITY_AVERAGE, TRIGGER_SEVERITY_HIGH, TRIGGER_SEVERITY_DISASTER); foreach ($severities as $snum => $sever) { $cb = new CCheckBox('trgSeverity[' . $sever . ']', isset($severity[$sever]), '', 1); $cb->setEnabled($filterEnable); $trgSeverities[] = array($cb, getSeverityCaption($sever)); $trgSeverities[] = BR(); } array_pop($trgSeverities); $dashForm->addRow(S_TRIGGERS_WITH_SEVERITY, $trgSeverities); $config = select_config(); $cb = new CComboBox('extAck', $extAck); $cb->addItems(array(EXTACK_OPTION_ALL => S_O_ALL, EXTACK_OPTION_BOTH => S_O_SEPARATED, EXTACK_OPTION_UNACK => S_O_UNACKNOWLEDGED_ONLY)); $cb->setEnabled($filterEnable && $config['event_ack_enable']); if (!$config['event_ack_enable']) { $cb->setAttribute('title', S_EVENT_ACKNOWLEDGING_DISABLED); } $dashForm->addRow(S_PROBLEM_DISPLAY, $cb); //----- $dashForm->addItemToBottomRow(new CButton('save', S_SAVE)); $dashboard_wdgt->addItem($dashForm);
break; case CONDITION_TYPE_TRIGGER_NAME: $condition = new CTextBox('new_condition[value]', '', ZBX_TEXTBOX_STANDARD_SIZE); break; case CONDITION_TYPE_TRIGGER_VALUE: $condition = new CComboBox('new_condition[value]'); foreach (array(TRIGGER_VALUE_FALSE, TRIGGER_VALUE_TRUE) as $trigerValue) { $condition->addItem($trigerValue, trigger_value2str($trigerValue)); } break; case CONDITION_TYPE_TIME_PERIOD: $condition = new CTextBox('new_condition[value]', ZBX_DEFAULT_INTERVAL, ZBX_TEXTBOX_STANDARD_SIZE); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $condition = new CComboBox('new_condition[value]'); $condition->addItems(getSeverityCaption()); break; case CONDITION_TYPE_MAINTENANCE: $condition = new CCol(_('maintenance')); break; case CONDITION_TYPE_NODE: $conditionFormList->addItem(new CVar('new_condition[value]', '0')); $condition = array(new CTextBox('node', '', ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), SPACE, new CButton('btn1', _('Select'), 'return PopUp("popup.php?srctbl=nodes&srcfld1=nodeid&srcfld2=name' . '&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value&dstfld2=node' . '&writeonly=1", 450, 450);', 'link_menu')); break; case CONDITION_TYPE_DRULE: $conditionFormList->addItem(new CVar('new_condition[value]', '0')); $condition = array(new CTextBox('drule', '', ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), SPACE, new CButton('btn1', _('Select'), 'return PopUp("popup.php?srctbl=drules&srcfld1=druleid&srcfld2=name' . '&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value&dstfld2=drule", 450, 450);', 'link_menu')); break; case CONDITION_TYPE_DCHECK: $conditionFormList->addItem(new CVar('new_condition[value]', '0')); $condition = array(new CTextBox('dcheck', '', ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), SPACE, new CButton('btn1', _('Select'), 'return PopUp("popup.php?srctbl=dchecks&srcfld1=dcheckid&srcfld2=name' . '&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value&dstfld2=dcheck&writeonly=1", 450, 450);', 'link_menu'));
/** * Create control for trigger severities. * It's mostly the same as usual button set, but background color is changed based on selected severiity. * Js file "/include/views/js/configuration.triggers.edit.js.php" is needed to make it work correcty. * * @param $selectedSeverity * * @return CDiv */ function getSeverityControl($selectedSeverity = TRIGGER_SEVERITY_NOT_CLASSIFIED) { $controls = array(); foreach (getSeverityCaption() as $severity => $caption) { $controls[] = new CRadioButton('priority', $severity, null, 'severity_' . $severity, $selectedSeverity == $severity); $label = new CLabel($caption, 'severity_' . $severity, 'severity_label_' . $severity); $label->attr('data-severity', $severity); $label->attr('data-severity-style', getSeverityStyle($severity)); $controls[] = $label; } return new CDiv($controls, 'jqueryinputset control-severity'); }
$frmTRLog->addVar('expressions[' . $id . '][view]', $expr['view']); $maxid = $maxid < $id ? $id : $maxid; } zbx_add_post_js('logexpr_count=' . ($maxid + 1)); $maxid = 0; foreach ($keys as $id => $val) { $del_url = new CLink(_('Delete'), '#', 'action', 'javascript: if(confirm("' . _('Delete keyword?') . '")) remove_keyword("keytr' . $id . '"); return false;'); $row = new CRow(array(htmlspecialchars($val['value']), $val['type'], $del_url)); $row->setAttribute('id', 'keytr' . $id); $keyTable->addRow($row); $frmTRLog->addVar('keys[' . $id . '][value]', $val['value']); $frmTRLog->addVar('keys[' . $id . '][type]', $val['type']); $maxid = $maxid < $id ? $id : $maxid; } zbx_add_post_js('key_count=' . ($maxid + 1)); $frmTRLog->addRow(SPACE, $keyTable); $frmTRLog->addRow(SPACE, $table); $sev_select = new CComboBox('priority', $priority); $sev_select->addItems(getSeverityCaption()); $frmTRLog->addRow(_('Severity'), $sev_select); $frmTRLog->addRow(_('Comments'), new CTextArea('comments', $comments)); $frmTRLog->addRow(_('URL'), new CTextBox('url', $url, 80)); $frmTRLog->addRow(_('Disabled'), new CCheckBox('status', $status == TRIGGER_STATUS_DISABLED ? 'yes' : 'no', null, 1)); $frmTRLog->addItemToBottomRow(new CSubmit('save_trigger', _('Save'), 'javascript: document.forms[0].action += \'?saction=1\';')); $frmTRLog->addItemToBottomRow(SPACE); $frmTRLog->addItemToBottomRow(new CButton('cancel', _('Cancel'), 'javascript: self.close();')); if ($bExprResult) { $frmTRLog->show(); } } require_once dirname(__FILE__) . '/include/page_footer.php';
} $statusSpan = new CSpan(trigger_value2str($event['value'])); // add colors and blinking to span depending on configuration and trigger parameters addTriggerValueStyle($statusSpan, $event['value'], $event['clock'], $event['acknowledged']); // host JS menu link $hostSpan = null; if ($_REQUEST['hostid'] == 0) { $hostSpan = new CSpan($host['name'], 'link_menu menu-host'); $scripts = $hostScripts[$host['hostid']]; $hostSpan->setAttribute('data-menu', hostMenuData($host, $scripts)); } // action $action = isset($actions[$event['eventid']]) ? $actions[$event['eventid']] : ' - '; $table->addRow(array(new CLink(zbx_date2str(EVENTS_ACTION_TIME_FORMAT, $event['clock']), 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid'], 'action'), is_show_all_nodes() ? get_node_name_by_elid($event['objectid']) : null, $hostSpan, new CSpan($tr_desc, 'link_menu'), $statusSpan, getSeverityCell($trigger['priority'], null, !$event['value']), $event['duration'], $config['event_ack_enable'] ? $ack : null, $action)); if ($CSV_EXPORT) { $csvRows[] = array(zbx_date2str(EVENTS_ACTION_TIME_FORMAT, $event['clock']), is_show_all_nodes() ? get_node_name_by_elid($event['objectid']) : null, $_REQUEST['hostid'] == 0 ? $host['name'] : null, $description, trigger_value2str($event['value']), getSeverityCaption($trigger['priority']), $event['duration'], $config['event_ack_enable'] ? $event['acknowledges'] ? _('Yes') : _('No') : null, strip_tags((string) $action)); } } } else { $events = array(); $paging = getPagingLine($events); } } if ($CSV_EXPORT) { print zbx_toCSV($csvRows); exit; } $table = array($paging, $table, $paging); } $events_wdgt->addItem($table); // NAV BAR
public function bodyToString() { $this->cleanItems(); $okCount = 0; $notClassifiedCount = 0; $informationCount = 0; $warningCount = 0; $averageCount = 0; $highCount = 0; $disasterCount = 0; $options = array('output' => array('triggerid', 'priority', 'value'), 'monitored' => true, 'skipDependent' => true); if ($this->hostid > 0) { $options['hostids'] = $this->hostid; } elseif ($this->groupid > 0) { $options['groupids'] = $this->groupid; } $triggers = API::Trigger()->get($options); foreach ($triggers as $trigger) { if ($trigger['value'] == TRIGGER_VALUE_TRUE) { switch ($trigger['priority']) { case TRIGGER_SEVERITY_NOT_CLASSIFIED: $notClassifiedCount++; break; case TRIGGER_SEVERITY_INFORMATION: $informationCount++; break; case TRIGGER_SEVERITY_WARNING: $warningCount++; break; case TRIGGER_SEVERITY_AVERAGE: $averageCount++; break; case TRIGGER_SEVERITY_HIGH: $highCount++; break; case TRIGGER_SEVERITY_DISASTER: $disasterCount++; break; } } elseif ($trigger['value'] == TRIGGER_VALUE_FALSE) { $okCount++; } } if ($this->show_header) { $header_str = _('Triggers info') . SPACE; if ($this->groupid != 0) { $group = get_hostgroup_by_groupid($this->groupid); $header_str .= _('Group') . SPACE . '"' . $group['name'] . '"'; } else { $header_str .= _('All groups'); } $header = new CCol($header_str, 'header'); if ($this->style == STYLE_HORIZONTAL) { $header->setColspan(8); } $this->addRow($header); } $okCount = getSeverityCell(null, $okCount . SPACE . _('Ok'), true); $notClassifiedCount = getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $notClassifiedCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED), !$notClassifiedCount); $informationCount = getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $informationCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_INFORMATION), !$informationCount); $warningCount = getSeverityCell(TRIGGER_SEVERITY_WARNING, $warningCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_WARNING), !$warningCount); $averageCount = getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $averageCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_AVERAGE), !$averageCount); $highCount = getSeverityCell(TRIGGER_SEVERITY_HIGH, $highCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_HIGH), !$highCount); $disasterCount = getSeverityCell(TRIGGER_SEVERITY_DISASTER, $disasterCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_DISASTER), !$disasterCount); if (STYLE_HORIZONTAL == $this->style) { $this->addRow(array($okCount, $notClassifiedCount, $informationCount, $warningCount, $averageCount, $highCount, $disasterCount)); } else { $this->addRow($okCount); $this->addRow($notClassifiedCount); $this->addRow($informationCount); $this->addRow($warningCount); $this->addRow($averageCount); $this->addRow($highCount); $this->addRow($disasterCount); } return parent::bodyToString(); }
public function bodyToString() { $this->cleanItems(); $ok = $uncl = $info = $warn = $avg = $high = $dis = 0; $options = array('monitored' => true, 'skipDependent' => true, 'output' => API_OUTPUT_SHORTEN); if ($this->hostid > 0) { $options['hostids'] = $this->hostid; } elseif ($this->groupid > 0) { $options['groupids'] = $this->groupid; } $triggers = API::Trigger()->get($options); $triggers = zbx_objectValues($triggers, 'triggerid'); $db_priority = DBselect('SELECT t.priority,t.value,count(DISTINCT t.triggerid) AS cnt' . ' FROM triggers t' . ' WHERE ' . dbConditionInt('t.triggerid', $triggers) . ' GROUP BY t.priority,t.value'); while ($row = DBfetch($db_priority)) { switch ($row['value']) { case TRIGGER_VALUE_TRUE: switch ($row['priority']) { case TRIGGER_SEVERITY_NOT_CLASSIFIED: $uncl += $row['cnt']; break; case TRIGGER_SEVERITY_INFORMATION: $info += $row['cnt']; break; case TRIGGER_SEVERITY_WARNING: $warn += $row['cnt']; break; case TRIGGER_SEVERITY_AVERAGE: $avg += $row['cnt']; break; case TRIGGER_SEVERITY_HIGH: $high += $row['cnt']; break; case TRIGGER_SEVERITY_DISASTER: $dis += $row['cnt']; break; } break; case TRIGGER_VALUE_FALSE: $ok += $row['cnt']; break; } } if ($this->show_header) { $header_str = _('Triggers info') . SPACE; if (!is_null($this->nodeid)) { $node = get_node_by_nodeid($this->nodeid); if ($node > 0) { $header_str .= '(' . $node['name'] . ')' . SPACE; } } if (remove_nodes_from_id($this->groupid) > 0) { $group = get_hostgroup_by_groupid($this->groupid); $header_str .= _('Group') . SPACE . '"' . $group['name'] . '"'; } else { $header_str .= _('All groups'); } $header = new CCol($header_str, 'header'); if ($this->style == STYLE_HORISONTAL) { $header->setColspan(8); } $this->addRow($header); } $trok = getSeverityCell(null, $ok . SPACE . _('Ok'), true); $uncl = getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $uncl . SPACE . getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED), !$uncl); $info = getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $info . SPACE . getSeverityCaption(TRIGGER_SEVERITY_INFORMATION), !$info); $warn = getSeverityCell(TRIGGER_SEVERITY_WARNING, $warn . SPACE . getSeverityCaption(TRIGGER_SEVERITY_WARNING), !$warn); $avg = getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $avg . SPACE . getSeverityCaption(TRIGGER_SEVERITY_AVERAGE), !$avg); $high = getSeverityCell(TRIGGER_SEVERITY_HIGH, $high . SPACE . getSeverityCaption(TRIGGER_SEVERITY_HIGH), !$high); $dis = getSeverityCell(TRIGGER_SEVERITY_DISASTER, $dis . SPACE . getSeverityCaption(TRIGGER_SEVERITY_DISASTER), !$dis); if (STYLE_HORISONTAL == $this->style) { $this->addRow(array($trok, $uncl, $info, $warn, $avg, $high, $dis)); } else { $this->addRow($trok); $this->addRow($uncl); $this->addRow($info); $this->addRow($warn); $this->addRow($avg); $this->addRow($high); $this->addRow($dis); } return parent::bodyToString(); }
/** * Initialize minimum trigger severities. * * @param string $severityMin * @param array $options * @param int $options['default'] * @param string $options['mapId'] */ private function _initSeveritiesMin($severityMin, array $options = array()) { $default = isset($options['default']) ? $options['default'] : TRIGGER_SEVERITY_NOT_CLASSIFIED; $mapId = isset($options['mapId']) ? $options['mapId'] : 0; $severityMinProfile = isset($this->_profileIds['severityMin']) ? $this->_profileIds['severityMin'] : null; if ($severityMin === null && $severityMinProfile !== null) { $severityMin = $severityMinProfile; } if ($severityMin !== null) { if ($severityMin == $default) { CProfile::delete($this->_profileIdx['severityMin'], $mapId); } else { CProfile::update($this->_profileIdx['severityMin'], $severityMin, PROFILE_TYPE_INT, $mapId); } } $this->data['severitiesMin'] = getSeverityCaption(); $this->data['severitiesMin'][$default] = $this->data['severitiesMin'][$default] . SPACE . '(' . _('default') . ')'; $this->ids['severityMin'] = $severityMin === null ? $default : $severityMin; }
if ($config['event_ack_enable']) { $cb_ack_status = new CComboBox('ack_status', $ack_status); $cb_ack_status->addItem(ZBX_ACK_STS_ANY, _('Any')); $cb_ack_status->additem(ZBX_ACK_STS_WITH_UNACK, _('With unacknowledged events')); $cb_ack_status->additem(ZBX_ACK_STS_WITH_LAST_UNACK, _('With last event unacknowledged')); $filterForm->addRow(_('Acknowledge status'), $cb_ack_status); } $ev_select = new CComboBox('show_events', $_REQUEST['show_events']); $ev_select->addItem(EVENTS_OPTION_NOEVENT, _('Hide all')); $ev_select->addItem(EVENTS_OPTION_ALL, _('Show all') . ' (' . $config['event_expire'] . ' ' . ($config['event_expire'] > 1 ? _('Days') : _('Day')) . ')'); if ($config['event_ack_enable']) { $ev_select->addItem(EVENTS_OPTION_NOT_ACK, _('Show unacknowledged') . ' (' . $config['event_expire'] . ' ' . ($config['event_expire'] > 1 ? _('Days') : _('Day')) . ')'); } $filterForm->addRow(_('Events'), $ev_select); $severity_select = new CComboBox('show_severity', $show_severity); $cb_items = array(-1 => _('All'), TRIGGER_SEVERITY_NOT_CLASSIFIED => getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED), TRIGGER_SEVERITY_INFORMATION => getSeverityCaption(TRIGGER_SEVERITY_INFORMATION), TRIGGER_SEVERITY_WARNING => getSeverityCaption(TRIGGER_SEVERITY_WARNING), TRIGGER_SEVERITY_AVERAGE => getSeverityCaption(TRIGGER_SEVERITY_AVERAGE), TRIGGER_SEVERITY_HIGH => getSeverityCaption(TRIGGER_SEVERITY_HIGH), TRIGGER_SEVERITY_DISASTER => getSeverityCaption(TRIGGER_SEVERITY_DISASTER)); $severity_select->addItems($cb_items); $filterForm->addRow(_('Min severity'), $severity_select); $action = 'javascript: this.checked ? $("status_change_days").enable() : $("status_change_days").disable()'; $sts_change_days_cb = new CNumericBox('status_change_days', $_REQUEST['status_change_days'], 4); if (!$_REQUEST['status_change']) { $sts_change_days_cb->setAttribute('disabled', 'disabled'); } $sts_change_days_cb->addStyle('vertical-align: middle;'); $cbd = new CCheckBox('status_change', $_REQUEST['status_change'], $action, 1); $cbd->addStyle('vertical-align: middle;'); $spand = new CSpan(_('days')); $spand->addStyle('vertical-align: middle;'); $filterForm->addRow(_('Age less than'), array($cbd, $sts_change_days_cb, $spand)); $filterForm->addRow(_('Show details'), new CCheckBox('show_details', $_REQUEST['show_details'], null, 1)); $filterForm->addRow(_('Filter by name'), new CTextBox('txt_select', $_REQUEST['txt_select'], 40));
foreach ($events as $event) { $trigger = $triggers[$event['objectid']]; $host = reset($trigger['hosts']); $host = $hosts[$host['hostid']]; $triggerItems = array(); $trigger['items'] = CMacrosResolverHelper::resolveItemNames($trigger['items']); foreach ($trigger['items'] as $item) { $triggerItems[] = array('name' => $item['name_expanded'], 'params' => array('itemid' => $item['itemid'], 'action' => in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? HISTORY_GRAPH : HISTORY_VALUES)); } $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, array('clock' => $event['clock'], 'ns' => $event['ns']))); // duration $event['duration'] = ($nextEvent = get_next_event($event, $events)) ? zbx_date2age($event['clock'], $nextEvent['clock']) : zbx_date2age($event['clock']); // action $action = isset($actions[$event['eventid']]) ? $actions[$event['eventid']] : ' - '; if ($csvExport) { $csvRows[] = array(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), getRequest('hostid', 0) == 0 ? $host['name'] : null, $description, trigger_value2str($event['value']), getSeverityCaption($trigger['priority']), $event['duration'], $config['event_ack_enable'] ? $event['acknowledges'] ? _('Yes') : _('No') : null, strip_tags((string) $action)); } else { $triggerDescription = new CSpan($description, 'pointer link_menu'); $triggerDescription->setMenuPopup(CMenuPopupHelper::getTrigger($trigger, $triggerItems, null, $event['clock'])); // acknowledge $ack = getEventAckState($event, true); // add colors and blinking to span depending on configuration and trigger parameters $statusSpan = new CSpan(trigger_value2str($event['value'])); addTriggerValueStyle($statusSpan, $event['value'], $event['clock'], $event['acknowledged']); // host JS menu link $hostName = null; if (getRequest('hostid', 0) == 0) { $hostName = new CSpan($host['name'], 'link_menu'); $hostName->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$host['hostid']])); } $table->addRow(array(new CLink(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid'], 'action'), $hostName, $triggerDescription, $statusSpan, getSeverityCell($trigger['priority'], null, !$event['value']), $event['duration'], $config['event_ack_enable'] ? $ack : null, $action));
$soundList = new CComboBox('messages[sounds.recovery]', $this->data['messages']['sounds.recovery']); foreach ($zbxSounds as $filename => $file) { $soundList->addItem($file, $filename); } $resolved = array(new CCheckBox('messages[triggers.recovery]', $this->data['messages']['triggers.recovery'], null, 1), _('Recovery'), SPACE, $soundList, new CButton('start', _('Play'), "javascript: testUserSound('messages_sounds.recovery');", 'formlist'), new CButton('stop', _('Stop'), 'javascript: AudioControl.stop();', 'formlist')); $triggersTable = new CTable('', 'invisible'); $triggersTable->addRow($resolved); $msgVisibility = array('1' => array('messages[timeout]', 'messages[sounds.repeat]', 'messages[sounds.recovery]', 'messages[triggers.recovery]', 'timeout_row', 'repeat_row', 'triggers_row')); // trigger sounds $severities = array(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_INFORMATION, TRIGGER_SEVERITY_WARNING, TRIGGER_SEVERITY_AVERAGE, TRIGGER_SEVERITY_HIGH, TRIGGER_SEVERITY_DISASTER); foreach ($severities as $severity) { $soundList = new CComboBox('messages[sounds.' . $severity . ']', $this->data['messages']['sounds.' . $severity]); foreach ($zbxSounds as $filename => $file) { $soundList->addItem($file, $filename); } $triggersTable->addRow(array(new CCheckBox('messages[triggers.severities][' . $severity . ']', isset($this->data['messages']['triggers.severities'][$severity]), null, 1), getSeverityCaption($severity), SPACE, $soundList, new CButton('start', _('Play'), "javascript: testUserSound('messages_sounds." . $severity . "');", 'formlist'), new CButton('stop', _('Stop'), 'javascript: AudioControl.stop();', 'formlist'))); zbx_subarray_push($msgVisibility, 1, 'messages[triggers.severities][' . $severity . ']'); zbx_subarray_push($msgVisibility, 1, 'messages[sounds.' . $severity . ']'); } $userMessagingFormList->addRow(_('Trigger severity'), $triggersTable, false, 'triggers_row'); zbx_add_post_js("\n\t\tjQuery('#messages_enabled').bind('click', function() {\n\t\t\tif (this.checked\n\t\t\t\t\t&& !jQuery(\"input[id='messages_triggers.recovery']\").is(':checked')\n\t\t\t\t\t&& !jQuery(\"input[id='messages_triggers.severities_0']\").is(':checked')\n\t\t\t\t\t&& !jQuery(\"input[id='messages_triggers.severities_1']\").is(':checked')\n\t\t\t\t\t&& !jQuery(\"input[id='messages_triggers.severities_2']\").is(':checked')\n\t\t\t\t\t&& !jQuery(\"input[id='messages_triggers.severities_3']\").is(':checked')\n\t\t\t\t\t&& !jQuery(\"input[id='messages_triggers.severities_4']\").is(':checked')\n\t\t\t\t\t&& !jQuery(\"input[id='messages_triggers.severities_5']\").is(':checked')) {\n\t\t\t\tjQuery(\"input[id='messages_triggers.recovery']\").attr('checked', true);\n\t\t\t\tjQuery(\"input[id='messages_triggers.severities_0']\").attr('checked', true);\n\t\t\t\tjQuery(\"input[id='messages_triggers.severities_1']\").attr('checked', true);\n\t\t\t\tjQuery(\"input[id='messages_triggers.severities_2']\").attr('checked', true);\n\t\t\t\tjQuery(\"input[id='messages_triggers.severities_3']\").attr('checked', true);\n\t\t\t\tjQuery(\"input[id='messages_triggers.severities_4']\").attr('checked', true);\n\t\t\t\tjQuery(\"input[id='messages_triggers.severities_5']\").attr('checked', true);\n\t\t\t}\n\n\t\t\t// enable/disable childs fields\n\t\t\tif (this.checked) {\n\t\t\t\tjQuery('#messagingTab input, #messagingTab select').removeAttr('disabled');\n\t\t\t}\n\t\t\telse {\n\t\t\t\tjQuery('#messagingTab input, #messagingTab select').attr('disabled', 'disabled');\n\t\t\t\tjQuery('#messages_enabled').removeAttr('disabled');\n\t\t\t}\n\t\t});\n\n\t\t// initial state: enable/disable childs fields\n\t\tif (jQuery('#messages_enabled').is(':checked')) {\n\t\t\tjQuery('#messagingTab input, #messagingTab select').removeAttr('disabled');\n\t\t}\n\t\telse {\n\t\t\tjQuery('#messagingTab input, #messagingTab select').attr('disabled', 'disabled');\n\t\t\tjQuery('#messages_enabled').removeAttr('disabled');\n\t\t}"); } // append form lists to tab $userTab = new CTabView(); if (!$this->data['form_refresh']) { $userTab->setSelected(0); } $userTab->addTab('userTab', _('User'), $userFormList); if (isset($userMediaFormList)) { $userTab->addTab('mediaTab', _('Media'), $userMediaFormList); }
// trigger status $filterForm->addRow(_('Triggers status'), new CComboBox('show_triggers', $filter['showTriggers'], null, array(TRIGGERS_OPTION_ALL => _('Any'), TRIGGERS_OPTION_RECENT_PROBLEM => _('Recent problem'), TRIGGERS_OPTION_IN_PROBLEM => _('Problem')))); // ack status if ($config['event_ack_enable']) { $filterForm->addRow(_('Acknowledge status'), new CComboBox('ack_status', $filter['ackStatus'], null, array(ZBX_ACK_STS_ANY => _('Any'), ZBX_ACK_STS_WITH_UNACK => _('With unacknowledged events'), ZBX_ACK_STS_WITH_LAST_UNACK => _('With last event unacknowledged')))); } // events if (!$overview) { $eventsComboBox = new CComboBox('show_events', $filter['showEvents'], null, array(EVENTS_OPTION_NOEVENT => _('Hide all'), EVENTS_OPTION_ALL => _n('Show all (%1$s day)', 'Show all (%1$s days)', $config['event_expire']))); if ($config['event_ack_enable']) { $eventsComboBox->addItem(EVENTS_OPTION_NOT_ACK, _n('Show unacknowledged (%1$s day)', 'Show unacknowledged (%1$s days)', $config['event_expire'])); } $filterForm->addRow(_('Events'), $eventsComboBox); } // min severity $filterForm->addRow(_('Minimum trigger severity'), new CComboBox('show_severity', $filter['showSeverity'], null, array(TRIGGER_SEVERITY_NOT_CLASSIFIED => getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED), TRIGGER_SEVERITY_INFORMATION => getSeverityCaption(TRIGGER_SEVERITY_INFORMATION), TRIGGER_SEVERITY_WARNING => getSeverityCaption(TRIGGER_SEVERITY_WARNING), TRIGGER_SEVERITY_AVERAGE => getSeverityCaption(TRIGGER_SEVERITY_AVERAGE), TRIGGER_SEVERITY_HIGH => getSeverityCaption(TRIGGER_SEVERITY_HIGH), TRIGGER_SEVERITY_DISASTER => getSeverityCaption(TRIGGER_SEVERITY_DISASTER)))); // age less than $statusChangeDays = new CNumericBox('status_change_days', $filter['statusChangeDays'], 3, false, false, false); if (!$filter['statusChange']) { $statusChangeDays->setAttribute('disabled', 'disabled'); } $statusChangeDays->addStyle('vertical-align: middle;'); $statusChangeCheckBox = new CCheckBox('status_change', $filter['statusChange'], 'javascript: this.checked ? $("status_change_days").enable() : $("status_change_days").disable()', 1); $statusChangeCheckBox->addStyle('vertical-align: middle;'); $daysSpan = new CSpan(_('days')); $daysSpan->addStyle('vertical-align: middle;'); $filterForm->addRow(_('Age less than'), array($statusChangeCheckBox, $statusChangeDays, SPACE, $daysSpan)); // name $filterForm->addRow(_('Filter by name'), new CTextBox('txt_select', $filter['txtSelect'], 40)); // application $filterForm->addRow(_('Filter by application'), array(new CTextBox('application', $filter['application'], 40), new CButton('application_name', _('Select'), 'return PopUp("popup.php?srctbl=applications&srcfld1=name&real_hosts=1&dstfld1=application&with_applications=1' . '&dstfrm=' . $filterForm->getName() . '");', 'filter-button')));
case CONDITION_TYPE_TRIGGER_NAME: $rowCondition[] = new CTextBox('new_condition[value]', '', ZBX_TEXTBOX_STANDARD_SIZE); break; case CONDITION_TYPE_TRIGGER_VALUE: $conditionValueComboBox = new CComboBox('new_condition[value]'); foreach (array(TRIGGER_VALUE_FALSE, TRIGGER_VALUE_TRUE) as $trigerValue) { $conditionValueComboBox->addItem($trigerValue, trigger_value2str($trigerValue)); } $rowCondition[] = $conditionValueComboBox; break; case CONDITION_TYPE_TIME_PERIOD: $rowCondition[] = new CTextBox('new_condition[value]', ZBX_DEFAULT_INTERVAL, ZBX_TEXTBOX_STANDARD_SIZE); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $conditionValueComboBox = new CComboBox('new_condition[value]'); $conditionValueComboBox->addItems(getSeverityCaption()); $rowCondition[] = $conditionValueComboBox; break; case CONDITION_TYPE_MAINTENANCE: $rowCondition[] = new CCol(_('maintenance')); break; case CONDITION_TYPE_NODE: $conditionFormList->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('node', '', ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), SPACE, new CButton('btn1', _('Select'), 'return PopUp("popup.php?srctbl=nodes&srcfld1=nodeid&srcfld2=name' . '&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value&dstfld2=node' . '&writeonly=1", 450, 450);', 'link_menu')); break; case CONDITION_TYPE_DRULE: $conditionFormList->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('drule', '', ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), SPACE, new CButton('btn1', _('Select'), 'return PopUp("popup.php?srctbl=drules&srcfld1=druleid&srcfld2=name' . '&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value&dstfld2=drule", 450, 450);', 'link_menu')); break; case CONDITION_TYPE_DCHECK: $conditionFormList->addItem(new CVar('new_condition[value]', '0'));
function condition_value2str($conditiontype, $value) { switch ($conditiontype) { case CONDITION_TYPE_HOST_GROUP: $groups = API::HostGroup()->get(array('groupids' => $value, 'output' => array('name'), 'nodeids' => get_current_nodeid(true), 'limit' => 1)); if ($groups) { $group = reset($groups); $str_val = ''; if (id2nodeid($value) != get_current_nodeid()) { $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER); } $str_val .= $group['name']; } else { return _('Unknown'); } break; case CONDITION_TYPE_TRIGGER: $trigs = API::Trigger()->get(array('triggerids' => $value, 'expandDescription' => true, 'output' => array('description'), 'selectHosts' => array('name'), 'nodeids' => get_current_nodeid(true), 'limit' => 1)); if ($trigs) { $trig = reset($trigs); $host = reset($trig['hosts']); $str_val = ''; if (id2nodeid($value) != get_current_nodeid()) { $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER); } $str_val .= $host['name'] . NAME_DELIMITER . $trig['description']; } else { return _('Unknown'); } break; case CONDITION_TYPE_HOST: case CONDITION_TYPE_TEMPLATE: if ($host = get_host_by_hostid($value)) { $str_val = ''; if (id2nodeid($value) != get_current_nodeid()) { $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER); } $str_val .= $host['name']; } else { return _('Unknown'); } break; case CONDITION_TYPE_TRIGGER_NAME: case CONDITION_TYPE_HOST_METADATA: case CONDITION_TYPE_HOST_NAME: $str_val = $value; break; case CONDITION_TYPE_TRIGGER_VALUE: $str_val = trigger_value2str($value); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $str_val = getSeverityCaption($value); break; case CONDITION_TYPE_TIME_PERIOD: $str_val = $value; break; case CONDITION_TYPE_MAINTENANCE: $str_val = _('maintenance'); break; case CONDITION_TYPE_NODE: if ($node = get_node_by_nodeid($value)) { $str_val = $node['name']; } else { return _('Unknown'); } break; case CONDITION_TYPE_DRULE: if ($drule = get_discovery_rule_by_druleid($value)) { $str_val = $drule['name']; } else { return _('Unknown'); } break; case CONDITION_TYPE_DCHECK: $row = DBfetch(DBselect('SELECT dr.name,c.dcheckid,c.type,c.key_,c.ports' . ' FROM drules dr,dchecks c' . ' WHERE dr.druleid=c.druleid' . ' AND c.dcheckid=' . zbx_dbstr($value))); if ($row) { $str_val = $row['name'] . NAME_DELIMITER . discovery_check2str($row['type'], $row['key_'], $row['ports']); } else { return _('Unknown'); } break; case CONDITION_TYPE_DOBJECT: $str_val = discovery_object2str($value); break; case CONDITION_TYPE_PROXY: if ($host = get_host_by_hostid($value)) { $str_val = $host['host']; } else { return _('Unknown'); } break; case CONDITION_TYPE_DHOST_IP: $str_val = $value; break; case CONDITION_TYPE_DSERVICE_TYPE: $str_val = discovery_check_type2str($value); break; case CONDITION_TYPE_DSERVICE_PORT: $str_val = $value; break; case CONDITION_TYPE_DSTATUS: $str_val = discovery_object_status2str($value); break; case CONDITION_TYPE_DUPTIME: $str_val = $value; break; case CONDITION_TYPE_DVALUE: $str_val = $value; break; case CONDITION_TYPE_EVENT_ACKNOWLEDGED: $str_val = $value ? _('Ack') : _('Not Ack'); break; case CONDITION_TYPE_APPLICATION: $str_val = $value; break; case CONDITION_TYPE_EVENT_TYPE: $str_val = eventType($value); break; default: return _('Unknown'); } return $str_val; }
if ($config['event_ack_enable']) { $ackStatusComboBox = new CComboBox('ack_status', $ackStatus); $ackStatusComboBox->addItem(ZBX_ACK_STS_ANY, _('Any')); $ackStatusComboBox->additem(ZBX_ACK_STS_WITH_UNACK, _('With unacknowledged events')); $ackStatusComboBox->additem(ZBX_ACK_STS_WITH_LAST_UNACK, _('With last event unacknowledged')); $filterForm->addRow(_('Acknowledge status'), $ackStatusComboBox); } $eventsComboBox = new CComboBox('show_events', $_REQUEST['show_events']); $eventsComboBox->addItem(EVENTS_OPTION_NOEVENT, _('Hide all')); $eventsComboBox->addItem(EVENTS_OPTION_ALL, _('Show all') . ' (' . $config['event_expire'] . ' ' . ($config['event_expire'] > 1 ? _('Days') : _('Day')) . ')'); if ($config['event_ack_enable']) { $eventsComboBox->addItem(EVENTS_OPTION_NOT_ACK, _('Show unacknowledged') . ' (' . $config['event_expire'] . ' ' . ($config['event_expire'] > 1 ? _('Days') : _('Day')) . ')'); } $filterForm->addRow(_('Events'), $eventsComboBox); $severityComboBox = new CComboBox('show_severity', $showSeverity); $severityComboBox->addItems(array(TRIGGER_SEVERITY_NOT_CLASSIFIED => getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED), TRIGGER_SEVERITY_INFORMATION => getSeverityCaption(TRIGGER_SEVERITY_INFORMATION), TRIGGER_SEVERITY_WARNING => getSeverityCaption(TRIGGER_SEVERITY_WARNING), TRIGGER_SEVERITY_AVERAGE => getSeverityCaption(TRIGGER_SEVERITY_AVERAGE), TRIGGER_SEVERITY_HIGH => getSeverityCaption(TRIGGER_SEVERITY_HIGH), TRIGGER_SEVERITY_DISASTER => getSeverityCaption(TRIGGER_SEVERITY_DISASTER))); $filterForm->addRow(_('Minimum trigger severity'), $severityComboBox); $statusChangeDays = new CNumericBox('status_change_days', $_REQUEST['status_change_days'], 3, false, false, false); if (!$_REQUEST['status_change']) { $statusChangeDays->setAttribute('disabled', 'disabled'); } $statusChangeDays->addStyle('vertical-align: middle;'); $statusChangeCheckBox = new CCheckBox('status_change', $_REQUEST['status_change'], 'javascript: this.checked ? $("status_change_days").enable() : $("status_change_days").disable()', 1); $statusChangeCheckBox->addStyle('vertical-align: middle;'); $daysSpan = new CSpan(_('days')); $daysSpan->addStyle('vertical-align: middle;'); $filterForm->addRow(_('Age less than'), array($statusChangeCheckBox, $statusChangeDays, SPACE, $daysSpan)); $filterForm->addRow(_('Show details'), new CCheckBox('show_details', $_REQUEST['show_details'], null, 1)); $filterForm->addRow(_('Filter by name'), new CTextBox('txt_select', $_REQUEST['txt_select'], 40)); $filterForm->addRow(_('Show hosts in maintenance'), new CCheckBox('show_maintenance', $_REQUEST['show_maintenance'], null, 1)); $filterForm->addItemToBottomRow(new CSubmit('filter_set', _('Filter'), 'chkbxRange.clearSelectedOnFilterChange();'));
/** * Validate conditions. * * @static * * @param array $conditions * @param int $conditions['conditiontype'] * @param array $conditions['value'] * * @return bool */ public static function validateConditions($conditions, $update = false) { $conditions = zbx_toArray($conditions); $hostGroupIdsAll = array(); $templateIdsAll = array(); $triggerIdsAll = array(); $hostIdsAll = array(); $discoveryRuleIdsAll = array(); $proxyIdsAll = array(); $proxyidsAll = array(); // build validators $timePeriodValidator = new CTimePeriodValidator(); $discoveryCheckTypeValidator = new CSetValidator(array('values' => array_keys(discovery_check_type2str()))); $discoveryObjectStatusValidator = new CSetValidator(array('values' => array_keys(discovery_object_status2str()))); $triggerSeverityValidator = new CSetValidator(array('values' => array_keys(getSeverityCaption()))); $discoveryObjectValidator = new CSetValidator(array('values' => array_keys(discovery_object2str()))); $triggerValueValidator = new CSetValidator(array('values' => array_keys(trigger_value2str()))); $eventTypeValidator = new CSetValidator(array('values' => array_keys(eventType()))); foreach ($conditions as $condition) { // on create operator is mandatory and needs validation, but on update it must be validated only if it's set if (!$update || $update && isset($condition['operator'])) { $operatorValidator = new CSetValidator(array('values' => get_operators_by_conditiontype($condition['conditiontype']))); if (!$operatorValidator->validate($condition['operator'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition operator.')); } } if (!$update || $update && isset($condition['value'])) { // validate condition values depending on condition type switch ($condition['conditiontype']) { case CONDITION_TYPE_HOST_GROUP: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $hostGroupIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_TEMPLATE: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $templateIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_TRIGGER: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $triggerIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_HOST: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $hostIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_DRULE: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $discoveryRuleIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_DCHECK: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $proxyIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_PROXY: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $proxyidsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_DOBJECT: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$discoveryObjectValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery object.')); } break; case CONDITION_TYPE_TIME_PERIOD: if (!$timePeriodValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, $timePeriodValidator->getError()); } break; case CONDITION_TYPE_DHOST_IP: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } else { if (!validate_ip_range($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action condition ip "%1$s".', $condition['value'])); } } break; case CONDITION_TYPE_DSERVICE_TYPE: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$discoveryCheckTypeValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery check.')); } break; case CONDITION_TYPE_DSERVICE_PORT: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!validate_port_list($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action condition port "%1$s".', $condition['value'])); } break; case CONDITION_TYPE_DSTATUS: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$discoveryObjectStatusValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery status.')); } break; case CONDITION_TYPE_MAINTENANCE: if (!zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Maintenance action condition value must be empty.')); } break; case CONDITION_TYPE_TRIGGER_SEVERITY: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$triggerSeverityValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition trigger severity.')); } break; case CONDITION_TYPE_TRIGGER_VALUE: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$triggerValueValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition trigger value.')); } break; case CONDITION_TYPE_EVENT_TYPE: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$eventTypeValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition event type.')); } break; case CONDITION_TYPE_TRIGGER_NAME: case CONDITION_TYPE_NODE: case CONDITION_TYPE_DUPTIME: case CONDITION_TYPE_DVALUE: case CONDITION_TYPE_APPLICATION: case CONDITION_TYPE_HOST_NAME: case CONDITION_TYPE_HOST_METADATA: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } break; default: self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition type.')); break; } } } if (!API::HostGroup()->isWritable($hostGroupIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition host group. Host group does not exist or you have no access to it.')); } if (!API::Host()->isWritable($hostIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition host. Host does not exist or you have no access to it.')); } if (!API::Template()->isWritable($templateIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition template. Template does not exist or you have no access to it.')); } if (!API::Trigger()->isWritable($triggerIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition trigger. Trigger does not exist or you have no access to it.')); } if (!API::DRule()->isWritable($discoveryRuleIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery rule. Discovery rule does not exist or you have no access to it.')); } if (!API::DCheck()->isWritable($proxyIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery check. Discovery check does not exist or you have no access to it.')); } if (!API::Proxy()->isWritable($proxyidsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition proxy. Proxy does not exist or you have no access to it.')); } return true; }
} $media = get_request('media', -1); $sendto = get_request('sendto', ''); $mediatypeid = get_request('mediatypeid', 0); $active = get_request('active', 0); $period = get_request('period', ZBX_DEFAULT_INTERVAL); $frmMedia = new CFormTable(_('New media')); $frmMedia->addVar('media', $media); $frmMedia->addVar('dstfrm', $_REQUEST['dstfrm']); $cmbType = new CComboBox('mediatypeid', $mediatypeid); $sql = 'SELECT mediatypeid,description ' . ' FROM media_type' . ' WHERE ' . DBin_node('mediatypeid') . ' ORDER BY type'; $types = DBselect($sql); while ($type = DBfetch($types)) { $cmbType->addItem($type['mediatypeid'], get_node_name_by_elid($type['mediatypeid'], null, ': ') . $type['description']); } $frmMedia->addRow(_('Type'), $cmbType); $frmMedia->addRow(_('Send to'), new CTextBox('sendto', $sendto, 20)); $frmMedia->addRow(_('When active'), new CTextBox('period', $period, 48)); $frm_row = array(); foreach (getSeverityCaption() as $i => $caption) { $frm_row[] = array(new CCheckBox('severity[' . $i . ']', str_in_array($i, $severity), null, $i), $caption); $frm_row[] = BR(); } $frmMedia->addRow(_('Use if severity'), $frm_row); $cmbStat = new CComboBox('active', $active); $cmbStat->addItem(0, _('Enabled')); $cmbStat->addItem(1, _('Disabled')); $frmMedia->addRow(_('Status'), $cmbStat); $frmMedia->addItemToBottomRow(array(new CSubmit('add', $media > -1 ? _('Save') : _('Add')), new CButtonCancel(null, 'close_window();'))); $frmMedia->Show(); require_once dirname(__FILE__) . '/include/page_footer.php';
function make_hoststat_summary($filter) { $table = new CTableInfo(_('No host groups found.')); $table->setHeader(array(is_show_all_nodes() ? _('Node') : null, _('Host group'), _('Without problems'), _('With problems'), _('Total'))); // get host groups $groups = API::HostGroup()->get(array('nodeids' => get_current_nodeid(), 'groupids' => $filter['groupids'], 'monitored_hosts' => 1, 'output' => array('groupid', 'name'))); $groups = zbx_toHash($groups, 'groupid'); foreach ($groups as &$group) { $group['nodename'] = get_node_name_by_elid($group['groupid']); } unset($group); CArrayHelper::sort($groups, array(array('field' => 'nodename', 'order' => ZBX_SORT_UP), array('field' => 'name', 'order' => ZBX_SORT_UP))); // get hosts $hosts = API::Host()->get(array('nodeids' => get_current_nodeid(), 'groupids' => zbx_objectValues($groups, 'groupid'), 'hostids' => !empty($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'filter' => array('maintenance_status' => $filter['maintenance']), 'output' => array('hostid', 'name'), 'selectGroups' => array('groupid'))); $hosts = zbx_toHash($hosts, 'hostid'); CArrayHelper::sort($hosts, array('name')); // get triggers $triggers = API::Trigger()->get(array('nodeids' => get_current_nodeid(), 'monitored' => true, 'maintenance' => $filter['maintenance'], 'expandData' => true, 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE), 'output' => array('triggerid', 'priority'), 'selectHosts' => array('hostid'))); if ($filter['extAck']) { $triggers_unack = API::Trigger()->get(array('nodeids' => get_current_nodeid(), 'monitored' => true, 'maintenance' => $filter['maintenance'], 'withLastEventUnacknowledged' => true, 'selectHosts' => API_OUTPUT_REFER, 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE), 'output' => API_OUTPUT_REFER)); $triggers_unack = zbx_toHash($triggers_unack, 'triggerid'); foreach ($triggers_unack as $tunack) { foreach ($tunack['hosts'] as $unack_host) { $hosts_with_unack_triggers[$unack_host['hostid']] = $unack_host['hostid']; } } } $hosts_data = array(); $problematic_host_list = array(); $lastUnack_host_list = array(); $highest_severity = array(); $highest_severity2 = array(); foreach ($triggers as $trigger) { foreach ($trigger['hosts'] as $trigger_host) { if (!isset($hosts[$trigger_host['hostid']])) { continue; } else { $host = $hosts[$trigger_host['hostid']]; } if ($filter['extAck'] && isset($hosts_with_unack_triggers[$host['hostid']])) { if (!isset($lastUnack_host_list[$host['hostid']])) { $lastUnack_host_list[$host['hostid']] = array(); $lastUnack_host_list[$host['hostid']]['host'] = $host['name']; $lastUnack_host_list[$host['hostid']]['hostid'] = $host['hostid']; $lastUnack_host_list[$host['hostid']]['severities'] = array(); $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_DISASTER] = 0; $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_HIGH] = 0; $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_AVERAGE] = 0; $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_WARNING] = 0; $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_INFORMATION] = 0; $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_NOT_CLASSIFIED] = 0; } if (isset($triggers_unack[$trigger['triggerid']])) { $lastUnack_host_list[$host['hostid']]['severities'][$trigger['priority']]++; } foreach ($host['groups'] as $gnum => $group) { if (!isset($highest_severity2[$group['groupid']])) { $highest_severity2[$group['groupid']] = 0; } if ($trigger['priority'] > $highest_severity2[$group['groupid']]) { $highest_severity2[$group['groupid']] = $trigger['priority']; } if (!isset($hosts_data[$group['groupid']])) { $hosts_data[$group['groupid']] = array('problematic' => 0, 'ok' => 0, 'lastUnack' => 0, 'hostids_all' => array(), 'hostids_unack' => array()); } if (!isset($hosts_data[$group['groupid']]['hostids_unack'][$host['hostid']])) { $hosts_data[$group['groupid']]['hostids_unack'][$host['hostid']] = $host['hostid']; $hosts_data[$group['groupid']]['lastUnack']++; } } } if (!isset($problematic_host_list[$host['hostid']])) { $problematic_host_list[$host['hostid']] = array(); $problematic_host_list[$host['hostid']]['host'] = $host['name']; $problematic_host_list[$host['hostid']]['hostid'] = $host['hostid']; $problematic_host_list[$host['hostid']]['severities'] = array(); $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_DISASTER] = 0; $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_HIGH] = 0; $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_AVERAGE] = 0; $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_WARNING] = 0; $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_INFORMATION] = 0; $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_NOT_CLASSIFIED] = 0; } $problematic_host_list[$host['hostid']]['severities'][$trigger['priority']]++; foreach ($host['groups'] as $gnum => $group) { if (!isset($highest_severity[$group['groupid']])) { $highest_severity[$group['groupid']] = 0; } if ($trigger['priority'] > $highest_severity[$group['groupid']]) { $highest_severity[$group['groupid']] = $trigger['priority']; } if (!isset($hosts_data[$group['groupid']])) { $hosts_data[$group['groupid']] = array('problematic' => 0, 'ok' => 0, 'lastUnack' => 0, 'hostids_all' => array(), 'hostids_unack' => array()); } if (!isset($hosts_data[$group['groupid']]['hostids_all'][$host['hostid']])) { $hosts_data[$group['groupid']]['hostids_all'][$host['hostid']] = $host['hostid']; $hosts_data[$group['groupid']]['problematic']++; } } } } foreach ($hosts as $host) { foreach ($host['groups'] as $group) { if (!isset($groups[$group['groupid']])) { continue; } if (!isset($groups[$group['groupid']]['hosts'])) { $groups[$group['groupid']]['hosts'] = array(); } $groups[$group['groupid']]['hosts'][$host['hostid']] = array('hostid' => $host['hostid']); if (!isset($highest_severity[$group['groupid']])) { $highest_severity[$group['groupid']] = 0; } if (!isset($hosts_data[$group['groupid']])) { $hosts_data[$group['groupid']] = array('problematic' => 0, 'ok' => 0, 'lastUnack' => 0); } if (!isset($problematic_host_list[$host['hostid']])) { $hosts_data[$group['groupid']]['ok']++; } } } foreach ($groups as $group) { if (!isset($hosts_data[$group['groupid']])) { continue; } $group_row = new CRow(); if (is_show_all_nodes()) { $group_row->addItem($group['nodename']); } $name = new CLink($group['name'], 'tr_status.php?groupid=' . $group['groupid'] . '&hostid=0&show_triggers=' . TRIGGERS_OPTION_ONLYTRUE); $group_row->addItem($name); $group_row->addItem(new CCol($hosts_data[$group['groupid']]['ok'], 'normal')); if ($filter['extAck']) { if ($hosts_data[$group['groupid']]['lastUnack']) { $table_inf = new CTableInfo(); $table_inf->setAttribute('style', 'width: 400px;'); $table_inf->setHeader(array(_('Host'), is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_DISASTER]) ? getSeverityCaption(TRIGGER_SEVERITY_DISASTER) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_HIGH]) ? getSeverityCaption(TRIGGER_SEVERITY_HIGH) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_AVERAGE]) ? getSeverityCaption(TRIGGER_SEVERITY_AVERAGE) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_WARNING]) ? getSeverityCaption(TRIGGER_SEVERITY_WARNING) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_INFORMATION]) ? getSeverityCaption(TRIGGER_SEVERITY_INFORMATION) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_NOT_CLASSIFIED]) ? getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED) : null)); $popup_rows = 0; foreach ($group['hosts'] as $host) { $hostid = $host['hostid']; if (!isset($lastUnack_host_list[$hostid])) { continue; } if ($popup_rows >= ZBX_WIDGET_ROWS) { break; } $popup_rows++; $host_data = $lastUnack_host_list[$hostid]; $r = new CRow(); $r->addItem(new CLink($host_data['host'], 'tr_status.php?groupid=' . $group['groupid'] . '&hostid=' . $hostid . '&show_triggers=' . TRIGGERS_OPTION_ONLYTRUE)); foreach ($lastUnack_host_list[$host['hostid']]['severities'] as $severity => $trigger_count) { if (!is_null($filter['severity']) && !isset($filter['severity'][$severity])) { continue; } $r->addItem(new CCol($trigger_count, getSeverityStyle($severity, $trigger_count))); } $table_inf->addRow($r); } $lastUnack_count = new CSpan($hosts_data[$group['groupid']]['lastUnack'], 'pointer red bold'); $lastUnack_count->setHint($table_inf); } else { $lastUnack_count = 0; } } // if hostgroup contains problematic hosts, hint should be built if ($hosts_data[$group['groupid']]['problematic']) { $table_inf = new CTableInfo(); $table_inf->setAttribute('style', 'width: 400px;'); $table_inf->setHeader(array(_('Host'), is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_DISASTER]) ? getSeverityCaption(TRIGGER_SEVERITY_DISASTER) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_HIGH]) ? getSeverityCaption(TRIGGER_SEVERITY_HIGH) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_AVERAGE]) ? getSeverityCaption(TRIGGER_SEVERITY_AVERAGE) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_WARNING]) ? getSeverityCaption(TRIGGER_SEVERITY_WARNING) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_INFORMATION]) ? getSeverityCaption(TRIGGER_SEVERITY_INFORMATION) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_NOT_CLASSIFIED]) ? getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED) : null)); $popup_rows = 0; foreach ($group['hosts'] as $host) { $hostid = $host['hostid']; if (!isset($problematic_host_list[$hostid])) { continue; } if ($popup_rows >= ZBX_WIDGET_ROWS) { break; } $popup_rows++; $host_data = $problematic_host_list[$hostid]; $r = new CRow(); $r->addItem(new CLink($host_data['host'], 'tr_status.php?groupid=' . $group['groupid'] . '&hostid=' . $hostid . '&show_triggers=' . TRIGGERS_OPTION_ONLYTRUE)); foreach ($problematic_host_list[$host['hostid']]['severities'] as $severity => $trigger_count) { if (!is_null($filter['severity']) && !isset($filter['severity'][$severity])) { continue; } $r->addItem(new CCol($trigger_count, getSeverityStyle($severity, $trigger_count))); } $table_inf->addRow($r); } $problematic_count = new CSpan($hosts_data[$group['groupid']]['problematic'], 'pointer'); $problematic_count->setHint($table_inf); } else { $problematic_count = 0; } switch ($filter['extAck']) { case EXTACK_OPTION_ALL: $group_row->addItem(new CCol($problematic_count, getSeverityStyle($highest_severity[$group['groupid']], $hosts_data[$group['groupid']]['problematic']))); $group_row->addItem($hosts_data[$group['groupid']]['problematic'] + $hosts_data[$group['groupid']]['ok']); break; case EXTACK_OPTION_UNACK: $group_row->addItem(new CCol($lastUnack_count, getSeverityStyle(isset($highest_severity2[$group['groupid']]) ? $highest_severity2[$group['groupid']] : 0, $hosts_data[$group['groupid']]['lastUnack']))); $group_row->addItem($hosts_data[$group['groupid']]['lastUnack'] + $hosts_data[$group['groupid']]['ok']); break; case EXTACK_OPTION_BOTH: $unackspan = $lastUnack_count ? new CSpan(array($lastUnack_count, SPACE . _('of') . SPACE)) : null; $group_row->addItem(new CCol(array($unackspan, $problematic_count), getSeverityStyle($highest_severity[$group['groupid']], $hosts_data[$group['groupid']]['problematic']))); $group_row->addItem($hosts_data[$group['groupid']]['problematic'] + $hosts_data[$group['groupid']]['ok']); break; } $table->addRow($group_row); } $script = new CJSScript(get_js("jQuery('#hat_hoststat_footer').html('" . _s('Updated: %s', zbx_date2str(_('H:i:s'))) . "')")); return new CDiv(array($table, $script)); }
$searchstring = getRequest('searchstring', ''); } if (function_exists('get_current_nodeid')) { $nodeids = get_current_nodeid(); } if (function_exists('GetCurrentNodeId')) { $nodeids = getCurrentNodeId(); } if ($output != 'ajax') { require_once dirname(__FILE__) . '/include/page_header.php'; } /* * Filter */ $config = select_config(); $pageFilter = new CPageFilter(array('groups' => array('monitored_hosts' => true), 'hosts' => array('monitored_hosts' => true, 'withInventory' => true), 'hostid' => $hostid, 'groupid' => $groupid, 'severitiesMin' => array(TRIGGER_SEVERITY_NOT_CLASSIFIED => getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED), TRIGGER_SEVERITY_INFORMATION => getSeverityCaption(TRIGGER_SEVERITY_INFORMATION), TRIGGER_SEVERITY_WARNING => getSeverityCaption(TRIGGER_SEVERITY_WARNING), TRIGGER_SEVERITY_AVERAGE => getSeverityCaption(TRIGGER_SEVERITY_AVERAGE), TRIGGER_SEVERITY_HIGH => getSeverityCaption(TRIGGER_SEVERITY_HIGH), TRIGGER_SEVERITY_DISASTER => getSeverityCaption(TRIGGER_SEVERITY_DISASTER)), 'severityMin' => $showSeverity)); $_REQUEST['groupid'] = $pageFilter->groupid; $_REQUEST['hostid'] = $pageFilter->hostid; function rightsErrorAjax() { $responseData = '{"jsonrpc": "2.0","error": {"message": "Access error. Check rights."}}'; echo $responseData; exit; } function rightsForLink($idl) { $glinks = DBfetchArray(DBselect('SELECT host1, host2 FROM hosts_links WHERE hosts_links.id = ' . $idl)); if (API::Host()->isWritable(array(1 * $glinks[0]['host1'])) and API::Host()->isWritable(array(1 * $glinks[0]['host2']))) { return true; }