Event log alarm on error

I would like to create an alarm on the Flexy based on an event in the event log. How can I monitor through the basic script or otherwise if a particular error code is logged in the event log?

@tedsch

Can you elaborate on exactly what event?

I would like to alarm on when the flexy can not contact the data mail box. So when the data sync does not occur.

@tedsch

How frequently are you syncing? I just need to know the timeframe to parse the file in. Are you exporting 1x second etc etc.

We are syncing every three minutes typically.

@tedsch

Ok, I have written a script that will review the events log on a cycled timer (I was doing every minute but this can be altered as you see fit).

DISCLAIMER: This code may not be perfect and is provided as is. As this is a custom solution, results may vary.

Logic

The way the script works is essentially by reading the events log. As we parse the log file on our cycle, if the length of the current line corresponds to the error message length for a failed sync (HTTPC connect error) we will assign a value that acts as the 'previous' error code.

As we continue through the log file, if the error message directly before that error message corresponds to the sending export request status code or the muting message, we determine if previous is = to the specific error message.

If that value does in fact = the error message, we send an email and trigger a tag signifying the message has been sent. We then start a 10 minute timer. During this 10 minutes the script will not fully execute. If we left it running constantly you would just get bombarded with emails when this error occurs.

Pseudocode

OPEN FILE
  Read the current line
  IF line length = error code
   Create previous value variable
  IF line length = send request
   IF Previous value = error code
    Send Email
    Start Timer & trigger boolean

BASIC Script

INIT Section:
TSET 1, 60 //Set a 60 second timer to cycle through the log file. 

ReviewLog Section:
s$ = "Your start time (minutes ago)"
OPEN "exp:$dtEV $ftT $st_m" + s$ + " $et_s0" FOR TEXT INPUT AS 1 //Open the event log file and retrieve the last 
//s$ amount of data. In my example I am using a 10 minute timer. 
p$ = "" //Empty string for previous

Loop:
A$ = GET 1
l% = Len A$

IF(MailSent@ = 0) THEN //If we haven't sent an email it is safe to proceed. 
    IF(A$ <> "") THEN
        IF(l% = 84) THEN
            p$ = "32601"
        ENDIF

        IF(l% = 108 OR l% = 89) THEN //check for send message or mute message
            IF(p$ = "32601") THEN
                SENDMAIL "Email", "CC", "Subject", "Message"
                MailSent@ = 1
                TSET 2, 10
                ONTIMER 2, "MailSent@ = 0"
            ENDIF
         ENDIF
  GOTO "Loop" //recursion
  ENDIF
ENDIF
CLOSE 1 //Close the file

Please feel free to provide your own enhancements to this code!

Hey @jseanor!

I’m looking for a way to look for an event code as well. Mine is 22307. The idea is whenever IO communication fails with another device, a tag will be force logged just once until communication resumes. This is about the closest I’ve come to finding a solution. Is there an easier way to do what I have described that doesn’t involve constantly opening and closing the events file, or do I need to manipulate this code?

Thanks!

You could setup heartbeat tags on the device(s) and then in the basic script have a timer that checks and stores the heartbeat tags value. If the heartbeat value is the same as what was stored during that last time it was checked then you have lost the connection to the device.

Below is an example of a function that does this. in the function heartbeat is a global variable that stores the heartbeat to be checked against each time the function is called.

// function checks the heartbeat from the plc
// if it has not changed since last check then raise error
FUNCTION CheckPLCHeartBeat()
IF (PLC_HEARTBEAT_TMR_ACC@ = heartBeat) THEN
IF (PLC_COMM_FAIL_ALM_ADMIN@=0) THEN
PLC_COMM_FAIL_ALM_ADMIN@=1
// do something or set a tag
ENDIF
ELSE
heartBeat = PLC_HEARTBEAT_TMR_ACC@
IF (PLC_COMM_FAIL_ALM_ADMIN@=1) THEN
PLC_COMM_FAIL_ALM_ADMIN@=0
ENDIF
IF (PLC_COMM_REBOOT_ALM_ADMIN@=1) THEN
PLC_COMM_REBOOT_ALM_ADMIN@=0
ENDIF
TSET 3,0
ENDIF
ENDFN.

1 Like