Tag Value change event log in audit_events table

Ignition doesn’t handle the auditing in the same way that Wonderware does. Ignition uses the audit log to record things that users do and some alarm notification information, there’s no built in way to log tag change events into the audit log.

Options for logging tag change events is to use the Historian and query the Historian for change events, use alarming on the tag with a Priority setting of Diagnostic, or roll your own.

I think in your case you are looking to mimic the way Wonderware stores tag changed events, in the same log as user events, in which case you would roll your own and you are on the right track. The way I would do this is to create a Gateway script and call that script from any tag value changed function that I want to log to the audit log.

Here’s the call used in the tag Valve Changed function - shared.EventLog.LogEvent(tagPath, previousValue, currentValue, initialChange, missedEvents)

Create a Gateway script (under Global/Script Library) called EventLog and you can add the following function to the script, you’ll need to modify the script for your table and column names - [code]def LogEvent(tagPath, previousValue, currentValue, initialChange, missedEvents):

User = 'Ignition'
UserHost = 'Gateway'
Action = 'tag event'
ActionTarget = str(tagPath)
ActionValue = str(currentValue.value)
StatusCode = 0
OriginatingSystem = 'Gateway'
OriginatingContext = 10  #value to enable searching for tag events

system.db.runPrepUpdate("INSERT INTO audit_log " \
                        "(event_timestamp, user, user_host, action, action_target, " \
                        "action_value, status_code, originating_system, originating_context) " \
                        "VALUES " \
                        "(now(), ?, ?, ?, ?, " \
                        "?, ?, ?, ?)", 
                        [User, UserHost, Action, ActionTarget,
                        ActionValue, StatusCode, OriginatingSystem, OriginatingContext], 
                        database='SCADA') #must include database connection name[/code]
  1. The Tag Value Changed function is executed by the Gateway, so there is no Client information (user, project) available.
  2. Although the doc information in the Value Changed function says the tagPath is a string, I think it’s an object which is why it’s wrapped with str().
  3. The action_value column in the table is a string column, which is why the currentValue.value is wrapped with str().
1 Like

Ooh! I was just going to mention that the database connection needs to be specified, since the script would run outside of a project.

Pat beat me to it, though… :laughing:

Hi Pat and JordanCClark,

Thank you for the code, :laughing:

I have perpared the code as per attached and It is working fine. Also please refer Event log sanpshot.

I want to understand below few points.

  1. I have comparing initialChange bit status in the Tag value change event script. Hence the false (unnecessary) events were not logged at the time, when I SAVE and PUBLISH the project.

A. But I am getting unnecessary events logged, in database when I change or modify the UDT. Is there any provision to avide unnecessary event logging, which will logged into the database when the UDT changed or modified.

B. Instead of using “If and Else” condition. Can I use directly like ( if initialChange == 0: then run the code.) witout using else, It will work? I had tried, using only If condition (without else), all code will run and unnecessary events gets logged in to the DB. Hence I am using the If and Else condition as shown in snapshot.

  1. Is Tag value changed (if newValue.value ‘:’) need to be comapre to aviod unnecessary events? or We need to compare between perviousValue.value and newValue.value like ( if perviousValue.value <> newValue.value: ) then run code?

  2. I have one UDT (Pump) and I written the code in 3 UDT tags. Is the indiviual scripting will load the system?

A. I am using UDT so I need the Master tag name in the Event Tag Path Field, so i have using UDT parameters in the Code to prepare tag path. Could we use shared scripting function and UDT parameters same time?

  1. Is the shared scripting function is the best option as you had explained?

Thank you in advance.




2 Likes