Question
Niklas Thilmont · Mar 14

Executing Actions on Global Interaction / Global Hooks?

Hey InterSystems Community!

This is probably far-fetched - is there a way to get notified/get a piece of code triggered whenever the state of a global changes?

Now what could I possibly want with that? Quite simple! I would like to forward the content of a global (in this case the "FSLog" global written by the FHIR implementation) while adding timestamps to it - to create some sort of file-based logging for it.

Product version: IRIS 2021.1
0
0 182
Discussion (9)3
Log in or sign up to continue

If your global is part of a class/table class parameter DSTIME could be an approach.
or any SQL trigger or any %OnAfterSave,  %OnAfterDelete, ...
 
For pure Globals all you have is the Journal (if enabled) 

Sadly it's a pure global in this case. But I will keep that in mind for the future, as logging to globals seems to be a common thing, and some actually are backed by classes.

Following on Robert's idea of the journal, you might set up a shadow server with a custom filter routine.  That routine could examine each journaled global set/kill that comes to it, choose the ones it cares about and do something with them, then "quit 0" so the shadow doesn't actually dejournal the activity.

We were thinking of using filebeat anyway. This might actually work smooth enough, with filebeat on the journal, filtering in a later step? I'll have to take a closer look at the journal itself, thank you!

How about polling the global looking for updates? It would be lightweight to just check if the value of ^FSLOG has incremented since the last check:

set lastFSEntry = ^FSLOG

or use $order:

set lastFSEntry = $order(^FSLOG(""),-1)

As for timestamps, in my test environment all of the ^FSLOG entries seem to end with timestamps already:

^FSLOG(41)="DispatchRequest^HS.FHIRServer.Service^11062|Msg|  [1] -> DO  0|03/14/2022 01:57:19.398158PM"

Mine doesn't do that - yet. Still using HealthShare 2020.1. I assume it'll be added with a later version!

11:     ^FSLOG(10)    =    "DispatchRequest^HS.FHIRServer.Service^3245|Msg|Dispatch interaction search-type for MedicationAdministration"
12:     ^FSLOG(11)    =    "BuildIncludeList^HS.FHIRServer.Service^3245|_include|include: "
13:     ^FSLOG(12)    =    "BuildRevIncludeList^HS.FHIRServer.Service^3245|_include|revInclude: "

As for the polling - I guess with a timestamp maybe added in the future (We're planning to upgrade soon), this may very well be the smartest solution. Thanks!

The only way you could accomplish this is by watching the journal files, there would be journals like "Set Global" and "Kill Global"