Action Component script - is the user available to my script
Action Component script - is the user available to my script
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
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.
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/
https://www.mcapra.com/
-
- Posts: 524
- Joined: Mon Oct 14, 2013 7:19 pm
Re: Action Component script - is the user available to my sc
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.
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
Maybe try having this passed to your script at some point.
Code: Select all
%username%
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
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
Re: Action Component script - is the user available to my sc
Sure enough, you're correct! The work is actually pretty trivial, as it turns out. From the component:
So your command might look like this:
Code: Select all
// Try getting the user
$username = get_user_attr(0, "username");
if (empty($username))
$username = "UNKNOWN_USER";
Code: Select all
php -q /tmp/user.php %username%
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
Re: Action Component script - is the user available to my sc
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
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.
Re: Action Component script - is the user available to my sc
No, all good, thanks