Page 1 of 1

Edit Nagios Core Web GUI Host URL to open in new tab.

Posted: Wed Oct 23, 2019 11:53 am
by humblestudent
Hello Community,

I am trying to customize the Nagios Core Web GUI to have the hosts' URL open in a new tab on a web browser. Particularly, I am trying to configure the https://name_of_nagios_host/nagios/cgi-bin/status.cgi?hostgroup=all&style=overview

I am trying to find this style=overview, but it looks like it is some how generating the list of hosts based off the cgi. I was wondering if there was a way to configure it to add target="_blank" to each a herf for host names.

Re: Edit Nagios Core Web GUI Host URL to open in new tab.

Posted: Wed Oct 23, 2019 12:07 pm
by scottwilkerson
The only way I can think to do this would be with JS, you would have to add the following to the botton of the /nagios/js/nag_funcs.js script

On a source install this file would be

Code: Select all

/usr/local/nagios/share/js/nag_funcs.js

Code: Select all

$(document).ready(function() {
    $( "a[href*='status.cgi?host']" ).attr( "target", "_blank" );
});

Re: Edit Nagios Core Web GUI Host URL to open in new tab.

Posted: Wed Oct 23, 2019 1:13 pm
by humblestudent
scottwilkerson wrote:The only way I can think to do this would be with JS, you would have to add the following to the botton of the /nagios/js/nag_funcs.js script

On a source install this file would be

Code: Select all

/usr/local/nagios/share/js/nag_funcs.js

Code: Select all

$(document).ready(function() {
    $( "a[href*='status.cgi?host']" ).attr( "target", "_blank" );
});
Thank you for your prompt reply @scottwilkerson

Unfortunately I do not see that file.

I am running Nagios Core 4.2.4

and here is what is listed in my js directory:

Code: Select all

$ pwd
/usr/local/nagios/share/js
$ ls
histogram-events.js  histogram-graph.js  jquery-1.7.1.min.js  map-directive.js  map.js                 nagios-time.js  trends-graph.js
histogram-form.js    histogram.js        jsonquery.js         map-form.js       nagios-decorations.js  trends-form.js  trends.js
I am looking around for that string of code you referenced to see if it resides in another location on this version.

Any additional tips or help would greatly be appreciated.

Re: Edit Nagios Core Web GUI Host URL to open in new tab.

Posted: Wed Oct 23, 2019 1:17 pm
by scottwilkerson
What version of nagios are you using? The file I showed is in the latest

Re: Edit Nagios Core Web GUI Host URL to open in new tab.

Posted: Wed Oct 23, 2019 1:19 pm
by scottwilkerson
Technically you could add a few new lines and add it to jquery-1.7.1.min.js

Re: Edit Nagios Core Web GUI Host URL to open in new tab.

Posted: Wed Oct 23, 2019 1:26 pm
by humblestudent
scottwilkerson wrote:Technically you could add a few new lines and add it to jquery-1.7.1.min.js
I am running Nagios Core Version 4.2.4

Your tip looks like it may have worked.

I added your code snippet to jquery-1.7.1.min.js and restarted the nagios and httpd services, and it looks like that was able to do the trick.

Code: Select all

/*! jQuery v1.7.1 jquery.com | jquery.org/license */
$(document).ready(function() {
    $( "a[href*='status.cgi?host']" ).attr( "target", "_blank" );
});
This seems to work when clicking on hosts under "Host Groups" and "Service Groups" but it doesn't seem to work when clicking on Hosts under "Hosts" (https://host_name/nagios/cgi-bin/status.cgi?hostgroup=all&style=hostdetail) and "Services" (https://host_name/nagios/cgi-bin/status.cgi?host=all) Any other thoughts?

Re: Edit Nagios Core Web GUI Host URL to open in new tab.

Posted: Wed Oct 23, 2019 1:45 pm
by scottwilkerson
You would have to play with this to get what you want

Example: all URL's that contain host=

Code: Select all

$(document).ready(function() {
    $( "a[href*='host=']" ).attr( "target", "_blank" );
});

Re: Edit Nagios Core Web GUI Host URL to open in new tab.

Posted: Wed Oct 23, 2019 1:46 pm
by humblestudent
humblestudent wrote:
scottwilkerson wrote:Technically you could add a few new lines and add it to jquery-1.7.1.min.js
I am running Nagios Core Version 4.2.4

Your tip looks like it may have worked.

I added your code snippet to jquery-1.7.1.min.js and restarted the nagios and httpd services, and it looks like that was able to do the trick.

Code: Select all

/*! jQuery v1.7.1 jquery.com | jquery.org/license */
$(document).ready(function() {
    $( "a[href*='status.cgi?host']" ).attr( "target", "_blank" );
});
This seems to work when clicking on hosts under "Host Groups" and "Service Groups" but it doesn't seem to work when clicking on Hosts under "Hosts" (https://host_name/nagios/cgi-bin/status.cgi?hostgroup=all&style=hostdetail) and "Services" (https://host_name/nagios/cgi-bin/status.cgi?host=all) Any other thoughts?
Think I answered my follow up question. when clicking on hosts under the Hosts and Services tab, they open to the following URL:

Code: Select all

https://name_of_nagios_server/nagios/cgi-bin/extinfo.cgi?type=1&host=server_or_service_name
so I also included the following code to the bottom of the jquery-1.7.1.min.js file.

Code: Select all

$(document).ready(function() {
    $( "a[href*='extinfo.cgi?type']" ).attr( "target", "_blank" );
});

Re: Edit Nagios Core Web GUI Host URL to open in new tab.

Posted: Wed Oct 23, 2019 1:47 pm
by humblestudent
scottwilkerson post resolved this issue.

Re: Edit Nagios Core Web GUI Host URL to open in new tab.

Posted: Wed Oct 23, 2019 1:53 pm
by scottwilkerson
humblestudent wrote:scottwilkerson post resolved this issue.
Great!

Locking thread