Page 1 of 1

Getting information from Nagios

Posted: Wed Mar 08, 2017 7:28 am
by tarzan
Hello everybody,

my questions are as follows:

you can access from a Perl program to the state of hosts and services on Nagios? Where can I find information about the controls or libraries that make it possible to obtain information about Nagios hosts and services?

thank you

Tarzan

Re: Getting information from Nagios

Posted: Wed Mar 08, 2017 4:23 pm
by mcapra
I don't know of any Perl libraries for assessing the Nagios Core system state, but the status.dat file defined in your nagios.cfg file under the status_file directive is a good place to start. Take a look through that file and see if it's got the sort of information you're looking to access.

Monitoring::Plugin is a pretty popular library for creating Nagios Core plugins though:
http://search.cpan.org/~nierlein/Monito ... /Plugin.pm

Re: Getting information from Nagios

Posted: Fri Mar 10, 2017 3:32 am
by tarzan
Thanks, I'll try and let you know.

Re: Getting information from Nagios

Posted: Fri Mar 10, 2017 3:02 pm
by mcapra
Sure! Let us know if you encounter additional issues.

Re: Getting information from Nagios

Posted: Wed Mar 15, 2017 4:06 am
by tarzan
Hello,

you can by a Perl program using macros on demand Nagios?

Thank you

Re: Getting information from Nagios

Posted: Wed Mar 15, 2017 2:24 pm
by mcapra
I assume you're talking about these?
https://assets.nagios.com/downloads/nag ... olist.html

The Nagios macros are evaluated when Nagios Core executes a given command. So if you wrote a Perl script that accepts certain arguments (a path, file, warning/critical thresholds, service name, etc), you could feel the Nagios Core macros into that script via the Nagios Core command definition.

Here's an example of a command definition calling check_disk locally with 3 arguments:

Code: Select all

define command {
       command_name                             check_local_disk
       command_line                             $USER1$/check_disk.pl -w $ARG1$ -c $ARG2$ -p $ARG3$
}
What macros you have access to for a given situation depends. You can reference that document I linked above for which macros are available in which contexts.