Developping a custom plugin

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
mrju
Posts: 3
Joined: Tue Apr 24, 2012 10:22 am

Developping a custom plugin

Post 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
User avatar
jsmurphy
Posts: 989
Joined: Wed Aug 18, 2010 9:46 pm

Re: Developping a custom plugin

Post 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.
mrju
Posts: 3
Joined: Tue Apr 24, 2012 10:22 am

Re: Developping a custom plugin

Post by mrju »

Ok, thank you for your reply !

I'll develop my own plugin development package then.
agriffin
Posts: 876
Joined: Mon May 09, 2011 9:36 am

Re: Developping a custom plugin

Post 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.
mrju
Posts: 3
Joined: Tue Apr 24, 2012 10:22 am

Re: Developping a custom plugin

Post 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 *), ...
agriffin
Posts: 876
Joined: Mon May 09, 2011 9:36 am

Re: Developping a custom plugin

Post 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.
Locked