/** * Class Constructor * * @param GlobalMainCfg $MAINCFG * @param GlobalMapCfg $MAPCFG * @author Lars Michelsen <*****@*****.**> */ public function __construct($MAPCFG, $getState = GET_STATE, $bIsView = IS_VIEW) { global $_BACKEND; $this->MAPCFG = $MAPCFG; if ($getState === GET_STATE) { $this->MAPOBJ = new NagVisMapObj($MAPCFG, $bIsView); // FIXME: needed? $this->MAPOBJ->setConfiguration($this->MAPCFG->getTypeDefaults('global')); $objConf = $MAPCFG->getMapObject(0); unset($objConf['type']); $this->MAPOBJ->setConfiguration($objConf); log_mem('postmapinit'); $this->MAPOBJ->fetchMapObjects(); log_mem('map ' . $this->MAPCFG->getName() . ' ' . count($this->MAPOBJ->getMembers())); log_mem('postmapobjects'); if ($bIsView === IS_VIEW) { $this->MAPOBJ->queueState(GET_STATE, GET_SINGLE_MEMBER_STATES); $_BACKEND->execute(); $this->MAPOBJ->applyState(); log_mem('postmapstate'); } else { $this->MAPOBJ->queueState(GET_STATE, DONT_GET_SINGLE_MEMBER_STATES); log_mem('postmapstatequeue'); } } }
/** * Parses the maps and maps for the overview page * Then it is called for a list of maps to return the current state * for the listed objects. * * @return String Json Code * @author Lars Michelsen <*****@*****.**> * FIXME: More cleanups, compacting and extraction of single parts */ public function parseMapsJson($what = COMPLETE, $objects = array()) { global $_BACKEND, $CORE; $mapList = $objects; $aMaps = array(); $aObjs = array(); log_mem('pre'); foreach ($mapList as $objectId) { $a = explode('-', $objectId, 2); if (!isset($a[1])) { continue; } $mapName = $a[1]; // list mode: Skip processing when this type of object should not be shown if (cfg('index', 'showmaps') != 1) { continue; } try { $ret = $this->parseMapJson($objectId, $mapName, $what); if ($ret === null) { // Skip maps which shal not be shown to the user continue; } } catch (Exception $e) { $aMaps[] = $this->mapError($mapName, $e->getMessage()); continue; } $aObjs[] = $ret; log_mem('post ' . $mapName); } // Now fetch and apply data from backend $_BACKEND->execute(); foreach ($aObjs as $aObj) { $aObj[0]->applyState(); $aObj[0]->fetchIcon(); if ($what === ONLY_STATE) { $aMaps[] = array_merge($aObj[0]->getObjectStateInformations(), $aObj[1]); } else { $aMaps[] = array_merge($aObj[0]->parseJson(), $aObj[1]); } } log_mem('post backend'); return json_encode($aMaps); }
/** * Gets all objects of the map * * @author Thomas Casteleyn <*****@*****.**> * @author Lars Michelsen <*****@*****.**> */ public function fetchMapObjects(&$arrMapNames = array(), $depth = 0) { foreach ($this->MAPCFG->getMapObjects() as $objConf) { $type = $objConf['type']; if ($type == 'global' || $type == 'template') { continue; } log_mem('preconf'); $typeDefs = $this->MAPCFG->getTypeDefaults($type); // merge with "global" settings foreach ($typeDefs as $key => $default) { if (!isset($objConf[$key])) { $objConf[$key] = $default; } } switch ($type) { case 'host': log_mem('prehost'); $OBJ = new NagVisHost($objConf['backend_id'], $objConf['host_name']); break; case 'service': $OBJ = new NagVisService($objConf['backend_id'], $objConf['host_name'], $objConf['service_description']); break; case 'hostgroup': $OBJ = new NagVisHostgroup($objConf['backend_id'], $objConf['hostgroup_name']); break; case 'servicegroup': $OBJ = new NagVisServicegroup($objConf['backend_id'], $objConf['servicegroup_name']); break; case 'dyngroup': $OBJ = new NagVisDynGroup($objConf['backend_id'], $objConf['name']); break; case 'aggr': $OBJ = new NagVisAggr($objConf['backend_id'], $objConf['name']); break; case 'map': // Initialize map configuration $SUBMAPCFG = new GlobalMapCfg($objConf['map_name']); $mapCfgInvalid = null; if ($SUBMAPCFG->checkMapConfigExists(0)) { try { $SUBMAPCFG->readMapConfig(); } catch (MapCfgInvalid $e) { $mapCfgInvalid = l('Map Configuration Error: [ERR]', array('ERR' => $e->getMessage())); } catch (Exception $e) { $mapCfgInvalid = l('Problem while processing map: [ERR]', array('ERR' => (string) $e)); } } $OBJ = new NagVisMapObj($SUBMAPCFG, !IS_VIEW); if ($mapCfgInvalid) { $OBJ->setProblem($mapCfgInvalid); } if (!$SUBMAPCFG->checkMapConfigExists(0)) { $OBJ->setProblem(l('mapCfgNotExists', 'MAP~' . $objConf['map_name'])); } /** * When the current map object is a summary object skip the map * child for preventing a loop */ if ($this->MAPCFG->getName() == $SUBMAPCFG->getName() && $this->isSummaryObject == true) { continue 2; } /** * This occurs when someone creates a map icon which links to itself * * The object will be marked as summary object and is ignored on next level. * See the code above. */ if ($this->MAPCFG->getName() == $SUBMAPCFG->getName()) { $OBJ->isSummaryObject = true; } /** * All maps which were seen before are stored in the list once. If * they are already in the list and depth is more than 3 levels, * skip them to prevent loops. */ if (isset($arrMapNames[$SUBMAPCFG->getName()]) && $depth > 3) { $OBJ->isLoopingBacklink = true; continue 2; } // Store this map in the mapNames list $arrMapNames[$SUBMAPCFG->getName()] = true; // Skip this map when the user is not permitted toview this map if (!$this->isPermitted($OBJ)) { continue 2; } break; case 'shape': $OBJ = new NagVisShape($objConf['icon']); break; case 'textbox': $OBJ = new NagVisTextbox(); break; case 'container': $OBJ = new NagVisContainer(); break; case 'line': $OBJ = new NagVisLine(); break; default: throw new NagVisException(l('unknownObject', array('TYPE' => $type, 'MAPNAME' => $this->getName()))); break; } log_mem('preconf'); // Apply default configuration to object $OBJ->setConfiguration($objConf); // Skip object by exclude filter? => Totally exclude (exclude_members) if ($this->hasExcludeFilters(!COUNT_QUERY) && $this->excludeMapObject($OBJ, !COUNT_QUERY)) { continue; } // Write member to object array $this->members[] = $OBJ; log_mem('posthost'); } // Now dig into the next map level. This has to be done here to fight // the loops at this level and not at the single branches of map links. foreach ($this->members as $OBJ) { $sType = $OBJ->getType(); if ($sType == 'map') { /** * When the current map object is a summary object skip the map * child for preventing a loop */ if ($sType == 'map' && $this->MAPCFG->getName() == $OBJ->MAPCFG->getName() && $this->isSummaryObject == true) { continue; } /** * All maps which produce a loop by linking back to earlier maps * need to be skipped here. */ if ($sType == 'map' && $OBJ->isLoopingBacklink) { continue; } if (!$OBJ->hasProblem()) { $OBJ->fetchMapObjects($arrMapNames, $depth + 1); } } } }