Compare commits
5 Commits
c4d7e9b8a9
...
update-ser
| Author | SHA1 | Date | |
|---|---|---|---|
| e48a3443f1 | |||
|
|
6e19575012 | ||
|
|
ae5977ef81 | ||
|
|
4581b3d019 | ||
|
|
bb6f12945f |
@@ -4,7 +4,14 @@ from odoo import api, fields, models
|
||||
class MaintenanceEquipment(models.Model):
|
||||
_inherit = "maintenance.equipment"
|
||||
|
||||
_sql_constraints = [
|
||||
('unique_name', 'UNIQUE(name)', 'Name must be unique.'),
|
||||
('unique_server_ip', 'UNIQUE(server_ip)', 'Server IP must be unique.'),
|
||||
('unique_ssh_target', 'UNIQUE(ssh_target)', 'Main Domain Name must be unique.'),
|
||||
]
|
||||
|
||||
server_ip = fields.Char("Server Ip Address")
|
||||
ssh_target = fields.Char("SSH Target", )
|
||||
distribution_id = fields.Many2one("os.distribution", string="Distribution")
|
||||
service_ids = fields.One2many("service.instance", "equipment_id", string="Services")
|
||||
hosting_city = fields.Char("Hosting City")
|
||||
@@ -17,8 +24,24 @@ class MaintenanceEquipment(models.Model):
|
||||
|
||||
name_fr = fields.Char("Name (FR)", compute="_compute_name_fr", store=True)
|
||||
|
||||
def copy_data(self, default=None):
|
||||
default = dict(default or {})
|
||||
if "server_ip" not in default:
|
||||
default["server_ip"] = False
|
||||
if "ssh_target" not in default:
|
||||
default["ssh_target"] = False
|
||||
vals_list = super().copy_data(default=default)
|
||||
if "name" not in default:
|
||||
for equipment, vals in zip(self, vals_list):
|
||||
vals["name"] = self.env._("%s (copy)", equipment.name)
|
||||
return vals_list
|
||||
|
||||
@api.depends("name")
|
||||
def _compute_name_fr(self):
|
||||
if not self.env["res.lang"]._lang_get("fr_FR"):
|
||||
for record in self:
|
||||
record.name_fr = record.name
|
||||
return
|
||||
for record in self:
|
||||
record.name_fr = record.with_context(lang="fr_FR").name
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<xpath expr="//field[@name='effective_date']/.." position="after">
|
||||
<group name="server_data" string="Server data">
|
||||
<field name="server_ip" />
|
||||
<field name="ssh_target" />
|
||||
<field name="hosting_city" />
|
||||
<field name="distribution_id" />
|
||||
<field name="nb_cores" />
|
||||
@@ -45,6 +46,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='category_id']" position="after">
|
||||
<field name="server_ip" optional="hide" />
|
||||
<field name="ssh_target" optional="hide" />
|
||||
<field name="hosting_city" optional="hide" />
|
||||
<field name="distribution_id" optional="hide" />
|
||||
<field name="nb_cores" optional="hide" />
|
||||
|
||||
2
maintenance_service_http_monitoring/.gitignore
vendored
Normal file
2
maintenance_service_http_monitoring/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.*~
|
||||
*pyc
|
||||
@@ -5,7 +5,7 @@
|
||||
"license": "AGPL-3",
|
||||
"category": "Tools",
|
||||
"summary": "Monitor HTTP availability of services",
|
||||
"depends": ["base", "maintenance", "hr_maintenance", "maintenance_server_data"],
|
||||
"depends": ["base", "maintenance", "base_maintenance", "hr_maintenance", "maintenance_server_data"],
|
||||
"external_dependencies": {"python": ["requests"]},
|
||||
"data": [
|
||||
"data/ir_config_parameter.xml",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<field name="model_id" ref="maintenance_server_data.model_service_instance" />
|
||||
<field name="state">code</field>
|
||||
<field name="code">model.cron_check_http_services()</field>
|
||||
<field name="interval_number">15</field>
|
||||
<field name="interval_number">10</field>
|
||||
<field name="interval_type">minutes</field>
|
||||
</record>
|
||||
<record id="ir_cron_maintenance_mode_expiry" model="ir.cron">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import logging
|
||||
import time
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
@@ -10,8 +10,8 @@ except ImportError:
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
HTTP_CHECK_TIMEOUT = 10 # seconds
|
||||
HTTP_RETRY_DELAY = 2 # seconds between pass 1 and pass 2
|
||||
HTTP_CHECK_TIMEOUT = 20 # seconds
|
||||
HTTP_KO_CONFIRMATION_DELAY = timedelta(minutes=5)
|
||||
|
||||
|
||||
class ServiceInstance(models.Model):
|
||||
@@ -36,14 +36,20 @@ class ServiceInstance(models.Model):
|
||||
string="HTTP Maintenance Request",
|
||||
readonly=True,
|
||||
)
|
||||
http_first_ko_at = fields.Datetime(
|
||||
string="First HTTP KO Check (current streak)",
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
def check_http_status(self):
|
||||
"""
|
||||
Perform HTTP check for each record and return the KO recordset.
|
||||
|
||||
Writes last_http_status_code, last_http_check_date and http_status_ok on every
|
||||
checked record. Does NOT create maintenance.request — that decision belongs to
|
||||
the caller (cron) after optional retry logic.
|
||||
checked record. Does NOT create maintenance.request — the cron only opens one
|
||||
once the service has been continuously KO for at least
|
||||
HTTP_KO_CONFIRMATION_DELAY, to avoid flagging transient outages (e.g. a short
|
||||
server overload) as real incidents.
|
||||
"""
|
||||
ko_records = self.browse()
|
||||
for rec in self:
|
||||
@@ -63,13 +69,16 @@ class ServiceInstance(models.Model):
|
||||
status_ok = status_code == 200
|
||||
except requests.exceptions.RequestException as e:
|
||||
_logger.warning("HTTP check failed for %s: %s", rec.service_url, e)
|
||||
rec.write(
|
||||
{
|
||||
"last_http_status_code": status_code,
|
||||
"last_http_check_date": now,
|
||||
"http_status_ok": status_ok,
|
||||
}
|
||||
)
|
||||
vals = {
|
||||
"last_http_status_code": status_code,
|
||||
"last_http_check_date": now,
|
||||
"http_status_ok": status_ok,
|
||||
}
|
||||
if status_ok:
|
||||
vals["http_first_ko_at"] = False
|
||||
elif not rec.http_first_ko_at:
|
||||
vals["http_first_ko_at"] = now
|
||||
rec.write(vals)
|
||||
if not status_ok:
|
||||
ko_records |= rec
|
||||
return ko_records
|
||||
@@ -106,13 +115,12 @@ class ServiceInstance(models.Model):
|
||||
@api.model
|
||||
def cron_check_http_services(self):
|
||||
"""
|
||||
Check all active services with a URL, with one retry on failure.
|
||||
Check all active services with a URL.
|
||||
|
||||
Pass 1: test every eligible service.
|
||||
- Services that had an open request and are now OK are auto-resolved.
|
||||
- Services still KO after pass 1 are retested after HTTP_RETRY_DELAY seconds.
|
||||
maintenance.request is created only for services that fail both passes,
|
||||
reducing noise from transient HTTP errors.
|
||||
A service must be continuously KO for at least HTTP_KO_CONFIRMATION_DELAY
|
||||
before a maintenance.request is created — this tolerates transient outages
|
||||
(e.g. a temporary server overload) regardless of how often this cron runs.
|
||||
Services that had an open request and are now OK are auto-resolved.
|
||||
"""
|
||||
domain = [
|
||||
("active", "=", True),
|
||||
@@ -123,25 +131,22 @@ class ServiceInstance(models.Model):
|
||||
lambda s: not s.equipment_id.maintenance_mode
|
||||
)
|
||||
|
||||
# Snapshot services that currently have an open request before pass 1
|
||||
# Snapshot services that currently have an open request before the check
|
||||
services_with_open_request = services.filtered(
|
||||
lambda s: s.http_maintenance_request
|
||||
and not s.http_maintenance_request.stage_id.done
|
||||
)
|
||||
|
||||
ko_after_pass1 = services.check_http_status()
|
||||
ko_services = services.check_http_status()
|
||||
|
||||
# Auto-resolve services that recovered during pass 1
|
||||
# Auto-resolve services that recovered
|
||||
recovered = services_with_open_request.filtered(lambda s: s.http_status_ok)
|
||||
if recovered:
|
||||
recovered._close_http_maintenance_request()
|
||||
|
||||
if not ko_after_pass1:
|
||||
return
|
||||
|
||||
time.sleep(HTTP_RETRY_DELAY)
|
||||
|
||||
ko_confirmed = ko_after_pass1.check_http_status()
|
||||
|
||||
for service in ko_confirmed:
|
||||
confirmed_ko = ko_services.filtered(
|
||||
lambda s: s.last_http_check_date - s.http_first_ko_at
|
||||
>= HTTP_KO_CONFIRMATION_DELAY
|
||||
)
|
||||
for service in confirmed_ko:
|
||||
service.equipment_id.create_http_maintenance_request(service)
|
||||
|
||||
@@ -11,9 +11,9 @@ EQUIPMENT_HTTP_REQUESTS = (
|
||||
"odoo.addons.maintenance_service_http_monitoring"
|
||||
".models.maintenance_equipment.http_requests"
|
||||
)
|
||||
SERVICE_INSTANCE_SLEEP = (
|
||||
"odoo.addons.maintenance_service_http_monitoring.models.service_instance.time.sleep"
|
||||
)
|
||||
|
||||
# Comfortably past HTTP_KO_CONFIRMATION_DELAY (currently 10 minutes).
|
||||
PAST_CONFIRMATION_DELAY = timedelta(minutes=20)
|
||||
|
||||
|
||||
def _mock_response(status_code):
|
||||
@@ -41,6 +41,13 @@ class TestHttpMonitoring(TransactionCase):
|
||||
}
|
||||
)
|
||||
|
||||
def _backdate_first_ko(self, *service_instances):
|
||||
"""Simulate that the current KO streak started long enough ago to be confirmed."""
|
||||
for service_instance in service_instances:
|
||||
service_instance.write(
|
||||
{"http_first_ko_at": fields.Datetime.now() - PAST_CONFIRMATION_DELAY}
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 1 -- HTTP 200 -> service marked OK
|
||||
# ------------------------------------------------------------------
|
||||
@@ -55,19 +62,26 @@ class TestHttpMonitoring(TransactionCase):
|
||||
self.assertIsNotNone(self.service_instance.last_http_check_date)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 2 -- Two KO passes -> maintenance.request created on the service
|
||||
# Test 2 -- KO confirmed only once continuously KO for HTTP_KO_CONFIRMATION_DELAY,
|
||||
# not on the first observed failure
|
||||
# ------------------------------------------------------------------
|
||||
def test_http_500_creates_maintenance_request(self):
|
||||
with (
|
||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
||||
patch(SERVICE_INSTANCE_SLEEP),
|
||||
):
|
||||
def test_http_500_creates_request_after_confirmation_delay(self):
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
|
||||
self.assertFalse(self.service_instance.http_status_ok)
|
||||
self.assertEqual(self.service_instance.last_http_status_code, 500)
|
||||
self.assertTrue(self.service_instance.http_first_ko_at)
|
||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
||||
|
||||
self._backdate_first_ko(self.service_instance)
|
||||
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
|
||||
request = self.service_instance.http_maintenance_request
|
||||
self.assertTrue(request)
|
||||
@@ -90,27 +104,29 @@ class TestHttpMonitoring(TransactionCase):
|
||||
self.assertEqual(self.service_instance.last_http_status_code, -1)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 4 -- Two consecutive cron runs KO -> no duplicate request
|
||||
# Test 4 -- Repeated failure after confirmation -> a single request, no duplicate
|
||||
# ------------------------------------------------------------------
|
||||
def test_no_duplicate_request_on_repeated_failure(self):
|
||||
with (
|
||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
||||
patch(SERVICE_INSTANCE_SLEEP),
|
||||
):
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
self.env["service.instance"].cron_check_http_services() # first_ko_at set
|
||||
|
||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
||||
self._backdate_first_ko(self.service_instance)
|
||||
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services() # confirmed, request created
|
||||
|
||||
request_1 = self.service_instance.http_maintenance_request
|
||||
self.assertTrue(request_1)
|
||||
|
||||
with (
|
||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
||||
patch(SERVICE_INSTANCE_SLEEP),
|
||||
):
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
self.env["service.instance"].cron_check_http_services() # still KO
|
||||
|
||||
self.assertEqual(self.service_instance.http_maintenance_request, request_1)
|
||||
self.assertEqual(
|
||||
@@ -181,7 +197,8 @@ class TestHttpMonitoring(TransactionCase):
|
||||
self.assertEqual(self.service_instance.last_http_status_code, 404)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 9 -- Webhook called when a new maintenance.request is created
|
||||
# Test 9 -- Webhook called only once the request is actually created
|
||||
# (after confirmation delay), not on the first observed failure
|
||||
# ------------------------------------------------------------------
|
||||
def test_webhook_called_on_new_request(self):
|
||||
self.env["ir.config_parameter"].sudo().set_param(
|
||||
@@ -190,7 +207,17 @@ class TestHttpMonitoring(TransactionCase):
|
||||
)
|
||||
with (
|
||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
||||
patch(SERVICE_INSTANCE_SLEEP),
|
||||
patch(EQUIPMENT_HTTP_REQUESTS) as mock_http,
|
||||
):
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
|
||||
mock_http.post.assert_not_called()
|
||||
self._backdate_first_ko(self.service_instance)
|
||||
|
||||
with (
|
||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
||||
patch(EQUIPMENT_HTTP_REQUESTS) as mock_http,
|
||||
):
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
@@ -209,15 +236,22 @@ class TestHttpMonitoring(TransactionCase):
|
||||
self.env["ir.config_parameter"].sudo().set_param(
|
||||
"maintenance_service_http_monitoring.webhook_url", ""
|
||||
)
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
|
||||
self._backdate_first_ko(self.service_instance)
|
||||
|
||||
with (
|
||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
||||
patch(SERVICE_INSTANCE_SLEEP),
|
||||
patch(EQUIPMENT_HTTP_REQUESTS) as mock_http,
|
||||
):
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
|
||||
self.assertTrue(self.service_instance.http_maintenance_request)
|
||||
mock_http.post.assert_not_called()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
@@ -235,22 +269,25 @@ class TestHttpMonitoring(TransactionCase):
|
||||
self.assertFalse(self.service_instance.last_http_check_date)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 12 -- Transient failure (KO pass 1, OK pass 2) -> no request created
|
||||
# Test 12 -- Transient failure (KO, then back OK before confirmation) ->
|
||||
# no request created, and the KO streak is reset
|
||||
# ------------------------------------------------------------------
|
||||
def test_transient_failure_no_request_created(self):
|
||||
with (
|
||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
||||
patch(SERVICE_INSTANCE_SLEEP),
|
||||
):
|
||||
mock_requests.get.side_effect = [
|
||||
_mock_response(500), # pass 1: KO
|
||||
_mock_response(200), # pass 2 (retry): OK
|
||||
]
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
|
||||
self.assertTrue(self.service_instance.http_first_ko_at)
|
||||
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(200)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
|
||||
self.assertTrue(self.service_instance.http_status_ok)
|
||||
self.assertEqual(self.service_instance.last_http_status_code, 200)
|
||||
self.assertFalse(self.service_instance.http_first_ko_at)
|
||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
||||
self.assertEqual(
|
||||
self.env["maintenance.request"].search_count(
|
||||
@@ -260,25 +297,33 @@ class TestHttpMonitoring(TransactionCase):
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 13 -- Confirmed failure (KO pass 1 and 2) -> request created
|
||||
# Test 13 -- Confirmed failure (KO continuously past the confirmation delay)
|
||||
# -> request created
|
||||
# ------------------------------------------------------------------
|
||||
def test_confirmed_failure_creates_request(self):
|
||||
with (
|
||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
||||
patch(SERVICE_INSTANCE_SLEEP) as mock_sleep,
|
||||
):
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(503)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
|
||||
mock_sleep.assert_called_once_with(2)
|
||||
self.assertEqual(mock_requests.get.call_count, 2)
|
||||
self.assertEqual(mock_requests.get.call_count, 1)
|
||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
||||
|
||||
self._backdate_first_ko(self.service_instance)
|
||||
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(503)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
|
||||
self.assertEqual(mock_requests.get.call_count, 1)
|
||||
self.assertFalse(self.service_instance.http_status_ok)
|
||||
self.assertEqual(self.service_instance.last_http_status_code, 503)
|
||||
self.assertTrue(self.service_instance.http_maintenance_request)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 14 -- 2 KO services on same equipment -> 2 distinct requests
|
||||
# once both reach the confirmation delay
|
||||
# ------------------------------------------------------------------
|
||||
def test_two_ko_services_same_equipment_create_two_requests(self):
|
||||
service2 = self.env["service"].create({"name": "Test Service 2"})
|
||||
@@ -290,10 +335,14 @@ class TestHttpMonitoring(TransactionCase):
|
||||
}
|
||||
)
|
||||
|
||||
with (
|
||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
||||
patch(SERVICE_INSTANCE_SLEEP),
|
||||
):
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
|
||||
self._backdate_first_ko(self.service_instance, service_instance2)
|
||||
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
@@ -317,11 +366,16 @@ class TestHttpMonitoring(TransactionCase):
|
||||
# Test 15 -- Service recovery closes the open request and posts a note
|
||||
# ------------------------------------------------------------------
|
||||
def test_service_recovery_closes_request(self):
|
||||
# First cron run: service is KO -> request created
|
||||
with (
|
||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
||||
patch(SERVICE_INSTANCE_SLEEP),
|
||||
):
|
||||
# First cron run: service is KO, streak just started -> no request yet
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
|
||||
self._backdate_first_ko(self.service_instance)
|
||||
|
||||
# Second cron run: streak confirmed -> request created
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(500)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
@@ -330,11 +384,8 @@ class TestHttpMonitoring(TransactionCase):
|
||||
self.assertTrue(request)
|
||||
self.assertFalse(request.stage_id.done)
|
||||
|
||||
# Second cron run: service is back OK -> request auto-closed
|
||||
with (
|
||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
||||
patch(SERVICE_INSTANCE_SLEEP),
|
||||
):
|
||||
# Next cron run: service is back OK -> request auto-closed
|
||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
||||
mock_requests.get.return_value = _mock_response(200)
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
self.env["service.instance"].cron_check_http_services()
|
||||
@@ -343,6 +394,8 @@ class TestHttpMonitoring(TransactionCase):
|
||||
self.assertTrue(request.stage_id.done)
|
||||
# http_maintenance_request must be cleared on the service instance
|
||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
||||
# KO streak must be reset
|
||||
self.assertFalse(self.service_instance.http_first_ko_at)
|
||||
# A chatter note must have been posted mentioning the service URL
|
||||
notes = request.message_ids.filtered(
|
||||
lambda m: self.service_instance.service_url in (m.body or "")
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<field name="last_http_status_code" />
|
||||
<field name="http_status_ok" />
|
||||
<field name="http_maintenance_request" optional="hide" />
|
||||
<field name="http_first_ko_at" optional="hide" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
2
maintenance_user_ssh_key/.gitignore
vendored
Normal file
2
maintenance_user_ssh_key/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.*~
|
||||
*pyc
|
||||
63
maintenance_user_ssh_key/README.md
Normal file
63
maintenance_user_ssh_key/README.md
Normal file
@@ -0,0 +1,63 @@
|
||||
==============================
|
||||
maintenance_user_ssh_key
|
||||
==============================
|
||||
|
||||
This module adds SSH key management to Odoo users. It introduces a new
|
||||
``ssh.key`` model and a ``ssh_key_ids`` One2many field on ``res.users``.
|
||||
|
||||
It allows administrators to associate SSH public keys with each user for
|
||||
authentication purposes (e.g., remote server access, deployment).
|
||||
|
||||
Features:
|
||||
|
||||
- **SSH Key model**: Store public keys per user.
|
||||
- **User integration**: SSH keys are displayed and editable directly on the
|
||||
user form view.
|
||||
- **Access control**: All internal users can view SSH keys; only users with
|
||||
``Settings / Administration`` rights can create, edit, or delete them.
|
||||
|
||||
# Installation
|
||||
|
||||
Use Odoo normal module installation procedure to install
|
||||
``maintenance_user_ssh_key``.
|
||||
|
||||
This module depends on ``base`` and requires no external Python dependencies.
|
||||
|
||||
# Configuration
|
||||
|
||||
No specific configuration is required. After installation:
|
||||
|
||||
1. Go to *Settings > Users & Companies > Users*.
|
||||
2. Open any user and navigate to the **SSH Keys** notebook page.
|
||||
3. Add SSH keys with the public key content.
|
||||
|
||||
# Usage
|
||||
|
||||
## Managing SSH Keys
|
||||
|
||||
- Open a user form and go to the *SSH Keys* tab.
|
||||
- Click **Add a line** and paste the public key content.
|
||||
|
||||
# Bug Tracker
|
||||
|
||||
Bugs are tracked on
|
||||
`our issues website <https://git.elabore.coop/Elabore/maintenance-tools/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and
|
||||
welcomed feedback.
|
||||
|
||||
# Credits
|
||||
|
||||
## Contributors
|
||||
|
||||
- Stéphan Sainléger
|
||||
|
||||
## Funders
|
||||
|
||||
The development of this module has been financially supported by:
|
||||
|
||||
- Elabore (https://elabore.coop)
|
||||
|
||||
## Maintainer
|
||||
|
||||
This module is maintained by Elabore.
|
||||
1
maintenance_user_ssh_key/__init__.py
Normal file
1
maintenance_user_ssh_key/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
22
maintenance_user_ssh_key/__manifest__.py
Normal file
22
maintenance_user_ssh_key/__manifest__.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Copyright 2026 Stéphan Sainléger (Elabore)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "maintenance_user_ssh_key",
|
||||
"version": "18.0.1.0.0",
|
||||
"author": "Elabore",
|
||||
"website": "https://git.elabore.coop/elabore/maintenance-tools",
|
||||
"maintainer": "Stéphan Sainléger",
|
||||
"license": "AGPL-3",
|
||||
"category": "Tools",
|
||||
"summary": "Manage SSH keys per user.",
|
||||
"depends": ["base"],
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"views/ssh_key_views.xml",
|
||||
"views/res_users_views.xml",
|
||||
],
|
||||
"installable": True,
|
||||
"auto_install": False,
|
||||
"application": False,
|
||||
}
|
||||
2
maintenance_user_ssh_key/models/__init__.py
Normal file
2
maintenance_user_ssh_key/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import ssh_key
|
||||
from . import res_users
|
||||
14
maintenance_user_ssh_key/models/res_users.py
Normal file
14
maintenance_user_ssh_key/models/res_users.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Copyright 2026 Stéphan Sainléger (Elabore)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
_inherit = "res.users"
|
||||
|
||||
ssh_key_ids = fields.One2many(
|
||||
comodel_name="ssh.key",
|
||||
inverse_name="user_id",
|
||||
string="SSH Keys",
|
||||
)
|
||||
18
maintenance_user_ssh_key/models/ssh_key.py
Normal file
18
maintenance_user_ssh_key/models/ssh_key.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Copyright 2026 Stéphan Sainléger (Elabore)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class SshKey(models.Model):
|
||||
_name = "ssh.key"
|
||||
_description = "SSH Key"
|
||||
|
||||
key = fields.Text(string="Public Key", required=True)
|
||||
user_id = fields.Many2one(
|
||||
comodel_name="res.users",
|
||||
string="User",
|
||||
required=True,
|
||||
ondelete="cascade",
|
||||
index=True,
|
||||
)
|
||||
3
maintenance_user_ssh_key/security/ir.model.access.csv
Normal file
3
maintenance_user_ssh_key/security/ir.model.access.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_ssh_key_user,ssh.key.user,model_ssh_key,base.group_user,1,0,0,0
|
||||
access_ssh_key_manager,ssh.key.manager,model_ssh_key,base.group_system,1,1,1,1
|
||||
|
21
maintenance_user_ssh_key/views/res_users_views.xml
Normal file
21
maintenance_user_ssh_key/views/res_users_views.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_users_form_ssh_key_inherit" model="ir.ui.view">
|
||||
<field name="name">res.users.form.ssh.key</field>
|
||||
<field name="model">res.users</field>
|
||||
<field name="inherit_id" ref="base.view_users_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//notebook" position="inside">
|
||||
<page string="SSH Keys" name="ssh_keys">
|
||||
<field name="ssh_key_ids">
|
||||
<list editable="top">
|
||||
<field name="key"/>
|
||||
</list>
|
||||
</field>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
44
maintenance_user_ssh_key/views/ssh_key_views.xml
Normal file
44
maintenance_user_ssh_key/views/ssh_key_views.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="ssh_key_view_tree" model="ir.ui.view">
|
||||
<field name="name">ssh.key.tree</field>
|
||||
<field name="model">ssh.key</field>
|
||||
<field name="arch" type="xml">
|
||||
<list editable="top">
|
||||
<field name="key"/>
|
||||
<field name="user_id"/>
|
||||
</list>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="ssh_key_view_form" model="ir.ui.view">
|
||||
<field name="name">ssh.key.form</field>
|
||||
<field name="model">ssh.key</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="user_id"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="key" nolabel="1"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="ssh_key_action" model="ir.actions.act_window">
|
||||
<field name="name">SSH Keys</field>
|
||||
<field name="res_model">ssh.key</field>
|
||||
<field name="view_mode">list,form</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
id="menu_ssh_key"
|
||||
action="ssh_key_action"
|
||||
parent="base.menu_security"
|
||||
sequence="50"/>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user