mirror of https://github.com/MISP/MISP
chg: [internal] Log exception for remote server POST test
parent
10b9dc4db3
commit
8dd8e58f5b
|
@ -128,6 +128,16 @@ class ServerSyncTool
|
|||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $testString
|
||||
* @return HttpSocketResponseExtended
|
||||
* @throws Exception
|
||||
*/
|
||||
public function postTest($testString)
|
||||
{
|
||||
return $this->post('/servers/postTest', ['testString' => $testString]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param mixed $data
|
||||
|
|
|
@ -2518,16 +2518,16 @@ class Server extends AppModel
|
|||
if (!$testFile) {
|
||||
throw new Exception("Could not load payload for POST test.");
|
||||
}
|
||||
$HttpSocket = $this->setupHttpSocket($server);
|
||||
$request = $this->setupSyncRequest($server);
|
||||
$uri = $server['Server']['url'] . '/servers/postTest';
|
||||
|
||||
$serverSync = new ServerSyncTool($server, $this->setupSyncRequest($server));
|
||||
|
||||
try {
|
||||
$response = $HttpSocket->post($uri, json_encode(array('testString' => $testFile)), $request);
|
||||
$response = $serverSync->postTest($testFile);
|
||||
$contentEncoding = $response->getHeader('Content-Encoding');
|
||||
$rawBody = $response->body;
|
||||
$response = $this->jsonDecode($rawBody);
|
||||
$response = $response->json();
|
||||
} catch (Exception $e) {
|
||||
$this->logException("Invalid response for remote server {$server['Server']['name']} POST test.", $e);
|
||||
$title = 'Error: POST connection test failed. Reason: ' . $e->getMessage();
|
||||
$this->loadLog()->createLogEntry('SYSTEM', 'error', 'Server', $server['Server']['id'], $title);
|
||||
return ['status' => 8];
|
||||
|
|
Loading…
Reference in New Issue