Access Tag Reference Tracker by Script

Is it possible to retrieve the Tag Reference Tracker log in the script?
Right now KI only can access this info from the designer tag diagnostic.
It will be really handy for searching.

There's no supported/exposed way to retrieve the information from the tag reference tracker, but like most things in Ignition, it's still possible.
I would recommend doing this on the gateway, but if you've got a gateway context already, then something like this:

from com.inductiveautomation.ignition.common.tags.config.model import TagReferenceQuery
from com.inductiveautomation.ignition.common.tags.paths import BasicTagPath

# @param activeSubscriptions True, only return references from current subscriptions to tag. False, returns all other stored references.
# @param activeSince References where the most recent activity occurred before [activeSince] will be filtered from results. 0, to ignore and return all references.
query = TagReferenceQuery(
	BasicTagPath("default", "path/to/tag".split("/")),
	False, #activeSubscriptions
	0 #activeSince
)

references = context.tagManager.getTagProvider("default").getTagReferences(query).get()
4 Likes

Sorry if this is something that I should know, but I hit this when I run that script (with tag provider and tag path arranged): NameError: global name 'context' is not defined Its in the module development environment I see. I don't know how to use that quite yet. Alright I figured out how to get it in a messageHandler and read out in the gateway logs. It is cumbersome.

Is there a "gateway scoped" script console? I tried running this is a message handler but I got the same error. I think I know that there is not but I want to double check

There is not.

If you have Phil’s Toolkit module it includes a decorator that will cause functions to be run in Gateway Scope, if you can’t go that route then the best you can do is a Gateway Message handler

IMO, clicking a button in Perspective is easier, because you can at least keep the script editing window open/floating and just apply your changes to fire it off.

We have plans to add a 'Gateway Script Console', probably at some point in the 8.3 lifecycle.

3 Likes

This makes me cringe. Please audit anything run from such a thing. My decorator only works on code in a project that is saved, which is auditable.

:person_shrugging:
I agree with you in principle, but as this thread points out, means to get the gateway to run arbitrary code (even not yet formally saved code) via the designer abound. What I will probably push for is a means to opt-out of the feature entirely. Thinking out loud, that opt-out may (need to) also apply to e.g. Perspective in the Designer's use of not-yet-saved scripting changes.

Well, that security/audit hole can be closed by leaving Perspective out of the system. :grimacing:

/me runs away

It would be good to enumerate them all in the docs. Tag config (scripts) are audited now-a-days, aren't they?

Ah I do not use perspective but I understand it runs entirely in the gateway, so that makes sense. I have to use the cumbersome messageHandler -> gateway log route and it really hurts my iteration time.

*Cough*

system.util.runInGateway()

Yes I will have to add your integration toolkit once I finish this project