import logging
import pprint
import nagios.object.host
+import nagios.object.hostgroup
class NagiosConfigError(Exception):
"""Base class for exceptions in this module."""
else:
self.objects['host'][identifier] = struct
+ if object_type == 'hostgroup':
+
+ ( identifier, struct ) = nagios.object.hostgroup.verify( cur_object, self.logger )
+ self.logger.debug( "Found hostgroup object structure for {0!r}: {1}".format( identifier, pp.pformat( struct ) ) )
+ ( file_name, rownum ) = cur_object['__object_definition__']
+
+ if identifier is None:
+ self.logger.warn( "Couldn't verify hostgroup object structure of {0!r}({1})".format(
+ file_name, rownum ) )
+ else:
+ if identifier in self.objects['hostgroup']:
+ msg = "Hostgroup object {0!r} even exists, ".format( identifier )
+ msg = msg + "new definition in {0!r}({1}) will not accepted.".format( file_name, rownum )
+ self.logger.warn( msg )
+ else:
+ self.objects['hostgroup'][identifier] = struct
+
cur_object = {}
self.logger.debug( "Row {0} in {1}: finishing block of type {2!r}".format( row_num, file_name, object_type ) )
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
}
"""
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',
+ 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:
--- /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 e 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__':
+ 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 '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