Home Directory Plugins Operating Systems Linux Check /etc/init.d/$script_name status

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

Check /etc/init.d/$script_name status

Rating
9 votes
Favoured:
2
Current Version
1.0
Last Release Date
2011-06-13
Compatible With
  • Nagios 2.x
  • Nagios 3.x
License
GPL
Hits
109618
Files:
FileDescription
check_exit_status.plcheck_exit_status.pl
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
This is a nagios plug-in to check the output or exit status or an application (designed for /etc/init.d scripts, but could work with any script).
If you just call it with a -s /path/script it will run the script with a 'status' argument and check the output for the pattern 'is running'
This is a nagios plug-in to check the output or exit status or an application (designed for /etc/init.d scripts, but could work with any script).
If you just call it with a -s /path/script it will run the script with a 'status' argument and check the output for the pattern 'is running'

If you want to run this on a remote host you need to do it via nrpe, because we can not run the /etc/init.d script remotely without a secure connection.

Copy the script to the remote host first, then add a line like this to your nrpe.cfg
command[check_httpd]=/usr/lib/nagios/plugins/check_exit_status.pl -s /etc/init.d/httpd -r

Don't forget to add to sudoers:
nrpe ALL=(root) NOPASSWD: /etc/init.d/* status

Local host example:
Original program: /etc/init.d/httpd

Will get called like so:
/etc/init.d/httpd status

Normal output of script is:
httpd (pid 15780) is running...

Output of check_exit_status.pl -s /etc/init.d/httpd:
/etc/init.d/httpd OK - httpd (pid 15780) is running...

Output if not running (check_exit_status.pl -s /etc/init.d/tcsd):
/etc/init.d/tcsd CRITICAL - tcsd is stopped

Options:
-h
Print detailed help screen

-s
'FULL PATH TO SCRIPT' (required)
This is the script to run, the script is designed to run scripts in the
/etc/init.d dir (but can run any script) and will call the script with
a 'status' argument. So if you use another script make sure it will
work with /path/script status, example: /etc/init.d/httpd status

-e
This is the "exitstaus" flag, it means check the exit status
code instead of looking for a pattern in the output of the script.

-p 'REGEX'
This is a pattern to look for in the output of the script to confirm it
is running, default is 'is running', but not all init.d scripts output
(iptables), so you can specify an arbitrary pattern.
All patterns are case insensitive.

-n
This is the "NOT" flag, it means not the -p pattern, so if you want to
make sure the output of the script does NOT contain -p 'REGEX'

-r
This is the "ROOT" flag, it means run as root via sudo. You will need a
line in your /etc/sudoers file like:
nagios ALL=(root) NOPASSWD: /etc/init.d/* status

-o
This is the "SUPPRESS OUTPUT" flag. Some programs have a long output
(like iptables), this flag suppresses that output so it is not printed
as a part of the nagios message.
Reviews (6)
Thanks for the thorough explanation of setting it up. I thought I can add some more to it to help.

- First for CentOS 6.5 I had to comment out the option in visudo 'Defaults requiretty' so that nrpe can become root thru script.

- Here is my config to help any others. I monitor Syslog-ng client and server remotely using the nrpe on each local machine.

# 'check_syslog-ng' command definition
define command{
command_name check_syslog-ng
command_line $USER1$/check_exit_status.pl -s /etc/init.d/syslog-ng -r
}

define service {
host_name prod-db-backup
service_description check_syslog-ng
is_volatile 1
check_command check_nrpe!check_syslog-ng
max_check_attempts 5
normal_check_interval 15
retry_check_interval 1
check_period 24x7
notification_interval 60
notifications_enabled 1
notification_period 24x7
notification_options w,u,c,r,f
contact_groups admingroup
stalking_options w,u,c
}

nrpe.cfg:
command[check_syslog-ng]=/usr/lib64/nagios/plugins/check_exit_status.pl -s /etc/init.d/syslog-ng -r

Reloaded Nagios and it worked just fine. No need for ARG or -w -c. If status is stopped, service alerts, if status is running, it stays green and checks.

Thank you again.
byihasn, June 28, 2013
1 of 1 people found this review helpful
add -w to !#/usr/bin/perl to allow for execution when you see "-bash: ./check_exit_status.pl: /usr/bin/perl^M: bad interpreter: No such file or directory
". should read as "!#/usr/bin/perl -w"
Owner's reply

Actually this is a problem with uploading an ascii file in binary mode.
If you simply run a "dos2unix check_exit_status.pl" it will fix this. Generally you should not run production code with -w on.

bySushilR, July 17, 2012
Hi,

Please let me know how to use this plugin for remote host. as i am using it, its showing me /etc/init.d/httpd CRITICAL - httpd dead but subsys locked ERROR

Regards
Sushil
Owner's reply

To run this on a remote host use nrpe and add a line like this to your nrpe.cfg
command[check_httpd]=/usr/lib/nagios/plugins/check_exit_status.pl -s /etc/init.d/httpd -r

Don't forget to add to sudoers:
nrpe ALL=(root) NOPASSWD: /etc/init.d/* status

Hi.. i want to ask.
i've already implement this plugin. when i run from the monitored server, it runs normally.
but when i run from my nagios server, it has output like this (example httpd):
"/etc/init.d/httpd CRITICAL - httpd dead but subsys locked"

need advice,
thanks
Owner's reply

To run this on a remote host use nrpe and add a line like this to your nrpe.cfg
command[check_httpd]=/usr/lib/nagios/plugins/check_exit_status.pl -s /etc/init.d/httpd -r

Don't forget to add to sudoers:
nrpe ALL=(root) NOPASSWD: /etc/init.d/* status

bycvanaxel, March 29, 2012
Can u make this possible to check for other host.

With -H and an -c check.
-H = host
-c = community.
Owner's reply

To run this on a remote host use nrpe and add a line like this to your nrpe.cfg
command[check_httpd]=/usr/lib/nagios/plugins/check_exit_status.pl -s /etc/init.d/httpd -r

Don't forget to add to sudoers:
nrpe ALL=(root) NOPASSWD: /etc/init.d/* status

bytaich, November 11, 2011
I think line 80 will not work properly. It should be: 'sudo -u root' not 'sudo -n'.

Nevertheless a very nice plugin. I like it.
Owner's reply

sudo uses -u root by default.
-n means non-interactive.