By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,086 Members | 1,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,086 IT Pros & Developers. It's quick & easy.

HostWatch * Monitoring

P: n/a
Hi All,

how I can make a simply HostWatch - system which use a mysql DB and send me
an e-Mail if the Server goes off and again on?
I began to programm this last night, but the MySQL inquiry is too hard for
me! =(

Thats my code:

----
<?php
$dbhost = "*****";
$dbuser = "*****";
$dbpass = "*****";
$dbname = "*****";

$db = mysql_connect($dbhost,$dbuser,$dbpass);
$res = mysql_db_query($dbname, "select * from adressen");
$num = mysql_num_rows($res);

for ($i=0; $i<$num; $i++)
{
$ID = mysql_result($res, $i, "ID");
$IP = mysql_result($res, $i, "IP");
$PO = mysql_result($res, $i, "PORT");
/////////////////////////////////////////////////////////////////////
$s = explode(" ",microtime());
$Starttime = $s[1]+$s[0];

// AUSWERTUNG HIER ANFANG PING & PORT KONTROLLE ==> ANFANG <==
$socket = @fsockopen($IP, $PO, &$errno, &$errstr, 2);
// AUSWERTUNG HIER ENDE PING & PORT KONTROLLE ==> ENDE <==

$t = explode( " ", microtime() );
$Endtime= $t[1] + $t[0];
$finalzeit = number_format( $Endtime-$Starttime, 3);
/////////////////////////////////////////////////////////////////////

if ($socket) {
mysql_select_db($dbname);
$query2 = "INSERT INTO monitoring (AID,STATUS,PING) values
('$ID','1','$finalzeit')" or die(mysql_error());
mysql_query($query2);
//$res2 = mysql_db_query($dbname, "select t.* from monitoring t left join
monitoring u on u.AID=t.AID and u.ZEIT>t.ZEIT where t.STATUS=0 and u.ID is
null");
//$num2 = mysql_num_rows($res2);
//if($num2 == 1){
// mail("***","Server wieder ON","Der Server ($ID) geht wieda","FROM:
alert@***.com");
//}else{
}else{
$query3 = "INSERT INTO monitoring (AID,STATUS,PING) values
('$ID','0','$finalzeit')" or die(mysql_error());
mysql_query($query3);

$res3 = mysql_db_query($dbname,".... ????");
$num3 = mysql_num_rows($res3);
if($num3 <= 1){

}else{
mail("****","Server offline","Der Server mit der ID $ID ist
offline","FROM: alert@***.com");
}
}
}
mysql_close($db);

?>
-----
This script is in a cronjob! Every minute the server execute this script.
That is, that I get every Minute an e-Mail Message. If the Server goes for 2
hours off I was received 60 messages.
My aim is to get a message one time for offline and if the server goes
online again one for online.

I hope for your help!

Gretting!
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.