]> Frank Brehm's Git Trees - my-stuff/nagios.git/commitdiff
Objekteigenschaft ignore_empty_object_props dazu
authorFrank Brehm <frank@brehm-online.com>
Sun, 5 Dec 2010 09:51:09 +0000 (09:51 +0000)
committerFrank Brehm <frank@brehm-online.com>
Sun, 5 Dec 2010 09:51:09 +0000 (09:51 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/nagios/trunk@142 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

bin/nagios/cfg/struct.py
bin/nagios/config.py

index cdf14018ed1ab78c88a2af6f67aaf6938c075fa4..a019bb1c5e669a018512ed37e4861f5d9277d0a2 100755 (executable)
@@ -25,7 +25,7 @@ class NagiosConfigStruct(object):
         return repr(dump)
 
     #------------------------------------------------------
-    def __init__( self, logger = None ):
+    def __init__( self, logger = None, , ignore_empty_object_props = True ):
         "Constructor."
 
         # Logging-Setup
@@ -45,6 +45,8 @@ class NagiosConfigStruct(object):
         else:
             self.logger = logger
 
+        self.ignore_empty_object_props = ignore_empty_object_props
+
     #------------------------------------------------------
     def __del__( self ):
         "Destructor"
@@ -140,13 +142,17 @@ class NagiosConfigStruct(object):
                 return result
 
         # Split line into key and value
-        match = re.search( r'^\s*(\w+)\s+(.*)', line )
+        match = re.search( r'^\s*(\w+)(?:\s+(.*))?', line )
         if match is None:
             raise NagiosConfigStructError( "Couldn't evaluate line {0!r}.".format( line ) )
 
         key = match.group(1)
         value = match.group(2)
 
+        if value is None:
+            if not self.ignore_empty_object_props:
+                raise NagiosConfigStructError( "No value given for key {0!r}.".format( key ) )
+
         # User defined definitions
         if re.match( r'^_', key ):
             key_upper = key.upper()
index ee1ca9c4d2fe261aa4a3636d84f383f5361412ac..03ce50644c29e879eab4e5e5a9aac1ae3014d8cf 100644 (file)
@@ -52,7 +52,7 @@ class NagiosConfig(object):
         return repr(dump)
 
     #------------------------------------------------------
-    def __init__( self, new_file = file_name ):
+    def __init__( self, new_file = file_name, ignore_empty_object_props = True ):
         "Konstruktor."
 
         # Logging-Setup
@@ -72,6 +72,7 @@ class NagiosConfig(object):
         self.objects = {}
         self.config_objects = {}
         self.objects_read = {}
+        self.ignore_empty_object_props = ignore_empty_object_props
 
     #------------------------------------------------------
     def __del__( self ):