{ Berbagi, Menulis, Dan Mengajar } Ilmu… » 7. Operating System » SERVER CHECK PHP By ARIP
SERVER CHECK PHP By ARIP
<?
/*
Fungsi untuk mengecek beberapa kondisi server.
Jika ada yang tidak beres, akan mengirim sms ke admin.
arif@ptpn-11.com
25/04/2012
*/
$host = ‘localhost';
$user = ‘gammu';
$pass = ‘gammu132′;
$db_name = ‘gammu';
$link = mysql_connect($host, $user, $pass);
mysql_select_db($db_name, $link);
$admin = array(
“arif” => ‘081332218352’,
“nofry” => ‘08563532669’,
);
$spaceHD = getSpaceHD();
if ($spaceHD)
kirimSMS($spaceHD);
function kirimSMS($text){
$valuesnya = ”;
global $admin;
foreach ($admin as $i => $value)
$valuesnya .= “(‘$value’, ‘$text’, ‘Gammu’),”;
$values = rtrim($valuesnya, ‘,’);
$query = “INSERT INTO outbox(DestinationNumber, TextDecoded, CreatorID) VALUES $values”;
$hasil = mysql_query($query);
}
function getSpaceHD(){
$output = shell_exec(‘df -h’);
$result = str_replace(array(“\r\n”, “\r”, “\n”), ” “,$output);
$datapisah = explode(” “,$result);
$hasil = ”;
foreach ($datapisah as $i => $value)
{
if (substr($value, -1) == ‘%’) {
if (substr($value, 0, -1) > 80) {
$hasil .= $value.’ ‘;
$hasil .= $datapisah[$i+1].’\n';
}
}
}
if ($hasil <> ”) {
$ket = “Hard Disk server penuh, harap segera dipindah. \n”.$hasil.'{SMS Server NXI}';
return $ket;
}
else
return false;
}
function getMemHD(){
$output = shell_exec(‘df -h’);
$result = str_replace(array(“\r\n”, “\r”, “\n”), ” “,$output);
$datapisah = explode(” “,$result);
$hasil = ”;
foreach ($datapisah as $i => $value)
{
if (substr($value, -1) == ‘%’) {
if (substr($value, 0, -1) > 80) {
$hasil .= $value.’ ‘;
$hasil .= $datapisah[$i+1].’\n';
}
}
}
if ($hasil <> ”) {
$ket = “Hard Disk server penuh, harap segera dipindah. \n”.$hasil.'{SMS Server NXI}';
return $ket;
}
else
return false;
}
?>
Filed under: 7. Operating System