new api 2.0
This commit is contained in:
parent
7145503284
commit
3922a052c9
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Services\CreateEventService;
|
||||
|
||||
final class CreateEventAction
|
||||
{
|
||||
public function __construct(
|
||||
private CreateEventService $createEventService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Event $event): Event
|
||||
{
|
||||
return $this->createEventService->__invoke($event);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Services\DeleteEventService;
|
||||
|
||||
final class DeleteEventAction
|
||||
{
|
||||
public function __construct(
|
||||
private DeleteEventService $deleteEventService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Event $event): void
|
||||
{
|
||||
$this->deleteEventService->__invoke($event);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Services\GetEventService;
|
||||
|
||||
final class GetEventAction
|
||||
{
|
||||
public function __construct(
|
||||
private GetEventService $getEventService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(int $idEvent): Event
|
||||
{
|
||||
return $this->getEventService->__invoke($idEvent);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
||||
use PandoraFMS\Modules\Events\Services\CountEventService;
|
||||
use PandoraFMS\Modules\Events\Services\ListEventService;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Entities\PaginationData;
|
||||
|
||||
final class ListEventAction
|
||||
{
|
||||
public function __construct(
|
||||
private ListEventService $listEventService,
|
||||
private CountEventService $countEventService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(EventFilter $eventFilter): array
|
||||
{
|
||||
return (new PaginationData(
|
||||
$eventFilter->getPage(),
|
||||
$eventFilter->getSizePage(),
|
||||
$this->countEventService->__invoke($eventFilter),
|
||||
$this->listEventService->__invoke($eventFilter)
|
||||
))->toArray();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Services\UpdateEventService;
|
||||
|
||||
final class UpdateEventAction
|
||||
{
|
||||
public function __construct(
|
||||
private UpdateEventService $updateEventService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Event $event, Event $oldEvent): Event
|
||||
{
|
||||
return $this->updateEventService->__invoke($event, $oldEvent);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Events\Actions\CreateEventAction;
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
use PandoraFMS\Modules\Shared\Services\ValidateAclSystem;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
final class CreateEventController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private CreateEventAction $createEventAction,
|
||||
private ValidateAclSystem $acl,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* tags={"Events"},
|
||||
* path="/event",
|
||||
* summary="Creates a new events",
|
||||
* @OA\RequestBody(ref="#/components/requestBodies/requestBodyEvent"),
|
||||
* @OA\Response(response=200, ref="#/components/responses/ResponseEvent"),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
// @var Event $event.
|
||||
$event = $this->fromRequest($request, Event::class);
|
||||
|
||||
//$this->acl->validate(0, 'UM', ' tried to manage event');
|
||||
|
||||
$result = $this->createEventAction->__invoke($event);
|
||||
|
||||
return $this->getResponse($response, $result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Events\Actions\DeleteEventAction;
|
||||
use PandoraFMS\Modules\Events\Actions\GetEventAction;
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
use PandoraFMS\Modules\Shared\Services\ValidateAclSystem;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
final class DeleteEventController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private DeleteEventAction $deleteEventAction,
|
||||
private ValidateAclSystem $acl,
|
||||
private GetEventAction $getEventAction
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Delete(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* tags={"Events"},
|
||||
* path="/event/{idEvent}",
|
||||
* summary="Deletes an event object.",
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterIdEvent"),
|
||||
* @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
$idEvent = $this->getParam($request, 'idEvent');
|
||||
$event = $this->getEventAction->__invoke($idEvent);
|
||||
|
||||
//$this->acl->validate(0, 'UM', ' tried to manage event');
|
||||
|
||||
$result = $this->deleteEventAction->__invoke($event);
|
||||
return $this->getResponse($response, $result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Events\Actions\GetEventAction;
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
use PandoraFMS\Modules\Shared\Services\ValidateAclSystem;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
final class GetEventController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private GetEventAction $getEventAction,
|
||||
private ValidateAclSystem $acl
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* path="/event/{idEvent}",
|
||||
* tags={"Events"},
|
||||
* summary="Show event",
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterIdEvent"),
|
||||
* @OA\Response(response=200, ref="#/components/responses/ResponseEvent"),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
$idEvent = $this->getParam($request, 'idEvent');
|
||||
|
||||
//$this->acl->validate(0, 'UM', ' tried to manage event');
|
||||
|
||||
$result = $this->getEventAction->__invoke($idEvent);
|
||||
return $this->getResponse($response, $result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Events\Actions\ListEventAction;
|
||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
use PandoraFMS\Modules\Shared\Services\ValidateAclSystem;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
final class ListEventController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private ListEventAction $listEventAction,
|
||||
private ValidateAclSystem $acl,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* tags={"Events"},
|
||||
* path="/event/list",
|
||||
* summary="List events",
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterPage"),
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterSizePage"),
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterSortField"),
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterSortDirection"),
|
||||
* @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventFilter"),
|
||||
* @OA\Response(
|
||||
* response="200",
|
||||
* description="List Events Object",
|
||||
* content={
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(
|
||||
* @OA\Property(
|
||||
* property="paginationData",
|
||||
* type="object",
|
||||
* ref="#/components/schemas/paginationData",
|
||||
* description="Page object",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="data",
|
||||
* type="array",
|
||||
* @OA\Items(
|
||||
* ref="#/components/schemas/Event",
|
||||
* description="Array of event objects"
|
||||
* )
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
* }
|
||||
* ),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
// @var EventFilter $eventFilter.
|
||||
$eventFilter = $this->fromRequest($request, EventFilter::class);
|
||||
|
||||
//$this->acl->validate(0, 'UM', ' tried to manage event');
|
||||
|
||||
$result = $this->listEventAction->__invoke($eventFilter);
|
||||
return $this->getResponse($response, $result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Events\Actions\GetEventAction;
|
||||
use PandoraFMS\Modules\Events\Actions\UpdateEventAction;
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
use PandoraFMS\Modules\Shared\Services\ValidateAclSystem;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
/**
|
||||
* @OA\Put(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* path="/event/{idEvent}",
|
||||
* tags={"Events"},
|
||||
* summary="Updates an event",
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterIdEvent"),
|
||||
* @OA\RequestBody(ref="#/components/requestBodies/requestBodyEvent"),
|
||||
* @OA\Response(response=200, ref="#/components/responses/ResponseEvent"),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*/
|
||||
final class UpdateEventController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private UpdateEventAction $updateEventAction,
|
||||
private ValidateAclSystem $acl,
|
||||
private GetEventAction $getEventAction
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
$idEvent = $this->getParam($request, 'idEvent');
|
||||
$event = $this->getEventAction->__invoke($idEvent);
|
||||
|
||||
$oldEvent = clone $event;
|
||||
$params = $this->extractParams($request);
|
||||
$event->fromArray($params);
|
||||
|
||||
//$this->acl->validate(0, 'UM', ' tried to manage event');
|
||||
|
||||
$result = $this->updateEventAction->__invoke($event, $oldEvent);
|
||||
return $this->getResponse($response, $result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,637 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Entities;
|
||||
|
||||
use PandoraFMS\Modules\Events\Enums\EventSeverityEnum;
|
||||
use PandoraFMS\Modules\Events\Enums\EventStatusEnum;
|
||||
use PandoraFMS\Modules\Events\Enums\EventTypeEnum;
|
||||
use PandoraFMS\Modules\Events\Validators\EventValidator;
|
||||
use PandoraFMS\Modules\Shared\Entities\Entity;
|
||||
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="Event",
|
||||
* type="object",
|
||||
* @OA\Property(
|
||||
* property="idEvent",
|
||||
* type="integer",
|
||||
* nullable=false,
|
||||
* description="Id event",
|
||||
* readOnly=true
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="idAgent",
|
||||
* type="integer",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Id agent",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="idUser",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Id user",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="idGroup",
|
||||
* type="integer",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Id group"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="status",
|
||||
* type="integer",
|
||||
* nullable=false,
|
||||
* enum={
|
||||
* "new",
|
||||
* "validated",
|
||||
* "inprocess",
|
||||
* },
|
||||
* default="new",
|
||||
* description="Event status, the available status are: new, validated, inprocess"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="timestamp",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Event registration date",
|
||||
* example="2023-21-02 08:34:16",
|
||||
* readOnly=true
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="event",
|
||||
* type="string",
|
||||
* nullable=false,
|
||||
* default="Event created for api",
|
||||
* description="Description event",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="utimestamp",
|
||||
* type="integer",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Event registration date",
|
||||
* example="1704898868",
|
||||
* readOnly=true
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="eventType",
|
||||
* type="string",
|
||||
* nullable=false,
|
||||
* enum={
|
||||
* "going_unknown",
|
||||
* "unknown",
|
||||
* "alert_fired",
|
||||
* "alert_recovered",
|
||||
* "alert_ceased",
|
||||
* "alert_manual_validation",
|
||||
* "recon_host_detected",
|
||||
* "system",
|
||||
* "error",
|
||||
* "new_agent",
|
||||
* "going_up_critical",
|
||||
* "going_down_critical",
|
||||
* "going_up_warning",
|
||||
* "going_down_warning",
|
||||
* "going_up_normal",
|
||||
* "going_down_normal",
|
||||
* "configuration_change",
|
||||
* "ncm"
|
||||
* },
|
||||
* default="unknown",
|
||||
* description="Event status, the available status are: going_unknown, unknown, alert_fired, alert_recovered, alert_ceased, alert_manual_validation, recon_host_detected, system, error, new_agent, going_up_critical, going_down_critical, going_up_warning, going_down_warning, going_up_normal, going_down_normal, configuration_change, ncm"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="idAgentModule",
|
||||
* type="integer",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Id agent module",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="idAlertAm",
|
||||
* type="integer",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Id alert action",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="criticity",
|
||||
* type="integer",
|
||||
* nullable=false,
|
||||
* enum={
|
||||
* "maintenance",
|
||||
* "informational",
|
||||
* "normal",
|
||||
* "warning",
|
||||
* "critical",
|
||||
* "minor",
|
||||
* "major"
|
||||
* },
|
||||
* default="maintenance",
|
||||
* description="Event critcity, the available criticity are: maintenance, informational, normal, warning, critical, minor, major"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="tags",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Tags",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="source",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Source",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="idExtra",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Extra id",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="criticalInstructions",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Critical instructions",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="warningInstructions",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Warning instructions",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="unknownInstructions",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Unknows instructions",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="ownerUser",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Id user",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="ackUtimestamp",
|
||||
* type="integer",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Event ack utimestamp",
|
||||
* example="1704898868",
|
||||
* readOnly=true
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="customData",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Custom data",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="data",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Data",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="moduleStatus",
|
||||
* type="integer",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Module status",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="eventCustomId",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Events Custom Id",
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* @OA\Response(
|
||||
* response="ResponseEvent",
|
||||
* description="Event object",
|
||||
* content={
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(
|
||||
* type="object",
|
||||
* ref="#/components/schemas/Event",
|
||||
* description="Event object"
|
||||
* ),
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* parameter="parameterIdEvent",
|
||||
* name="idEvent",
|
||||
* in="path",
|
||||
* description="Event id",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="integer",
|
||||
* default=1
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* request="requestBodyEvent",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(ref="#/components/schemas/Event")
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
final class Event extends Entity
|
||||
{
|
||||
private ?int $idEvent = null;
|
||||
private ?int $idAgent = null;
|
||||
private ?string $idUser = null;
|
||||
private ?int $idGroup = null;
|
||||
private ?EventStatusEnum $status = null;
|
||||
private ?string $timestamp = null;
|
||||
private ?string $event = null;
|
||||
private ?int $utimestamp = null;
|
||||
private ?EventTypeEnum $eventType = null;
|
||||
private ?int $idAgentModule = null;
|
||||
private ?int $idAlertAm = null;
|
||||
private ?EventSeverityEnum $criticity = null;
|
||||
private ?string $tags = null;
|
||||
private ?string $source = null;
|
||||
private ?string $idExtra = null;
|
||||
private ?string $criticalInstructions = null;
|
||||
private ?string $warningInstructions = null;
|
||||
private ?string $unknownInstructions = null;
|
||||
private ?string $ownerUser = null;
|
||||
private ?int $ackUtimestamp = null;
|
||||
private ?string $customData = null;
|
||||
private ?string $data = null;
|
||||
private ?int $moduleStatus = null;
|
||||
private ?string $eventCustomId = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function fieldsReadOnly(): array
|
||||
{
|
||||
return ['idEvent' => 1];
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'idEvent' => $this->getIdEvent(),
|
||||
'idAgent' => $this->getIdAgent(),
|
||||
'idUser' => $this->getIdUser(),
|
||||
'idGroup' => $this->getIdGroup(),
|
||||
'status' => $this->getStatus()?->name,
|
||||
'timestamp' => $this->getTimestamp(),
|
||||
'event' => $this->getEvent(),
|
||||
'utimestamp' => $this->getUtimestamp(),
|
||||
'eventType' => $this->getEventType()?->name,
|
||||
'idAgentModule' => $this->getIdAgentModule(),
|
||||
'idAlertAm' => $this->getIdAlertAm(),
|
||||
'criticity' => $this->getCriticity()?->name,
|
||||
'tags' => $this->getTags(),
|
||||
'source' => $this->getSource(),
|
||||
'idExtra' => $this->getIdExtra(),
|
||||
'criticalInstructions' => $this->getCriticalInstructions(),
|
||||
'warningInstructions' => $this->getWarningInstructions(),
|
||||
'unknownInstructions' => $this->getUnknownInstructions(),
|
||||
'ownerUser' => $this->getOwnerUser(),
|
||||
'ackUtimestamp' => $this->getAckUtimestamp(),
|
||||
'customData' => $this->getCustomData(),
|
||||
'data' => $this->getData(),
|
||||
'moduleStatus' => $this->getModuleStatus(),
|
||||
'eventCustomId' => $this->getEventCustomId(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getValidations(): array
|
||||
{
|
||||
return [
|
||||
'idEvent' => [
|
||||
EventValidator::INTEGER,
|
||||
EventValidator::GREATERTHAN,
|
||||
],
|
||||
'idAgent' => [
|
||||
EventValidator::INTEGER,
|
||||
EventValidator::GREATERTHAN,
|
||||
],
|
||||
'idUser' => EventValidator::STRING,
|
||||
'idGroup' => [
|
||||
EventValidator::INTEGER,
|
||||
EventValidator::GREATERTHAN,
|
||||
],
|
||||
'status' => EventValidator::VALIDSTATUS,
|
||||
'timestamp' => EventValidator::DATETIME,
|
||||
'event' => EventValidator::STRING,
|
||||
'utimestamp' => [
|
||||
EventValidator::INTEGER,
|
||||
EventValidator::GREATERTHAN,
|
||||
],
|
||||
'eventType' => EventValidator::VALIDTYPE,
|
||||
'idAgentModule' => [
|
||||
EventValidator::INTEGER,
|
||||
EventValidator::GREATERTHAN,
|
||||
],
|
||||
'idAlertAm' => [
|
||||
EventValidator::INTEGER,
|
||||
EventValidator::GREATERTHAN,
|
||||
],
|
||||
'criticity' => EventValidator::VALIDSEVERITY,
|
||||
'tags' => EventValidator::STRING,
|
||||
'source' => EventValidator::STRING,
|
||||
'idExtra' => EventValidator::STRING,
|
||||
'criticalInstructions' => EventValidator::STRING,
|
||||
'warningInstructions' => EventValidator::STRING,
|
||||
'unknownInstructions' => EventValidator::STRING,
|
||||
'ownerUser' => EventValidator::STRING,
|
||||
'ackUtimestamp' => [
|
||||
EventValidator::INTEGER,
|
||||
EventValidator::GREATERTHAN,
|
||||
],
|
||||
'customData' => EventValidator::STRING,
|
||||
'data' => EventValidator::STRING,
|
||||
'moduleStatus' => EventValidator::INTEGER,
|
||||
'eventCustomId' => EventValidator::STRING,
|
||||
];
|
||||
}
|
||||
|
||||
public function validateFields(array $filters): array
|
||||
{
|
||||
return (new EventValidator())->validate($filters);
|
||||
}
|
||||
|
||||
public function getIdEvent(): ?int
|
||||
{
|
||||
return $this->idEvent;
|
||||
}
|
||||
public function setIdEvent(?int $idEvent): self
|
||||
{
|
||||
$this->idEvent = $idEvent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIdAgent(): ?int
|
||||
{
|
||||
return $this->idAgent;
|
||||
}
|
||||
public function setIdAgent(?int $idAgent): self
|
||||
{
|
||||
$this->idAgent = $idAgent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIdUser(): ?string
|
||||
{
|
||||
return $this->idUser;
|
||||
}
|
||||
public function setIdUser(?string $idUser): self
|
||||
{
|
||||
$this->idUser = $idUser;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIdGroup(): ?int
|
||||
{
|
||||
return $this->idGroup;
|
||||
}
|
||||
public function setIdGroup(?int $idGroup): self
|
||||
{
|
||||
$this->idGroup = $idGroup;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStatus(): ?EventStatusEnum
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
public function setStatus(null|string|EventStatusEnum $status): self
|
||||
{
|
||||
if (is_string($status) === true) {
|
||||
$this->status = EventStatusEnum::get(strtoupper($status));
|
||||
} else {
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTimestamp(): ?string
|
||||
{
|
||||
return $this->timestamp;
|
||||
}
|
||||
public function setTimestamp(?string $timestamp): self
|
||||
{
|
||||
$this->timestamp = $timestamp;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEvent(): ?string
|
||||
{
|
||||
return $this->event;
|
||||
}
|
||||
public function setEvent(?string $event): self
|
||||
{
|
||||
$this->event = $event;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUtimestamp(): ?int
|
||||
{
|
||||
return $this->utimestamp;
|
||||
}
|
||||
public function setUtimestamp(?int $utimestamp): self
|
||||
{
|
||||
$this->utimestamp = $utimestamp;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEventType(): ?EventTypeEnum
|
||||
{
|
||||
return $this->eventType;
|
||||
}
|
||||
public function setEventType(null|string|EventTypeEnum $eventType): self
|
||||
{
|
||||
if (is_string($eventType) === true) {
|
||||
$this->eventType = EventTypeEnum::get(strtoupper($eventType));
|
||||
} else {
|
||||
$this->eventType = $eventType;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIdAgentModule(): ?int
|
||||
{
|
||||
return $this->idAgentModule;
|
||||
}
|
||||
public function setIdAgentModule(?int $idAgentModule): self
|
||||
{
|
||||
$this->idAgentModule = $idAgentModule;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIdAlertAm(): ?int
|
||||
{
|
||||
return $this->idAlertAm;
|
||||
}
|
||||
public function setIdAlertAm(?int $idAlertAm): self
|
||||
{
|
||||
$this->idAlertAm = $idAlertAm;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCriticity(): ?EventSeverityEnum
|
||||
{
|
||||
return $this->criticity;
|
||||
}
|
||||
public function setCriticity(null|string|EventSeverityEnum $criticity): self
|
||||
{
|
||||
if (is_string($criticity) === true) {
|
||||
$this->criticity = EventSeverityEnum::get(strtoupper($criticity));
|
||||
} else {
|
||||
$this->criticity = $criticity;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTags(): ?string
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
public function setTags(?string $tags): self
|
||||
{
|
||||
$this->tags = $tags;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSource(): ?string
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
public function setSource(?string $source): self
|
||||
{
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIdExtra(): ?string
|
||||
{
|
||||
return $this->idExtra;
|
||||
}
|
||||
public function setIdExtra(?string $idExtra): self
|
||||
{
|
||||
$this->idExtra = $idExtra;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCriticalInstructions(): ?string
|
||||
{
|
||||
return $this->criticalInstructions;
|
||||
}
|
||||
public function setCriticalInstructions(?string $criticalInstructions): self
|
||||
{
|
||||
$this->criticalInstructions = $criticalInstructions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWarningInstructions(): ?string
|
||||
{
|
||||
return $this->warningInstructions;
|
||||
}
|
||||
public function setWarningInstructions(?string $warningInstructions): self
|
||||
{
|
||||
$this->warningInstructions = $warningInstructions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUnknownInstructions(): ?string
|
||||
{
|
||||
return $this->unknownInstructions;
|
||||
}
|
||||
public function setUnknownInstructions(?string $unknownInstructions): self
|
||||
{
|
||||
$this->unknownInstructions = $unknownInstructions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOwnerUser(): ?string
|
||||
{
|
||||
return $this->ownerUser;
|
||||
}
|
||||
public function setOwnerUser(?string $ownerUser): self
|
||||
{
|
||||
$this->ownerUser = $ownerUser;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAckUtimestamp(): ?int
|
||||
{
|
||||
return $this->ackUtimestamp;
|
||||
}
|
||||
public function setAckUtimestamp(?int $ackUtimestamp): self
|
||||
{
|
||||
$this->ackUtimestamp = $ackUtimestamp;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCustomData(): ?string
|
||||
{
|
||||
return $this->customData;
|
||||
}
|
||||
public function setCustomData(?string $customData): self
|
||||
{
|
||||
$this->customData = $customData;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getData(): ?string
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
public function setData(?string $data): self
|
||||
{
|
||||
$this->data = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getModuleStatus(): ?int
|
||||
{
|
||||
return $this->moduleStatus;
|
||||
}
|
||||
public function setModuleStatus(?int $moduleStatus): self
|
||||
{
|
||||
$this->moduleStatus = $moduleStatus;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEventCustomId(): ?string
|
||||
{
|
||||
return $this->eventCustomId;
|
||||
}
|
||||
public function setEventCustomId(?string $eventCustomId): self
|
||||
{
|
||||
$this->eventCustomId = $eventCustomId;
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Entities;
|
||||
|
||||
use PandoraFMS\Modules\Events\Enums\EventSeverityEnum;
|
||||
use PandoraFMS\Modules\Events\Enums\EventStatusEnum;
|
||||
use PandoraFMS\Modules\Events\Enums\EventTypeEnum;
|
||||
use PandoraFMS\Modules\Shared\Builders\Builder;
|
||||
use PandoraFMS\Modules\Shared\Core\DataMapperAbstract;
|
||||
use PandoraFMS\Modules\Shared\Core\MappeableInterface;
|
||||
use PandoraFMS\Modules\Shared\Repositories\Repository;
|
||||
|
||||
final class EventDataMapper extends DataMapperAbstract
|
||||
{
|
||||
public const TABLE_NAME = 'tevento';
|
||||
public const ID_EVENT = 'id_evento';
|
||||
public const ID_AGENT = 'id_agente';
|
||||
public const ID_USER = 'id_usuario';
|
||||
public const ID_GROUP = 'id_grupo';
|
||||
public const STATUS = 'estado';
|
||||
public const TIMESTAMP = 'timestamp';
|
||||
public const EVENT = 'evento';
|
||||
public const UTIMESTAMP = 'utimestamp';
|
||||
public const EVENT_TYPE = 'event_type';
|
||||
public const ID_AGENTMODULE = 'id_agentmodule';
|
||||
public const ID_ALERT_AM = 'id_alert_am';
|
||||
public const CRITICITY = 'criticity';
|
||||
public const TAGS = 'tags';
|
||||
public const SOURCE = 'source';
|
||||
public const ID_EXTRA = 'id_extra';
|
||||
public const CRITICAL_INSTRUCTIONS = 'critical_instructions';
|
||||
public const WARNING_INSTRUCTIONS = 'warning_instructions';
|
||||
public const UNKNOWN_INSTRUCTIONS = 'unknown_instructions';
|
||||
public const OWNER_USER = 'owner_user';
|
||||
public const ACK_UTIMESTAMP = 'ack_utimestamp';
|
||||
public const CUSTOM_DATA = 'custom_data';
|
||||
public const DATA = 'data';
|
||||
public const MODULE_STATUS = 'module_status';
|
||||
public const EVENT_CUSTOM_ID = 'event_custom_id';
|
||||
|
||||
public function __construct(
|
||||
private Repository $repository,
|
||||
private Builder $builder,
|
||||
) {
|
||||
parent::__construct(
|
||||
self::TABLE_NAME,
|
||||
self::ID_EVENT,
|
||||
);
|
||||
}
|
||||
|
||||
public function getClassName(): string
|
||||
{
|
||||
return Event::class;
|
||||
}
|
||||
|
||||
public function fromDatabase(array $data): Event
|
||||
{
|
||||
return $this->builder->build(new Event(), [
|
||||
'idEvent' => $data[self::ID_EVENT],
|
||||
'idAgent' => $data[self::ID_AGENT],
|
||||
'idUser' => $data[self::ID_USER],
|
||||
'idGroup' => $data[self::ID_GROUP],
|
||||
'status' => EventStatusEnum::get($data[self::STATUS]),
|
||||
'timestamp' => $data[self::TIMESTAMP],
|
||||
'event' => $this->repository->safeOutput($data[self::EVENT]),
|
||||
'utimestamp' => $data[self::UTIMESTAMP],
|
||||
'eventType' => EventTypeEnum::get($data[self::EVENT_TYPE]),
|
||||
'idAgentModule' => $data[self::ID_AGENTMODULE],
|
||||
'idAlertAm' => $data[self::ID_ALERT_AM],
|
||||
'criticity' => EventSeverityEnum::get($data[self::CRITICITY]),
|
||||
'tags' => $data[self::TAGS],
|
||||
'source' => $data[self::SOURCE],
|
||||
'idExtra' => $data[self::ID_EXTRA],
|
||||
'criticalInstructions' => $this->repository->safeOutput($data[self::CRITICAL_INSTRUCTIONS]),
|
||||
'warningInstructions' => $this->repository->safeOutput($data[self::WARNING_INSTRUCTIONS]),
|
||||
'unknownInstructions' => $this->repository->safeOutput($data[self::UNKNOWN_INSTRUCTIONS]),
|
||||
'ownerUser' => $data[self::OWNER_USER],
|
||||
'ackUtimestamp' => $data[self::ACK_UTIMESTAMP],
|
||||
'customData' => $this->repository->safeOutput($data[self::CUSTOM_DATA]),
|
||||
'data' => $this->repository->safeOutput($data[self::DATA]),
|
||||
'moduleStatus' => $data[self::MODULE_STATUS],
|
||||
'eventCustomId' => $this->repository->safeOutput($data[self::EVENT_CUSTOM_ID]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function toDatabase(MappeableInterface $data): array
|
||||
{
|
||||
/** @var Event $data */
|
||||
return [
|
||||
self::ID_EVENT => $data->getIdEvent(),
|
||||
self::ID_AGENT => $data->getIdAgent(),
|
||||
self::ID_USER => $data->getIdUser(),
|
||||
self::ID_GROUP => $data->getIdGroup(),
|
||||
self::STATUS => $data->getStatus()?->value,
|
||||
self::TIMESTAMP => $data->getTimestamp(),
|
||||
self::EVENT => $this->repository->safeInput($data->getEvent()),
|
||||
self::UTIMESTAMP => $data->getUtimestamp(),
|
||||
self::EVENT_TYPE => $data->getEventType()?->value,
|
||||
self::ID_AGENTMODULE => $data->getIdAgentModule(),
|
||||
self::ID_ALERT_AM => $data->getIdAlertAm(),
|
||||
self::CRITICITY => $data->getCriticity()?->value,
|
||||
self::TAGS => $data->getTags(),
|
||||
self::SOURCE => $data->getSource(),
|
||||
self::ID_EXTRA => $data->getIdExtra(),
|
||||
self::CRITICAL_INSTRUCTIONS => $this->repository->safeInput($data->getCriticalInstructions()),
|
||||
self::WARNING_INSTRUCTIONS => $this->repository->safeInput($data->getWarningInstructions()),
|
||||
self::UNKNOWN_INSTRUCTIONS => $this->repository->safeInput($data->getUnknownInstructions()),
|
||||
self::OWNER_USER => $data->getOwnerUser(),
|
||||
self::ACK_UTIMESTAMP => $data->getAckUtimestamp(),
|
||||
self::CUSTOM_DATA => $this->repository->safeInput($data->getCustomData()),
|
||||
self::DATA => $this->repository->safeInput($data->getData()),
|
||||
self::MODULE_STATUS => $data->getModuleStatus(),
|
||||
self::EVENT_CUSTOM_ID => $this->repository->safeInput($data->getEventCustomId()),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Entities;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Core\FilterAbstract;
|
||||
use PandoraFMS\Modules\Shared\Validators\Validator;
|
||||
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="EventFilter",
|
||||
* type="object",
|
||||
* allOf={
|
||||
* @OA\Schema(ref="#/components/schemas/Event"),
|
||||
* @OA\Schema(
|
||||
* @OA\Property(
|
||||
* property="idEvent",
|
||||
* default=null,
|
||||
* readOnly=false
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="freeSearch",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Find word in name field."
|
||||
* )
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* request="requestBodyEventFilter",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(ref="#/components/schemas/EventFilter")
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
final class EventFilter extends FilterAbstract
|
||||
{
|
||||
private ?string $freeSearch = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setDefaultFieldOrder(EventDataMapper::UTIMESTAMP);
|
||||
$this->setDefaultDirectionOrder($this::ASC);
|
||||
$this->setEntityFilter(new Event());
|
||||
}
|
||||
|
||||
public function fieldsTranslate(): array
|
||||
{
|
||||
return [
|
||||
'idEvent' => EventDataMapper::ID_EVENT,
|
||||
'utimestamp' => EventDataMapper::UTIMESTAMP,
|
||||
];
|
||||
}
|
||||
|
||||
public function fieldsReadOnly(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'freeSearch' => $this->getFreeSearch(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getValidations(): array
|
||||
{
|
||||
$validations = [];
|
||||
if($this->getEntityFilter() !== null) {
|
||||
$validations = $this->getEntityFilter()->getValidations();
|
||||
}
|
||||
$validations['freeSearch'] = Validator::STRING;
|
||||
return $validations;
|
||||
}
|
||||
|
||||
public function validateFields(array $filters): array
|
||||
{
|
||||
return (new Validator())->validate($filters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of freeSearch.
|
||||
*
|
||||
* @return ?string
|
||||
*/
|
||||
public function getFreeSearch(): ?string
|
||||
{
|
||||
return $this->freeSearch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of freeSearch.
|
||||
*
|
||||
* @param ?string $freeSearch
|
||||
*
|
||||
*/
|
||||
public function setFreeSearch(?string $freeSearch): self
|
||||
{
|
||||
$this->freeSearch = $freeSearch;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of fieldsFreeSearch.
|
||||
*
|
||||
* @return ?array
|
||||
*/
|
||||
public function getFieldsFreeSearch(): ?array
|
||||
{
|
||||
return [EventDataMapper::UTIMESTAMP];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Enums;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Traits\EnumTrait;
|
||||
|
||||
enum EventSeverityEnum: int
|
||||
{
|
||||
use EnumTrait;
|
||||
|
||||
case MAINTENANCE = 0;
|
||||
case INFORMATIONAL = 1;
|
||||
case NORMAL = 2;
|
||||
case WARNING = 3;
|
||||
case CRITICAL = 4;
|
||||
case MINOR = 5;
|
||||
case MAJOR = 6;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Enums;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Traits\EnumTrait;
|
||||
|
||||
enum EventStatusEnum: int
|
||||
{
|
||||
use EnumTrait;
|
||||
|
||||
case NEW = 0;
|
||||
case VALIDATED = 1;
|
||||
case INPROCESS = 2;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Enums;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Traits\EnumTrait;
|
||||
|
||||
enum EventTypeEnum: string
|
||||
{
|
||||
use EnumTrait;
|
||||
|
||||
case GOING_UNKNOWN = 'going_unknown';
|
||||
case UNKNOWN = 'unknown';
|
||||
case ALERT_FIRED = 'alert_fired';
|
||||
case ALERT_RECOVERED = 'alert_recovered';
|
||||
case ALERT_CEASED = 'alert_ceased';
|
||||
case ALERT_MANUAL_VALIDATION = 'alert_manual_validation';
|
||||
case RECON_HOST_DETECTED = 'recon_host_detected';
|
||||
case SYSTEM = 'system';
|
||||
case ERROR = 'error';
|
||||
case NEW_AGENT = 'new_agent';
|
||||
case GOING_UP_WARNING = 'going_up_warning';
|
||||
case GOING_DOWN_WARNING = 'going_down_warning';
|
||||
case GOING_UP_CRITICAL = 'going_up_critical';
|
||||
case GOING_DOWN_CRITICAL = 'going_down_critical';
|
||||
case GOING_UP_NORMAL = 'going_up_normal';
|
||||
case GOING_DOWN_NORMAL = 'going_down_normal';
|
||||
case CONFIGURATION_CHANGE = 'configuration_change';
|
||||
case NCM = 'ncm';
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Repositories;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Entities\EventDataMapper;
|
||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
||||
use PandoraFMS\Modules\Shared\Repositories\Repository;
|
||||
|
||||
class EventRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Repository $repository,
|
||||
private EventDataMapper $eventDataMapper
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Event[],
|
||||
*/
|
||||
public function list(EventFilter $eventFilter): array
|
||||
{
|
||||
return $this->repository->__list(
|
||||
$eventFilter,
|
||||
$this->eventDataMapper
|
||||
);
|
||||
}
|
||||
|
||||
public function count(EventFilter $eventFilter): int
|
||||
{
|
||||
return $this->repository->__count(
|
||||
$eventFilter,
|
||||
$this->eventDataMapper
|
||||
);
|
||||
}
|
||||
|
||||
public function getOne(EventFilter $eventFilter): Event
|
||||
{
|
||||
return $this->repository->__getOne(
|
||||
$eventFilter,
|
||||
$this->eventDataMapper
|
||||
);
|
||||
}
|
||||
|
||||
public function create(Event $event): Event
|
||||
{
|
||||
$id = $this->repository->__create($event, $this->eventDataMapper);
|
||||
return $event->setIdEvent($id);
|
||||
}
|
||||
|
||||
public function update(Event $event): Event
|
||||
{
|
||||
return $this->repository->__update(
|
||||
$event,
|
||||
$this->eventDataMapper,
|
||||
$event->getIdEvent()
|
||||
);
|
||||
}
|
||||
|
||||
public function delete(int $id): void
|
||||
{
|
||||
$this->repository->__delete($id, $this->eventDataMapper);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Services;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
||||
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
||||
|
||||
final class CountEventService
|
||||
{
|
||||
public function __construct(
|
||||
private EventRepository $eventRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(EventFilter $eventFilter): int
|
||||
{
|
||||
return $this->eventRepository->count($eventFilter);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Services;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
||||
use PandoraFMS\Modules\Events\Validations\EventValidation;
|
||||
use PandoraFMS\Modules\Shared\Services\Audit;
|
||||
|
||||
final class CreateEventService
|
||||
{
|
||||
public function __construct(
|
||||
private Audit $audit,
|
||||
private EventRepository $eventRepository,
|
||||
private EventValidation $eventValidation
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Event $event): Event
|
||||
{
|
||||
$this->eventValidation->__invoke($event);
|
||||
|
||||
$event = $this->eventRepository->create($event);
|
||||
|
||||
$this->audit->write(
|
||||
AUDIT_LOG_USER_MANAGEMENT,
|
||||
'Create event '.$event->getIdEvent(),
|
||||
json_encode($event->toArray())
|
||||
);
|
||||
|
||||
return $event;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Services;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Services\Audit;
|
||||
|
||||
final class DeleteEventService
|
||||
{
|
||||
public function __construct(
|
||||
private Audit $audit,
|
||||
private EventRepository $eventRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Event $event): void
|
||||
{
|
||||
$idEvent = $event->getIdEvent();
|
||||
$this->eventRepository->delete($idEvent);
|
||||
|
||||
$this->audit->write(
|
||||
AUDIT_LOG_USER_MANAGEMENT,
|
||||
'Deleted event '.$idEvent
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Services;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
||||
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
||||
|
||||
final class GetEventService
|
||||
{
|
||||
public function __construct(
|
||||
private EventRepository $eventRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(int $idEvent): Event
|
||||
{
|
||||
$eventFilter = new EventFilter();
|
||||
/** @var Event $entityFilter */
|
||||
$entityFilter = $eventFilter->getEntityFilter();
|
||||
$entityFilter->setIdEvent($idEvent);
|
||||
|
||||
return $this->eventRepository->getOne($eventFilter);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Services;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
||||
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
||||
|
||||
final class ListEventService
|
||||
{
|
||||
public function __construct(
|
||||
private EventRepository $eventRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(EventFilter $eventFilter): array
|
||||
{
|
||||
return $this->eventRepository->list($eventFilter);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Services;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
||||
use PandoraFMS\Modules\Events\Validations\EventValidation;
|
||||
use PandoraFMS\Modules\Shared\Services\Audit;
|
||||
|
||||
final class UpdateEventService
|
||||
{
|
||||
public function __construct(
|
||||
private Audit $audit,
|
||||
private EventRepository $eventRepository,
|
||||
private EventValidation $eventValidation
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Event $event, Event $oldEvent): Event
|
||||
{
|
||||
$this->eventValidation->__invoke($event, $oldEvent);
|
||||
|
||||
$event = $this->eventRepository->update($event);
|
||||
|
||||
$this->audit->write(
|
||||
AUDIT_LOG_USER_MANAGEMENT,
|
||||
'Update event '.$event->getIdEvent(),
|
||||
json_encode($event->toArray())
|
||||
);
|
||||
|
||||
return $event;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Validations;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Services\ExistNameEventService;
|
||||
use PandoraFMS\Modules\Shared\Exceptions\BadRequestException;
|
||||
|
||||
final class EventValidation
|
||||
{
|
||||
public function __construct(
|
||||
private ExistNameEventService $existNameEventService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Event $event, ?Event $oldEvent = null): void
|
||||
{
|
||||
if (!$event->getName()) {
|
||||
throw new BadRequestException(__('Name is missing'));
|
||||
}
|
||||
|
||||
if($oldEvent === null || $oldEvent->getName() !== $event->getName()) {
|
||||
if($this->existNameEventService->__invoke($event->getName()) === true) {
|
||||
throw new BadRequestException(
|
||||
__('Name %s is already exists', $event->getName())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if($event->getIsAgentView() === null) {
|
||||
$event->setIsAgentView(false);
|
||||
}
|
||||
|
||||
if($event->getIsAgentEdit() === null) {
|
||||
$event->setIsAgentEdit(false);
|
||||
}
|
||||
|
||||
if($event->getIsAlertEdit() === null) {
|
||||
$event->setIsAlertEdit(false);
|
||||
}
|
||||
|
||||
if($event->getIsUserManagement() === null) {
|
||||
$event->setIsUserManagement(false);
|
||||
}
|
||||
|
||||
if($event->getIsDbManagement() === null) {
|
||||
$event->setIsDbManagement(false);
|
||||
}
|
||||
|
||||
if($event->getIsAlertManagement() === null) {
|
||||
$event->setIsAlertManagement(false);
|
||||
}
|
||||
|
||||
if($event->getIsPandoraManagement() === null) {
|
||||
$event->setIsPandoraManagement(false);
|
||||
}
|
||||
|
||||
if($event->getIsReportView() === null) {
|
||||
$event->setIsReportView(false);
|
||||
}
|
||||
|
||||
if($event->getIsReportEdit() === null) {
|
||||
$event->setIsReportEdit(false);
|
||||
}
|
||||
|
||||
if($event->getIsReportManagement() === null) {
|
||||
$event->setIsReportManagement(false);
|
||||
}
|
||||
|
||||
if($event->getIsEventView() === null) {
|
||||
$event->setIsEventView(false);
|
||||
}
|
||||
|
||||
if($event->getIsEventEdit() === null) {
|
||||
$event->setIsEventEdit(false);
|
||||
}
|
||||
|
||||
if($event->getIsEventManagement() === null) {
|
||||
$event->setIsEventManagement(false);
|
||||
}
|
||||
|
||||
if($event->getIsAgentDisable() === null) {
|
||||
$event->setIsAgentDisable(false);
|
||||
}
|
||||
|
||||
if($event->getIsMapView() === null) {
|
||||
$event->setIsMapView(false);
|
||||
}
|
||||
|
||||
if($event->getIsMapEdit() === null) {
|
||||
$event->setIsMapEdit(false);
|
||||
}
|
||||
|
||||
if($event->getIsMapManagement() === null) {
|
||||
$event->setIsMapManagement(false);
|
||||
}
|
||||
|
||||
if($event->getIsVconsoleView() === null) {
|
||||
$event->setIsVconsoleView(false);
|
||||
}
|
||||
|
||||
if($event->getIsVconsoleEdit() === null) {
|
||||
$event->setIsVconsoleEdit(false);
|
||||
}
|
||||
|
||||
if($event->getIsVconsoleManagement() === null) {
|
||||
$event->setIsVconsoleManagement(false);
|
||||
}
|
||||
|
||||
if($event->getIsNetworkConfigView() === null) {
|
||||
$event->setIsNetworkConfigView(false);
|
||||
}
|
||||
|
||||
if($event->getIsNetworkConfigEdit() === null) {
|
||||
$event->setIsNetworkConfigEdit(false);
|
||||
}
|
||||
|
||||
if($event->getIsNetworkConfigManagement() === null) {
|
||||
$event->setIsNetworkConfigManagement(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Validators;
|
||||
|
||||
use PandoraFMS\Modules\Events\Enums\EventSeverityEnum;
|
||||
use PandoraFMS\Modules\Events\Enums\EventStatusEnum;
|
||||
use PandoraFMS\Modules\Events\Enums\EventTypeEnum;
|
||||
use PandoraFMS\Modules\Shared\Validators\Validator;
|
||||
|
||||
class EventValidator extends Validator
|
||||
{
|
||||
public const VALIDSEVERITY = 'ValidSeverity';
|
||||
public const VALIDSTATUS = 'ValidStatus';
|
||||
public const VALIDTYPE = 'ValidType';
|
||||
|
||||
protected function isValidSeverity($section): bool
|
||||
{
|
||||
$result = EventSeverityEnum::get(strtoupper($section));
|
||||
return empty($result) === true ? false : true;
|
||||
}
|
||||
|
||||
protected function isValidStatus($status): bool
|
||||
{
|
||||
$result = EventStatusEnum::get(strtoupper($status));
|
||||
return empty($result) === true ? false : true;
|
||||
}
|
||||
|
||||
protected function isValidType($type): bool
|
||||
{
|
||||
$result = EventTypeEnum::get(strtoupper($type));
|
||||
return empty($result) === true ? false : true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
use PandoraFMS\Modules\Events\Controllers\CreateEventController;
|
||||
use PandoraFMS\Modules\Events\Controllers\DeleteEventController;
|
||||
use PandoraFMS\Modules\Events\Controllers\GetEventController;
|
||||
use PandoraFMS\Modules\Events\Controllers\ListEventController;
|
||||
use PandoraFMS\Modules\Events\Controllers\UpdateEventController;
|
||||
use Slim\App;
|
||||
|
||||
return function (App $app) {
|
||||
$app->map(['GET', 'POST'], '/event/list', ListEventController::class);
|
||||
$app->get('/event/{idEvent}', GetEventController::class);
|
||||
$app->post('/event', CreateEventController::class);
|
||||
$app->put('/event/{idEvent}', UpdateEventController::class);
|
||||
$app->delete('/event/{idEvent}', DeleteEventController::class);
|
||||
};
|
Loading…
Reference in New Issue