From 375c2879f6f6bf2d249c0534854271c536c89f9d Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 25 Jan 2024 15:44:50 +0100 Subject: [PATCH] new api 2.0 --- pandora_console/api/v1/config/routes.php | 1 + pandora_console/api/v1/public/swagger.json | 628 +++++++++++- .../Actions/CreateEventFilterAction.php | 19 + .../Actions/DeleteEventFilterAction.php | 19 + .../Actions/GetEventFilterAction.php | 19 + .../Actions/ListEventFilterAction.php | 28 + .../Actions/UpdateEventFilterAction.php | 19 + .../CreateEventFilterController.php | 47 + .../DeleteEventFilterController.php | 47 + .../Controllers/GetEventFilterController.php | 44 + .../Controllers/ListEventFilterController.php | 74 ++ .../UpdateEventFilterController.php | 52 + .../EventFilters/Entities/EventFilter.php | 924 ++++++++++++++++++ .../Entities/EventFilterDataMapper.php | 169 ++++ .../Entities/EventFilterFilter.php | 121 +++ .../Enums/EventFilterAlertEnum.php | 14 + .../Enums/EventFilterCustomDataEnum.php | 13 + .../Enums/EventFilterGroupByEnum.php | 15 + .../Enums/EventFilterStatusEnum.php | 17 + .../Repositories/EventFilterRepository.php | 65 ++ .../Services/CountEventFilterService.php | 19 + .../Services/CreateEventFilterService.php | 33 + .../Services/DeleteEventFilterService.php | 29 + .../Services/ExistNameEventFilterService.php | 31 + .../Services/GetEventFilterService.php | 25 + .../Services/ListEventFilterService.php | 19 + .../Services/UpdateEventFilterService.php | 33 + .../Validations/EventFilterValidation.php | 172 ++++ .../Validators/EventFilterValidator.php | 49 + .../lib/Modules/EventFilters/routes.php | 16 + .../lib/Modules/Events/Entities/Event.php | 6 +- .../Modules/Events/Entities/EventFilter.php | 33 +- .../Shared/Core/DataMapperAbstract.php | 1 + .../Modules/Shared/Documentation/OpenApi.php | 4 + .../Modules/Shared/Validators/Validator.php | 22 +- .../lib/Modules/Users/Entities/User.php | 6 +- pandora_console/operation/events/events.php | 11 +- 37 files changed, 2753 insertions(+), 91 deletions(-) create mode 100644 pandora_console/include/lib/Modules/EventFilters/Actions/CreateEventFilterAction.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Actions/DeleteEventFilterAction.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Actions/GetEventFilterAction.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Actions/ListEventFilterAction.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Actions/UpdateEventFilterAction.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Controllers/CreateEventFilterController.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Controllers/DeleteEventFilterController.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Controllers/GetEventFilterController.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Controllers/ListEventFilterController.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Controllers/UpdateEventFilterController.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Entities/EventFilter.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Entities/EventFilterDataMapper.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Entities/EventFilterFilter.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Enums/EventFilterAlertEnum.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Enums/EventFilterCustomDataEnum.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Enums/EventFilterGroupByEnum.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Enums/EventFilterStatusEnum.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Repositories/EventFilterRepository.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Services/CountEventFilterService.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Services/CreateEventFilterService.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Services/DeleteEventFilterService.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Services/ExistNameEventFilterService.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Services/GetEventFilterService.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Services/ListEventFilterService.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Services/UpdateEventFilterService.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Validations/EventFilterValidation.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/Validators/EventFilterValidator.php create mode 100644 pandora_console/include/lib/Modules/EventFilters/routes.php diff --git a/pandora_console/api/v1/config/routes.php b/pandora_console/api/v1/config/routes.php index aa77df22c3..efc139bd40 100644 --- a/pandora_console/api/v1/config/routes.php +++ b/pandora_console/api/v1/config/routes.php @@ -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); diff --git a/pandora_console/api/v1/public/swagger.json b/pandora_console/api/v1/public/swagger.json index fa4b812025..f6b261ac19 100644 --- a/pandora_console/api/v1/public/swagger.json +++ b/pandora_console/api/v1/public/swagger.json @@ -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" diff --git a/pandora_console/include/lib/Modules/EventFilters/Actions/CreateEventFilterAction.php b/pandora_console/include/lib/Modules/EventFilters/Actions/CreateEventFilterAction.php new file mode 100644 index 0000000000..fff7512c68 --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Actions/CreateEventFilterAction.php @@ -0,0 +1,19 @@ +createEventFilterService->__invoke($eventFilter); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Actions/DeleteEventFilterAction.php b/pandora_console/include/lib/Modules/EventFilters/Actions/DeleteEventFilterAction.php new file mode 100644 index 0000000000..e780144694 --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Actions/DeleteEventFilterAction.php @@ -0,0 +1,19 @@ +deleteEventFilterService->__invoke($eventFilter); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Actions/GetEventFilterAction.php b/pandora_console/include/lib/Modules/EventFilters/Actions/GetEventFilterAction.php new file mode 100644 index 0000000000..ec3fe20b59 --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Actions/GetEventFilterAction.php @@ -0,0 +1,19 @@ +getEventFilterService->__invoke($idEventFilter); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Actions/ListEventFilterAction.php b/pandora_console/include/lib/Modules/EventFilters/Actions/ListEventFilterAction.php new file mode 100644 index 0000000000..c7c124239b --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Actions/ListEventFilterAction.php @@ -0,0 +1,28 @@ +getPage(), + $eventFilterFilter->getSizePage(), + $this->countEventFilterService->__invoke($eventFilterFilter), + $this->listEventFilterService->__invoke($eventFilterFilter) + ))->toArray(); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Actions/UpdateEventFilterAction.php b/pandora_console/include/lib/Modules/EventFilters/Actions/UpdateEventFilterAction.php new file mode 100644 index 0000000000..0101c4efbd --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Actions/UpdateEventFilterAction.php @@ -0,0 +1,19 @@ +updateEventFilterService->__invoke($eventFilter, $oldEventFilter); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Controllers/CreateEventFilterController.php b/pandora_console/include/lib/Modules/EventFilters/Controllers/CreateEventFilterController.php new file mode 100644 index 0000000000..4d2b026c7f --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Controllers/CreateEventFilterController.php @@ -0,0 +1,47 @@ +fromRequest($request, EventFilter::class); + + $this->acl->validate(0, 'EW', ' tried to write event'); + + $result = $this->createEventFilterAction->__invoke($eventFilter); + + return $this->getResponse($response, $result); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Controllers/DeleteEventFilterController.php b/pandora_console/include/lib/Modules/EventFilters/Controllers/DeleteEventFilterController.php new file mode 100644 index 0000000000..72fd08f3da --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Controllers/DeleteEventFilterController.php @@ -0,0 +1,47 @@ +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); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Controllers/GetEventFilterController.php b/pandora_console/include/lib/Modules/EventFilters/Controllers/GetEventFilterController.php new file mode 100644 index 0000000000..ed5259e11a --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Controllers/GetEventFilterController.php @@ -0,0 +1,44 @@ +getParam($request, 'idEventFilter'); + + $this->acl->validate(0, 'ER', ' tried to read event'); + + $result = $this->getEventFilterAction->__invoke($idEventFilter); + return $this->getResponse($response, $result); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Controllers/ListEventFilterController.php b/pandora_console/include/lib/Modules/EventFilters/Controllers/ListEventFilterController.php new file mode 100644 index 0000000000..ce593f8289 --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Controllers/ListEventFilterController.php @@ -0,0 +1,74 @@ +fromRequest($request, EventFilterFilter::class); + + $this->acl->validate(0, 'ER', ' tried to read event'); + + $result = $this->listEventFilterAction->__invoke($eventFilterFilter); + return $this->getResponse($response, $result); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Controllers/UpdateEventFilterController.php b/pandora_console/include/lib/Modules/EventFilters/Controllers/UpdateEventFilterController.php new file mode 100644 index 0000000000..6cb88c5199 --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Controllers/UpdateEventFilterController.php @@ -0,0 +1,52 @@ +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); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Entities/EventFilter.php b/pandora_console/include/lib/Modules/EventFilters/Entities/EventFilter.php new file mode 100644 index 0000000000..17ac0e9d0c --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Entities/EventFilter.php @@ -0,0 +1,924 @@ + 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; + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Entities/EventFilterDataMapper.php b/pandora_console/include/lib/Modules/EventFilters/Entities/EventFilterDataMapper.php new file mode 100644 index 0000000000..e786a8f94b --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Entities/EventFilterDataMapper.php @@ -0,0 +1,169 @@ +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()), + ]; + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Entities/EventFilterFilter.php b/pandora_console/include/lib/Modules/EventFilters/Entities/EventFilterFilter.php new file mode 100644 index 0000000000..4279dc6b6a --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Entities/EventFilterFilter.php @@ -0,0 +1,121 @@ +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]; + } + +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Enums/EventFilterAlertEnum.php b/pandora_console/include/lib/Modules/EventFilters/Enums/EventFilterAlertEnum.php new file mode 100644 index 0000000000..0d2611b86d --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Enums/EventFilterAlertEnum.php @@ -0,0 +1,14 @@ +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); + } + +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Services/CountEventFilterService.php b/pandora_console/include/lib/Modules/EventFilters/Services/CountEventFilterService.php new file mode 100644 index 0000000000..3dba3799cb --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Services/CountEventFilterService.php @@ -0,0 +1,19 @@ +eventFilterRepository->count($eventFilterFilter); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Services/CreateEventFilterService.php b/pandora_console/include/lib/Modules/EventFilters/Services/CreateEventFilterService.php new file mode 100644 index 0000000000..41b958c785 --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Services/CreateEventFilterService.php @@ -0,0 +1,33 @@ +eventFilterValidation->__invoke($eventFilter); + + $eventFilter = $this->eventFilterRepository->create($eventFilter); + + $this->audit->write( + AUDIT_LOG_EVENT, + 'Create eventFilter '.$eventFilter->getName(), + json_encode($eventFilter->toArray()) + ); + + return $eventFilter; + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Services/DeleteEventFilterService.php b/pandora_console/include/lib/Modules/EventFilters/Services/DeleteEventFilterService.php new file mode 100644 index 0000000000..489b0a4ccd --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Services/DeleteEventFilterService.php @@ -0,0 +1,29 @@ +getIdEventFilter(); + $nameEventFilter = $eventFilter->getName(); + $this->eventFilterRepository->delete($idEventFilter); + + $this->audit->write( + AUDIT_LOG_EVENT, + 'Deleted eventFilter '.$nameEventFilter + ); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Services/ExistNameEventFilterService.php b/pandora_console/include/lib/Modules/EventFilters/Services/ExistNameEventFilterService.php new file mode 100644 index 0000000000..0c94777a8b --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Services/ExistNameEventFilterService.php @@ -0,0 +1,31 @@ +getEntityFilter(); + $entityFilter->setName($name); + + try { + $this->eventFilterRepository->getOne($eventFilterFilter); + return true; + } catch (NotFoundException) { + return false; + } + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Services/GetEventFilterService.php b/pandora_console/include/lib/Modules/EventFilters/Services/GetEventFilterService.php new file mode 100644 index 0000000000..115388efcc --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Services/GetEventFilterService.php @@ -0,0 +1,25 @@ +getEntityFilter(); + $entityFilter->setIdEventFilter($idEventFilter); + + return $this->eventFilterRepository->getOne($eventFilterFilter); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Services/ListEventFilterService.php b/pandora_console/include/lib/Modules/EventFilters/Services/ListEventFilterService.php new file mode 100644 index 0000000000..d9b8aacf0e --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Services/ListEventFilterService.php @@ -0,0 +1,19 @@ +eventFilterRepository->list($eventFilterFilter); + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Services/UpdateEventFilterService.php b/pandora_console/include/lib/Modules/EventFilters/Services/UpdateEventFilterService.php new file mode 100644 index 0000000000..1c38442bc3 --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Services/UpdateEventFilterService.php @@ -0,0 +1,33 @@ +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; + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Validations/EventFilterValidation.php b/pandora_console/include/lib/Modules/EventFilters/Validations/EventFilterValidation.php new file mode 100644 index 0000000000..17661cd9b6 --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Validations/EventFilterValidation.php @@ -0,0 +1,172 @@ +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)); + } + } + } + } +} diff --git a/pandora_console/include/lib/Modules/EventFilters/Validators/EventFilterValidator.php b/pandora_console/include/lib/Modules/EventFilters/Validators/EventFilterValidator.php new file mode 100644 index 0000000000..902fc81d48 --- /dev/null +++ b/pandora_console/include/lib/Modules/EventFilters/Validators/EventFilterValidator.php @@ -0,0 +1,49 @@ +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); +}; diff --git a/pandora_console/include/lib/Modules/Events/Entities/Event.php b/pandora_console/include/lib/Modules/Events/Entities/Event.php index ec363179d6..b7133124fe 100644 --- a/pandora_console/include/lib/Modules/Events/Entities/Event.php +++ b/pandora_console/include/lib/Modules/Events/Entities/Event.php @@ -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", diff --git a/pandora_console/include/lib/Modules/Events/Entities/EventFilter.php b/pandora_console/include/lib/Modules/Events/Entities/EventFilter.php index 63417a695d..c7e9dc877e 100644 --- a/pandora_console/include/lib/Modules/Events/Entities/EventFilter.php +++ b/pandora_console/include/lib/Modules/Events/Entities/EventFilter.php @@ -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; diff --git a/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php b/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php index cf06d654f7..d91207c74c 100644 --- a/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php +++ b/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php @@ -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', ]; diff --git a/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php b/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php index 89f6b1bef5..d9ad47d8ed 100644 --- a/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php +++ b/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php @@ -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" * ), diff --git a/pandora_console/include/lib/Modules/Shared/Validators/Validator.php b/pandora_console/include/lib/Modules/Shared/Validators/Validator.php index af20885676..5600342275 100644 --- a/pandora_console/include/lib/Modules/Shared/Validators/Validator.php +++ b/pandora_console/include/lib/Modules/Shared/Validators/Validator.php @@ -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()); diff --git a/pandora_console/include/lib/Modules/Users/Entities/User.php b/pandora_console/include/lib/Modules/Users/Entities/User.php index 6e1fe22893..99fe282f7d 100644 --- a/pandora_console/include/lib/Modules/Users/Entities/User.php +++ b/pandora_console/include/lib/Modules/Users/Entities/User.php @@ -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( diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 31d4336928..6a7286e302 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -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));