'2d_coords': ( 'intarray', { 'count_min': 2, 'count_max': 2 } ),
'3d_coords': ( 'intarray', { 'count_min': 3, 'count_max': 3 } ),
},
+ 'service': {
+ 'host_name': ( 'array', None ),
+ 'hostgroup_name': ( 'array', None ),
+ 'service_description': ( 'string', None ),
+ 'display_name': ( 'string', None ),
+ 'servicegroups': ( 'array', None ),
+ 'is_volatile': ( 'bool', None ),
+ 'check_command': ( 'string', None ),
+ 'initial_state': ( 'set', { 'valid_values': set( [ 'o', 'w', 'u', 'c' ] ) } ),
+ 'max_check_attempts': ( 'int', None ),
+ 'check_interval': ( 'int', None ),
+ 'retry_interval': ( 'int', None ),
+ 'active_checks_enabled': ( 'bool', None ),
+ 'passive_checks_enabled': ( 'bool', None ),
+ 'check_period': ( 'string', None ),
+ 'obsess_over_service': ( 'bool', None ),
+ 'check_freshness': ( 'bool', None ),
+ 'freshness_threshold': ( 'int', None ),
+ 'event_handler': ( 'string', None ),
+ 'event_handler_enabled': ( 'bool', None ),
+ 'low_flap_threshold': ( 'int', None ),
+ 'high_flap_threshold': ( 'int', None ),
+ 'flap_detection_enabled': ( 'bool', None ),
+ 'flap_detection_options': ( 'set', { 'valid_values': set( [ 'o', 'w', 'u', 'c' ] ) } ),
+ 'process_perf_data': ( 'bool', None ),
+ 'retain_status_information': ( 'bool', None ),
+ 'retain_nonstatus_information': ( 'bool', None ),
+ 'notification_interval': ( 'int', None ),
+ 'first_notification_delay': ( 'int', None ),
+ 'notification_period': ( 'string', None ),
+ 'notification_options': ( 'set', { 'valid_values': set( [ 'w', 'u', 'c', 'r', 'f', 's', ] ) } ),
+ 'notifications_enabled': ( 'bool', None ),
+ 'contacts': ( 'array', None ),
+ 'contact_groups': ( 'array', None ),
+ 'stalking_options': ( 'set', { 'valid_values': set( [ 'o', 'w', 'u', 'c' ] ) } ),
+ 'notes': ( 'string', None ),
+ 'notes_url': ( 'string', None ),
+ 'action_url': ( 'string', None ),
+ 'icon_image': ( 'string', None ),
+ 'icon_image_alt': ( 'string', None ),
+ },
+ 'hostgroup': {
+ 'hostgroup_name': ( 'string', None ),
+ 'alias': ( 'string', None ),
+ 'members': ( 'array', None ),
+ 'hostgroup_members': ( 'array', None ),
+ 'notes': ( 'string', None ),
+ 'notes_url': ( 'string', None ),
+ 'action_url': ( 'string', None ),
+ },
+ 'servicegroup': {
+ 'servicegroup_name': ( 'string', None ),
+ 'alias': ( 'string', None ),
+ 'members': ( 'array', None ),
+ 'servicegroup_members': ( 'array', None ),
+ 'notes': ( 'string', None ),
+ 'notes_url': ( 'string', None ),
+ 'action_url': ( 'string', None ),
+ },
+ 'contact': {
+ 'contact_name': ( 'string', None ),
+ 'alias': ( 'string', None ),
+ 'contactgroups': ( 'array', None ),
+ 'host_notifications_enabled': ( 'bool', None ),
+ 'service_notifications_enabled': ( 'bool', None ),
+ 'host_notification_period': ( 'string', None ),
+ 'service_notification_period': ( 'string', None ),
+ 'host_notification_options': ( 'set', { 'valid_values': set( [ 'd', 'u', 'r', 'f', 's', 'n' ] ) } ),
+ 'service_notification_options': ( 'set', { 'valid_values': set( [ 'w', 'u', 'c', 'r', 'f', 's', 'n' ] ) } ),
+ 'host_notification_commands': ( 'string', None ),
+ 'service_notification_commands': ( 'string', None ),
+ 'email': ( 'string', None ),
+ 'pager': ( 'string', None ),
+ 'addressx': ( 'string', None ),
+ 'can_submit_commands': ( 'bool', None ),
+ 'retain_status_information': ( 'bool', None ),
+ 'retain_nonstatus_information': ( 'bool', None ),
+ },
}
if object_type not in key_def:
if not object_type in self.objects_read:
self.objects_read[object_type] = []
+ if 'register' not in cur_object:
+ cur_object['register'] = ( True, None, 0 )
+
self.objects_read[object_type].append(cur_object)
cur_object = {}
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# $Id$
-# $URL$
-
-import re
-import pprint
-
-from nagios.object.verify import NagiosVerifyError, NagiosObjectVerifier
-
-#-----------------------------------------------------------------------
-def verify( definition, logger ):
- "Verifying a given definition block as a Nagios host"
-
- res = {}
- identifier = None
-
- """
-define host{
- *host_name host_name
- *alias alias
- display_name display_name
- *address address
- parents host_names
- hostgroups hostgroup_names
- check_command command_name
- initial_state [o,d,u]
- *max_check_attempts #
- check_interval #
- retry_interval #
- active_checks_enabled [0/1]
- passive_checks_enabled [0/1]
- *check_period timeperiod_name
- obsess_over_host [0/1]
- check_freshness [0/1]
- freshness_threshold #
- event_handler command_name
- event_handler_enabled [0/1]
- low_flap_threshold #
- high_flap_threshold #
- flap_detection_enabled [0/1]
- flap_detection_options [o,d,u]
- process_perf_data [0/1]
- retain_status_information [0/1]
- retain_nonstatus_information [0/1]
- *contacts contacts
- *contact_groups contact_groups
- *notification_interval #
- first_notification_delay #
- *notification_period timeperiod_name
- notification_options [d,u,r,f,s]
- notifications_enabled [0/1]
- stalking_options [o,d,u]
- notes note_string
- notes_url url
- action_url url
- icon_image image_file
- icon_image_alt alt_string
- vrml_image image_file
- statusmap_image image_file
- 2d_coords x_coord,y_coord
- 3d_coords x_coord,y_coord,z_coord
- use templates
- register [0/1]
- name object_name
-}
-"""
-
- valid_keys = set( [
- 'host_name', 'alias', 'display_name', 'address', 'parents', 'hostgroups', 'check_command', 'initial_state',
- 'max_check_attempts', 'check_interval', 'retry_interval', 'active_checks_enabled', 'passive_checks_enabled',
- 'check_period', 'obsess_over_host', 'check_freshness', 'freshness_threshold', 'event_handler', 'event_handler_enabled',
- 'low_flap_threshold', 'high_flap_threshold', 'flap_detection_enabled', 'flap_detection_options', 'process_perf_data',
- 'retain_status_information', 'retain_nonstatus_information', 'contacts', 'contact_groups', 'notification_interval',
- 'first_notification_delay', 'notification_period', 'notification_options', 'notifications_enabled', 'stalking_options',
- 'notes', 'notes_url', 'action_url', 'icon_image', 'icon_image_alt', 'vrml_image', 'statusmap_image',
- '2d_coords', '3d_coords',
- 'use', 'register', 'name'
- ] )
-
- pp = pprint.PrettyPrinter( indent = 4, depth = 6, width = 120 )
- logger.debug( "Verifying host object structure:\n{0}".format( pp.pformat( definition ) ) )
-
- for key in definition:
- if key == '__object_definition__':
- res['__object_definition__'] = definition['__object_definition__']
- continue
- if re.match( r'^_', key ):
- key_upper = key.upper()
- if key_upper in res:
- logger.warn( "Double entry {0} for host definition in {1}({2}).".format( key_upper, definition[key][1], definition[key][2] ) )
- else:
- res[key_upper] = definition[key][0]
- continue
- if not key in valid_keys:
- logger.warn( "Invalid property {0!r} for host definition in {1}({2}).".format(
- key, definition[key][1], definition[key][2] ) )
-
- verifier = NagiosObjectVerifier( logger = logger )
-
- # Einfache String-Eigenschaften
- for key in ( 'name', '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:
- 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], 'string', args )
- 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 ( 'use', 'parents', 'hostgroups', 'contacts', 'contact_groups' ):
- 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], 'array', 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 ( 'initial_state', 'flap_detection_options', 'stalking_options' ):
- 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], valid_values = set( [ 'o', 'd', 'u' ] ) )
- res[key] = verifier.verify_property( definition[key][0], 'set', 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 ( 'notification_options' ):
- 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], valid_values = set( [ 'r', 'd', 'u', 'f', 's' ] ) )
- res[key] = verifier.verify_property( definition[key][0], 'set', 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 ( 'max_check_attempts', 'check_interval', 'retry_interval', 'freshness_threshold', 'low_flap_threshold',
- 'high_flap_threshold', 'notification_interval', 'first_notification_delay', ):
- 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], 'int', 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 ( 'register', '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 'register' not in res:
- res['register'] = True
-
- if 'host_name' in res:
- identifier = res['host_name']
- elif 'name' in res:
- identifier = res['name']
-
- return ( identifier, res )
-
-# vim: fileencoding=utf-8 filetype=python ts=4 expandtab
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# $Id$
-# $URL$
-
-import re
-import pprint
-
-from nagios.object.verify import NagiosVerifyError, NagiosObjectVerifier
-
-#-----------------------------------------------------------------------
-def verify( definition, logger ):
- "Verifying a given definition block as a Nagios host group"
-
- res = {}
- identifier = None
-
- """
-define hostgroup{
- *hostgroup_name hostgroup_name
- *alias alias
- members hosts
- hostgroup_members hostgroups
- notes note_string
- notes_url url
- action_url url
- use templates
- register [0/1]
- name object_name
-}
-"""
-
- valid_keys = set( [
- 'hostgroup_name', 'alias', 'members', 'hostgroup_members', 'notes', 'notes_url', 'action_url',
- 'use', 'register', 'name'
- ] )
-
- pp = pprint.PrettyPrinter( indent = 4, depth = 6, width = 120 )
- logger.debug( "Verifying hostgroup object structure:\n{0}".format( pp.pformat( definition ) ) )
-
- for key in definition:
- if key == '__object_definition__':
- res['__object_definition__'] = definition['__object_definition__']
- continue
- if re.match( r'^_', key ):
- key_upper = key.upper()
- if key_upper in res:
- logger.warn( "Double entry {0} for hostgroup definition in {1}({2}).".format( key_upper, definition[key][1], definition[key][2] ) )
- else:
- res[key_upper] = definition[key][0]
- continue
- if not key in valid_keys:
- logger.warn( "Invalid property {0!r} for hostgroup definition in {1}({2}).".format(
- key, definition[key][1], definition[key][2] ) )
-
- verifier = NagiosObjectVerifier( logger = logger )
-
- # Einfache String-Eigenschaften
- for key in ( 'name', 'hostgroup_name', 'alias', 'notes', 'notes_url', 'action_url', ):
- if key in definition:
- try:
- if key in res:
- logger.warn( "Double entry {0} for hostgroup 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], 'string', args )
- except NagiosVerifyError as e:
- logger.warn( "Property error for hostgroup definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) )
-
- # Array-String-Eigenschaften
- for key in ( 'use', 'members', 'hostgroup_members', ):
- 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], 'array', 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 ( 'register', ):
- 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 ) )
-
- if 'register' not in res:
- res['register'] = True
-
- if 'hostgroup_name' in res:
- identifier = res['hostgroup_name']
- elif 'name' in res:
- identifier = res['name']
-
- return ( identifier, res )
-
-# vim: fileencoding=utf-8 filetype=python ts=4 expandtab
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# $Id$
-# $URL$
-
-import re
-import pprint
-
-from nagios.object.verify import NagiosVerifyError, NagiosObjectVerifier
-
-#-----------------------------------------------------------------------
-def verify( definition, logger ):
- "Verifying a given definition block of a Nagion service"
-
- res = {}
- identifier = None
-
- """
-define service{
- host_name host_names
- hostgroup_name hostgroup_names
- service_description service_description
- display_name display_name
- servicegroups servicegroup_names
- is_volatile [0/1]
- check_command command_name
- initial_state [o,w,u,c]
- max_check_attempts #
- check_interval #
- retry_interval #
- active_checks_enabled [0/1]
- passive_checks_enabled [0/1]
- check_period timeperiod_name
- obsess_over_service [0/1]
- check_freshness [0/1]
- freshness_threshold #
- event_handler command_name
- event_handler_enabled [0/1]
- low_flap_threshold #
- high_flap_threshold #
- flap_detection_enabled [0/1]
- flap_detection_options [o,w,c,u]
- process_perf_data [0/1]
- retain_status_information [0/1]
- retain_nonstatus_information [0/1]
- notification_interval #
- first_notification_delay #
- notification_period timeperiod_name
- notification_options [w,u,c,r,f,s]
- notifications_enabled [0/1]
- contacts contacts
- contact_groups contact_groups
- stalking_options [o,w,u,c]
- notes note_string
- notes_url url
- action_url url
- icon_image image_file
- icon_image_alt alt_string
- use templates
- register [0/1]
- name object_name
-}
-"""
-
- valid_keys = set( [
- 'host_name', 'hostgroup_name', 'service_description', 'display_name', 'servicegroups',
- 'is_volatile', 'check_command', 'initial_state', 'max_check_attempts', 'check_interval',
- 'retry_interval', 'active_checks_enabled', 'passive_checks_enabled', 'check_period',
- 'obsess_over_service', 'check_freshness', 'freshness_threshold', 'event_handler',
- 'event_handler_enabled', 'low_flap_threshold', 'high_flap_threshold', 'flap_detection_enabled',
- 'flap_detection_options', 'process_perf_data', 'retain_status_information',
- 'notification_interval', 'first_notification_delay', 'notification_period',
- 'notification_options', 'notifications_enabled', 'contacts', 'contact_groups',
- 'stalking_options', 'notes', 'notes_url', 'action_url', 'icon_image', 'icon_image_alt',
- 'use', 'register', 'name'
- ] )
-
- pp = pprint.PrettyPrinter( indent = 4, depth = 6, width = 120 )
- logger.debug( "Verifying service object structure:\n{0}".format( pp.pformat( definition ) ) )
-
- for key in definition:
- if key == '__object_definition__':
- res['__object_definition__'] = definition['__object_definition__']
- continue
- if re.match( r'^_', key ):
- key_upper = key.upper()
- if key_upper in res:
- logger.warn( "Double entry {0} for host definition in {1}({2}).".format( key_upper, definition[key][1], definition[key][2] ) )
- else:
- res[key_upper] = definition[key][0]
- continue
- if not key in valid_keys:
- logger.warn( "Invalid Property {0!r} for service definition in {1}({2}).".format(
- key, definition[key][1], definition[key][2] ) )
-
- verifier = NagiosObjectVerifier( logger = logger )
-
- # Einfache String-Eigenschaften
- for key in ( 'name', 'service_description', 'display_name', 'check_command', 'check_period', 'event_handler', 'notification_period',
- 'notes', 'notes_url', 'action_url', 'icon_image', 'icon_image_alt', ):
- if key in definition:
- try:
- if key in res:
- logger.warn( "Double entry {0} for service 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], 'string', args )
- except NagiosVerifyError as e:
- logger.warn( "Property error for service definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) )
-
- # Array-String-Eigenschaften
- for key in ( 'use', 'host_name', 'hostgroup_name', 'servicegroups', 'contacts', 'contact_groups' ):
- if key in definition:
- try:
- if key in res:
- logger.warn( "Double entry {0} for service 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], 'array', args )
- except NagiosVerifyError as e:
- logger.warn( "Property error for service definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) )
-
- for key in ( 'initial_state', 'flap_detection_options', 'stalking_options' ):
- if key in definition:
- try:
- if key in res:
- logger.warn( "Double entry {0} for service definition in {1}({2}).".format( key, definition[key][1], definition[key][2] ) )
- else:
- args = dict( file = definition[key][1], row = definition[key][2], valid_values = set( [ 'o', 'w', 'u', 'c' ] ) )
- res[key] = verifier.verify_property( definition[key][0], 'set', args )
- except NagiosVerifyError as e:
- logger.warn( "Property error for service definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) )
-
- for key in ( 'notification_options' ):
- if key in definition:
- try:
- if key in res:
- logger.warn( "Double entry {0} for service definition in {1}({2}).".format( key, definition[key][1], definition[key][2] ) )
- else:
- args = dict( file = definition[key][1], row = definition[key][2], valid_values = set( [ 'w', 'u', 'c', 'r', 'f', 's' ] ) )
- res[key] = verifier.verify_property( definition[key][0], 'set', args )
- except NagiosVerifyError as e:
- logger.warn( "Property error for service definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) )
-
- for key in ( 'max_check_attempts', 'check_interval', 'retry_interval', 'freshness_threshold', 'low_flap_threshold',
- 'high_flap_threshold', 'notification_interval', 'first_notification_delay', ):
- if key in definition:
- try:
- if key in res:
- logger.warn( "Double entry {0} for service 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], 'int', args )
- except NagiosVerifyError as e:
- logger.warn( "Property error for service definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) )
-
- for key in ( 'register', 'is_volatile', 'active_checks_enabled', 'passive_checks_enabled', 'obsess_over_host', 'check_freshness',
- 'event_handler_enabled', '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 service 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 service definition in {0}({1}): {2}".format( definition[key][1], definition[key][2], e ) )
-
- if 'register' not in res:
- res['register'] = True
-
- if 'service_description' in res:
- identifier = res['service_description']
- elif 'name' in res:
- identifier = res['name']
-
- return ( identifier, res )
-
-# vim: fileencoding=utf-8 filetype=python ts=4 expandtab