vigiboard / vigiboard / model / vigilo_bdd / eventhistory.py @ 57f7cb3f
History | View | Annotate | Download (2.46 KB)
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) |