can indigo email the activity log ?

Posted on
Thu Jun 26, 2008 12:16 pm
boyakaa offline
Posts: 90
Joined: May 12, 2008

can indigo email the activity log ?

Can indigo email the activity log. With any type of variables like file size, time of day, and most important of all "specific event"?

Posted on
Sat Jun 28, 2008 9:31 am
matt (support) offline
Site Admin
User avatar
Posts: 20542
Joined: Jan 27, 2003
Location: Texas

Re: can indigo email the activity log ?

A script like this will email, presuming you have configured the SMTP settings int he Indigo Preferences dialog, the last 100 lines from the Event Log:
Code: Select all
tell application "IndigoServer"
   set eventLogDump to build event log list line count 100
   send email to "foo@foo.com" with subject "Event Log" with body eventLogDump
end tell

Regards,
Matt

Posted on
Mon Sep 21, 2009 8:29 pm
wi_pedaler offline
User avatar
Posts: 79
Joined: Apr 29, 2004
Location: Southeast Wisconsin, USA

(No subject)

Matt,
HUGE THANKS for such a slick and effective solution!
Once again, the Indigo support forums come through with a robust solution that I had implemented in less than 2 minutes. [it took a while to decide how many lines to send]

Posted on
Tue Jan 26, 2010 5:17 pm
sparker offline
Posts: 147
Joined: Oct 30, 2003
Location: Broomfield, Colorado

Re: can indigo email the activity log ?

Here's a "shell script" that I put in a cronjob when I was trying to debug temperature issues:

Code: Select all
cd "/Library/Application Support/Perceptive Automation/Indigo 4/Logs"
cat *.txt | tr '\r' '\n' > all.log
grep 'homeTemperature' all.log > temps_only.log
rm all.log.gz ; gzip all.log
( cat temps_only.log ; uuencode all.log.gz all.log.gz )  | mail -s "Home Event Logs" me@mydomain.com


This would have the temperature records in the body of the email, and all the logs attached as a gzip file if I needed to know more.... :)

Steve

--
Steve Parker
X10 user from the early 80's
Fully converted to Insteon in 2013
Proud Indigo owner since the beginning... :)

Posted on
Sat Jul 30, 2011 4:53 pm
Matt offline
Posts: 406
Joined: Aug 13, 2006
Location: Northern Idaho

Re: can indigo email the activity log ?

In the interest of skinning cats, I submit my method:

Code: Select all
tell application "Finder"
   set pth to "MacMini HD:Library:Application Support:Perceptive Automation:Indigo 5:Logs:" as alias
   set filelist to files in pth
   set filelist to sort filelist by modification date
   set theText to name of first item in filelist
   set theText to (pth as string) & theText as alias
   set theContent to read theText
end tell

do shell script "echo " & quoted form of theContent & " |mail -s 'Indigo Log' emailaddress@gmail.com"


I have grown to hate scripting the Mail app. In my experience it often asks for the account password before it will check email or send it, which is a nasty hiccup for an automated system. The above code bypasses that problem altogether.

Image

Posted on
Thu Dec 29, 2011 6:15 pm
chrismoore offline
Posts: 28
Joined: Dec 02, 2011

Re: can indigo email the activity log ?

This is great! Does anyone know if there is a way to email a log of just the error messages?

Posted on
Fri Dec 30, 2011 12:16 am
jay (support) offline
Site Admin
User avatar
Posts: 16780
Joined: Mar 19, 2008
Location: Austin, Texas

Re: can indigo email the activity log ?

Not a particularly easy way. You can turn on SQL logging then write a python script to open the database, pull out the error messages, format them, and email them.

Interesting idea for a plugin...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Dec 30, 2011 12:40 am
berkinet offline
User avatar
Posts: 3427
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: can indigo email the activity log ?

chrismoore wrote:
This is great! Does anyone know if there is a way to email a log of just the error messages?
I'm not sure if you'd call this easy... But, it's not too hard to run a shell script to grep the actual log file for the messages you want and then mail the result of the shell script. Pretty straight forward in AppleScript, something like:
    set errorLines to do shell script "/usr/bin/grep error <path to the log file>"
    send email to "me@foo.com" with subject "Error Lines "with body errorLines

Change "error" to the string or regular expression you want, and change the path. I'm on my iPad so I can't check it right now.

Posted on
Fri Dec 30, 2011 6:50 pm
chrismoore offline
Posts: 28
Joined: Dec 02, 2011

Re: can indigo email the activity log ?

berkinet wrote:
I'm not sure if you'd call this easy... But, it's not too hard to run a shell script to grep the actual log file for the messages you want and then mail the result of the shell script. Pretty straight forward in AppleScript, something like:
    set errorLines to do shell script "/usr/bin/grep error <path to the log file>"
    send email to "me@foo.com" with subject "Error Lines "with body errorLines

Change "error" to the string or regular expression you want, and change the path. I'm on my iPad so I can't check it right now.



Thanks for the help. I'm not very good with Applescript, but I think I did what you suggested and the mail message I receive has not content. The applescript I used was:

set errorLines to do shell script "/usr/bin/grep error Server HD:Library:Application Support:Perceptive Automation:Indigo 5:Logs:"
send email to "my email" with subject "Error Lines " with body errorLines

If you get a chance to test it out and get it working I would really appreciate it!

Posted on
Fri Dec 30, 2011 7:12 pm
berkinet offline
User avatar
Posts: 3427
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: can indigo email the activity log ?

chrismoore wrote:
...If you get a chance to test it out and get it working I would really appreciate it!

Sure. Try this:
Code: Select all
tell application "IndigoServer"
   set myAddress to "foo@bar.com"
   set mySubject to "Indigo Log Error Report"
   set logFile to "/Library/Application Support/Perceptive Automation/Indigo 5/Logs/indigo_log.txt"
   
   set errorLines to do shell script ("/usr/bin/grep -i error \"" & logFile & "\"")
   
   send email to myAddress with subject mySubject with body errorLines
end tell

Set myAddress and mySubject to whatever you like. But, make sure you don't remove the quotes.
Then, paste this into the AppleScript Editor and save it in the Indigo scripts directory into any folder except the Attachments folder. I created a myScripts folder to keep my own scripts in.
Finally, setup a schedule to run it when you want. I suggest just before midnight, since the Indigo log alias tools over at midnight.

You can tweak the line selection by changing the arguments to grep. The -i option makes the search case insensitive (I.e. it will match Error, error, ERROR, etc.). You could also change the text to search for if there were particular errors you wanted. Take a look at the grep man page in a terminal window. Just type "man grep."

Post back if you have any problems or questions.

Posted on
Fri Dec 30, 2011 7:40 pm
chrismoore offline
Posts: 28
Joined: Dec 02, 2011

Re: can indigo email the activity log ?

Works great, thanks!

Posted on
Fri Dec 30, 2011 7:43 pm
matt (support) offline
Site Admin
User avatar
Posts: 20542
Joined: Jan 27, 2003
Location: Texas

Re: can indigo email the activity log ?

Richard -- You should be coding the example scripts in python. I know you know the language now. ;-)

Image

Posted on
Fri Dec 30, 2011 8:37 pm
berkinet offline
User avatar
Posts: 3427
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: can indigo email the activity log ?

support wrote:
.You should be coding the example scripts in python. I know you know the language now. ;-)

Well, besides the complexity of doing this with popen or sup process or os.open, or command...
Then there is the issue of mailing from the shell on a Mac...

The clincher was the wonderful Indigo send email to... ...with subject... ...with body
You just made it too easy.

I could actually have done it in 2 lines in AS + 2 for the tell block. Try that in Python :-)

Posted on
Fri Dec 30, 2011 8:53 pm
matt (support) offline
Site Admin
User avatar
Posts: 20542
Joined: Jan 27, 2003
Location: Texas

Re: can indigo email the activity log ?

POOF. Your wish is my command. Try:

Code: Select all
indigo.server.sendEmailTo("foo@fooville.com", subject="log errors", body="hello there")

You are on your own for for the grep, but I'll bet you can figure that out in 1 python line as well. ;-)

Image

Posted on
Fri Dec 30, 2011 9:15 pm
berkinet offline
User avatar
Posts: 3427
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: can indigo email the activity log ?

You're worse than my mother :wink:

1 line:
Code: Select all
indigo.server.sendEmailTo("foo@barcom", subject="log errors", body=os.popen('/usr/bin/grep -i error "/Library/Application Support/Perceptive Automation/Indigo 5/Logs/indigo_log.txt"').read())

Besides being compact, its also totally incomprehensible to someone getting started.

So, this is probably the better way to go:
Code: Select all
myAddress = "foo@bar.com"
mySubject = "Log Error Report"
logFile = '"/Library/Application Support/Perceptive Automation/Indigo 5/Logs/indigo_log.txt"'

errorLines = os.popen('/usr/bin/grep -i error ' + logFile).read()

indigo.server.sendEmailTo(myAddress, subject=mySubject, body=errorLines)


Notes for @chrismoore and others: This can be run as an embedded script since the way Indigo runs Python is a little better behaved than AppleScript.
Last edited by berkinet on Fri Dec 30, 2011 9:21 pm, edited 1 time in total.

Who is online

Users browsing this forum: No registered users and 2 guests