except NagiosVerifyError as e:
logger.warn( "Property error for host definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) )
+ for key in ( 'active_checks_enabled', 'passive_checks_enabled', 'obsess_over_host', 'check_freshness', 'flap_detection_enabled',
+ 'process_perf_data', 'retain_status_information', 'retain_nonstatus_information', 'notifications_enabled', ):
+ 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] ) )
+ else:
+ args = dict( file = definition[key][1], row = definition[key][2] )
+ res[key] = verifier.verify_property( definition[key][0], 'bool', args )
+ except NagiosVerifyError as e:
+ logger.warn( "Property error for host definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) )
+
+ for key in ( '2d_coords', '3d_coords', ):
+ 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] ) )
+ else:
+ args = dict( file = definition[key][1], row = definition[key][2] )
+ res[key] = verifier.verify_property( definition[key][0], 'intarray', args )
+ except NagiosVerifyError as e:
+ logger.warn( "Property error for host definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) )
+
if 'host_name' in res:
identifier = res['host_name']
elif 'name' in res:
return self.verify_set_property( definition, args )
elif type == "int":
return self.verify_int_property( definition, args )
+ elif type == "intarray":
+ return self.verify_intarray_property( definition, args )
+ elif type == "bool":
+ return self.verify_bool_property( definition, args )
raise NagiosVerifyError( "Unknown property type {0!r} given.".format( type ) )
if args is None:
args = dict()
- array = re.split( r',+', definition )
+ result_array = [ ]
+
+ match = re.match( r'^\+(.*)', definition )
+ if match is None:
+ def_cleared = definition
+ else:
+ result_array = [ '+' ]
+ def_cleared = match.group(1)
+
+ array = re.split( r',+', def_cleared )
if len(array) == 0:
if not 'empty_ok' in args:
raise NagiosVerifyError( "Empty property is not allowed." )
- return array
+ for part in array:
+ result_array.append(part)
+
+ return result_array
#------------------------------------------------------
def verify_set_property( self, definition, args = None ):
return val
+ #------------------------------------------------------
+ def verify_intarray_property( self, definition, args = None ):
+
+ if args is None:
+ args = dict()
+
+ match = re.match( r'^\+(.*)', definition )
+ if match is None:
+ def_cleared = definition
+ else:
+ result_array = [ '+' ]
+ def_cleared = match.group(1)
+
+ array = re.split( r',+', def_cleared )
+
+ if len(array) == 0 and len(result_array) == 0:
+ if not 'empty_ok' in args:
+ raise NagiosVerifyError( "Empty property is not allowed." )
+
+ for part in array:
+ match = re.match( r'^(\d+)$', part )
+ if match is None:
+ raise NagiosVerifyError( "Not a integer value in {0!r}({1}): {2!r}".format( args['file'], args['row'], definition ) )
+
+ val = int( match.group(1) )
+ result_array.append(val)
+
+ return result_array
+
+ #------------------------------------------------------
+ def verify_bool_property( self, definition, args = None ):
+
+ if args is None:
+ args = dict()
+
+ match = re.match( r'^(\d+)$', definition )
+ if match is None:
+ raise NagiosVerifyError( "Not a integer bool value in {0!r}({1}): {2!r}".format( args['file'], args['row'], definition ) )
+
+ val = int( match.group(1) )
+ if val > 1:
+ raise NagiosVerifyError( "Not a bool value in {0!r}({1}): {2!r}".format( args['file'], args['row'], definition ) )
+
+ if val == 1:
+ return True
+
+ return False
+
#-----------------------------------------------------------------------
# vim: fileencoding=utf-8 filetype=python ts=4 expandtab