1
"AlarmHandlerSuperMouse module."
3
from xml.sax import parseString
5
from cdb._alarmhandler import AlarmHandler
6
from cdb._base import _get_string_from_date
8
__all__ = ["AlarmHandlerSuperMouse"]
10
class AlarmHandlerSuperMouse(AlarmHandler):
13
The AlarmHandlerSuperMouse class is used to store and retrieve Alarm Handlers (ALH).
15
The CDB keeps track of when an ALH was in use. An ALH is associated with a tag
16
and retrieved via that tag, get_tagged_alh. It is also possible to associate a
17
new ALH with an existing tag; the old ALH is stored for diagnostic purposes.
19
A couple of methods are provided for diagnostics. It is possible to retrieve a
20
list of tags that were in use over a given time period, get_used_tags, and to
21
retrieve the values of an ALH that was in use at a given time, get_used_alh.
28
Construct an AlarmHandlerSuperMouse.
30
@exception CdbPermanentError: Unable to contact CDB server or invalid URL
33
super(AlarmHandlerSuperMouse,
34
self).__init__("/cdb/alarmHandlerSuperMouse?wsdl")
37
return "AlarmHandlerSuperMouse \
38
\n\tset_url(string url) \
40
\n\tget_tagged_alh(string tag) \
41
\n\tget_used_alh(datetime timestamp) \
42
\n\tget_used_tags(datetime start_time, datetime stop_time) \
44
\n\tset_tagged_alh(string tag, [{string name, string hihi, string hi, string lo, string lolo}] alarms) \
45
\n\tset_tag_in_use(string tag, datetime creation_time)"
48
def set_tagged_alh(self, tag, alarms):
50
Set the values of the alarm handler with the given tag. If an alarm handler with
51
the tag already exists then the passed in alarm handler will become the new
52
alarm handler for that tag. If there is an old alarm handler that has been used,
53
it will be accessible via the get_used_tags and get_used_alh methods.
55
@param tag: the name of the tag
56
@param alarms: a list dictionaries containing the alarm handler data:<pre>
57
keys: 'name', 'hihi', 'hi', 'lo', 'lolo'</pre>
59
@return a string containing a status message
61
@exception CdbTemporaryError: The problem maybe transient and retrying the
63
@exception CdbPermanentError: Maybe due to to bad data being passed in or an
64
unexpected internal error
67
_alarm_xml = "<alarmhandler>"
69
_alarm_xml = (_alarm_xml + "<alarm>"
70
+ "<name>" + str(_alarm["name"]) + "</name>"
71
+ "<hihi>" + str(_alarm["hihi"]) + "</hihi>"
72
+ "<hi>" + str(_alarm["hi"]) + "</hi>"
73
+ "<lo>" + str(_alarm["lo"]) + "</lo>"
74
+ "<lolo>" + str(_alarm["lolo"]) + "</lolo>"
76
_alarm_xml = _alarm_xml + "</alarmhandler>"
78
xml = str(self._client.setTaggedALH(str(tag), _alarm_xml))
79
parseString(xml, self._status_handler)
80
return self._status_handler.get_message()
82
def set_tag_in_use(self, tag, creation_time):
84
Record the fact that the alarm handler with the given tag and creation time is
85
now in use. Only one alarm handler maybe in use at a time. A call to this method
86
will supersede all previous calls to this method.
88
@param tag: the name of the tag
89
@param creation_time: the datetime of when the alarm handler was created in UTC
91
@return a string containing a status message
93
@exception CdbTemporaryError: The problem maybe transient and retrying the
95
@exception CdbPermanentError: Maybe due to to bad data being passed in or an
96
unexpected internal error
99
creation_time = _get_string_from_date(creation_time)
100
xml = str(self._client.setTagInUse(str(tag), creation_time))
101
parseString(xml, self._status_handler)
102
return self._status_handler.get_message()