1#!/usr/local/bin/python3.8 2# -*- coding: utf-8 -*- 3 4__author__ = 'Jan-Piet Mens <jpmens()gmail.com>' 5__copyright__ = 'Copyright 2014 Jan-Piet Mens' 6__license__ = 'Eclipse Public License - v 1.0 (http://www.eclipse.org/legal/epl-v10.html)' 7 8 9import pynsca 10from pynsca import NSCANotifier 11 12 13def plugin(srv, item): 14 15 srv.logging.debug("*** MODULE=%s: service=%s, target=%s", __file__, item.service, item.target) 16 17 config = item.config 18 19 statii = [ pynsca.OK, pynsca.WARNING, pynsca.CRITICAL, pynsca.UNKNOWN ] 20 status = pynsca.OK 21 try: 22 prio = item.priority 23 status = statii[prio] 24 except: 25 pass 26 27 nsca_host = str(config['nsca_host']) 28 29 host_name = item.addrs[0] 30 service_description = item.addrs[1] 31 32 # If the incoming payload has been transformed, use that, 33 # else the original payload 34 text = item.message 35 36 try: 37 notif = NSCANotifier(nsca_host) 38 notif.svc_result(host_name, service_description, status, text) 39 except Exception as e: 40 srv.logging.warning("Cannot notify to NSCA host `%s': %s" % (nsca_host, e)) 41 return False 42 43 return True 44