From: Frank Brehm Date: Sun, 5 Dec 2010 13:08:15 +0000 (+0000) Subject: Mit Parsen timeperiods angefangen X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=9b5d2d6fcb694c827a2fc41f3ece25a1dd6bce2b;p=my-stuff%2Fnagios.git Mit Parsen timeperiods angefangen git-svn-id: http://svn.brehm-online.com/svn/my-stuff/nagios/trunk@144 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- diff --git a/bin/nagios/cfg/struct.py b/bin/nagios/cfg/struct.py index 4565ce2..4ae3549 100755 --- a/bin/nagios/cfg/struct.py +++ b/bin/nagios/cfg/struct.py @@ -6,6 +6,7 @@ import os import re +import pprint from nagios.object.verify import NagiosVerifyError, NagiosObjectVerifier @@ -437,6 +438,29 @@ Returns None if the key is invalid.""" returns a key/value pair on success, returns None on failure""" + for key in ( 'timeperiod_name', 'alias', 'exclude', 'name', 'register', 'use' ): + match = re.match( r'^' + key + r'\s+', line ) + if match is not None: + return None + + re_time = r'(?:(?:(?:[01][0-9]|2[0-3]):[0-5][0-9])|24:00)' + re_timerange = re_time + r'\s*-\s*' + re_time + re_timeranges = r'(' + re_timerange + r')(?:,(' + re_timerange + r'))*' + re_weekdays = r'(monday|tuesday|wednesday|thursday|friday|saturday|sunday)' + + regex = r'^' + re_weekdays + r'\s+' + re_timeranges + r'$' + #self.logger.debug( "Timeperiod Regex {0!r}.\n\t{1!r}".format( regex, line ) ) + + match = re.search( regex, line ) + if match is not None: + + pp = pprint.PrettyPrinter( indent = 4, depth = 6, width = 120 ) + key = match.group(1) + value = [] + for v in match.groups()[1:-1]: + value.append(v) + return ( key, value ) + # Currently only a stub return None