#!/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
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' ):
--- /dev/null
+#!/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