Antonio Garcia ... · Aug 10, 2018

Ensemble - Username


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.


0 395
Discussion (8)2
Log in or sign up to continue

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))'

Username would be _Ensemble because Ensemble switches users.

Tried OnInit, available context is not enough there:

Method OnInit() As %Status

And here's the break:

ENSDEMO 7e1>zw
%Ensemble("Debug","TraceCat","My Terminal Output")=0
%Ensemble("Debug","TraceCat","My Terminal Output","user")=1
<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

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

Nothing works...

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"