]> Frank Brehm's Git Trees - my-stuff/nagios.git/commitdiff
bischen weiter ...
authorFrank Brehm <frank@brehm-online.com>
Sun, 21 Nov 2010 08:43:03 +0000 (08:43 +0000)
committerFrank Brehm <frank@brehm-online.com>
Sun, 21 Nov 2010 08:43:03 +0000 (08:43 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/nagios/trunk@125 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

bin/nagios/__init__.pyc [deleted file]
bin/nagios/config.py
bin/nagios/object/__init__.pyc [deleted file]
bin/nagios/object/host.py
bin/nagios/object/host.pyc [deleted file]
bin/nagios/object/verify.py [new file with mode: 0644]

diff --git a/bin/nagios/__init__.pyc b/bin/nagios/__init__.pyc
deleted file mode 100644 (file)
index c9f7b03..0000000
Binary files a/bin/nagios/__init__.pyc and /dev/null differ
index 9db8a4c3e4869ad0b0c95595d31f6b57e742473f..599a7c995ee6114aab407f5eba6e9f89d4ae3202 100644 (file)
@@ -1,6 +1,9 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
+# $Id: $
+# $URL: $
+
 import os
 import re
 import sys
diff --git a/bin/nagios/object/__init__.pyc b/bin/nagios/object/__init__.pyc
deleted file mode 100644 (file)
index e210bd7..0000000
Binary files a/bin/nagios/object/__init__.pyc and /dev/null differ
index a5f5846bd67841416f809c688808f4903591878d..2706880172845931d38832144a059ae5f2fc350e 100644 (file)
@@ -1,10 +1,16 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
+# $Id: $
+# $URL: $
+
 import re
 
+from nagios.object.verify import NagiosVerifyError, verify_object_property
+
+#-----------------------------------------------------------------------
 def verfify( definition, logger )
-"Verifiziert einen übergebenen Definitionsblock als Nagios-Host."
+    "Verifiziert einen übergebenen Definitionsblock als Nagios-Host."
 
     res = {}
     identifier = None
@@ -73,17 +79,17 @@ define host{
             logger.warn( "Ungültige Eigenschaft {0!r} für Hostdefinition in {1}({2}).".format(
                 key, definition[key][1], definition[key][2] )
 
-    if 'host_name' in definition:
-        identifier = definition['host_name'][0]
-        res['host_name'] = definition['host_name'][0]
-    else
-        logger.warn( "Kein Hostname in Hostdefinition gegeben." )
-
     # Einfache String-Eigenschaften
-    for key in ( 'alias', 'address', 'display_name', 'check_period', 'event_handler', 'notification_period',
+    for key in ( 'host_name', 'alias', 'address', 'display_name', 'check_period', 'event_handler', 'notification_period',
                  'notes', 'notes_url', 'action_url', 'icon_image', 'icon_image_alt', 'vrml_image', 'statusmap_image' ):
         if key in definition:
-            res[key] = definition[key][0]
+            try:
+                if key in res:
+                    logger.warn( "Double entry {0} for host definition in {1}({2}).".format( key, definition[key][1], definition[key][2] )
+                else:
+                    res[key] = verify_object_property( definition[key][0], 'string' )
+            except NagiosVerifyError as e:
+                logger.warn( "Property error for host definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e )  )
 
     # Array-String-Eigenschaften
     for key in ( 'parents', 'hostgroups', 'contacts', 'contact_groups' ):
diff --git a/bin/nagios/object/host.pyc b/bin/nagios/object/host.pyc
deleted file mode 100644 (file)
index ef9b2bc..0000000
Binary files a/bin/nagios/object/host.pyc and /dev/null differ
diff --git a/bin/nagios/object/verify.py b/bin/nagios/object/verify.py
new file mode 100644 (file)
index 0000000..cec786a
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# $Id: $
+# $URL: $
+
+import re
+
+#-----------------------------------------------------------------------
+class NagiosVerifyError(Exception):
+    """Base class for exceptions in this module."""
+    pass
+
+#-----------------------------------------------------------------------
+def verify_object_property( definition, type, args = None ):
+    "Verifiziert den Wert einer übergebenen Objekteigenschaft."
+
+    if definition is None:
+        raise NagiosVerifyError( "Undefined property given." )
+
+    definition = re.sub( r'^\s+', '', definition, 0 )
+    definition = re.sub( r'\s+$', '', definition, 0 )
+
+    if type == "string":
+        return verify_string_property( definition, args )
+
+#-----------------------------------------------------------------------
+def verify_string_property( definition, args = None ):
+    "Verifiziert den Wert als einfachen String"
+
+    if args is None:
+        args = dict()
+
+    if definition == '':
+        if not 'empty_ok' in args:
+            raise NagiosVerifyError( "Empty property is not allowed." )
+
+    return definition
+    
+
+# vim: fileencoding=utf-8 filetype=python ts=4 expandtab