add sendnotifications and update checker cron

Signed-off-by: szaimen <szaimen@e.mail.de>
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
szaimen 2021-11-30 13:11:19 +01:00
parent c8e8c27925
commit a46a36ee41
4 changed files with 77 additions and 1 deletions

View file

@ -367,6 +367,51 @@ class DockerActionManager
}
}
public function sendNotification(Container $container, string $subject, string $message)
{
if ($this->GetContainerStartingState($container) instanceof RunningState) {
$containerName = $container->GetIdentifier();
// schedule the exec
$url = $this->BuildApiUrl(sprintf('/containers/%s/exec', urlencode($containerName)));
$response = json_decode(
$this->guzzleClient->request(
'POST',
$url,
[
'json' => [
'AttachStdout' => true,
'Tty' => true,
'Cmd' => [
'bash',
'/notify.sh',
$subject,
$message
],
],
]
)->getBody()->getContents()
);
// get the id from the response
$id = $response['Id'];
// start the exec
$url = $this->BuildApiUrl(sprintf('/exec/%s/start', $id));
$this->guzzleClient->request(
'POST',
$url,
[
'json' => [
'Detach' => false,
'Tty' => true,
],
]
);
}
}
public function DisconnectContainerFromNetwork(Container $container)
{