Logging in database

I have created a script to keep track of the windows opened in my ignition project. I am using the system.db.runPrepUpdate function to insert the needed values in my database. However, on top of inserting the Action of Open Window in my database it also adds the SQL query in the db. Does anyone have an idea why it does that?

Show your code. We won't be able to help without seeing what you're doing.

The script can be cleaned up a bit but we can put that aside for the time being -

How are you calling this function and where? I assume probably on visionWindowOpened or similar, but please show that as well. What column is getting the full SQL query inside of it? If I had to guess it's ActionTarget or ActionValue.

Right, show how you are calling it please. You are doing WindowOpened('somethinghere', 'somethingelsehere') - show that.

That looks ok. What exactly is coming through in your database? Can you run this on a window and show what you are getting in your db?

in the Action column it says "query" and in the Action target column it says " "INSERT INTO audit events "
"(event_timestamp, actor, actor_host, action, action_target, "
"action_value, status_code, originating_system, originating_context)"
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
but instead of the question marks it's the actual values

Is there any other script on the window that are doing similar? You're Action variable is hardcoded to Action = "OpenWindow". Is there anyhting on the root container or a property change of something that uses a query that is calling a similar function? Is there any other rows beneath the latest that do have "OpenWindow" in the Action column?

If you do have other functions like this around your window, I would think your open window would be the first one written and then maybe you're getting rows from these other functions.

SELECT * FROM audit_events WHERE action='OpenWindow' yield anything?

Also what happens if you test it manually in script console - shared.WindowScript.WindowOpened("Test Window", '') - does this appear correctly?

Well, you're writing to the audit log, then the auditing system logs the query action to the audit log.
From the manual:

The following functions generate entries in the audit log if called from Vision component-based scripts, or from the Designer's Scripting Console.

4 Likes

Right so other actions were automatically being logged. Should have caught that when I saw the audit_events table.

Instead of writing your own function to insert into audit_events you are better off using the built-in function in system.util.audit system.util.audit - Ignition User Manual 8.1 - Ignition Documentation

In general for anything you do in Ignition (I saw on another post you said you're new to the software) you're always best off looking for a built-in solution first.

If no one has shown you yet, check out https://www.inductiveuniversity.com/

2 Likes

@bopguap why would you create a topic, get your answer, then try to delete all of your posts so future readers can't follow along and potentially resolve their own issues?? Not a very respectful decision. If this was reddit, you would be shadow banned. I suggest you undelete your deleted posts and not do it again. You've lost my support if you don't, and I hope others follow suit as well

Why would you delete this?? There's no IP in there whatsoever
image

8 Likes