Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alarm-mail
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs
ds
alarm-mail
Commits
ee59f618
Commit
ee59f618
authored
4 years ago
by
Graziano Scalamera
Browse files
Options
Downloads
Patches
Plain Diff
Fix SendAlarmPROCFS
parent
05282ab1
No related branches found
Branches containing commit
Tags
1.2.1
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/AlarmMail.py
+80
-26
80 additions, 26 deletions
src/AlarmMail.py
with
80 additions
and
26 deletions
src/AlarmMail.py
+
80
−
26
View file @
ee59f618
...
...
@@ -176,7 +176,7 @@ class AlarmMail (PyTango.Device_4Impl):
msg_link
=
''
att_conf_str
=
''
values
=
[]
if
len
(
egiga_url
)
>
0
:
if
len
(
self
.
egiga_url
)
>
0
:
if
params
[
'
values
'
].
startswith
(
'
{
'
):
jsonval
=
json
.
loads
(
params
[
'
values
'
])
for
key
,
value
in
jsonval
.
iteritems
():
...
...
@@ -223,7 +223,7 @@ class AlarmMail (PyTango.Device_4Impl):
print
e
if
len
(
att_conf_str
)
>
0
:
link
=
egiga_url
+
'
&start=
'
+
start_date
+
'
&stop=
'
+
stop_date
+
'
&ts=
'
+
att_conf_str
+
'
&show_error=
'
link
=
self
.
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
:
...
...
@@ -314,18 +314,18 @@ class AlarmMail (PyTango.Device_4Impl):
m
=
re
.
compile
(
"
hdbppes_
"
+
word2
+
"
_
"
+
word2
).
match
(
params
[
'
name
'
])
if
m
is
not
None
:
hdbppes
=
"
archiving/hdb++archiver/
"
+
m
.
groups
()[
0
]
dev
=
PyTango
.
DeviceProxy
(
hdbppes
)
try
:
#tmp_nok = dev.read_attribute("AttributeNokList")
tmp_errs
=
dev
.
read_attribute
(
"
AttributeErrorList
"
)
tmp_list
=
dev
.
read_attribute
(
"
AttributeList
"
)
#nok_list = tmp_nok.value
err_list
=
tmp_errs
.
value
att_list
=
tmp_list
.
value
#comb_list = map(lambda x,y:(x,y),att_list,err_list)
except
(
DevFailed
,
ConnectionFailed
,
EventSystemFailed
),
e
:
print
'
Error read_attribute: %s
'
%
(
e
[
0
][
'
desc
'
])
if
len
(
hdbppes
)
>
0
:
dev
=
PyTango
.
DeviceProxy
(
hdbppes
)
try
:
#tmp_nok = dev.read_attribute("AttributeNokList")
tmp_errs
=
dev
.
read_attribute
(
"
AttributeErrorList
"
)
tmp_list
=
dev
.
read_attribute
(
"
AttributeList
"
)
#nok_list = tmp_nok.value
err_list
=
tmp_errs
.
value
att_list
=
tmp_list
.
value
#comb_list = map(lambda x,y:(x,y),att_list,err_list)
except
(
DevFailed
,
ConnectionFailed
,
EventSystemFailed
),
e
:
print
'
Error read_attribute: %s
'
%
(
e
[
0
][
'
desc
'
])
comb_list
=
map
(
lambda
x
,
y
:(
x
,
y
),
att_list
,
err_list
)
...
...
@@ -370,18 +370,72 @@ class AlarmMail (PyTango.Device_4Impl):
#print('looping param=' + param)
#print(params)
try
:
att_conf_id
=
self
.
att_conf_Map
[
params
[
'
name
'
]]
dtnow
=
datetime
.
now
()
dtstart
=
dtnow
-
timedelta
(
hours
=
24
)
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
=
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
=
egiga_url
msg
=
MIMEText
(
'
<html><head></head><body><p>NEW ALARM DETECTED: <br>Name:
'
+
params
[
'
name
'
]
+
'
<br>Message:
'
+
params
[
'
msg
'
]
+
'
<br>Values:
'
+
params
[
'
values
'
]
+
'
<br>Formula:
'
+
params
[
'
formula
'
]
+
'
<br><br>HDB++ eGiga link:<br><br><a href=
"'
+
msg_procfs
+
'"
>
'
+
msg_procfs
+
'
</a></p></body></html>
'
,
'
html
'
)
dtnow
=
datetime
.
now
()
dtstart
=
dtnow
-
timedelta
(
hours
=
24
)
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
"
)
#values= {
#}
msg_link
=
''
att_conf_str
=
''
values
=
[]
if
len
(
self
.
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
:
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
]
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
if
len
(
att_conf_str
)
>
0
:
link
=
self
.
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
:
msg
=
MIMEText
(
'
NEW ALARM DETECTED:
\n
Name:
'
+
params
[
'
name
'
]
+
'
\n
Message:
'
+
params
[
'
msg
'
]
+
'
\n
Values:
'
+
params
[
'
values
'
]
+
'
\n
Formula:
'
+
params
[
'
formula
'
])
else
:
msg
=
MIMEText
(
'
<html><head></head><body><p>NEW ALARM DETECTED: <br>Name:
'
+
params
[
'
name
'
]
+
'
<br>Message:
'
+
params
[
'
msg
'
]
+
'
<br>Values:
'
+
params
[
'
values
'
]
+
'
<br>Formula:
'
+
params
[
'
formula
'
]
+
'
<br><br>HDB++ eGiga link:<br><br>
'
+
msg_link
+
'
</p></body></html>
'
,
'
html
'
)
msg
[
'
Subject
'
]
=
'
ALARMED
'
+
params
[
'
name
'
]
+
'
-
'
+
params
[
'
msg
'
]
msg
[
'
From
'
]
=
'"'
+
self
.
email_name
+
'"
<
'
+
self
.
email_user
+
'
>
'
groups
=
params
[
'
groups
'
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment