User macro for actions component

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

User macro for actions component

Post by WillemDH »

Hello,

I already asked if it's possible to use a 'user' macro, so we can pass the user initiating the event chain to scripts for logging etc. https://support.nagios.com/forum/viewto ... actor+user where TASK ID 5801 was created by Sean.
But now I have the same question for Nagios XI. I don't see an existing macro in the actions component documentation for the Nagios user initiating an action. As we have multiple actions where we need to know who initiated the action, I was wondering if it is already possible to somehow retrieve the user initiating the action in Nagios XI.
If not, please let me know, then I'll create a feature request for this.

Grtz

Willem
Nagios XI 5.8.1
https://outsideit.net
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: User macro for actions component

Post by ssax »

Looks like it would be possible:

If you edit:

Code: Select all

/usr/local/nagiosxi/html/includes/components/actions/actions.inc.php
And add (around line 973):

Code: Select all

"username" => "$_SESSION[username]",
So it looks like:

Code: Select all

$objectvars = array(
        "objecttype" => "host",
        "username" => "$_SESSION[username]",
        "host" => $hostname,
Then at around line 1050 as well:

Code: Select all

    $objectvars = array(
        "objecttype" => "service",
        "username" => "$_SESSION[username]",
        "service" => $servicename,
Then you could use %username% in the action URL and it would work for you.

Code: Select all

http://my.test.url/do_the_thing/?servicename=%servicename%&username=%username%
I've also submitted a feature request for it:

Code: Select all

NEW TASK ID 6244 created - Nagios XI Feature Request: Add the ability to use %username% in the actions component
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: User macro for actions component

Post by WillemDH »

Sean,

It seems to work, but there is something weird. I set "Nagios - %username%" in the Comment field in the Actions component. After Saving the actions, the field appears to be empty again. When executing the chain, it does seem to work however. if I set just Nagios - %username% (without the double quotes, it does show.
Anyway it works. This particular use case I implemented it for was an event chain to initiate a VMware snapshot by the way. By providing the username, our VMware admins can easily see who created the snashot. i'll see if I can find some time to release these scripts on the Nagios Exchange.
If one day we could provide field values in the Reactor action popup window, it would be perfect, then our sysadmins can also provide the reason for the snapshot for example. See https://support.nagios.com/forum/viewto ... t=+reactor

Have a nice day and thanks alot.

Willem
Nagios XI 5.8.1
https://outsideit.net
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: User macro for actions component

Post by ssax »

Hmm, it's working for me in all the fields which field are you talking about, I don't see a comment field. Do you mean the command field? Can you send me a sanitized screenshot or paste the text with the field name?
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: User macro for actions component

Post by WillemDH »

I'm sorry if I wasn't clear. The comment field is a field from my "NAF - Initiate VMware Snapshot" event chain. See screenshot.
You do not have the required permissions to view the files attached to this post.
Nagios XI 5.8.1
https://outsideit.net
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: User macro for actions component

Post by ssax »

I believe we are running into the same type of bug as this (that we submitted earlier):

https://support.nagios.com/forum/viewto ... 54#p143154
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: User macro for actions component

Post by WillemDH »

That is possible Sean. Although I thought this other issue was solved. Anyway this thread can be closed. Tx!
Nagios XI 5.8.1
https://outsideit.net
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: User macro for actions component

Post by hsmith »

WillemDH wrote:That is possible Sean. Although I thought this other issue was solved. Anyway this thread can be closed. Tx!
Thanks for the feedback, Willem. I'll close this one.
Former Nagios Employee.
me.
Locked