Send Fail Notification Script

Posted on
Fri Jan 01, 2016 5:49 pm
FFS offline
Posts: 21
Joined: Jan 24, 2011

Send Fail Notification Script

Here's a script that will monitor the log file and if it sees a "send failed (no acknowledgment)" Error, it updates a Variable that can be watched with a Trigger.

You may need to change the logFilePath. I'm currently using version 6 and that's what the path is set to.
To set it up, make a new Schedule and set it to a minute or how often you want it to check.
Then set it's Action to Execute Script (Server Actions > Script & File Actions > Execute Script) and paste in the script below.

Two variables are created;
The first is named LogModTime, which is used to check to see if the log file has been modified.
The other is called LogSendFailure, which is the Error line from the log. This is the Variable to watch for changes using a Trigger.

I use it to have Growl/Prowl send me a text message if something fails.
To do that, I set up another Trigger to see if the LogSendFailure Variable Changes. When it does, the Action is a Growl Notify and I set the Description, (under Action Settings...), to %%v:1234567890%%, where 1234567890 is the LogSendVariable's ID (which you can easily copy by right-clicking it in the Variable List). That way Growl/Prowl will show the error line in the text.

Code: Select all
__author__ = "FredenFromSweden"
__version__ = ".3"
__date__ = "2015-12-27"

# Set Log file path
## MAKE SURE THIS IS THE FOLDER THE LOG FILE IS IN
logFilePath = "/Library/Application Support/Perceptive Automation/Indigo 6/Logs/"


import os
import shutil

# Make Log file names
logFileCurrent = logFilePath + "indigo_log.txt"
logFileLast = logFilePath + "indigo_log_last.txt"

# Create variables & file if needed
try:
    indigo.variable.create("LogModTime", "")
except:
    pass
try:
    indigo.variable.create("LogSendFailure", "")
except:
    pass
try:
    open(logFileLast, 'a').close()
except:
    pass


# Get Log file last modified time from Indigo variable
lastLogModTime = indigo.variables["LogModTime"].value

# Get Log file current modified time and update Indigo variable with it
curLogModTime = os.path.getmtime(logFileCurrent)
indigo.variable.updateValue("LogModTime", str(curLogModTime))

# Test for Log file modification
if (lastLogModTime != str(curLogModTime)):

    # Open & read current Log file
    fCur = open(logFileCurrent, "r")
    logCurrent = fCur.readlines()
    fCur.close()

    # Get & set last Log file
    fPrev = open(logFileLast, "r")
    logPrev = fPrev.readlines()
    fPrev.close()

    # Duplicate the current log file
    shutil.copy2(logFileCurrent, logFileLast)

    # Get the differences between the log files
    logDiff = (list(set(logCurrent) - set(logPrev)))

    # Test each line for 'send failed'
    for line in logDiff:
        if "send failed (no acknowledgment)" in line:

            # Set LogSendFailure variable to send failure notice
            indigo.variable.updateValue("LogSendFailure", line)

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest