Time stamps in SMTP mail
Posted: Mon Mar 05, 2018 5:52 pm
I don't know how the open source updates are done, but I managed to insert time stamps on my AD SMTP notifications. The modification is trivial for the adventurous or the knowledgeable. I did this because there may be a delay in notification delivery and I want AD to timestamp the message rather than rely on time of receipt.
The file modified is types.py in /opt/alarmdecoder-webapp/ad2web/notifications/
Step 1) back up the original module as a failsafe by copying it to types.py.org
Step 2) add
Step 3) find the following section of code and add the bit between the modification comments (it should take up only one line in the file; use space key before text to align it as seen below):
Step 4) reboot the machine running the web app.
It should just work after that and will append "<message text> [hh:mm:ssAM|PM Dow mm/dd/yy]". The %Z was to insert the time zone, but that apparently isn't defined in the AD python raspberry Pi image implementation - or I missed something obvious as I'm new to python - and so doesn't appear.
The file modified is types.py in /opt/alarmdecoder-webapp/ad2web/notifications/
Step 1) back up the original module as a failsafe by copying it to types.py.org
Step 2) add
- Code: Select all
import datetime
Step 3) find the following section of code and add the bit between the modification comments (it should take up only one line in the file; use space key before text to align it as seen below):
- Code: Select all
def send(self, type, **kwargs):
errors = []
for id, n in self._notifiers.iteritems():
if n and n.subscribes_to(type, **kwargs):
try:
message = self._build_message(type, **kwargs)
if message:
#modification ->
message = message + " [" + datetime.datetime.now().strftime("%I:%M:%S%p %Z %a %m/%d/%y") + "]"
#modification <-
if n.delay > 0 and type in (ZONE_FAULT, ZONE_RESTORE, BYPASS):
Step 4) reboot the machine running the web app.
It should just work after that and will append "<message text> [hh:mm:ssAM|PM Dow mm/dd/yy]". The %Z was to insert the time zone, but that apparently isn't defined in the AD python raspberry Pi image implementation - or I missed something obvious as I'm new to python - and so doesn't appear.