Skip to content
Snippets Groups Projects
Commit 05282ab1 authored by Graziano Scalamera's avatar Graziano Scalamera
Browse files

Add configurable egiga url

parent d9caa560
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# "$Name: $";
# "$Header: /home/cvsadm/cvsroot/fermi/servers/alarmmail/AlarmMail.py,v 1.6 2019-06-20 11:52:19 graziano Exp $";
# ############################################################################
......@@ -178,53 +176,54 @@ class AlarmMail (PyTango.Device_4Impl):
msg_link = ''
att_conf_str = ''
values=[]
if params['values'].startswith('{'):
jsonval=json.loads(params['values'])
for key, value in jsonval.iteritems():
values+=[key+'='+str(value).replace('"', '')]
else:
values=params['values'].split(',')
for value in values:
#values[value.split('=',1)[0]] = value.split('=',1)[1]
att = value.split('=',1)[0]
if len(att) == 0:
continue
#print('looping value=' + value + ' len(value.split(''='',1)[0])=')
print('looping value=' + value)
#print(len(att))
print(' -> ' + value.split('=',1)[0])
word = '([a-zA-Z0-9\+\._\*\#\-\:]+)'
#ind = r'\[[0-9]+\]);'
ind = r'\[(.*?)\]'
try:
m = re.compile("tango://"+word+"/"+word+"/"+word+"/"+word+"/"+word+ind).match(att) #match fqdn with ind
if m is not None:
att="tango://"+m.groups()[0]+"/"+m.groups()[1]+"/"+m.groups()[2]+"/"+m.groups()[3]+"/"+m.groups()[4]
att_conf_id=self.att_conf_fqdn_Map[att]
else:
m1 = re.compile(word+"/"+word+"/"+word+"/"+word+ind).match(value.split('=',1)[0]) #match NOT fqdn with ind
if m1 is not None:
att=m1.groups()[0]+"/"+m1.groups()[1]+"/"+m1.groups()[2]+"/"+m1.groups()[3]
att_conf_id=self.att_conf_Map[att]
if len(egiga_url) > 0:
if params['values'].startswith('{'):
jsonval=json.loads(params['values'])
for key, value in jsonval.iteritems():
values+=[key+'='+str(value).replace('"', '')]
else:
values=params['values'].split(',')
for value in values:
#values[value.split('=',1)[0]] = value.split('=',1)[1]
att = value.split('=',1)[0]
if len(att) == 0:
continue
#print('looping value=' + value + ' len(value.split(''='',1)[0])=')
print('looping value=' + value)
#print(len(att))
print(' -> ' + value.split('=',1)[0])
word = '([a-zA-Z0-9\+\._\*\#\-\:]+)'
#ind = r'\[[0-9]+\]);'
ind = r'\[(.*?)\]'
try:
m = re.compile("tango://"+word+"/"+word+"/"+word+"/"+word+"/"+word+ind).match(att) #match fqdn with ind
if m is not None:
att="tango://"+m.groups()[0]+"/"+m.groups()[1]+"/"+m.groups()[2]+"/"+m.groups()[3]+"/"+m.groups()[4]
att_conf_id=self.att_conf_fqdn_Map[att]
else:
m2 = re.compile("tango://"+word+"/"+word+"/"+word+"/"+word+"/"+word).match(att) #match fqdn without ind
if m2 is not None:
att="tango://"+m2.groups()[0]+"/"+m2.groups()[1]+"/"+m2.groups()[2]+"/"+m2.groups()[3]+"/"+m2.groups()[4]
att_conf_id=self.att_conf_fqdn_Map[att]
else: #try NOT fqdn without ind
att=value.split('=',1)[0]
m1 = re.compile(word+"/"+word+"/"+word+"/"+word+ind).match(value.split('=',1)[0]) #match NOT fqdn with ind
if m1 is not None:
att=m1.groups()[0]+"/"+m1.groups()[1]+"/"+m1.groups()[2]+"/"+m1.groups()[3]
att_conf_id=self.att_conf_Map[att]
if len(att_conf_str) == 0:
att_conf_str = str(att_conf_id)+',1,1'
else:
att_conf_str += ';' + str(att_conf_id)+',1,1'
else:
m2 = re.compile("tango://"+word+"/"+word+"/"+word+"/"+word+"/"+word).match(att) #match fqdn without ind
if m2 is not None:
att="tango://"+m2.groups()[0]+"/"+m2.groups()[1]+"/"+m2.groups()[2]+"/"+m2.groups()[3]+"/"+m2.groups()[4]
att_conf_id=self.att_conf_fqdn_Map[att]
else: #try NOT fqdn without ind
att=value.split('=',1)[0]
att_conf_id=self.att_conf_Map[att]
if len(att_conf_str) == 0:
att_conf_str = str(att_conf_id)+',1,1'
else:
att_conf_str += ';' + str(att_conf_id)+',1,1'
except Exception, e:
print 'Cannot find att_conf_id for ', value
print e
except Exception, e:
print 'Cannot find att_conf_id for ', value
print e
if len(att_conf_str) > 0:
link = 'http://fcsproxy.elettra.trieste.it/docs/egiga2m/egiga2m.html?conf=fermi_hdbpp&start='+start_date+'&stop='+stop_date+'&ts='+att_conf_str+'&show_error='
link = egiga_url+'&start='+start_date+'&stop='+stop_date+'&ts='+att_conf_str+'&show_error='
msg_link = '<a href="'+link+'">'+link+'</a><br>'
if len(msg_link) == 0:
......@@ -378,10 +377,10 @@ class AlarmMail (PyTango.Device_4Impl):
dtnow = dtnow + timedelta(hours=1)
stop_date = dtnow.strftime("%Y-%m-%d %H:%M:%S")
start_date = dtstart.strftime("%Y-%m-%d %H:%M:%S")
msg_procfs = 'http://fcsproxy.elettra.trieste.it/docs/egiga2m/egiga2m.html?conf=fermi_hdbpp&start='+start_date+'&stop='+stop_date+'&ts='+str(att_conf_id)+',1,1&show_error='
msg_procfs = egiga_url+'&start='+start_date+'&stop='+stop_date+'&ts='+str(att_conf_id)+',1,1&show_error='
except Exception, e:
print 'Cannot find att_conf_id for', params['name']
msg_procfs = 'http://fcsproxy.elettra.trieste.it/docs/egiga2m/egiga2m.html?conf=fermi_hdbpp'
msg_procfs = egiga_url
msg = MIMEText('<html><head></head><body><p>NEW ALARM DETECTED: <br>Name: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +params['name'] + '<br>Message: &nbsp;&nbsp;' + params['msg'] + '<br>Values: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + params['values'] + '<br>Formula: &nbsp;&nbsp;' + params['formula']+'<br><br>HDB++ eGiga link:<br><br><a href="'+msg_procfs+'">'+msg_procfs+'</a></p></body></html>','html')
msg['Subject'] = 'ALARMED ' + params['name'] + ' - ' + params['msg']
msg['From'] = '"'+ self.email_name +'"<'+self.email_user+'>'
......@@ -456,6 +455,10 @@ class AlarmMailClass(PyTango.DeviceClass):
[PyTango.DevString,
'',
[] ],
'egiga_url':
[PyTango.DevString,
"eGiga url",
[] ],
}
......
<?xml version="1.0" encoding="ASCII"?>
<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl">
<classes name="AlarmMail" pogoRevision="9.4">
<description description="" title="Alarm Mail Notification" sourcePath="/home/graziano/workspace/fermi/servers/alarmmail" language="Python" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<classes name="AlarmMail" pogoRevision="9.6">
<description description="" title="Alarm Mail Notification" sourcePath="/home/graziano/ws/ds/alarm-mail/src" language="Python" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<inheritances classname="Device_Impl" sourcePath=""/>
<identification contact="at elettra.eu - graziano.scalamera" author="graziano.scalamera" emailDomain="elettra.eu" classFamily="Miscellaneous" siteSpecific="" platform="All Platforms" bus="Not Applicable" manufacturer="none" reference=""/>
</description>
......@@ -39,6 +39,10 @@
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<deviceProperties name="egiga_url" description="eGiga url">
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0">
<argin description="none">
<type xsi:type="pogoDsl:VoidType"/>
......@@ -93,6 +97,6 @@
</argout>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</commands>
<preferences docHome="./doc_html" makefileHome="/usr/local/tango-9.2.5a/share/pogo/preferences"/>
<preferences docHome="./doc_html" makefileHome="/usr/local/tango-9.3.3/share/pogo/preferences"/>
</classes>
</pogoDsl:PogoSystem>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment