diff --git a/config/packages/monolog.yaml b/config/packages/monolog.yaml index a4d45ad..717f13b 100644 --- a/config/packages/monolog.yaml +++ b/config/packages/monolog.yaml @@ -7,7 +7,7 @@ when@dev: handlers: main: type: stream - level: debug + level: info path: php://stderr formatter: App\Formatter\CustomLineFormatter channels: ["!event"] diff --git a/src/Controller/OgAgent/CreateImageAction.php b/src/Controller/OgAgent/CreateImageAction.php index 206f1a7..e003bc3 100644 --- a/src/Controller/OgAgent/CreateImageAction.php +++ b/src/Controller/OgAgent/CreateImageAction.php @@ -16,6 +16,7 @@ use App\Model\TraceStatus; use App\Service\Trace\CreateService; use Doctrine\ORM\EntityManagerInterface; use Exception; +use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -30,9 +31,10 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; class CreateImageAction extends AbstractController { public function __construct( - protected readonly EntityManagerInterface $entityManager, - protected readonly HttpClientInterface $httpClient, - protected readonly CreateService $createService, + protected readonly EntityManagerInterface $entityManager, + protected readonly HttpClientInterface $httpClient, + protected readonly CreateService $createService, + protected readonly LoggerInterface $logger, ) { } @@ -77,6 +79,7 @@ class CreateImageAction extends AbstractController } try { + $this->logger->info('Creating image', ['image' => $image->getId()]); $response = $this->httpClient->request('POST', 'https://'.$image->getClient()->getIp().':8000/CloningEngine/CrearImagen', [ 'verify_peer' => false, 'verify_host' => false, @@ -86,7 +89,9 @@ class CreateImageAction extends AbstractController 'json' => $data, ]); + } catch (TransportExceptionInterface $e) { + $this->logger->error('Error creating image', ['image' => $image->getId(), 'error' => $e->getMessage()]); return new JsonResponse( data: ['error' => $e->getMessage()], status: Response::HTTP_INTERNAL_SERVER_ERROR diff --git a/src/Controller/OgAgent/DeployImageAction.php b/src/Controller/OgAgent/DeployImageAction.php index 1d20b25..617505c 100644 --- a/src/Controller/OgAgent/DeployImageAction.php +++ b/src/Controller/OgAgent/DeployImageAction.php @@ -15,6 +15,7 @@ use App\Model\DeployMethodTypes; use App\Model\TraceStatus; use App\Service\Trace\CreateService; use Doctrine\ORM\EntityManagerInterface; +use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -29,9 +30,10 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; class DeployImageAction extends AbstractController { public function __construct( - protected readonly EntityManagerInterface $entityManager, - protected readonly HttpClientInterface $httpClient, - protected readonly CreateService $createService, + protected readonly EntityManagerInterface $entityManager, + protected readonly HttpClientInterface $httpClient, + protected readonly CreateService $createService, + protected readonly LoggerInterface $logger, ) { } @@ -91,8 +93,10 @@ class DeployImageAction extends AbstractController ], 'json' => $data, ]); + $this->logger->info('Deploying image', ['image' => $image->getId()]); } catch (TransportExceptionInterface $e) { + $this->logger->error('Error deploying image', ['image' => $image->getId(), 'error' => $e->getMessage()]); return new JsonResponse( data: ['error' => $e->getMessage()], status: Response::HTTP_INTERNAL_SERVER_ERROR diff --git a/src/Controller/OgAgent/PartitionAssistantAction.php b/src/Controller/OgAgent/PartitionAssistantAction.php index b3cd3a3..0044048 100644 --- a/src/Controller/OgAgent/PartitionAssistantAction.php +++ b/src/Controller/OgAgent/PartitionAssistantAction.php @@ -15,6 +15,7 @@ use App\Model\ImageStatus; use App\Model\TraceStatus; use App\Service\Trace\CreateService; use Doctrine\ORM\EntityManagerInterface; +use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -29,9 +30,10 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; class PartitionAssistantAction extends AbstractController { public function __construct( - protected readonly EntityManagerInterface $entityManager, - protected readonly HttpClientInterface $httpClient, - protected readonly CreateService $createService, + protected readonly EntityManagerInterface $entityManager, + protected readonly HttpClientInterface $httpClient, + protected readonly CreateService $createService, + protected readonly LoggerInterface $logger, ) { } @@ -98,7 +100,9 @@ class PartitionAssistantAction extends AbstractController ], 'json' => $result, ]); + $this->logger->info('Partitioning disk', ['client' => $client->getId(), 'disk' => $diskNumber]); } catch (TransportExceptionInterface $e) { + $this->logger->error('Error partitioning disk', ['client' => $client->getId(), 'disk' => $diskNumber, 'error' => $e->getMessage()]); return new JsonResponse( data: ['error' => "Error en disco $diskNumber: " . $e->getMessage()], status: Response::HTTP_INTERNAL_SERVER_ERROR diff --git a/src/Controller/OgAgent/PowerOffAction.php b/src/Controller/OgAgent/PowerOffAction.php index 2ba5741..766dd91 100644 --- a/src/Controller/OgAgent/PowerOffAction.php +++ b/src/Controller/OgAgent/PowerOffAction.php @@ -14,6 +14,7 @@ use App\Model\ImageStatus; use App\Model\TraceStatus; use App\Service\Trace\CreateService; use Doctrine\ORM\EntityManagerInterface; +use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -31,6 +32,7 @@ class PowerOffAction extends AbstractController protected readonly EntityManagerInterface $entityManager, protected readonly HttpClientInterface $httpClient, protected readonly CreateService $createService, + protected readonly LoggerInterface $logger, ) { } @@ -55,8 +57,10 @@ class PowerOffAction extends AbstractController ], 'json' => $data, ]); + $this->logger->info('Powering off client', ['client' => $client->getId()]); } catch (TransportExceptionInterface $e) { + $this->logger->error('Error powering off client', ['client' => $client->getId(), 'error' => $e->getMessage()]); return new JsonResponse( data: ['error' => $e->getMessage()], status: Response::HTTP_INTERNAL_SERVER_ERROR diff --git a/src/Controller/OgAgent/RebootAction.php b/src/Controller/OgAgent/RebootAction.php index dcbc139..323f782 100644 --- a/src/Controller/OgAgent/RebootAction.php +++ b/src/Controller/OgAgent/RebootAction.php @@ -14,6 +14,7 @@ use App\Model\ImageStatus; use App\Model\TraceStatus; use App\Service\Trace\CreateService; use Doctrine\ORM\EntityManagerInterface; +use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -28,9 +29,10 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; class RebootAction extends AbstractController { public function __construct( - protected readonly EntityManagerInterface $entityManager, - protected readonly HttpClientInterface $httpClient, - protected readonly CreateService $createService, + protected readonly EntityManagerInterface $entityManager, + protected readonly HttpClientInterface $httpClient, + protected readonly CreateService $createService, + protected readonly LoggerInterface $logger, ) { } @@ -55,8 +57,10 @@ class RebootAction extends AbstractController ], 'json' => $data, ]); + $this->logger->info('Rebooting client', ['client' => $client->getId()]); } catch (TransportExceptionInterface $e) { + $this->logger->error('Error rebooting client', ['client' => $client->getId(), 'error' => $e->getMessage()]); return new JsonResponse( data: ['error' => $e->getMessage()], status: Response::HTTP_INTERNAL_SERVER_ERROR diff --git a/src/Controller/OgAgent/StatusAction.php b/src/Controller/OgAgent/StatusAction.php index e5f94e4..6ecd8d0 100644 --- a/src/Controller/OgAgent/StatusAction.php +++ b/src/Controller/OgAgent/StatusAction.php @@ -79,6 +79,7 @@ class StatusAction extends AbstractController $client->setStatus($statusCode === Response::HTTP_OK ? ClientStatus::OG_LIVE : ClientStatus::OFF); } catch (TransportExceptionInterface $e) { + $this->logger->error('Error checking client status', ['client' => $client->getId(), 'error' => $e->getMessage()]); $client->setStatus(ClientStatus::OFF); $this->entityManager->persist($client); $this->entityManager->flush(); @@ -116,7 +117,7 @@ class StatusAction extends AbstractController } catch (TransportExceptionInterface $e) { $client->setStatus(ClientStatus::OFF); - + $this->logger->error('Error checking client status', ['client' => $client->getId(), 'error' => $e->getMessage()]); return Response::HTTP_INTERNAL_SERVER_ERROR; } diff --git a/src/Controller/OgBoot/AbstractOgBootController.php b/src/Controller/OgBoot/AbstractOgBootController.php index f6f132d..2ea3d77 100644 --- a/src/Controller/OgBoot/AbstractOgBootController.php +++ b/src/Controller/OgBoot/AbstractOgBootController.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Controller\OgBoot; use App\Controller\OgBoot\PxeBootFile\PostAction; +use App\Service\Trace\CreateService; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\Attribute\Autowire; @@ -30,6 +31,7 @@ abstract class AbstractOgBootController extends AbstractController protected string $ogLogIp, protected readonly EntityManagerInterface $entityManager, protected readonly HttpClientInterface $httpClient, + protected readonly CreateService $createService, ) { } diff --git a/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php b/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php index b0aa21c..f437848 100644 --- a/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php +++ b/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php @@ -6,6 +6,7 @@ use App\Controller\OgBoot\AbstractOgBootController; use App\Entity\OgLive; use App\Model\OgLiveStatus; use Doctrine\ORM\EntityManagerInterface; +use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -27,7 +28,8 @@ class InstallOgLiveResponseAction extends AbstractController const string OG_BOOT_DIRECTORY = '/opt/opengnsys/ogboot/tftpboot//'; public function __construct( - protected readonly EntityManagerInterface $entityManager + protected readonly EntityManagerInterface $entityManager, + protected readonly LoggerInterface $logger, ) { } @@ -62,6 +64,7 @@ class InstallOgLiveResponseAction extends AbstractController } $this->updateOgLive($ogLive, $message, $status); + $this->logger->info(sprintf('OgLive %s updated successfully', $ogLive->getChecksum())); return new JsonResponse(data: sprintf('OgLive %s updated successfully', $ogLive->getChecksum()), status: Response::HTTP_OK); }