728x90
<?php
$MAX_CHECK_LIMIT_PERCENT = 80.0;
function clearPatternStr($str, $pattern = "\n", $replace = ""){
while(strstr($str,$pattern))
$str = preg_replace("(".$pattern.")",$replace,$str);
return $str;
}
function generateTxt($msg, $indexs){
global $MAX_CHECK_LIMIT_PERCENT;
$content = date("Y-m-d H:i:s",time())." 기준 하드용량 체크 내역입니다. <BR>";
$content.= " 하드사용량이 기준치 이상이 되는 파티션이 발견되어 경고메일을 보냅니다.<BR> ";
$content.= " 하드 디스크의 사용량을 점검하여 불필요한 파일을 정리하십시오.<BR>";
$content.= " 현재 디스크 사용량 판별 기준치 ".$MAX_CHECK_LIMIT_PERCENT." % <BR>";
$content.= " <BR>";
$t = 0;
for($i = 0; $i < sizeof($msg); $i++){
if($i == $indexs[$t]){
$content.= "<font color='red'><strong>".$msg[$i]."</strong></font><BR>";
$t++;
}else
$content.= $msg[$i]."<BR>";
}
return $header.$content;
}
$command = "df -h";
$output = exec($command, $msg, $err);
$indexs = Array();
// connection 과 file get이 제대로 되었는지 확인
foreach($msg as $num => $val ){
if($num==0) continue;
$line = clearPatternStr($val, " "," ");
$field = explode(" ", $line);
if((float)$field[4] > $MAX_CHECK_LIMIT_PERCENT){
$flag = true;
array_push($indexs, $num);
}
}
$content = generateTxt($msg, $indexs);
if($flag) {
// 용량체크후, 기준치 보다 이상일 경우에 해당 로직 수행
/* code */
}
?>
내 경우에는 하드 디스크 용량을 체크후 일정 사용량이상(퍼센트로 판별)이 되면 이메일로 메일을 보내도록 구성하였다.
coolsms에 있는 SMS 문자 발송을 참고하여 XPertMailer 을 사용해서 메일을 보내는 로직으로 변경하였다.
참고 : http://www.coolsms.co.kr/?mid=download&category=40869&document_srl=123552