Hooking script into Nagios

Hi!

I have a perl script which returns data in the following format -

AppName : BillingApp
	"status" = "OK";

AppName : PaymentApp
        "status" = "WARN";

AppName : OrderApp
         "status" = "ERROR";

AppName : OrderApp
         "status" = "FATAL";

the output consists of 100+ apps, with each one of them returning their status.

Here is what I need -

Want to create a wrapper script which returns a cumulative summary. I need a step by step instructions on how to hook a script like this into nagios?

What I desire -

Instead of a cumulative result, can I display the result in Nagios on a per application basis using this one script (and a wrapper script on top of it)?
I would need clear instructions here.

If you can also provide me with a wrapper script for reference in relation to how the result can be presented to Nagios that would be great.

Please help!!

Thanks,
Jack

---------- Post updated at 05:59 PM ---------- Previous update was at 03:14 PM ----------

Can you folks help?

Thanks,
jack

Not really understand what you ask for.

So why not provide the expect output directly?

If you need summary the status, try it:

$ awk 'BEGIN{RS=""}{a[$3 FS $6]++}END{for (i in a) print i , a}' urfile
PaymentApp "WARN"; 1
OrderApp "FATAL"; 1
OrderApp "ERROR"; 1
BillingApp "OK"; 1

Thanks for your reply!

I have a script which basically does a wget on a set of URLs and returns the health of the application in the format that I gave above.

I want to plug this into Nagios so that I can see the output within Nagios 3.x.

Do you know how to achieve that?

Also what I desire is that from the output I can create a single check for each of the apps as if they are different checks (but in this case being returned from a single script).

Thanks,

Jack

Use exit code SO nagios can understand error.

The following is far from perfect or complete, but it should give you an idea:

Declare a nagios command and send the name of the service as a parameter by using nagios built-in macros.

define command{
command_name check_app
command_line /path/to/your/script $SERVICEDESC$
}

Then use a generic script to evaluate the status of the service. (based in rdcwayx' code):

#!/bin/bash
if [ -n "$(awk 'BEGIN{RS=""}/'$1'/{a[$3 FS $6]++}END{for (i in a) print i , a}' your_file)" ]; then
	echo "App is OK" && exit $0;
else
	echo 'App down!' && exit 2;
else
	echo "Unknown Status" && exit 3;
fi

You might need to adjust paths according to your nagios.cfg file.

:smiley: