Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
Check /etc/init.d/$script_name status
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!
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 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.
- 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.
". should read as "!#/usr/bin/perl -w"
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.
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
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
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
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
With -H and an -c check.
-H = host
-c = community.
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
Nevertheless a very nice plugin. I like it.
sudo uses -u root by default.
-n means non-interactive.