def _get_alarms(self): nagios_user = self.conf.nagios.user nagios_password = self.conf.nagios.password nagios_url = self.conf.nagios.url if not nagios_user: return [] if not nagios_password: LOG.warning(_LW('Nagios password is not defined')) return [] if not nagios_url: LOG.warning(_LW('Nagios url is not defined')) return [] session = requests.Session() payload = {'host': 'all', 'limit': '0'} response = session.get(nagios_url, params=payload, auth=(nagios_user, nagios_password)) if response.status_code == requests.codes.ok: nagios_services = NagiosParser().parse(response.text) return nagios_services else: LOG.error( _LE('Failed to get nagios data. Response code: %s') % response.status_code) return []
def _get_alarms(self): nagios_user = self.conf.nagios.user nagios_password = self.conf.nagios.password nagios_url = self.conf.nagios.url if not nagios_user: return [] if not nagios_password: LOG.warning(_LW('Nagios password is not defined')) return [] if not nagios_url: LOG.warning(_LW('Nagios url is not defined')) return [] session = requests.Session() payload = {'host': 'all', 'limit': '0'} response = session.get(nagios_url, params=payload, auth=(nagios_user, nagios_password)) if response.status_code == requests.codes.ok: nagios_services = NagiosParser().parse(response.text) return nagios_services else: LOG.error(_LE('Failed to get nagios data. Response code: %s') % response.status_code) return []
def setup_app(pecan_config=PECAN_CONFIG, conf=None): if conf is None: raise RuntimeError('Config is actually mandatory') app_hooks = [hooks.ConfigHook(conf), hooks.TranslationHook()] pecan.configuration.set_config(dict(pecan_config), overwrite=True) pecan_debug = conf.api.pecan_debug if conf.api.workers != 1 and pecan_debug: pecan_debug = False LOG.warning(_LW('pecan_debug cannot be enabled, if workers is > 1, ' 'the value is overridden with False')) app = pecan.make_app( pecan_config['app']['root'], debug=pecan_debug, hooks=app_hooks, guess_content_type_from_ext=False ) return app
def setup_app(pecan_config=PECAN_CONFIG, conf=None): if conf is None: raise RuntimeError('Config is actually mandatory') app_hooks = [ hooks.ConfigHook(conf), hooks.TranslationHook(), hooks.RPCHook(conf), hooks.ContextHook() ] pecan.configuration.set_config(dict(pecan_config), overwrite=True) pecan_debug = conf.api.pecan_debug if conf.api.workers != 1 and pecan_debug: pecan_debug = False LOG.warning( _LW('pecan_debug cannot be enabled, if workers is > 1, ' 'the value is overridden with False')) app = pecan.make_app(pecan_config['app']['root'], debug=pecan_debug, hooks=app_hooks, guess_content_type_from_ext=False) return app
def subgraph_matching(base_graph, subgraph, matches, validate=False): """Find all occurrences of subgraph in the graph In the following, a partial mapping is a copy of the sub-graph. As we go, vertices of curr_mapping graph will be updated with new fields used only for the traversal: - MAPPED_V_ID: The vertex_id of the corresponding vertex in the graph. If it is not empty, than this vertex is already mapped - NEIGHBORS_MAPPED: True or None. When set True it means all the neighbors of this vertex have already been mapped Implementation Details: ---------------------- - Init Step: copy the sub-graph to create the first candidate mapping graph. In which known vertices mappings are added to vertices MAPPED_V_ID. So, we now have a sub-graph copy where some of the vertices already have a mapping Main loop steps: - Steps 1: Pop a partially mapped sub-graph from the queue. If all its vertices have a MAPPED_V_ID, add it to final mappings - Steps 2 & 3: Find one template vertex that is not mapped but has a mapped neighbor - Step 4: CHECK PROPERTIES In the graph find candidate vertices that are linked to that neighbor and match the template vertex properties - Step 5: CHECK STRUCTURE Filter candidate vertices according to edges """ final_subgraphs = [] initial_sg = _create_initial_subgraph(matches, base_graph, subgraph, validate) if not initial_sg: LOG.warning(_LW('subgraph_matching:Initial sub-graph creation failed')) LOG.warning(_LW('subgraph_matching: Known matches: %s'), str(matches)) return final_subgraphs queue = [initial_sg] while queue: curr_subgraph = queue.pop(0) # STEP 1: STOPPING CONDITION mapped_vertices = list(filter( lambda v: v.get(MAPPED_V_ID), curr_subgraph.get_vertices())) if len(mapped_vertices) == subgraph.num_vertices(): final_subgraphs.append(curr_subgraph) continue # STEP 2: CAN WE THROW THIS SUB-GRAPH? vertices_with_unmapped_neighbors = list(filter( lambda v: not v.get(NEIGHBORS_MAPPED), mapped_vertices)) if not vertices_with_unmapped_neighbors: continue # STEP 3: FIND A SUB-GRAPH VERTEX TO MAP v_with_unmapped_neighbors = vertices_with_unmapped_neighbors.pop(0) unmapped_neighbors = list(filter( lambda v: not v.get(MAPPED_V_ID), curr_subgraph.neighbors(v_with_unmapped_neighbors.vertex_id))) if not unmapped_neighbors: # Mark vertex as NEIGHBORS_MAPPED=True v_with_unmapped_neighbors[NEIGHBORS_MAPPED] = True curr_subgraph.update_vertex(v_with_unmapped_neighbors) queue.append(curr_subgraph) continue subgraph_vertex_to_map = unmapped_neighbors.pop(0) # STEP 4: PROPERTIES CHECK graph_candidate_vertices = base_graph.neighbors( v_id=v_with_unmapped_neighbors[MAPPED_V_ID], vertex_attr_filter=subgraph_vertex_to_map) # STEP 5: STRUCTURE CHECK edges = _get_edges_to_mapped_vertices(curr_subgraph, subgraph_vertex_to_map.vertex_id) for graph_vertex in graph_candidate_vertices: subgraph_vertex_to_map[MAPPED_V_ID] = graph_vertex.vertex_id subgraph_vertex_to_map[GRAPH_VERTEX] = graph_vertex curr_subgraph.update_vertex(subgraph_vertex_to_map) if _graph_contains_subgraph_edges(base_graph, curr_subgraph, edges): queue.append(curr_subgraph.copy()) # Last thing: Convert results to the expected format! result = [] for mapping in final_subgraphs: # TODO(ihefetz) If needed, Here we can easily extract the edge # matches from the mapping graph a = {v.vertex_id: v[GRAPH_VERTEX] for v in mapping.get_vertices()} result.append(a) return result