[omd-commits] OMD Git: omd: nagvis: NagVis external urls point to the DEFAULT_GUI urls now by default

git version control git at mathias-kettner.de
Fri Jul 8 11:25:17 CEST 2011


Module:   omd
Branch:   master
Commit:   7afb805596c7a73647d723b70439d7fd4f555300
URL:      http://omdistro.org/projects/omd/repository/revisions/7afb805596c7a73647d723b70439d7fd4f555300

Author:   Lars Michelsen <lm at mathias-kettner.de>
Date:     Fri Jul  8 11:25:09 2011 +0200
Commiter: Lars Michelsen <lm at mathias-kettner.de>
Date:     Fri Jul  8 11:25:09 2011 +0200

nagvis: NagVis external urls point to the DEFAULT_GUI urls now by default

---

 packages/nagvis/NAGVIS_URLS.hook |  117 ++++++++++++++++++++++++++++++++++++++
 packages/omd/DEFAULT_GUI.hook    |    7 ++
 2 files changed, 124 insertions(+), 0 deletions(-)

diff --git a/packages/nagvis/NAGVIS_URLS.hook b/packages/nagvis/NAGVIS_URLS.hook
new file mode 100755
index 0000000..f77590b
--- /dev/null
+++ b/packages/nagvis/NAGVIS_URLS.hook
@@ -0,0 +1,117 @@
+#!/bin/bash
+
+# Alias: NagVis linked Web GUI
+# Menu: Addons
+# Description: 
+#  When clicking on NagVis map icons the user is redirected to another
+#  Web-GUI. By default this is the classic Nagios webinterface. With
+#  this switch the targeted Web-GUI can be changed.
+
+# Makes it possible to switch all the links from NagVis 
+# to the default Web GUI to the choosen GUI or a defined
+# other one.
+#
+# Idea: Default mode is "auto". In this mode the HOOK
+# checks the current configuration for the default
+# web gui and sets the NagVis links to point to it.
+# It is also possible to force the other Web GUIs instead
+# of "auto".
+# Another option is "none". In this case OMD configures
+# nothing and NagVis uses the hard coded optionsa
+
+case "$1" in
+    default)
+        echo "auto"
+    ;;
+    choices)
+        echo "auto: Use the default Web-GUI"
+        echo "nagios: Classic Nagios webinterface"
+        echo "check_mk: The Check_MK's Multisite GUI"
+        echo "thruk: Thruk Monitoring Webinterface"
+        echo "none: disable"
+    ;;
+    set)
+        GUI=$2
+        if [ "$2" == "auto" ] && [ "$CONFIG_DEFAULT_GUI" != "welcome" ] && [ "$CONFIG_DEFAULT_GUI" != "nagvis" ]; then
+            GUI=$CONFIG_DEFAULT_GUI
+        fi
+        
+        if [ "$GUI" == "check_mk" ]; then
+            HTMLCGI="/$OMD_SITE/check_mk"
+            HOSTURL="[htmlcgi]/view.py?view_name=host&site=&host=[host_name]"
+            SERVICEURL="[htmlcgi]/view.py?view_name=service&site=&host=[host_name]&service=[service_description]"
+            HOSTGROUPURL="[htmlcgi]/view.py?view_name=hostgroup&site=&hostgroup=[hostgroup_name]"
+            SERVICEGROUPURL="[htmlcgi]/view.py?view_name=servicegroup&site=&servicegroup=[servicegroup_name]"
+        else
+            HTMLCGI="/$OMD_SITE/$GUI/cgi-bin"
+            HOSTURL="[htmlcgi]/status.cgi?host=[host_name]"
+            HOSTGROUPURL="[htmlcgi]/status.cgi?hostgroup=[hostgroup_name]"
+            SERVICEURL="[htmlcgi]/extinfo.cgi?type=2&host=[host_name]&service=[service_description]"
+            SERVICEGROUPURL="[htmlcgi]/status.cgi?servicegroup=[servicegroup_name]&style=detail"
+        fi
+        
+        # Now update the NagVis configuration. It needs to be written to the [defaults] section in nagvis.ini.php.
+        # Following cases:
+        # - Commented out nagios urls
+        # - Uncommented nagios urls
+        # - Custom urls commented out and not commented out
+        # - Not present options
+        # - And also not present sections
+        #
+        # Second part: Replace or add the htmlcgi value in [paths]
+        python <<EOF
+cfg = file('$OMD_ROOT/etc/nagvis/nagvis.ini.php').readlines()
+todo = [ 'host', 'hostgroup', 'service', 'servicegroup', 'htmlcgi' ]
+urls = {
+    'host':         "$HOSTURL",
+    'hostgroup':    "$HOSTGROUPURL",
+    'service':      "$SERVICEURL",
+    'servicegroup': "$SERVICEGROUPURL",
+}
+inDefaults = False
+inPaths  = False
+for num, l in enumerate(cfg):
+    l = l.strip()
+    if l == '[defaults]':
+        inDefaults = True
+    elif l == '[paths]':
+        inPaths = True
+    elif not l or l[0] == '[' and l[-1] == ']':
+        # Other sections terminate the paths,defaults sections
+
+        # Need to add attributes which have not been replaced?
+        if inPaths and 'htmlcgi' in todo:                    
+            cfg.insert(num, 'htmlcgi="$HTMLCGI"\n')
+            if 'htmlcgi' in todo:
+                todo.remove('htmlcgi')
+        elif inDefaults:
+            for ty in [ 'host', 'hostgroup', 'service', 'servicegroup' ]:
+                if ty in todo:
+                    cfg.insert(num, '%surl="%s"\n' % (ty, urls[ty]))
+                    if ty in todo:
+                        todo.remove(ty)
+
+        inDefaults = False
+        inPaths  = False
+    elif inDefaults:
+        for ty in [ 'host', 'hostgroup', 'service', 'servicegroup' ]:
+            if '%surl=' % ty in l:
+                cfg[num] = '%surl="%s"\n' % (ty, urls[ty])
+                if ty in todo:
+                    todo.remove(ty)
+    elif inPaths:
+        if 'htmlcgi=' in l:
+            cfg[num] = 'htmlcgi="$HTMLCGI"\n'
+            if 'htmlcgi' in todo:
+                todo.remove('htmlcgi')
+
+# Section was missing
+if 'htmlcgi' in todo:
+    cfg += [ '\n', '[paths]\n', 'htmlcgi="$HTMLCGI"\n' ]
+
+file('$OMD_ROOT/etc/nagvis/nagvis.ini.php', 'w').write(''.join(cfg))
+EOF
+        
+    ;;
+
+esac
diff --git a/packages/omd/DEFAULT_GUI.hook b/packages/omd/DEFAULT_GUI.hook
index bf3ceeb..b17c323 100755
--- a/packages/omd/DEFAULT_GUI.hook
+++ b/packages/omd/DEFAULT_GUI.hook
@@ -19,6 +19,13 @@ case "$1" in
             echo "nagvis: NagVis - The visualisation addon for Nagios"
             echo "none: No default webinterface"
     ;;
+    set)
+            # This is some sort of hack. The problem here:
+            # The NAGVIS_URL hook depends on this hooks value but is not
+            # executed when this hook is changed. It would be better to
+            # solve this in a more general way in omd.
+            omd config set NAGVIS_URLS $2 >/dev/null 2>&1
+    ;;
     depends)
         [ "$CONFIG_APACHE_MODE" != none ]
     ;;



More information about the omd-commits mailing list