Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
temperature-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
th
temperature-daemon
Commits
2df22ce4
Commit
2df22ce4
authored
6 years ago
by
Johannes Walcher
Browse files
Options
Downloads
Patches
Plain Diff
added check for valid data (not only any data)
parent
66fd254e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/mail.py
+23
-5
23 additions, 5 deletions
plugins/mail.py
tempermonitor.py
+11
-2
11 additions, 2 deletions
tempermonitor.py
with
34 additions
and
7 deletions
plugins/mail.py
+
23
−
5
View file @
2df22ce4
...
...
@@ -3,7 +3,7 @@ from email.mime.text import MIMEText
from
email.utils
import
formatdate
import
smtplib
UNKNOWN_SENSOR_SUBJECT
=
"
WARNING: Unconfigured Sensor ID
"
UNKNOWN_SENSOR_SUBJECT
=
"
WARNING: Unconfigured Sensor ID
: {owid}
"
UNKNOWN_SENSOR_BODY
=
"""
Hello Guys,
An unknown sensor has been connected to the temperature monitoring service.
...
...
@@ -54,6 +54,20 @@ This is unlikely - please come and check
Regards, Temperature
"""
NO_VALID_DATA_SUBJECT
=
"
WARNING: Garbage data
"
NO_VALID_DATA_BODY
=
"""
Helly guys,
We have data on the line - but it fails even the most simple verification.
The last received line was:
{last_line}
please check if the controller is going haywire.
Regards, Temperature
"""
def
init
(
monitor
):
...
...
@@ -80,9 +94,10 @@ class PluginMail:
msg
[
'
Subject
'
]
=
subject
msg
[
'
From
'
]
=
self
.
config
[
'
mail
'
][
'
from
'
]
if
urgent
:
msg
[
'
To
'
]
=
self
.
config
[
'
mail
'
][
'
to_urgent
'
]
recipients
=
self
.
config
[
'
mail
'
][
'
to_urgent
'
]
.
split
(
'
,
'
)
else
:
msg
[
'
To
'
]
=
self
.
config
[
'
mail
'
][
'
to
'
]
recipients
=
self
.
config
[
'
mail
'
][
'
to
'
].
split
(
'
,
'
)
msg
[
'
To
'
]
=
"
,
"
.
join
([
s
.
strip
()
for
s
in
recipients
])
msg
[
'
Date
'
]
=
formatdate
(
localtime
=
True
)
print
(
"
Notification: {}
"
.
format
(
subject
))
...
...
@@ -97,15 +112,18 @@ class PluginMail:
self
.
_mail_rate_limit
[
subject
]
=
time
.
time
()
smtp
=
smtplib
.
SMTP
(
"
mail.stusta.mhn.de
"
)
#smtp.sendmail(msg['From'],
msg['To']
, msg.as_string())
#smtp.sendmail(msg['From'],
recipients
, msg.as_string())
smtp
.
quit
()
async
def
err_nodata
(
self
,
**
kwargs
):
await
self
.
send_mail
(
NO_DATA_SUBJECT
,
NO_DATA_BODY
)
async
def
err_no_valid_data
(
self
,
**
lwargs
):
await
self
.
send_mail
(
NO_VALID_DATA_SUBJECT
,
NO_VALID_DATA_BODY
)
async
def
err_unknown_sensor
(
self
,
**
kwargs
):
await
self
.
send_mail
(
UNKNOWN_SENSOR_SUBJECT
,
UNKNOWN_SENSOR_SUBJECT
.
format
(
**
kwargs
)
,
UNKNOWN_SENSOR_BODY
.
format
(
**
kwargs
))
async
def
err_problem_sensor
(
self
,
**
kwargs
):
...
...
This diff is collapsed.
Click to expand it.
tempermonitor.py
+
11
−
2
View file @
2df22ce4
...
...
@@ -34,7 +34,7 @@ class Sensor:
self
.
temperature
=
None
self
.
last_update
=
0
self
.
calibration
=
0
self
.
valid
=
Fals
e
self
.
valid
=
Tru
e
try
:
if
owid
in
config
:
...
...
@@ -125,9 +125,14 @@ class TempMonitor:
Read the protocol, update the sensors or trigger a collectd update
"""
await
self
.
reconnect
()
last_valid_data_received
=
time
.
time
()
line
=
""
while
True
:
# Wait for the next line
if
time
.
time
()
-
last_valid_data_received
>
1800
:
self
.
call_plugin
(
"
err_no_valid_data
"
,
last_line
=
line
)
try
:
line
=
await
asyncio
.
wait_for
(
self
.
_reader
.
readline
(),
...
...
@@ -146,6 +151,7 @@ class TempMonitor:
continue
#print("recv:", line)
if
line
==
''
:
# Block has ended
await
self
.
store_sensors
()
...
...
@@ -158,6 +164,9 @@ class TempMonitor:
print
(
"
Invaid line received: {}
\n
{}
"
.
format
(
line
,
exc
))
continue
## we have at least a valid line
last_valid_data_received
=
time
.
time
()
sensor
=
self
.
sensors
.
get
(
owid
,
None
)
if
not
sensor
:
# If the sensor is new - notify the operators
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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