Module: nagvis
Branch: master
Commit: 49a0d81219e7f61486e923d93f856e503145e616
URL:
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=49a0d81219e7f61486e923d93f856e503145e616
Author: Lars Michelsen <[email protected]>
Date: Tue Dec 28 22:58:40 2010 +0100
Implemented new object id handling in automap code
---
ChangeLog | 1 +
TODO | 2 +
etc/automaps/__automap.cfg | 7 --
share/server/core/classes/CoreModAutoMap.php | 3 +
share/server/core/classes/GlobalMapCfg.php | 2 +-
share/server/core/classes/NagVisAutoMap.php | 79 +++++++++++++++++++++-
share/server/core/classes/NagVisAutomapCfg.php | 8 ++
share/server/core/classes/objects/NagiosHost.php | 8 --
8 files changed, 91 insertions(+), 19 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 734ac0d..68f6487 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,6 +27,7 @@ Automap
* Made automap coord parsing regex resistent against html entities in the URL
* Hiding deprecated maxLayers option from modify view dialog
* Automap params changed via GUI can be made permanent now
+ * The x/y coords don't need to be set as dummy values in automap configs
anymore
Backend: Livestatus
* Bugfix: PHP error when trying to write to socket while the remote host is
not
diff --git a/TODO b/TODO
index 3159144..e5b701f 100644
--- a/TODO
+++ b/TODO
@@ -17,3 +17,5 @@ Fehlerbehandlung:
Ajax Schnittstelle umbauen: Kleines Protokoll einbauen, mit Header inkl.
Fehlercodes etc.
Bessere Fehlerbehandlung z.B. auf Ãbersichtsseite, wenn Antwort kein
gültiges JS ist.
+
+ Standard PHP Fehler in Exceptions umwandeln und Exceptions ordentlich
behandeln
diff --git a/etc/automaps/__automap.cfg b/etc/automaps/__automap.cfg
index c94e5db..ed070d2 100644
--- a/etc/automaps/__automap.cfg
+++ b/etc/automaps/__automap.cfg
@@ -19,12 +19,9 @@ label_border=transparent
# file.
#
# The settings of the first host will be used for all objects on the map.
-# The coords x/y need to be set but will be ignored on the automap.
#
define host {
host_name=__dummy__
-x=0
-y=0
url=[htmlcgi]/status.cgi?host=[host_name]
}
@@ -42,12 +39,8 @@ url=[htmlcgi]/status.cgi?host=[host_name]
# options defined for a host with this name. When it finds a host it reads all
# configuration options and uses them to render the object on the automap.
#
-# The coords x/y need to be set but will be ignored on the automap.
-#
#define host {
#host_name=www2.nagvis.org
-#x=0
-#y=0
#iconset=std_big
#url=[htmlbase]/frontend/nagvis-js/index.php?mod=AutoMap&act=view&show=__automap&root=www2.nagvis.org&childLayers=2&renderMode=undirected
#}
diff --git a/share/server/core/classes/CoreModAutoMap.php
b/share/server/core/classes/CoreModAutoMap.php
index 6971091..c17dfdf 100644
--- a/share/server/core/classes/CoreModAutoMap.php
+++ b/share/server/core/classes/CoreModAutoMap.php
@@ -195,6 +195,9 @@ class CoreModAutoMap extends CoreModule {
$MAPCFG->readMapConfig();
$MAPCFG->filterMapObjects($aVals['i']);
+ // Filter by explicit list of host object ids
+ $this->opts['filterByIds'] = $aVals['i'];
+
$MAP = new NagVisAutoMap($this->CORE, $MAPCFG, $BACKEND,
$this->opts, IS_VIEW);
$MAPOBJ = $MAP->MAPOBJ;
return $MAP->parseObjectsJson($aVals['ty']);
diff --git a/share/server/core/classes/GlobalMapCfg.php
b/share/server/core/classes/GlobalMapCfg.php
index 8db54e8..240e597 100644
--- a/share/server/core/classes/GlobalMapCfg.php
+++ b/share/server/core/classes/GlobalMapCfg.php
@@ -1789,7 +1789,7 @@ class GlobalMapCfg {
* @return String The object ID
* @author Lars Michelsen <[email protected]>
*/
- private function genObjId($s) {
+ protected function genObjId($s) {
return substr(sha1($s), 0, 6);
}
diff --git a/share/server/core/classes/NagVisAutoMap.php
b/share/server/core/classes/NagVisAutoMap.php
index c8bc748..3967971 100644
--- a/share/server/core/classes/NagVisAutoMap.php
+++ b/share/server/core/classes/NagVisAutoMap.php
@@ -43,6 +43,7 @@ class NagVisAutoMap extends GlobalMap {
private $ignoreHosts;
private $filterGroup;
private $filterByState;
+ private $filterByIds = null;
private $rootObject;
private $arrMapObjects;
@@ -54,6 +55,8 @@ class NagVisAutoMap extends GlobalMap {
private $graphvizPath;
private $noBinaryFound;
+
+ private $objIdFile;
/**
* Automap constructor
@@ -72,6 +75,7 @@ class NagVisAutoMap extends GlobalMap {
$this->arrHostnamesParsed = Array();
$this->mapCode = '';
+ $this->objIdFile = $CORE->getMainCfg()->getValue('paths',
'var').'automap.hostids';
$this->graphvizPath = '';
$this->noBinaryFound = false;
@@ -148,6 +152,9 @@ class NagVisAutoMap extends GlobalMap {
if(!isset($prop['filterByState']) || $prop['filterByState'] ==
'')
$prop['filterByState'] = '';
+ if(isset($prop['filterByIds']))
+ $this->filterByIds = $prop['filterByIds'];
+
// Store properties in object
$this->options = $prop;
@@ -175,6 +182,19 @@ class NagVisAutoMap extends GlobalMap {
$this->getParentObjectTree();
}
}
+
+ /**
+ * On automap updates not all objects are updated at once.
Filter
+ * the child tree by the given list of host object ids.
+ */
+ if($this->filterByIds) {
+ $names = $this->objIdsToNames($this->filterByIds);
+ $this->rootObject->filterChilds($names);
+
+ // Filter the parent object tree too when enabled
+ if(isset($this->parentLayers) && $this->parentLayers !=
0)
+ $this->rootObject->filterParents($names);
+ }
/**
* It is possible to filter the object tree by a hostgroup.
@@ -516,6 +536,44 @@ class NagVisAutoMap extends GlobalMap {
# END Public Methods
# #####################################################
+
+ /**
+ * Transforms a list of automap object_ids to hostnames using the
object_id
+ * translation file. Unknown object_ids are skipped
+ *
+ * @author Lars Michelsen <[email protected]>
+ */
+ private function objIdsToNames($ids) {
+ $names = Array();
+ $map = $this->loadObjIds();
+ foreach($ids AS $id) {
+ $name = array_search($id, $map);
+ if($name !== FALSE)
+ $names[] = $name;
+ }
+ return $names;
+ }
+
+ /**
+ * Loads the hostname to object_id mapping table from the central file
+ *
+ * @author Lars Michelsen <[email protected]>
+ */
+ private function loadObjIds() {
+ if($this->CORE->checkExisting($this->objIdFile, false))
+ return json_decode(file_get_contents($this->objIdFile),
true);
+ else
+ return Array();
+ }
+
+ /**
+ * Saves the given hostname to object_id mapping table in the central
file
+ *
+ * @author Lars Michelsen <[email protected]>
+ */
+ private function storeObjIds($a) {
+ return file_put_contents($this->objIdFile, json_encode($a)) !==
false;
+ }
private function loadObjectConfigurations() {
// Load the hosts from mapcfg into the aConf array
@@ -524,10 +582,23 @@ class NagVisAutoMap extends GlobalMap {
foreach($aHosts AS $aHost) {
$aConf[$aHost['host_name']] = $aHost;
}
-
- // Loop all map object
+
+ // And now load the stored object id (or get a new one)
+ $objIds = $this->loadObjIds();
+ $newObjId = false;
+
+ // Loop all map objects to load host individual configurations
and the uniqe
+ // object id
foreach(array_merge(Array($this->rootObject),
$this->arrMapObjects) AS $OBJ) {
$name = $OBJ->getName();
+
+ if(!isset($objIds[$name])) {
+ $objIds[$name] =
$this->MAPCFG->genObjIdAutomap($name);
+ $newObjId = true;
+ }
+
+ $OBJ->setObjectId($objIds[$name]);
+
// Try to find a matching object in the map
configuration
if(isset($aConf[$name])) {
unset($aConf[$name]['type']);
@@ -536,6 +607,9 @@ class NagVisAutoMap extends GlobalMap {
$OBJ->setConfiguration($aConf[$name]);
}
}
+
+ // When some new object ids have been added store them
+ $this->storeObjIds($objIds);
}
/**
@@ -750,7 +824,6 @@ class NagVisAutoMap extends GlobalMap {
private function fetchHostObjectByName($hostName) {
$hostObject = new NagVisHost($this->CORE, $this->BACKEND,
$this->backend_id, $hostName);
$hostObject->setConfiguration($this->MAPCFG->getObjectConfiguration());
- $hostObject->setObjectId(0);
$this->rootObject = $hostObject;
}
diff --git a/share/server/core/classes/NagVisAutomapCfg.php
b/share/server/core/classes/NagVisAutomapCfg.php
index 4803217..0e0c8b8 100644
--- a/share/server/core/classes/NagVisAutomapCfg.php
+++ b/share/server/core/classes/NagVisAutomapCfg.php
@@ -46,6 +46,10 @@ class NagVisAutomapCfg extends GlobalMapCfg {
// Start of the parent constructor
parent::__construct($CORE, $this->name);
+
+ // Modify must values -> coords don't need to be set
+ parent::$validConfig['host']['x']['must'] = 0;
+ parent::$validConfig['host']['y']['must'] = 0;
$this->type = 'automap';
@@ -93,6 +97,10 @@ class NagVisAutomapCfg extends GlobalMapCfg {
public function writeElement($id) { }
+ public function genObjIdAutomap($s) {
+ return $this->genObjId($s);
+ }
+
public function filterMapObjects($a) {
if(isset($this->mapConfig[2])) {
$global = $this->mapConfig[0];
diff --git a/share/server/core/classes/objects/NagiosHost.php
b/share/server/core/classes/objects/NagiosHost.php
index 449594e..f51d96d 100644
--- a/share/server/core/classes/objects/NagiosHost.php
+++ b/share/server/core/classes/objects/NagiosHost.php
@@ -466,10 +466,6 @@ class NagiosHost extends NagVisStatefulObject {
$OBJ->setConfiguration($objConf);
$OBJ->fetchIcon();
- // The number of objects on the map
controlls the object id to take
- // 0 is reserved for the root host
-
$OBJ->setObjectId(count($arrHostnames)+1);
-
// Append the object to the
parentObjects array
$this->parentObjects[] = $OBJ;
@@ -522,10 +518,6 @@ class NagiosHost extends NagVisStatefulObject {
$OBJ->setConfiguration($objConf);
$OBJ->fetchIcon();
- // The number of objects on the map
controlls the object id to take
- // 0 is reserved for the root host
-
$OBJ->setObjectId(count($arrHostnames)+1);
-
// Append the object to the
childObjects array
$this->childObjects[] = $OBJ;
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins