From 04c7c117fc410d99fc1c7e4a76141028bfc4b405 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Sun, 12 Dec 2010 22:13:21 +0000 Subject: [PATCH] Umgestaltung angefangen git-svn-id: http://svn.brehm-online.com/svn/my-stuff/nagios/trunk@151 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- bin/nagios/cfg/struct.py | 46 ++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/bin/nagios/cfg/struct.py b/bin/nagios/cfg/struct.py index 396ffc8..a7770f5 100755 --- a/bin/nagios/cfg/struct.py +++ b/bin/nagios/cfg/struct.py @@ -209,22 +209,22 @@ Returns None if the key is invalid.""" key_def = { 'host': { - 'host_name': ( 'string', None ), - 'alias': ( 'string', None ), + 'host_name': ( 'string', { 'mandantory': True } ), + 'alias': ( 'string', { 'mandantory': True } ), 'display_name': ( 'string', None ), - 'address': ( 'string', None ), + 'address': ( 'string', { 'mandantory': True } ), 'parents': ( 'array', None ), 'hostgroups': ( 'array', None ), 'check_command': ( 'string', None ), 'initial_state': ( 'set', { 'valid_values': set( [ 'o', 'd', 'u' ] ) } ), - 'max_check_attempts': ( 'int', None ), + 'max_check_attempts': ( 'int', { 'mandantory': True } ), 'check_interval': ( 'int', None ), 'retry_interval': ( 'int', None ), 'normal_check_interval': ( 'int', { 'deprecated': True, } ), 'retry_check_interval': ( 'int', { 'deprecated': True, } ), 'active_checks_enabled': ( 'bool', None ), 'passive_checks_enabled': ( 'bool', None ), - 'check_period': ( 'string', None ), + 'check_period': ( 'string', { 'mandantory': True } ), 'failure_prediction_enabled': ( 'bool', None ), 'obsess_over_host': ( 'bool', None ), 'check_freshness': ( 'bool', None ), @@ -238,11 +238,11 @@ Returns None if the key is invalid.""" 'process_perf_data': ( 'bool', None ), 'retain_status_information': ( 'bool', None ), 'retain_nonstatus_information': ( 'bool', None ), - 'contacts': ( 'array', None ), - 'contact_groups': ( 'array', None ), - 'notification_interval': ( 'int', None ), + 'contacts': ( 'array', { 'mandantory': True } ), + 'contact_groups': ( 'array', { 'mandantory': True } ), + 'notification_interval': ( 'int', { 'mandantory': True } ), 'first_notification_delay': ( 'int', None ), - 'notification_period': ( 'string', None ), + 'notification_period': ( 'string', { 'mandantory': True } ), 'notification_options': ( 'set', { 'valid_values': set( [ 'd', 'u', 'r', 'f', 's' ] ) } ), 'notifications_enabled': ( 'bool', None ), 'stalking_options': ( 'set', { 'valid_values': set( [ 'o', 'd', 'u' ] ) } ), @@ -429,7 +429,19 @@ Returns None if the key is invalid.""" if key not in key_def[object_type]: return None - return key_def[object_type][key] + test_type = key_def[object_type][key][0] + test_args = key_def[object_type][key][1] + + if test_args is None: + test_args = {} + + if not 'deprecated' in test_args: + test_args['deprecated'] = False + + if not 'mandantory' in test_args: + test_args['mandantory'] = False + + return ( test_type, test_args ) #------------------------------------------------------ def check_timeperiod_line_syntax( self, line ): @@ -447,12 +459,14 @@ returns None on failure""" re_timeranges = r'(' + re_timerange + r')(?:,(' + re_timerange + r'))*' re_weekdays = r'(monday|tuesday|wednesday|thursday|friday|saturday|sunday)' re_isodate = r'(\d\d\d\d)-(0[1-9]|1[0-2])-([0-2][1-9]|3[01])' + re_monthname = r'(january|ferbruary|march|april|may|june|july|august|september|october|november|december)' pp = pprint.PrettyPrinter( indent = 4, depth = 6, width = 120 ) # first search for a simple weekday regex = r'^' + re_weekdays + r'\s+' + re_timeranges + r'$' - #self.logger.debug( "Timeperiod Regex {0!r}.\n\t{1!r}".format( regex, line ) ) + if self.verbose >= 4: + self.logger.debug( "Timeperiod Regex {0!r}.\n\t{1!r}".format( regex, line ) ) match = re.search( regex, line ) if match is not None: @@ -463,8 +477,9 @@ returns None on failure""" return ( key, value ) # Now search single ISO formatted date or a range of two ISO formatted dates - regex = r'^' + re_isodate + r'(?:\s*-\s*' + re_isodate + r')?\s+' + re_timeranges + r'$' - self.logger.debug( "Timeperiod Regex {0!r}.\n\t{1!r}".format( regex, line ) ) + regex = r'^' + re_isodate + r'(?:\s*-\s*' + re_isodate + r')?(?:\s*/\s*(\d+))\s+' + re_timeranges + r'$' + if self.verbose >= 3: + self.logger.debug( "Timeperiod Regex {0!r}.\n\t{1!r}".format( regex, line ) ) match = re.search( regex, line ) if match is not None: @@ -500,9 +515,12 @@ returns None on failure""" key = key + ' - ' + date_end.isoformat() + if match.group(7) is not None: + key = key + ' / ' + match.group(7) + # Formatting the value ... value = [] - for v in match.groups()[6:-1]: + for v in match.groups()[7:-1]: value.append(v) return ( key, value ) -- 2.39.5