Browse Source

[IMP] Module 'nsca_client' - External dependency on '/usr/sbin/nsca_send' removed, replaced by a check at the runtime

pull/1280/head
sebalix 9 years ago
committed by Enric Tobella
parent
commit
a02d8d6bc4
No known key found for this signature in database GPG Key ID: 1A2546A1B7BA2451
  1. 5
      nsca_client/__openerp__.py
  2. 17
      nsca_client/models/nsca_check.py

5
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",

17
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))
Loading…
Cancel
Save