Monitoring Website URL Status Using Nagios check_http

Nagios Core and Nagios XI has a features to monitoring website URL status. By default Nagios supports URL monitoring and there is an command check_http, however if you want to monitor URL like SSL certification you can also do by extending the command options.

Monitoring Website URL Status

Check manually before writing the commands in commands.cfg file. which give us an confirmation that how we have to add commands

./check_http -H server-FQDN --onredirect=follow -s "Keyword" -f ok -I IP-ADDRESS -u '/abc/' -p PORT-NUMBER
HTTP OK: HTTP/1.1 200 OK - 6707 bytes in 0.004 second response time |time=0.004296s;;;0.000000 size=6707B;;;0

If website has an redirection URL you have to follow the redirection by adding onredirect

./check_http -H server-FQDN -f follow -I IP-ADDRESS -u "/abc/" -p PORTNUMBER -a "USERNAME:PASSWORD"
HTTP OK: HTTP/1.1 200 OK - 6707 bytes in 0.003 second response time |time=0.003003s;;;0.000000 size=6707B;;;0

define the command to check HTTP status

# vi /usr/local/nagios/etc/commands.cfg
define command {
command_name check_website
command_line $USER1$/check_http -H $HOSTADDRESS$ $ARG1$
}

define command {
command_name check_http_cert
command_line $USER1$/check_http -H $HOSTADDRESS$ -C $ARG1$
}

define command {
command_name check_http_content
command_line $USER1$/check_http -H $HOSTADDRESS$ --onredirect=follow -s "$ARG1$"
}

Now Add the service configuration

Include below configuration in HOSTNAME.cfg file. if there is no host is defined then define one.

define service {
host_name servername.arkit.co.in
service_description _abc_ URL Content Regex1
use generic-service
check_command check_website!-r "KeyWord" -f ok -I IP-ADDRESS -u '/abc/' -p 8080!!!!!!!
max_check_attempts 5
check_interval 5
retry_interval 1
check_period timeperiod_24x7
notification_interval 60
notification_period timeperiod_24x7
notification_options n
notifications_enabled 0
contacts nagiosadmin
register 0
}

define service {
host_name servername.arkit.co.in
service_description _abc_ URL Content1
use generic-service
check_command check_website!-s "KeyWord" -f ok -I IP-ADDRESS -u '/abc/' -p 8080!!!!!!!
max_check_attempts 5
check_interval 5
retry_interval 1
check_period timeperiod_24x7
notification_interval 60
notification_period timeperiod_24x7
notifications_enabled 0
contacts nagiosadmin
register 0
}

define service {
host_name servername.arkit.co.in
service_description _abc_ URL Monitoring1
use generic-service
check_command check_website! -f ok -I IP-ADDRESS -u '/abc/' -p 8080!!!!!!!
max_check_attempts 5
check_interval 5
retry_interval 1
check_period timeperiod_24x7
notification_interval 60
notification_period timeperiod_24x7
notifications_enabled 0
contacts nagiosadmin
register 0
}

Above services defined to monitor Website URL status on given port number example is 8080. Checking for website content and search for regular expression given on the command

SSL Certificate Status Monitoring

To check SSL Certificate status using check_http below is the command

$ ./check_http -H google.com -C 30,14
OK - Certificate '*.google.com' will expire on Tue 09 Apr 2019 02:15:00 PM PDT.

check_http command options

Options:

  • -h, –help Print detailed help screen
  • -V, –version Print version information
  • –extra-opts=[section][@file] Read options from an ini file. See https://www.nagios-plugins.org/doc/extra-opts.html for usage and examples.
  • -H, –hostname=ADDRESS Host name argument for servers using host headers (virtual host) Append a port to include it in the header (eg: example.com:5000)
  • -I, –IP-address=ADDRESS IP address or name (use numeric address if possible to bypass DNS lookup).
  • -p, –port=INTEGER Port number (default: 80)
  • -4, –use-ipv4 Use IPv4 connection
  • -6, –use-ipv6 Use IPv6 connection
  • -S, –ssl=VERSION Connect via SSL. Port defaults to 443. VERSION is optional, and prevents auto-negotiation (1 = TLSv1, 2 = SSLv2, 3 = SSLv3).
  • –sni Enable SSL/TLS hostname extension support (SNI)
  • -C, –certificate=INTEGER[,INTEGER] Minimum number of days a certificate has to be valid. Port defaults to 443 (when this option is used the URL is not checked.)
  • -J, –client-cert=FILE Name of file that contains the client certificate (PEM format) to be used in establishing the SSL session
  • -K, –private-key=FILE Name of file containing the private key (PEM format) matching the client certificate
  • -e, –expect=STRING Comma-delimited list of strings, at least one of them is expected in the first (status) line of the server response (default: HTTP/1.) If specified skips all other status line logic (ex: 3xx,4xx, 5xx processing)
  • -d, –header-string=STRING String to expect in the response headers
  • -s, –string=STRING String to expect in the content
  • -u, –url=PATH URL to GET or POST (default: /)
  • -P, –post=STRING URL encoded http POST data
  • -j, –method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE) Set HTTP method.
  • -N, –no-body Don’t wait for document body: stop reading after headers. (Note that this still does an HTTP GET or POST, not a HEAD.)
  • -M, –max-age=SECONDS Warn if document is more than SECONDS old. the number can also be of the form “10m” for minutes, “10h” for hours, or “10d” for days.
  • -T, –content-type=STRING specify Content-Type header media type when Posting
  • -l, –linespan Allow regex to span newlines (must precede -r or -R)
  • -r, –regex, –ereg=STRING Search page for regex STRING
  • -R, –eregi=STRING Search page for case-insensitive regex STRING
  • –invert-regex Return CRITICAL if found, OK if not
  • -a, –authorization=AUTH_PAIR Username:password on sites with basic authentication
  • -b, –proxy-authorization=AUTH_PAIR Username:password on proxy-servers with basic authentication
  • -A, –useragent=STRING String to be sent in http header as “User Agent”
  • -k, –header=STRING Any other tags to be sent in http header. Use multiple times for additional headers
  • -E, –extended-perfdata Print additional performance data
  • -L, –link Wrap output in HTML link (obsoleted by urlize)
  • -f, –onredirect=<ok|warning|critical|follow|sticky|stickyport> How to handle redirected pages. sticky is like follow but stick to the specified IP address. sticky port also ensures port stays the same.
  • -m, –pagesize=INTEGER<:INTEGER> Minimum page size required (bytes) : Maximum page size required (bytes)
  • -w, –warning=DOUBLE Response time to result in warning status (seconds)
  • -c, –critical=DOUBLE Response time to result in critical status (seconds)
  • -t, –timeout=INTEGER Seconds before connection times out (default: 10)

That’s it.

Related Articles

Monitoring Tool

EMC Storage Monitoring

NagiosCore Graphs

Thanks for your wonderful Support and Encouragement

Ravi Kumar Ankam

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

5 Responses

  1. blank Manthan says:

    In which file this service configuration need to add ?

    *Now Add the service configuration*

    • blank ARK says:

      You have to define the host configuration, if there is no host defined. In same host config file you have to add above service defination.

      • blank Manthan says:

        i have add new host and it showing on browser but service not showing on monitoring page but using ./check_website and whole path i am getting website status . i am using redirection url.

        so please advise

  2. blank Rodrigo Silva says:

    Hi, I need monitorig website whith check_http, but when I realized the configuration appear the date incorrect, no the date website client. Also, I need configuring that are recirect ?? I must use ondirect ??. Option H ??

Leave a Reply

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