Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_website PHP script

Rating
0 votes
Favoured:
0
Current Version
1.0
Last Release Date
2010-09-01
Compatible With
  • Nagios 2.x
  • Nagios 3.x
Owner
License
Other
Hits
103276
Files:
FileDescription
check_websitecheck_website
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
PHP check-script which can check a website(URL) and react if errors like 404, 500 etc are returned.
PHP check-script which can check a website(URL) and react if errors like 404, 500 etc are returned.

#!/usr/local/bin/php

/*
** This script will check a response code from an URL
** Made by Soeren,IT 07-07-2010
*/

if(!isset($argv[1])) { echo "Usage: ./check_www "; exit(2); }

$url = "http://" . $argv[1];
$header = @get_headers($url, 1);

if(!$header) { echo "Could not connect to $url"; exit(2); }

if(preg_match('/200/', $header[0]))
{
print_r($header[0]);
exit(0);
}
elseif(preg_match('/302/', $header[0]))
{
print_r($header[0]);
exit(0);
}
elseif(preg_match('/301/', $header[0]))
{
print_r($header[0]);
exit(0);
}
else
{
print_r($header[0]);
exit(2);
}
?>



Remember to change /usr/local/bin/php to whereever your php-binary is located and chmod +x check_www.

commands.cfg:

define command{
command_name check_www
command_line /usr/local/libexec/nagios/check_www $ARG1$
}


services.cfg:


define service{
use default-critical
host_name webserver
contact_groups it-department
service_description Website: www.example.org
check_command check_www!www.example.org
}