From 0f9a656fb0c4f276babd6f1317ee439c050c729d Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Sun, 21 Nov 2010 08:43:03 +0000 Subject: [PATCH] bischen weiter ... git-svn-id: http://svn.brehm-online.com/svn/my-stuff/nagios/trunk@125 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- bin/nagios/__init__.pyc | Bin 134 -> 0 bytes bin/nagios/config.py | 3 +++ bin/nagios/object/__init__.pyc | Bin 148 -> 0 bytes bin/nagios/object/host.py | 24 +++++++++++-------- bin/nagios/object/host.pyc | Bin 144 -> 0 bytes bin/nagios/object/verify.py | 41 +++++++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 9 deletions(-) delete mode 100644 bin/nagios/__init__.pyc delete mode 100644 bin/nagios/object/__init__.pyc delete mode 100644 bin/nagios/object/host.pyc create mode 100644 bin/nagios/object/verify.py diff --git a/bin/nagios/__init__.pyc b/bin/nagios/__init__.pyc deleted file mode 100644 index c9f7b03687460948d49c59b0263c6597d1df20c7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 134 zcmcckiI;26`kOw<3{b!bq#b~`m<33rFfasbfJFQ>fCK{?QLGOX)6dAyP1R2;O3cgF zPf0CH&C&NuOwY_O)=$dJ)6au21X8Urs}5^CFW)8 zr=*sp=IG}orf23C>lRd&WaQ`RCuQbAMfCHNvQm>v^yA|*^D;}~?sCf1^~elB7*<` diff --git a/bin/nagios/object/host.py b/bin/nagios/object/host.py index a5f5846..2706880 100644 --- a/bin/nagios/object/host.py +++ b/bin/nagios/object/host.py @@ -1,10 +1,16 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +# $Id: $ +# $URL: $ + import re +from nagios.object.verify import NagiosVerifyError, verify_object_property + +#----------------------------------------------------------------------- def verfify( definition, logger ) -"Verifiziert einen übergebenen Definitionsblock als Nagios-Host." + "Verifiziert einen übergebenen Definitionsblock als Nagios-Host." res = {} identifier = None @@ -73,17 +79,17 @@ define host{ logger.warn( "Ungültige Eigenschaft {0!r} für Hostdefinition in {1}({2}).".format( key, definition[key][1], definition[key][2] ) - if 'host_name' in definition: - identifier = definition['host_name'][0] - res['host_name'] = definition['host_name'][0] - else - logger.warn( "Kein Hostname in Hostdefinition gegeben." ) - # Einfache String-Eigenschaften - for key in ( 'alias', 'address', 'display_name', 'check_period', 'event_handler', 'notification_period', + for key in ( 'host_name', 'alias', 'address', 'display_name', 'check_period', 'event_handler', 'notification_period', 'notes', 'notes_url', 'action_url', 'icon_image', 'icon_image_alt', 'vrml_image', 'statusmap_image' ): if key in definition: - res[key] = definition[key][0] + 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: + res[key] = verify_object_property( definition[key][0], 'string' ) + except NagiosVerifyError as e: + logger.warn( "Property error for host definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) ) # Array-String-Eigenschaften for key in ( 'parents', 'hostgroups', 'contacts', 'contact_groups' ): diff --git a/bin/nagios/object/host.pyc b/bin/nagios/object/host.pyc deleted file mode 100644 index ef9b2bc160aa6b23d4e33227ca73fa0130044dc1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 144 zcmcckiI?k>+ykFv1}I1X8Urs}5^CFW)8 zr=*sp=IG}orf23C>lRd&WaQ`RCuQbAMfCHNvQm>vfEtQR^nkJ)K;1UE`6;D2sdgYc Iih-B`06tM6H2?qr diff --git a/bin/nagios/object/verify.py b/bin/nagios/object/verify.py new file mode 100644 index 0000000..cec786a --- /dev/null +++ b/bin/nagios/object/verify.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# $Id: $ +# $URL: $ + +import re + +#----------------------------------------------------------------------- +class NagiosVerifyError(Exception): + """Base class for exceptions in this module.""" + pass + +#----------------------------------------------------------------------- +def verify_object_property( definition, type, args = None ): + "Verifiziert den Wert einer übergebenen Objekteigenschaft." + + if definition is None: + raise NagiosVerifyError( "Undefined property given." ) + + definition = re.sub( r'^\s+', '', definition, 0 ) + definition = re.sub( r'\s+$', '', definition, 0 ) + + if type == "string": + return verify_string_property( definition, args ) + +#----------------------------------------------------------------------- +def verify_string_property( definition, args = None ): + "Verifiziert den Wert als einfachen String" + + if args is None: + args = dict() + + if definition == '': + if not 'empty_ok' in args: + raise NagiosVerifyError( "Empty property is not allowed." ) + + return definition + + +# vim: fileencoding=utf-8 filetype=python ts=4 expandtab -- 2.39.5