1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2009-2012:
# Gabes Jean, naparuba@gmail.com
# Gerhard Lausser, Gerhard.Lausser@consol.de
# Gregory Starck, g.starck@gmail.com
# Hartmut Goebel, h.goebel@goebel-consult.de
#
# This file is part of Shinken.
#
# Shinken is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Shinken is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
import time
### Will be populated by the UI with it's own value
app = None
def depgraph_host(name):
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
if not user:
return {'app': app, 'elt': None, 'valid_user': False}
# Ok we are in a detail page but the user ask for a specific search
search = app.request.GET.get('global_search', None)
loop = bool(int(app.request.GET.get('loop', '0')))
loop_time = int(app.request.GET.get('loop_time', '10'))
if search:
new_h = app.datamgr.get_host(search)
if new_h:
app.bottle.redirect("/depgraph/" + search)
h = app.datamgr.get_host(name)
return {'app': app, 'elt': h, 'user': user, 'valid_user': True, 'loop' : loop, 'loop_time' : loop_time}
def depgraph_srv(hname, desc):
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
if not user:
return {'app': app, 'elt': None, 'valid_user': False}
loop = bool(int(app.request.GET.get('loop', '0')))
loop_time = int(app.request.GET.get('loop_time', '10'))
# Ok we are in a detail page but the user ask for a specific search
search = app.request.GET.get('global_search', None)
if search:
new_h = app.datamgr.get_host(search)
if new_h:
app.bottle.redirect("/depgraph/" + search)
s = app.datamgr.get_service(hname, desc)
return {'app': app, 'elt': s, 'user': user, 'valid_user': True, 'loop' : loop, 'loop_time' : loop_time}
def get_depgraph_widget():
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
if not user:
return {'app': app, 'elt': None, 'valid_user': False}
search = app.request.GET.get('search', '').strip()
if not search:
# Ok look for the first host we can find
hosts = app.datamgr.get_hosts()
for h in hosts:
search = h.get_name()
break
elts = search.split('/', 1)
if len(elts) == 1:
s = app.datamgr.get_host(search)
else: # ok we got a service! :)
s = app.datamgr.get_service(elts[0], elts[1])
wid = app.request.GET.get('wid', 'widget_depgraph_' + str(int(time.time())))
collapsed = (app.request.GET.get('collapsed', 'False') == 'True')
options = {'search': {'value': search, 'type': 'hst_srv', 'label': 'Search an element'},
}
title = 'Relation graph for %s' % search
return {'app': app, 'elt': s, 'user': user,
'wid': wid, 'collapsed': collapsed, 'options': options, 'base_url': '/widget/depgraph', 'title': title,
}
def get_depgraph_inner(name):
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
if not user:
return {'app': app, 'elt': None, 'user': None}
elt = None
if '/' in name:
elts = name.split('/', 1)
elt = app.datamgr.get_service(elts[0], elts[1])
else:
elt = app.datamgr.get_host(name)
return {'app': app, 'elt': elt, 'user': user}
widget_desc = '''<h4>Relation graph</h4>
Show a graph of an object relations
'''
pages = {depgraph_host: {'routes': ['/depgraph/:name'], 'view': 'depgraph', 'static': True},
depgraph_srv: {'routes': ['/depgraph/:hname/:desc'], 'view': 'depgraph', 'static': True},
get_depgraph_widget: {'routes': ['/widget/depgraph'], 'view': 'widget_depgraph', 'static': True, 'widget': ['dashboard'], 'widget_desc': widget_desc, 'widget_name': 'depgraph', 'widget_picture': '/static/depgraph/img/widget_depgraph.png'},
get_depgraph_inner: {'routes': ['/inner/depgraph/:name#.+#'], 'view': 'inner_depgraph', 'static': True},
}
|