stix77

Web Monitoring with sms warning

Sep 13th, 2013
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. <?php
  2. function checkURL($url) {
  3.    
  4.     //array of emails to send warning
  5.     $adminEmails=array("admin1@t-zones.sk","admin2@vodafonemail.cz");
  6.     //email of sender
  7.     $senderEmail="monitoring@domain.tld";
  8.     //array of valid http codes
  9.     $validStatus=array(200,301,302);
  10.     //minimum filesize in bytes
  11.     $minFileSize=500;
  12.    
  13.     if(!function_exists('curl_init')) die("Curl PHP package not installed!");
  14.    
  15.     $ch=curl_init();
  16.     curl_setopt($ch, CURLOPT_URL, $url);
  17.     curl_setopt($ch, CURLOPT_HEADER, true);
  18.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  19.     $response=curl_exec($ch);
  20.     $info=curl_getinfo($ch);
  21.     $statusCode=intval($info['http_code']);
  22.     $filesize=$info['size_download'];
  23.  
  24.     if(!in_array($statusCode,$validStatus) || $filesize<$minFileSize) {
  25.         $message = "Web ERROR ($url) - Status Code: $statusCode, Filesize: $filesize\r\n";
  26.         foreach($adminEmails as $email) {
  27.             mail($email, "Web Monitoring ERROR", $message, "From: $senderEmail\r\nReply-To: $senderEmail\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\n");
  28.         }
  29.     }
  30. }
  31.  
  32. checkURL("http://google.com/");
  33. ?>
Add Comment
Please, Sign In to add comment