verbesserte Fehlerbehandlung bei offline vom Bot

This commit is contained in:
Marko Oldenburg 2016-02-02 22:06:40 +01:00
parent 9a89a51132
commit a3779c527d

View File

@ -35,7 +35,7 @@ use Time::HiRes qw(gettimeofday);
use HttpUtils; use HttpUtils;
use Blocking; use Blocking;
my $version = "0.1.57"; my $version = "0.1.60";
@ -307,7 +307,7 @@ sub HOMBOT_RetrieveHomebotInfoFinished($$$) {
if( $hash->{helper}{requestErrorCounter} > 1 && ReadingsVal( $name, "luigiHttpSrvState", "not running" ) eq "running" ) { if( $hash->{helper}{requestErrorCounter} > 1 && ReadingsVal( $name, "luigiHttpSrvState", "not running" ) eq "running" ) {
Log3 $name, 3, "HOMBOT ($name) - Connecting Problem, Check Luigi HTTP Server" unless(exists($hash->{helper}{RUNNING_PID})); Log3 $name, 3, "HOMBOT ($name) - Connecting Problem, will check Luigi HTTP Server" unless(exists($hash->{helper}{RUNNING_PID}));
$hash->{helper}{RUNNING_PID} = BlockingCall("HOMBOT_Check_Bot_Alive", $name."|request", "HOMBOT_Evaluation_Bot_Alive", 15, "HOMBOT_Aborted_Bot_Alive", $hash) unless(exists($hash->{helper}{RUNNING_PID})); $hash->{helper}{RUNNING_PID} = BlockingCall("HOMBOT_Check_Bot_Alive", $name."|request", "HOMBOT_Evaluation_Bot_Alive", 15, "HOMBOT_Aborted_Bot_Alive", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
} }
@ -721,10 +721,9 @@ sub HOMBOT_HTTP_POSTerrorHandling($$$) {
if( $hash->{helper}{setErrorCounter} > 1 && ReadingsVal( $name, "luigiHttpSrvState", "not running" ) eq "running" ) { if( $hash->{helper}{setErrorCounter} > 1 && ReadingsVal( $name, "luigiHttpSrvState", "not running" ) eq "running" ) {
Log3 $name, 3, "HOMBOT ($name) - Start SSH Connection, Check Luigi HTTP Server"; Log3 $name, 3, "HOMBOT ($name) - Connecting Problem, will check Luigi HTTP Server" unless(exists($hash->{helper}{RUNNING_PID}));
HOMBOT_SSH_Read( $hash, 'uname' );
Log3 $name, 4, "HOMBOT ($name) - ENDE check ssh Error Schleife"; $hash->{helper}{RUNNING_PID} = BlockingCall("HOMBOT_Check_Bot_Alive", $name."|set", "HOMBOT_Evaluation_Bot_Alive", 15, "HOMBOT_Aborted_Bot_Alive", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
} }
readingsBeginUpdate( $hash ); readingsBeginUpdate( $hash );
@ -834,46 +833,29 @@ sub HOMBOT_Check_Bot_Alive($) {
my $host = $hash->{HOST}; my $host = $hash->{HOST};
my $sshalive; my $sshalive;
Log3 $name, 4, "HOMBOT ($name) - Start SSH Connection for check Hombot alive"; Log3 $name, 3, "HOMBOT ($name) - Start SSH Connection for check Hombot alive";
$sshalive = qx(/usr/bin/sshpass -p 'most9981' /usr/bin/ssh root\@$host "uname" );
$sshalive = qx(/usr/bin/sshpass -p 'most9981' /usr/bin/ssh root\@$host 'uname' );
if( $sshalive ) { if( $sshalive ) {
my $hombotstate = ( ( $sshalive =~ /Linux/ and not ( $sshalive =~ /Connection refused/ or $sshalive =~ /No route to host/ or $sshalive =~ /Connection reset by peer/) ) ? "online" : "offline"); my $lgSrvPID = ((split (/\s+/,qx(/usr/bin/sshpass -p 'most9981' /usr/bin/ssh root\@$host 'ps | grep -v grep | grep /usr/bin/lg.srv' )))[1]);
if( $hombotstate eq "online" ) { if( not defined( $lgSrvPID ) ) {
Log3 $name, 4, "HOMBOT ($name) - Hombot is online, will check lg.srv Prozess"; qx(/usr/bin/sshpass -p 'most9981' /usr/bin/ssh root\@$host '/usr/bin/lg.srv &' );
my $lgSrvPID = ((split (/\s+/,qx(/usr/bin/sshpass -p 'most9981' /usr/bin/ssh root\@$host 'ps | grep -v grep | grep /usr/bin/lg.srv' )))[1]);
if( not defined( $lgSrvPID ) ) {
Log3 $name, 4, "HOMBOT ($name) - Luigi Webserver is not running, i'll start it";
qx(/usr/bin/sshpass -p 'most9981' /usr/bin/ssh root\@$host '/usr/bin/lg.srv &' );
Log3 $name, 4, "HOMBOT ($name) - Luigi Webserver was restarted"; return "$name|$callingtype|restarted";
return "$name|$callingtype|restarted";
} else {
Log3 $name, 4, "HOMBOT ($name) - Luigi Webserver is running";
return "$name|$callingtype|running";
}
} else { } else {
Log3 $name, 4, "HOMBOT ($name) - Hombot is not online"; return "$name|$callingtype|running";
return "$name|$callingtype|offline";
} }
} else { } else {
Log3 $name, 4, "HOMBOT ($name) - Sorry, I have problems with processing"; return "$name|$callingtype|offline";
return "$name|$callingtype|error";
} }
} }
@ -888,16 +870,11 @@ sub HOMBOT_Evaluation_Bot_Alive($) {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $callingtype = $a[1]; my $callingtype = $a[1];
my $alivestate = $a[2]; my $alivestate = $a[2];
Log3 $name, 3, "HOMBOT ($name) - String = $string";
delete($hash->{helper}{RUNNING_PID}); delete($hash->{helper}{RUNNING_PID});
return if($hash->{helper}{DISABLED}); return if($hash->{helper}{DISABLED});
Log3 $name, 3, "HOMBOT ($name) - alivestate = $alivestate";
Log3 $name, 3, "HOMBOT ($name) - callingtype = $callingtype";
readingsBeginUpdate( $hash ); readingsBeginUpdate( $hash );
if( $callingtype eq "request" ) { if( $callingtype eq "request" ) {
@ -933,17 +910,6 @@ sub HOMBOT_Evaluation_Bot_Alive($) {
Log3 $name, 3, "HOMBOT ($name) - Hombot is not online"; Log3 $name, 3, "HOMBOT ($name) - Hombot is not online";
} }
elsif( $alivestate eq "error" ) {
$hash->{helper}{requestErrorCounter} = 0;
readingsBulkUpdate( $hash, "luigiHttpSrvState", "not running");
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
readingsBulkUpdate ( $hash, "state", "unknown Errors");
Log3 $name, 3, "HOMBOT ($name) - unknown Errors, please check your Network Configuration";
}
} }
elsif( $callingtype eq "set" ) { elsif( $callingtype eq "set" ) {
@ -953,6 +919,7 @@ sub HOMBOT_Evaluation_Bot_Alive($) {
readingsBulkUpdate( $hash, "luigiHttpSrvState", "running"); readingsBulkUpdate( $hash, "luigiHttpSrvState", "running");
readingsBulkUpdate( $hash, "hombotState", "ONLINE"); readingsBulkUpdate( $hash, "hombotState", "ONLINE");
HOMBOT_Get_stateRequestLocal( $hash );
Log3 $name, 3, "HOMBOT ($name) - Luigi Webserver was restarted"; Log3 $name, 3, "HOMBOT ($name) - Luigi Webserver was restarted";
} }
@ -963,6 +930,7 @@ sub HOMBOT_Evaluation_Bot_Alive($) {
readingsBulkUpdate( $hash, "luigiHttpSrvState", "running"); readingsBulkUpdate( $hash, "luigiHttpSrvState", "running");
readingsBulkUpdate( $hash, "hombotState", "ONLINE"); readingsBulkUpdate( $hash, "hombotState", "ONLINE");
HOMBOT_Get_stateRequestLocal( $hash );
Log3 $name, 3, "HOMBOT ($name) - Luigi Webserver is running"; Log3 $name, 3, "HOMBOT ($name) - Luigi Webserver is running";
} }
@ -977,17 +945,6 @@ sub HOMBOT_Evaluation_Bot_Alive($) {
Log3 $name, 3, "HOMBOT ($name) - Hombot is not online"; Log3 $name, 3, "HOMBOT ($name) - Hombot is not online";
} }
elsif( $alivestate eq "error" ) {
$hash->{helper}{setErrorCounter} = 0;
readingsBulkUpdate( $hash, "luigiHttpSrvState", "not running");
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
readingsBulkUpdate ( $hash, "state", "unknown Errors");
Log3 $name, 3, "HOMBOT ($name) - unknown Errors, please check your Network Configuration";
}
} }
readingsEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );