def __init__(self): # create a map of valid endpoints/arguments for endpoint in Model.all_attributes.object_definitions.keys(): self[endpoint] = Model.all_attributes.object_definitions[ endpoint].keys() self[endpoint] += Model.all_attributes.object_definitions["any"] del self["any"] if not self.main_cfg_values: parser = Parsers.config(config['nagios_main_cfg']) parser.parse() self.main_cfg_values.update(dict(parser.maincfg_values)) # set endpoint keys self.endpoint_keys = { 'hostgroup': 'hostgroup_name', 'hostextinfo': 'host_name', 'host': 'host_name', 'service': 'service_description', 'servicegroup': 'servicegroup_name', 'contact': 'contact_name', 'contactgroup': 'contactgroup_name', 'timeperiod': 'timeperiod_name', 'command': 'command_name', }
def reload_cache(self): 'Reload configuration cache' self.objects = [] ObjectFetcher.relations= {} global config config = Parsers.config(cfg_file) config.parse() if self.object_type != None: key_name = "all_%s" % (self.object_type) if not config.data.has_key(key_name): return [] objects = config.data[ key_name ] else: # If no object type was requested objects = [] for v in config.data.values(): objects += v for i in objects: object_type = i['meta']['object_type'] Class = string_to_class.get( object_type, ObjectDefinition ) i = Class(item=i) # self.find_relations(i) self.objects.append(i) return self.objects
def __init__(self): # create a map of valid endpoints/arguments for endpoint in Model.all_attributes.object_definitions.keys(): self[endpoint] = Model.all_attributes.object_definitions[endpoint].keys() self[endpoint] += Model.all_attributes.object_definitions["any"] del self["any"] if not self.main_cfg_values: parser = Parsers.config(config['nagios_main_cfg']) parser.parse() self.main_cfg_values.update(dict(parser.maincfg_values)) # set endpoint keys self.endpoint_keys = { 'hostgroup':'hostgroup_name', 'hostextinfo':'host_name', 'host':'host_name', 'service':'service_description', 'servicegroup':'servicegroup_name', 'contact':'contact_name', 'contactgroup':'contactgroup_name', 'timeperiod':'timeperiod_name', 'command':'command_name', }
#!/usr/bin/python ''' Convenient stateless functions for pynag. This module is used by the /rest/ interface of adagios. ''' import platform from pynag import Model from pynag import Parsers from pynag import Control from pynag import __version__ from socket import gethostbyname_ex import adagios.settings _config = Parsers.config(adagios.settings.nagios_config) _config.parse() maincfg_values = _config.maincfg_values cfg_file = _config.cfg_file version = __version__ def _get_dict(x): x.__delattr__('objects') return x._original_attributes #__dict__ #_get_dict = lambda x: del (x.objects) #timeperiods = map(_get_dict, Model.Timeperiod.objects.all) #hosts = map(_get_dict, Model.Host.objects.all )
Convenient stateless functions for pynag. This module is used by the /rest/ interface of adagios. ''' import platform from pynag import Model from pynag import Parsers from pynag import Control from pynag import __version__ from socket import gethostbyname_ex import adagios.settings _config = Parsers.config(adagios.settings.nagios_config) _config.parse() maincfg_values = _config.maincfg_values cfg_file = _config.cfg_file version = __version__ def _get_dict(x): x.__delattr__('objects') return x._original_attributes #__dict__ #_get_dict = lambda x: del (x.objects) #timeperiods = map(_get_dict, Model.Timeperiod.objects.all) #hosts = map(_get_dict, Model.Host.objects.all ) #contacts = map(_get_dict, Model.Contact.objects.all ) #services = map(_get_dict, Model.Service.objects.all ) #contactgroups = map(_get_dict, Model.Contactgroup.objects.all )
# define post-scan actions, printed summaries, etc. in the scan_end() callback function scan( config['nmap_target'] ) if __name__ == '__main__': # create the nmap scanner try: nm = nmap.PortScannerAsync() except nmap.PortScannerError: print('Nmap not found', sys.exc_info()[0]) sys.exit(-1) except: raise config = parse_arguments() # create the nagios parser nc = Parsers.config( config['nagios_config'] ) nc.extended_parse() # transform the specified target (which could be an entire network, a block, etc) # into a sorted list of IP addresses. This allows the user to resume a long scan # if it has to be interrupted, or crashes, or times out and so forth. # config['nmap_target'] = sort_listscan( config['nmap_target'] ) host_count = len( config['nmap_target'] ) main()