if (isset($row['serviceupid'])) { $services[$row['serviceupid']]['childs'][] = array('id' => $row['serviceid'], 'soft' => 0, 'linkid' => 0); } if (isset($row['servicedownid'])) { $services[$row['serviceid']]['childs'][] = array('id' => $row['servicedownid'], 'soft' => 1, 'linkid' => $row['linkid']); } } $treeServ = array(); createServiceTree($services, $treeServ); //return into $treeServ parametr //permission issue $treeServ = del_empty_nodes($treeServ); //---- if (isset($_REQUEST['msg']) && !empty($_REQUEST['msg'])) { show_messages(true, $_REQUEST['msg']); } //show_table_header(S_IT_SERVICES_BIG); $tree = new CTree('service_conf_tree', $treeServ, array('caption' => bold(S_SERVICE), 'algorithm' => bold(S_STATUS_CALCULATION), 'description' => bold(S_TRIGGER))); if ($tree) { $serv_wdgt = new CWidget(); $serv_wdgt->addHeader(S_IT_SERVICES_BIG, SPACE); $serv_wdgt->addItem($tree->getHTML()); $serv_wdgt->show(); } else { error(S_CANT_FORMAT_TREE); } $tr_ov_menu[] = array('test1', null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))); $tr_ov_menu[] = array('test2', null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))); $jsmenu = new CPUMenu($tr_ov_menu, 170); $jsmenu->InsertJavaScript(); include_once "include/page_footer.php";
function get_item_data_overview_cells(&$table_row, &$ithosts, $hostname) { $css_class = ''; unset($it_ov_menu); $value = '-'; $ack = null; if (isset($ithosts[$hostname])) { if ($ithosts[$hostname]['tr_value'] == TRIGGER_VALUE_TRUE) { $css_class = getSeverityStyle($ithosts[$hostname]['severity']); $ack = get_last_event_by_triggerid($ithosts[$hostname]['triggerid']); $ack = $ack['acknowledged'] == 1 ? array(SPACE, new CImg('images/general/tick.png', 'ack')) : null; } $value = formatItemValue($ithosts[$hostname]); $it_ov_menu = array(array(_('Values'), null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))), array(_('500 latest values'), 'history.php?action=showlatest&itemid=' . $ithosts[$hostname]['itemid'], array('tw' => '_blank'))); switch ($ithosts[$hostname]['value_type']) { case ITEM_VALUE_TYPE_UINT64: case ITEM_VALUE_TYPE_FLOAT: $it_ov_menu = array_merge(array(array(_('Graphs'), null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))), array(_('Last hour graph'), 'history.php?period=3600&action=showgraph&itemid=' . $ithosts[$hostname]['itemid'], array('tw' => '_blank')), array(_('Last week graph'), 'history.php?period=604800&action=showgraph&itemid=' . $ithosts[$hostname]['itemid'], array('tw' => '_blank')), array(_('Last month graph'), 'history.php?period=2678400&action=showgraph&itemid=' . $ithosts[$hostname]['itemid'], array('tw' => '_blank'))), $it_ov_menu); break; default: break; } } if ($value != '-') { $value = new CSpan($value, 'link'); } $value_col = new CCol(array($value, $ack), $css_class); if (isset($it_ov_menu)) { $it_ov_menu = new CPUMenu($it_ov_menu, 170); $value_col->onClick($it_ov_menu->getOnActionJS()); unset($it_ov_menu); } array_push($table_row, $value_col); return $table_row; }
function get_trigger_overview_cells(&$table_row, &$trhosts, &$hostname) { $css_class = NULL; unset($tr_ov_menu); $ack = null; if (isset($trhosts[$hostname])) { unset($ack_menu); switch ($trhosts[$hostname]['value']) { case TRIGGER_VALUE_TRUE: $css_class = get_severity_style($trhosts[$hostname]['priority']); if ($ack = get_last_event_by_triggerid($trhosts[$hostname]['triggerid'])) { $ack_menu = array(S_ACKNOWLEDGE, 'acknow.php?eventid=' . $ack['eventid'], array('tw' => '_blank')); } if (1 == $ack['acknowledged']) { $ack = new CImg('images/general/tick.png', 'ack'); } else { $ack = null; } break; case TRIGGER_VALUE_FALSE: $css_class = 'normal'; break; default: $css_class = 'unknown_trigger'; } $style = 'cursor: pointer; '; if (time(NULL) - $trhosts[$hostname]['lastchange'] < 300) { $style .= 'background-image: url(images/gradients/blink1.gif); ' . 'background-position: top left; ' . 'background-repeat: repeat;'; } else { if (time(NULL) - $trhosts[$hostname]['lastchange'] < 900) { $style .= 'background-image: url(images/gradients/blink2.gif); ' . 'background-position: top left; ' . 'background-repeat: repeat;'; } } unset($item_menu); $tr_ov_menu = array(array(S_TRIGGER, null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))), array(S_EVENTS, 'events.php?triggerid=' . $trhosts[$hostname]['triggerid'], array('tw' => '_blank'))); if (isset($ack_menu)) { $tr_ov_menu[] = $ack_menu; } $db_items = DBselect('select distinct i.itemid, i.description, i.key_, i.value_type ' . ' from items i, functions f ' . ' where f.itemid=i.itemid and f.triggerid=' . $trhosts[$hostname]['triggerid']); while ($item_data = DBfetch($db_items)) { $description = item_description($item_data); switch ($item_data['value_type']) { case ITEM_VALUE_TYPE_UINT64: case ITEM_VALUE_TYPE_FLOAT: $action = 'showgraph'; $status_bar = S_SHOW_GRAPH_OF_ITEM . ' \'' . $description . '\''; break; case ITEM_VALUE_TYPE_LOG: case ITEM_VALUE_TYPE_STR: case ITEM_VALUE_TYPE_TEXT: default: $action = 'showlatest'; $status_bar = S_SHOW_VALUES_OF_ITEM . ' \'' . $description . '\''; break; } if (strlen($description) > 25) { $description = substr($description, 0, 22) . '...'; } $item_menu[$action][] = array($description, 'history.php?action=' . $action . '&itemid=' . $item_data['itemid'] . '&period=3600', array('tw' => '', 'sb' => $status_bar)); } if (isset($item_menu['showgraph'])) { $tr_ov_menu[] = array(S_GRAPHS, null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))); $tr_ov_menu = array_merge($tr_ov_menu, $item_menu['showgraph']); } if (isset($item_menu['showlatest'])) { $tr_ov_menu[] = array(S_VALUES, null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))); $tr_ov_menu = array_merge($tr_ov_menu, $item_menu['showlatest']); } unset($item_menu); } // dependency // TRIGGERS ON WHICH DEPENDS THIS $desc = array(); if (isset($trhosts[$hostname])) { $triggerid = $trhosts[$hostname]['triggerid']; $dependency = false; $dep_table = new CTableInfo(); $dep_table->AddOption('style', 'width: 200px;'); $dep_table->addRow(bold(S_DEPENDS_ON . ':')); $sql_dep = 'SELECT * FROM trigger_depends WHERE triggerid_down=' . $triggerid; $dep_res = DBselect($sql_dep); while ($dep_row = DBfetch($dep_res)) { $dep_table->addRow(SPACE . '-' . SPACE . expand_trigger_description($dep_row['triggerid_up'])); $dependency = true; } if ($dependency) { $img = new Cimg('images/general/down_icon.png', 'DEP_DOWN'); $img->AddOption('style', 'vertical-align: middle; border: 0px;'); $img->SetHint($dep_table); array_push($desc, $img); } unset($img, $dep_table, $dependency); // TRIGGERS THAT DEPEND ON THIS $dependency = false; $dep_table = new CTableInfo(); $dep_table->AddOption('style', 'width: 200px;'); $dep_table->addRow(bold(S_DEPENDENT . ':')); $sql_dep = 'SELECT * FROM trigger_depends WHERE triggerid_up=' . $triggerid; $dep_res = DBselect($sql_dep); while ($dep_row = DBfetch($dep_res)) { $dep_table->addRow(SPACE . '-' . SPACE . expand_trigger_description($dep_row['triggerid_down'])); $dependency = true; } if ($dependency) { $img = new Cimg('images/general/up_icon.png', 'DEP_UP'); $img->AddOption('style', 'vertical-align: middle; border: 0px;'); $img->SetHint($dep_table); array_push($desc, $img); } unset($img, $dep_table, $dependency); } //------------------------ $status_col = new CCol(array($desc, $ack), $css_class); if (isset($style)) { $status_col->AddOption('style', $style); } if (isset($tr_ov_menu)) { $tr_ov_menu = new CPUMenu($tr_ov_menu, 170); $status_col->OnClick($tr_ov_menu->GetOnActionJS()); $status_col->AddAction('onmouseover', 'this.old_border=this.style.border; this.style.border=\'1px dotted #0C0CF0\''); $status_col->AddAction('onmouseout', 'this.style.border=this.old_border;'); } array_push($table_row, $status_col); return $table_row; }
/** * Creates and returns a trigger status cell for the trigger overview table. * * @see get_triggers_overview() * * @param array $triggerHosts an array with the data about the trigger for each host * @param string $hostName the name of the cells corresponding host * @param string $screenId * * @return CCol */ function get_trigger_overview_cells($triggerHosts, $hostName, $screenId = null) { $ack = null; $css_class = null; $desc = array(); $config = select_config(); // for how long triggers should blink on status change (set by user in administration->general) if (isset($triggerHosts[$hostName])) { // problem trigger if ($triggerHosts[$hostName]['value'] == TRIGGER_VALUE_TRUE) { $css_class = getSeverityStyle($triggerHosts[$hostName]['priority']); $ack = null; if ($config['event_ack_enable'] == 1) { $event = get_last_event_by_triggerid($triggerHosts[$hostName]['triggerid']); if ($event) { if ($screenId) { global $page; $ack_menu = array(_('Acknowledge'), 'acknow.php?eventid=' . $event['eventid'] . '&screenid=' . $screenId . '&backurl=' . $page['file']); } else { $ack_menu = array(_('Acknowledge'), 'acknow.php?eventid=' . $event['eventid'] . '&backurl=overview.php', array('tw' => '_blank')); } if ($event['acknowledged'] == 1) { $ack = new CImg('images/general/tick.png', 'ack'); } } } } else { $css_class = 'normal'; } $style = 'cursor: pointer; '; // set blinking gif as background if trigger age is less then $config['blink_period'] if ($config['blink_period'] > 0 && time() - $triggerHosts[$hostName]['lastchange'] < $config['blink_period']) { $style .= 'background-image: url(images/gradients/blink.gif); background-position: top left; background-repeat: repeat;'; } unset($item_menu); $tr_ov_menu = array(array(_('Trigger'), null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))), array(_('Events'), 'events.php?triggerid=' . $triggerHosts[$hostName]['triggerid'], array('tw' => '_blank'))); if (isset($ack_menu)) { $tr_ov_menu[] = $ack_menu; } $dbItems = DBselect('SELECT DISTINCT i.itemid,i.name,i.key_,i.value_type' . ' FROM items i,functions f' . ' WHERE f.itemid=i.itemid' . ' AND f.triggerid=' . $triggerHosts[$hostName]['triggerid']); while ($item = DBfetch($dbItems)) { $description = itemName($item); switch ($item['value_type']) { case ITEM_VALUE_TYPE_UINT64: case ITEM_VALUE_TYPE_FLOAT: $action = 'showgraph'; $status_bar = _('Show graph of item') . ' \'' . $description . '\''; break; case ITEM_VALUE_TYPE_LOG: case ITEM_VALUE_TYPE_STR: case ITEM_VALUE_TYPE_TEXT: default: $action = 'showlatest'; $status_bar = _('Show values of item') . ' \'' . $description . '\''; break; } if (zbx_strlen($description) > 25) { $description = zbx_substr($description, 0, 22) . '...'; } $item_menu[$action][] = array($description, 'history.php?action=' . $action . '&itemid=' . $item['itemid'] . '&period=3600', array('tw' => '', 'sb' => $status_bar)); } if (isset($item_menu['showgraph'])) { $tr_ov_menu[] = array(_('Graphs'), null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))); $tr_ov_menu = array_merge($tr_ov_menu, $item_menu['showgraph']); } if (isset($item_menu['showlatest'])) { $tr_ov_menu[] = array(_('Values'), null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))); $tr_ov_menu = array_merge($tr_ov_menu, $item_menu['showlatest']); } unset($item_menu); // dependency: triggers on which depends this $triggerid = !empty($triggerHosts[$hostName]['triggerid']) ? $triggerHosts[$hostName]['triggerid'] : 0; $dep_table = new CTableInfo(); $dep_table->setAttribute('style', 'width: 200px;'); $dep_table->addRow(bold(_('Depends on') . ':')); $dependency = false; $dep_res = DBselect('SELECT td.* FROM trigger_depends td WHERE td.triggerid_down=' . $triggerid); while ($dep_row = DBfetch($dep_res)) { $dep_table->addRow(SPACE . '-' . SPACE . CTriggerHelper::expandDescriptionById($dep_row['triggerid_up'])); $dependency = true; } if ($dependency) { $img = new Cimg('images/general/arrow_down2.png', 'DEP_DOWN'); $img->setAttribute('style', 'vertical-align: middle; border: 0px;'); $img->setHint($dep_table, '', '', false); array_push($desc, $img); } unset($img, $dep_table, $dependency); // triggers that depend on this $dep_table = new CTableInfo(); $dep_table->setAttribute('style', 'width: 200px;'); $dep_table->addRow(bold(_('Dependent') . ':')); $dependency = false; $dep_res = DBselect('SELECT td.* FROM trigger_depends td WHERE td.triggerid_up=' . $triggerid); while ($dep_row = DBfetch($dep_res)) { $dep_table->addRow(SPACE . '-' . SPACE . CTriggerHelper::expandDescriptionById($dep_row['triggerid_down'])); $dependency = true; } if ($dependency) { $img = new Cimg('images/general/arrow_up2.png', 'DEP_UP'); $img->setAttribute('style', 'vertical-align: middle; border: 0px;'); $img->setHint($dep_table, '', '', false); array_push($desc, $img); } unset($img, $dep_table, $dependency); } if (is_array($desc) && count($desc) > 0 || $ack) { $tableColumn = new CCol(array($desc, $ack), $css_class . ' hosts'); } else { $tableColumn = new CCol(SPACE, $css_class . ' hosts'); } if (isset($style)) { $tableColumn->setAttribute('style', $style); } if (isset($tr_ov_menu)) { $tr_ov_menu = new CPUMenu($tr_ov_menu, 170); $tableColumn->onClick($tr_ov_menu->getOnActionJS()); $tableColumn->addAction('onmouseover', 'jQuery(this).css({border: "1px dotted #0C0CF0", padding: "0 2px"})'); $tableColumn->addAction('onmouseout', 'jQuery(this).css({border: "", padding: "1px 3px"})'); } return $tableColumn; }
function getActionMapBySysmap($sysmap) { $action_map = new CAreaMap('links' . $sysmap['sysmapid']); $hostids = array(); foreach ($sysmap['selements'] as $snum => $selement) { if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) { $hostids[$selement['elementid']] = $selement['elementid']; } } $scripts_by_hosts = CScript::getScriptsByHosts($hostids); $options = array('nodeids' => get_current_nodeid(true), 'hostids' => $hostids, 'output' => API_OUTPUT_EXTEND, 'nopermissions' => 1); $hosts = CHost::get($options); $hosts = zbx_toHash($hosts, 'hostid'); // Draws elements $map_info = getSelementsInfo($sysmap); //SDII($map_info); foreach ($sysmap['selements'] as $snum => $db_element) { $links_menus = ''; $menus = ''; if ($db_element['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) { $host = $hosts[$db_element['elementid']]; if ($host['status'] == HOST_STATUS_MONITORED) { $host_nodeid = id2nodeid($db_element['elementid']); foreach ($scripts_by_hosts[$db_element['elementid']] as $id => $script) { $script_nodeid = id2nodeid($script['scriptid']); if (bccomp($host_nodeid, $script_nodeid) == 0) { $menus .= "['" . $script['name'] . "',\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $db_element["elementid"] . "&scriptid=" . $script['scriptid'] . "','" . S_TOOLS . "',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } } $menus = "['" . S_TOOLS . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus; $links_menus .= "['" . S_STATUS_OF_TRIGGERS . "',\"javascript: redirect('tr_status.php?hostid=" . $db_element['elementid'] . "');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } } else { if ($db_element['elementtype'] == SYSMAP_ELEMENT_TYPE_MAP) { $links_menus .= "['" . S_SUBMAP . "',\"javascript: redirect('maps.php?sysmapid=" . $db_element['elementid'] . "');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } else { if ($db_element['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER) { $links_menus .= "['" . S_LATEST_EVENTS . "',\"javascript: redirect('events.php?source=0&triggerid=" . $db_element['elementid'] . "&nav_time=" . (time() - 7 * 86400) . "');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } else { if ($db_element['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST_GROUP) { $links_menus .= "['" . S_STATUS_OF_TRIGGERS . "',\"javascript: redirect('tr_status.php?hostid=0&groupid=" . $db_element['elementid'] . "');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } } } } if (!empty($db_element['url']) || !empty($links_menus)) { $menus .= "['" . S_LINKS . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],"; $menus .= $links_menus; if (!empty($db_element['url'])) { $menus .= "['" . S_URL . "',\"javascript: location.replace('" . $db_element['url'] . "');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } } $menus = trim($menus, ','); $menus = 'show_popup_menu(event,[' . $menus . '],180); cancelEvent(event);'; $back = get_png_by_selement($db_element, $map_info[$db_element['selementid']]); if (!$back) { continue; } $r_area = new CArea(array($db_element['x'], $db_element['y'], $db_element['x'] + imagesx($back), $db_element['y'] + imagesy($back)), '', '', 'rect'); if (!empty($menus)) { $r_area->addAction('onclick', 'javascript: ' . $menus); } $action_map->addItem($r_area); } $jsmenu = new CPUMenu(null, 170); $jsmenu->InsertJavaScript(); return $action_map; }
function get_item_data_overview_cells(&$table_row, &$ithosts, $hostname) { $css_class = NULL; unset($it_ov_menu); $value = '-'; $ack = null; if (isset($ithosts[$hostname])) { if ($ithosts[$hostname]['tr_value'] == TRIGGER_VALUE_TRUE) { $css_class = get_severity_style($ithosts[$hostname]['severity']); $ack = get_last_event_by_triggerid($ithosts[$hostname]['triggerid']); if (1 == $ack['acknowledged']) { $ack = array(SPACE, new CImg('images/general/tick.png', 'ack')); } else { $ack = null; } } $value = format_lastvalue($ithosts[$hostname]); $it_ov_menu = array(array(S_VALUES, null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))), array(S_500_LATEST_VALUES, 'history.php?action=showlatest&itemid=' . $ithosts[$hostname]['itemid'], array('tw' => '_blank'))); switch ($ithosts[$hostname]['value_type']) { case ITEM_VALUE_TYPE_UINT64: case ITEM_VALUE_TYPE_FLOAT: $it_ov_menu = array_merge(array(array(S_GRAPHS, null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))), array(S_LAST_HOUR_GRAPH, 'history.php?period=3600&action=showgraph&itemid=' . $ithosts[$hostname]['itemid'], array('tw' => '_blank')), array(S_LAST_WEEK_GRAPH, 'history.php?period=604800&action=showgraph&itemid=' . $ithosts[$hostname]['itemid'], array('tw' => '_blank')), array(S_LAST_MONTH_GRAPH, 'history.php?period=2678400&action=showgraph&itemid=' . $ithosts[$hostname]['itemid'], array('tw' => '_blank'))), $it_ov_menu); break; default: break; } } // if($value == '-') $css_class = 'center'; $value_col = new CCol(array($value, $ack), $css_class); if (isset($it_ov_menu)) { $it_ov_menu = new CPUMenu($it_ov_menu, 170); $value_col->OnClick($it_ov_menu->GetOnActionJS()); $value_col->AddOption('style', 'cursor: pointer;'); $value_col->AddAction('onmouseover', 'this.old_border=this.style.border; this.style.border=\'1px dotted #0C0CF0\''); $value_col->AddAction('onmouseout', 'this.style.border=this.old_border;'); unset($it_ov_menu); } array_push($table_row, $value_col); return $table_row; }
function insert_trigger_form() { $frmTrig = new CFormTable(S_TRIGGER, 'triggers.php'); $frmTrig->setHelp('config_triggers.php'); // if(isset($_REQUEST['hostid'])){ // $frmTrig->addVar('hostid',$_REQUEST['hostid']); // } $dep_el = array(); $dependencies = get_request('dependencies', array()); $limited = null; if (isset($_REQUEST['triggerid'])) { $frmTrig->addVar('triggerid', $_REQUEST['triggerid']); $trigger = get_trigger_by_triggerid($_REQUEST['triggerid']); $caption = array(); $trigid = $_REQUEST['triggerid']; do { $sql = 'SELECT t.triggerid, t.templateid, h.host' . ' FROM triggers t, functions f, items i, hosts h' . ' WHERE t.triggerid=' . $trigid . ' AND h.hostid=i.hostid' . ' AND i.itemid=f.itemid' . ' AND f.triggerid=t.triggerid'; $trig = DBfetch(DBselect($sql)); if ($_REQUEST['triggerid'] != $trigid) { $caption[] = ' : '; $caption[] = new CLink($trig['host'], 'triggers.php?form=update&triggerid=' . $trig['triggerid'], 'highlight underline'); } $trigid = $trig['templateid']; } while ($trigid != 0); $caption[] = S_TRIGGER . ' "'; $caption = array_reverse($caption); $caption[] = htmlspecialchars($trigger['description']); $caption[] = '"'; $frmTrig->setTitle($caption); $limited = $trigger['templateid'] ? 'yes' : null; } $expression = get_request('expression', ''); $description = get_request('description', ''); $type = get_request('type', 0); $priority = get_request('priority', 0); $status = get_request('status', 0); $comments = get_request('comments', ''); $url = get_request('url', ''); $expr_temp = get_request('expr_temp', ''); $input_method = get_request('input_method', IM_ESTABLISHED); if (isset($_REQUEST['triggerid']) && !isset($_REQUEST['form_refresh']) || isset($limited)) { $description = $trigger['description']; $expression = explode_exp($trigger['expression'], 0); if (!isset($limited) || !isset($_REQUEST['form_refresh'])) { $type = $trigger['type']; $priority = $trigger['priority']; $status = $trigger['status']; $comments = $trigger['comments']; $url = $trigger['url']; $trigs = DBselect('SELECT t.triggerid,t.description,t.expression ' . ' FROM triggers t,trigger_depends d ' . ' WHERE t.triggerid=d.triggerid_up ' . ' AND d.triggerid_down=' . $_REQUEST['triggerid']); while ($trig = DBfetch($trigs)) { if (uint_in_array($trig['triggerid'], $dependencies)) { continue; } array_push($dependencies, $trig['triggerid']); } } } $frmTrig->addRow(S_NAME, new CTextBox('description', $description, 90, $limited)); if ($input_method == IM_TREE) { $alz = analyze_expression($expression); if ($alz !== false) { list($outline, $eHTMLTree) = $alz; if (isset($_REQUEST['expr_action']) && $eHTMLTree != null) { $new_expr = remake_expression($expression, $_REQUEST['expr_target_single'], $_REQUEST['expr_action'], $expr_temp); if ($new_expr !== false) { $expression = $new_expr; $alz = analyze_expression($expression); if ($alz !== false) { list($outline, $eHTMLTree) = $alz; } else { show_messages(false, '', S_EXPRESSION_SYNTAX_ERROR); } $expr_temp = ''; } else { show_messages(false, '', S_EXPRESSION_SYNTAX_ERROR); } } $frmTrig->addVar('expression', $expression); $exprfname = 'expr_temp'; $exprtxt = new CTextBox($exprfname, $expr_temp, 65, 'yes'); $macrobtn = new CButton('insert_macro', S_INSERT_MACRO, 'return call_ins_macro_menu(event);'); //disabling button, if this trigger is templated if ($limited == 'yes') { $macrobtn->setAttribute('disabled', 'disabled'); } $exprparam = "this.form.elements['{$exprfname}'].value"; } else { show_messages(false, '', S_EXPRESSION_SYNTAX_ERROR); $input_method = IM_ESTABLISHED; } } if ($input_method != IM_TREE) { $exprfname = 'expression'; $exprtxt = new CTextBox($exprfname, $expression, 75, $limited); $exprparam = "getSelectedText(this.form.elements['{$exprfname}'])"; } $add_expr_button = new CButton('insert', $input_method == IM_TREE ? S_EDIT : S_ADD, "return PopUp('popup_trexpr.php?dstfrm=" . $frmTrig->getName() . "&dstfld1={$exprfname}&srctbl=expression" . "&srcfld1=expression&expression=' + escape({$exprparam}),1000,700);"); //disabling button, if this trigger is templated if ($limited == 'yes') { $add_expr_button->setAttribute('disabled', 'disabled'); } $row = array($exprtxt, $add_expr_button); if (isset($macrobtn)) { array_push($row, $macrobtn); } if ($input_method == IM_TREE) { array_push($row, BR()); if (empty($outline)) { $tmpbtn = new CButton('add_expression', S_ADD, ""); if ($limited == 'yes') { $tmpbtn->setAttribute('disabled', 'disabled'); } array_push($row, $tmpbtn); } else { $tmpbtn = new CButton('and_expression', S_AND_BIG, ""); if ($limited == 'yes') { $tmpbtn->setAttribute('disabled', 'disabled'); } array_push($row, $tmpbtn); $tmpbtn = new CButton('or_expression', S_OR_BIG, ""); if ($limited == 'yes') { $tmpbtn->setAttribute('disabled', 'disabled'); } array_push($row, $tmpbtn); $tmpbtn = new CButton('replace_expression', S_REPLACE, ""); if ($limited == 'yes') { $tmpbtn->setAttribute('disabled', 'disabled'); } array_push($row, $tmpbtn); } } $frmTrig->addVar('input_method', $input_method); $frmTrig->addVar('toggle_input_method', ''); $exprtitle = array(S_EXPRESSION); if ($input_method != IM_FORCED) { $btn_im = new CSpan(S_TOGGLE_INPUT_METHOD, 'link'); $btn_im->setAttribute('onclick', 'javascript: ' . "document.getElementById('toggle_input_method').value=1;" . "document.getElementById('input_method').value=" . ($input_method == IM_TREE ? IM_ESTABLISHED : IM_TREE) . ';' . "document.forms['" . $frmTrig->getName() . "'].submit();"); $exprtitle[] = array(SPACE, '(', $btn_im, ')'); } $frmTrig->addRow($exprtitle, $row); if ($input_method == IM_TREE) { $exp_table = new CTable(); $exp_table->setClass('tableinfo'); $exp_table->setAttribute('id', 'exp_list'); $exp_table->setOddRowClass('even_row'); $exp_table->setEvenRowClass('even_row'); $exp_table->setHeader(array($limited == 'yes' ? null : S_TARGET, S_EXPRESSION, S_EXPRESSION_PART_ERROR, $limited == 'yes' ? null : S_DELETE)); $allowedTesting = true; if ($eHTMLTree != null) { foreach ($eHTMLTree as $i => $e) { if ($limited != 'yes') { $del_url = new CSpan(S_DELETE, 'link'); $del_url->setAttribute('onclick', 'javascript: if(confirm("' . S_DELETE_EXPRESSION_Q . '")) {' . ' delete_expression(\'' . $e['id'] . '\');' . ' document.forms["config_triggers.php"].submit(); ' . '}'); $tgt_chk = new CCheckbox('expr_target_single', $i == 0 ? 'yes' : 'no', 'check_target(this);', $e['id']); } else { $tgt_chk = null; } if (!isset($e['expression']['levelErrors'])) { $errorImg = new CImg('images/general/ok_icon.png', 'expression_no_errors'); $errorImg->setHint(S_EXPRESSION_PART_NO_ERROR, '', '', false); } else { $allowedTesting = false; $errorImg = new CImg('images/general/error_icon.png', 'expression_errors'); $errorTexts = array(); if (is_array($e['expression']['levelErrors'])) { foreach ($e['expression']['levelErrors'] as $expVal => $errTxt) { if (count($errorTexts) > 0) { array_push($errorTexts, BR()); } array_push($errorTexts, $expVal, ':', $errTxt); } } $errorImg->setHint($errorTexts, '', 'left', false); } //if it is a templated trigger if ($limited == 'yes') { //make all links inside inactive for ($i = 0; $i < count($e['list']); $i++) { if (gettype($e['list'][$i]) == 'object' && get_class($e['list'][$i]) == 'CSpan' && $e['list'][$i]->getAttribute('class') == 'link') { $e['list'][$i]->setClass(''); $e['list'][$i]->setAttribute('onclick', ''); } } } $errorCell = new CCol($errorImg, 'center'); $row = new CRow(array($tgt_chk, $e['list'], $errorCell, isset($del_url) ? $del_url : null)); $exp_table->addRow($row); } } else { $allowedTesting = false; $outline = ''; } $frmTrig->addVar('remove_expression', ''); $btn_test = new CButton('test_expression', S_TEST, "openWinCentered(" . "'tr_testexpr.php?expression=' + encodeURIComponent(this.form.elements['expression'].value)" . ",'ExpressionTest'" . ",850,400" . ",'titlebar=no, resizable=yes, scrollbars=yes');" . "return false;"); if (!isset($allowedTesting) || !$allowedTesting) { $btn_test->setAttribute('disabled', 'disabled'); } if (empty($outline)) { $btn_test->setAttribute('disabled', 'yes'); } //SDI($outline); $wrapOutline = new CSpan(array($outline)); $wrapOutline->addStyle('white-space: pre;'); $frmTrig->addRow(SPACE, array($wrapOutline, BR(), BR(), $exp_table, $btn_test)); } // dependencies foreach ($dependencies as $val) { array_push($dep_el, array(new CCheckBox('rem_dependence[' . $val . ']', 'no', null, strval($val)), expand_trigger_description($val)), BR()); $frmTrig->addVar('dependencies[]', strval($val)); } if (count($dep_el) == 0) { array_push($dep_el, S_NO_DEPENDENCES_DEFINED); } else { array_push($dep_el, new CButton('del_dependence', S_DELETE_SELECTED)); } $frmTrig->addRow(S_THE_TRIGGER_DEPENDS_ON, $dep_el); /* end dependencies */ /* new dependency */ // $frmTrig->addVar('new_dependence','0'); // $txtCondVal = new CTextBox('trigger','',75,'yes'); $btnSelect = new CButton('btn1', S_ADD, "return PopUp('popup.php?srctbl=triggers" . '&srcfld1=triggerid' . '&reference=deptrigger' . '&multiselect=1' . "',1000,700);", 'T'); $frmTrig->addRow(S_NEW_DEPENDENCY, $btnSelect, 'new'); // end new dependency $type_select = new CComboBox('type'); $type_select->additem(TRIGGER_MULT_EVENT_DISABLED, S_NORMAL, $type == TRIGGER_MULT_EVENT_ENABLED ? 'no' : 'yes'); $type_select->additem(TRIGGER_MULT_EVENT_ENABLED, S_NORMAL . SPACE . '+' . SPACE . S_MULTIPLE_PROBLEM_EVENTS, $type == TRIGGER_MULT_EVENT_ENABLED ? 'yes' : 'no'); $frmTrig->addRow(S_EVENT_GENERATION, $type_select); $cmbPrior = new CComboBox('priority', $priority); for ($i = 0; $i <= 5; $i++) { $cmbPrior->addItem($i, get_severity_description($i)); } $frmTrig->addRow(S_SEVERITY, $cmbPrior); $frmTrig->addRow(S_COMMENTS, new CTextArea("comments", $comments, 90, 7)); $frmTrig->addRow(S_URL, new CTextBox("url", $url, 90)); $frmTrig->addRow(S_DISABLED, new CCheckBox("status", $status)); $frmTrig->addItemToBottomRow(new CButton("save", S_SAVE)); if (isset($_REQUEST["triggerid"])) { $frmTrig->addItemToBottomRow(SPACE); $frmTrig->addItemToBottomRow(new CButton("clone", S_CLONE)); $frmTrig->addItemToBottomRow(SPACE); if (!$limited) { $frmTrig->addItemToBottomRow(new CButtonDelete(S_DELETE_TRIGGER_Q, url_param("form") . url_param('groupid') . url_param("hostid") . url_param("triggerid"))); } } $frmTrig->addItemToBottomRow(SPACE); $frmTrig->addItemToBottomRow(new CButtonCancel(url_param('groupid') . url_param("hostid"))); $jsmenu = new CPUMenu(null, 170); $jsmenu->InsertJavaScript(); $script = "function addPopupValues(list){\n\t\t\t\t\t\tif(!isset('object', list)) return false;\n\n\t\t\t\t\t\tif(list.object == 'deptrigger'){\n\t\t\t\t\t\t\tfor(var i=0; i < list.values.length; i++){\n\t\t\t\t\t\t\t\tcreate_var('" . $frmTrig->getName() . "', 'new_dependence['+i+']', list.values[i], false);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tcreate_var('" . $frmTrig->getName() . "','add_dependence', 1, true);\n\t\t\t\t\t\t}\n\t\t\t\t\t}"; insert_js($script); return $frmTrig; }
function get_action_map_by_sysmapid($sysmapid) { $action_map = new CMap("links{$sysmapid}"); $db_elements = DBselect('SELECT * FROM sysmaps_elements WHERE sysmapid=' . $sysmapid); while ($db_element = DBfetch($db_elements)) { $url = $db_element["url"]; $alt = "Label: " . $db_element["label"]; $scripts_by_hosts = null; if ($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST) { $host = get_host_by_hostid($db_element["elementid"]); if ($host["status"] != HOST_STATUS_MONITORED) { continue; } $scripts_by_hosts = get_accessible_scripts_by_hosts(array($db_element["elementid"])); if (empty($url)) { $url = 'tr_status.php?hostid=' . $db_element['elementid'] . '&noactions=true&onlytrue=true&compact=true'; } $alt = "Host: " . $host["host"] . " " . $alt; } else { if ($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_MAP) { $map = get_sysmap_by_sysmapid($db_element["elementid"]); if (empty($url)) { $url = "maps.php?sysmapid=" . $db_element["elementid"]; } $alt = "Host: " . $map["name"] . " " . $alt; } elseif ($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_TRIGGER) { if (empty($url) && $db_element["elementid"] != 0) { $url = "events.php?triggerid=" . $db_element["elementid"]; } } else { if ($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST_GROUP) { if (empty($url) && $db_element["elementid"] != 0) { $url = "events.php?hostid=0&groupid=" . $db_element["elementid"]; } } } } if (empty($url)) { continue; } $back = get_png_by_selementid($db_element["selementid"]); if (!$back) { continue; } $x1_ = $db_element["x"]; $y1_ = $db_element["y"]; $x2_ = $db_element["x"] + imagesx($back); $y2_ = $db_element["y"] + imagesy($back); $r_area = new CArea(array($x1_, $y1_, $x2_, $y2_), $url, $alt, 'rect'); if (!empty($scripts_by_hosts)) { $menus = ''; $host_nodeid = id2nodeid($db_element["elementid"]); foreach ($scripts_by_hosts[$db_element["elementid"]] as $id => $script) { $script_nodeid = id2nodeid($script['scriptid']); if (bccomp($host_nodeid, $script_nodeid) == 0) { $menus .= "['" . $script['name'] . "',\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $db_element["elementid"] . "&scriptid=" . $script['scriptid'] . "','" . S_TOOLS . "',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } } $menus .= "[" . zbx_jsvalue(S_LINKS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],"; $menus .= "['" . S_STATUS_OF_TRIGGERS . "',\"javascript: redirect('tr_status.php?hostid=" . $db_element['elementid'] . "&noactions=true&onlytrue=true&compact=true')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; if (!empty($db_element["url"])) { $menus .= "['" . S_MAP . SPACE . S_URL . "',\"javascript: redirect('" . $url . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } $menus = trim($menus, ','); $menus = "show_popup_menu(event,[[" . zbx_jsvalue(S_TOOLS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus . "],180); cancelEvent(event);"; $r_area->AddAction('onclick', 'javascript: ' . $menus); } $action_map->AddItem($r_area); //AddRectArea($x1_,$y1_,$x2_,$y2_, $url, $alt); } $jsmenu = new CPUMenu(null, 170); $jsmenu->InsertJavaScript(); return $action_map; }