Revision 57f7cb3f
Rename non-conflicting files.
git ls-files |while read f; do
mkdir p "../vigiboard/$(dirname "$f")"; git mv - "$f" "../vigiboard/$f";
done
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@485 b22e2e97-25c9-44ff-b637-2e5ceca36478
README.txt | ||
---|---|---|
1 |
Vigiboard Module |
vigiboard/config/app_cfg.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
""" |
|
3 |
Global configuration file for TG2-specific settings in vigiboard. |
|
4 |
|
|
5 |
This file complements development/deployment.ini. |
|
6 |
|
|
7 |
Please note that **all the argument values are strings**. If you want to |
|
8 |
convert them into boolean, for example, you should use the |
|
9 |
:func:`paste.deploy.converters.asbool` function, as in:: |
|
10 |
|
|
11 |
from paste.deploy.converters import asbool |
|
12 |
setting = asbool(global_conf.get('the_setting')) |
|
13 |
|
|
14 |
""" |
|
15 |
|
|
16 |
from tg.configuration import AppConfig |
|
17 |
|
|
18 |
import vigiboard |
|
19 |
from vigiboard import model |
|
20 |
from vigiboard.lib import app_globals, helpers |
|
21 |
|
|
22 |
base_config = AppConfig() |
|
23 |
base_config.renderers = [] |
|
24 |
|
|
25 |
base_config.package = vigiboard |
|
26 |
|
|
27 |
#Set the default renderer |
|
28 |
base_config.default_renderer = 'genshi' |
|
29 |
base_config.renderers.append('genshi') |
|
30 |
# if you want raw speed and have installed chameleon.genshi |
|
31 |
# you should try to use this renderer instead. |
|
32 |
# warning: for the moment chameleon does not handle i18n translations |
|
33 |
#base_config.renderers.append('chameleon_genshi') |
|
34 |
|
|
35 |
#Configure the base SQLALchemy Setup |
|
36 |
base_config.use_sqlalchemy = True |
|
37 |
base_config.model = vigiboard.model |
|
38 |
base_config.DBSession = vigiboard.model.DBSession |
|
39 |
|
|
40 |
# Configure the authentication backend |
|
41 |
base_config.auth_backend = 'sqlalchemy' |
|
42 |
base_config.sa_auth.dbsession = model.DBSession |
|
43 |
# what is the class you want to use to search for users in the database |
|
44 |
base_config.sa_auth.user_class = model.User |
|
45 |
# what is the class you want to use to search for groups in the database |
|
46 |
base_config.sa_auth.group_class = model.Group |
|
47 |
# what is the class you want to use to search for permissions in the database |
|
48 |
base_config.sa_auth.permission_class = model.Permission |
|
49 |
|
|
50 |
# override this if you would like to provide a different who plugin for |
|
51 |
# managing login and logout of your application |
|
52 |
base_config.sa_auth.form_plugin = None |
|
53 |
|
|
54 |
# You may optionally define a page where you want users to be redirected to |
|
55 |
# on login: |
|
56 |
base_config.sa_auth.post_login_url = '/post_login' |
|
57 |
|
|
58 |
# You may optionally define a page where you want users to be redirected to |
|
59 |
# on logout: |
|
60 |
base_config.sa_auth.post_logout_url = '/post_logout' |
vigiboard/config/deployment.ini_tmpl | ||
---|---|---|
1 |
# |
|
2 |
# vigiboard - TurboGears configuration |
|
3 |
# |
|
4 |
# The %(here)s variable will be replaced with the parent directory of this file |
|
5 |
# |
|
6 |
[DEFAULT] |
|
7 |
# WARGING == If debug is not set to false, you'll get the interactive |
|
8 |
# debugger on production, which is a huge security hole. |
|
9 |
|
|
10 |
debug = false |
|
11 |
email_to = you@yourdomain.com |
|
12 |
smtp_server = localhost |
|
13 |
error_email_from = paste@localhost |
|
14 |
|
|
15 |
[server:main] |
|
16 |
use = egg:Paste#http |
|
17 |
host = 0.0.0.0 |
|
18 |
port = 8080 |
|
19 |
|
|
20 |
[app:main] |
|
21 |
use = egg:vigiboard |
|
22 |
full_stack = true |
|
23 |
cache_dir = %(here)s/data |
|
24 |
beaker.session.key = vigiboard |
|
25 |
beaker.session.secret = ${app_instance_secret} |
|
26 |
app_instance_uuid = ${app_instance_uuid} |
|
27 |
|
|
28 |
# If you'd like to fine-tune the individual locations of the cache data dirs |
|
29 |
# for the Cache data, or the Session saves, un-comment the desired settings |
|
30 |
# here: |
|
31 |
#beaker.cache.data_dir = %(here)s/data/cache |
|
32 |
#beaker.session.data_dir = %(here)s/data/sessions |
|
33 |
# Specify the database for SQLAlchemy to use via |
|
34 |
# turbogears.database |
|
35 |
# %(here) may include a ':' character on Windows environments; this can |
|
36 |
# invalidate the URI when specifying a SQLite db via path name |
|
37 |
sqlalchemy.url = sqlite:///%(here)s/somedb.db |
|
38 |
sqlalchemy.echo = False |
|
39 |
|
|
40 |
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* |
|
41 |
# Debug mode will enable the interactive debugging tool, allowing ANYONE to |
|
42 |
# execute malicious code after an exception is raised. |
|
43 |
#set debug = false |
|
44 |
|
|
45 |
# Logging configuration |
|
46 |
# Add additional loggers, handlers, formatters here |
|
47 |
# Uses python's logging config file format |
|
48 |
# http://docs.python.org/lib/logging-config-fileformat.html |
|
49 |
|
|
50 |
[loggers] |
|
51 |
keys = root, vigiboard, sqlalchemy, auth |
|
52 |
|
|
53 |
[handlers] |
|
54 |
keys = console |
|
55 |
|
|
56 |
[formatters] |
|
57 |
keys = generic |
|
58 |
|
|
59 |
# If you create additional loggers, add them as a key to [loggers] |
|
60 |
[logger_root] |
|
61 |
level = INFO |
|
62 |
handlers = console |
|
63 |
|
|
64 |
[logger_vigiboard] |
|
65 |
level = INFO |
|
66 |
handlers = |
|
67 |
qualname = vigiboard |
|
68 |
|
|
69 |
[logger_sqlalchemy] |
|
70 |
level = WARN |
|
71 |
handlers = |
|
72 |
qualname = sqlalchemy.engine |
|
73 |
# "level = INFO" logs SQL queries. |
|
74 |
# "level = DEBUG" logs SQL queries and results. |
|
75 |
# "level = WARN" logs neither. (Recommended for production systems.) |
|
76 |
|
|
77 |
|
|
78 |
# A logger for authentication, identification and authorization -- this is |
|
79 |
# repoze.who and repoze.what: |
|
80 |
[logger_auth] |
|
81 |
level = WARN |
|
82 |
handlers = |
|
83 |
qualname = auth |
|
84 |
|
|
85 |
# If you create additional handlers, add them as a key to [handlers] |
|
86 |
[handler_console] |
|
87 |
class = StreamHandler |
|
88 |
args = (sys.stderr,) |
|
89 |
level = NOTSET |
|
90 |
formatter = generic |
|
91 |
|
|
92 |
# If you create additional formatters, add them as a key to [formatters] |
|
93 |
[formatter_generic] |
|
94 |
format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
95 |
datefmt = %H:%M:%S |
vigiboard/config/environment.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
"""WSGI environment setup for vigiboard.""" |
|
3 |
|
|
4 |
from vigiboard.config.app_cfg import base_config |
|
5 |
|
|
6 |
__all__ = ['load_environment'] |
|
7 |
|
|
8 |
#Use base_config to setup the environment loader function |
|
9 |
load_environment = base_config.make_load_environment() |
vigiboard/config/middleware.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
|
|
4 |
"""WSGI middleware initialization for the vigiboard application.""" |
|
5 |
from vigiboard.config.app_cfg import base_config |
|
6 |
from vigiboard.config.environment import load_environment |
|
7 |
from vigiboard.config.vigiboard_conf import vigiboard_config |
|
8 |
from paste.cascade import Cascade |
|
9 |
from paste.urlparser import StaticURLParser |
|
10 |
|
|
11 |
__all__ = ['make_app'] |
|
12 |
|
|
13 |
# Use base_config to setup the necessary PasteDeploy application factory. |
|
14 |
# make_base_app will wrap the TG2 app with all the middleware it needs. |
|
15 |
make_base_app = base_config.setup_tg_wsgi_app(load_environment) |
|
16 |
|
|
17 |
|
|
18 |
def make_app(global_conf, full_stack=True, **app_conf): |
|
19 |
""" |
|
20 |
Set vigiboard up with the settings found in the PasteDeploy configuration |
|
21 |
file used. |
|
22 |
|
|
23 |
:param global_conf: The global settings for vigiboard (those |
|
24 |
defined under the ``[DEFAULT]`` section). |
|
25 |
:type global_conf: dict |
|
26 |
:param full_stack: Should the whole TG2 stack be set up? |
|
27 |
:type full_stack: str or bool |
|
28 |
:return: The vigiboard application with all the relevant middleware |
|
29 |
loaded. |
|
30 |
|
|
31 |
This is the PasteDeploy factory for the vigiboard application. |
|
32 |
|
|
33 |
``app_conf`` contains all the application-specific settings (those defined |
|
34 |
under ``[app:main]``. |
|
35 |
|
|
36 |
|
|
37 |
""" |
|
38 |
# Petit hack permettant d'importer la configuration de vigiboard |
|
39 |
try: |
|
40 |
# chargement de l'application |
|
41 |
|
|
42 |
myapp = __import__(app_conf['appname'] ,globals(), locals(), [],-1) |
|
43 |
base_config.package = myapp |
|
44 |
|
|
45 |
# chargement de la conf de l'application |
|
46 |
myconf = __import__( |
|
47 |
app_conf['appname'] + '.config.' + app_conf['appname'] ,globals(), locals(), [app_conf['appname'] + '_config'],-1) |
|
48 |
myconf = getattr(myconf,app_conf['appname'] + '_config') |
|
49 |
for conf in myconf: |
|
50 |
app_conf[conf] = myconf[conf] |
|
51 |
except: |
|
52 |
print "vigilo-core runing without application" |
|
53 |
|
|
54 |
for i in vigiboard_config: |
|
55 |
app_conf[i] = vigiboard_config[i] |
|
56 |
|
|
57 |
# on cré l'application de base |
|
58 |
app = make_base_app(global_conf, full_stack=True, **app_conf) |
|
59 |
|
|
60 |
# on rajoute le path public de l'application |
|
61 |
import vigiboard |
|
62 |
app = Cascade([ |
|
63 |
StaticURLParser(global_conf['here'] + '/' + app_conf['appname'] + '/public'), |
|
64 |
StaticURLParser(vigiboard.__file__.rsplit('/',1)[0] + '/public'),app] |
|
65 |
) |
|
66 |
|
|
67 |
return app |
vigiboard/config/vigiboard_conf.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""Configuration de Vigiboard.""" |
|
4 |
|
|
5 |
vigiboard_config = { |
|
6 |
'vigiboard_bdd.basename' : '' |
|
7 |
} |
vigiboard/controllers/controller.template | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
"""Sample controller module""" |
|
3 |
|
|
4 |
# turbogears imports |
|
5 |
from tg import expose |
|
6 |
#from tg import redirect, validate, flash |
|
7 |
|
|
8 |
# third party imports |
|
9 |
#from pylons.i18n import ugettext as _ |
|
10 |
#from repoze.what import predicates |
|
11 |
|
|
12 |
# project specific imports |
|
13 |
from vigiboard.lib.base import BaseController |
|
14 |
#from vigiboard.model import DBSession, metadata |
|
15 |
|
|
16 |
|
|
17 |
class SampleController(BaseController): |
|
18 |
#Uncomment this line if your controller requires an authenticated user |
|
19 |
#allow_only = authorize.not_anonymous() |
|
20 |
|
|
21 |
@expose('vigiboard.templates.index') |
|
22 |
def index(self): |
|
23 |
return dict(page='index') |
vigiboard/controllers/error.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
"""Error controller""" |
|
3 |
|
|
4 |
from tg import request, expose |
|
5 |
|
|
6 |
__all__ = ['ErrorController'] |
|
7 |
|
|
8 |
|
|
9 |
class ErrorController(object): |
|
10 |
""" |
|
11 |
Generates error documents as and when they are required. |
|
12 |
|
|
13 |
The ErrorDocuments middleware forwards to ErrorController when error |
|
14 |
related status codes are returned from the application. |
|
15 |
|
|
16 |
This behaviour can be altered by changing the parameters to the |
|
17 |
ErrorDocuments middleware in your config/middleware.py file. |
|
18 |
|
|
19 |
""" |
|
20 |
|
|
21 |
@expose('vigiboard.templates.error') |
|
22 |
def document(self, *args, **kwargs): |
|
23 |
"""Render the error document""" |
|
24 |
resp = request.environ.get('pylons.original_response') |
|
25 |
default_message = ("<p>We're sorry but we weren't able to process " |
|
26 |
" this request.</p>") |
|
27 |
values = dict(prefix=request.environ.get('SCRIPT_NAME', ''), |
|
28 |
code=request.params.get('code', resp.status_int), |
|
29 |
message=request.params.get('message', default_message)) |
|
30 |
return values |
vigiboard/controllers/secure.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
"""Sample controller with all its actions protected.""" |
|
3 |
from tg import expose, flash |
|
4 |
from pylons.i18n import ugettext as _, lazy_ugettext as l_ |
|
5 |
from repoze.what.predicates import has_permission |
|
6 |
#from dbsprockets.dbmechanic.frameworks.tg2 import DBMechanic |
|
7 |
#from dbsprockets.saprovider import SAProvider |
|
8 |
|
|
9 |
from vigiboard.lib.base import BaseController |
|
10 |
#from vigiboard.model import DBSession, metadata |
|
11 |
|
|
12 |
__all__ = ['SecureController'] |
|
13 |
|
|
14 |
|
|
15 |
class SecureController(BaseController): |
|
16 |
"""Sample controller-wide authorization""" |
|
17 |
|
|
18 |
# The predicate that must be met for all the actions in this controller: |
|
19 |
allow_only = has_permission('manage', |
|
20 |
msg=l_('Only for people with the "manage" permission')) |
|
21 |
|
|
22 |
@expose('vigiboard.templates.index') |
|
23 |
def index(self): |
|
24 |
"""Let the user know that's visiting a protected controller.""" |
|
25 |
flash(_("Secure Controller here")) |
|
26 |
return dict(page='index') |
|
27 |
|
|
28 |
@expose('vigiboard.templates.index') |
|
29 |
def some_where(self): |
|
30 |
"""Let the user know that this action is protected too.""" |
|
31 |
return dict(page='some_where') |
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/userutils.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""Fonctions utiles en rapport avec l'utilisateur""" |
|
4 |
|
|
5 |
from vigiboard.model import DBSession, Permission, Groups, GroupPermissions |
|
6 |
from sets import Set |
|
7 |
import tg |
|
8 |
|
|
9 |
def get_user_groups(): |
|
10 |
|
|
11 |
""" |
|
12 |
Permet de connaître l'ensemble des groups d'hôte et de service de vigiboard |
|
13 |
auquel l'utilisateur appartient |
|
14 |
|
|
15 |
@return: Liste des groups |
|
16 |
""" |
|
17 |
|
|
18 |
# Requête permettant d'obtenir les groups directs de l'utilisateur |
|
19 |
|
|
20 |
groups = DBSession.query(Groups.name).join( |
|
21 |
( GroupPermissions , Groups.name == GroupPermissions.groupname ), |
|
22 |
( Permission , |
|
23 |
Permission.permission_id == GroupPermissions.idpermission ) |
|
24 |
).filter(Permission.permission_name.in_( |
|
25 |
tg.request.environ.get('repoze.who.identity').get('permissions') |
|
26 |
)) |
|
27 |
|
|
28 |
lst_grp = Set([i.name for i in groups]) |
|
29 |
lst_tmp = lst_grp |
|
30 |
|
|
31 |
# On recherche maintenant les groupes indirect |
|
32 |
|
|
33 |
while len(lst_tmp) > 0: |
|
34 |
groups = DBSession.query(Groups.name).filter(Groups.parent.in_(lst_tmp)) |
|
35 |
tmp = Set([]) |
|
36 |
for i in groups : |
|
37 |
tmp.add(i.name) |
|
38 |
lst_grp.add(i.name) |
|
39 |
lst_tmp = tmp |
|
40 |
|
|
41 |
return lst_grp |
vigiboard/controllers/vigiboard_controller.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
from tg import expose, flash, require, url, request, redirect, config |
|
4 |
|
|
5 |
from pylons.i18n import ugettext as _, lazy_ugettext as l_ |
|
6 |
from catwalk.tg2 import Catwalk |
|
7 |
from repoze.what import predicates |
|
8 |
|
|
9 |
from vigiboard.lib.base import BaseController |
|
10 |
from vigiboard.model import DBSession |
|
11 |
from vigiboard.controllers.error import ErrorController |
|
12 |
from vigiboard import model |
|
13 |
from vigiboard.controllers.secure import SecureController |
|
14 |
class Vigiboard_RootController(BaseController): |
|
15 |
""" |
|
16 |
The root controller for the vigiboard application. |
|
17 |
|
|
18 |
All the other controllers and WSGI applications should be mounted on this |
|
19 |
controller. For example:: |
|
20 |
|
|
21 |
panel = ControlPanelController() |
|
22 |
another_app = AnotherWSGIApplication() |
|
23 |
|
|
24 |
Keep in mind that WSGI applications shouldn't be mounted directly: They |
|
25 |
must be wrapped around with :class:`tg.controllers.WSGIAppController`. |
|
26 |
|
|
27 |
""" |
|
28 |
secc = SecureController() |
|
29 |
|
|
30 |
admin = Catwalk(model, DBSession) |
|
31 |
|
|
32 |
error = ErrorController() |
|
33 |
|
|
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 |
@expose('vigiboard.templates.authentication') |
|
60 |
def auth(self): |
|
61 |
"""Display some information about auth* on this application.""" |
|
62 |
return dict(page='auth') |
|
63 |
|
|
64 |
@expose('vigiboard.templates.index') |
|
65 |
@require(predicates.has_permission('manage', msg=l_('Only for managers'))) |
|
66 |
def manage_permission_only(self, **kw): |
|
67 |
"""Illustrate how a page for managers only works.""" |
|
68 |
return dict(page='managers stuff') |
|
69 |
|
|
70 |
@expose('vigiboard.templates.index') |
|
71 |
@require(predicates.is_user('editor', msg=l_('Only for the editor'))) |
|
72 |
def editor_user_only(self, **kw): |
|
73 |
"""Illustrate how a page exclusive for the editor works.""" |
|
74 |
return dict(page='editor stuff') |
|
75 |
|
|
76 |
@expose('vigiboard.templates.login') |
|
77 |
def login(self, came_from=url('/')): |
|
78 |
"""Start the user login.""" |
|
79 |
login_counter = request.environ['repoze.who.logins'] |
|
80 |
if login_counter > 0: |
|
81 |
flash(_('Wrong credentials'), 'warning') |
|
82 |
return dict(page='login', login_counter=str(login_counter), |
|
83 |
came_from=came_from) |
|
84 |
|
|
85 |
@expose() |
|
86 |
def post_login(self, came_from=url('/')): |
|
87 |
""" |
|
88 |
Redirect the user to the initially requested page on successful |
|
89 |
authentication or redirect her back to the login page if login failed. |
|
90 |
|
|
91 |
""" |
|
92 |
if not request.identity: |
|
93 |
login_counter = request.environ['repoze.who.logins'] + 1 |
|
94 |
redirect(url('/login', came_from=came_from, __logins=login_counter)) |
|
95 |
userid = request.identity['repoze.who.userid'] |
|
96 |
flash(_('Welcome back, %s!') % userid) |
|
97 |
redirect(came_from) |
|
98 |
|
|
99 |
@expose() |
|
100 |
def post_logout(self, came_from=url('/')): |
|
101 |
""" |
|
102 |
Redirect the user to the initially requested page on logout and say |
|
103 |
goodbye as well. |
|
104 |
|
|
105 |
""" |
|
106 |
flash(_('We hope to see you soon!')) |
|
107 |
redirect(came_from) |
|
108 |
|
vigiboard/lib/__init__.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
|
vigiboard/lib/app_globals.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
|
|
3 |
"""The application's Globals object""" |
|
4 |
|
|
5 |
__all__ = ['Globals'] |
|
6 |
|
|
7 |
|
|
8 |
class Globals(object): |
|
9 |
"""Container for objects available throughout the life of the application. |
|
10 |
|
|
11 |
One instance of Globals is created during application initialization and |
|
12 |
is available during requests via the 'app_globals' variable. |
|
13 |
|
|
14 |
""" |
|
15 |
|
|
16 |
def __init__(self): |
|
17 |
"""Do nothing, by default.""" |
|
18 |
pass |
vigiboard/lib/base.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
|
|
3 |
"""The base Controller API.""" |
|
4 |
|
|
5 |
from tg import TGController, tmpl_context |
|
6 |
from tg.render import render |
|
7 |
from tg import request |
|
8 |
from pylons.i18n import _, ungettext, N_ |
|
9 |
from tw.api import WidgetBunch |
|
10 |
import vigiboard.model as model |
|
11 |
|
|
12 |
__all__ = ['Controller', 'BaseController'] |
|
13 |
|
|
14 |
|
|
15 |
class BaseController(TGController): |
|
16 |
""" |
|
17 |
Base class for the controllers in the application. |
|
18 |
|
|
19 |
Your web application should have one of these. The root of |
|
20 |
your application is used to compute URLs used by your app. |
|
21 |
|
|
22 |
""" |
|
23 |
|
|
24 |
def __call__(self, environ, start_response): |
|
25 |
"""Invoke the Controller""" |
|
26 |
# TGController.__call__ dispatches to the Controller method |
|
27 |
# the request is routed to. This routing information is |
|
28 |
# available in environ['pylons.routes_dict'] |
|
29 |
|
|
30 |
request.identity = request.environ.get('repoze.who.identity') |
|
31 |
tmpl_context.identity = request.identity |
|
32 |
return TGController.__call__(self, environ, start_response) |
vigiboard/lib/helpers.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
|
|
3 |
"""WebHelpers used in vigiboard.""" |
|
4 |
|
|
5 |
from webhelpers import date, feedgenerator, html, number, misc, text |
vigiboard/model/__init__.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
"""The application's model objects""" |
|
3 |
|
|
4 |
from zope.sqlalchemy import ZopeTransactionExtension |
|
5 |
from sqlalchemy.orm import scoped_session, sessionmaker |
|
6 |
#from sqlalchemy import MetaData |
|
7 |
from sqlalchemy.ext.declarative import declarative_base |
|
8 |
|
|
9 |
# Global session manager: DBSession() returns the Thread-local |
|
10 |
# session object appropriate for the current web request. |
|
11 |
maker = sessionmaker(autoflush=True, autocommit=False, |
|
12 |
extension=ZopeTransactionExtension()) |
|
13 |
DBSession = scoped_session(maker) |
|
14 |
|
|
15 |
# Base class for all of our model classes: By default, the data model is |
|
16 |
# defined with SQLAlchemy's declarative extension, but if you need more |
|
17 |
# control, you can switch to the traditional method. |
|
18 |
DeclarativeBase = declarative_base() |
|
19 |
|
|
20 |
# There are two convenient ways for you to spare some typing. |
|
21 |
# You can have a query property on all your model classes by doing this: |
|
22 |
# DeclarativeBase.query = DBSession.query_property() |
|
23 |
# Or you can use a session-aware mapper as it was used in TurboGears 1: |
|
24 |
# DeclarativeBase = declarative_base(mapper=DBSession.mapper) |
|
25 |
|
|
26 |
# Global metadata. |
|
27 |
# The default metadata is the one from the declarative base. |
|
28 |
metadata = DeclarativeBase.metadata |
|
29 |
|
|
30 |
# If you have multiple databases with overlapping table names, you'll need a |
|
31 |
# metadata for each database. Feel free to rename 'metadata2'. |
|
32 |
#metadata2 = MetaData() |
|
33 |
|
|
34 |
##### |
|
35 |
# Generally you will not want to define your table's mappers, and data objects |
|
36 |
# here in __init__ but will want to create modules them in the model directory |
|
37 |
# and import them at the bottom of this file. |
|
38 |
# |
|
39 |
###### |
|
40 |
|
|
41 |
def init_model(engine): |
|
42 |
"""Call me before using any of the tables or classes in the model.""" |
|
43 |
|
|
44 |
DBSession.configure(bind=engine) |
|
45 |
# If you are using reflection to introspect your database and create |
|
46 |
# table objects for you, your tables must be defined and mapped inside |
|
47 |
# the init_model function, so that the engine is available if you |
|
48 |
# use the model outside tg2, you need to make sure this is called before |
|
49 |
# you use the model. |
|
50 |
|
|
51 |
# |
|
52 |
# See the following example: |
|
53 |
|
|
54 |
#global t_reflected |
|
55 |
|
|
56 |
#t_reflected = Table("Reflected", metadata, |
|
57 |
# autoload=True, autoload_with=engine) |
|
58 |
|
|
59 |
#mapper(Reflected, t_reflected) |
|
60 |
|
|
61 |
# Import your model modules here. |
|
62 |
from vigiboard.model.auth import User, Group, Permission |
|
63 |
from vigiboard.model.vigilo_bdd import Events, EventHistory, Graph, \ |
|
64 |
GraphGroups, GraphToGroups, Groups, GroupPermissions, HostGroups, Host, \ |
|
65 |
PerfDataSource, ServiceGroups, ServiceHautNiveau, Service, ServiceTopo |
vigiboard/model/auth.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
""" |
|
3 |
Auth* related model. |
|
4 |
|
|
5 |
This is where the models used by :mod:`repoze.who` and :mod:`repoze.what` are |
|
6 |
defined. |
|
7 |
|
|
8 |
It's perfectly fine to re-use this definition in the vigiboard application, |
|
9 |
though. |
|
10 |
|
|
11 |
""" |
|
12 |
import os |
|
13 |
from datetime import datetime |
|
14 |
import sys |
|
15 |
try: |
|
16 |
from hashlib import sha1 |
|
17 |
except ImportError: |
|
18 |
sys.exit('ImportError: No module named hashlib\n' |
|
19 |
'If you are on python2.4 this library is not part of python. ' |
|
20 |
'Please install it. Example: easy_install hashlib') |
|
21 |
|
|
22 |
from sqlalchemy import Table, ForeignKey, Column |
|
23 |
from sqlalchemy.types import Unicode, Integer, DateTime |
|
24 |
from sqlalchemy.orm import relation, synonym |
|
25 |
|
|
26 |
from vigiboard.model import DeclarativeBase, metadata, DBSession |
|
27 |
|
|
28 |
__all__ = ['User', 'Group', 'Permission'] |
|
29 |
|
|
30 |
|
|
31 |
#{ Association tables |
|
32 |
|
|
33 |
|
|
34 |
# This is the association table for the many-to-many relationship between |
|
35 |
# groups and permissions. This is required by repoze.what. |
|
36 |
group_permission_table = Table('tg_group_permission', metadata, |
|
37 |
Column('group_id', Integer, ForeignKey('tg_group.group_id', |
|
38 |
onupdate="CASCADE", ondelete="CASCADE")), |
|
39 |
Column('permission_id', Integer, ForeignKey('tg_permission.permission_id', |
|
40 |
onupdate="CASCADE", ondelete="CASCADE")), |
|
41 |
mysql_engine='InnoDB', |
|
42 |
mysql_charset='utf8' |
|
43 |
) |
|
44 |
|
|
45 |
# This is the association table for the many-to-many relationship between |
|
46 |
# groups and members - this is, the memberships. It's required by repoze.what. |
|
47 |
user_group_table = Table('tg_user_group', metadata, |
|
48 |
Column('user_id', Integer, ForeignKey('tg_user.user_id', |
|
49 |
onupdate="CASCADE", ondelete="CASCADE")), |
|
50 |
Column('group_id', Integer, ForeignKey('tg_group.group_id', |
|
51 |
onupdate="CASCADE", ondelete="CASCADE")), |
|
52 |
mysql_engine='InnoDB', |
|
53 |
mysql_charset='utf8' |
|
54 |
) |
|
55 |
|
|
56 |
|
|
57 |
#{ The auth* model itself |
|
58 |
|
|
59 |
|
|
60 |
class Group(DeclarativeBase): |
|
61 |
""" |
|
62 |
Group definition for :mod:`repoze.what`. |
|
63 |
|
|
64 |
Only the ``group_name`` column is required by :mod:`repoze.what`. |
|
65 |
|
|
66 |
""" |
|
67 |
|
|
68 |
__tablename__ = 'tg_group' |
|
69 |
__table_args__ = {'mysql_engine':'InnoDB', 'mysql_charset':'utf8'} |
|
70 |
|
|
71 |
#{ Columns |
|
72 |
|
|
73 |
group_id = Column(Integer, autoincrement=True, primary_key=True) |
|
74 |
|
|
75 |
group_name = Column(Unicode(16), unique=True, nullable=False) |
|
76 |
|
|
77 |
display_name = Column(Unicode(255)) |
|
78 |
|
|
79 |
created = Column(DateTime, default=datetime.now) |
|
80 |
|
|
81 |
#{ Relations |
|
82 |
|
|
83 |
users = relation('User', secondary=user_group_table, backref='groups') |
|
84 |
|
|
85 |
#{ Special methods |
|
86 |
|
|
87 |
def __repr__(self): |
|
88 |
return '<Group: name=%s>' % self.group_name |
|
89 |
|
|
90 |
def __unicode__(self): |
|
91 |
return self.group_name |
|
92 |
|
|
93 |
#} |
|
94 |
|
|
95 |
|
|
96 |
# The 'info' argument we're passing to the email_address and password columns |
|
97 |
# contain metadata that Rum (http://python-rum.org/) can use generate an |
|
98 |
# admin interface for your models. |
|
99 |
class User(DeclarativeBase): |
|
100 |
""" |
|
101 |
User definition. |
|
102 |
|
|
103 |
This is the user definition used by :mod:`repoze.who`, which requires at |
|
104 |
least the ``user_name`` column. |
|
105 |
|
|
106 |
""" |
|
107 |
__tablename__ = 'tg_user' |
|
108 |
__table_args__ = {'mysql_engine':'InnoDB', 'mysql_charset':'utf8'} |
|
109 |
|
|
110 |
#{ Columns |
|
111 |
|
|
112 |
user_id = Column(Integer, autoincrement=True, primary_key=True) |
|
113 |
|
|
114 |
user_name = Column(Unicode(16), unique=True, nullable=False) |
|
115 |
|
|
116 |
email_address = Column(Unicode(255), unique=True, nullable=False, |
|
117 |
info={'rum': {'field':'Email'}}) |
|
118 |
|
|
119 |
display_name = Column(Unicode(255)) |
|
120 |
|
|
121 |
_password = Column('password', Unicode(80), |
|
122 |
info={'rum': {'field':'Password'}}) |
|
123 |
|
|
124 |
created = Column(DateTime, default=datetime.now) |
|
125 |
|
|
126 |
#{ Special methods |
|
127 |
|
|
128 |
def __repr__(self): |
|
129 |
return '<User: email="%s", display name="%s">' % ( |
|
130 |
self.email_address, self.display_name) |
|
131 |
|
|
132 |
def __unicode__(self): |
|
133 |
return self.display_name or self.user_name |
|
134 |
|
|
135 |
#{ Getters and setters |
|
136 |
|
|
137 |
@property |
|
138 |
def permissions(self): |
|
139 |
"""Return a set of strings for the permissions granted.""" |
|
140 |
perms = set() |
|
141 |
for g in self.groups: |
|
142 |
perms = perms | set(g.permissions) |
|
143 |
return perms |
|
144 |
|
|
145 |
@classmethod |
|
146 |
def by_email_address(cls, email): |
|
147 |
"""Return the user object whose email address is ``email``.""" |
|
148 |
return DBSession.query(cls).filter(cls.email_address==email).first() |
|
149 |
|
|
150 |
@classmethod |
|
151 |
def by_user_name(cls, username): |
|
152 |
"""Return the user object whose user name is ``username``.""" |
|
153 |
return DBSession.query(cls).filter(cls.user_name==username).first() |
|
154 |
|
|
155 |
def _set_password(self, password): |
|
156 |
"""Hash ``password`` on the fly and store its hashed version.""" |
|
157 |
hashed_password = password |
|
158 |
|
|
159 |
if isinstance(password, unicode): |
|
160 |
password_8bit = password.encode('UTF-8') |
|
161 |
else: |
|
162 |
password_8bit = password |
|
163 |
|
|
164 |
salt = sha1() |
|
165 |
salt.update(os.urandom(60)) |
|
166 |
hash = sha1() |
|
167 |
hash.update(password_8bit + salt.hexdigest()) |
|
168 |
hashed_password = salt.hexdigest() + hash.hexdigest() |
|
169 |
|
|
170 |
# Make sure the hashed password is an UTF-8 object at the end of the |
|
171 |
# process because SQLAlchemy _wants_ a unicode object for Unicode |
|
172 |
# columns |
|
173 |
if not isinstance(hashed_password, unicode): |
|
174 |
hashed_password = hashed_password.decode('UTF-8') |
|
175 |
|
|
176 |
self._password = hashed_password |
|
177 |
|
|
178 |
def _get_password(self): |
|
179 |
"""Return the hashed version of the password.""" |
|
180 |
return self._password |
|
181 |
|
|
182 |
password = synonym('_password', descriptor=property(_get_password, |
|
183 |
_set_password)) |
|
184 |
|
|
185 |
#} |
|
186 |
|
|
187 |
def validate_password(self, password): |
|
188 |
""" |
|
189 |
Check the password against existing credentials. |
|
190 |
|
|
191 |
:param password: the password that was provided by the user to |
|
192 |
try and authenticate. This is the clear text version that we will |
|
193 |
need to match against the hashed one in the database. |
|
194 |
:type password: unicode object. |
|
195 |
:return: Whether the password is valid. |
|
196 |
:rtype: bool |
|
197 |
|
|
198 |
""" |
|
199 |
hashed_pass = sha1() |
|
200 |
hashed_pass.update(password + self.password[:40]) |
|
201 |
return self.password[40:] == hashed_pass.hexdigest() |
|
202 |
|
|
203 |
|
|
204 |
class Permission(DeclarativeBase): |
|
205 |
""" |
|
206 |
Permission definition for :mod:`repoze.what`. |
|
207 |
|
|
208 |
Only the ``permission_name`` column is required by :mod:`repoze.what`. |
|
209 |
|
|
210 |
""" |
|
211 |
|
|
212 |
__tablename__ = 'tg_permission' |
|
213 |
__table_args__ = {'mysql_engine':'InnoDB', 'mysql_charset':'utf8'} |
|
214 |
|
|
215 |
#{ Columns |
|
216 |
|
|
217 |
permission_id = Column(Integer, autoincrement=True, primary_key=True) |
|
218 |
|
|
219 |
permission_name = Column(Unicode(16), unique=True, nullable=False) |
|
220 |
|
|
221 |
description = Column(Unicode(255)) |
|
222 |
|
|
223 |
#{ Relations |
|
224 |
|
|
225 |
groups = relation(Group, secondary=group_permission_table, |
|
226 |
backref='permissions') |
|
227 |
|
|
228 |
#{ Special methods |
|
229 |
|
|
230 |
def __repr__(self): |
|
231 |
return '<Permission: name=%s>' % self.permission_name |
|
232 |
|
|
233 |
def __unicode__(self): |
|
234 |
return self.permission_name |
|
235 |
|
|
236 |
#} |
|
237 |
|
|
238 |
|
|
239 |
#} |
vigiboard/model/model.template | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
"""Sample model module.""" |
|
3 |
|
|
4 |
from sqlalchemy import * |
|
5 |
from sqlalchemy.orm import mapper, relation |
|
6 |
from sqlalchemy import Table, ForeignKey, Column |
|
7 |
from sqlalchemy.types import Integer, Unicode |
|
8 |
#from sqlalchemy.orm import relation, backref |
|
9 |
|
|
10 |
from vigiboard.model import DeclarativeBase, metadata, DBSession |
|
11 |
|
|
12 |
|
|
13 |
class SampleModel(DeclarativeBase): |
|
14 |
__tablename__ = 'sample_model' |
|
15 |
|
|
16 |
#{ Columns |
|
17 |
|
|
18 |
id = Column(Integer, primary_key=True) |
|
19 |
|
|
20 |
data = Column(Unicode(255), nullable=False) |
|
21 |
|
|
22 |
#} |
vigiboard/model/vigilo_bdd/__init__.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""BdD Vigiboard""" |
|
4 |
|
|
5 |
from .eventhistory import EventHistory |
|
6 |
from .events import Events |
|
7 |
from .graphgroups import GraphGroups |
|
8 |
from .graph import Graph |
|
9 |
from .groups import Groups |
|
10 |
from .grouppermissions import GroupPermissions |
|
11 |
from .hostgroups import HostGroups |
|
12 |
from .host import Host |
|
13 |
from .perfdatasource import PerfDataSource |
|
14 |
from .servicegroups import ServiceGroups |
|
15 |
from .servicehautniveau import ServiceHautNiveau |
|
16 |
from .service import Service |
|
17 |
from .servicetopo import ServiceTopo |
|
18 |
from .graphtogroups import GraphToGroups |
|
19 |
from .version import Version |
|
20 |
from .state import State |
vigiboard/model/vigilo_bdd/eventhistory.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""Modèle pour la table EventHistory""" |
|
4 |
from __future__ import absolute_import |
|
5 |
from sqlalchemy.orm import mapper |
|
6 |
from sqlalchemy import ForeignKey, Table, Column |
|
7 |
from sqlalchemy.types import Integer, String, Text, DateTime |
|
8 |
|
|
9 |
from sqlalchemy.databases.mysql import MSEnum |
|
10 |
from datetime import datetime |
|
11 |
from ..vigilo_bdd_config import bdd_basename, metadata |
|
12 |
|
|
13 |
# Generation par SQLAutoCode |
|
14 |
|
|
15 |
event_history = Table( |
|
16 |
bdd_basename + 'event_history', metadata, |
|
17 |
Column(u'idhistory', Integer(), primary_key=True, nullable=False, |
|
18 |
autoincrement=True), |
|
19 |
Column(u'type_action', |
|
20 |
MSEnum('Nagios update state', 'Acknowlegement change state', |
|
21 |
'New occurence', 'User comment', 'Ticket change', 'Oncall', |
|
22 |
'Forced state'), |
|
23 |
primary_key=False, nullable=False), |
|
24 |
Column(u'idevent', Integer(), |
|
25 |
ForeignKey( |
|
26 |
bdd_basename +'events.idevent' |
|
27 |
), index=True, primary_key=False, nullable=False), |
|
28 |
Column(u'value', |
|
29 |
String(length=255, convert_unicode=True, assert_unicode=None), |
|
30 |
primary_key=False), |
|
31 |
Column(u'text', |
|
32 |
Text(length=None, convert_unicode=True, assert_unicode=None), |
|
33 |
primary_key=False), |
|
34 |
Column(u'timestamp', DateTime(timezone=False), default=datetime.now(), |
|
35 |
primary_key=False), |
|
36 |
Column(u'username', |
|
37 |
String(length=255, convert_unicode=True, assert_unicode=None), |
|
38 |
primary_key=False), |
|
39 |
mysql_engine='InnoDB', |
|
40 |
mysql_charset='utf8' |
|
41 |
) |
|
42 |
|
|
43 |
# Classe a mapper |
|
44 |
|
|
45 |
class EventHistory(object): |
|
46 |
""" |
|
47 |
Classe liée avec la table associée |
|
48 |
""" |
|
49 |
def __init__(self, type_action, idevent, value='', text='', username=''): |
|
50 |
|
|
51 |
""" |
|
52 |
Fonction d'initialisation, permet de faire un INSERT en une fonction |
|
53 |
|
|
54 |
@param type_action: Le type d'action effectué, peut être 'Nagios update state', |
|
55 |
'Acknowlegement change state', 'New occurence', 'User comment', 'Ticket change', |
|
56 |
'Oncall' ou 'Forced state' |
|
57 |
@param idevent: Identifiant de l'évènement |
|
58 |
@param value: Nouvelle sévérité |
|
59 |
@param text: Commentaire sur l'action effectuée |
|
60 |
@param username: Nom d'utilisateur de la personne effectuant l'action |
|
61 |
""" |
|
62 |
|
|
63 |
self.type_action = type_action |
|
64 |
self.idevent = idevent |
|
65 |
self.value = value |
|
66 |
self.text = text |
|
67 |
self.username = username |
|
68 |
|
|
69 |
mapper(EventHistory, event_history) |
vigiboard/model/vigilo_bdd/events.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""Modèle pour la table Events""" |
|
4 |
from __future__ import absolute_import |
|
5 |
|
|
6 |
from sqlalchemy.orm import mapper |
|
7 |
from sqlalchemy import Table, Column, DefaultClause, ForeignKey |
|
8 |
from sqlalchemy.types import Integer, String, Text, DateTime |
|
9 |
|
|
10 |
from sqlalchemy.databases.mysql import MSEnum, MSBoolean |
|
11 |
|
|
12 |
from datetime import datetime |
|
13 |
|
|
14 |
from ..vigilo_bdd_config import bdd_basename, metadata |
|
15 |
|
|
16 |
# Generation par SQLAutoCode |
|
17 |
|
|
18 |
events = Table(bdd_basename + 'events', metadata, |
|
19 |
Column(u'idevent', Integer(), primary_key=True, nullable=False, |
|
20 |
autoincrement=True), |
|
21 |
Column(u'hostname', |
|
22 |
String(length=100, convert_unicode=True, assert_unicode=None), |
|
23 |
ForeignKey(bdd_basename +'host.name'), |
|
24 |
index=True, primary_key=False, nullable=False), |
|
25 |
Column(u'servicename', |
|
26 |
String(length=100, convert_unicode=True, assert_unicode=None), |
|
27 |
ForeignKey(bdd_basename + 'service.name'), |
|
28 |
index=True, primary_key=False), |
|
29 |
Column(u'severity', Integer(), primary_key=False, nullable=False), |
|
30 |
Column(u'status', MSEnum('None','Acknowledged','AAClosed'), |
|
31 |
primary_key=False, nullable=False, |
|
32 |
server_default=DefaultClause('None', for_update=False)), |
|
33 |
Column(u'active', MSBoolean(), primary_key=False, default='True'), |
|
34 |
Column(u'timestamp', DateTime(timezone=False), primary_key=False), |
|
35 |
Column(u'output', |
|
36 |
Text(length=None, convert_unicode=True, assert_unicode=None), |
|
37 |
primary_key=False, nullable=False), |
|
38 |
Column(u'timestamp_active', DateTime(timezone=False), primary_key=False), |
|
39 |
Column(u'trouble_ticket', |
|
40 |
String(length=20, convert_unicode=True, assert_unicode=None), |
|
41 |
primary_key=False), |
|
42 |
Column(u'occurence', Integer(), primary_key=False), |
|
43 |
Column(u'impact', Integer(), primary_key=False), |
|
44 |
Column(u'rawstate', MSEnum('WARNING','OK','CRITICAL','UNKNOWN')), |
|
45 |
mysql_engine='InnoDB', |
|
46 |
mysql_charset='utf8' |
|
47 |
) |
|
48 |
|
|
49 |
# Classe a mapper |
|
50 |
|
|
51 |
class Events(object): |
|
52 |
|
|
53 |
""" |
|
54 |
Classe liée avec la table associée |
|
55 |
""" |
|
56 |
|
|
57 |
def __init__(self, hostname, servicename, server_source = '', severity = 0, |
|
58 |
status = 'None', active = True, timestamp = datetime.now(), |
|
59 |
output = '', event_timestamp = datetime.now(), |
|
60 |
last_check = datetime.now(), recover_output = '', |
|
61 |
timestamp_active = datetime.now(), |
|
62 |
timestamp_cleared=None, trouble_ticket = None, |
|
63 |
occurence = 1): |
|
64 |
|
|
65 |
self.hostname = hostname |
|
66 |
self.servicename = servicename |
|
67 |
self.server_source = server_source |
|
68 |
self.severity = severity |
|
69 |
self.status = status |
|
70 |
self.active = active |
|
71 |
self.timestamp = timestamp |
|
72 |
self.output = output |
|
73 |
self.event_timestamp = event_timestamp |
|
74 |
self.last_check = last_check |
|
75 |
self.recover_output = recover_output |
|
76 |
self.timestamp_active = timestamp_active |
|
77 |
self.timestamp_cleared = timestamp_cleared |
|
78 |
self.trouble_ticket = trouble_ticket |
|
79 |
self.occurence = occurence |
|
80 |
|
|
81 |
def get_date(self, element): |
|
82 |
|
|
83 |
""" |
|
84 |
Permet de convertir une variable de temps en la chaîne de caractère : |
|
85 |
jour mois heure:minutes:secondes |
|
86 |
|
|
87 |
@param element: nom de l'élément à convertir de la classe elle même |
|
88 |
""" |
|
89 |
|
|
90 |
element = self.__dict__[element] |
|
91 |
date = datetime.now() - element |
|
92 |
if date.days < 7 : |
|
93 |
return element.strftime('%a %H:%M:%S') |
|
94 |
else : |
|
95 |
return element.strftime('%d %b %H:%M:%S') |
|
96 |
|
|
97 |
def get_since_date(self, element): |
|
98 |
|
|
99 |
""" |
|
100 |
Permet d'obtenir le temps écoulé entre maintenant (datetime.now()) |
|
101 |
et le temps contenu dans la variable de temps indiquée |
|
102 |
|
|
103 |
@param element: nom de l'élément de la classe elle même à utiliser |
|
104 |
pour le calcul |
|
105 |
""" |
|
106 |
|
|
107 |
date = datetime.now() - self.__dict__[element] |
|
108 |
minutes, seconds = divmod(date.seconds, 60) |
|
109 |
hours, minutes = divmod(minutes, 60) |
|
110 |
return "%dd %dh %d'" % (date.days , hours , minutes) |
|
111 |
|
|
112 |
mapper(Events, events) |
vigiboard/model/vigilo_bdd/graph.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""Modèle pour la table Graph""" |
|
4 |
from __future__ import absolute_import |
|
5 |
|
|
6 |
from sqlalchemy.orm import mapper |
|
7 |
from sqlalchemy import Table, Column |
|
8 |
from sqlalchemy.types import String |
|
9 |
|
|
10 |
from ..vigilo_bdd_config import bdd_basename, metadata |
|
11 |
|
|
12 |
# Generation par SQLAutoCode |
|
13 |
|
|
14 |
graph = Table(bdd_basename + 'graph', |
|
15 |
metadata, |
|
16 |
Column(u'name', |
|
17 |
String(length=100, convert_unicode=True, assert_unicode=None), |
|
18 |
primary_key=True, nullable=False), |
|
19 |
Column(u'template', |
|
20 |
String(length=2500, convert_unicode=True, assert_unicode=None), |
|
21 |
primary_key=False, nullable=False), |
|
22 |
Column(u'vlabel', |
|
23 |
String(length=2500, convert_unicode=True, assert_unicode=None), |
|
24 |
primary_key=False, nullable=False), |
|
25 |
mysql_engine='InnoDB', |
|
26 |
mysql_charset='utf8' |
|
27 |
) |
|
28 |
|
|
29 |
# Classe a mapper |
|
30 |
|
|
31 |
class Graph(object): |
|
32 |
|
|
33 |
""" |
|
34 |
Classe liée avec la table associée |
|
35 |
""" |
|
36 |
|
|
37 |
def __init__(self, name, template = '', vlabel = ''): |
|
38 |
self.name = name |
|
39 |
self.template = template |
|
40 |
self.vlabel = vlabel |
|
41 |
|
|
42 |
mapper(Graph, graph) |
vigiboard/model/vigilo_bdd/graphgroups.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""Modèle pour la table GraphGroups""" |
|
4 |
from __future__ import absolute_import |
|
5 |
|
|
6 |
from sqlalchemy.orm import mapper |
|
7 |
from sqlalchemy import Table, Column |
|
8 |
from sqlalchemy.types import Integer, String |
|
9 |
|
|
10 |
from ..vigilo_bdd_config import bdd_basename, metadata |
|
11 |
|
|
12 |
# Generation par SQLAutoCode |
|
13 |
|
|
14 |
graphgroups = Table(bdd_basename + 'graphgroups', |
|
15 |
metadata, |
|
16 |
Column(u'name', |
|
17 |
String(length=100, convert_unicode=True, assert_unicode=None), |
|
18 |
primary_key=True, nullable=False), |
|
19 |
Column(u'parent', Integer(), primary_key=False, nullable=True), |
|
20 |
mysql_engine='InnoDB', |
|
21 |
mysql_charset='utf8' |
|
22 |
) |
|
23 |
|
|
24 |
# Classe a mapper |
|
25 |
|
|
26 |
class GraphGroups(object): |
|
27 |
""" |
|
28 |
Classe liée avec la table associée |
|
29 |
""" |
|
30 |
|
|
31 |
def __init__(self, name, parent=None): |
|
32 |
self.name = name |
|
33 |
self.parent = parent |
|
34 |
|
|
35 |
mapper(GraphGroups, graphgroups) |
vigiboard/model/vigilo_bdd/graphtogroups.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""Modèle pour la table GraphToGroups""" |
|
4 |
from __future__ import absolute_import |
|
5 |
|
|
6 |
from sqlalchemy.orm import mapper |
|
7 |
from sqlalchemy import Table, ForeignKey, Column |
|
8 |
from sqlalchemy.types import String |
|
9 |
|
|
10 |
from ..vigilo_bdd_config import bdd_basename, metadata |
|
11 |
|
|
12 |
# Generation par SQLAutoCode |
|
13 |
|
|
14 |
graphtogroups = Table( |
|
15 |
bdd_basename + 'graphtogroups', |
|
16 |
metadata, |
|
17 |
Column(u'graphname', |
|
18 |
String(length=100, convert_unicode=False, assert_unicode=None), |
|
19 |
ForeignKey(bdd_basename + 'graph.name'), |
|
20 |
primary_key=True, nullable=False), |
|
21 |
Column(u'groupname', |
|
22 |
String(length=100, convert_unicode=False, assert_unicode=None), |
|
23 |
ForeignKey(bdd_basename + \ |
|
24 |
'graphgroups.name'), |
|
25 |
primary_key=True, nullable=False), |
|
26 |
mysql_engine='InnoDB', |
|
27 |
mysql_charset='utf8' |
|
28 |
) |
|
29 |
|
|
30 |
# Classe a mapper |
|
31 |
|
|
32 |
class GraphToGroups(object): |
|
33 |
""" |
|
34 |
Classe liée avec la table associée |
|
35 |
""" |
|
36 |
|
|
37 |
def __init__(self, graphname, groupname): |
|
38 |
self.graphname = graphname |
|
39 |
self.groupname = groupname |
|
40 |
|
|
41 |
|
|
42 |
mapper(GraphToGroups, graphtogroups) |
vigiboard/model/vigilo_bdd/grouppermissions.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""Modèle pour la table GroupPermissions""" |
|
4 |
from __future__ import absolute_import |
|
5 |
|
|
6 |
from sqlalchemy.orm import mapper |
|
7 |
from sqlalchemy import Table, ForeignKey, Column |
|
8 |
from sqlalchemy.types import Integer, String |
|
9 |
|
|
10 |
from ..vigilo_bdd_config import bdd_basename, metadata |
|
11 |
|
|
12 |
# Generation par SQLAutoCode |
|
13 |
|
|
14 |
grouppermissions = Table( |
|
15 |
bdd_basename + 'grouppermissions', |
|
16 |
metadata, |
|
17 |
Column(u'groupname', |
|
18 |
String(length=100, convert_unicode=True, assert_unicode=None), |
|
19 |
ForeignKey(bdd_basename +'groups.name'), |
|
20 |
primary_key=True, nullable=False), |
|
21 |
Column(u'idpermission', |
|
22 |
Integer(), autoincrement=False, primary_key=True, nullable=False), |
|
23 |
mysql_engine='InnoDB', |
|
24 |
mysql_charset='utf8' |
|
25 |
) |
|
26 |
|
|
27 |
# Classe a mapper |
|
28 |
|
|
29 |
class GroupPermissions(object): |
|
30 |
|
|
31 |
""" |
|
32 |
Classe liée avec la table associée |
|
33 |
""" |
|
34 |
|
|
35 |
def __init__(self, groupname, idpermission = 0): |
|
36 |
self.groupname = groupname |
|
37 |
self.idpermission = idpermission |
|
38 |
|
|
39 |
mapper(GroupPermissions, grouppermissions) |
vigiboard/model/vigilo_bdd/groups.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""Modèle pour la table Groups""" |
|
4 |
from __future__ import absolute_import |
|
5 |
|
|
6 |
from sqlalchemy.orm import mapper |
|
7 |
from sqlalchemy import Table, Column |
|
8 |
from sqlalchemy.types import String |
|
9 |
|
|
10 |
from ..vigilo_bdd_config import bdd_basename, metadata |
|
11 |
|
|
12 |
# Generation par SQLAutoCode |
|
13 |
|
|
14 |
groups = Table(bdd_basename + 'groups', |
|
15 |
metadata, |
|
16 |
Column(u'name', |
|
17 |
String(length=100, convert_unicode=True, assert_unicode=None), |
|
18 |
primary_key=True, nullable=False), |
|
19 |
Column(u'parent', |
|
20 |
String(length=100, convert_unicode=True, assert_unicode=None), |
|
21 |
index=True, primary_key=False), |
|
22 |
mysql_engine='InnoDB', |
|
23 |
mysql_charset='utf8' |
|
24 |
) |
|
25 |
|
|
26 |
# Classe a mapper |
|
27 |
|
|
28 |
class Groups(object): |
|
29 |
|
|
30 |
""" |
|
31 |
Classe liée avec la table associée |
|
32 |
""" |
|
33 |
|
|
34 |
def __init__(self, name, parent=None): |
|
35 |
self.name = name |
|
36 |
self.parent = parent |
|
37 |
|
|
38 |
mapper(Groups, groups) |
vigiboard/model/vigilo_bdd/host.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""Modèle pour la table Host""" |
|
4 |
from __future__ import absolute_import |
|
5 |
|
|
6 |
from sqlalchemy.orm import mapper |
|
7 |
from sqlalchemy import Table, Column |
|
8 |
from sqlalchemy.types import Integer, String |
|
9 |
|
|
10 |
from ..vigilo_bdd_config import bdd_basename, metadata |
|
11 |
|
|
12 |
# Generation par SQLAutoCode |
|
13 |
|
|
14 |
host = Table(bdd_basename + 'host', |
|
15 |
metadata, |
|
16 |
Column(u'name', |
|
17 |
String(length=255, convert_unicode=True, assert_unicode=None), |
|
18 |
index=True,primary_key=True, nullable=False), |
|
19 |
Column(u'checkhostcmd', |
|
20 |
String(length=255, convert_unicode=True, assert_unicode=None), |
|
21 |
primary_key=False, nullable=False), |
|
22 |
Column(u'community', |
|
23 |
String(length=255, convert_unicode=True, assert_unicode=None), |
|
24 |
primary_key=False, nullable=False), |
|
25 |
Column(u'fqhn', |
|
26 |
String(length=255, convert_unicode=True, assert_unicode=None), |
|
27 |
primary_key=False, nullable=False), |
|
28 |
Column(u'hosttpl', |
|
29 |
String(length=255, convert_unicode=True, assert_unicode=None), |
|
30 |
primary_key=False, nullable=False), |
|
31 |
Column(u'mainip', |
|
32 |
String(length=255, convert_unicode=True, assert_unicode=None), |
|
33 |
primary_key=False, nullable=False), |
|
34 |
Column(u'port', Integer(), primary_key=False, nullable=False), |
Also available in: Unified diff