tanss: complete sync + db_audit: DB audit log viewer/export #7

Open
hermes wants to merge 3 commits from hermes/odoo-dev:feature/tanss-integration into main
Collaborator

Summary

Two workstreams:

1. TANSS integration (finished)

  • Multi-entity sync: technicians, tickets, devices + Node-RED sync API
  • Odoo 19 fixes: models.Constraint, session dict access, AccessDenied, datetime comparison, password=True removal
  • Full test suite green (79 tests)

2. db_audit (new module)

  • View & export MariaDB/PostgreSQL audit logs inside Odoo
  • Sources (connection + Test Connection), 15-min cron import, CSV export
  • MariaDB general_log/slow_query_log; PG pg_stat_activity + pg_stat_database
  • Incremental dedup (query_id cursor / backend-start first-sight)
  • 13 unit tests (mocked drivers)

Verification

  • Local: 102/102 tests green (forgejo 46 + tanss 79 + db_audit 13)
  • Deployed to 10.98.10.23 (odoo-hermes-app, host :8091), all 3 modules installed, live import against PostgreSQL 18.6 verified (backends + stats deltas), menu + cron present, HTTP 200.
## Summary Two workstreams: ### 1. TANSS integration (finished) - Multi-entity sync: technicians, tickets, devices + Node-RED sync API - Odoo 19 fixes: models.Constraint, session dict access, AccessDenied, datetime comparison, `password=True` removal - Full test suite green (79 tests) ### 2. db_audit (new module) - View & export MariaDB/PostgreSQL audit logs inside Odoo - Sources (connection + Test Connection), 15-min cron import, CSV export - MariaDB general_log/slow_query_log; PG pg_stat_activity + pg_stat_database - Incremental dedup (query_id cursor / backend-start first-sight) - 13 unit tests (mocked drivers) ### Verification - Local: 102/102 tests green (forgejo 46 + tanss 79 + db_audit 13) - Deployed to 10.98.10.23 (odoo-hermes-app, host :8091), all 3 modules installed, live import against PostgreSQL 18.6 verified (backends + stats deltas), menu + cron present, HTTP 200.
Phase 2+ of the TANSS integration, previously uncommitted:
- tanss.device + tanss.ticket models (main-API pull, upsert by stable id)
- technicians pull into res.partner (tanss_technician_id)
- Node-RED sync driver: /api/tanss/servers, /api/tanss/sync/<id>(/status)
- technician session API: /api/tanss/auth + /api/tanss/my-tickets
- internal service user (tanss_service) created at install
- views for tickets, security groups, ticket views

Odoo 19 fixes (verified against live 19.0 source):
- _sql_constraints is dead -> models.Constraint (ticket + device)
- Constraint attribute must start with _ (table_objects assertion)
- Session is __slots__ MutableMapping: item access, .sid, not .session_id
- res.users._login raises AccessDenied (not AccessError) on bad password
- fields.Char(password=) removed in v19
- ticket pull change detection: v19 reads Datetime fields as datetime
  objects, from_unix() returns str -> canonicalize both sides (_dt_cmp)
- register all 8 test files in tests/__init__ (5 were never imported,
  so 56 of 79 tests never ran)

Result: forgejo 46 + tanss 79 = 125 tests, 0 failures.
Docs: TANSS_ENTITY_ANALYSIS.md (entity/transport decision record).
Adds a 'DB Audit Log Viewer' module:
- db_audit.source: one record per external DB (MariaDB/MySQL or
  PostgreSQL), connection settings, Test Connection probe, Import now,
  Purge old events, per-source cron toggle.
- db_audit.event: every imported row (general_log, slow_query_log,
  pg_stat_activity backends, pg_stat_database counter deltas) with
  kind/user/host/statement/duration/rows and a JSON raw payload.
- Incremental import (MySQL query_id cursor; PG first-sight dedup on
  backend start + counter fingerprint) and a 15-minute cron.
- One-click CSV export of the filtered view.
- Optional drivers (pymysql / psycopg2): module loads without them and
  reports the missing driver instead of crashing.
- 13 unit tests (mocked drivers) + run_tests.sh 'dbaudit' target;
  full suite now 102 tests green.

Odoo 19: models.Constraint for the dedupe unique key, <list> views,
context_today()+relativedelta() search filters.
Live testing against MariaDB 10.11 revealed the import only worked for the
MySQL-8 column layout the mocks assumed. Fixes:

- general_log columns differ (MariaDB: event_time/user_host/argument;
  MySQL 8: +schema/query_id/sql_text) -> DESCRIBE + map available columns
- slow log table is slow_log on MariaDB, slow_query_log on MySQL 8 -> probe
  both via _mysql_slow_table (SELECT COUNT)
- timestamp(6) microseconds broke Datetime.to_datetime -> _normalize_ts
- duration: MariaDB time(6) 'H:MM:SS.ffffff' strings -> _mysql_duration
- incremental cursor: query_id (MySQL 8) -> timestamp cursor + content
  fingerprint dedup (works on both, no monotonic id needed)
- probe: read mysql.general_log/slow_log (not {db}.*), try slow_log+slow_query_log

Tests: 13 -> 17 (added MariaDB 10.11 schema suite + duration parsing).
Local 106/106 green; verified live against MariaDB 10.11 and PostgreSQL 18.6.
This pull request has changes conflicting with the target branch.
  • addons/tanss_integration/__manifest__.py
  • addons/tanss_integration/models/tanss_server.py
  • addons/tanss_integration/models/tanss_sync_log.py
  • addons/tanss_integration/tests/__init__.py
  • addons/tanss_integration/tests/common.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u feature/tanss-integration:hermes-feature/tanss-integration
git switch hermes-feature/tanss-integration

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff hermes-feature/tanss-integration
git switch hermes-feature/tanss-integration
git rebase main
git switch main
git merge --ff-only hermes-feature/tanss-integration
git switch hermes-feature/tanss-integration
git rebase main
git switch main
git merge --no-ff hermes-feature/tanss-integration
git switch main
git merge --squash hermes-feature/tanss-integration
git switch main
git merge --ff-only hermes-feature/tanss-integration
git switch main
git merge hermes-feature/tanss-integration
git push origin main
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
shuber/odoo-dev!7
No description provided.