Esempio n. 1
0
def init_plugins(options):
    """Pass any parameters to plugins."""
    # Yes, this could be done in a more generic way with plugins providing
    # a specific interface that provides both the plugin's options and
    # a function to process those options. For now this is sufficient.

    snmp = plugin.search(query.IQuery, "snmp")
    snmp.use_bulk(not options.disable_snmp_bulk)
Esempio n. 2
0
def get_filter(test, name, default, arguments):
    """Search the plugins for the requested filter and create it"""

    filter_class = plugin.search(IFilter, name, None)
    if filter_class:
        assert issubclass(filter_class, _Filter)
        return filter_class(test, default, arguments)
    else:
        raise errors.InitError("Invalid filter type '%s'" % name)
Esempio n. 3
0
 def setUp(self):
     self.notification = plugin.search(notify.INotification, self.name)
     self.macros = {
             'host': notify.Macros(test_notify.ENVIRONMENT_HOST),
             'service': notify.Macros(test_notify.ENVIRONMENT_SERVICE)}
     self.factory = dummy_server.SMTP()
     self.server = reactor.listenTCP(0, self.factory)
     self.config = coil.parse(notify.DEFAULT_CONFIG)
     self.config.merge(coil.struct.Struct(self.notification.defaults))
     self.config['smtp.port'] = self.server.getHost().port
Esempio n. 4
0
def parse_options():
    notify_plugins = plugin.search(INotification)
    notify_list = ", ".join(notify_plugins)

    parser = OptionParser()
    parser.add_option("-m", "--method",
            help="notification method: %s" % notify_list)
    parser.add_option("-H", "--host", action="store_true", default=False,
            help="this is a host notification")
    parser.add_option("-S", "--service", action="store_true", default=False,
            help="this is a service notification")
    parser.add_option("-c", "--config",
            help="load notification coil config")
    parser.add_option("-l", "--logfile",
            help="log errors to a given file")
    parser.add_option("-v", "--loglevel", default="WARN",
            help="set a specific log level")
    parser.add_option("-d", "--daemonize", action="store_true",
            help="daemonize to avoid blocking nagios")
    parser.add_option("-D", "--dump", action="store_true",
            help="just dump the config")
    options, args = parser.parse_args()

    if args:
        parser.error("unknown extra arguments: %s" % args)

    if not options.method:
        parser.error("--method is required")

    if options.method not in notify_plugins:
        parser.error("invalid method, choose from: %s" % notify_list)

    if not options.dump and 1 != sum([options.host, options.service]):
        parser.error("choose one and only one: host, service")

    if options.daemonize and not options.logfile:
        parser.error("--daemonize requires --log-file")

    return options, notify_plugins[options.method]
Esempio n. 5
0
    def new_query(self, conf, qcls=None):
        """Create a new query and register it or return an existing one"""

        # Find the correct Query class for this type
        if not qcls:
            qtype = conf.get('type')
            qcls = plugin.search(IQuery, qtype, None)
            if not qcls:
                raise errors.ConfigError(conf,
                        "Unknown query type '%s'" % qtype)

        qobj = qcls(self._nagcat, conf)
        key = str(qobj)
        if key in self._queries:
            log.debug("Reusing query '%s'", key)
            qobj = self._queries[key]
            qobj.update(conf)
        else:
            log.debug("Adding query '%s'", key)
            self._queries[key] = qobj

        return qobj
Esempio n. 6
0
    def setUp(self):
        snmp = plugin.search(query.IQuery, "snmp")
        snmp.use_bulk(self.bulk)

        QueryTestCase.setUp(self)
        return SnmpTestCase.setUp(self)
Esempio n. 7
0
 def testSearch(self):
     plugins = plugin.search(plugin.INagcatPlugin)
     self.assert_(plugins)