Gateway History Provider: Method to get list of History Providers from Gateway

Wondering if anyone knows how to access the list of History Provider names from the Gateway using scripts. I can't seem to be able to find a method to do this. (Tried this method ' 'system.db.getConnections()' but this gives you the Gateway/Config/Database/Connections list)

I Designer it is found under Tag Properties:

In my test environment, this approach seemed to work:

tagBrowseResults = system.tag.browseHistoricalTags().results
historyProviders = [str(result.path.lastPathComponent) for result in tagBrowseResults]
print historyProviders

Output:

['Sample_SQLite_Database']

Tag provider list:
image

Love it! Thanks.

1 Like

Is there a way to filter the historical providers to return only the ones that are enabled? I have a project that needs this list, but it'll also return the historical tag providers of database connection that are disabled, which is not preferable since I'll use the value they select in a storeTagHistory function call.

I feel kinda silly at the moment; I took this at face value without validating it. The method I posted above does not return the database if it is not enabled:

image

Using the script from post 2, this is the output:

['Sample_SQLite_Database', 'Test History Provider 2']
1 Like

Thank you for developing this just for me :smiling_face_with_three_hearts:. What I ended up doing in the meantime is to retrieve the "Valid" database connections, since they correspond to historical tag providers (?). This didn't seem right to me as there might be instances where the list of database connections and historical tag providers will not match exactly, so I would run into problems then.

Are there obvious cases where this would happen?

Here is the script I got from a smart coworker:

for row in system.dataset.toPyDataSet(system.db.getConnections()):
    if row[3] == "Valid":
        ... # put work here

Since the OP had explicitly stated that this approach was not applicable to this usage case, I intentionally didn't go there. Instead, I looked for functions and methods that were specific to tag history. When I couldn't find anything in the system functions for determining enabledness, I started digging around in the gateway looking specifically for the enabled bool, but I never found it. Instead, as I was looking for it, one of my experiments yielded the expected result, so I decided to call it a night and post it. Edit: but then it occurred to me that a disabled provider shouldn't be showing up in a tag browse, so I did a quick test and discovered that it did not return disabled tag history providers.

Oops! I spent time trying to fix a problem that didn't exist. lol

1 Like

This isn't for a Tag Browse component - I'm adding the historical tag providers to a dropdown for selection.

That's right, I forgot about OP mentioning using getConnections().

The 'proper' way to do this is to go from a GatewayContext instance to the HistoryManager, then use the getStores(HistoryFlavor) method (using the static SQLTAG HistoryFlavor).

Wait! What?

Since when is using a GatewayContext anything but utterly unsupported?

Well, okay, proper is a strong word. The only way to do it, and get an answer that will be right 100% of the time, is the method I described. An ideas post would be good for a scripting function or something, if this is a common thing folks need.

How about an addition into Ignition Extensions?

:man_shrugging:
Current Ignition Extensions:

from com.inductiveautomation.ignition.gateway.history import HistoryFlavor
stores = system.util.context.historyManager.getHistoryStores(HistoryFlavor.SQLTAG)

With a fancier scripting implementation:

stores = system.util.getHistoryProviders()

It doesn't feel worthwhile to add to Ignition Extensions where you've already got easy access to the local context. It would be more valuable first party, as a 'blessed' option.

2 Likes

I found some more time to play around with this again, and I'm calling the following lines of code in a library script with a gateway message handler via send request:

stores = context.historyManager.getStores(HistoryFlavor.SQLTAG)
return [str(stores[0]), dir(stores[0])]
Output:
['Sample_SQLite_Database', ['__add__', '__class__', '__cmp__', '__contains__', '__delattr__', '__doc__', '__ensure_finalizer__', 
'__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', 
'__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', 
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__str__', 
'__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 
'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdecimal', 
'isdigit', 'islower', 'isnumeric', 'isspace', 'istitle', 'isunicode', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 
'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 
'swapcase', 'title', 'translate', 'upper', 'zfill']]

It doesn't return the database when the database is disabled, and I still don't see the enabled bit I was looking for, so I must have missed a key concept. What is the advantage of this approach over system.tag.browseHistoricalTags().results? Is it the fact that it doesn't return non SQL historical tag provider types?

The standard Ignition function system.tag.browseHistoricalTags can be used to retrieve the list of Historical Providers.

The code i used is:
[a.path for a in system.tag.browseHistoricalTags('').getResults()]

Given an empty path parameter the results are simply the top level histprov paths. You can then access the results and retrieve the path for each using a list comprehension.

1 Like