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;
}
        // if element use icon map and icon map is set for map, and is host like element, we use default icon map icon
        if ($map['iconmapid'] && $selement['use_iconmap'] && ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST || $selement['elementtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS)) {
            $iconid = $defaultAutoIconId;
        } else {
            $iconid = $selement['iconid_off'];
        }
        $mapInfo[$selement['selementid']] = array('iconid' => $iconid, 'icon_type' => SYSMAP_ELEMENT_ICON_OFF);
        $mapInfo[$selement['selementid']]['name'] = $selement['elementtype'] == SYSMAP_ELEMENT_TYPE_IMAGE ? _('Image') : $selement['elementName'];
    }
    $allLinks = true;
} else {
    // we need selements to be a hash for further processing
    $map['selements'] = zbx_toHash($map['selements'], 'selementid');
    add_triggerExpressions($map['selements']);
    $areas = populateFromMapAreas($map);
    $mapInfo = getSelementsInfo($map, array('severity_min' => get_request('severity_min')));
    processAreasCoordinates($map, $areas, $mapInfo);
    $allLinks = false;
}
/*
 * Draw map
 */
drawMapConnectors($im, $map, $mapInfo, $allLinks);
if (!isset($_REQUEST['noselements'])) {
    drawMapHighligts($im, $map, $mapInfo);
    drawMapSelements($im, $map, $mapInfo);
}
$expandMacros = get_request('expand_macros', true);
drawMapLabels($im, $map, $mapInfo, $expandMacros);
drawMapLinkLabels($im, $map, $mapInfo, $expandMacros);
if (!isset($_REQUEST['noselements']) && $map['markelements'] == 1) {
Example #4
0
    }
    $map_info = array();
    foreach ($map['selements'] as $selement) {
        // if element use icon map and icon map is set for map, and is host like element, we use default icon map icon
        if ($map['iconmapid'] && $selement['use_iconmap'] && ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST || $selement['elementtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS)) {
            $iconid = $defaultAutoIconId;
        } else {
            $iconid = $selement['iconid_off'];
        }
        $map_info[$selement['selementid']] = array('iconid' => $iconid, 'icon_type' => SYSMAP_ELEMENT_ICON_OFF);
        $map_info[$selement['selementid']]['name'] = $selement['elementtype'] == SYSMAP_ELEMENT_TYPE_IMAGE ? _('Image') : $selement['elementName'];
    }
    $allLinks = true;
} else {
    $areas = populateFromMapAreas($map);
    $map_info = getSelementsInfo($map);
    processAreasCoordinates($map, $areas, $map_info);
    $allLinks = false;
}
/*
 * Draw map
 */
drawMapConnectors($im, $map, $map_info, $allLinks);
if (!isset($_REQUEST['noselements'])) {
    drawMapHighligts($im, $map, $map_info);
    drawMapSelements($im, $map, $map_info);
}
$expand_macros = get_request('expand_macros', true);
drawMapLabels($im, $map, $map_info, $expand_macros);
drawMapLinkLabels($im, $map, $map_info, $expand_macros);
if (!isset($_REQUEST['noselements']) && $map['markelements'] == 1) {
Example #5
0
function get_selement_iconid($selement, $info = null)
{
    if ($selement['selementid'] > 0) {
        if (is_null($info)) {
            // get sysmap
            $options = array('sysmapids' => $selement['sysmapid'], 'output' => API_OUTPUT_EXTEND);
            $sysmaps = CMap::get($options);
            $sysmap = reset($sysmaps);
            $sysmap['selements'] = array($selement);
            $map_info = getSelementsInfo($sysmap);
            $info = reset($map_info);
            //-----
        }
        //SDI($info);
        switch ($info['icon_type']) {
            case SYSMAP_ELEMENT_ICON_OFF:
                $info['iconid'] = $selement['iconid_off'];
                break;
            case SYSMAP_ELEMENT_ICON_ON:
                $info['iconid'] = $selement['iconid_on'];
                break;
            case SYSMAP_ELEMENT_ICON_UNKNOWN:
                $info['iconid'] = $selement['iconid_unknown'];
                break;
            case SYSMAP_ELEMENT_ICON_MAINTENANCE:
                $info['iconid'] = $selement['iconid_maintenance'];
                break;
        }
        // Process for default icons
        if ($info['iconid'] == 0) {
            $info['iconid'] = $selement['iconid_off'];
        }
        //------
    } else {
        $info['iconid'] = $selement['iconid_off'];
    }
    return $info['iconid'];
}
Example #6
0
        // if element use icon map and icon map is set for map, and is host like element, we use default icon map icon
        if ($map['iconmapid'] && $selement['use_iconmap'] && ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST || $selement['elementtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS)) {
            $iconid = $defaultAutoIconId;
        } else {
            $iconid = $selement['iconid_off'];
        }
        $mapInfo[$selement['selementid']] = ['iconid' => $iconid, 'icon_type' => SYSMAP_ELEMENT_ICON_OFF];
        $mapInfo[$selement['selementid']]['name'] = $selement['elementtype'] == SYSMAP_ELEMENT_TYPE_IMAGE ? _('Image') : $selement['elementName'];
    }
    $allLinks = true;
} else {
    // we need selements to be a hash for further processing
    $map['selements'] = zbx_toHash($map['selements'], 'selementid');
    add_triggerExpressions($map['selements']);
    $areas = populateFromMapAreas($map);
    $mapInfo = getSelementsInfo($map, ['severity_min' => getRequest('severity_min')]);
    processAreasCoordinates($map, $areas, $mapInfo);
    $allLinks = false;
}
/*
 * Draw map
 */
drawMapConnectors($im, $map, $mapInfo, $allLinks);
if (!isset($_REQUEST['noselements'])) {
    drawMapHighligts($im, $map, $mapInfo);
    drawMapSelements($im, $map, $mapInfo);
}
$expandMacros = getRequest('expand_macros', true);
drawMapLabels($im, $map, $mapInfo, $expandMacros, $graphtheme);
drawMapLinkLabels($im, $map, $mapInfo, $expandMacros, $graphtheme);
if (!isset($_REQUEST['noselements']) && $map['markelements'] == 1) {