View Single Post
  #28  
Old 2nd September 2006, 21:41
MicCo MicCo is offline
Junior Member
 
Join Date: Aug 2006
Location: Denmark
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Hi Falko,

Regarding:
Quote:
Originally Posted by falko
What does /root/ispconfig/scripts/shell/check_services.php look like when this happens again?
This is how it looks before adding any other monitoring:
Quote:
<?php

class check_services {

function warning()
{

$warning = "";

if(!$this->_check_tcp("213.173.250.118",80)) {
$warning .= "WARNING: service web not running (server: epsilon.eurohost.dk, port: 80)!\n\n";

}
if(!$this->_check_ftp("213.173.250.118",21)) {
$warning .= "WARNING: service ftp not running (server: epsilon.eurohost.dk, port: 21)!\n\n";

}
if(!$this->_check_tcp("213.173.250.118",25)) {
$warning .= "WARNING: service mail not running (server: epsilon.eurohost.dk, port: 25)!\n\n";

}
if(!$this->_check_tcp("213.173.250.118",110)) {
$warning .= "WARNING: service pop3 not running (server: epsilon.eurohost.dk, port: 110)!\n\n";

}



if($warning != ""){
$warning .= "Message generated at ".date("F j, Y, G:i", time()).".\n";
return $warning;
} else {
return false;
}

}

function _check_tcp ($host,$port) {

$fp = fsockopen ($host, $port, &$errno, &$errstr, 2);

if ($fp) {
fclose($fp);
return true;
} else {
return false;
}
}

function _check_udp ($host,$port) {

$fp = fsockopen ('udp://'.$host, $port, &$errno, &$errstr, 2);

if ($fp) {
fclose($fp);
return true;
} else {
return false;
}
}

function _check_ftp ($host,$port){

$conn_id = @ftp_connect($host, $port);

if($conn_id){
@ftp_close($conn_id);
return true;
} else {
return false;
}
}
}

$cs = new check_services;

if(is_file("/home/admispconfig/ispconfig/adminmail.txt")){
$fp = fopen ("/home/admispconfig/ispconfig/adminmail.txt", "r");
$email = trim(fread($fp, filesize ("/home/admispconfig/ispconfig/adminmail.txt")));
fclose($fp);
$email = str_replace("\r\n", "", $email);
$email = str_replace("\r", "", $email);
$email = str_replace("\n", "", $email);
}
$msg = $cs->warning();
if(!empty($email) && strstr($email, "@") && strlen($email) > 3 && $msg) mail($email, "WARNING: services not running", $msg);
?>
This is what it looks like when adding monitoring for service at port 443:

Quote:
<?php

class check_services {

function warning()
{

$warning = "";

if(!$this->_check_tcp("213.173.250.118",80)) {
$warning .= "WARNING: service web not running (server: epsilon.eurohost.dk, port: 80)!\n\n";

}
if(!$this->_check_ftp("213.173.250.118",21)) {
$warning .= "WARNING: service ftp not running (server: epsilon.eurohost.dk, port: 21)!\n\n";

}
if(!$this->_check_tcp("213.173.250.118",25)) {
$warning .= "WARNING: service mail not running (server: epsilon.eurohost.dk, port: 25)!\n\n";

}
if(!$this->_check_tcp("213.173.250.118",110)) {
$warning .= "WARNING: service pop3 not running (server: epsilon.eurohost.dk, port: 110)!\n\n";

}
if(!$this->_check_tcp("213.173.250.118/SSL",443)) {
$warning .= "WARNING: service not running (server: epsilon.eurohost.dk, port: 443)!\n\n";

}



if($warning != ""){
$warning .= "Message generated at ".date("F j, Y, G:i", time()).".\n";
return $warning;
} else {
return false;
}

}

function _check_tcp ($host,$port) {

$fp = fsockopen ($host, $port, &$errno, &$errstr, 2);

if ($fp) {
fclose($fp);
return true;
} else {
return false;
}
}

function _check_udp ($host,$port) {

$fp = fsockopen ('udp://'.$host, $port, &$errno, &$errstr, 2);

if ($fp) {
fclose($fp);
return true;
} else {
return false;
}
}

function _check_ftp ($host,$port){

$conn_id = @ftp_connect($host, $port);

if($conn_id){
@ftp_close($conn_id);
return true;
} else {
return false;
}
}
}

$cs = new check_services;

if(is_file("/home/admispconfig/ispconfig/adminmail.txt")){
$fp = fopen ("/home/admispconfig/ispconfig/adminmail.txt", "r");
$email = trim(fread($fp, filesize ("/home/admispconfig/ispconfig/adminmail.txt")));
fclose($fp);
$email = str_replace("\r\n", "", $email);
$email = str_replace("\r", "", $email);
$email = str_replace("\n", "", $email);
}
$msg = $cs->warning();
if(!empty($email) && strstr($email, "@") && strlen($email) > 3 && $msg) mail($email, "WARNING: services not running", $msg);
?>
Looking forward to see Your comment.
__________________
Best regards,

MicCo
________________________________
Reply With Quote