Вы находитесь на странице: 1из 11

Linux 101 Hacks

5 Nagios check_http Plugin Examples for HTTP / HTTPS


by RAMESH

What is check_http?
5 check_http examples
Syntax and Options
Related Commands

What is check_http?

check_http plugin is used to verify the status of HTTP server (or HTTPS) that is running on a remote
host. If you’ve installed Nagios from source, check_httpd command will be located in the
/usr/local/nagios/libexec directory.

5 check_http Command Examples

1. Check HTTP
Check whether Apache HTTP is running on a remote server using check_http.

$ check_http -H 192.168.1.50
HTTP OK HTTP/1.1 200 OK - 332 bytes in 0.004 seconds |time=0.004144s;;;0.000000 siz

2. Check HTTPS
Check whether Apache HTTPS is running on a remote server using check_http.

$ check_http -H 192.168.1.50 -S
HTTP OK HTTP/1.1 200 OK - 332 bytes in 0.004 seconds |time=0.004144s;;;0.000000 siz

If the remote server runs only HTTP and not HTTPS, you’ll get “HTTP CRITICAL – Unable to open TCP
socket” message as shown below.

$ check_http -H 192.168.1.50 -S
Connection refused
HTTP CRITICAL - Unable to open TCP socket

3. Check HTTP (or HTTPS) on different port


You can check tomcat server, or apache server, or glassfish, or any server that is running on a different
port by speficying the port number as shown below.

$ check_http -H 192.168.1.50 -p 8080


HTTP OK HTTP/1.1 200 OK - 332 bytes in 0.004 seconds |time=0.004144s;;;0.000000 siz
/ y | ;;;

For HTTPS running on a different port, do the following.

$ check_http -H 192.168.1.50 -S -p 8443


HTTP OK HTTP/1.1 200 OK - 332 bytes in 0.004 seconds |time=0.004144s;;;0.000000 siz

4. Check Specific URL


To check whether a specific webpage is available, use the -u option as shown below.

$ check_http -H 101hacks.com -u https://linux.101hacks.com/toc

5. Check SSL Certificate Expiry


You can check whether a SSL certificate of the website expires within the next X number of days as shown
below. In the following example, we are checking whether the website certificate expires in the next 365
days. The output indicates that it expires in 300 days.

$ check_http -H 101hacks.com -C 365


WARNING - Certificate expires in 300 day(s) (01/01/2011 10:10).
Syntax and Options

check_http -H hostname (or) -I ip-address {optional options}

Short Long
Option Description
Option Option
-H –hostname host name of the server where HTTP (or HTTPS) daemon is running
-I –IP-address ip address of the HTTP (or HTTPS) server
-p –port Port number where HTTP server runs. Default is 80
-4 –use-ipv4 This will use IPv4 connection
-6 –use-ipv6 This will use IPv6 connection
-S –ssl This will use HTTPS using default 443 port
-C –certificate Minimum number of days a SSL certiface must be valid.
-e –expect Expected response string. Default is HTTP/1
-s –string Expected content string.
-u –url URL to check
-P –post URL encoded http POST data
Do not wait for whole document body to download. Stop once the headers are
-N –no-body
downloaded.
Check whether a document is older than x seconds. Use 5 for 5 seconds, 5m for 5
-M –max-age
minutes, 5h for 5 hours, 5d for 5 days.
–content-
-T Indicate content type in header for POST request
type
-l –linespan Regular expression can span to new line (Use this with -r or -R option)
–regex, –
-r Use this regular expression to search for string in the HTTP page
ereg
-R –eregi Same as above, but with ignore case.

-a If the site user basic authentication send uid, pwd in the format uid:pwd
authorization
-A –useragent Pass the specified string as “User Agent” in HTTP header.
-k –header Add additional tags that should be sent in the HTTP header.
-L –link The output is wrapped as HTML link
When a URL is redirected, use this to either follow the URL, or send ok, warning,
-f –onredirect
or critical notification
Specify the minimum and maximum page size expected in bytes. Format is
-m –pagesize
minimum:maximum
-w –warning Response time in seconds for warning state
Specify the minimum and maximum page size expected in bytes. Format is
-m –pagesize
minimum:maximum
-w –warning Response time in seconds for warning state
-c –critical Response time in seconds for critical state
-t –timeout Number of seconds to wait before connection times out. Default is 10 seconds

Related Commands

check_ping
check_ftp

Comments on this entry are closed.


Christian August 1, 2011, 8:42 am

Can i specify what a valid response is, i.e. does the HTML display “xx welcome xx”?

LINK

hunk_lee October 26, 2011, 7:06 pm

Hello, ask a question, check_http detect page size, page size detection value changes again, the
alarm.

LINK

Alex Lam February 5, 2012, 7:47 pm

Is it possible to check a web page through an authenticated proxy server?

LINK

Marcin June 29, 2012, 7:54 am

That is superb artile I was looking for! Far better then Nagios documentation.

LINK
alexydz December 20, 2012, 10:29 pm

great! Far better then Nagios documentation.

LINK

nitin April 25, 2013, 5:45 am

Dear Friends,

I am gettinr this error in nagios3. can anyone help me out for this problem:-

Check-Website-Response
UNKNOWN 2013-04-25 18:11:24 0d 0h 55m 37s 4/4 RESPONSE: UNKNOWN – ERROR: /usr/bin/nc
does does not exist

i am really getting frustrate from this nagios error

LINK

Andrew May 31, 2013, 12:54 pm

nitin: you need to install the netcat package for your distribution which will provide
/usr/bin/nc
LINK

Mohan August 1, 2013, 6:20 am

Thanks for a good article on check_http

I had been using this plugin for a while. But today when I am trying to post an XML message to the
server, from console it works well but does not work with nrpe.
It says “Unknown option specified in config file ”

The command is

check_http -I 10.0.0.76 -p 8192 –url=”/MYServiceBus/” –post=”” –eregi=.Status_Code.0./Status_Code.


-c 7 -w 5 -v

Any pointer if I am missing anything but obvious.

LINK

sunardo September 8, 2013, 9:39 pm

hello.. I test the command from command line successfull, but when I insert in configuration
file (cfg) it gives Error: Service check command ‘check_http -H MYIP -u http://MYIP/test.php‘ specified
in service ‘HTTP’ for host ‘Server01’ not defined anywhere!
Here is my configuration :
define service{
use generic-service ; Name of service template to use
host_name Server01
service_description check http://MYIP/test.php
check_command check_http -H MYIP -u http://MYIP/test.php
notifications_enabled 0
}

Would you please be so kind as to help me?

LINK

ChrisW September 25, 2013, 1:25 pm

@sunardo – I just ran into this exact same thing. It looks like that with the default install,
there’s no configuration set up to tell Icinga where to look for the check_http executable. You need to add
the full path to it in the check_command. For example:
check_command /usr/share/nagios/plugins/check_http -H MYIP -u http://MYIP/test.php

LINK

JOB March 10, 2014, 6:38 am


Hi,
I Have problem with the check_http when I try ur command test , I have the next message :
check_http: command not found

and nagios show : connection refused

Thank you for your help

LINK

diramos March 12, 2014, 10:34 am

JOB,
Try to put full path in the command line. i.e:
/usr/nagios/libexec/check_http …..

Diramos

LINK

David April 12, 2014, 10:44 am

The -S option is not working with 2.0 plugins. It says -S is for version. How can I get it to work
with https with Nagios4 and plugins 2.x?
LINK

Thomas April 28, 2014, 4:12 pm

I am running into the same problem as David


command line output while running with -S is “check_http: Invalid option – SSL is not available”

LINK

Next post: UNIX / Linux whatis Command Examples


Previous post: UNIX / Linux split Command Examples

Home | Linux 101 Hacks – Table of Contents | Contact | Email | RSS | Copyright © 2009–2017 Ramesh Natarajan All rights
reserved | Terms of Service