updated the model for actions, site history
[monitor.git] / monitor / database / info / action.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         loginbase = Field(String,default=None)
51         hostname = Field(String,default=None)
52         # NOTE:
53         #       the expected kinds of actions are:
54         #               * reboot node
55         #               * open ticket, send notice 
56         #               * close ticket
57         #               * apply penalty to site
58         #               * backoff penalty to site
59         action = Field(String)
60
61         # NOTE: describes the kind of action.  i.e. online-notice, offline-notice,
62         # reboot-first-try, reboot-second-try, penalty-pause, penalty-warning, penalty-no-create,
63         # penalty-disable-slices, 
64         action_type = Field(String, default=None)
65
66         message_id = Field(Integer, default=0)
67         penalty_level = Field(Integer, default=0)
68
69         # NOTE: in case an exception is thrown while trying to perform an action.
70         error_string = Field(String, default=None)
71
72         #issue = ManyToOne('IssueRecord')
73         # NOTE: this is the parent relation to fb records.  first create the
74         # action record, then append to this value all of the findbad records we
75         # want to have in our set.
76         # Model:
77         #    - create action record
78         #    - find fbnode records
79         #    - append fbnode records to action record
80         #  OR
81         #    - find fbnode records
82         #    - create action record with fbnodes as argument
83         # findbad_records = OneToMany('FindbadNodeRecord', order_by='-date_checked')
84
85         # NOTE: can I move 'message_index, escellation_level, and penalty_level'
86         #    into the same value?  Maybe not penalty level, since there are only two;
87         #    and, there may be additional message and escellation levels.
88         #send_email_to = Field(PickleType, default=None)
89         #action_description = Field(PickleType, default=None)
90         #message_arguments = Field(PickleType, default=None)
91
92         # NOTE: not sure this needs to be in the db.
93         #escellation_level = Field(Integer, default=0)
94         #stage = Field(String, default=None)