From a02d8d6bc49aaaea611496daf48fd83a9c6d3d7d Mon Sep 17 00:00:00 2001 From: sebalix Date: Wed, 16 Dec 2015 18:17:57 +0100 Subject: [PATCH] [IMP] Module 'nsca_client' - External dependency on '/usr/sbin/nsca_send' removed, replaced by a check at the runtime --- nsca_client/__openerp__.py | 5 ----- nsca_client/models/nsca_check.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/nsca_client/__openerp__.py b/nsca_client/__openerp__.py index 2c073676e..6bfaf81a4 100644 --- a/nsca_client/__openerp__.py +++ b/nsca_client/__openerp__.py @@ -11,11 +11,6 @@ "license": "AGPL-3", "application": False, "installable": True, - "external_dependencies": { - "bin": [ - '/usr/sbin/send_nsca', - ], - }, "data": [ "security/ir.model.access.csv", "data/ir_config_parameter.xml", diff --git a/nsca_client/models/nsca_check.py b/nsca_client/models/nsca_check.py index 79bdcaa2f..1159d7e76 100644 --- a/nsca_client/models/nsca_check.py +++ b/nsca_client/models/nsca_check.py @@ -3,15 +3,23 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging +import os import shlex import subprocess from openerp import _, api, fields, models +from openerp.exceptions import Warning as UserError from openerp.addons.base.ir.ir_cron import str2tuple _logger = logging.getLogger(__name__) +SEND_NSCA_BIN = '/usr/sbin/send_nsca' + + +def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + class NscaCheck(models.Model): _name = "nsca.check" @@ -73,6 +81,7 @@ class NscaCheck(models.Model): @api.model def _cron_check(self, check_id): + self._check_send_nsca_command() check = self.browse(check_id) rc, message = 3, "Unknown" try: @@ -128,3 +137,11 @@ class NscaCheck(models.Model): _logger.info("%s: %s", check_result, stdout.strip()) except Exception, exc: _logger.error(exc) + + def _check_send_nsca_command(self): + """Check if the NSCA client is installed.""" + if not is_exe(SEND_NSCA_BIN): + raise UserError( + _(u"Command '%s' not found. Please install the NSCA client.\n" + u"On Debian/Ubuntu: apt-get install nsca-client") % ( + SEND_NSCA_BIN))