From: Frank Brehm Date: Sun, 21 Nov 2010 18:25:12 +0000 (+0000) Subject: Bugfixing, Debug-Ausgabe mit pprint X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=9ab3a1823a011c4ad0a94c6f58d84a86b97f6a84;p=my-stuff%2Fnagios.git Bugfixing, Debug-Ausgabe mit pprint git-svn-id: http://svn.brehm-online.com/svn/my-stuff/nagios/trunk@128 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- diff --git a/bin/check_nagios_config.py b/bin/check_nagios_config.py index dc73f39..070da81 100755 --- a/bin/check_nagios_config.py +++ b/bin/check_nagios_config.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import sys +import pprint from nagios.config import NagiosConfig, NagiosConfigError #print "Modul-Suchpfade:" @@ -23,7 +24,7 @@ except NagiosConfigError as e: #print "Nagios-Objekt: " + repr( nagios_conf ) -print nagios_conf.dump_config() +#print nagios_conf.dump_config() nagios_conf.read_objects() # vim: fileencoding=utf-8 filetype=python ts=4 expandtab diff --git a/bin/nagios/config.py b/bin/nagios/config.py index 0583a48..4130d12 100644 --- a/bin/nagios/config.py +++ b/bin/nagios/config.py @@ -9,6 +9,7 @@ import re import sys import warnings import logging +import pprint import nagios.object.host class NagiosConfigError(Exception): @@ -247,7 +248,9 @@ class NagiosConfig(object): for file_name in files: self.read_objectfile(file_name) - self.logger.debug( "Gelesene Objekte: {0!r}".format( self.objects ) ) + #self.logger.debug( "Gelesene Objekte: {0!r}".format( self.objects ) ) + pp = pprint.PrettyPrinter( indent = 4, depth = 6, width = 120 ) + self.logger.debug( "Gelesene Objekte: {0}".format( pp.pformat( self.objects ) ) ) return @@ -298,9 +301,9 @@ class NagiosConfig(object): self.logger.debug( "Gefunden: key: {0!r}, value: {1!r}".format( key, value ) ) if key in cur_object: self.logger.warn( "Doppelter Eintrag für Eigenschaft {0!r} von {1!r} in {2}({3}).".format( - key, object_type, file_name, row_num ) + key, object_type, file_name, row_num ) ) else: - cur_object[key] = ( value, file, row_num ) + cur_object[key] = ( value, file_name, row_num ) else: @@ -309,7 +312,7 @@ class NagiosConfig(object): in_block = True cur_object = {} object_type = match.group(1).lower() - cur_object['__object_definition__'] = ( file, row_num ) + cur_object['__object_definition__'] = ( file_name, row_num ) self.logger.debug( "Zeile {0} in {1}: Beginne Block vom Type {2!r}".format( row_num, file_name, object_type ) ) continue diff --git a/bin/nagios/config.pyc b/bin/nagios/config.pyc deleted file mode 100644 index ba01b13..0000000 Binary files a/bin/nagios/config.pyc and /dev/null differ diff --git a/bin/nagios/object/host.py b/bin/nagios/object/host.py index d411827..168a972 100644 --- a/bin/nagios/object/host.py +++ b/bin/nagios/object/host.py @@ -9,13 +9,13 @@ import re from nagios.object.verify import NagiosVerifyError, verify_object_property #----------------------------------------------------------------------- -def verfify( definition, logger ) +def verfify( definition, logger ): "Verifiziert einen übergebenen Definitionsblock als Nagios-Host." res = {} identifier = None -""" + """ define host{ *host_name host_name *alias alias @@ -77,7 +77,7 @@ define host{ for key in definition: if not key in valid_keys: logger.warn( "Ungültige Eigenschaft {0!r} für Hostdefinition in {1}({2}).".format( - key, definition[key][1], definition[key][2] ) + key, definition[key][1], definition[key][2] ) ) # Einfache String-Eigenschaften for key in ( 'host_name', 'alias', 'address', 'display_name', 'check_period', 'event_handler', 'notification_period', @@ -85,7 +85,7 @@ define host{ 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] ) + 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: @@ -94,15 +94,15 @@ define host{ # Array-String-Eigenschaften for key in ( 'parents', 'hostgroups', 'contacts', 'contact_groups' ): if key in definition: - array = re.split( r',+', definition[key][0] - res[key] = array[] + array = re.split( r',+', definition[key][0] ) + res[key] = array[:] if 'initial_state' in definition: - array = re.split( r',+', definition['initial_state'][0] + array = re.split( r',+', definition['initial_state'][0] ) for value in array: if value not in ( 'o', 'd', 'u' ): logger.warn( "Ungültiger Wert für 'initial_state' in {0}({1}) gegeben.".format( - definition['initial_state'][1], definition['initial_state'][2] ) + definition['initial_state'][1], definition['initial_state'][2] ) ) return ( identifier, res )