5 Nagios check_http Plugin Examples for HTTP / HTTPS

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 size=332B;;;0

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 size=332B;;;0

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 size=332B;;;0

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 size=332B;;;0

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 Option Long Option Option Description
-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
-N –no-body Do not wait for whole document body to download. Stop once the headers are downloaded.
-M –max-age Check whether a document is older than x seconds. Use 5 for 5 seconds, 5m for 5 minutes, 5h for 5 hours, 5d for 5 days.
-T –content-type Indicate content type in header for POST request
-l –linespan Regular expression can span to new line (Use this with -r or -R option)
-r –regex, –ereg Use this regular expression to search for string in the HTTP page
-R –eregi Same as above, but with ignore case.
-a –authorization If the site user basic authentication send uid, pwd in the format uid:pwd
-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
-f –onredirect When a URL is redirected, use this to either follow the URL, or send ok, warning, or critical notification
-m –pagesize Specify the minimum and maximum page size expected in bytes. Format is minimum:maximum
-w –warning Response time in seconds for warning state
-m –pagesize Specify the minimum and maximum page size expected in bytes. Format is 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”?

  • 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.

  • Alex Lam February 5, 2012, 7:47 pm

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

  • Marcin June 29, 2012, 7:54 am

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

  • alexydz December 20, 2012, 10:29 pm

    great! Far better then Nagios documentation.

  • 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

  • Andrew May 31, 2013, 12:54 pm

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

  • 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.

  • 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?

  • 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

  • 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

  • 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

  • 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?

  • 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”