import sys
import warnings
import logging
+import pprint
import nagios.object.host
class NagiosConfigError(Exception):
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
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:
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
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
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',
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:
# 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 )