diff --git a/maintenance_server_monitoring/.gitignore b/maintenance_server_monitoring/.gitignore new file mode 100644 index 0000000..6da5887 --- /dev/null +++ b/maintenance_server_monitoring/.gitignore @@ -0,0 +1,2 @@ +*.*~ +*pyc diff --git a/maintenance_server_monitoring/README.rst b/maintenance_server_monitoring/README.rst new file mode 100644 index 0000000..2e1e290 --- /dev/null +++ b/maintenance_server_monitoring/README.rst @@ -0,0 +1,44 @@ +====================================== +maintenance_server_data +====================================== + +Gather several identification data about the servers to maintain. + +Installation +============ + +Use Odoo normal module installation procedure to install +``maintenance_server_data``. + +Known issues / Roadmap +====================== + +None yet. + +Bug Tracker +=========== + +Bugs are tracked on `our issues website `_. 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. diff --git a/maintenance_server_monitoring/__init__.py b/maintenance_server_monitoring/__init__.py new file mode 100644 index 0000000..cde864b --- /dev/null +++ b/maintenance_server_monitoring/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models diff --git a/maintenance_server_monitoring/__manifest__.py b/maintenance_server_monitoring/__manifest__.py new file mode 100644 index 0000000..df2cd3f --- /dev/null +++ b/maintenance_server_monitoring/__manifest__.py @@ -0,0 +1,37 @@ +# Copyright 2023 Stéphan Sainléger (Elabore) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "maintenance_server_monitoring", + "version": "16.0.1.0.0", + "author": "Elabore", + "website": "https://elabore.coop", + "maintainer": "Clément Thomas", + "license": "AGPL-3", + "category": "Tools", + "summary": "Monitor some data on remote hosts", + # any module necessary for this one to work correctly + "depends": [ + "base", + "maintenance", + ], + "qweb": [ + # "static/src/xml/*.xml", + ], + "external_dependencies": { + "python": [], + }, + # always loaded + "data": [ + "views/maintenance_equipment_views.xml", + ], + # 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, +} \ No newline at end of file diff --git a/maintenance_server_monitoring/models/__init__.py b/maintenance_server_monitoring/models/__init__.py new file mode 100644 index 0000000..b31f6b6 --- /dev/null +++ b/maintenance_server_monitoring/models/__init__.py @@ -0,0 +1 @@ +from . import maintenance_equipment \ No newline at end of file diff --git a/maintenance_server_monitoring/models/maintenance_equipment.py b/maintenance_server_monitoring/models/maintenance_equipment.py new file mode 100644 index 0000000..783ef20 --- /dev/null +++ b/maintenance_server_monitoring/models/maintenance_equipment.py @@ -0,0 +1,46 @@ +from odoo import fields, models +import subprocess +import sys +import psutil + + +class MaintenanceEquipment(models.Model): + _inherit = 'maintenance.equipment' + + server_domain = fields.Char('Server Domain') + ssh_private_key_path = fields.Char("SSH private key path", default="/opt/odoo/auto/dev/ssh_keys/id_rsa") + last_monitoring_test_date = fields.Datetime('Date of last monitoring test', readonly=True) + ping_ok = fields.Boolean("Ping ok", readonly=True) + available_memory_percent = fields.Float('Percent of available memory', readonly=True) + + def install_dependencies(self): + if "ping3" not in sys.modules: + command = ['pip','install',"ping3"] + response = subprocess.call(command) + return response + + + def monitoring_test(self): + self.install_dependencies() + self.test_ping() + self.test_available_memory_percent() + self.last_monitoring_test_date = fields.Datetime.now() + return + + def test_available_memory_percent(self): + import paramiko + ssh = paramiko.SSHClient() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + ssh.connect(self.server_domain, username="root", key_filename=self.ssh_private_key_path) + _stdin, stdout, _stderr = ssh.exec_command("free | grep Mem | awk '{print $3/$2 * 100.0}'") + self.available_memory_percent = float(stdout.read().decode()) + + def test_ping(self): + from ping3 import ping + hostname = self.server_domain + r = ping(hostname) + if r: + self.ping_ok = True + else: + self.ping_ok = False + return \ No newline at end of file diff --git a/maintenance_server_monitoring/views/maintenance_equipment_views.xml b/maintenance_server_monitoring/views/maintenance_equipment_views.xml new file mode 100644 index 0000000..ad24c2e --- /dev/null +++ b/maintenance_server_monitoring/views/maintenance_equipment_views.xml @@ -0,0 +1,37 @@ + + + + equipment.form.server.inherit + maintenance.equipment + + + + + + + + + + + + +