Friday, August 27, 2010

Simple Nagios NRPE bash plugin to check a URL or image existance.

Copy and paste the following Bash script and name the file as check_url.




#!/bin/bash

VAR=`wget --spider $1 2>&1`
CHECK=`echo $VAR | grep '200 OK'`

if [ "$CHECK" != "" ]; then
echo "LOGO OK - Site Logo exist site is up"
exit 0
else
echo "LOGO CRITICAL - Site logo missing site is down"
exit 2
fi



Save it on /usr/lib/nagios/plugins/ and make it a executable file. chmod +x check_url

call the check_url with the image path or link path you wanted to check as follows.

/usr/lib/nagios/plugins/check_url http://www.google.com//intl/en_com/images/srpr/logo1w.png

3 comments:

  1. Clear and concise bash. Thanks!

    ReplyDelete
  2. Perfect Thank you!
    Light and easy for anyone to understand!
    Thanks

    ReplyDelete
  3. This will not work if web page has re-directions enable. You need to change your code on line 3:

    from

    VAR=`wget --spider $1 2>&1`

    To

    VAR=`wget --spider $1 --max-redirect=0 2>&1`

    hope it will help..

    ReplyDelete