From b919f246b433c4662ab50dd7819647e5e6b623d2 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Sun, 21 Nov 2010 23:25:54 +0000 Subject: [PATCH] Weitergemacht git-svn-id: http://svn.brehm-online.com/svn/my-stuff/nagios/trunk@130 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- bin/nagios/object/host.py | 48 +++++++++++++++++++++---------------- bin/nagios/object/verify.py | 16 +++++++++++++ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/bin/nagios/object/host.py b/bin/nagios/object/host.py index d61af16..03bda98 100644 --- a/bin/nagios/object/host.py +++ b/bin/nagios/object/host.py @@ -115,29 +115,37 @@ define host{ for key in ( 'initial_state', 'flap_detection_options', 'stalking_options' ): if key in definition: - array = re.split( r',+', definition[key][0] ) - for value in array: - 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: - args = dict( file = definition[key][1], row = definition[key][2], valid_values = set( [ 'o', 'd', 'u' ] ) ) - res[key] = verifier.verify_property( definition[key][0], 'set', args ) - except NagiosVerifyError as e: - logger.warn( "Property error for host definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) ) + 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: + args = dict( file = definition[key][1], row = definition[key][2], valid_values = set( [ 'o', 'd', 'u' ] ) ) + res[key] = verifier.verify_property( definition[key][0], 'set', args ) + except NagiosVerifyError as e: + logger.warn( "Property error for host definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) ) for key in ( 'notification_options' ): if key in definition: - array = re.split( r',+', definition[key][0] ) - for value in array: - 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: - args = dict( file = definition[key][1], row = definition[key][2], valid_values = set( [ 'r', 'd', 'u', 'f', 's' ] ) ) - res[key] = verifier.verify_property( definition[key][0], 'set', args ) - except NagiosVerifyError as e: - logger.warn( "Property error for host definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) ) + 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: + args = dict( file = definition[key][1], row = definition[key][2], valid_values = set( [ 'r', 'd', 'u', 'f', 's' ] ) ) + res[key] = verifier.verify_property( definition[key][0], 'set', args ) + except NagiosVerifyError as e: + logger.warn( "Property error for host definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) ) + + for key in ( 'max_check_attempts', 'check_interval', 'retry_interval', 'freshness_threshold', 'low_flap_threshold', + 'high_flap_threshold', 'notification_interval', 'first_notification_delay', ): + if key in definition: + 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: + args = dict( file = definition[key][1], row = definition[key][2] ) + res[key] = verifier.verify_property( definition[key][0], 'int', args ) + except NagiosVerifyError as e: + logger.warn( "Property error for host definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) ) if 'host_name' in res: identifier = res['host_name'] diff --git a/bin/nagios/object/verify.py b/bin/nagios/object/verify.py index 220435d..0702b33 100644 --- a/bin/nagios/object/verify.py +++ b/bin/nagios/object/verify.py @@ -55,6 +55,8 @@ Returns the verified structure or raises an NagiosVerifyError. return self.verify_array_property( definition, args ) elif type == "set": return self.verify_set_property( definition, args ) + elif type == "int": + return self.verify_int_property( definition, args ) raise NagiosVerifyError( "Unknown property type {0!r} given.".format( type ) ) @@ -118,6 +120,20 @@ Raises a NagiosVerifyError unless args['empty_ok'] is given. return res + #------------------------------------------------------ + def verify_int_property( self, definition, args = None ): + + if args is None: + args = dict() + + match = re.match( r'^(\d+)$', definition ) + if match is None: + raise NagiosVerifyError( "Not a integer value in {0!r}({1}): {2!r}".format( args['file'], args['row'], definition ) ) + + val = int( match.group(1) ) + + return val + #----------------------------------------------------------------------- # vim: fileencoding=utf-8 filetype=python ts=4 expandtab -- 2.39.5