vendor/fourtwosix/status-bundle/src/Controller/AlarmController.php line 41

Open in your IDE?
  1. <?php
  2. namespace Fourtwosix\StatusBundle\Controller;
  3. use Fourtwosix\StatusBundle\Classes\StatusModel;
  4. use Fourtwosix\StatusBundle\Exceptions\DuplicateHandlerException;
  5. use Fourtwosix\StatusBundle\Services\SchedulingLoader;
  6. use Fourtwosix\StatusBundle\Services\StatusLoader;
  7. use Fourtwosix\StatusBundle\Services\OpenMetricEncoder;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
  13. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  14. use Symfony\Component\Serializer\Serializer;
  15. use Symfony\Contracts\Translation\TranslatorInterface;
  16. class AlarmController extends AbstractController
  17. {
  18.     protected StatusLoader $statusLoader;
  19.     protected SchedulingLoader $schedulingLoader;
  20.     protected TranslatorInterface $translator;
  21.     public function __construct(
  22.         StatusLoader $statusLoader,
  23.         SchedulingLoader $schedulingLoader,
  24.         TranslatorInterface $translator
  25.     ) {
  26.         $this->statusLoader $statusLoader;
  27.         $this->schedulingLoader $schedulingLoader;
  28.         $this->translator $translator;
  29.     }
  30.     /**
  31.      * Returns a json with the checks results on the system
  32.      * @return JsonResponse
  33.      * @throws DuplicateHandlerException
  34.      */
  35.     #[Route('/api/_alarm/errors'name'fourtwosix_status_bundle.alarms.errors')]
  36.     public function index(): Response
  37.     {
  38.         $statusCode 200;
  39.         $errors = [];
  40.         $statusErrors $this->statusLoader->loadErrors();
  41.         $schedulingErrors $this->schedulingLoader->loadErrors();
  42.         if ($statusErrors->count() > 0) {
  43.             $statusCode 500;
  44.             $errors["status"] = $statusErrors;
  45.         }
  46.         if ($schedulingErrors->count() > 0) {
  47.             $statusCode 500;
  48.             $errors["scheduling"] = $schedulingErrors;
  49.         }
  50.         return $this->json([
  51.             "errors" => $errors
  52.         ], $statusCode);
  53.     }
  54. }