function getActionMapBySysmap($sysmap)
{
    $action_map = new CAreaMap('links' . $sysmap['sysmapid']);
    $areas = populateFromMapAreas($sysmap);
    $map_info = getSelementsInfo($sysmap);
    processAreasCoordinates($sysmap, $areas, $map_info);
    $hostids = array();
    foreach ($sysmap['selements'] as $sid => &$selement) {
        if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
            $hostids[$selement['elementid']] = $selement['elementid'];
            // expanding hosts url macros again as some hosts were added from hostgroup areeas
            // and automatic expanding only happens for elements that are defined for map in db
            foreach ($selement['urls'] as $urlid => $url) {
                $selement['urls'][$urlid]['url'] = str_replace('{HOST.ID}', $selement['elementid'], $url['url']);
            }
        }
        if ($selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS) {
            unset($sysmap['selements'][$sid]);
        }
    }
    unset($selement);
    if (count($hostids)) {
        $scripts_by_hosts = API::Script()->getScriptsByHosts($hostids);
    }
    $hosts = API::Host()->get(array('nodeids' => get_current_nodeid(true), 'hostids' => $hostids, 'output' => array('status'), 'nopermissions' => true, 'preservekeys' => true, 'selectScreens' => API_OUTPUT_COUNT));
    foreach ($sysmap['selements'] as $elem) {
        $back = get_png_by_selement($map_info[$elem['selementid']]);
        $area = new CArea(array($elem['x'], $elem['y'], $elem['x'] + imagesx($back), $elem['y'] + imagesy($back)), '', '', 'rect');
        $area->addClass('menu-map');
        // pop up menu
        order_result($elem['urls'], 'name');
        $menuData = array('urls' => array_values($elem['urls']), 'elementId' => $elem['elementid'], 'elementType' => $elem['elementtype'], 'scripts' => array(), 'hasScreens' => false, 'isMonitored' => false);
        if ($elem['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
            $host = $hosts[$elem['elementid']];
            $menuData['scripts'] = $scripts_by_hosts[$elem['elementid']];
            $menuData['hasScreens'] = (bool) $host['screens'];
            $menuData['isMonitored'] = $hosts[$elem['elementid']]['status'] == HOST_STATUS_MONITORED;
        }
        $area->setAttribute('data-menu', $menuData);
        $action_map->addItem($area);
    }
    return $action_map;
}
Example #2
0
/**
 * Create map area with submenu for sysmap elements.
 * In submenu gathered information about urls, scripts and submaps.
 *
 * @param array $sysmap
 * @param array $options
 * @param int   $options['severity_min']
 *
 * @return CAreaMap
 */
function getActionMapBySysmap($sysmap, array $options = array())
{
    $sysmap['selements'] = zbx_toHash($sysmap['selements'], 'selementid');
    $sysmap['links'] = zbx_toHash($sysmap['links'], 'linkid');
    $actionMap = new CAreaMap('links' . $sysmap['sysmapid']);
    $areas = populateFromMapAreas($sysmap);
    $mapInfo = getSelementsInfo($sysmap, $options);
    processAreasCoordinates($sysmap, $areas, $mapInfo);
    $hostIds = array();
    $triggerIds = array();
    foreach ($sysmap['selements'] as $id => &$selement) {
        if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
            $hostIds[$selement['elementid']] = $selement['elementid'];
            // expanding host URL macros again as some hosts were added from hostgroup areas
            // and automatic expanding only happens for elements that are defined for map in db
            foreach ($selement['urls'] as $urlId => $url) {
                $selement['urls'][$urlId]['url'] = str_replace('{HOST.ID}', $selement['elementid'], $url['url']);
            }
        } elseif ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER) {
            $triggerIds[$selement['elementid']] = $selement['elementid'];
        }
        if ($selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS) {
            unset($sysmap['selements'][$id]);
        }
    }
    unset($selement);
    $hostScripts = API::Script()->getScriptsByHosts($hostIds);
    $hosts = API::Host()->get(array('hostids' => $hostIds, 'output' => array('hostid', 'status'), 'nopermissions' => true, 'preservekeys' => true, 'selectGraphs' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT));
    $triggers = API::Trigger()->get(array('output' => array('triggerid'), 'triggerids' => $triggerIds, 'selectHosts' => array('status'), 'preservekeys' => true, 'nopermissions' => true));
    foreach ($sysmap['selements'] as $elem) {
        $back = get_png_by_selement($mapInfo[$elem['selementid']]);
        $area = new CArea(array($elem['x'], $elem['y'], $elem['x'] + imagesx($back), $elem['y'] + imagesy($back)), '', '', 'rect');
        $area->addClass('menu-map');
        $hostId = null;
        $scripts = null;
        $gotos = null;
        switch ($elem['elementtype']) {
            case SYSMAP_ELEMENT_TYPE_HOST:
                $host = $hosts[$elem['elementid']];
                if ($hostScripts[$elem['elementid']]) {
                    $hostId = $elem['elementid'];
                    $scripts = $hostScripts[$elem['elementid']];
                }
                $gotos['triggerStatus'] = array('hostid' => $elem['elementid'], 'show_severity' => isset($options['severity_min']) ? $options['severity_min'] : null);
                $gotos['showTriggers'] = $hosts[$elem['elementid']]['status'] == HOST_STATUS_MONITORED;
                $gotos['graphs'] = array('hostid' => $host['hostid']);
                $gotos['showGraphs'] = (bool) $host['graphs'];
                $gotos['screens'] = array('hostid' => $host['hostid']);
                $gotos['showScreens'] = (bool) $host['screens'];
                $gotos['inventory'] = array('hostid' => $host['hostid']);
                $gotos['latestData'] = array('hostids' => array($host['hostid']));
                break;
            case SYSMAP_ELEMENT_TYPE_MAP:
                $gotos['submap'] = array('sysmapid' => $elem['elementid'], 'severity_min' => isset($options['severity_min']) ? $options['severity_min'] : null);
                break;
            case SYSMAP_ELEMENT_TYPE_TRIGGER:
                $gotos['events'] = array('triggerid' => $elem['elementid'], 'stime' => date(TIMESTAMP_FORMAT, time() - SEC_PER_WEEK), 'period' => SEC_PER_WEEK);
                $gotos['showEvents'] = false;
                if (isset($triggers[$elem['elementid']])) {
                    foreach ($triggers[$elem['elementid']]['hosts'] as $host) {
                        if ($host['status'] == HOST_STATUS_MONITORED) {
                            $gotos['showEvents'] = true;
                            break;
                        }
                    }
                }
                break;
            case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                $gotos['triggerStatus'] = array('groupid' => $elem['elementid'], 'hostid' => 0, 'show_severity' => isset($options['severity_min']) ? $options['severity_min'] : null);
                // always show active trigger link for host group map elements
                $gotos['showTriggers'] = true;
                break;
        }
        order_result($elem['urls'], 'name');
        $area->setMenuPopup(CMenuPopupHelper::getMap($hostId, $scripts, $gotos, $elem['urls']));
        $actionMap->addItem($area);
    }
    return $actionMap;
}
Example #3
0
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;
}