Пример #1
0
    def _load_dispatcher_class(self):
        # Get config
        if not hasattr(AlertSender, 'config'):
            AlertSender.config = get_alertengine_config('alertengine.conf')

        # Load module
        module = __import__(
            'nav.alertengine.dispatchers.%s_dispatcher' % self.handler,
            globals(), locals(), [self.handler])

        # Return matching object from module based on case-insensitive match
        namemap = {name.lower(): obj for name, obj in vars(module).items()}
        return namemap[self.handler.lower()]
Пример #2
0
    def send(self, *args, **kwargs):
        """Sends an alert via this medium."""
        if self.handler not in self._handlers:
            # Get config
            if not hasattr(AlertSender, 'config'):
                AlertSender.config = get_alertengine_config(
                    os.path.join(nav.path.sysconfdir, 'alertengine.conf'))

            # Load module
            module = __import__(
                'nav.alertengine.dispatchers.%s_dispatcher' % self.handler,
                globals(), locals(), [self.handler])

            # Init module with config
            self.__class__._handlers[self.handler] = getattr(
                module, self.handler)(config=AlertSender.config.get(
                    self.handler, {}))

        # Delegate sending of message
        return self._handlers[self.handler].send(*args, **kwargs)