예제 #1
0
function make_latest_issues($params = array())
{
    global $USER_DETAILS;
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY);
    $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array());
    $scripts_by_hosts = get_accessible_scripts_by_hosts($available_hosts);
    $config = select_config();
    $sql_select = '';
    $sql_from = '';
    $sql_where = '';
    $limit = 20;
    if (!empty($params)) {
        if (isset($params['limit'])) {
            $limit = $params['limit'];
        }
        if (isset($params['groupid']) && $params['groupid'] > 0) {
            $sql_select .= ',g.name ';
            $sql_from .= ',groups g ';
            $sql_where .= ' AND g.groupid=hg.groupid ' . ' AND hg.groupid=' . $params['groupid'];
        }
        if (isset($params['hostid']) && $params['hostid'] > 0) {
            $sql_where .= ' AND h.hostid=' . $params['hostid'];
        }
    }
    $table = new CTableInfo();
    $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, isset($params['groupid']) && $params['groupid'] > 0 ? S_GROUP : null, S_HOST, S_ISSUE, S_LAST_CHANGE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS));
    $sql = 'SELECT DISTINCT t.triggerid,t.status,t.description,t.expression,t.priority,t.lastchange,t.value,h.host,h.hostid ' . $sql_select . ' FROM triggers t,hosts h,items i,functions f,hosts_groups hg ' . $sql_from . ' WHERE f.itemid=i.itemid ' . ' AND h.hostid=i.hostid ' . ' AND hg.hostid=h.hostid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND t.value=' . TRIGGER_VALUE_TRUE . $sql_where . ' ORDER BY t.lastchange DESC';
    $result = DBselect($sql, $limit);
    while ($row = DBfetch($result)) {
        // Check for dependencies
        if (trigger_dependent($row["triggerid"])) {
            continue;
        }
        $host = null;
        $menus = '';
        $host_nodeid = id2nodeid($row['hostid']);
        foreach ($scripts_by_hosts[$row['hostid']] 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=" . $row['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']}],";
            }
        }
        $menus .= "[" . zbx_jsvalue(S_LINKS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],";
        $menus .= "['" . S_LATEST_DATA . "',\"javascript: redirect('latest.php?groupid=0&hostid=" . $row['hostid'] . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
        $menus = rtrim($menus, ',');
        $menus = "show_popup_menu(event,[[" . zbx_jsvalue(S_TOOLS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus . "],180);";
        $host = new CSpan($row['host'], 'link');
        $host->setAttribute('onclick', 'javascript: ' . $menus);
        $host->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
        $event_sql = 'SELECT DISTINCT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged, t.type, t.url ' . ' FROM events e, triggers t ' . ' WHERE e.object=' . EVENT_SOURCE_TRIGGERS . ' AND e.objectid=' . $row['triggerid'] . ' AND t.triggerid=e.objectid ' . ' 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'], 'action');
                    $ack->setHint($ack_info);
                } else {
                    $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row_event['eventid'], 'on');
                }
            }
            //			$description = expand_trigger_description($row['triggerid']);
            $description = expand_trigger_description_by_data(array_merge($row, array('clock' => $row_event['clock'])), ZBX_FLAG_EVENT);
            //actions
            $actions = get_event_actions_stat_hints($row_event['eventid']);
            $clock = new CLink(zbx_date2str(S_DATE_FORMAT_YMDHMS, $row_event['clock']), 'events.php?triggerid=' . $row['triggerid'] . '&source=0&show_unknown=1&nav_time=' . $row_event['clock'], 'action');
            if ($row_event['url']) {
                $description = new CLink($description, $row_event['url'], 'action', null, true);
            } else {
                $description = new CSpan($description, 'pointer');
            }
            $description = new CCol($description, get_severity_style($row["priority"]));
            $description->setHint(make_popup_eventlist($row_event['eventid'], $row['type']));
            $table->addRow(array(get_node_name_by_elid($row['triggerid']), $host, $description, $clock, zbx_date2age($row_event['clock']), $ack, $actions));
        }
        unset($row, $description, $actions, $alerts, $hint);
    }
    $table->setFooter(new CCol(S_UPDATED . ': ' . date("H:i:s", time())));
    return $table;
}
예제 #2
0
파일: report5.php 프로젝트: rennhak/zabbix
        $time_dif = 7 * 24 * 3600;
        break;
    case 'month':
        $time_dif = 10 * 24 * 3600;
        break;
    case 'year':
        $time_dif = 365 * 24 * 3600;
        break;
    case 'day':
    default:
        $time_dif = 24 * 3600;
        break;
}
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY);
$available_triggers = get_accessible_triggers(PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
$scripts_by_hosts = get_accessible_scripts_by_hosts($available_hosts);
$triggers = array();
$triggerids = array();
$sql = 'SELECT h.host, h.hostid, t.triggerid, t.description, t.expression, t.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);
예제 #3
0
//SDI($_REQUEST['groupid'].' : '.$_REQUEST['hostid']);
validate_group_with_host($PAGE_GROUPS, $PAGE_HOSTS);
//SDI($_REQUEST['groupid'].' : '.$_REQUEST['hostid']);
$mute = get_profile('web.tr_status.mute', 0);
if (isset($audio) && !$mute) {
    play_sound($audio);
}
$trigg_wdgt = new CWidget();
$r_form = new CForm();
$r_form->setMethod('get');
//	$available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY);
//	$available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY);
$available_groups = $PAGE_GROUPS['groupids'];
$available_hosts = $PAGE_HOSTS['hostids'];
$available_triggers = get_accessible_triggers(PERM_READ_ONLY, $PAGE_HOSTS['hostids']);
$scripts_by_hosts = get_accessible_scripts_by_hosts($PAGE_HOSTS['hostids']);
$cmbGroups = new CComboBox('groupid', $PAGE_GROUPS['selected'], 'javascript: submit();');
$cmbHosts = new CComboBox('hostid', $PAGE_HOSTS['selected'], 'javascript: submit();');
foreach ($PAGE_GROUPS['groups'] as $groupid => $name) {
    $cmbGroups->addItem($groupid, get_node_name_by_elid($groupid) . $name);
}
foreach ($PAGE_HOSTS['hosts'] as $hostid => $name) {
    $cmbHosts->addItem($hostid, get_node_name_by_elid($hostid) . $name);
}
$r_form->addItem(array(S_GROUP . SPACE, $cmbGroups));
$r_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts));
$r_form->addVar('fullscreen', $_REQUEST['fullscreen']);
$url = 'tr_status.php' . ($_REQUEST['fullscreen'] ? '' : '?fullscreen=1');
$fs_icon = new CDiv(SPACE, 'fullscreen');
$fs_icon->setAttribute('title', $_REQUEST['fullscreen'] ? S_NORMAL . ' ' . S_VIEW : S_FULLSCREEN);
$fs_icon->addAction('onclick', new CScript("javascript: document.location = '" . $url . "';"));
예제 #4
0
파일: maps.inc.php 프로젝트: rennhak/zabbix
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;
}