Exemplo n.º 1
0
import ConfigParser
import os, shutil, subprocess, shlex

from platform import node
from glob import iglob

import vogeler.log as logger
from vogeler.exceptions import VogelerPluginException

log = logger.setup_logger(logLevel='DEBUG', logFile=None, name='vogeler-plugins')

class VogelerPlugin(object):
    compiled_plugin_file = '/tmp/vogeler-plugins.cfg'
    authorized_plugins = ()
    plugin_registry = {}
    def __init__(self, plugin_dir='/etc/vogeler/plugins'):
        log.info("Vogeler is parsing plugins")
        self.registered_plugins = {}
        self.plugin_dir = plugin_dir
        self._compile_plugins()

    def execute_plugin(self, plugin):
        if plugin in self.authorized_plugins:
            try:
                command = self.plugin_registry[plugin]['command']
                plugin_format = self.plugin_registry[plugin]['result_format']
                result = subprocess.Popen(shlex.split(command), stdout = subprocess.PIPE).communicate()
                return self.format_response(plugin, result, plugin_format)
            except:
                #raise VogelerPluginException("Unable to execute plugin: %s" % command)
                log.debug("Unable to execute plugin: %s" % command)
Exemplo n.º 2
0
import json

import vogeler.log as logger
from vogeler.exceptions import VogelerRunnerException
from vogeler.messaging import amqp

log = logger.setup_logger(logLevel='DEBUG', logFile=None, name='vogeler-runner')

class VogelerRunner(object):
    def __init__(self, destination, **kwargs):
        try:
            self.routing_key = destination
            self.ch = amqp.setup_amqp(kwargs['host'], kwargs['username'], kwargs['password'])
            log.info("Vogeler(Runner) is starting up")
        except:
            raise VogelerRunnerException("Unable to connect to %s as %s" % (kwargs['host'], kwargs['username']) )

    def message(self, message, durable=True):
        log.info("Vogeler(Runner) is sending a message")
        try:
            msg = amqp.amqp.Message(json.dumps(message))
            if durable == True:
                msg.properties['deliver_mode'] = 2
            self.ch.basic_publish(msg, exchange=amqp.broadcast_exchange, routing_key=self.routing_key)
        except:
            raise VogelerRunnerException("Unable to publish message: %s" % message)

    def close(self):
        log.info("Closing channel")
        self.ch.close()
Exemplo n.º 3
0
import json

import vogeler.log as logger
from vogeler.exceptions import VogelerClientException
from vogeler.messaging import amqp

log = logger.setup_logger(logLevel='DEBUG', logFile=None, name='vogeler-client')

class VogelerClient(object):
    """
    Base class for operating as a Vogeler client instance

    :param none callback_function: Callback function to use when messages are recieved

    .. attribute:: callback_function

        External callback used for processing messages

    .. attribute:: ch

        an instance of :class:`amqplib.client_0_8.channel.Channel`

    .. attribute:: queue

        an instance of :class:`amqplib.client_0_8.channel.Queue`

    :raises: :class:`vogeler.exceptions.VogelerClientException`


    """
    def __init__(self, callback_function=None, **kwargs):