Adding DNS check
This commit is contained in:
parent
80ba45b83b
commit
5986875818
1 changed files with 31 additions and 2 deletions
|
@ -126,9 +126,13 @@ class RunMonitoring extends Command
|
||||||
$result = $this->checkRequest($task, CURLPROTO_FTP | CURLPROTO_FTPS);
|
$result = $this->checkRequest($task, CURLPROTO_FTP | CURLPROTO_FTPS);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'dns':
|
||||||
|
$result = $this->checkDns($task);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Nothing to do here
|
// Nothing to do here
|
||||||
continue 2;
|
throw new Exception('Unknown type "'.$task->type.'"');
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_status = 1;
|
$new_status = 1;
|
||||||
|
@ -139,7 +143,8 @@ class RunMonitoring extends Command
|
||||||
}
|
}
|
||||||
catch(Exception $e) {
|
catch(Exception $e) {
|
||||||
//TODO: handle system exception differently
|
//TODO: handle system exception differently
|
||||||
$history = $this->saveHistory($task, false, $e->getMessage());
|
//$history = $this->saveHistory($task, false, $e->getMessage());
|
||||||
|
$this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
// Changing task timestamps and status
|
// Changing task timestamps and status
|
||||||
|
@ -254,6 +259,30 @@ class RunMonitoring extends Command
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final private function checkDns(Task $task) {
|
||||||
|
if (! function_exists('exec') || ! is_callable('exec')) {
|
||||||
|
throw new MonitoringException('The "exec" command is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($task->params) || empty($task->params)) {
|
||||||
|
throw new Exception('Params are required');
|
||||||
|
}
|
||||||
|
|
||||||
|
$cmd = 'nslookup '.trim($task->params).' '.$task->host;
|
||||||
|
|
||||||
|
// If command failed
|
||||||
|
if (false === $exec = exec($cmd.' '.$task->host, $output, $code)) {
|
||||||
|
throw new MonitoringException('Unable to execute DNS lookup');
|
||||||
|
}
|
||||||
|
|
||||||
|
// If command returned a non-zero code
|
||||||
|
if ($code > 0) {
|
||||||
|
throw new MonitoringException('DNS lookup task failed ('.$exec.')');
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
final private function checkRequest(Task $task, $protocol = CURLPROTO_HTTP | CURLPROTO_HTTPS) {
|
final private function checkRequest(Task $task, $protocol = CURLPROTO_HTTP | CURLPROTO_HTTPS) {
|
||||||
if (app()->environment() == 'local') {
|
if (app()->environment() == 'local') {
|
||||||
//throw new MonitoringException('Forcing error for testing');
|
//throw new MonitoringException('Forcing error for testing');
|
||||||
|
|
Loading…
Add table
Reference in a new issue