/ Published in: PHP
Script File launched every 3 minutes to check WebSite status.
It uses AWSSDKforPHP library http://docs.amazonwebservices.com/AWSSdkDocsPHP/latest/DeveloperGuide/php-dg-setup.html
It uses AWSSDKforPHP library http://docs.amazonwebservices.com/AWSSdkDocsPHP/latest/DeveloperGuide/php-dg-setup.html
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php require_once('AWSSDKforPHP/sdk.class.php'); function checkOnline($domain) { //get answer if ($response) return true; return false; } function sendNotificationEmail($message){ $email = new AmazonSES(); $response = $email->send_email( "[email protected]" // Email to send notifications ), ), 'Data' => 'WebSite not available', 'Charset' => 'UTF-8' ), 'Charset' => 'UTF-8' ), 'Charset' => 'UTF-8' ) ) ), //'ReplyToAddresses' => array('[email protected]', '[email protected]') ) ); // Success? return $response->isOK(); } 'instanceId'=>'i-1923cb7e', 'testUrl'=>'http://www.domain1.com', ), 'instanceId'=>'i-32243d57', 'testUrl'=>'http://www.domain2.com', ), 'instanceId'=>'i-ddcfc1bb', 'testUrl'=>'http://www.domain3.com', ) ); $ec2 = new AmazonEC2(); foreach ($Instances as $key => $val){ echo $key." => ". $val["instanceId"] ; if(checkOnline($val["testUrl"])) { echo "OnLine"; } else{ $response = $ec2->reboot_instances($val["instanceId"]); echo "OffLIne"; if(!$response->isOK()){ sendNotificationEmail("The WebSite ".$key." is not available and it couldn't be restarted \n please check status ".$val["testUrl"]); } else{ sendNotificationEmail("The WebSite ".$key." and it's been restarted \n check status here ".$val["testUrl"]); } } } //You may add crontab using : */3 * * * * wget --spider 'http://www.yourdomain.com/scriptJob.php' ?>