mirror of
https://github.com/Karaka-Management/oms-Monitoring.git
synced 2026-01-11 16:38:40 +00:00
82 lines
2.2 KiB
PHP
Executable File
82 lines
2.2 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Jingga
|
|
*
|
|
* PHP Version 8.1
|
|
*
|
|
* @package Modules\Monitoring
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 2.0
|
|
* @version 1.0.0
|
|
* @link https://jingga.app
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Monitoring\Controller;
|
|
|
|
use Modules\Admin\Models\SettingsEnum;
|
|
use phpOMS\Contract\RenderableInterface;
|
|
use phpOMS\Message\Mail\Email;
|
|
use phpOMS\Message\RequestAbstract;
|
|
use phpOMS\Message\ResponseAbstract;
|
|
use phpOMS\Views\NullView;
|
|
|
|
/**
|
|
* Monitoring controller class.
|
|
*
|
|
* @package Modules\Monitoring
|
|
* @license OMS License 2.0
|
|
* @link https://jingga.app
|
|
* @since 1.0.0
|
|
* @codeCoverageIgnore
|
|
*/
|
|
final class CliController extends Controller
|
|
{
|
|
/**
|
|
* Method which creates a workflow instance
|
|
*
|
|
* @param RequestAbstract $request Request
|
|
* @param ResponseAbstract $response Response
|
|
* @param mixed $data Generic data
|
|
*
|
|
* @return RenderableInterface Response can be rendered
|
|
*
|
|
* @since 1.0.0
|
|
* @codeCoverageIgnore
|
|
*/
|
|
public function cliLogReport(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : RenderableInterface
|
|
{
|
|
$handler = $this->app->moduleManager->get('Admin', 'Api')->setUpServerMailHandler();
|
|
|
|
/** @var \Model\Setting $emailSettings */
|
|
$emailSettings = $this->app->appSettings->get(
|
|
names: SettingsEnum::MAIL_SERVER_ADDR,
|
|
module: 'OnlineResourceWatcher'
|
|
);
|
|
|
|
$today = new \DateTime('now');
|
|
|
|
$hasErrorReport = \is_file($file = __DIR__ . '/../../../Logs/' . $today->format('Y-m-d') . '.log');
|
|
|
|
// @todo: define report email template
|
|
$mail = new Email();
|
|
$mail->setFrom($emailSettings->content);
|
|
$mail->addTo($emailSettings->content);
|
|
$mail->subject = 'Error report';
|
|
|
|
if ($hasErrorReport) {
|
|
$mail->body = 'Your daily Error report.';
|
|
$mail->bodyAlt = 'Your daily Error report.';
|
|
|
|
$mail->addAttachment($file);
|
|
} else {
|
|
$mail->body = 'No errors today.';
|
|
$mail->bodyAlt = 'No errors today.';
|
|
}
|
|
|
|
$handler->send($mail);
|
|
|
|
return new NullView();
|
|
}
|
|
}
|