new api 2.0

This commit is contained in:
daniel 2024-01-25 15:44:50 +01:00
parent cb367985ba
commit 375c2879f6
37 changed files with 2753 additions and 91 deletions

View File

@ -3,6 +3,7 @@
use Slim\App;
return function (App $app) {
(include __DIR__.'/../../../include/lib/Modules/EventFilters/routes.php')($app);
(include __DIR__.'/../../../include/lib/Modules/Events/routes.php')($app);
(include __DIR__.'/../../../include/lib/Modules/Groups/routes.php')($app);
(include __DIR__.'/../../../include/lib/Modules/Profiles/routes.php')($app);

View File

@ -22,6 +22,218 @@
}
],
"paths": {
"/eventFilter": {
"post": {
"tags": ["EventFilters"],
"summary": "Creates a new eventFilters",
"operationId": "3a3a1ec7e7235dc17584194df1ac42ad",
"requestBody": {
"$ref": "#/components/requestBodies/requestBodyEventFilter"
},
"responses": {
"200": {
"$ref": "#/components/responses/ResponseEventFilter"
},
"400": {
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
},
"500": {
"$ref": "#/components/responses/InternalServerError"
}
},
"security": [
{
"bearerAuth": []
}
]
}
},
"/eventFilter/{idEventFilter}": {
"get": {
"tags": ["EventFilters"],
"summary": "Show eventFilter",
"operationId": "4c19710ddc729298a150fe7701bef236",
"parameters": [
{
"$ref": "#/components/parameters/parameterIdEventFilter"
}
],
"responses": {
"200": {
"$ref": "#/components/responses/ResponseEventFilter"
},
"400": {
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
},
"500": {
"$ref": "#/components/responses/InternalServerError"
}
},
"security": [
{
"bearerAuth": []
}
]
},
"put": {
"tags": ["EventFilters"],
"summary": "Updates an eventFilter",
"operationId": "41212d7a86529c93be4306698e20c977",
"parameters": [
{
"$ref": "#/components/parameters/parameterIdEventFilter"
}
],
"requestBody": {
"$ref": "#/components/requestBodies/requestBodyEventFilter"
},
"responses": {
"200": {
"$ref": "#/components/responses/ResponseEventFilter"
},
"400": {
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
},
"500": {
"$ref": "#/components/responses/InternalServerError"
}
},
"security": [
{
"bearerAuth": []
}
]
},
"delete": {
"tags": ["EventFilters"],
"summary": "Deletes an eventFilter object.",
"operationId": "128df05b98479f6c8313b50b271c924e",
"parameters": [
{
"$ref": "#/components/parameters/parameterIdEventFilter"
}
],
"responses": {
"200": {
"$ref": "#/components/responses/successfullyDeleted"
},
"400": {
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
},
"500": {
"$ref": "#/components/responses/InternalServerError"
}
},
"security": [
{
"bearerAuth": []
}
]
}
},
"/eventFilter/list": {
"post": {
"tags": ["EventFilters"],
"summary": "List eventFilters",
"operationId": "2714e7f72ae116642e777523742f4271",
"parameters": [
{
"$ref": "#/components/parameters/parameterPage"
},
{
"$ref": "#/components/parameters/parameterSizePage"
},
{
"$ref": "#/components/parameters/parameterSortField"
},
{
"$ref": "#/components/parameters/parameterSortDirection"
}
],
"requestBody": {
"$ref": "#/components/requestBodies/requestBodyEventFilter"
},
"responses": {
"200": {
"description": "List Incidence object",
"content": {
"application/json": {
"schema": {
"properties": {
"paginationData": {
"$ref": "#/components/schemas/paginationData"
},
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/EventFilter"
}
}
},
"type": "object"
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
},
"500": {
"$ref": "#/components/responses/InternalServerError"
}
},
"security": [
{
"bearerAuth": []
}
]
}
},
"/event/{idEvent}/comment": {
"post": {
"tags": ["Events"],
@ -1500,6 +1712,333 @@
},
"components": {
"schemas": {
"EventFilter": {
"properties": {
"idEventFilter": {
"description": "Id EventFilter",
"type": "integer",
"readOnly": true,
"nullable": false
},
"idGroupFilter": {
"description": "Id group filter",
"type": "integer",
"default": null,
"nullable": true
},
"name": {
"description": "Name of the eventFilter",
"type": "string",
"default": null,
"nullable": false
},
"idGroup": {
"description": "Id group",
"type": "integer",
"default": null,
"nullable": true
},
"severity": {
"description": "Severity event filter",
"type": "array",
"items": {
"properties": {
"severity": {
"description": "Event severity, the available severity are: maintenance, informational, normal, warning, critical, minor, major",
"type": "integer",
"default": "maintenance",
"enum": [
"maintenance",
"informational",
"normal",
"warning",
"critical",
"minor",
"major"
],
"nullable": true
}
},
"type": "object"
},
"default": null,
"nullable": true
},
"status": {
"description": "Event status, the available status are: all, new, validated, inprocess, not_validated, not_in_process",
"type": "integer",
"default": null,
"enum": [
"all",
"new",
"validated",
"inprocess",
"not_validated",
"not_in_process"
],
"nullable": true
},
"eventType": {
"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",
"type": "string",
"default": null,
"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"
],
"nullable": true
},
"search": {
"description": "Search in fields id, event, extraId, source and custom_data",
"type": "string",
"default": null,
"nullable": true
},
"isNotSearch": {
"description": "Not search",
"type": "boolean",
"default": false,
"nullable": true
},
"textAgent": {
"description": "Name agent",
"type": "string",
"default": null,
"readOnly": true,
"nullable": true
},
"idAgent": {
"description": "Id agent",
"type": "integer",
"default": null,
"nullable": true
},
"idAgentModule": {
"description": "Id agent module",
"type": "integer",
"default": null,
"nullable": true
},
"pagination": {
"description": "Block size pagination",
"type": "integer",
"default": null,
"nullable": true
},
"slice": {
"description": "Period search events 8h",
"type": "integer",
"default": null,
"nullable": true
},
"idUserAck": {
"description": "Id user ack",
"type": "string",
"default": null,
"nullable": true
},
"groupBy": {
"description": "Event filter group by, the available group by are: all, events, agents, extra_ids",
"type": "integer",
"default": null,
"enum": ["all", "events", "agents", "extra_ids"],
"nullable": true
},
"tagWith": {
"description": "Tags filter",
"type": "array",
"items": {
"properties": {
"idTags": {
"description": "Tags id",
"type": "integer",
"default": null,
"nullable": true
}
},
"type": "object"
},
"default": null,
"nullable": true
},
"tagWithout": {
"description": "Tags not filter",
"type": "array",
"items": {
"properties": {
"idTags": {
"description": "Tags id",
"type": "integer",
"default": null,
"nullable": true
}
},
"type": "object"
},
"default": null,
"nullable": true
},
"filterOnlyAlert": {
"description": "Event filter event by, the available filter are: all, filter_alert_events, only_alert_events",
"type": "integer",
"default": null,
"enum": ["all", "filter_alert_events", "only_alert_events"],
"nullable": true
},
"searchSecondaryGroups": {
"description": "Search in secondary groups",
"type": "boolean",
"default": false,
"nullable": true
},
"searchRecursiveGroups": {
"description": "Search in recursive groups",
"type": "boolean",
"default": false,
"nullable": true
},
"dateFrom": {
"description": "Search event registration date",
"type": "string",
"default": null,
"example": "2023-02-21",
"nullable": true
},
"dateTo": {
"description": "Search event registration date",
"type": "string",
"default": null,
"example": "2023-02-21",
"nullable": true
},
"source": {
"description": "Search source field",
"type": "string",
"default": null,
"nullable": true
},
"idExtra": {
"description": "Search source idExtra",
"type": "string",
"default": null,
"nullable": true
},
"userComment": {
"description": "Search source userComment",
"type": "string",
"default": null,
"nullable": true
},
"idSourceEvent": {
"description": "Search id source event",
"type": "integer",
"default": null,
"nullable": true
},
"serverId": {
"description": "Server ids filter, only metaconsole",
"type": "array",
"items": {
"properties": {
"idNode": {
"description": "Node id",
"type": "integer",
"default": null,
"nullable": true
}
},
"type": "object"
},
"default": null,
"nullable": true
},
"timeFrom": {
"description": "Search event registration date",
"type": "string",
"default": null,
"example": "08:34:16",
"nullable": true
},
"timeTo": {
"description": "Search event registration date",
"type": "string",
"default": null,
"example": "08:34:16",
"nullable": true
},
"customData": {
"description": "Search custom data",
"type": "string",
"default": null,
"nullable": true
},
"customDataFilterType": {
"description": "Event filter event by, the available filter are: all, filter_alert_events, only_alert_events",
"type": "integer",
"default": null,
"enum": ["only_alert_events", "filter_alert_events"],
"nullable": true
},
"ownerUser": {
"description": "Search owner user",
"type": "string",
"default": null,
"nullable": true
},
"privateFilterUser": {
"description": "Search private filter user",
"type": "string",
"default": null,
"nullable": true
},
"regex": {
"description": "Search regex",
"type": "string",
"default": null,
"nullable": true
}
},
"type": "object"
},
"EventFilterFilter": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/EventFilter"
},
{
"properties": {
"idEventFilter": {
"default": null,
"readOnly": false
},
"freeSearch": {
"description": "Find word in name field.",
"type": "string",
"default": null,
"nullable": true
}
},
"type": "object"
}
]
},
"EventComment": {
"properties": {
"idEventComment": {
@ -1605,7 +2144,7 @@
"type": "string",
"default": null,
"readOnly": true,
"example": "2023-21-02 08:34:16",
"example": "2023-02-21 08:34:16",
"nullable": true
},
"event": {
@ -1660,8 +2199,8 @@
"default": null,
"nullable": true
},
"criticity": {
"description": "Event critcity, the available criticity are: maintenance, informational, normal, warning, critical, minor, major",
"severity": {
"description": "Event severity, the available severity are: maintenance, informational, normal, warning, critical, minor, major",
"type": "integer",
"default": "maintenance",
"enum": [
@ -1752,29 +2291,6 @@
},
"type": "object"
},
"EventFilter": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/Event"
},
{
"properties": {
"idEvent": {
"default": null,
"readOnly": false
},
"freeSearch": {
"description": "Find word in name field.",
"type": "string",
"default": null,
"nullable": true
}
},
"type": "object"
}
]
},
"Group": {
"properties": {
"idGroup": {
@ -2231,7 +2747,7 @@
"type": "string",
"default": null,
"readOnly": true,
"example": "2023-21-02 08:34:16",
"example": "2023-02-21 08:34:16",
"nullable": true
},
"email": {
@ -2365,7 +2881,7 @@
"type": "string",
"default": null,
"readOnly": true,
"example": "2023-21-02 08:34:16",
"example": "2023-02-21 08:34:16",
"nullable": true
},
"lastFailedLogin": {
@ -2373,7 +2889,7 @@
"type": "string",
"default": null,
"readOnly": true,
"example": "2023-21-02 08:34:16",
"example": "2023-02-21 08:34:16",
"nullable": true
},
"failedAttempt": {
@ -2643,6 +3159,16 @@
}
},
"responses": {
"ResponseEventFilter": {
"description": "EventFilter object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/EventFilter"
}
}
}
},
"ResponseEventComment": {
"description": "Event comment object",
"content": {
@ -2816,6 +3342,16 @@
}
},
"parameters": {
"parameterIdEventFilter": {
"name": "idEventFilter",
"in": "path",
"description": "EventFilter id",
"required": true,
"schema": {
"type": "integer",
"default": 1
}
},
"parameterIdEventComment": {
"name": "idComment",
"in": "path",
@ -2929,6 +3465,26 @@
}
},
"requestBodies": {
"requestBodyEventFilter": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/EventFilter"
}
}
}
},
"requestBodyEventFilterFilter": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/EventFilterFilter"
}
}
}
},
"requestBodyEventComment": {
"required": true,
"content": {
@ -2959,16 +3515,6 @@
}
}
},
"requestBodyEventFilter": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/EventFilter"
}
}
}
},
"requestBodyGroup": {
"required": true,
"content": {
@ -3085,6 +3631,10 @@
"name": "Events",
"description": "API Endpoints of events"
},
{
"name": "EventFilters",
"description": "API Endpoints of filter events"
},
{
"name": "Groups",
"description": "API Endpoints of Groups"

View File

@ -0,0 +1,19 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Actions;
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
use PandoraFMS\Modules\EventFilters\Services\CreateEventFilterService;
final class CreateEventFilterAction
{
public function __construct(
private CreateEventFilterService $createEventFilterService
) {
}
public function __invoke(EventFilter $eventFilter): EventFilter
{
return $this->createEventFilterService->__invoke($eventFilter);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Actions;
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
use PandoraFMS\Modules\EventFilters\Services\DeleteEventFilterService;
final class DeleteEventFilterAction
{
public function __construct(
private DeleteEventFilterService $deleteEventFilterService
) {
}
public function __invoke(EventFilter $eventFilter): void
{
$this->deleteEventFilterService->__invoke($eventFilter);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Actions;
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
use PandoraFMS\Modules\EventFilters\Services\GetEventFilterService;
final class GetEventFilterAction
{
public function __construct(
private GetEventFilterService $getEventFilterService
) {
}
public function __invoke(int $idEventFilter): EventFilter
{
return $this->getEventFilterService->__invoke($idEventFilter);
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Actions;
use PandoraFMS\Modules\EventFilters\Entities\EventFilterFilter;
use PandoraFMS\Modules\EventFilters\Services\CountEventFilterService;
use PandoraFMS\Modules\EventFilters\Services\ListEventFilterService;
use PandoraFMS\Modules\Shared\Entities\PaginationData;
final class ListEventFilterAction
{
public function __construct(
private ListEventFilterService $listEventFilterService,
private CountEventFilterService $countEventFilterService
) {
}
public function __invoke(EventFilterFilter $eventFilterFilter): array
{
return (new PaginationData(
$eventFilterFilter->getPage(),
$eventFilterFilter->getSizePage(),
$this->countEventFilterService->__invoke($eventFilterFilter),
$this->listEventFilterService->__invoke($eventFilterFilter)
))->toArray();
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Actions;
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
use PandoraFMS\Modules\EventFilters\Services\UpdateEventFilterService;
final class UpdateEventFilterAction
{
public function __construct(
private UpdateEventFilterService $updateEventFilterService
) {
}
public function __invoke(EventFilter $eventFilter, EventFilter $oldEventFilter): EventFilter
{
return $this->updateEventFilterService->__invoke($eventFilter, $oldEventFilter);
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Controllers;
use PandoraFMS\Modules\EventFilters\Actions\CreateEventFilterAction;
use PandoraFMS\Modules\EventFilters\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 CreateEventFilterController extends Controller
{
public function __construct(
private CreateEventFilterAction $createEventFilterAction,
private ValidateAclSystem $acl,
) {
}
/**
* @OA\Post(
* security={{ "bearerAuth": {}}},
* tags={"EventFilters"},
* path="/eventFilter",
* summary="Creates a new eventFilters",
* @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventFilter"),
* @OA\Response(response=200, ref="#/components/responses/ResponseEventFilter"),
* @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, 'EW', ' tried to write event');
$result = $this->createEventFilterAction->__invoke($eventFilter);
return $this->getResponse($response, $result);
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Controllers;
use PandoraFMS\Modules\EventFilters\Actions\DeleteEventFilterAction;
use PandoraFMS\Modules\EventFilters\Actions\GetEventFilterAction;
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 DeleteEventFilterController extends Controller
{
public function __construct(
private DeleteEventFilterAction $deleteEventFilterAction,
private ValidateAclSystem $acl,
private GetEventFilterAction $getEventFilterAction
) {
}
/**
* @OA\Delete(
* security={{ "bearerAuth": {}}},
* tags={"EventFilters"},
* path="/eventFilter/{idEventFilter}",
* summary="Deletes an eventFilter object.",
* @OA\Parameter(ref="#/components/parameters/parameterIdEventFilter"),
* @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
{
$idEventFilter = $this->getParam($request, 'idEventFilter');
$eventFilter = $this->getEventFilterAction->__invoke($idEventFilter);
$this->acl->validate(0, 'EW', ' tried to write event');
$result = $this->deleteEventFilterAction->__invoke($eventFilter);
return $this->getResponse($response, $result);
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Controllers;
use PandoraFMS\Modules\EventFilters\Actions\GetEventFilterAction;
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 GetEventFilterController extends Controller
{
public function __construct(
private GetEventFilterAction $getEventFilterAction,
private ValidateAclSystem $acl
) {
}
/**
* @OA\Get(
* security={{ "bearerAuth": {}}},
* path="/eventFilter/{idEventFilter}",
* tags={"EventFilters"},
* summary="Show eventFilter",
* @OA\Parameter(ref="#/components/parameters/parameterIdEventFilter"),
* @OA\Response(response=200, ref="#/components/responses/ResponseEventFilter"),
* @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
{
$idEventFilter = $this->getParam($request, 'idEventFilter');
$this->acl->validate(0, 'ER', ' tried to read event');
$result = $this->getEventFilterAction->__invoke($idEventFilter);
return $this->getResponse($response, $result);
}
}

View File

@ -0,0 +1,74 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Controllers;
use PandoraFMS\Modules\EventFilters\Actions\ListEventFilterAction;
use PandoraFMS\Modules\EventFilters\Entities\EventFilterFilter;
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 ListEventFilterController extends Controller
{
public function __construct(
private ListEventFilterAction $listEventFilterAction,
private ValidateAclSystem $acl,
) {
}
/**
* @OA\Post(
* security={{ "bearerAuth": {}}},
* tags={"EventFilters"},
* path="/eventFilter/list",
* summary="List eventFilters",
* @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 Incidence 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/EventFilter",
* description="Array of incidences Type 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 EventFilterFilter $eventFilterFilter.
$eventFilterFilter = $this->fromRequest($request, EventFilterFilter::class);
$this->acl->validate(0, 'ER', ' tried to read event');
$result = $this->listEventFilterAction->__invoke($eventFilterFilter);
return $this->getResponse($response, $result);
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Controllers;
use PandoraFMS\Modules\EventFilters\Actions\GetEventFilterAction;
use PandoraFMS\Modules\EventFilters\Actions\UpdateEventFilterAction;
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="/eventFilter/{idEventFilter}",
* tags={"EventFilters"},
* summary="Updates an eventFilter",
* @OA\Parameter(ref="#/components/parameters/parameterIdEventFilter"),
* @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventFilter"),
* @OA\Response(response=200, ref="#/components/responses/ResponseEventFilter"),
* @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 UpdateEventFilterController extends Controller
{
public function __construct(
private UpdateEventFilterAction $updateEventFilterAction,
private ValidateAclSystem $acl,
private GetEventFilterAction $getEventFilterAction
) {
}
public function __invoke(Request $request, Response $response): Response
{
$idEventFilter = $this->getParam($request, 'idEventFilter');
$eventFilter = $this->getEventFilterAction->__invoke($idEventFilter);
$oldEventFilter = clone $eventFilter;
$params = $this->extractParams($request);
$eventFilter->fromArray($params);
$this->acl->validate(0, 'EW', ' tried to write event');
$result = $this->updateEventFilterAction->__invoke($eventFilter, $oldEventFilter);
return $this->getResponse($response, $result);
}
}

View File

@ -0,0 +1,924 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Entities;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterAlertEnum;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterCustomDataEnum;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterGroupByEnum;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterStatusEnum;
use PandoraFMS\Modules\EventFilters\Validators\EventFilterValidator;
use PandoraFMS\Modules\Events\Enums\EventTypeEnum;
use PandoraFMS\Modules\Shared\Entities\Entity;
/**
* @OA\Schema(
* schema="EventFilter",
* type="object",
* @OA\Property(
* property="idEventFilter",
* type="integer",
* nullable=false,
* description="Id EventFilter",
* readOnly=true
* ),
* @OA\Property(
* property="idGroupFilter",
* type="integer",
* nullable=true,
* default=null,
* description="Id group filter"
* ),
* @OA\Property(
* property="name",
* type="string",
* nullable=false,
* default=null,
* description="Name of the eventFilter"
* ),
* @OA\Property(
* property="idGroup",
* type="integer",
* nullable=true,
* default=null,
* description="Id group"
* ),
* @OA\Property(
* property="severity",
* type="array",
* nullable=true,
* default=null,
* description="Severity event filter",
* @OA\Items(
* @OA\Property(
* property="severity",
* type="integer",
* nullable=true,
* enum={
* "maintenance",
* "informational",
* "normal",
* "warning",
* "critical",
* "minor",
* "major"
* },
* default="maintenance",
* description="Event severity, the available severity are: maintenance, informational, normal, warning, critical, minor, major"
* )
* )
* ),
* @OA\Property(
* property="status",
* type="integer",
* nullable=true,
* enum={
* "all",
* "new",
* "validated",
* "inprocess",
* "not_validated",
* "not_in_process"
* },
* default=null,
* description="Event status, the available status are: all, new, validated, inprocess, not_validated, not_in_process"
* ),
* @OA\Property(
* property="eventType",
* type="string",
* nullable=true,
* 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=null,
* 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="search",
* type="string",
* nullable=true,
* default=null,
* description="Search in fields id, event, extraId, source and custom_data"
* ),
* @OA\Property(
* property="isNotSearch",
* type="boolean",
* nullable=true,
* default=false,
* description="Not search"
* ),
* @OA\Property(
* property="textAgent",
* type="string",
* nullable=true,
* default=null,
* description="Name agent",
* readOnly=true
* ),
* @OA\Property(
* property="idAgent",
* type="integer",
* nullable=true,
* default=null,
* description="Id agent"
* ),
* @OA\Property(
* property="idAgentModule",
* type="integer",
* nullable=true,
* default=null,
* description="Id agent module"
* ),
* @OA\Property(
* property="pagination",
* type="integer",
* nullable=true,
* default=null,
* description="Block size pagination"
* ),
* @OA\Property(
* property="slice",
* type="integer",
* nullable=true,
* default=null,
* description="Period search events 8h"
* ),
* @OA\Property(
* property="idUserAck",
* type="string",
* nullable=true,
* default=null,
* description="Id user ack"
* ),
* @OA\Property(
* property="groupBy",
* type="integer",
* nullable=true,
* enum={
* "all",
* "events",
* "agents",
* "extra_ids"
* },
* default=null,
* description="Event filter group by, the available group by are: all, events, agents, extra_ids"
* ),
* @OA\Property(
* property="tagWith",
* type="array",
* nullable=true,
* default=null,
* description="Tags filter",
* @OA\Items(
* @OA\Property(
* property="idTags",
* type="integer",
* nullable=true,
* default=null,
* description="Tags id"
* )
* )
* ),
* @OA\Property(
* property="tagWithout",
* type="array",
* nullable=true,
* default=null,
* description="Tags not filter",
* @OA\Items(
* @OA\Property(
* property="idTags",
* type="integer",
* nullable=true,
* default=null,
* description="Tags id"
* )
* )
* ),
* @OA\Property(
* property="filterOnlyAlert",
* type="integer",
* nullable=true,
* enum={
* "all",
* "filter_alert_events",
* "only_alert_events"
* },
* default=null,
* description="Event filter event by, the available filter are: all, filter_alert_events, only_alert_events"
* ),
* @OA\Property(
* property="searchSecondaryGroups",
* type="boolean",
* nullable=true,
* default=false,
* description="Search in secondary groups"
* ),
* @OA\Property(
* property="searchRecursiveGroups",
* type="boolean",
* nullable=true,
* default=false,
* description="Search in recursive groups"
* ),
* @OA\Property(
* property="dateFrom",
* type="string",
* nullable=true,
* default=null,
* description="Search event registration date",
* example="2023-02-21"
* ),
* @OA\Property(
* property="dateTo",
* type="string",
* nullable=true,
* default=null,
* description="Search event registration date",
* example="2023-02-21"
* ),
* @OA\Property(
* property="source",
* type="string",
* nullable=true,
* default=null,
* description="Search source field"
* ),
* @OA\Property(
* property="idExtra",
* type="string",
* nullable=true,
* default=null,
* description="Search source idExtra"
* ),
* @OA\Property(
* property="userComment",
* type="string",
* nullable=true,
* default=null,
* description="Search source userComment"
* ),
* @OA\Property(
* property="idSourceEvent",
* type="integer",
* nullable=true,
* default=null,
* description="Search id source event"
* ),
* @OA\Property(
* property="serverId",
* type="array",
* nullable=true,
* default=null,
* description="Server ids filter, only metaconsole",
* @OA\Items(
* @OA\Property(
* property="idNode",
* type="integer",
* nullable=true,
* default=null,
* description="Node id"
* )
* )
* ),
* @OA\Property(
* property="timeFrom",
* type="string",
* nullable=true,
* default=null,
* description="Search event registration date",
* example="08:34:16"
* ),
* @OA\Property(
* property="timeTo",
* type="string",
* nullable=true,
* default=null,
* description="Search event registration date",
* example="08:34:16"
* ),
* @OA\Property(
* property="customData",
* type="string",
* nullable=true,
* default=null,
* description="Search custom data"
* ),
* @OA\Property(
* property="customDataFilterType",
* type="integer",
* nullable=true,
* enum={
* "only_alert_events",
* "filter_alert_events"
* },
* default=null,
* description="Event filter event by, the available filter are: all, filter_alert_events, only_alert_events"
* ),
* @OA\Property(
* property="ownerUser",
* type="string",
* nullable=true,
* default=null,
* description="Search owner user"
* ),
* @OA\Property(
* property="privateFilterUser",
* type="string",
* nullable=true,
* default=null,
* description="Search private filter user"
* ),
* @OA\Property(
* property="regex",
* type="string",
* nullable=true,
* default=null,
* description="Search regex"
* )
* )
*
* @OA\Response(
* response="ResponseEventFilter",
* description="EventFilter object",
* content={
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="object",
* ref="#/components/schemas/EventFilter",
* description="EventFilter object"
* )
* )
* }
* )
*
* @OA\Parameter(
* parameter="parameterIdEventFilter",
* name="idEventFilter",
* in="path",
* description="EventFilter id",
* required=true,
* @OA\Schema(
* type="integer",
* default=1
* )
* )
*
* @OA\RequestBody(
* request="requestBodyEventFilter",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/EventFilter")
* )
* )
*/
final class EventFilter extends Entity
{
private ?int $idEventFilter = null;
private ?int $idGroupFilter = null;
private ?string $name = null;
private ?int $idGroup = null;
private ?EventTypeEnum $eventType = null;
private ?array $severity = null;
private ?EventFilterStatusEnum $status = null;
private ?string $search = null;
private ?bool $isNotSearch = null;
private ?string $textAgent = null;
private ?int $idAgent = null;
private ?int $idAgentModule = null;
private ?int $pagination = null;
private ?int $slice = null;
private ?string $idUserAck = null;
private ?EventFilterGroupByEnum $groupBy = null;
private ?array $tagWith = null;
private ?array $tagWithout = null;
private ?EventFilterAlertEnum $filterOnlyAlert = null;
private ?bool $searchSecondaryGroups = null;
private ?bool $searchRecursiveGroups = null;
private ?string $dateFrom = null;
private ?string $dateTo = null;
private ?string $source = null;
private ?string $idExtra = null;
private ?string $userComment = null;
private ?int $idSourceEvent = null;
private ?array $serverId = null;
private ?string $timeFrom = null;
private ?string $timeTo = null;
private ?string $customData = null;
private ?EventFilterCustomDataEnum $customDataFilterType = null;
private ?string $ownerUser = null;
private ?string $privateFilterUser = null;
private ?string $regex = null;
public function __construct()
{
}
public function fieldsReadOnly(): array
{
return ['idEventFilter' => 1];
}
public function jsonSerialize(): mixed
{
return [
'idEventFilter' => $this->getIdEventFilter(),
'idGroupFilter' => $this->getIdGroupFilter(),
'name' => $this->getName(),
'idGroup' => $this->getIdGroup(),
'eventType' => $this->getEventType()?->name,
'severity' => $this->getSeverity(),
'status' => $this->getStatus()?->name,
'search' => $this->getSearch(),
'isNotSearch' => $this->getIsNotSearch(),
'textAgent' => $this->getTextAgent(),
'idAgent' => $this->getIdAgent(),
'idAgentModule' => $this->getIdAgentModule(),
'pagination' => $this->getPagination(),
'slice' => $this->getSlice(),
'idUserAck' => $this->getIdUserAck(),
'groupBy' => $this->getGroupBy()?->name,
'tagWith' => $this->getTagWith(),
'tagWithout' => $this->getTagWithout(),
'filterOnlyAlert' => $this->getFilterOnlyAlert()?->name,
'searchSecondaryGroups' => $this->getSearchSecondaryGroups(),
'searchRecursiveGroups' => $this->getSearchRecursiveGroups(),
'dateFrom' => $this->getDateFrom(),
'dateTo' => $this->getDateTo(),
'source' => $this->getSource(),
'idExtra' => $this->getIdExtra(),
'userComment' => $this->getUserComment(),
'idSourceEvent' => $this->getIdSourceEvent(),
'serverId' => $this->getServerId(),
'timeFrom' => $this->getTimeFrom(),
'timeTo' => $this->getTimeTo(),
'customData' => $this->getCustomData(),
'customDataFilterType' => $this->getCustomDataFilterType()?->name,
'ownerUser' => $this->getOwnerUser(),
'privateFilterUser' => $this->getPrivateFilterUser(),
'regex' => $this->getRegex(),
];
}
public function getValidations(): array
{
return [
'idEventFilter' => [
EventFilterValidator::INTEGER,
EventFilterValidator::GREATERTHAN,
],
'idGroupFilter' => [
EventFilterValidator::INTEGER,
EventFilterValidator::GREATEREQUALTHAN,
],
'name' => EventFilterValidator::STRING,
'idGroup' => [
EventFilterValidator::INTEGER,
EventFilterValidator::GREATEREQUALTHAN,
],
'eventType' => EventFilterValidator::VALIDFILTERTYPE,
'severity' => EventFilterValidator::ARRAY,
'status' => EventFilterValidator::VALIDFILTERSTATUS,
'search' => EventFilterValidator::STRING,
'isNotSearch' => EventFilterValidator::BOOLEAN,
'textAgent' => EventFilterValidator::STRING,
'idAgent' => [
EventFilterValidator::INTEGER,
EventFilterValidator::GREATEREQUALTHAN,
],
'idAgentModule' => [
EventFilterValidator::INTEGER,
EventFilterValidator::GREATEREQUALTHAN,
],
'pagination' => [
EventFilterValidator::INTEGER,
EventFilterValidator::GREATEREQUALTHAN,
],
'slice' => [
EventFilterValidator::INTEGER,
EventFilterValidator::GREATEREQUALTHAN,
],
'idUserAck' => EventFilterValidator::STRING,
'groupBy' => EventFilterValidator::VALIDFILTERGROUPBY,
'tagWith' => EventFilterValidator::ARRAY,
'tagWithout' => EventFilterValidator::ARRAY,
'filterOnlyAlert' => EventFilterValidator::VALIDFILTERALERT,
'searchSecondaryGroups' => EventFilterValidator::BOOLEAN,
'searchRecursiveGroups' => EventFilterValidator::BOOLEAN,
'dateFrom' => EventFilterValidator::DATE,
'dateTo' => EventFilterValidator::DATE,
'source' => EventFilterValidator::STRING,
'idExtra' => EventFilterValidator::STRING,
'userComment' => EventFilterValidator::STRING,
'idSourceEvent' => [
EventFilterValidator::INTEGER,
EventFilterValidator::GREATEREQUALTHAN,
],
'serverId' => EventFilterValidator::ARRAY,
'timeFrom' => EventFilterValidator::TIME,
'timeTo' => EventFilterValidator::TIME,
'customData' => EventFilterValidator::STRING,
'customDataFilterType' => EventFilterValidator::VALIDFILTERCUSTOMDATA,
'ownerUser' => EventFilterValidator::STRING,
'privateFilterUser' => EventFilterValidator::STRING,
'regex' => EventFilterValidator::STRING,
];
}
public function validateFields(array $filters): array
{
return (new EventFilterValidator())->validate($filters);
}
public function getIdEventFilter(): ?int
{
return $this->idEventFilter;
}
public function setIdEventFilter(?int $idEventFilter): self
{
$this->idEventFilter = $idEventFilter;
return $this;
}
public function getIdGroupFilter(): ?int
{
return $this->idGroupFilter;
}
public function setIdGroupFilter(?int $idGroupFilter): self
{
$this->idGroupFilter = $idGroupFilter;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getIdGroup(): ?int
{
return $this->idGroup;
}
public function setIdGroup(?int $idGroup): self
{
$this->idGroup = $idGroup;
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 getSeverity(): ?array
{
return $this->severity;
}
public function setSeverity(?array $severity): self
{
$this->severity = $severity;
return $this;
}
public function getStatus(): ?EventFilterStatusEnum
{
return $this->status;
}
public function setStatus(null|string|EventFilterStatusEnum $status): self
{
if (is_string($status) === true) {
$this->status = EventFilterStatusEnum::get(strtoupper($status));
} else {
$this->status = $status;
}
return $this;
}
public function getSearch(): ?string
{
return $this->search;
}
public function setSearch(?string $search): self
{
$this->search = $search;
return $this;
}
public function getIsNotSearch(): ?bool
{
return $this->isNotSearch;
}
public function setIsNotSearch(?bool $isNotSearch): self
{
$this->isNotSearch = $isNotSearch;
return $this;
}
public function getTextAgent(): ?string
{
return $this->textAgent;
}
public function setTextAgent(?string $textAgent): self
{
$this->textAgent = $textAgent;
return $this;
}
public function getIdAgent(): ?int
{
return $this->idAgent;
}
public function setIdAgent(?int $idAgent): self
{
$this->idAgent = $idAgent;
return $this;
}
public function getIdAgentModule(): ?int
{
return $this->idAgentModule;
}
public function setIdAgentModule(?int $idAgentModule): self
{
$this->idAgentModule = $idAgentModule;
return $this;
}
public function getPagination(): ?int
{
return $this->pagination;
}
public function setPagination(?int $pagination): self
{
$this->pagination = $pagination;
return $this;
}
public function getSlice(): ?int
{
return $this->slice;
}
public function setSlice(?int $slice): self
{
$this->slice = $slice;
return $this;
}
public function getIdUserAck(): ?string
{
return $this->idUserAck;
}
public function setIdUserAck(?string $idUserAck): self
{
$this->idUserAck = $idUserAck;
return $this;
}
public function getGroupBy(): ?EventFilterGroupByEnum
{
return $this->groupBy;
}
public function setGroupBy(null|string|EventFilterGroupByEnum $groupBy): self
{
if (is_string($groupBy) === true) {
$this->groupBy = EventFilterGroupByEnum::get(strtoupper($groupBy));
} else {
$this->groupBy = $groupBy;
}
return $this;
}
public function getTagWith(): ?array
{
return $this->tagWith;
}
public function setTagWith(?array $tagWith): self
{
$this->tagWith = $tagWith;
return $this;
}
public function getTagWithout(): ?array
{
return $this->tagWithout;
}
public function setTagWithout(?array $tagWithout): self
{
$this->tagWithout = $tagWithout;
return $this;
}
public function getFilterOnlyAlert(): ?EventFilterAlertEnum
{
return $this->filterOnlyAlert;
}
public function setFilterOnlyAlert(null|string|EventFilterAlertEnum $filterOnlyAlert): self
{
if (is_string($filterOnlyAlert) === true) {
$this->filterOnlyAlert = EventFilterAlertEnum::get(strtoupper($filterOnlyAlert));
} else {
$this->filterOnlyAlert = $filterOnlyAlert;
}
return $this;
}
public function getSearchSecondaryGroups(): ?bool
{
return $this->searchSecondaryGroups;
}
public function setSearchSecondaryGroups(?bool $searchSecondaryGroups): self
{
$this->searchSecondaryGroups = $searchSecondaryGroups;
return $this;
}
public function getSearchRecursiveGroups(): ?bool
{
return $this->searchRecursiveGroups;
}
public function setSearchRecursiveGroups(?bool $searchRecursiveGroups): self
{
$this->searchRecursiveGroups = $searchRecursiveGroups;
return $this;
}
public function getDateFrom(): ?string
{
return $this->dateFrom;
}
public function setDateFrom(?string $dateFrom): self
{
$this->dateFrom = $dateFrom;
return $this;
}
public function getDateTo(): ?string
{
return $this->dateTo;
}
public function setDateTo(?string $dateTo): self
{
$this->dateTo = $dateTo;
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 getUserComment(): ?string
{
return $this->userComment;
}
public function setUserComment(?string $userComment): self
{
$this->userComment = $userComment;
return $this;
}
public function getIdSourceEvent(): ?int
{
return $this->idSourceEvent;
}
public function setIdSourceEvent(?int $idSourceEvent): self
{
$this->idSourceEvent = $idSourceEvent;
return $this;
}
public function getServerId(): ?array
{
return $this->serverId;
}
public function setServerId(?array $serverId): self
{
$this->serverId = $serverId;
return $this;
}
public function getTimeFrom(): ?string
{
return $this->timeFrom;
}
public function setTimeFrom(?string $timeFrom): self
{
$this->timeFrom = $timeFrom;
return $this;
}
public function getTimeTo(): ?string
{
return $this->timeTo;
}
public function setTimeTo(?string $timeTo): self
{
$this->timeTo = $timeTo;
return $this;
}
public function getCustomData(): ?string
{
return $this->customData;
}
public function setCustomData(?string $customData): self
{
$this->customData = $customData;
return $this;
}
public function getCustomDataFilterType(): ?EventFilterCustomDataEnum
{
return $this->customDataFilterType;
}
public function setCustomDataFilterType(null|string|EventFilterCustomDataEnum $customDataFilterType): self
{
if (is_string($customDataFilterType) === true) {
$this->customDataFilterType = EventFilterCustomDataEnum::get(strtoupper($customDataFilterType));
} else {
$this->customDataFilterType = $customDataFilterType;
}
return $this;
}
public function getOwnerUser(): ?string
{
return $this->ownerUser;
}
public function setOwnerUser(?string $ownerUser): self
{
$this->ownerUser = $ownerUser;
return $this;
}
public function getPrivateFilterUser(): ?string
{
return $this->privateFilterUser;
}
public function setPrivateFilterUser(?string $privateFilterUser): self
{
$this->privateFilterUser = $privateFilterUser;
return $this;
}
public function getRegex(): ?string
{
return $this->regex;
}
public function setRegex(?string $regex): self
{
$this->regex = $regex;
return $this;
}
}

View File

@ -0,0 +1,169 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Entities;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterAlertEnum;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterCustomDataEnum;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterGroupByEnum;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterStatusEnum;
use PandoraFMS\Modules\Events\Enums\EventSeverityEnum;
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 EventFilterDataMapper extends DataMapperAbstract
{
public const TABLE_NAME = 'tevent_filter';
public const ID_FILTER = 'id_filter';
public const ID_GROUP_FILTER = 'id_group_filter';
public const NAME = 'id_name';
public const ID_GROUP = 'id_group';
public const EVENT_TYPE = 'event_type';
public const SEVERITY = 'severity';
public const STATUS = 'status';
public const SEARCH = 'search';
public const NOT_SEARCH = 'not_search';
public const TEXT_AGENT = 'text_agent';
public const ID_AGENT = 'id_agent';
public const ID_AGENT_MODULE = 'id_agent_module';
public const PAGINATION = 'pagination';
public const SLICE = 'event_view_hr';
public const ID_USER_ACK = 'id_user_ack';
public const ORDER_BY = 'group_rep';
public const TAG_WITH = 'tag_with';
public const TAG_WITHOUT = 'tag_without';
public const FILTER_ONLY_ALERT = 'filter_only_alert';
public const SEARCH_SECONDARY_GROUPS = 'search_secondary_groups';
public const SEARCH_RECURSIVE_GROUPS = 'search_recursive_groups';
public const DATE_FROM = 'date_from';
public const DATE_TO = 'date_to';
public const SOURCE = 'source';
public const ID_EXTRA = 'id_extra';
public const USER_COMMENT = 'user_comment';
public const ID_SOURCE_EVENT = 'id_source_event';
public const SERVER_ID = 'server_id';
public const TIME_FROM = 'time_from';
public const TIME_TO = 'time_to';
public const CUSTOM_DATA = 'custom_data';
public const CUSTOM_DATA_FILTER_TYPE = 'custom_data_filter_type';
public const OWNER_USER = 'owner_user';
public const PRIVATE_FILTER_USER = 'private_filter_user';
public const REGEX = 'regex';
public function __construct(
private Repository $repository,
private Builder $builder,
) {
parent::__construct(
self::TABLE_NAME,
self::ID_FILTER,
);
}
public function getClassName(): string
{
return EventFilter::class;
}
public function fromDatabase(array $data): EventFilter
{
$severity = null;
if(empty($data[self::SEVERITY]) === false) {
$severities = explode(',', $data[self::SEVERITY]);
foreach ($severities as $value) {
$severity[] = EventSeverityEnum::get($value, 'value')?->name;
}
}
return $this->builder->build(new EventFilter(), [
'idEventFilter' => $data[self::ID_FILTER],
'idGroupFilter' => $data[self::ID_GROUP_FILTER],
'name' => $this->repository->safeOutput($data[self::NAME]),
'idGroup' => $data[self::ID_GROUP],
'eventType' => EventTypeEnum::get($data[self::EVENT_TYPE]),
'severity' => $severity,
'status' => EventFilterStatusEnum::get($data[self::STATUS]),
'search' => $this->repository->safeOutput($data[self::SEARCH]),
'isNotSearch' => $data[self::NOT_SEARCH],
'textAgent' => $this->repository->safeOutput($data[self::TEXT_AGENT]),
'idAgent' => $data[self::ID_AGENT],
'idAgentModule' => $data[self::ID_AGENT_MODULE],
'pagination' => $data[self::PAGINATION],
'slice' => $data[self::SLICE],
'idUserAck' => $data[self::ID_USER_ACK],
'groupBy' => EventFilterGroupByEnum::get($data[self::ORDER_BY]),
'tagWith' => (empty($data[self::TAG_WITH]) === false) ? explode(',', $this->repository->safeOutput($data[self::TAG_WITH])) : null,
'tagWithout' => (empty($data[self::TAG_WITHOUT]) === false) ? explode(',', $this->repository->safeOutput($data[self::TAG_WITHOUT])) : null,
'filterOnlyAlert' => EventFilterAlertEnum::get($data[self::FILTER_ONLY_ALERT]),
'searchSecondaryGroups' => $data[self::SEARCH_SECONDARY_GROUPS],
'searchRecursiveGroups' => $data[self::SEARCH_RECURSIVE_GROUPS],
'dateFrom' => $data[self::DATE_FROM],
'dateTo' => $data[self::DATE_TO],
'source' => $this->repository->safeOutput($this->repository->safeOutput($data[self::SOURCE])),
'idExtra' => $this->repository->safeOutput($data[self::ID_EXTRA]),
'userComment' => $this->repository->safeOutput($data[self::USER_COMMENT]),
'idSourceEvent' => $data[self::ID_SOURCE_EVENT],
'serverId' => (empty($data[self::SERVER_ID]) === false) ? explode(',', $data[self::SERVER_ID]) : null,
'timeFrom' => $data[self::TIME_FROM],
'timeTo' => $data[self::TIME_TO],
'customData' => $this->repository->safeOutput($data[self::CUSTOM_DATA]),
'customDataFilterType' => EventFilterCustomDataEnum::get($data[self::CUSTOM_DATA_FILTER_TYPE]),
'ownerUser' => $data[self::OWNER_USER],
'privateFilterUser' => $data[self::PRIVATE_FILTER_USER],
'regex' => $this->repository->safeOutput($data[self::REGEX]),
]);
}
public function toDatabase(MappeableInterface $data): array
{
/** @var EventFilter $data */
$severity = null;
if(empty($data->getSeverity()) === false) {
$severities = [];
foreach ($data->getSeverity() as $value) {
$severities[] = EventSeverityEnum::get($value)?->value;
}
$severity = implode(',', $severities);
}
return [
self::ID_FILTER => $data->getIdEventFilter(),
self::ID_GROUP_FILTER => $data->getIdGroupFilter(),
self::NAME => $this->repository->safeInput($data->getName()),
self::ID_GROUP => $data->getIdGroup(),
self::EVENT_TYPE => $data->getEventType()?->value,
self::SEVERITY => $severity,
self::STATUS => $data->getStatus()?->value,
self::SEARCH => $this->repository->safeInput($data->getSearch()),
self::NOT_SEARCH => $data->getIsNotSearch(),
self::TEXT_AGENT => $this->repository->safeInput($data->getTextAgent()),
self::ID_AGENT => $data->getIdAgent(),
self::ID_AGENT_MODULE => $data->getIdAgentModule(),
self::PAGINATION => $data->getPagination(),
self::SLICE => $data->getSlice(),
self::ID_USER_ACK => $data->getIdUserAck(),
self::ORDER_BY => $data->getGroupBy()?->value,
self::TAG_WITH => (empty($data->getTagWith()) === false) ? implode(',', $data->getTagWith()) : null,
self::TAG_WITHOUT => (empty($data->getTagWithout()) === false) ? implode(',', $data->getTagWithout()) : null,
self::FILTER_ONLY_ALERT => $data->getFilterOnlyAlert()?->value,
self::SEARCH_SECONDARY_GROUPS => $data->getSearchSecondaryGroups(),
self::SEARCH_RECURSIVE_GROUPS => $data->getSearchRecursiveGroups(),
self::DATE_FROM => $data->getDateFrom(),
self::DATE_TO => $data->getDateTo(),
self::SOURCE => $this->repository->safeInput($data->getSource()),
self::ID_EXTRA => $this->repository->safeInput($data->getIdExtra()),
self::USER_COMMENT => $this->repository->safeInput($data->getUserComment()),
self::ID_SOURCE_EVENT => $data->getIdSourceEvent(),
self::SERVER_ID => (empty($data->getServerId()) === false) ? $this->repository->safeInput('"'.implode('","', $data->getServerId()).'"') : null,
self::TIME_FROM => $data->getTimeFrom(),
self::TIME_TO => $data->getTimeTo(),
self::CUSTOM_DATA => $this->repository->safeInput($data->getCustomData()),
self::CUSTOM_DATA_FILTER_TYPE => $data->getCustomDataFilterType()?->value,
self::OWNER_USER => $data->getOwnerUser(),
self::PRIVATE_FILTER_USER => $data->getPrivateFilterUser(),
self::REGEX => $this->repository->safeInput($data->getRegex()),
];
}
}

View File

@ -0,0 +1,121 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Entities;
use PandoraFMS\Modules\Shared\Core\FilterAbstract;
use PandoraFMS\Modules\Shared\Validators\Validator;
/**
* @OA\Schema(
* schema="EventFilterFilter",
* type="object",
* allOf={
* @OA\Schema(ref="#/components/schemas/EventFilter"),
* @OA\Schema(
* @OA\Property(
* property="idEventFilter",
* default=null,
* readOnly=false
* ),
* @OA\Property(
* property="freeSearch",
* type="string",
* nullable=true,
* default=null,
* description="Find word in name field."
* )
* )
* }
* )
*
* @OA\RequestBody(
* request="requestBodyEventFilterFilter",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/EventFilterFilter")
* ),
* )
*/
final class EventFilterFilter extends FilterAbstract
{
private ?string $freeSearch = null;
public function __construct()
{
$this->setDefaultFieldOrder(EventFilterDataMapper::NAME);
$this->setDefaultDirectionOrder($this::ASC);
$this->setEntityFilter(new EventFilter());
}
public function fieldsTranslate(): array
{
return [
'idEventFilter' => EventFilterDataMapper::ID_FILTER,
'name' => EventFilterDataMapper::NAME,
];
}
public function fieldsReadOnly(): array
{
return [
'tagWith' => 1,
'tagWithout' => 1,
];
}
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 [EventFilterDataMapper::NAME];
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Enums;
use PandoraFMS\Modules\Shared\Traits\EnumTrait;
enum EventFilterAlertEnum: int
{
use EnumTrait;
case ALL = -1;
case FILTER_ALERT_EVENTS = 0;
case ONLY_ALERT_EVENTS = 1;
}

View File

@ -0,0 +1,13 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Enums;
use PandoraFMS\Modules\Shared\Traits\EnumTrait;
enum EventFilterCustomDataEnum: int
{
use EnumTrait;
case NAME = 0;
case VALUE = 1;
}

View File

@ -0,0 +1,15 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Enums;
use PandoraFMS\Modules\Shared\Traits\EnumTrait;
enum EventFilterGroupByEnum: int
{
use EnumTrait;
case ALL = 0;
case EVENTS = 1;
case AGENTS = 2;
case EXTRA_IDS = 3;
}

View File

@ -0,0 +1,17 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Enums;
use PandoraFMS\Modules\Shared\Traits\EnumTrait;
enum EventFilterStatusEnum: int
{
use EnumTrait;
case ALL = -1;
case NEW = 0;
case VALIDATED = 1;
case IN_PROCESS = 2;
case NOT_VALIDATED = 3;
case NOT_IN_PROCESS = 4;
}

View File

@ -0,0 +1,65 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Repositories;
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
use PandoraFMS\Modules\EventFilters\Entities\EventFilterDataMapper;
use PandoraFMS\Modules\EventFilters\Entities\EventFilterFilter;
use PandoraFMS\Modules\Shared\Repositories\Repository;
class EventFilterRepository
{
public function __construct(
private Repository $repository,
private EventFilterDataMapper $eventFilterDataMapper
) {
}
/**
* @return EventFilter[],
*/
public function list(EventFilterFilter $eventFilterFilter): array
{
return $this->repository->__list(
$eventFilterFilter,
$this->eventFilterDataMapper
);
}
public function count(EventFilterFilter $eventFilterFilter): int
{
return $this->repository->__count(
$eventFilterFilter,
$this->eventFilterDataMapper
);
}
public function getOne(EventFilterFilter $eventFilterFilter): EventFilter
{
return $this->repository->__getOne(
$eventFilterFilter,
$this->eventFilterDataMapper
);
}
public function create(EventFilter $eventFilter): EventFilter
{
$id = $this->repository->__create($eventFilter, $this->eventFilterDataMapper);
return $eventFilter->setIdEventFilter($id);
}
public function update(EventFilter $eventFilter): EventFilter
{
return $this->repository->__update(
$eventFilter,
$this->eventFilterDataMapper,
$eventFilter->getIdEventFilter()
);
}
public function delete(int $id): void
{
$this->repository->__delete($id, $this->eventFilterDataMapper);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Services;
use PandoraFMS\Modules\EventFilters\Entities\EventFilterFilter;
use PandoraFMS\Modules\EventFilters\Repositories\EventFilterRepository;
final class CountEventFilterService
{
public function __construct(
private EventFilterRepository $eventFilterRepository,
) {
}
public function __invoke(EventFilterFilter $eventFilterFilter): int
{
return $this->eventFilterRepository->count($eventFilterFilter);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Services;
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
use PandoraFMS\Modules\EventFilters\Repositories\EventFilterRepository;
use PandoraFMS\Modules\EventFilters\Validations\EventFilterValidation;
use PandoraFMS\Modules\Shared\Services\Audit;
final class CreateEventFilterService
{
public function __construct(
private Audit $audit,
private EventFilterRepository $eventFilterRepository,
private EventFilterValidation $eventFilterValidation
) {
}
public function __invoke(EventFilter $eventFilter): EventFilter
{
$this->eventFilterValidation->__invoke($eventFilter);
$eventFilter = $this->eventFilterRepository->create($eventFilter);
$this->audit->write(
AUDIT_LOG_EVENT,
'Create eventFilter '.$eventFilter->getName(),
json_encode($eventFilter->toArray())
);
return $eventFilter;
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Services;
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
use PandoraFMS\Modules\EventFilters\Repositories\EventFilterRepository;
use PandoraFMS\Modules\Shared\Services\Audit;
final class DeleteEventFilterService
{
public function __construct(
private Audit $audit,
private EventFilterRepository $eventFilterRepository,
) {
}
public function __invoke(EventFilter $eventFilter): void
{
$idEventFilter = $eventFilter->getIdEventFilter();
$nameEventFilter = $eventFilter->getName();
$this->eventFilterRepository->delete($idEventFilter);
$this->audit->write(
AUDIT_LOG_EVENT,
'Deleted eventFilter '.$nameEventFilter
);
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Services;
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
use PandoraFMS\Modules\EventFilters\Entities\EventFilterFilter;
use PandoraFMS\Modules\EventFilters\Repositories\EventFilterRepository;
use PandoraFMS\Modules\Shared\Exceptions\NotFoundException;
final class ExistNameEventFilterService
{
public function __construct(
private EventFilterRepository $eventFilterRepository,
) {
}
public function __invoke(string $name): bool
{
$eventFilterFilter = new EventFilterFilter();
/** @var EventFilter $entityFilter */
$entityFilter = $eventFilterFilter->getEntityFilter();
$entityFilter->setName($name);
try {
$this->eventFilterRepository->getOne($eventFilterFilter);
return true;
} catch (NotFoundException) {
return false;
}
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Services;
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
use PandoraFMS\Modules\EventFilters\Entities\EventFilterFilter;
use PandoraFMS\Modules\EventFilters\Repositories\EventFilterRepository;
final class GetEventFilterService
{
public function __construct(
private EventFilterRepository $eventFilterRepository,
) {
}
public function __invoke(int $idEventFilter): EventFilter
{
$eventFilterFilter = new EventFilterFilter();
/** @var EventFilter $entityFilter */
$entityFilter = $eventFilterFilter->getEntityFilter();
$entityFilter->setIdEventFilter($idEventFilter);
return $this->eventFilterRepository->getOne($eventFilterFilter);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Services;
use PandoraFMS\Modules\EventFilters\Entities\EventFilterFilter;
use PandoraFMS\Modules\EventFilters\Repositories\EventFilterRepository;
final class ListEventFilterService
{
public function __construct(
private EventFilterRepository $eventFilterRepository,
) {
}
public function __invoke(EventFilterFilter $eventFilterFilter): array
{
return $this->eventFilterRepository->list($eventFilterFilter);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Services;
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
use PandoraFMS\Modules\EventFilters\Repositories\EventFilterRepository;
use PandoraFMS\Modules\EventFilters\Validations\EventFilterValidation;
use PandoraFMS\Modules\Shared\Services\Audit;
final class UpdateEventFilterService
{
public function __construct(
private Audit $audit,
private EventFilterRepository $eventFilterRepository,
private EventFilterValidation $eventFilterValidation
) {
}
public function __invoke(EventFilter $eventFilter, EventFilter $oldEventFilter): EventFilter
{
$this->eventFilterValidation->__invoke($eventFilter, $oldEventFilter);
$eventFilter = $this->eventFilterRepository->update($eventFilter);
$this->audit->write(
AUDIT_LOG_EVENT,
'Update eventFilter '.$eventFilter->getName(),
json_encode($eventFilter->toArray())
);
return $eventFilter;
}
}

View File

@ -0,0 +1,172 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Validations;
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterAlertEnum;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterGroupByEnum;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterStatusEnum;
use PandoraFMS\Modules\EventFilters\Services\ExistNameEventFilterService;
use PandoraFMS\Modules\Events\Enums\EventSeverityEnum;
use PandoraFMS\Modules\Groups\Services\GetGroupService;
use PandoraFMS\Modules\Shared\Exceptions\BadRequestException;
use PandoraFMS\Modules\Tags\Services\GetTagService;
use PandoraFMS\Modules\Users\Services\GetUserService;
final class EventFilterValidation
{
public function __construct(
private ExistNameEventFilterService $existNameEventFilterService,
private GetUserService $getUserService,
private GetGroupService $getGroupService,
private GetTagService $getTagService
) {
}
public function __invoke(EventFilter $eventFilter, ?EventFilter $oldEventFilter = null): void
{
if (!$eventFilter->getName()) {
throw new BadRequestException(__('Name is missing'));
}
if($oldEventFilter === null || $oldEventFilter->getName() !== $eventFilter->getName()) {
if($this->existNameEventFilterService->__invoke($eventFilter->getName()) === true) {
throw new BadRequestException(
__('Name %s is already exists', $eventFilter->getName())
);
}
}
if ($eventFilter->getIdGroupFilter() === null) {
$eventFilter->setIdGroupFilter(0);
}
if ($eventFilter->getIdGroup() === null) {
$eventFilter->setIdGroup(0);
}
if ($eventFilter->getStatus() === null) {
$eventFilter->setStatus(EventFilterStatusEnum::ALL);
}
if ($eventFilter->getIsNotSearch() === null) {
$eventFilter->setIsNotSearch(false);
}
if ($eventFilter->getPagination() === null) {
$eventFilter->setPagination(0);
}
if ($eventFilter->getSlice() === null) {
$eventFilter->setSlice(0);
}
if ($eventFilter->getGroupBy() === null) {
$eventFilter->setGroupBy(EventFilterGroupByEnum::ALL);
}
if ($eventFilter->getFilterOnlyAlert() === null) {
$eventFilter->setFilterOnlyAlert(EventFilterAlertEnum::ALL);
}
if ($eventFilter->getSearchSecondaryGroups() === null) {
$eventFilter->setSearchSecondaryGroups(false);
}
if ($eventFilter->getSearchRecursiveGroups() === null) {
$eventFilter->setSearchRecursiveGroups(false);
}
if ($eventFilter->getTagWith() === null) {
$eventFilter->setTagWith([]);
}
if ($eventFilter->getTagWithout() === null) {
$eventFilter->setTagWithout([]);
}
if (empty($eventFilter->getIdUserAck()) === false) {
$this->validateUser($eventFilter->getIdUserAck());
}
if (empty($eventFilter->getOwnerUser()) === false) {
$this->validateUser($eventFilter->getOwnerUser());
}
if (empty($eventFilter->getIdGroup()) === false) {
$this->validateGroup($eventFilter->getIdGroup());
}
if (empty($eventFilter->getIdGroupFilter()) === false) {
$this->validateGroup($eventFilter->getIdGroupFilter());
}
if (empty($eventFilter->getTagWith()) === false) {
$this->validateTags($eventFilter->getTagWith());
}
if (empty($eventFilter->getTagWithout()) === false) {
$this->validateTags($eventFilter->getTagWithout());
}
if (empty($eventFilter->getIdAgent()) === false) {
$this->validateAgent($eventFilter->getIdAgent());
}
if (empty($eventFilter->getIdAgentModule()) === false) {
$this->validateAgentModule($eventFilter->getIdAgentModule());
}
if (empty($eventFilter->getServerId()) === false) {
$this->validateNodes($eventFilter->getServerId());
}
if (empty($eventFilter->getSeverity()) === false) {
$this->validateSeverities($eventFilter->getSeverity());
}
}
private function validateUser(string $idUser): void
{
$this->getUserService->__invoke($idUser);
}
protected function validateGroup(int $idGroup): void
{
$this->getGroupService->__invoke($idGroup);
}
protected function validateTags(array $tags): void
{
foreach ($tags as $tag) {
$this->getTagService->__invoke((int) $tag);
}
}
protected function validateAgent(int $idAgent): void
{
// TODO: create new service for this.
}
protected function validateAgentModule(int $idAgentModule): void
{
// TODO: create new service for this.
}
protected function validateNodes(array $nodes): void
{
// TODO: create new service for this.
}
protected function validateSeverities(array $severities): void
{
foreach ($severities as $severity) {
if($severity !== null) {
$result = EventSeverityEnum::get(strtoupper($severity));
if (empty($result) === true) {
throw new BadRequestException(__('Invalid severity: %s', $severity));
}
}
}
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace PandoraFMS\Modules\EventFilters\Validators;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterAlertEnum;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterCustomDataEnum;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterGroupByEnum;
use PandoraFMS\Modules\EventFilters\Enums\EventFilterStatusEnum;
use PandoraFMS\Modules\Events\Enums\EventTypeEnum;
use PandoraFMS\Modules\Shared\Validators\Validator;
class EventFilterValidator extends Validator
{
public const VALIDFILTERALERT = 'ValidFilterAlert';
public const VALIDFILTERCUSTOMDATA = 'ValidFilterCustomData';
public const VALIDFILTERGROUPBY = 'ValidFilterGroupBy';
public const VALIDFILTERSTATUS = 'ValidFilterStatus';
public const VALIDFILTERTYPE = 'ValidFilterType';
protected function isValidFilterAlert($section): bool
{
$result = EventFilterAlertEnum::get(strtoupper($section));
return empty($result) === true ? false : true;
}
protected function isValidFilterCustomData($status): bool
{
$result = EventFilterCustomDataEnum::get(strtoupper($status));
return empty($result) === true ? false : true;
}
protected function isValidFilterGroupBy($type): bool
{
$result = EventFilterGroupByEnum::get(strtoupper($type));
return empty($result) === true ? false : true;
}
protected function isValidFilterStatus($status): bool
{
$result = EventFilterStatusEnum::get(strtoupper($status));
return empty($result) === true ? false : true;
}
protected function isValidFilterType($type): bool
{
$result = EventTypeEnum::get(strtoupper($type));
return empty($result) === true ? false : true;
}
}

View File

@ -0,0 +1,16 @@
<?php
use PandoraFMS\Modules\EventFilters\Controllers\CreateEventFilterController;
use PandoraFMS\Modules\EventFilters\Controllers\DeleteEventFilterController;
use PandoraFMS\Modules\EventFilters\Controllers\GetEventFilterController;
use PandoraFMS\Modules\EventFilters\Controllers\ListEventFilterController;
use PandoraFMS\Modules\EventFilters\Controllers\UpdateEventFilterController;
use Slim\App;
return function (App $app) {
$app->map(['GET', 'POST'], '/eventFilter/list', ListEventFilterController::class);
$app->get('/eventFilter/{idEventFilter}', GetEventFilterController::class);
$app->post('/eventFilter', CreateEventFilterController::class);
$app->put('/eventFilter/{idEventFilter}', UpdateEventFilterController::class);
$app->delete('/eventFilter/{idEventFilter}', DeleteEventFilterController::class);
};

View File

@ -58,7 +58,7 @@ use PandoraFMS\Modules\Shared\Entities\Entity;
* nullable=true,
* default=null,
* description="Event registration date",
* example="2023-21-02 08:34:16",
* example="2023-02-21 08:34:16",
* readOnly=true
* ),
* @OA\Property(
@ -119,7 +119,7 @@ use PandoraFMS\Modules\Shared\Entities\Entity;
* description="Id alert action",
* ),
* @OA\Property(
* property="criticity",
* property="severity",
* type="integer",
* nullable=false,
* enum={
@ -132,7 +132,7 @@ use PandoraFMS\Modules\Shared\Entities\Entity;
* "major"
* },
* default="maintenance",
* description="Event critcity, the available criticity are: maintenance, informational, normal, warning, critical, minor, major"
* description="Event severity, the available severity are: maintenance, informational, normal, warning, critical, minor, major"
* ),
* @OA\Property(
* property="tags",

View File

@ -5,38 +5,7 @@ namespace PandoraFMS\Modules\Events\Entities;
use PandoraFMS\Modules\Events\Validators\EventValidator;
use PandoraFMS\Modules\Shared\Core\FilterAbstract;
/**
* @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;

View File

@ -86,6 +86,7 @@ abstract class DataMapperAbstract
'PandoraFMS\\Modules\\Users\\UserProfiles\\Entities\\UserProfile' => 'UserProfile',
'PandoraFMS\\Modules\\Profiles\\Entities\\Profile' => 'Profile',
'PandoraFMS\\Modules\\Events\\Entities\\Event' => 'Event',
'PandoraFMS\\Modules\\EventFilters\\Entities\\EventFilter' => 'EventFilter',
'PandoraFMS\\Modules\\Groups\\Entities\\Group' => 'Group',
'PandoraFMS\\Modules\\Tags\\Entities\\Tag' => 'Tag',
];

View File

@ -41,6 +41,10 @@ use OpenApi\Annotations as OA;
* description="API Endpoints of events"
* ),
* @OA\Tag(
* name="EventFilters",
* description="API Endpoints of filter events"
* ),
* @OA\Tag(
* name="Groups",
* description="API Endpoints of Groups"
* ),

View File

@ -90,24 +90,22 @@ class Validator
return is_array($arg);
}
public function isDate($date)
{
return $this->isDateTime($date, 'Y-m-d');
}
public function isTime($date)
{
return $this->isDateTime($date, 'H:i:s');
}
public function isDateTime($date, $format = 'Y-m-d H:i:s')
{
$d = \DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
public function isDate($date, $format = 'Y-m-d')
{
$d = \DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
public function isTime($date, $format = 'H:i:s')
{
$d = \DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
public function isTimeZone(string $timeZone): string
{
return array_search($timeZone, timezone_identifiers_list());

View File

@ -90,7 +90,7 @@ use PandoraFMS\Modules\Users\Validators\UserValidator;
* nullable=true,
* default=null,
* description="User registration date",
* example="2023-21-02 08:34:16",
* example="2023-02-21 08:34:16",
* readOnly=true
* ),
* @OA\Property(
@ -240,7 +240,7 @@ use PandoraFMS\Modules\Users\Validators\UserValidator;
* nullable=true,
* default=null,
* description="Date of last password change",
* example="2023-21-02 08:34:16",
* example="2023-02-21 08:34:16",
* readOnly=true
* ),
* @OA\Property(
@ -249,7 +249,7 @@ use PandoraFMS\Modules\Users\Validators\UserValidator;
* nullable=true,
* default=null,
* description="Date of last login failure",
* example="2023-21-02 08:34:16",
* example="2023-02-21 08:34:16",
* readOnly=true
* ),
* @OA\Property(

View File

@ -1350,8 +1350,15 @@ if ($loaded_filter !== false && $from_event_graph != 1 && isset($fb64) === false
$id_user_ack = $filter['id_user_ack'];
$owner_user = $filter['owner_user'];
$group_rep = $filter['group_rep'];
$tag_with = json_decode(io_safe_output($filter['tag_with']));
$tag_without = json_decode(io_safe_output($filter['tag_without']));
$tag_with = [];
if ($filter['tag_with'] !== null) {
$tag_with = json_decode(io_safe_output($filter['tag_with']));
}
$tag_without = [];
if ($filter['tag_with'] !== null) {
$tag_without = json_decode(io_safe_output($filter['tag_without']));
}
$tag_with_base64 = base64_encode(json_encode($tag_with));
$tag_without_base64 = base64_encode(json_encode($tag_without));