Page 1 of 1

Stop Nagios from inserting things into Services Page..?

Posted: Thu Jan 17, 2013 11:18 am
by mmartin
Hello All,

Nagios Core 3.2.3

I have NSCA running on another server. From that NSCA server I send Nagios the proper "send_nsca" message, but in the
last portion of the Message string (which is the 'status message' of the service) I send Nagios a list of files to display
using some <ul> and <li> tags. Which is pretty cool because I didn't think about that before, where you could BOLD something
using the <b> tags and stuff like that.

So I decided I would send it a File list from NSCA.
Here is the NSCA message being sent to nagios:

Code: Select all

echo "Host_Name1,Service Description String,2,<b>CRITICAL: <i>There are File(s) >= 1.5 GB:</i></b><ul type='' style='display: inherit;'><li>Test_File_1 (1.81 GB)</li><li>Test_File_2 (1.51 GB)</li></ul>"
# Here is the Status 'MESSAGE' portion of the string above, so it's a little more readable...

Code: Select all

<b>CRITICAL: <i>There are File(s) >= 1.5 GB:</i></b>
<ul type='' style='display: inherit;'>
	<li>Test_File_1 (1.81 GB)</li>
	<li>Test_File_2 (1.51 GB)</li>
</ul>
That echo command above gets piped to the send_nsca command. Which sends the last portion (*i.e. after the last comma,
which is the delimiter)
to Nagios as is, as its 'Status Information'. Then it displays the list in the cell as so...

The problem I'm having is that after I send the string, then look at it in the web page I notice there is alot of extra space after the list
in the cell. So I used the Firefox Web Developer Tool and viewed the Frame's source code of that "Service Status" page (*i.e. the
page that displays ALL Services' Statuses)
and I could see that which ever CGI script, (*I assume it's a CGI Script that does it?), it
inserts a   at the end of the message before the closing </TD> tag which closes that Table's Cell. The cells I'm talking
about are in the Column for "Status Information".

# Here is the line from the Services Web Page that displays my 'Message' I send it...

Code: Select all

<TD CLASS='statusBGCRITICAL' valign='center'><b>CRITICAL: <i>There are File(s) >= 1.5 GB:</i></b><ul type='' style='display: inherit; page-break-after:avoid;'><li>STAT.YR4YR5.JWP - (1.65 GB)</li><li>SERIESTABLE.JWP - (1.54 GB)</li><li>PROD.POINTER - (2.01 GB)</li><li>ORDER.HISTORY.LINE - (1.51 GB)</li></ul> </TD>
***As you can see there is now a " " after MY closing </ul> tag, but before their closing </TD> tag...

Anyway, the " " that gets appended really adds alot of extra space after the list (*i.e. after MY closing </ul> tag.) and
if I remove the " " it removes this space and displays perfectly. I also tried removing the " " from a cell
in the table that was PLAIN TEXT ONLY and then refreshed the page and it did nothing to change the way it was displayed...

So I thought maybe, since Nagios Core is Open-Source, I could get into the script that builds those html pages and stop it from appending
the " " to the end of your "Status Message"...

Anyone know which script does this?
Or any other thoughts would be much appreciated as well...!


Thanks in Advance,
Matt

Re: Stop Nagios from inserting things into Services Page..?

Posted: Thu Jan 17, 2013 11:25 am
by mmartin
After I just submitted the First Post, I came across this information in the Nagios Documentation on the "cgis.html" Page:
File Name: status.cgi

Description:
This is the most important CGI included with Nagios. It allows you to view the current status of all hosts and services that are being monitored. The status CGI can produce two main types of output - a status overview of all host groups (or a particular host group) and a detailed view of all services (or those associated with a particular host).
I wasn't the one who installed Nagios on our server, so I wasn't sure if Nagios came as Source code or if it came as a package type thing...
So I was wondering if its possible to get the source of the status.cgi script and edit it as I suggested previously, then recompile it..?
Is that possible?

Thanks Again,
Matt

Re: Stop Nagios from inserting things into Services Page..?

Posted: Thu Jan 17, 2013 12:14 pm
by sreinhardt
Yes you certainly should be able to do that. Nagios Core download can be found at that link. You will have to be familiar with C, but it is entirely possible.

Re: Stop Nagios from inserting things into Services Page..?

Posted: Thu Jan 17, 2013 1:25 pm
by mmartin
Hey sreinhardt, thanks for the reply!!!

Yea, I did find it in status.c and I think I narrowed it down to line 1791..
This is in version 3.2.3, in case you were wondering...

So I downloaded the Nagios Source code onto another server I use that uses the same processor type --> i686, and same OS, which is SLES 11... This
way I can download/install and configure it without screwing up my REAL Nagios installation...

Anyway, I found the thing to remove in 'status.c', so I removed it from the file. Then ran the following commands as it tells you in the Nagios Documentation:

Code: Select all

# tar xvzf nagios-3.2.3.tar.gz
# ./configure --with-command-group=nagios
# make all
# make install
After running those commands I copied the original status.cgi from the Main Nagios server and backed it up, just in case... Then I sftp'ed the new, edited version
of the script to the Main Nagios server. I then tried to refresh the "Services" page and got the following Error Message:

Code: Select all

Whoops!

Error: Could not open CGI config file '/usr/local/nagios/etc/cgi.cfg' for reading!

Here are some things you should check in order to resolve this error:

    Make sure you've installed a CGI config file in its proper location. See the error message about for details on where the CGI is expecting to find the configuration file. A sample CGI configuration file (named cgi.cfg) can be found in the sample-config/ subdirectory of the Nagios source code distribution.
    Make sure the user your web server is running as has permission to read the CGI config file. 

Make sure you read the documentation on installing and configuring Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at http://www.nagios.org. 
Is there a way to specify the cgi.cfg path before I run "make" or "configure", whichever one it is...?
Because the Directory location is almost the same as the default, except after the "/usr/local" there is a Username as a Directory and then
there's the /nagios directory...
i.e. The Directory is: "/usr/local/Username/nagios"

Any thoughts would be great!

Thanks AGAIN,
Matt

Re: Stop Nagios from inserting things into Services Page..?

Posted: Thu Jan 17, 2013 2:06 pm
by abrist
You could try a symlink if it allowed in your environment. Or change the target directories before compile. You can find the options with:

Code: Select all

./configure --help

Re: Stop Nagios from inserting things into Services Page..?

Posted: Thu Jan 17, 2013 3:05 pm
by mmartin
Hey abrist, thanks for your reply!

Yes, symlinks are allowed I believe...

So that config dir gets defined when running the "configure" command and not the "make" Command, right?
Looking in the configure command's help menu, I don't see any options for defining the cgi.cfg location, or any config directory options at all..?

Do you know what determines where Nagios will define where the different cfg's are kept?
Thought maybe it was the "--with-cgiurl=" but that is for the browser... i.e. "/nagios/cgi-bin"

EDIT:
Just looked again at the help for "configure" command... Do you know is this the option I want to use?

Code: Select all

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
			  [/usr/local/nagios]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
			  [PREFIX]
Thanks Again,
Matt

Re: Stop Nagios from inserting things into Services Page..?

Posted: Thu Jan 17, 2013 3:20 pm
by mmartin
VICTORY!!!

Got it working... It was the "--prefix" option, as I guess you probably knew already.
Anyway, thanks you guys for your help with this... Very Much Appreciated!!!

This is why I love Open Source Software... You don't like something... Then change it lol..!


Again, thanks for your help with this!!

Thanks Again,
Matt

Re: Stop Nagios from inserting things into Services Page..?

Posted: Fri Jan 18, 2013 11:53 am
by abrist
You are most welcome. Enjoy your custom build, cheers!