/** * 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; }