Page 1 of 1

Action Component script - is the user available to my script

Posted: Fri Apr 21, 2017 9:37 am
by skynardo
Testing a script to be executed via Components Action Command. I'd like to capture the username of the nagios user that clicked on the action (in my script). Is this possible?

Re: Action Component script - is the user available to my sc

Posted: Fri Apr 21, 2017 12:04 pm
by mcapra
Possible? Probably, but the work would be non-trivial. You could grab the cookie's nagiosxi value and reverse engineer that against the PHP session data (in /var/lib/php/session/sess_<nagiosxi_val_from_cookie>).

Another option would be to use some clever jQuery to pass the username in the top-left corner of the page off to the script via arguments.

Re: Action Component script - is the user available to my sc

Posted: Fri Apr 21, 2017 1:22 pm
by SteveBeauchemin
Doesn't Quick Actions have a user parameter that shows who is the current logged in user?
Maybe try having this passed to your script at some point.

Code: Select all

%username%
Admin menu / Manage Components / Actions --> settings
Add it to your URL / Command: line
Update your script to read it.

You cannot capture the user name, but you can pass it to the script.

That is how I do it.

Steve B

Re: Action Component script - is the user available to my sc

Posted: Fri Apr 21, 2017 1:59 pm
by mcapra
Sure enough, you're correct! The work is actually pretty trivial, as it turns out. From the component:

Code: Select all

// Try getting the user
    $username = get_user_attr(0, "username");

    if (empty($username))
        $username = "UNKNOWN_USER";
So your command might look like this:

Code: Select all

php -q /tmp/user.php %username%

Re: Action Component script - is the user available to my sc

Posted: Fri Apr 21, 2017 4:36 pm
by skynardo
Thank you, all I had to do was pass %username% to my script as you said Steve. The doc I was using only mentioned the Host and Service Macros available to Actions component.

Re: Action Component script - is the user available to my sc

Posted: Mon Apr 24, 2017 9:32 am
by cdienger
Did you have any additional questions on this topic?

Re: Action Component script - is the user available to my sc

Posted: Wed Jun 07, 2017 1:29 pm
by skynardo
No, all good, thanks