LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-16-2012, 02:12 AM   #1
waelkd
LQ Newbie
 
Registered: Oct 2008
Posts: 11

Rep: Reputation: 0
Running a Perl script on nagios


Good day everyone,

I installed nagios on centreon platform, now I wrote a perl script that fetches data from specif date from an sql table,to make it run when needed ,my question is , where should i write ,implement this file? Any ideas on this guys?

Thanks
 
Old 05-16-2012, 08:37 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
It depends on what server has the SQL and whether your script pulls the data locally or remotely.

Nagios can run commands and use output (a single line of output and a return code) for monitoring. If your perl script can be run from the Nagios master to talk to the SQL on a remote host (or if the SQL is on the same host as the Nagios master) then you can put the perl script on the master (typical location for most scripts/plugins is /usr/local/nagios/libexec). You can configure the commands.cfg file to have the run of the perl script with variables to be passed in (if any) then add the entry to services.cfg to call the commands.cfg entry and pass in any variables.

If however the perl code is designed to run on a remote host which has the SQL and you want your Nagios master to interrogate you'd need an agent on that remote host. The most common one used for UNIX/Linux is NRPE. For Windows I'd recommend NSClientPlus (nsclient++). You can then use the check_nrpe plugin on the master to interrogate those hosts.
For NRPE on the remote UNIX/Linux you'd add a line calling the command into /usr/local/nagios/etc/nrpe.cfg then on the master you'd set it up to call check_nrpe in commands.cfg and set services.cfg.

The perl script itself as noted needs to output only one line (Nagios doesn't understand multiline output) along with a return code. The defined return codes are common among all Nagios scripts.

An example perl with Nagios return codes defined is below:

Code:
#!/usr/bin/perl
#
######################################################################################################
# 020604 jda
# This script checks memory usage HP9000 boxes via SNMP
#
######################################################################################################
use Getopt::Long;
GetOptions( "H=s"                => \$hostname);
$snmpget = "/usr/bin/snmpget";                                  # define path to command

$target_community = "-v 2c -t 1 -r 9 -c public";
$total_memory = ".1.3.6.1.4.1.11.2.3.1.1.8.0";
$used_memory = ".1.3.6.1.4.1.11.2.3.1.1.7.0";

# ----------------------------------------Variable initialization----------------------------------- #
# Define Variables: These are used to return exit values to NAGIOS
$UNKNOWN_STATE=3;
$CRITICAL_STATE=2;
$WARNING_STATE=1;
$OK_STATE=0;

# -------------------------------------------------------------------------------------------------- #
@totmem = split(/= /, qx/$snmpget $target_community $hostname $total_memory/);  # shell out and do it
@totmem = split(/: /, $totmem[1]);                                              # strip it down further
@usedmem = split(/: /, qx/$snmpget $target_community $hostname $used_memory/);  # shell out and do it
chomp($totmem[1]);
chomp($usedmem[1]);
$totmem = int($totmem[1] / 1024);
$usedmem = int($usedmem[1]/1024);
$total = ($totmem - $usedmem);
print $totmem . " Total Memory, " . $usedmem . " Used, " . $total . "MB Free\n";

# -------------------------------------------------------------------------------------------------- #
exit $OK_STATE;                                         # tell nagios its ok
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl script runs in terminal but not when called by nagios nicko18 Linux - Software 1 04-11-2012 11:37 AM
Perl Script works from command line, but not when evoked by Nagios gfem Linux - General 10 06-05-2008 03:59 PM
Running a perl script bobfinners Linux - Software 1 06-23-2005 05:18 PM
running perl script dav_y2k Linux - Newbie 3 04-25-2005 05:00 AM
Perl script not running on FreeBSD J_Szucs *BSD 12 07-13-2002 09:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration