Created
April 13, 2020 02:20
-
-
Save Zobber/a09f0e22cf4ca616a64f67793367140d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // This script is run every 5 minutes | |
| // A ping failure will generate an email | |
| // We ping critical servers that serve to identify both a server failure and/or a circuit or VPN failure. | |
| // Define descriptions and ip addresses below to test on | |
| $hosts = array( | |
| array("description" => "Google.com", "hostip" => "www.google.com"), | |
| array("description" => "Office1", "hostip" => "192.168.1.2") | |
| ); | |
| // Setup the email parameters and the ping count (one should suffice) | |
| $mailto = "you@yourdomain.com"; | |
| $mailfrom = "you@yourdomain.com"; | |
| $pingcount =2; | |
| // Loop on each host and ping it | |
| // check the return code from exec via status. | |
| // cmdoutput holds the full ping result as an array but we don't really need it. | |
| foreach ($hosts as $host){ | |
| $description = $host["description"]; | |
| $hostip = $host["hostip"]; | |
| unset($cmdoutput); | |
| exec("ping -n $pingcount $hostip", $cmdoutput, $status); | |
| $finalout = ""; | |
| foreach ($cmdoutput as $value) { | |
| $finalout = $finalout.$value."\n"; | |
| } | |
| echo $finalout; | |
| if($status == 0){ | |
| echo("<BR>$description ($hostip) is Up<BR>"); | |
| } | |
| else { | |
| // echo("$description ($hostip) is Down<br>"); | |
| mail($mailto,"Network Issue with $description!",$finalout,"From: $mailfrom"); | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment