[NEW] refactoring of maintenance_server_monitoring in several modules
This commit is contained in:
2
maintenance_server_monitoring_ping/.gitignore
vendored
Normal file
2
maintenance_server_monitoring_ping/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.*~
|
||||
*pyc
|
44
maintenance_server_monitoring_ping/README.rst
Normal file
44
maintenance_server_monitoring_ping/README.rst
Normal file
@@ -0,0 +1,44 @@
|
||||
======================================
|
||||
maintenance_server_monitoring_ping
|
||||
======================================
|
||||
|
||||
Improve monitoring with ping test
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Use Odoo normal module installation procedure to install
|
||||
``maintenance_server_monitoring_ping``.
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
|
||||
None yet.
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `our issues website <https://github.com/elabore-coop/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
|
||||
------------
|
||||
|
||||
* Clément Thomas
|
||||
|
||||
Funders
|
||||
-------
|
||||
|
||||
The development of this module has been financially supported by:
|
||||
* Elabore (https://elabore.coop)
|
||||
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
This module is maintained by Elabore.
|
3
maintenance_server_monitoring_ping/__init__.py
Normal file
3
maintenance_server_monitoring_ping/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
36
maintenance_server_monitoring_ping/__manifest__.py
Normal file
36
maintenance_server_monitoring_ping/__manifest__.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Copyright 2023 Stéphan Sainléger (Elabore)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "maintenance_server_monitoring_ping",
|
||||
"version": "14.0.1.0.0",
|
||||
"author": "Elabore",
|
||||
"website": "https://elabore.coop",
|
||||
"maintainer": "Clément Thomas",
|
||||
"license": "AGPL-3",
|
||||
"category": "Tools",
|
||||
"summary": "Monitor ping on remote hosts",
|
||||
# any module necessary for this one to work correctly
|
||||
"depends": [
|
||||
"maintenance_server_monitoring"
|
||||
],
|
||||
"qweb": [
|
||||
# "static/src/xml/*.xml",
|
||||
],
|
||||
"external_dependencies": {
|
||||
"python": [],
|
||||
},
|
||||
# always loaded
|
||||
"data": [
|
||||
|
||||
],
|
||||
# only loaded in demonstration mode
|
||||
"demo": [],
|
||||
"js": [],
|
||||
"css": [],
|
||||
"installable": True,
|
||||
# Install this module automatically if all dependency have been previously
|
||||
# and independently installed. Used for synergetic or glue modules.
|
||||
"auto_install": False,
|
||||
"application": False,
|
||||
}
|
1
maintenance_server_monitoring_ping/models/__init__.py
Normal file
1
maintenance_server_monitoring_ping/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import maintenance_equipment
|
@@ -0,0 +1,71 @@
|
||||
from odoo import fields, models, api
|
||||
import subprocess
|
||||
|
||||
MAX_PING_MS_WARNING = 1000
|
||||
MAX_PING_MS_ERROR = 5000
|
||||
|
||||
class MaintenanceEquipment(models.Model):
|
||||
_inherit = 'maintenance.equipment'
|
||||
|
||||
ping_ok = fields.Boolean("Ping ok", readonly=True)
|
||||
|
||||
def get_tests(self):
|
||||
res = super(MaintenanceEquipment, self).get_tests()
|
||||
res.append("ping_ok")
|
||||
return res
|
||||
|
||||
def test_ping_ok(self):
|
||||
"""
|
||||
test PING with ping3 library
|
||||
|
||||
Returns:
|
||||
MonitoringTest: representing current test with :
|
||||
* result = False if error
|
||||
* result = True if no error
|
||||
* error defined with MonitoringTest.ERROR or MonitoringTest.WARNING depending on ping time comparaison
|
||||
with MAX_PING_MS_WARNING and MAX_PING_MS_ERROR
|
||||
* log file
|
||||
"""
|
||||
test = self.MonitoringTest("Ping")
|
||||
|
||||
try:
|
||||
from ping3 import ping
|
||||
except ImportError as e:
|
||||
# unable to import ping3
|
||||
try:
|
||||
command = ['pip3','install',"ping3==4.0.5"]
|
||||
response = subprocess.call(command) # run "pip install ping3" command
|
||||
if response != 0:
|
||||
return test.test_error(False, f"ping3 : unable to install : response = {response}")
|
||||
else:
|
||||
from ping3 import ping
|
||||
except Exception as e:
|
||||
return test.test_error(False, f"ping3 : unable to install : {e}")
|
||||
|
||||
hostname = self.server_domain
|
||||
if not hostname:
|
||||
# equipment host name not filled
|
||||
return test.test_error(False, f"host name seems empty !")
|
||||
|
||||
try:
|
||||
r = ping(hostname)
|
||||
except Exception as e:
|
||||
# Any problem when call ping
|
||||
return test.test_error(False, f"unable to call ping ! > {e}")
|
||||
|
||||
if r:
|
||||
test.result = True
|
||||
ping_ms = int(r*1000)
|
||||
if ping_ms < MAX_PING_MS_WARNING:
|
||||
# ping OK
|
||||
return test.test_ok(True, f"PING OK in {ping_ms} ms")
|
||||
elif ping_ms < MAX_PING_MS_ERROR:
|
||||
# ping result between WARNING and ERROR => WARNING
|
||||
return test.test_warning(True, f"PING OK in {ping_ms}ms (> {MAX_PING_MS_WARNING})")
|
||||
else:
|
||||
# ping result higher than ERROR => ERROR
|
||||
return test.test_error(False, f"PING OK in {ping_ms}ms (> {MAX_PING_MS_ERROR})")
|
||||
else:
|
||||
return test.test_error(False, "PING FAILED")
|
||||
|
||||
|
Reference in New Issue
Block a user