Changeset 6645


Ignore:
Timestamp:
Jan 29, 2009, 7:34:45 PM (16 years ago)
Author:
maarten
Message:

Parents directive is searched with NetworkX
Last commit for nagios config. Nagios code will move to separate app

Location:
trunk/exodus
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/exodus/settings.py

    r6517 r6645  
    2121# AP subnet size
    2222AP_NETMASK = 26
    23 
    24 
     23# Graph for network
     24try:
     25    import networkx as nx
     26    G = nx.Graph()
     27except:
     28    G = 'no_networkx'
    2529# Master super path, set to current working path
    2630EXODUS_ROOT =  os.path.dirname(__file__)
  • trunk/exodus/templates/nagios/object.nagios

    r6618 r6645  
    1212    icon_image_alt Node {{ node.name }}
    1313    statusmap_image nodes.gd2
    14 }
     14{% ifnotequal viewpoint 'none' %}    parents {{ node.name|getParents:viewpoint }}{% else %}}{% endifnotequal %}
     15{% ifnotequal viewpoint 'none' %}}{% endifnotequal %}
  • trunk/exodus/templates/viewNagios.html

    r6610 r6645  
    66        <table border="3" cellpadding="1">
    77                <tr>
     8            <td colspan=2>
     9            If you have installed <a href=http://networkx.lanl.gov/>networkx</a> the parent directive can be rendered<br/>
     10            Currently no monitor is added to the exodus database so the monitor parameter is set<br/>
     11            to a node viewpoint.<br/>
     12            This is the last commit for nagios until the new build environment/addon structure for<br/>
     13            exodus is defined...<br/><br/>
     14            example usage: view/nagios/AZC/exodus.cfg<br/>
     15            searches for parent dependencies between each node and AZC<br/>
     16            </td>
     17        </tr>
     18        <tr>
    819                        <td class="list" >Full nagios config from exodus</td>
    920                        <td class="list" ><a class="list" href="{% url exodus.views.viewNagios %}">exodus.cfg</a></td>
  • trunk/exodus/templatetags/location.py

    r6618 r6645  
    11from django import template
    22from django.template.defaultfilters import stringfilter
     3
     4from exodus.settings import G
     5if G != 'no_networkx':
     6    from networkx import shortest_path
    37
    48register = template.Library()
     
    1014
    1115register.filter('getLocationName', getLocationName)
     16
     17def getParents(node,viewpoint):
     18    if G != 'no_networkx':
     19        route = shortest_path(G,viewpoint,node)
     20        parents = [viewpoint]
     21        if route and len(route) > 2:
     22            for hop in route:
     23                if hop != node and hop != viewpoint:
     24                    bakhop = G.neighbors(hop)
     25                    G.remove_node(hop)
     26                    if not shortest_path(G,viewpoint,node):
     27                        parents.append(hop)
     28                    for link in bakhop:
     29                        G.add_edge(hop,link)
     30        return ' '.join(parents)
     31    else:
     32        return viewpoint
     33register.filter('getParents', getParents)
  • trunk/exodus/urls.py

    r6629 r6645  
    2929    url(r'^view/nagios/$', 'exodus.urls.direct_to_template', {'template': 'viewNagios.html'}, "nagios"),
    3030    (r'^view/nagios/exodus.cfg$', 'exodus.views.viewNagios'),
     31    (r'^view/nagios/(?P<monitor>.+)/exodus.cfg$', 'exodus.views.viewNagios'),
    3132   
    3233    # 3th party/embedded database browser
  • trunk/exodus/views.py

    r6637 r6645  
    99
    1010from exodus.models import Node, Network, Location
     11from exodus.settings import G
    1112
    1213# Views
     
    7677            mimetype='text/plain')
    7778
    78 def viewNagios(request):
     79def viewNagios(request, monitor='none'):
    7980    nodes = Node.objects.all()
    8081    networks = Network.objects.all()
    8182    locations = Location.objects.all()
    82     return render_to_response('nagios/exodus.cfg', {'nodes' : nodes, 'networks' : networks, 'locations' : locations}, mimetype='text/plain')
     83    #TODO monitors should be added to exodus (static hosts)
     84    # to get the viewpoint of the monitor
     85    #viewpoint = DhcpStatic.objects.filter(hostname=monitor).accespoint.node.name
     86    # for demo purpose the viewpoint is set to the monitor
     87    viewpoint=monitor
     88    # check if networkx is available
     89    if G == 'no_networkx':
     90        monitor = 'none'
     91        print 'Networkx is not available'
     92    #only if monitor is set create a graph to work with
     93    if monitor != 'none':
     94        G.clear
     95        for node in Node.objects.all():
     96            if node.status == 'up':
     97                    G.add_node(node.name)
     98                    for interface in node.interface_set.all():
     99                        if interface.mode == 'mn' and interface.link.node.status == 'up':
     100                            G.add_edge(node.name,interface.link.node.name)
     101   
     102    return render_to_response('nagios/exodus.cfg', {'nodes' : nodes, 'networks' : networks, 'locations' : locations, 'viewpoint' : viewpoint}, mimetype='text/plain')
    83103
    84104
Note: See TracChangeset for help on using the changeset viewer.