예제 #1
0
def _create_logical_hosts_graph_structure(hostgroups = None):
    """
    Creates a graph containing one node per service, grouped by host.
    Services may be filtered by containing hostgroup, using the hostgroup
    parameter that may contain an array of strings (hostgroup names)
    """
    g = Graph()
    slist = get_all_services()
    hlist = get_all_hosts()
    permissions = utils.get_contact_permissions(current_user.shinken_contact)
    tmp = {}
    for s in slist:
        if s in permissions['services']:
            tmp[s] = slist[s]
    slist = tmp

    # Nodes
    for sname in slist:
        for hname, s in slist[sname].iteritems():
            h = hlist[hname]
            filtered = False
            # Filter by hostgroups
            if hostgroups is not None:
                filtered = any([test in hostgroups for g in s['host_groups']])
            if not filtered:
                g.add_or_get_group_from_host(h).add_node(g.add_node_from_service(s))
    # Edges
    for sname in slist:
        for s in slist[sname].itervalues():
            for parent_host, parent_service in _extract_service_dependencies(s):
                g.add_link_from_service_dependency(parent_host, parent_service, s['host_name'], s['description'])
    return g
예제 #2
0
def _create_logical_services_graph_structure(hosts=None, servicegroups=None):
    """
    Generates a graph object from the Shinken configuration, containing services as nodes and services dependencies as edges.
    The hosts parameter can contain an array of host names. If provided, only services from those hosts will be included.
    The servicegroups parameter can contain an array of service group names. If provided, only services belonging to those groups will be included.
    """
    g = Graph()
    slist = get_all_services()

    #remove forbidden services
    permissions = utils.get_contact_permissions(current_user.shinken_contact)
    tmp = {}
    for s in slist:
        if s in permissions['services']:
            tmp[s] = slist[s]
    slist = tmp

    # Create nodes
    for h in slist.itervalues():
        for s in h.itervalues():
            include = True
            if hosts is not None:
                include = s['host_name'] in hosts
            if include and servicegroups is not None:
                include = any([
                    group.name in servicegroups for group in s['servicegroups']
                ])
            if include:
                g.add_node_from_service(s)

    # Create links
    # We don't really check for duplicates here as the graph object will manage that for us
    for h in slist.itervalues():
        for s in h.itervalues():
            for parent_host, parent_service in _extract_service_dependencies(
                    s):
                g.add_link_from_service_dependency(parent_host, parent_service,
                                                   s['host_name'],
                                                   s['description'])

    return g
예제 #3
0
def _create_logical_services_graph_structure(hosts = None, servicegroups = None):
    """
    Generates a graph object from the Shinken configuration, containing services as nodes and services dependencies as edges.
    The hosts parameter can contain an array of host names. If provided, only services from those hosts will be included.
    The servicegroups parameter can contain an array of service group names. If provided, only services belonging to those groups will be included.
    """
    g = Graph()
    slist = get_all_services()

    #remove forbidden services
    permissions = utils.get_contact_permissions(current_user.shinken_contact)
    tmp = {}
    for s in slist:
        if s in permissions['services']:
            tmp[s] = slist[s]
    slist = tmp

    # Create nodes
    for h in slist.itervalues():
        for s in h.itervalues():
            include = True
            if hosts is not None:
                include = s['host_name'] in hosts
            if include and servicegroups is not None:
                include = any([group.name in servicegroups for group in s['servicegroups']])
            if include:
                g.add_node_from_service(s)
    
    # Create links
    # We don't really check for duplicates here as the graph object will manage that for us
    for h in slist.itervalues():
        for s in h.itervalues():
            for parent_host, parent_service in _extract_service_dependencies(s):
                g.add_link_from_service_dependency(parent_host, parent_service, s['host_name'], s['description'])


    return g
예제 #4
0
def _create_logical_hosts_graph_structure(hostgroups=None):
    """
    Creates a graph containing one node per service, grouped by host.
    Services may be filtered by containing hostgroup, using the hostgroup
    parameter that may contain an array of strings (hostgroup names)
    """
    g = Graph()
    slist = get_all_services()
    hlist = get_all_hosts()
    permissions = utils.get_contact_permissions(current_user.shinken_contact)
    tmp = {}
    for s in slist:
        if s in permissions['services']:
            tmp[s] = slist[s]
    slist = tmp

    # Nodes
    for sname in slist:
        for hname, s in slist[sname].iteritems():
            h = hlist[hname]
            filtered = False
            # Filter by hostgroups
            if hostgroups is not None:
                filtered = any([test in hostgroups for g in s['host_groups']])
            if not filtered:
                g.add_or_get_group_from_host(h).add_node(
                    g.add_node_from_service(s))
    # Edges
    for sname in slist:
        for s in slist[sname].itervalues():
            for parent_host, parent_service in _extract_service_dependencies(
                    s):
                g.add_link_from_service_dependency(parent_host, parent_service,
                                                   s['host_name'],
                                                   s['description'])
    return g