$CONTACTADDRESSv$ macro expansion in extinfo.cgi

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
OwenC
Posts: 4
Joined: Mon Mar 07, 2016 3:45 am

$CONTACTADDRESSv$ macro expansion in extinfo.cgi

Post by OwenC »

I have a scenario where I want to use the $CONTACTADDRESSv$ macros to build a URL for the action_url host directive. The $CONTACTADDRESSv$ should be based on the contact currently logged into the CGI web interface.

This doesn't work. Is there a way to do this?

OwenC
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: $CONTACTADDRESSv$ macro expansion in extinfo.cgi

Post by eloyd »

Sorry, that's not how CONTACTADDRESS works (see https://assets.nagios.com/downloads/nag ... olist.html). If you want to get the name of the person logged in to the web GUI, then you need to reach out and grab web server variables, not Nagios variables. Nagios has no idea who is logged in to the web interface.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
OwenC
Posts: 4
Joined: Mon Mar 07, 2016 3:45 am

Re: $CONTACTADDRESSv$ macro expansion in extinfo.cgi

Post by OwenC »

@elyod,

Thanks for the response.

Technically Nagios does know who is logged in because it grabs that from the "REMOTE_USER" environment variable, see: https://fossies.org/dox/nagios-4.1.1/cg ... tml#l00064

Remember that it shows this in the GUI as "Logged in as <http_username>". This is how it is able to do things like filter views based on the contact (once the contact matches the <httpd_username>).

The problem I am having is that I need to have either:
  1. (a) The $CONTACT*$ macros expanded using the currently logged on user OR
  • (b) Some way of accessing the name of the currently logged on <http_username> (if I get the <http_username> I can do $CONTACTADDRESS1:<http_username>$ to get the value that I need)
I have tested (b) and it works in principle, I just need a way to dynamically get <http_username>.

OwenC
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: $CONTACTADDRESSv$ macro expansion in extinfo.cgi

Post by eloyd »

No, the nagios program does not know who is logged in unless it queries the web server variable as you said. The GUI CGIs do that as part of their display. Your plugins do not. In fact, they cannot. The nagios process that is running has no GUI, no web interface, no web server, and no REMOTE_USER associated with it. The two things are separate.

To say it differently:

The nagios process (the program) does not have a concept of who is looking at it through the GUI. In fact, many people could be looking at it simultaneously, each with a different username. The REMOTE_USER is only available to the CGIs that are providing the GUI. To get the information from the GUI to the running nagios process, you would have to customize the GUI to write the name of a logged in user somewhere, ensure it's manageable and accurate, and then have your plugin/notification script look at that information to determine who to send things to.

Way complex.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: $CONTACTADDRESSv$ macro expansion in extinfo.cgi

Post by hsmith »

Thanks, Eric.

@ OwenC, does this clear it up?
Former Nagios Employee.
me.
OwenC
Posts: 4
Joined: Mon Mar 07, 2016 3:45 am

Re: $CONTACTADDRESSv$ macro expansion in extinfo.cgi

Post by OwenC »

Eric,

I think I understand what you are saying.

To put it another way then...It is the Nagios process that is doing the substitution of the macro values. The CGIs are only a front end that display information that is requested from the Nagios process.

In order for the Nagios process to know which objects to do substitution for, the CGI would have to pass as a parameter the ID of the object to the Nagios process. This would be somewhat similar to the way in which the CGI itself is passed the ID of the object for which it should display information. So for example, for the extinfo.cgi to display information about the host FILESERVER01 we call it like:

Code: Select all

https://nagios.company.com/nagios/cgi-bin/extinfo.cgi?type=1&host=FILESERVER01
Given that in the above the extinfo.cgi is not passed a parameter that specifies who the current user is (eg. &contact=<http_username>) then it actually doesn't really know who the current user is and so can't pass that back into the Nagios process.

One thing I don't quite get though is that there is logic that determines whether the currently logged on user has access to a given object (HOST) even with a URL like the one above, and it does this based on the currently logged on username matching that of a contact (authenticated contact). I just tested this....I have a contact that has access to exactly 2 hosts and they can use a URL like the one above to view their 2 allowed hosts successfully but not any other host (it gives "It appears as though you do not have permission to view information for this host..."). Is the determination of the whether the contact has access to host information done in the CGI or in the Nagios process?

OwenC
OwenC
Posts: 4
Joined: Mon Mar 07, 2016 3:45 am

Re: $CONTACTADDRESSv$ macro expansion in extinfo.cgi

Post by OwenC »

BTW....its not a plugin or a notification that I wan't this for.

I want the macro substitution to happen in the host.notes_url and/or host.action_url links that are displayed in the extinfo.cgi when it is displaying details about a host.

OwenC
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: $CONTACTADDRESSv$ macro expansion in extinfo.cgi

Post by eloyd »

Yes, you are correct in your analysis. The problem with what you want to do is that the notes_url and action_url are generated by nagios the process, not Nagios the GUI. They come straight out of the config file. So, without thinking about this too much, I'm not sure how you would even get that information from the GUI into the URL unless you rewrite the GUI CGI to include the "&remote_user=<REMOTE_USER>" part. This would attach it to all action_url and notes_url entities, and might not be a bad idea for an improvement.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: $CONTACTADDRESSv$ macro expansion in extinfo.cgi

Post by ssax »

Thanks eloyd!

OwenC, you can submit a feature request for this functionality here:

https://github.com/NagiosEnterprises/nagioscore
Locked