$scripts_wdgt->addItem($frmScr); } else { $form = new CForm(); $form->setName('frm_scripts'); $form->setAttribute('id', 'scripts'); $form->addVar('action', '1'); $numrows = new CDiv(); $numrows->setAttribute('name', 'numrows'); $scripts_wdgt->addHeader(S_SCRIPTS_BIG); $scripts_wdgt->addHeader($numrows); $table = new CTableInfo(S_NO_SCRIPTS_DEFINED); $table->setHeader(array(new CCheckBox('all_scripts', null, "checkAll('" . $form->getName() . "','all_scripts','scripts');"), make_sorting_header(S_NAME, 'name'), make_sorting_header(S_COMMAND, 'command'), S_USER_GROUP, S_HOST_GROUP, S_HOST_ACCESS)); $sortfield = getPageSortField('name'); $sortorder = getPageSortOrder(); $options = array('output' => API_OUTPUT_EXTEND, 'editable' => 1, 'select_groups' => API_OUTPUT_EXTEND); $scripts = CScript::get($options); // sorting order_result($scripts, $sortfield, $sortorder); // PAGING UPPER $paging = getPagingLine($scripts); $scripts_wdgt->addItem($paging); //--------- foreach ($scripts as $snum => $script) { $scriptid = $script['scriptid']; $user_group_name = S_ALL_S; if ($script['usrgrpid'] > 0) { $user_group = CUserGroup::get(array('usrgrpids' => $script['usrgrpid'], 'extendoutput' => 1)); $user_group = reset($user_group); $user_group_name = $user_group['name']; } $host_group_name = S_ALL_S;
function make_latest_issues($filter = array()) { global $page; $config = select_config(); $limit = isset($filter['limit']) ? $filter['limit'] : 20; $options = array('groupids' => $filter['groupids'], 'monitored' => 1, 'maintenance' => $filter['maintenance'], 'skipDependent' => 1, 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE), 'select_groups' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND, 'sortfield' => 'lastchange', 'sortorder' => ZBX_SORT_DOWN, 'limit' => $limit); if (isset($filter['hostids'])) { $options['hostids'] = $filter['hostids']; } $triggers = CTrigger::get($options); // GATHER HOSTS FOR SELECTED TRIGGERS {{{ $triggers_hosts = array(); foreach ($triggers as $tnum => $trigger) { // if trigger is lost(broken expression) we skip it if (empty($trigger['hosts'])) { unset($triggers[$tnum]); continue; } $triggers_hosts = array_merge($triggers_hosts, $trigger['hosts']); } $triggers_hosts = zbx_toHash($triggers_hosts, 'hostid'); $triggers_hostids = array_keys($triggers_hosts); // }}} GATHER HOSTS FOR SELECTED TRIGGERS $scripts_by_hosts = CScript::getScriptsByHosts($triggers_hostids); $table = new CTableInfo(); $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST, S_ISSUE, S_LAST_CHANGE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS)); $thosts_cache = array(); foreach ($triggers as $tnum => $trigger) { // Check for dependencies $group = reset($trigger['groups']); $host = reset($trigger['hosts']); $trigger['hostid'] = $host['hostid']; $trigger['host'] = $host['host']; $host = null; $menus = ''; $host_nodeid = id2nodeid($trigger['hostid']); foreach ($scripts_by_hosts[$trigger['hostid']] as $id => $script) { $script_nodeid = id2nodeid($script['scriptid']); if (bccomp($host_nodeid, $script_nodeid) == 0) { $menus .= "[" . zbx_jsvalue($script['name']) . ",\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $trigger['hostid'] . "&scriptid=" . $script['scriptid'] . "','" . S_TOOLS . "',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } } if (!empty($scripts_by_hosts)) { $menus = "['" . S_TOOLS . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus; } if (isset($thosts_cache[$trigger['hostid']])) { $hprofile = $thosts_cache[$trigger['hostid']]; } else { $hprofile = CHost::get(array('hostids' => $trigger['hostid'], 'output' => API_OUTPUT_SHORTEN, 'select_profile' => API_OUTPUT_EXTEND)); $hprofile = reset($hprofile); $thosts_cache[$hprofile['hostid']] = $hprofile; } $menus .= "['" . S_LINKS . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],"; $menus .= "['" . S_LATEST_DATA . "',\"javascript: redirect('latest.php?groupid=" . $group['groupid'] . '&hostid=' . $trigger['hostid'] . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; if (!empty($hprofile['profile'])) { $menus .= "['" . S_PROFILE . "',\"javascript: redirect('hostprofiles.php?hostid=" . $trigger['hostid'] . "&prof_type=0')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } if (!empty($hprofile['profile_ext'])) { $menus .= "['" . S_EXTENDED_PROFILE . "',\"javascript: redirect('hostprofiles.php?hostid=" . $trigger['hostid'] . "&prof_type=1')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } $menus = rtrim($menus, ','); $menus = 'show_popup_menu(event,[' . $menus . '],180);'; $host = new CSpan($trigger['host'], 'link_menu pointer'); $host->setAttribute('onclick', 'javascript: ' . $menus); //$host = new CSpan($trigger['host'],'link_menu pointer'); //$host->setAttribute('onclick','javascript: '.$menus); // Maintenance {{{ $trigger_host = $triggers_hosts[$trigger['hostid']]; $text = null; $style = 'link_menu'; if ($trigger_host['maintenance_status']) { $style .= ' orange'; $options = array('maintenanceids' => $trigger_host['maintenanceid'], 'output' => API_OUTPUT_EXTEND); $maintenances = CMaintenance::get($options); $maintenance = reset($maintenances); $text = $maintenance['name']; $text .= ' [' . ($trigger_host['maintenance_type'] ? S_NO_DATA_MAINTENANCE : S_NORMAL_MAINTENANCE) . ']'; } $host = new CSpan($trigger['host'], $style . ' pointer'); $host->setAttribute('onclick', 'javascript: ' . $menus); if (!is_null($text)) { $host->setHint($text, '', '', false); } // }}} Maintenance $event_sql = 'SELECT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged' . ' FROM events e' . ' WHERE e.object=' . EVENT_OBJECT_TRIGGER . ' AND e.objectid=' . $trigger['triggerid'] . ' AND e.value=' . TRIGGER_VALUE_TRUE . ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC'; $res_events = DBSelect($event_sql, 1); while ($row_event = DBfetch($res_events)) { $ack = NULL; if ($config['event_ack_enable']) { if ($row_event['acknowledged'] == 1) { $ack_info = make_acktab_by_eventid($row_event['eventid']); $ack_info->setAttribute('style', 'width: auto;'); $ack = new CLink(S_YES, 'acknow.php?eventid=' . $row_event['eventid'] . '&backurl=' . $page['file'], 'off'); $ack->setHint($ack_info, '', '', false); } else { $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row_event['eventid'] . '&backurl=' . $page['file'], 'on'); } } // $description = expand_trigger_description($row['triggerid']); $description = expand_trigger_description_by_data(zbx_array_merge($trigger, array('clock' => $row_event['clock'])), ZBX_FLAG_EVENT); //actions $actions = get_event_actions_stat_hints($row_event['eventid']); $clock = new CLink(zbx_date2str(S_BLOCKS_LATEST_ISSUES_DATE_FORMAT, $row_event['clock']), 'events.php?triggerid=' . $trigger['triggerid'] . '&source=0&show_unknown=1&nav_time=' . $row_event['clock']); if ($trigger['url']) { $description = new CLink($description, $trigger['url'], null, null, true); } else { $description = new CSpan($description, 'pointer'); } $description = new CCol($description, get_severity_style($trigger['priority'])); $description->setHint(make_popup_eventlist($row_event['eventid'], $trigger['type'], $trigger['triggerid']), '', '', false); $table->addRow(array(get_node_name_by_elid($trigger['triggerid']), $host, $description, $clock, zbx_date2age($row_event['clock']), $ack, $actions)); } unset($trigger, $description, $actions); } $table->setFooter(new CCol(S_UPDATED . ': ' . zbx_date2str(S_BLOCKS_LATEST_ISSUES_TIME_FORMAT))); return $table; }
require_once "include/hosts.inc.php"; require_once "include/scripts.inc.php"; require_once "include/forms.inc.php"; $page['title'] = "S_SCRIPTS"; $page['file'] = 'scripts_exec.php'; define('ZBX_PAGE_NO_MENU', 1); include_once "include/page_header.php"; // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields = array('hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({execute})'), 'scriptid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({execute})'), 'execute' => array(T_ZBX_INT, O_OPT, P_ACT, IN('0,1'), null)); check_fields($fields); if (isset($_REQUEST['execute'])) { $scriptid = $_REQUEST['scriptid']; $hostid = $_REQUEST['hostid']; $sql = 'SELECT name ' . ' FROM scripts ' . ' WHERE scriptid=' . $scriptid; $script_info = DBfetch(DBselect($sql)); $result = CScript::execute(array('hostid' => $hostid, 'scriptid' => $scriptid)); if ($result === false) { show_messages(false, '', S_SCRIPT_ERROR); } else { $message = $result['value']; if ($result['response'] == 'failed') { error($message); show_messages(false, '', S_SCRIPT_ERROR); $message = ''; } $frmResult = new CFormTable($script_info['name'] . ': ' . script_make_command($scriptid, $hostid)); $frmResult->addRow(S_RESULT, new CTextArea('message', $message, 100, 25, 'yes')); $frmResult->addItemToBottomRow(new CButton('close', S_CLOSE, 'window.close();')); $frmResult->show(); } }
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; }
private static function script($action, $params) { CScript::$error = array(); switch ($action) { default: $result = call_user_func(array('CScript', $action), $params); } self::$result = $result; }
public static function getScriptsByHosts($hostids) { zbx_value2array($hostids); $obj_params = array('hostids' => $hostids, 'preservekeys' => 1); $hosts_read_only = CHost::get($obj_params); $hosts_read_only = zbx_objectValues($hosts_read_only, 'hostid'); $obj_params = array('editable' => 1, 'hostids' => $hostids, 'preservekeys' => 1); $hosts_read_write = CHost::get($obj_params); $hosts_read_write = zbx_objectValues($hosts_read_write, 'hostid'); // initialize array $scripts_by_host = array(); foreach ($hostids as $id => $hostid) { $scripts_by_host[$hostid] = array(); } //----- $options = array('hostids' => $hostids, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1); $groups = CHostGroup::get($options); $obj_params = array('groupids' => zbx_objectValues($groups, 'groupid'), 'sortfield' => 'name', 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1); $scripts = CScript::get($obj_params); foreach ($scripts as $num => $script) { $add_to_hosts = array(); $hostids = zbx_objectValues($groups[$script['groupid']]['hosts'], 'hostid'); if (PERM_READ_WRITE == $script['host_access']) { if ($script['groupid'] > 0) { $add_to_hosts = zbx_uint_array_intersect($hosts_read_write, $hostids); } else { $add_to_hosts = $hosts_read_write; } } else { if (PERM_READ_ONLY == $script['host_access']) { if ($script['groupid'] > 0) { $add_to_hosts = zbx_uint_array_intersect($hosts_read_only, $hostids); } else { $add_to_hosts = $hosts_read_only; } } } foreach ($add_to_hosts as $id => $hostid) { $scripts_by_host[$hostid][] = $script; } } //SDII(count($scripts_by_host)); return $scripts_by_host; }
$time_dif = 7 * 86400; break; case 'month': $time_dif = 30 * 86400; break; case 'year': $time_dif = 365 * 86400; break; case 'day': default: $time_dif = 86400; break; } $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY); $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array()); $scripts_by_hosts = CScript::getScriptsByHosts($available_hosts); $triggers = array(); $triggerids = array(); $sql = 'SELECT h.host, MAX(h.hostid) as hostid, t.triggerid, t.description, t.expression, ' . ' MAX(t.lastchange) as lastchange, t.priority, count(distinct e.eventid) as cnt_event ' . ' FROM hosts h, triggers t, functions f, items i, events e' . ' WHERE h.hostid = i.hostid ' . ' and i.itemid = f.itemid ' . ' and t.triggerid=f.triggerid ' . ' and t.triggerid=e.objectid ' . ' and e.object=' . EVENT_OBJECT_TRIGGER . ' and e.clock>' . (time() - $time_dif) . ' and ' . DBcondition('t.triggerid', $available_triggers) . ' and ' . DBin_node('t.triggerid') . ' GROUP BY h.host,t.triggerid,t.description,t.expression,t.priority ' . ' ORDER BY cnt_event desc, h.host, t.description, t.triggerid'; $result = DBselect($sql, 100); while ($row = DBfetch($result)) { $row['items'] = array(); $triggers[$row['triggerid']] = $row; $triggerids[$row['triggerid']] = $row['triggerid']; } $sql = 'SELECT f.triggerid, i.* ' . ' FROM functions f, items i ' . ' WHERE ' . DBcondition('f.triggerid', $triggerids) . ' AND i.itemid=f.itemid'; $result = DBselect($sql); while ($row = DBfetch($result)) { $item['itemid'] = $row['itemid']; $item['action'] = str_in_array($row['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues'; $item['description'] = item_description($row);