Nagios check_http Plugin Examples for HTTP / HTTPS

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 http://test.com/test

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 test.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
This entry was posted in Linux How-To. Bookmark the permalink.

2 Responses to Nagios check_http Plugin Examples for HTTP / HTTPS

  1. sophiiete la says:

    Hello,
    please i cant understand the meaning of each parameter in the response of check_http, can you explain it to me :

    HTTP OK: HTTP/1.1 200 OK – 11609 bytes in 0.223 second response time

    THANK YOU,

    • paradox says:

      HTTP OK is the plugin stating that the HTTP check was completed and an HTTP service was found.

      HTTP/1.1 this will have a response code after it, in this case the response code 200 means the request has succeeded. The information returned with the response is dependent on the method used in the request.

      The rest is the amount of data the plugin sent and received in bytes and how long it took to respond.

Leave a Reply

Your email address will not be published. Required fields are marked *