Parsing an alarm source path with API function?

I presume that there’s an API call we can use to parse alarm source paths properly to pull out the provider, tagpath, and alarm name, without resorting to using split(':')s and fixed indices which just feels dodgy.
E.g. parsing this

almSource = prov:{}:/tag:{}:/alm:{}
almSourceList = almSource.split(':')

prov = almSourceList[1]
tag = almSourceList[3]
alm = almSourceList[5]

Very late (this topic randomly came up in the list of unanswered topics below the fold), but for posterity...
This :/ separated syntax is the string representation of a QualifiedPath. If you want to avoid doing the parsing manually, you can import and call that class yourself.

And the common IDs you reference within a QualifiedPath can be referenced in WellKnownPathTypes.

2 Likes

hi @PGriffith, @nminchin

Would you have some example of this ?

Thanks in advance

I think it'd be something like this, but haven't tested yet:

from com.inductiveautomation.ignition.common import QualifiedPath
qp = "prov:{}:/tag:{}:/alm" 
qp2 = QualifiedPath.parse(qp)
qp2.Tag
qp2.Provider
qp2.Alarm
2 Likes

Hi @nminchin,

thanks for the info

regards

Actually, you need slightly different syntax to pull out members:

from com.inductiveautomation.ignition.common import QualifiedPath, WellKnownPathTypes

qp = "prov:{}:/tag:{}:/alm" 
qp2 = QualifiedPath.parse(qp)
tag = qp2.getPathComponent(WellKnownPathTypes.Tag) # or just "tag"
provider = qp2.getPathComponent(WellKnownPathTypes.Provider) # or just "prov""
alarm = qp2.getPathComponent(WellKnownPathTypes.Alarm) # or just "alm"
4 Likes