Ensemble - Username

Hi,

Not sure if is possible, but I am trying to find the way to show in the log the username of whoever enable a specific service. The idea is that a service is normally disabled..if someone enable it, the username will be reported to the log...

I have tried with $username but it only return "_Ensemble" when running from ensemble although it works in Studio.

Thanks

Answers

Audit database contains correct username:

You can also get Username by these two ways:

  • write ^CacheTemp.EnsUsername($job)
  • write %request.GetCookie("Username")

But they are not as reliable as audit database.

Thanks but I am afraid that did not work... when adding that into my service code and run it... I had an error message:

ERROR <Ens>ErrException: <UNDEFINED>zOnInit+14^CUH.Serv.ODSCodeGlobalUpdate.1 *%request -- logged as '-' number - @' Do ##class(Ens.Util.Log).LogInfo($classname(),"OnInit",%request.GetCookie("Username"))'

ERROR <Ens>ErrException: <UNDEFINED>zOnInit+13^CUH.Serv.ODSCodeGlobalUpdate.1 ^CacheTemp.EnsUsername(960) -- logged as '-' number - @' Do ##class(Ens.Util.Log).LogInfo($classname(),"OnInit",^CacheTemp.EnsUsername($job))'

As I said

they are not as reliable as audit database.

First one may not work at all, try safe get: $g(^CacheTemp.EnsUsername($job)).

Second one wouldn't work outside of CSP/ZEN context. Check that %request exists and is an object before calling GetCookie method.

Thank you but not sure about what you said.

I don't have a %request. It is just a Business Service doing nothing...and all I want is to get the username who enable it last time. Well, actually not last time. The service is normally off, so when is turned on, I want the username to be recorded in the log.

I have a function which actually run "write $USERNAME" and if I run it from Studio returns the username!

I don't have a %request.

Checked again and my suggested approach only works on production start, not host start, sorry.

I have a function which actually run "write $USERNAME" and if I run it from Studio returns the username!

$username returns current user, which for Ensemble job is correctly _Ensemble. You can try to query audit database for that info I guess.

I haven't tested this myself, but did you try using the OnInit() callback method?

There's a bit of information here.

Maybe you're already doing this and finding $username="_Ensemble"

Username would be _Ensemble because Ensemble switches users.

Tried OnInit, available context is not enough there:

Method OnInit() As %Status
{
    break
}

And here's the break:

break
 ^
<BREAK>zOnInit+1^Demo.Workflow.WFMetric.1
ENSDEMO 7e1>zw
 
%Ensemble("ArchiveFlags")=""
%Ensemble("ArchiveFlags","Demo.Workflow.WFMetric")=""
%Ensemble("ArchiveFlags","Demo.Workflow.WFMetric","iCfg")=0
%Ensemble("Config","%ModIndexFlag")=1
%Ensemble("ConfigName")="Demo.Workflow.WFMetric"
%Ensemble("Debug","TraceCat","My Terminal Output")=0
%Ensemble("Debug","TraceCat","My Terminal Output","user")=1
%Ensemble("Debug","TraceCat","user")=1
%Ensemble("DoTrace")=2
%Ensemble("JobKey")=10548
%Ensemble("LogSystemTrace")=0
<Private variables>

Thought about $zparent but it didn't help too:

ENSDEMO 7e1>w $system.Process.UserName($zparent)
CSP Gateway

That's exactly what I am doing...using OnInit method:

Method OnInit() As %Status
{
SET tSC=$$$OK

// Add info to the log.
$$$LOGINFO("*******************************")
$$$LOGINFO("Run by:"_$Username)
$$$LOGINFO(" > "_$SYSTEM.Process.UserName())
...

Nothing works...