panic.ds.PyAlarm module

class panic.ds.PyAlarm.AlarmHook(condition=None, action=None)[source]

Bases: fandango.objects.Object

This class identifies an Action to be executed as response to an alarm. :param condition: a boolean function that will return True if this action is appliable to the given argument.

e.g. (condition=lambda s: ‘@’ in s) will apply for mail addresses
Parameters:action – function([tag,receivers,...]) to be executed when the action is applied.
apply(tag, receivers)[source]

This method will apply the given action to the argument. Overridable in subclasses

match(argument)[source]

This method will apply the given condition to the argument. Overridable in subclasses

class panic.ds.PyAlarm.PyAlarm(cl, name)[source]

Bases: PyTango._PyTango.Device_4Impl, fandango.log.Logger

Acknowledge(argin)[source]
AddNewAlarm(argin)[source]
AddReceiver(argin)[source]
CheckAcknowledged(argin)[source]
CheckDisabled(argin)[source]
CreateAlarmContext(argin)[source]
Disable(argin)[source]

(TAG,comment,[timeout s/m/h/d]) Disable an alarm (skips update loop) until timeout.

Enable(argin)[source]
EvaluateFormula(argin, tag_name=None, as_string=True, lock=False, _locals=None, variables=None)[source]

This method can be called from both updateAlarms thread or external clients

GenerateReport(tag_name, mail_receivers='', message='DETAILS', values=None, user_comment=None, html=False)[source]

When called from Tango a single argument is received; which is a list containing all arguments :param message: Can be one of self.MESSAGE_TYPES or a different text

GetRelease(argin=None)[source]
MAX_SMS_DAY = 20
MESSAGE_TYPES = ['ALARM', 'ACKNOWLEDGED', 'RECOVERED', 'REMINDER', 'AUTORESET', 'RESET', 'DISABLED']
Panic = None
RemoveAlarm(argin)[source]
Renounce(argin)[source]
ResetAlarm(argin)[source]
ResetAll(argin)[source]
SaveHtml(argin)[source]
SendAlarm(argin)[source]

Arguments: ALARM or Formula, receivers to test

SendMail(argin)[source]

Arguments: message, subject, receivers

SendSMS(tag, receivers=[], message='TEST', values=None)[source]

Sending sms, completely dependent of your personal SMS configuration. :param tag_name: Alarm or Test message to be sent :param receivers: SMS numbers to receive the alarm

State()[source]

State redefinition is required to keep independency between attribute configuration (max/min alarms) and the device State

Status()[source]
alarm_attr_allowed(req_type)[source]

Alarms should be always readable, the quality of the alarm will change if needed

alarm_attr_read(attr, fire_event=True)[source]

This is the method where you control the value assignt to each Alarm attributes

always_executed_hook()[source]
create_alarm_attribute(argin)[source]
delete_device(stop=False)[source]
dev_state()[source]
dev_status()[source]
dyn_attr()[source]
free_alarm(tag_name, comment='', message=None, notify=True)[source]

message for freeing alarm must be RESET/ACKNOWLEDGED/DISABLED

getMemUsage()[source]
get_active_alarms()[source]
get_enabled(force=False)[source]
get_last_values(alarm='', variables=None)[source]
get_state()[source]
get_status()[source]
init_device(update_properties=True, allow=True)[source]

This method will be called first for creating the device. It will be called afterwards to force a reloading of Alarms or Properties

is_LastAlarm_allowed(req_type=None)[source]
parse_action_receivers(tag_name, message, receivers)[source]

Filters the alarm receivers extracting ACTION([message]:...) formulas. Extracts arguments from every action and return them as a list.

parse_defines(argin, tag='$ALARM', message='', date='')[source]

Replaces keywords on receivers. Accepted keywords in actions are:

$ALARM/$TAG/$NAME : Alarm name $DEVICE : PyAlarm name $DESCRIPTION : Description text $VALUES : last values stored for that alarm $REPORT : full report sent when the alarm was raised $DATE/$DATETIME : current time as YYYYMMDD_hhmm $MESSAGE : type of alarm event (RESET,ALARM,REMINDER,...) $JSON : all the previous fields in a JSON dictionary
parse_receivers(tag_name='', filtre=False, receivers=None, message='')[source]

Filters the Alarm receivers matching tag_name; also replaces addresses entered in the PhoneBook This method is called from free_alarm and send_alarm.

read_AcknowledgedAlarms(attr)[source]
read_ActiveAlarms(attr)[source]
read_AlarmConfiguration(attr)[source]
read_AlarmList(attr)[source]
read_AlarmReceivers(attr)[source]
read_DisabledAlarms(attr)[source]
read_FailedAlarms(attr)[source]
read_LastAlarm(attr)[source]
read_LastUpdate(attr)[source]
read_MemUsage(attr)[source]
read_PastAlarms(attr)[source]
read_PhoneBook(attr)[source]
read_SentEmails(attr)[source]
read_SentSMS(attr)[source]
read_VersionNumber(attr)[source]
read_attr_hardware(data)[source]
send_alarm(tag_name, message='', values=None, receivers=None, comment='')[source]
This method parses receivers and:
  • Sends email/SMS for alarms
  • Sends email/sms for RECOVERED/REMINDER if specified in AlertOnRecovery property
  • Triggers snapshots for ALARMS
  • Saves HTML report

ACKNOWLEDGE/RESET messages are not managed here, but in free_alarm

set_alarm(tag_name)[source]
set_state(state)[source]
set_status(status)[source]
start()[source]
stop()[source]
trigger_action(alarm, args, message='', asynch=True)[source]
Executing a command on alarm/disable/reset/acknowledge:
ACTION(alarm:command,mach/alarm/beep/play_sequence,$DESCRIPTION)

see full description at doc/recipes/ActionsOnAlarm.rst

trigger_snapshot(tag_name, user_comment=None)[source]

First check for existing contexts with name=tag_name. If 1 exists and reason is Alarm, it is used. If reason is not, a new one is created. Then an snapshot is taken for the cotnext.

updateAlarms()[source]
update_flag_file()[source]

If there’s Active Alarms writes a 1 to the file specified by FlagFile property, else writes 0

update_locals(_locals=None, check=True, update=True)[source]

This method is used to override _locals variables passed to TangoEval object.

If check is True, It will also check which alarms are enabled and update their values accordingly.

If update is False it will perform a dry run; without updating the cached values.

update_log_file(argin='', tag='', report='', message='')[source]
class panic.ds.PyAlarm.PyAlarmClass(name)[source]

Bases: PyTango._PyTango.DeviceClass

attr_list = {'FailedAlarms': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.SPECTRUM, PyTango._PyTango.AttrWriteType.READ, 512]], 'LastAlarm': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.SCALAR, PyTango._PyTango.AttrWriteType.READ], {'Display level': PyTango._PyTango.DispLevel.EXPERT, 'description': "Returns Alarm:AlarmDate for last alarms until each is read once, then it's cleared (used for archiving)"}], 'AlarmConfiguration': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.SPECTRUM, PyTango._PyTango.AttrWriteType.READ, 512], {'Display level': PyTango._PyTango.DispLevel.EXPERT, 'description': 'Returns Property:Value list'}], 'AcknowledgedAlarms': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.SPECTRUM, PyTango._PyTango.AttrWriteType.READ, 512]], 'DisabledAlarms': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.SPECTRUM, PyTango._PyTango.AttrWriteType.READ, 512]], 'SentSMS': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.IMAGE, PyTango._PyTango.AttrWriteType.READ, 512, 512]], 'LastUpdate': [[PyTango._PyTango.CmdArgType.DevDouble, PyTango._PyTango.AttrDataFormat.SCALAR, PyTango._PyTango.AttrWriteType.READ], {'description': 'Timestamp of the last cycle completed'}], 'SentEmails': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.IMAGE, PyTango._PyTango.AttrWriteType.READ, 512, 512]], 'MemUsage': [[PyTango._PyTango.CmdArgType.DevDouble, PyTango._PyTango.AttrDataFormat.SCALAR, PyTango._PyTango.AttrWriteType.READ]], 'ActiveAlarms': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.SPECTRUM, PyTango._PyTango.AttrWriteType.READ, 512], {'description': 'Retrieves a list of Active Alarms showing AlarmDate:AlarmDescription'}], 'PhoneBook': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.SPECTRUM, PyTango._PyTango.AttrWriteType.READ, 512]], 'VersionNumber': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.SCALAR, PyTango._PyTango.AttrWriteType.READ], {'Display level': PyTango._PyTango.DispLevel.EXPERT, 'description': 'Version number and release note'}], 'AlarmReceivers': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.SPECTRUM, PyTango._PyTango.AttrWriteType.READ, 512], {'description': 'Returns the list of Receivers for each Alarm'}], 'PastAlarms': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.SPECTRUM, PyTango._PyTango.AttrWriteType.READ, 512], {'description': 'Returns AlarmDate:ACKDate:AlarmDescription for all OLD alarms already acknowledged'}], 'AlarmList': [[PyTango._PyTango.CmdArgType.DevString, PyTango._PyTango.AttrDataFormat.SPECTRUM, PyTango._PyTango.AttrWriteType.READ, 512], {'description': 'Returns the content of the AlarmList property'}]}
class_property_list = {'StartupDelay': [PyTango._PyTango.CmdArgType.DevLong, 'Number of seconds that PyAlarm will wait before starting to evaluate alarms.', [0]], 'PanicAdminUsers': [PyTango._PyTango.CmdArgType.DevVarStringArray, 'Users authorized to modify the Alarms (apart of receivers) ', []], 'PhoneBook': [PyTango._PyTango.CmdArgType.DevVarStringArray, 'List of receiver aliases, declared like:\n \t%USER:user@accelerator.es;SMS:+34666555666', []], 'GlobalReceivers': [PyTango._PyTango.CmdArgType.DevVarStringArray, 'Receivers to be applied globally to all alarms\n Declared as FILTER:receiver,ACTION(MESSAGE:...) like\n \t*VC*:vacuum@cells.es,ACTION(RESET:command,t/t/t/stop)', [0]], 'AllowedActions': [PyTango._PyTango.CmdArgType.DevVarStringArray, 'List of OS commands that alarms are able to execute.', []], 'PanicUserTimeout': [PyTango._PyTango.CmdArgType.DevLong, 'Number of seconds to keep user login in panic GUI', [60]], 'FromAddress': [PyTango._PyTango.CmdArgType.DevString, 'Address that will appear as Sender in mail and SMS', ['oncall']], 'SMSConfig': [PyTango._PyTango.CmdArgType.DevString, 'Arguments for sendSMS command', [':']], 'UserValidator': [PyTango._PyTango.CmdArgType.DevString, 'Module.Class to be used to validate admin user/passwords.', []]}
cmd_list = {'SaveHtml': [[PyTango._PyTango.CmdArgType.DevVarStringArray, 'message,subject'], [PyTango._PyTango.CmdArgType.DevString, '']], 'GetRelease': [[PyTango._PyTango.CmdArgType.DevVoid, ''], [PyTango._PyTango.CmdArgType.DevString, '']], 'CreateAlarmContext': [[PyTango._PyTango.CmdArgType.DevVarStringArray, 'tag,attributes,...'], [PyTango._PyTango.CmdArgType.DevLong, 'new context ID']], 'Enable': [[PyTango._PyTango.CmdArgType.DevString, "(TAG,) This is used to inform which alarm should be enabled, alarm won't skip the updateAlarms loop"], [PyTango._PyTango.CmdArgType.DevString, 'If succeed, returns DONE']], 'GenerateReport': [[PyTango._PyTango.CmdArgType.DevVarStringArray, 'tag,message,receivers,...,description'], [PyTango._PyTango.CmdArgType.DevVarStringArray, 'result, subject, receivers']], 'ResetAlarm': [[PyTango._PyTango.CmdArgType.DevVarStringArray, "This is used to inform which alarm should be reset. If it doesn't exst an error occurs, comment"], [PyTango._PyTango.CmdArgType.DevVarStringArray, 'If succeed, returns the list of ActiveAlarms']], 'Acknowledge': [[PyTango._PyTango.CmdArgType.DevVarStringArray, 'This is used to inform which alarm should be acknowledged, no more reminders will be sent, comment'], [PyTango._PyTango.CmdArgType.DevVarStringArray, 'If succeed, returns the list of ActiveAlarms']], 'SendAlarm': [[PyTango._PyTango.CmdArgType.DevVarStringArray, 'alarm/formula/True,receivers,...'], [PyTango._PyTango.CmdArgType.DevString, '']], 'CheckAcknowledged': [[PyTango._PyTango.CmdArgType.DevString, 'alarm tag'], [PyTango._PyTango.CmdArgType.DevBoolean, 'true if alarm is on the list else false']], 'SendSMS': [[PyTango._PyTango.CmdArgType.DevVarStringArray, 'tag/message,receivers,...'], [PyTango._PyTango.CmdArgType.DevString, '']], 'Renounce': [[PyTango._PyTango.CmdArgType.DevString, 'This is used to inform which alarm should be renounced, all reminders will be send again.'], [PyTango._PyTango.CmdArgType.DevString, 'If succeed, returns DONE']], 'EvaluateFormula': [[PyTango._PyTango.CmdArgType.DevString, 'alarm formula to test with the current environment'], [PyTango._PyTango.CmdArgType.DevString, 'result obtained']], 'Disable': [[PyTango._PyTango.CmdArgType.DevVarStringArray, '(TAG,comment,[timeout s/m/h/d]) Disable an alarm (skips update loop) until timeout'], [PyTango._PyTango.CmdArgType.DevString, 'If succeed, returns DONE']], 'SendMail': [[PyTango._PyTango.CmdArgType.DevVarStringArray, 'message,subject,receivers'], [PyTango._PyTango.CmdArgType.DevString, '']], 'ResetAll': [[PyTango._PyTango.CmdArgType.DevVarStringArray, 'User message'], [PyTango._PyTango.CmdArgType.DevString, '']], 'AddReceiver': [[PyTango._PyTango.CmdArgType.DevVarStringArray, 'Attribute,ReceiverAddress'], [PyTango._PyTango.CmdArgType.DevVarStringArray, 'AlarmReceivers values'], {}], 'CheckDisabled': [[PyTango._PyTango.CmdArgType.DevString, 'alarm tag'], [PyTango._PyTango.CmdArgType.DevBoolean, 'true if alarm is on the list else false']]}
device_property_list = {'EvalTimeout': [PyTango._PyTango.CmdArgType.DevLong, 'Timeout for read_attribute calls, in milliseconds .', [500]], 'FlagFile': [PyTango._PyTango.CmdArgType.DevString, 'File where a 1 or 0 value will be written depending if theres active alarms or not.\n<br>This file can be used by other notification systems.', ['/tmp/alarm_ds.nagios']], 'RethrowState': [PyTango._PyTango.CmdArgType.DevBoolean, 'Whether exceptions in State reading will activate the Alarm.', [True]], 'Reminder': [PyTango._PyTango.CmdArgType.DevLong, 'If a number of seconds is set, a reminder mail will be sent while the alarm is still active, if 0 no Reminder will be sent.', [0]], 'LogFile': [PyTango._PyTango.CmdArgType.DevString, 'File where alarms are logged, like /tmp/alarm_$NAME.log\n\n Keywords are $DEVICE,$ALARM,$NAME,$DATE\n\n From version 6.0 a FolderDS-like device can be used for remote logging:\n\n \ttango://test/folder/01/$ALARM_$DATE.log', ['']], 'UseTaurus': [PyTango._PyTango.CmdArgType.DevBoolean, 'Use Taurus to connect to devices instead of plain PyTango.', [False]], 'UseProcess': [PyTango._PyTango.CmdArgType.DevBoolean, 'To create new OS processes instead of threads.', [False]], 'RethrowAttribute': [PyTango._PyTango.CmdArgType.DevBoolean, 'Whether exceptions in Attribute reading will activate the Alarm.', [False]], 'AlarmSeverities': [PyTango._PyTango.CmdArgType.DevVarStringArray, 'ALARM:DEBUG/INFO/WARNING/ERROR #DEBUG alarms will not trigger messages', []], 'LogLevel': [PyTango._PyTango.CmdArgType.DevString, 'stdout log filter', ['INFO']], 'AlarmConfigurations': [PyTango._PyTango.CmdArgType.DevVarStringArray, 'Configuration customization appliable to each alarm. The format is:\n<br>TAG:PAR1=Value1;PAR2=Value2;...', []], 'AlarmReceivers': [PyTango._PyTango.CmdArgType.DevVarStringArray, 'Users that will be notified for each alarm. The format is:\n<br>[TYPE]:[ADDRESS]:[attributes];...\n<br>\n<br>[TYPE]: MAIL / SMS\n<br>[ADDRESS] : operator@accelerator.es / +34666555444\n<br>[attributes]: domain/family/member/attribute;domain/family/*', []], 'IgnoreExceptions': [PyTango._PyTango.CmdArgType.DevString, 'Value can be False/True/NaN to return Exception, None or NotANumber in case of read_attribute exception.', ['True']], 'FromAddress': [PyTango._PyTango.CmdArgType.DevString, 'Address that will appear as Sender in mail and SMS', ['oncall']], 'SMSConfig': [PyTango._PyTango.CmdArgType.DevString, 'Arguments for sendSMS command', [':']], 'UseSnap': [PyTango._PyTango.CmdArgType.DevBoolean, 'If false no snapshots will be trigered (unless specifically added to receivers)', [True]], 'AutoReset': [PyTango._PyTango.CmdArgType.DevFloat, 'If a number of seconds is set, the alarm will reset if the conditions are no longer active after the given interval.', [3600.0]], 'Enabled': [PyTango._PyTango.CmdArgType.DevString, 'If False forces the device to Disabled state and avoids messaging; if INT then it will last only for N seconds after Startup; if a python formula is written it will be used to enable/disable the device', ['120']], 'AlarmThreshold': [PyTango._PyTango.CmdArgType.DevLong, 'Min number of consecutive Events/Pollings that must trigger an Alarm.', [3]], 'PollingPeriod': [PyTango._PyTango.CmdArgType.DevFloat, 'Period in SECONDS in which all attributes not event-driven will be polled.\n @TODO for convenience any value above 300 will be divided by 1000, @DEPRECATE', [15.0]], 'CreateNewContexts': [PyTango._PyTango.CmdArgType.DevBoolean, 'It enables PyAlarm to create new contexts for alarms if no matching context exists in the database.', [False]], 'MaxMessagesPerAlarm': [PyTango._PyTango.CmdArgType.DevLong, 'Max Number of messages to be sent each time that an Alarm is activated/recovered/reset.', [0]], 'AlertOnRecovery': [PyTango._PyTango.CmdArgType.DevString, "It can contain 'email' and/or 'sms' keywords to specify if an automatic message must be sent in case of alarm returning to safe level.", ['false']], 'HtmlFolder': [PyTango._PyTango.CmdArgType.DevString, 'File where alarm reports are saved', ['htmlreports']], 'StartupDelay': [PyTango._PyTango.CmdArgType.DevLong, 'Number of seconds that PyAlarm will wait before starting to evaluate alarms.', [0]], 'AlarmDescriptions': [PyTango._PyTango.CmdArgType.DevVarStringArray, 'Description to be included in emails for each alarm. The format is:\n<br>TAG:AlarmDescription...', []], 'AlarmList': [PyTango._PyTango.CmdArgType.DevVarStringArray, 'List of alarms to be monitorized. The format is:\n<br>domain/family/member #It simply checks that dev is alive\n<br>domain/family/member/attribute > VALUE\n<br>domain/family/member/State == UNKNOWN\n<br>domain/family/*/Temperature > VALUE\n<br>\n<br>When using wildcards all slash / must be included', []]}
dyn_attr(dev_list)[source]
class panic.ds.PyAlarm.SingletonTangoEval(formula='', launch=True, timeout=1000, keeptime=100, trace=False, proxies=None, attributes=None, cache=0, use_events=False, event_hook=None, **kwargs)[source]

Bases: fandango.tango.TangoEval, fandango.objects.Singleton

panic.ds.PyAlarm.main(args=None)[source]