def setUp(self):
        self.tmpdir = tempfile.mkdtemp(prefix="test-connector-metro-")
        self.rrd_base_dir = os.path.join(self.tmpdir, "rrds")
        os.mkdir(self.rrd_base_dir)

        confdb = MetroConfDB(os.path.join(os.path.dirname(__file__),
                                     "connector-metro.db"))
        confdb.reload()
        rrdtool = Mock()
        rrdtool.run.side_effect = lambda *a, **kw: defer.succeed(None)
        rrdtool.rrd_base_dir = self.rrd_base_dir
        rrdtool.rrd_path_mode = "flat"
        self.mgr = RRDToolManager(rrdtool, confdb)
        self.mgr._fixperms = Mock()
예제 #2
0
 def setUp(self, signal):
     self.tmpdir = tempfile.mkdtemp(prefix="test-connector-metro-")
     client = ClientStub("testhostname", None, None)
     rrd_base_dir = os.path.join(self.tmpdir, "rrds")
     os.mkdir(rrd_base_dir)
     confdb = MetroConfDB(os.path.join(os.path.dirname(__file__),
                                       "connector-metro.db"))
     self.rrdtool_pool = RRDToolPoolManagerStub(rrd_base_dir,
                 "flat", "/usr/bin/rrdtool")
     rrdtool = RRDToolManager(self.rrdtool_pool, confdb)
     threshold_checker = ThresholdChecker(rrdtool, confdb)
     self.btr = BusToRRDtool(confdb, rrdtool, threshold_checker)
     self.btr.setClient(client)
     d = self.btr.startService()
     d.addCallback(lambda _x: confdb.reload())
     return d
예제 #3
0
def makeService(options):
    """ the service that wraps everything the connector needs. """
    from vigilo.connector.options import getSettings, parseSubscriptions

    settings = getSettings(options, __name__)

    from vigilo.common.logging import get_logger

    LOGGER = get_logger(__name__)

    from vigilo.common.gettext import translate

    _ = translate(__name__)

    from vigilo.connector.client import client_factory
    from vigilo.connector.handlers import buspublisher_factory

    from vigilo.connector_metro.rrdtool import RRDToolPoolManager
    from vigilo.connector_metro.rrdtool import RRDToolManager
    from vigilo.connector_metro.confdb import MetroConfDB
    from vigilo.connector_metro.threshold import ThresholdChecker
    from vigilo.connector_metro.bustorrdtool import BusToRRDtool

    root_service = service.MultiService()

    # Client du bus
    client = client_factory(settings)
    client.setServiceParent(root_service)
    providers = []

    # Configuration
    try:
        conffile = settings["connector-metro"]["config"]
    except KeyError:
        LOGGER.error(
            _("Please set the path to the configuration " "database generated by VigiConf in the settings.ini.")
        )
        sys.exit(1)
    confdb = MetroConfDB(conffile)
    confdb.setServiceParent(root_service)

    try:
        must_check_th = settings["connector-metro"].as_bool("check_thresholds")
    except KeyError:
        must_check_th = True

    # Gestion RRDTool
    rrd_base_dir = settings["connector-metro"]["rrd_base_dir"]
    rrd_path_mode = settings["connector-metro"]["rrd_path_mode"]
    rrd_bin = settings["connector-metro"].get("rrd_bin", "/usr/bin/rrdtool")
    rrdcached = settings["connector-metro"].get("rrdcached", None)
    try:
        pool_size = settings["connector-metro"].as_int("rrd_processes")
    except KeyError:
        pool_size = None
    rrdtool_pool = RRDToolPoolManager(
        rrd_base_dir, rrd_path_mode, rrd_bin, check_thresholds=must_check_th, rrdcached=rrdcached, pool_size=pool_size
    )
    rrdtool = RRDToolManager(rrdtool_pool, confdb)

    # Gestion des seuils
    if must_check_th:
        threshold_checker = ThresholdChecker(rrdtool, confdb)
        bus_publisher = buspublisher_factory(settings, client)
        bus_publisher.registerProducer(threshold_checker, streaming=True)
        providers.append(bus_publisher)
    else:
        threshold_checker = None

    # Gestionnaire principal des messages
    bustorrdtool = BusToRRDtool(confdb, rrdtool, threshold_checker)
    bustorrdtool.setClient(client)
    subs = parseSubscriptions(settings)
    queue = settings["bus"]["queue"]
    queue_messages_ttl = int(settings["bus"].get("queue_messages_ttl", 0))
    bustorrdtool.subscribe(queue, queue_messages_ttl, subs)
    providers.append(bustorrdtool)

    # Statistiques
    from vigilo.connector.status import statuspublisher_factory

    status_publisher = statuspublisher_factory(settings, client, providers=providers)

    return root_service