Page 1 of 1

Developping a custom plugin

Posted: Tue Apr 24, 2012 10:41 am
by mrju
Hi there !

I have been asked to develop some plugins for Nagios Core in order to watch a service.
I read the development guideline, but I still have some questions. Indeed, some functions have already been developed such as set_thresholds(), but is there a library I could download to use them. Moreover are there some header files in which the main constants (such as UNKNOWN_STATE, OK_STATE, ...) are defined ?
To summarize, is there a sort of package for the plugin development ?
Not that I am lazy but I just do not want to waste my time writing things that already exist.
Just for information, I plan to develop my plugins in C.

In advance, thanks for your help.

Julien

Re: Developping a custom plugin

Posted: Tue Apr 24, 2012 6:24 pm
by jsmurphy
I think you are trying to delve deeper into the Nagios code than is necessary for adding additional checks.

In order to get information Nagios will run an executable (usually) found in the nagios/libexec folder, these scripts/binaries are completely separate entities from the core Nagios application and can be run standalone from the command line. From these scripts Nagios only expects two pieces of information 1. An exit code and 2. print output to STDOUT. There is a third optional piece of information which is performance data but lets not worry about that.

So to give a hello world example (in Perl because it's my favourite this week)

Code: Select all

#!/usr/bin/perl
use warnings;
use strict;
print "Hello world\n";
exit 0;
This will give Nagios the status text "Hello world" for the check and a status of OK... the state/exit table is as follows:
0 - OK
1 - Warning
2 - Critical
3 - Unknown

Hopefully this has made your task a bit easier, to the best of my knowledge there's no package for plugin development because there wouldn't really be anything except for an enum to put in it.

Re: Developping a custom plugin

Posted: Wed Apr 25, 2012 7:11 am
by mrju
Ok, thank you for your reply !

I'll develop my own plugin development package then.

Re: Developping a custom plugin

Posted: Wed Apr 25, 2012 12:35 pm
by agriffin
The library you're looking for is included with the nagios-plugins package. Under the lib directory there are a bunch of C files to help with plugin development.

Re: Developping a custom plugin

Posted: Thu Apr 26, 2012 10:33 am
by mrju
Yes i saw these files but is it possible to compile them into a static or dynamic library independently from the nagios plugin package ? I mean a library which would contain only the generic functions such as set_thresholds(thresholds *, char *, char *), get_status(double, thresholds *), ...

Re: Developping a custom plugin

Posted: Fri Apr 27, 2012 9:53 am
by agriffin
It's possible but it would take some effort. For now, the easiest solution would be to copy those files into the source for your plugin.