sqall01/alertR

ClientExecuter and .py script to email and text

Closed this issue · 3 comments

Greetings,

First of all I want to thank you for sharing this project. Even a person like me with no coding experience can tell this is very well done; you really know you stuff man.
I was trying hard not to bother you with questions but I am at dead end. Because I have no experience with python or any other language for that matter I would find it difficult to explain this issue in the python forums for example. I have made it this far just spending a big share of hours in your tutorials and using the log files, but like I said, I am stuck and I didn't know where else to look for answers. So, if you find the time will you be so kind to help me solve this issue, which is:
I am trying for the clientExecuter that I got running on the same host as the server to send out an email and text message using the python script that I found online. When I check the log file of the clientExecuter I see the message that it receives the sensor alert, but, fails when it tries to execute the python script. Bellow is a section of the clientExecuter config file, a section of the log file and the python script. At the end I have included a link with the clientConsole image, in case it is useful, and a couple pictures with my version of a lazy circuit that may help some else.
Thank you!

---------------------ClientExecuter config.xml (section)------------------

            <!--
                the arguments that are used for the command that
                is executed when a sensor alert was triggered
                (the amount of arguments are variable)
            -->
            <triggerArgument>/home/alertr/alertClientExecuter/scripts/notification.py</triggerArgument>
            <triggerArgument>start</triggerArgument>

            <!--
                the arguments that are used for the command that
                is executed when a all alerts are stopped
                (the amount of arguments are variable)
            -->
            <stopArgument>/home/alertr/alertClientExecuter/scripts/notification.py</stopArgument>
            <stopArgument>stop</stopArgument>
        </executer>
    </alert>
</alerts>

************************* Send email and text script **************************
`#!/usr/bin/python

import smtplib

sender = 'alertr@example.com'
receivers = ['emailOne@domain.net','emailTwo@yahoo.com','9361234567@vtext.com']

message = """From: Alert System alertrR@localhot.org
To: Person <email@@yahoo.com>
Subject: SMTP e-mail test

This is a test e-mail message.
"""

try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"`


------------ClientExecuter - logfile.log--------------------------------
10/13/2016 14:16:02 INFO: [client.pyc]: Received sensor alert.
10/13/2016 14:16:02 ERROR: [alert.pyc]: Executing process 'send email and text' with trigger arguments failed.
Traceback (most recent call last):
File "/home/alertr/alertClientExecuter/lib/alert.py", line 73, in triggerAlert
subprocess.Popen(self.triggerExecute, close_fds=True)
File "/usr/lib/python2.7/subprocess.py", line 710, in init
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory


------------(might be useful for someone else)--------------------
Image of how the Console looks at this point:
https://my.owndrive.com/index.php/s/aBE3LlBwH536EgL
Images showing a trigger switch created using your guide:
https://my.owndrive.com/index.php/s/gVBeBLtcN7pwuMD
https://my.owndrive.com/index.php/s/aQLT8kiyaextk1k

Hi,

thank you very much.

I think I spotted the error. Well the log file says "no such file or directory". So the executable seems not to be there. When we look at your configuration, then we see that you have the following line:

execute="/usr/bin/pyton">

Which has to be:

execute="/usr/bin/python">

This should fix the issue :)

Man! I am sorry you had to read all of that wordy explanation just to catch a typo.
It worked! Very much appreciated!!!

I hope you had a good weekend, and, Thank you again.

No problem. Sometimes when sitting in front of such a problem one just gets blind to this :)