Revision b8500d1a
Amélioration Pylint
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@599 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigiboard/controllers/root.py | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import tg |
6 | 6 |
|
7 |
from tg import config, expose, flash, require, request, redirect, \
|
|
7 |
from tg import expose, flash, require, request, redirect, \ |
|
8 | 8 |
validate, tmpl_context, session |
9 | 9 |
|
10 | 10 |
from tw.forms import validators |
11 | 11 |
|
12 | 12 |
from pylons.i18n import ugettext as _ |
13 | 13 |
|
14 |
from sqlalchemy import sql, asc
|
|
14 |
from sqlalchemy import asc |
|
15 | 15 |
|
16 |
from vigiboard.lib.base import TGController |
|
17 | 16 |
from vigiboard.model import DBSession |
18 | 17 |
|
19 |
from vigiboard.model import ServiceHautNiveau, HostGroups, \ |
|
20 |
Events, EventHistory |
|
18 |
from vigiboard.model import HostGroups, Events, EventHistory |
|
21 | 19 |
|
22 | 20 |
from repoze.what.predicates import Any, not_anonymous |
23 | 21 |
|
... | ... | |
27 | 25 |
from vigiboard.controllers.vigiboardrequest import \ |
28 | 26 |
VigiboardRequest |
29 | 27 |
|
30 |
from vigiboard.controllers.vigiboard_controller import Vigiboard_RootController
|
|
28 |
from vigiboard.controllers.vigiboard_controller import VigiboardRootController |
|
31 | 29 |
|
32 | 30 |
__all__ = ['RootController'] |
33 | 31 |
|
34 |
class RootController(Vigiboard_RootController):
|
|
32 |
class RootController(VigiboardRootController): |
|
35 | 33 |
|
36 | 34 |
""" |
37 | 35 |
Le controller général de vigiboard |
... | ... | |
156 | 154 |
3: _('Initial'), 4: _('Maintenance'), 5: _('Minor'), |
157 | 155 |
6: _('Major'), 7: _('Critical') } |
158 | 156 |
eventdetails = {} |
159 |
for edname, edlink in tg.config['vigiboard_links.eventdetails'].iteritems(): |
|
157 |
for edname, edlink in \ |
|
158 |
tg.config['vigiboard_links.eventdetails'].iteritems(): |
|
159 |
|
|
160 | 160 |
eventdetails[edname] = edlink[1] % { |
161 | 161 |
'idevent': events.idevent, |
162 | 162 |
'host': events.hostname, |
163 | 163 |
'service': events.servicename |
164 | 164 |
} |
165 |
|
|
165 | 166 |
return dict( |
166 | 167 |
initial_state = severity[int(initial_state)], |
167 | 168 |
current_state = severity[events.severity], |
... | ... | |
291 | 292 |
).get('repoze.who.userid') |
292 | 293 |
|
293 | 294 |
for req in events.req : |
294 |
if isinstance(req,Events): |
|
295 |
if isinstance(req, Events):
|
|
295 | 296 |
event = req |
296 | 297 |
else: |
297 | 298 |
event = req[0] |
... | ... | |
312 | 313 |
flash(_('Updated successfully')) |
313 | 314 |
# Redirection vers la dernière page accédée |
314 | 315 |
redirect(request.environ.get('HTTP_REFERER').split( |
315 |
request.environ.get('HTTP_HOST')+tg.config['base_url_filter.base_url'])[1]) |
|
316 |
request.environ.get('HTTP_HOST') + \ |
|
317 |
tg.config['base_url_filter.base_url'])[1]) |
|
316 | 318 |
|
317 | 319 |
|
318 | 320 |
@validate(validators={"plugin_name":validators.OneOf( |
319 | 321 |
[i for [i,j] in tg.config['vigiboard_plugins']])}, |
320 |
error_handler=process_form_errors)
|
|
322 |
error_handler = process_form_errors)
|
|
321 | 323 |
@expose('json') |
322 |
def get_plugin_value(self,plugin_name,*arg,**krgv):
|
|
324 |
def get_plugin_value(self, plugin_name, *arg, **krgv):
|
|
323 | 325 |
""" |
324 | 326 |
Permet aux plugins de pouvoir récupérer des valeurs Json |
325 | 327 |
""" |
326 |
plugin = [i for i in tg.config['vigiboard_plugins'] if i[0] == plugin_name][0] |
|
328 |
plugin = [i for i in tg.config['vigiboard_plugins'] \ |
|
329 |
if i[0] == plugin_name][0] |
|
327 | 330 |
try: |
328 | 331 |
mypac = __import__( |
329 |
'vigiboard.controllers.vigiboard_plugin.' +\
|
|
330 |
plugin[0],globals(), locals(), [plugin[1]],-1)
|
|
331 |
p = getattr(mypac,plugin[1])()
|
|
332 |
return p.controller(*arg,**krgv)
|
|
332 |
'vigiboard.controllers.vigiboard_plugin.' + plugin[0],
|
|
333 |
globals(), locals(), [plugin[1]], -1)
|
|
334 |
plug = getattr(mypac, plugin[1])()
|
|
335 |
return plug.controller(*arg, **krgv)
|
|
333 | 336 |
except: |
334 | 337 |
raise |
335 | 338 |
|
336 |
@validate(validators={"fontsize":validators.Int()}, error_handler=process_form_errors) |
|
339 |
@validate(validators= {"fontsize": validators.Int()}, |
|
340 |
error_handler = process_form_errors) |
|
337 | 341 |
@expose('json') |
338 |
def set_fontsize(self,fontsize): |
|
339 |
try:
|
|
340 |
session['fontsize'] = fontsize
|
|
341 |
session.save()
|
|
342 |
return dict(ret='ok')
|
|
343 |
except:
|
|
344 |
return dict(ret='fail')
|
|
342 |
def set_fontsize(self, fontsize):
|
|
343 |
"""
|
|
344 |
Save font size
|
|
345 |
"""
|
|
346 |
session['fontsize'] = fontsize
|
|
347 |
session.save()
|
|
348 |
return dict(ret= 'ok')
|
|
345 | 349 |
|
346 |
@validate(validators={"refresh":validators.Int()}, error_handler=process_form_errors) |
|
350 |
@validate(validators= {"refresh": validators.Int()}, |
|
351 |
error_handler = process_form_errors) |
|
347 | 352 |
@expose('json') |
348 |
def set_refresh(self,refresh): |
|
349 |
try: |
|
350 |
session['refresh'] = refresh |
|
351 |
session.save() |
|
352 |
return dict(ret='ok') |
|
353 |
except: |
|
354 |
return dict(ret='fail') |
|
355 |
|
|
353 |
def set_refresh(self, refresh): |
|
354 |
""" |
|
355 |
Save refresh time |
|
356 |
""" |
|
357 |
session['refresh'] = refresh |
|
358 |
session.save() |
|
359 |
return dict(ret= 'ok') |
vigiboard/controllers/secure.py | ||
---|---|---|
17 | 17 |
|
18 | 18 |
# The predicate that must be met for all the actions in this controller: |
19 | 19 |
allow_only = has_permission('manage', |
20 |
msg=l_('Only for people with the "manage" permission'))
|
|
20 |
msg=l_('Only for people with the "manage" permission')) |
|
21 | 21 |
|
22 | 22 |
@expose('vigiboard.templates.index') |
23 | 23 |
def index(self): |
vigiboard/controllers/template.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
"""Fallback controller.""" |
|
3 |
|
|
4 |
from vigiboard.lib.base import BaseController |
|
5 |
|
|
6 |
__all__ = ['TemplateController'] |
|
7 |
|
|
8 |
|
|
9 |
class TemplateController(BaseController): |
|
10 |
""" |
|
11 |
The fallback controller for vigiboard. |
|
12 |
|
|
13 |
By default, the final controller tried to fulfill the request |
|
14 |
when no other routes match. It may be used to display a template |
|
15 |
when all else fails, e.g.:: |
|
16 |
|
|
17 |
def view(self, url): |
|
18 |
return render('/%s' % url) |
|
19 |
|
|
20 |
Or if you're using Mako and want to explicitly send a 404 (Not |
|
21 |
Found) response code when the requested template doesn't exist:: |
|
22 |
|
|
23 |
import mako.exceptions |
|
24 |
|
|
25 |
def view(self, url): |
|
26 |
try: |
|
27 |
return render('/%s' % url) |
|
28 |
except mako.exceptions.TopLevelLookupException: |
|
29 |
abort(404) |
|
30 |
|
|
31 |
""" |
|
32 |
|
|
33 |
def view(self, url): |
|
34 |
"""Abort the request with a 404 HTTP status code.""" |
|
35 |
abort(404) |
vigiboard/controllers/vigiboard_controller.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
3 |
from tg import expose, flash, require, url, request, redirect, config |
|
3 |
""" |
|
4 |
Controller for authentification |
|
5 |
""" |
|
6 |
|
|
7 |
from tg import expose, flash, require, url, request, redirect |
|
4 | 8 |
|
5 | 9 |
from pylons.i18n import ugettext as _, lazy_ugettext as l_ |
6 | 10 |
from catwalk.tg2 import Catwalk |
... | ... | |
11 | 15 |
from vigiboard.controllers.error import ErrorController |
12 | 16 |
from vigiboard import model |
13 | 17 |
from vigiboard.controllers.secure import SecureController |
14 |
class Vigiboard_RootController(BaseController):
|
|
18 |
class VigiboardRootController(BaseController): |
|
15 | 19 |
""" |
16 | 20 |
The root controller for the vigiboard application. |
17 | 21 |
|
... | ... | |
31 | 35 |
|
32 | 36 |
error = ErrorController() |
33 | 37 |
|
34 |
# # on charge les controleurs souhaité en dynamique |
|
35 |
# def __init__(self) : |
|
36 |
# super(RootController,self).__init__() |
|
37 |
# a = config['app_conf']['appname'] |
|
38 |
# p = __import__(a + '.config.' + a,globals(), locals(), [a + '_config'],-1) |
|
39 |
# print getattr(p,a + '_config') |
|
40 |
# |
|
41 |
# for mod in config['vigilo_mods']: |
|
42 |
# try : |
|
43 |
# mymod = __import__( |
|
44 |
# 'vigiboard.controllers.' + mod + '_ctl',globals(), locals(), [mod + 'Controller'],-1) |
|
45 |
# setattr(self,mod,getattr(mymod,mod + 'Controller')()) |
|
46 |
# except: |
|
47 |
# pass |
|
48 |
|
|
49 |
# @expose('vigiboard.templates.index') |
|
50 |
# def index(self): |
|
51 |
# """Handle the front-page.""" |
|
52 |
# return dict(page='index') |
|
53 |
# |
|
54 |
# @expose('vigiboard.templates.about') |
|
55 |
# def about(self): |
|
56 |
# """Handle the 'about' page.""" |
|
57 |
# return dict(page='about') |
|
58 |
|
|
59 | 38 |
@expose('vigiboard.templates.authentication') |
60 | 39 |
def auth(self): |
61 | 40 |
"""Display some information about auth* on this application.""" |
vigiboard/controllers/vigiboard_plugin/__init__.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
3 |
""" |
|
4 |
Generic plugin |
|
5 |
""" |
|
6 |
|
|
7 |
from pylons.i18n import ugettext as _ |
|
3 | 8 |
|
4 | 9 |
class VigiboardRequestPlugin(object): |
5 | 10 |
|
... | ... | |
48 | 53 |
|
49 | 54 |
return '' |
50 | 55 |
|
51 |
def context(self,context): |
|
56 |
def context(self, context):
|
|
52 | 57 |
|
53 | 58 |
""" |
54 | 59 |
Fonction permettant de rajouter du context à la page d'évènements, |
vigiboard/controllers/vigiboard_plugin/shn.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
3 |
""" |
|
4 |
Plugin SHN : High level service |
|
5 |
""" |
|
3 | 6 |
|
4 | 7 |
from vigiboard.controllers.vigiboard_plugin import \ |
5 | 8 |
VigiboardRequestPlugin |
6 |
from vigiboard.model import DBSession, ServiceHautNiveau, Events, Service
|
|
7 |
from sqlalchemy import sql, asc
|
|
9 |
from vigiboard.model import DBSession, ServiceHautNiveau, Events |
|
10 |
from sqlalchemy import sql |
|
8 | 11 |
from pylons.i18n import ugettext as _ |
9 |
from tg import tmpl_context,config,url
|
|
12 |
from tg import tmpl_context, url
|
|
10 | 13 |
from tw.jquery.ui_dialog import JQueryUIDialog |
11 | 14 |
|
12 | 15 |
class PluginSHN (VigiboardRequestPlugin): |
... | ... | |
17 | 20 |
""" |
18 | 21 |
|
19 | 22 |
def __init__(self): |
20 |
super(PluginSHN,self).__init__( |
|
23 |
super(PluginSHN, self).__init__(
|
|
21 | 24 |
table = [ServiceHautNiveau.servicename_dep, |
22 | 25 |
sql.func.count(Events.idevent)], |
23 | 26 |
outerjoin = [(ServiceHautNiveau, |
24 | 27 |
ServiceHautNiveau.servicename_dep == Events.servicename)], |
25 | 28 |
groupby = [(Events),(ServiceHautNiveau.servicename_dep)], |
26 | 29 |
name = _(u'SHNs impacté'), |
27 |
style = {'title':u'Services de haut niveau impactés','style':'text-align:center'}, |
|
30 |
style = {'title': u'Services de haut niveau impactés', |
|
31 |
'style': 'text-align:center'}, |
|
28 | 32 |
object_name = "shn" |
29 | 33 |
) |
30 | 34 |
|
31 | 35 |
def show(self, req): |
32 | 36 |
"""Fonction d'affichage""" |
33 | 37 |
if req[1] : |
34 |
return '<a href="javascript:vigiboard_shndialog(\'%s\',\'%d\')" class="SHNLien">%s</a>' % (url(''), req[0].idevent, req[2]) |
|
38 |
return '<a href="javascript:vigiboard_shndialog(\'%s\',\'%d\')"' + \ |
|
39 |
' class="SHNLien">%s</a>' % (url(''), req[0].idevent, req[2]) |
|
35 | 40 |
else : |
36 | 41 |
return "" |
37 | 42 |
|
38 |
def context(self,context): |
|
43 |
def context(self, context):
|
|
39 | 44 |
"""Fonction de context""" |
40 | 45 |
|
41 | 46 |
tmpl_context.shndialog = JQueryUIDialog(id='SHNDialog', |
42 |
autoOpen=False,title='%s%s' % (_('Service de haut niveau'),' ')) |
|
43 |
context.append([tmpl_context.shndialog,self.object_name]) |
|
47 |
autoOpen=False, title='%s%s' % (_('Service de haut niveau'), |
|
48 |
' ')) |
|
49 |
context.append([tmpl_context.shndialog, self.object_name]) |
|
44 | 50 |
|
45 |
def controller(self,*argv,**krgv): |
|
51 |
def controller(self, *argv, **krgv): |
|
52 |
"""Ajout de fonctionnalités au controlleur""" |
|
46 | 53 |
idevent = krgv['idevent'] |
47 |
e = DBSession.query(Events.servicename).filter(Events.idevent == idevent) |
|
48 |
s = e.one().servicename |
|
49 |
e = DBSession.query(ServiceHautNiveau.servicename).filter(ServiceHautNiveau.servicename_dep == s) |
|
50 |
return dict( shns = [ee.servicename for ee in e]) |
|
54 |
service = DBSession.query(Events.servicename |
|
55 |
).filter(Events.idevent == idevent).one().servicename |
|
56 |
|
|
57 |
shns = DBSession.query(ServiceHautNiveau.servicename |
|
58 |
).filter(ServiceHautNiveau.servicename_dep == service) |
|
59 |
return dict( shns = [shn.servicename for shn in shns]) |
|
51 | 60 |
|
vigiboard/controllers/vigiboard_plugin/tests.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
3 |
""" |
|
4 |
Plugin for tests |
|
5 |
""" |
|
3 | 6 |
|
4 | 7 |
from vigiboard.controllers.vigiboard_plugin.shn import \ |
5 | 8 |
PluginSHN |
... | ... | |
9 | 12 |
"""Plugin de test""" |
10 | 13 |
|
11 | 14 |
def __init__(self): |
12 |
super(PluginSHN,self).__init__( |
|
15 |
PluginSHN.__init__( |
|
16 |
self, |
|
13 | 17 |
table = [EventHistory.idevent], |
14 | 18 |
join = [(EventHistory, EventHistory.idevent == Events.idevent)] |
15 | 19 |
) |
16 | 20 |
|
17 | 21 |
def show(self, req): |
18 |
"""Fonction d'affichage""" |
|
19 |
return req[1] |
|
20 |
|
|
22 |
"""Fonction d'affichage""" |
|
23 |
return req[1] |
vigiboard/controllers/vigiboardrequest.py | ||
---|---|---|
100 | 100 |
mypac = __import__( |
101 | 101 |
'vigiboard.controllers.vigiboard_plugin.' +\ |
102 | 102 |
plug[0],globals(), locals(), [plug[1]],-1) |
103 |
self.add_plugin(getattr(mypac,plug[1])()) |
|
103 |
self.add_plugin(getattr(mypac, plug[1])())
|
|
104 | 104 |
except: |
105 | 105 |
raise |
106 | 106 |
|
... | ... | |
274 | 274 |
|
275 | 275 |
# Liste des éléments pour la tête du tableau |
276 | 276 |
|
277 |
lst_title = [['',{}], [_('Date')+ '<span style="font-weight:normal">' + _('<br />[Duration]') + '</span>', {'style':'text-align:left'}], ['#',{'title':_('Nombre d\'occurrences')}], [_('Host'),{'style':'text-align:left'}], |
|
278 |
[_('Service Type<br />Service Name'),{'style':'text-align:left'}], [_('Output'),{'style':'text-align:left'}]] |
|
279 |
lst_title.extend([[plug.name,plug.style] for plug in self.plugin]) |
|
280 |
lst_title.extend([[_('[TT]'),{'title':_('Trouble Ticket')}], ['',{}]]) |
|
277 |
lst_title = [ |
|
278 |
['',{}], |
|
279 |
[_('Date')+ '<span style="font-weight:normal">' + \ |
|
280 |
_('<br />[Duration]') + '</span>', |
|
281 |
{'style':'text-align:left'}], |
|
282 |
['#', {'title':_('Nombre d\'occurrences')}], |
|
283 |
[_('Host'), {'style':'text-align:left'}], |
|
284 |
[_('Service Type<br />Service Name'), |
|
285 |
{'style':'text-align:left'}], |
|
286 |
[_('Output'), {'style':'text-align:left'}] |
|
287 |
] |
|
288 |
lst_title.extend([[plug.name, plug.style] for plug in self.plugin]) |
|
289 |
lst_title.extend([[_('[TT]'), {'title': _('Trouble Ticket')}], |
|
290 |
['', {}]]) |
|
281 | 291 |
events = [lst_title] |
282 | 292 |
i = 0 |
283 | 293 |
class_tr = ['odd', 'even'] |
... | ... | |
358 | 368 |
hists = {} |
359 | 369 |
i = 0 |
360 | 370 |
class_tr = ['odd', 'even'] |
361 |
hostname = self.events[1][0].hostname |
|
362 |
servicename = self.events[1][0].servicename |
|
363 | 371 |
hist_tmp = [] |
364 | 372 |
last_idevent = history[0].idevent |
365 | 373 |
for hist in history : |
Also available in: Unified diff