setup both monitor and zabbix databases in /etc/plc.d/monitor
[monitor.git] / monitor / database / infovacuum / actionrecord.py
1 from elixir import Entity, Field, OneToMany, ManyToOne, ManyToMany
2 from elixir import options_defaults, using_options, setup_all, has_one
3 from elixir import String, Integer, DateTime, PickleType, Boolean
4 from datetime import datetime,timedelta
5 import elixir
6 import traceback
7
8 from monitor.database.dborm import mon_metadata, mon_session
9 __metadata__ = mon_metadata
10 __session__  = mon_session
11
12 #class IssueType(Entity):
13 #       shortname = Field(String, default=None)
14 #       description = Field(String, default=None)
15 #       issue_record = ManyToMany('IssueRecord')
16
17 #class IssueRecord(Entity):
18 #       date_created = Field(DateTime,default=datetime.now)
19 #       date_last_updated = Field(DateTime,default=datetime.now)
20 #       date_action_taken = Field(DateTime,default=datetime.now)
21 #
22 #       hostname = Field(String,default=None)
23 #       loginbase = Field(String)
24 #
25 #       ticket_id = Field(Integer, default=0)
26 #       rt = Field(PickleType, default=None)
27 #
28 #       # open, paused, closed
29 #       status = Field(String, default="open")
30 #
31 #       take_action = Field(Boolean, default=False)
32 #       send_email = Field(Boolean, default=True)
33 #
34 #       message_series =  Field(String, default="nodedown")
35 #       message_index = Field(Integer, default=0)
36 #       penalty_level = Field(Integer, default=0)
37 #
38 #       issue_type = ManyToMany('IssueType')
39 #       actions = OneToMany('ActionRecord', order_by='-date_created')
40
41
42 class ActionRecord(Entity):
43         @classmethod
44         def get_latest_by(cls, **kwargs):
45                 # TODO: need to sort on 'round' since actions will not be globally sync'd.
46                 return cls.query.filter_by(**kwargs).order_by(ActionRecord.id.desc()).first()
47
48 # ACCOUNTING
49         date_created = Field(DateTime,default=datetime.now)
50         hostname = Field(String,default=None)
51         loginbase = Field(String)
52
53         #issue = ManyToOne('IssueRecord')
54         # NOTE: this is the parent relation to fb records.  first create the
55         # action record, then append to this value all of the findbad records we
56         # want to have in our set.
57         # Model:
58         #    - create action record
59         #    - find fbnode records
60         #    - append fbnode records to action record
61         #  OR
62         #    - find fbnode records
63         #    - create action record with fbnodes as argument
64         findbad_records = OneToMany('FindbadNodeRecord', order_by='-date_checked')
65
66         # NOTE: can I move 'message_index, escellation_level, and penalty_level'
67         #    into the same value?  Maybe not penalty level, since there are only two;
68         #    and, there may be additional message and escellation levels.
69         send_email_to = Field(PickleType, default=None)
70         action_description = Field(PickleType, default=None)
71         message_arguments = Field(PickleType, default=None)
72
73         # NOTE: not sure this needs to be in the db.
74         escellation_level = Field(Integer, default=0)
75         stage = Field(String, default=None)