Commit Graph

31 Commits

Author SHA1 Message Date
Stéphan Sainléger
c4d7e9b8a9 [IMP] maintenance_service_http_monitoring: auto-close request on service recovery
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 6m50s
Previously, maintenance requests created on HTTP failures were never
automatically resolved. Operators had to close them manually, with no
traceability of when or why the request was closed.

This commit adds automatic resolution when a service returns HTTP 200
while an open maintenance request exists for it.

**Detection logic** (in ``cron_check_http_services``):

Before pass 1, the cron takes a snapshot of all services that currently
have an open (non-done) ``maintenance.request`` via
``http_maintenance_request``. After pass 1, services in that snapshot
that are now OK (``http_status_ok = True``) are identified as recovered
and passed to the new ``_close_http_maintenance_request()`` method.

**Closure logic** (new ``_close_http_maintenance_request`` method):

1. Finds the first ``maintenance.stage`` with ``done = True``.
   If none exists (misconfigured instance), the method is a no-op.
2. Moves the ``maintenance.request`` to that done stage via ``sudo()``
   to bypass ACL restrictions from the cron user context.
3. Posts a chatter note on the request as OdooBot (``base.partner_root``)
   using ``subtype_xmlid="mail.mt_note"`` (internal note, not a follower
   notification) indicating the service URL and that the closure was
   performed automatically by the monitoring cron.
4. Clears ``http_maintenance_request`` on the ``service.instance``,
   allowing a fresh request to be created if the service fails again.

**Tests** (2 new, 16 total):

- ``test_service_recovery_closes_request``: full end-to-end scenario —
  first cron run produces a KO request, second cron run with HTTP 200
  asserts the request is in a done stage, the chatter note mentioning
  the service URL exists, and ``http_maintenance_request`` is cleared.
- ``test_no_close_when_no_open_request``: calling
  ``_close_http_maintenance_request`` on a service with no open request
  is a no-op and does not raise.

**README**: "Automatic Maintenance Requests" section extended with the
recovery behaviour (done stage, OdooBot note, field cleared).
2026-06-15 18:03:31 +02:00
Stéphan Sainléger
c238e54808 [IMP] maintenance_service_http_monitoring: rework maintenance.request creation
Previously, a single ``maintenance.request`` was created per equipment,
regardless of how many services were down on that equipment. The name
was ``[HTTP KO] {equipment.name}`` and deduplication relied on a
name+date+equipment search that was fragile (manual clear of the field
would lose the reference to an existing open request).

This commit reworks the whole creation logic:

- **1 request per KO service** instead of 1 per equipment. Each failing
  ``service.instance`` gets its own ``maintenance.request``, allowing
  fine-grained tracking and independent resolution.

- **Request name** is now ``[HTTP KO] {service_url}``, making it
  immediately identifiable without opening the record.

- **Description** includes the error detail: ``HTTP {status_code}`` for
  HTTP errors, or a human-readable network error label when
  ``last_http_status_code == -1`` (timeout / DNS / SSL failures).

- **Deduplication** is now based solely on whether an open (non-done)
  ``maintenance.request`` already exists on the ``service.instance``
  via the new ``http_maintenance_request`` field. No date boundary —
  as long as the request is open, no new one is created.

- **``http_maintenance_request``** field moved from
  ``maintenance.equipment`` to ``service.instance``, where it belongs
  given the 1-request-per-service model. It is exposed as an optional
  hidden column in the service instance list view.

- ``_build_ko_services_description()`` is removed (no longer needed).

- ``create_http_maintenance_request()`` now receives a single
  ``service.instance`` recordset instead of a list.

Tests updated accordingly (14 tests total):
- Tests 2, 4, 9, 10, 12, 13 now assert on
  ``service_instance.http_maintenance_request``.
- Test 2 also verifies the request name contains the service URL and
  the description contains the HTTP status code.
- New test 14 asserts that two KO services on the same equipment
  produce two distinct requests with the correct names.
2026-06-15 17:47:25 +02:00
Stéphan Sainléger
2724d29f25 [CLN] maintenance_service_http_monitoring: apply ruff 2026-06-15 17:41:48 +02:00
Stéphan Sainléger
b9b8662bad [IMP] maintenance_service_http_monitoring: add double check on HTTP errors
to reduce "noise" from transient HTTP errors
2026-06-15 17:41:48 +02:00
Stéphan Sainléger
cb3ed485b8 [IMP] maintenance_service_http_monitoring: add tests 2026-06-15 15:47:15 +02:00
Stéphan Sainléger
959374f75f [FIX] maintenance_service_http_monitoring: add missing hr_maintenance dependency 2026-06-15 15:46:46 +02:00
Boris Gallet
da0cbab39b [ADD] maintenance_service_http_monitoring: webhook_rocketchat_via_n8n + parameters 2026-03-29 23:44:25 +02:00
Stéphan Sainléger
3bf8ccfb61 [MIG] maintenance_create_requests_from_project_task: Migration to 18.0 2026-03-29 23:44:25 +02:00
Stéphan Sainléger
1f9a0996c0 [MIG] maintenance_service_http_monitoring: Migration to 18.0 2026-03-29 23:44:25 +02:00
Stéphan Sainléger
d0c23d9246 [MIG] maintenance_server_data: Migration to 18.0 2026-03-29 23:44:25 +02:00
Stéphan Sainléger
163abfb23d [MIG] maintenance_project_task_domain: Migration to 18.0 2026-03-17 22:44:23 +01:00
Stéphan Sainléger
a563a9f860 [IMP] maintenance_project_task_domain, maintenance_server_data, maintenance_service_http_monitoring, maintenance_create_requests_from_project_task: pre-commit execution 2026-03-17 22:01:38 +01:00
30a19649d2 [CI] sync config from odoo-elabore-ci 2026-03-10 16:25:38 +00:00
Stéphan Sainléger
51d3d42491 [NEW] maintenance_service_http_monitoring: create add-on
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m33s
2026-02-26 15:49:48 +01:00
Stéphan Sainléger
00a97e876c [IMP] maintenance_server_data: add active field in service.instance model
and make the active field value follow the equipement active field
2026-02-26 15:49:48 +01:00
Stéphan Sainléger
5b0f220834 [IMP] maintenance_server_data: add service.instance views 2026-02-26 15:49:48 +01:00
edeacc4555 [ADD] maintenance_project_task_domain
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m29s
2025-10-21 16:22:39 +02:00
ab57dc9c40 Sync config from odoo-elabore-ci:16.0
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 7m35s
2025-09-17 13:39:43 +00:00
Stéphan Sainléger
d3a9afa8a5 [IMP] maintenance_create_requests_from_project_task: add maintenance_team of the equipment 2025-06-04 15:43:31 +02:00
Stéphan Sainléger
fe6928d7c6 [IMP] maintenance_create_requests_from_project_task: add default domain 2025-06-03 16:20:31 +02:00
Stéphan Sainléger
1e7671c119 [ADD] maintenance_create_requests_from_project_task: create add-on 2025-06-03 16:20:31 +02:00
Boris Gallet
ff75a1b4cd [IMP] add `name_fr` field to maintenance equipment 2025-05-13 17:45:50 +02:00
clementthomas
4373d8a23d [IMP] maintenance_server_monitoring
* add test_ok, test_warning and test_error functions to simplify code
* add ssh_ok test
2024-04-05 12:38:51 +02:00
clementthomas
373c7f406b [IMP] maintenance_server_monitoring:
quick fix
2024-04-03 18:18:20 +02:00
clementthomas
b18940fe56 [IMP] maintenance_server_monitoring:
* add cron
* ssh in other module
* new maintenance request if error
* disk usage test
2024-04-03 18:13:02 +02:00
clementthomas
5f9119c4e8 [IMP] maintenance_server_monitoring:
+Readme
2024-04-02 13:34:52 +02:00
clementthomas
e4d6071e65 [NEW] maintenance_server_monitoring 2024-04-02 13:26:45 +02:00
clementthomas
2e9f01cb0d [MIG] migration of maintenance_server 2024-04-02 13:26:31 +02:00
Stéphan Sainléger
1b9b6d004f [I18N] maintenance_server_data: add french translation 2024-02-13 17:03:17 +01:00
Stéphan Sainléger
eb98973d16 [NEW] maintenance_server_data: create add-on 2024-02-13 17:03:17 +01:00
Stéphan Sainléger
d82e1701f9 Initial commit 2023-04-17 11:58:54 +02:00