[icinga-checkins] icinga.org: icinga-web/mhein/default: * added additional host info to status map

git at icinga.org git at icinga.org
Thu Oct 8 13:45:23 CEST 2009


Module: icinga-web
Branch: mhein/default
Commit: 6ebf2604286cae79677f5bcf426b1018cf8fc86c
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=6ebf2604286cae79677f5bcf426b1018cf8fc86c

Author: Christian Doebler <christian.doebler at netways.de>
Date:   Tue Oct  6 12:47:36 2009 +0200

* added additional host info to status map
* restructured status-map js

---

 .../Cronks/models/System/StatusMapModel.class.php  |   31 +++-
 .../Cronks/templates/System/StatusMapSuccess.php   |  198 ++++++++-----------
 2 files changed, 106 insertions(+), 123 deletions(-)

diff --git a/app/modules/Cronks/models/System/StatusMapModel.class.php b/app/modules/Cronks/models/System/StatusMapModel.class.php
index e14b09f..f843ef1 100644
--- a/app/modules/Cronks/models/System/StatusMapModel.class.php
+++ b/app/modules/Cronks/models/System/StatusMapModel.class.php
@@ -81,14 +81,29 @@ class Cronks_System_StatusMapModel extends ICINGACronksBaseModel
 			}
 		}
 
-		$hostsFlat = array(
-			'id'		=> '-1',
-			'name'		=> 'Icinga',
-			'data'		=> array(
-				'relation'	=> 'Icinga Monitoring Process',
-			),
-			'children'	=> $this->flattenStructure($hosts)
-		);
+		$hostsFlatStruct = $this->flattenStructure($hosts);
+
+		if (count($hostsFlatStruct) == 1) {
+			$hostsFlat = $hostsFlatStruct;
+			$icingaProc = array(
+				'id'		=> '-1',
+				'name'		=> 'Icinga',
+				'data'		=> array(
+					'relation'	=> 'Icinga Monitoring Process',
+				),
+				'children'	=> array(),
+			);
+			array_push($hostsFlat[0]['children'], $icingaProc);
+		} else {
+			$hostsFlat = array(
+				'id'		=> '-1',
+				'name'		=> 'Icinga',
+				'data'		=> array(
+					'relation'	=> 'Icinga Monitoring Process',
+				),
+				'children'	=> $hostsFlatStruct,
+			);
+		}
 
 		return $hostsFlat;
 
diff --git a/app/modules/Cronks/templates/System/StatusMapSuccess.php b/app/modules/Cronks/templates/System/StatusMapSuccess.php
index 757dacd..ad92dad 100644
--- a/app/modules/Cronks/templates/System/StatusMapSuccess.php
+++ b/app/modules/Cronks/templates/System/StatusMapSuccess.php
@@ -13,124 +13,23 @@
 	<div id="jitLog"></div>
 </div>
 <script type="text/javascript">
-	var JitLog = {
-	    elem: false,
-	    write: function(text){
-	        if (!this.elem) 
-	            this.elem = document.getElementById("jitLog");
-	        this.elem.innerHTML = text;
-	        this.elem.style.left = (500 - this.elem.offsetWidth / 2) + "px";
-	    }
-	};
-
 	function jitAddEvent(obj, type, fn) {
-	    if (obj.addEventListener) obj.addEventListener(type, fn, false);
-	    else obj.attachEvent("on" + type, fn);
+		if (obj.addEventListener) {
+			obj.addEventListener(type, fn, false);
+		} else {
+			obj.attachEvent("on" + type, fn);
+		}
 	};
 
-
-	function jitInit(json){
-	    //init data
-	    //var json = {};
-	    //end
-	    
-	    var infovis = document.getElementById("jitMap");
-	    var w = infovis.offsetWidth, h = infovis.offsetHeight;
-	    
-	    //init canvas
-	    //Create a new canvas instance.
-	    var canvas = new Canvas("mycanvas", {
-	        //Where to append the canvas widget
-	        "injectInto": "jitMap",
-	        "width": w,
-	        "height": h,
-	        
-	        //Optional: create a background canvas and plot
-	        //concentric circles in it.
-	        "backgroundCanvas": {
-	            "styles": {
-	                "strokeStyle": "#e0e0e0"
-	            },
-	            
-	            "impl": {
-	                "init": function(){},
-	                "plot": function(canvas, ctx){
-	                    var times = 6, d = 100;
-	                    var pi2 = Math.PI * 2;
-	                    for (var i = 1; i <= times; i++) {
-	                        ctx.beginPath();
-	                        ctx.arc(0, 0, i * d, 0, pi2, true);
-	                        ctx.stroke();
-	                        ctx.closePath();
-	                    }
-	                }
-	            }
-	        }
-	    });
-	    //end
-	    //init RGraph
-	    var rgraph = new RGraph(canvas, {
-	        //Set Node and Edge colors.
-	        Node: {
-	            color: "#ccddee"
-	        },
-	        Edge: {
-	            color: "#56A5EC"
-	        },
-	        onBeforeCompute: function(node){
-	            JitLog.write("centering " + node.name + "...");
-	            //Add the relation list in the right column.
-	            //This list is taken from the data property of each JSON node.
-	            document.getElementById("jitDetails").innerHTML = node.data.relation;
-	        },
-	        
-	        onAfterCompute: function(){
-	            JitLog.write("done");
-	        },
-	        //Add the name of the node in the correponding label
-	        //and a click handler to move the graph.
-	        //This method is called once, on label creation.
-	        onCreateLabel: function(domElement, node){
-	            domElement.innerHTML = node.name;
-	            domElement.onclick = function(){
-	                rgraph.onClick(node.id);
-	            };
-	        },
-	        //Change some label dom properties.
-	        //This method is called each time a label is plotted.
-	        onPlaceLabel: function(domElement, node){
-	            var style = domElement.style;
-	            style.display = "";
-	            style.cursor = "pointer";
-
-	            if (node._depth <= 1) {
-	                style.fontSize = "1em";
-	                style.color = "#000000";
-	            
-	            } else if(node._depth == 2){
-	                style.fontSize = "0.9em";
-	                style.color = "#505050";
-	            
-	            } else {
-	                style.display = "none";
-	            }
-
-	            var left = parseInt(style.left);
-	            var w = domElement.offsetWidth;
-	            style.left = (left - w / 2) + "px";
-	        }
-	    });
-	    
-	    //load JSON data
-	    rgraph.loadJSON(json);
-	    //compute positions and make the first plot
-	    rgraph.refresh();
-	    //end
-	    //append information about the root relations in the right column
-	    document.getElementById("jitDetails").innerHTML = rgraph.graph.getNode(rgraph.root).data.relation;
-	}
-
-	//jitInit("/web/cronks/statusMap/json");
+	var JitLog = {
+		elem: false,
+		write: function(text) {
+			if (!this.elem) 
+				this.elem = document.getElementById("jitLog");
+				this.elem.innerHTML = text;
+				this.elem.style.left = (500 - this.elem.offsetWidth / 2) + "px";
+			}
+	};
 
 	function JitStatusMap (config) {
 
@@ -146,6 +45,75 @@
 
 		this.jitJson = false;
 
+		function jitInit (json) {
+			var infovis = document.getElementById("jitMap");
+			var w = infovis.offsetWidth, h = infovis.offsetHeight;
+			var canvas = new Canvas("mycanvas", {
+				"injectInto": "jitMap",
+				"width": w,
+				"height": h,
+				"backgroundCanvas": {
+					"styles": {
+						"strokeStyle": "#e0e0e0"
+					},
+					"impl": {
+						"init": function() {},
+						"plot": function(canvas, ctx) {
+							var times = 6, d = 100;
+							var pi2 = Math.PI * 2;
+							for (var i = 1; i <= times; i++) {
+								ctx.beginPath();
+								ctx.arc(0, 0, i * d, 0, pi2, true);
+								ctx.stroke();
+								ctx.closePath();
+							}
+						}
+					}
+				}
+			});
+			var rgraph = new RGraph(canvas, {
+				Node: {
+					color: "#ccddee"
+				},
+				Edge: {
+					color: "#56A5EC"
+				},
+				onBeforeCompute: function(node){
+					JitLog.write("centering " + node.name + "...");
+					document.getElementById("jitDetails").innerHTML = node.data.relation;
+				},
+				onAfterCompute: function(){
+					JitLog.write("done");
+				},
+				onCreateLabel: function(domElement, node){
+					domElement.innerHTML = node.name;
+					domElement.onclick = function(){
+						rgraph.onClick(node.id);
+					};
+				},
+				onPlaceLabel: function(domElement, node){
+					var style = domElement.style;
+					style.display = "";
+					style.cursor = "pointer";
+					if (node._depth <= 1) {
+						style.fontSize = "1em";
+						style.color = "#000000";
+					} else if(node._depth == 2){
+						style.fontSize = "0.9em";
+						style.color = "#505050";
+					} else {
+						style.display = "none";
+					}
+					var left = parseInt(style.left);
+					var w = domElement.offsetWidth;
+					style.left = (left - w / 2) + "px";
+				}
+			});
+			rgraph.loadJSON(json);
+			rgraph.refresh();
+			document.getElementById("jitDetails").innerHTML = rgraph.graph.getNode(rgraph.root).data.relation;
+		}
+
 		this.init = function (config) {
 			this.setConfig(config);
 			this.getMapData();





More information about the icinga-checkins mailing list