Action Component script - is the user available to my script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
skynardo
Posts: 136
Joined: Tue Sep 18, 2012 8:59 am
Location: St. Louis, MO

Action Component script - is the user available to my script

Post 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?
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

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

Post 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.
Former Nagios employee
https://www.mcapra.com/
SteveBeauchemin
Posts: 524
Joined: Mon Oct 14, 2013 7:19 pm

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

Post 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
XI 5.7.3 / Core 4.4.6 / NagVis 1.9.8 / LiveStatus 1.5.0p11 / RRDCached 1.7.0 / Redis 3.2.8 /
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

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

Post 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%
Former Nagios employee
https://www.mcapra.com/
skynardo
Posts: 136
Joined: Tue Sep 18, 2012 8:59 am
Location: St. Louis, MO

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

Post 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.
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

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

Post by cdienger »

Did you have any additional questions on this topic?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
skynardo
Posts: 136
Joined: Tue Sep 18, 2012 8:59 am
Location: St. Louis, MO

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

Post by skynardo »

No, all good, thanks
Locked