def makeService(options): """ the service that wraps everything the connector needs. """ from vigilo.connector.options import getSettings 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.handlers import backupprovider_factory from vigilo.connector.socket import socketlistener_factory from vigilo.connector_nagios.nagioscommand import nagioscmdh_factory from vigilo.connector_nagios.nagiosconf import nagiosconffile_factory try: socket_filename = settings['connector-nagios']['listen_unix'] # Statement seems to have no effect # pylint: disable-msg=W0104 settings['connector-nagios']['nagios_pipe'] settings["bus"]["queue"] except KeyError, e: LOGGER.error(_("Missing configuration option: %s"), str(e)) sys.exit(1)
def _db_thread(self): """ Cette méthode est exécutée dans un thread séparé. C'est elle qui traite les demandes d'opérations sur la base de données et retourne les résultats sous la forme d'un objet C{Deferred}. @note: Cette méthode ne retourne pas tant que la méthode L{DatabaseWrapper.shutdown} n'a pas été appelée. """ from vigilo.common.logging import get_logger from vigilo.common.gettext import translate logger = get_logger(__name__) _ = translate(__name__) while True: op = self.queue.get() if op is None: return else: func, args, kwargs, d, txn = op if txn: transaction.begin() try: result = d.callback, func(*args, **kwargs) if txn: transaction.commit() except Exception: if txn: transaction.abort() result = d.errback, Failure() self.queue.task_done() reactor.callFromThread(*result)
""" from __future__ import absolute_import import os import shutil import glob import re from vigilo.common.conf import settings from vigilo.common.logging import get_logger LOGGER = get_logger(__name__) from vigilo.common.gettext import translate _ = translate(__name__) from vigilo.vigiconf import conf from vigilo.vigiconf.lib import VigiConfError from vigilo.vigiconf.lib.systemcommand import SystemCommand, SystemCommandError class ServerError(VigiConfError): """Exception concernant un objet L{Server}""" def __init__(self, value, iServerName = ''): super(ServerError, self).__init__(value) self.value = value self.mServer = iServerName def __str__(self):
# vim: set fileencoding=utf-8 sw=4 ts=4 et : # Copyright (C) 2006-2014 CS-SI # License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html> """Metrology to RRDTool connector.""" import sys, os from zope.interface import implements from twisted.plugin import IPlugin from twisted.application import service from vigilo.common.gettext import translate from vigilo.connector import options as base_options _ = translate('vigilo.connector_metro') class MetroConnectorServiceMaker(object): """ Creates a service that wraps everything the connector needs. """ implements(service.IServiceMaker, IPlugin) tapname = "vigilo-metro" description = "Vigilo connector for performance data" options = base_options.make_options('vigilo.connector_metro') def makeService(self, options): """ the service that wraps everything the connector needs. """ from vigilo.connector_metro import makeService return makeService(options)
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
def change_password(*args): """ Change le mot de passe d'un utilisateur dans la base de données de Vigilo. """ from vigilo.common.gettext import translate _ = translate(__name__) usage=_("%prog [options] [username]"), parser = OptionParser( description=_("Changes Vigilo's password for user 'username' " "or the currently logged in user if this argument is omitted."), ) parser.add_option("-c", "--config", action="store", dest="config", type="string", default=None, help=_("Load configuration from " "this file.")) parser.add_option("-f", action="store", dest="passfile", metavar="FILE", type="string", default=None, help=_("Read the new password from " "this file.")) (options, args) = parser.parse_args() from vigilo.common.conf import settings if options.config: settings.load_file(options.config) else: settings.load_module(__name__) from vigilo.common.logging import get_logger logger = get_logger(__name__) if len(args) > 1: print _('Too many arguments') sys.exit(1) from vigilo.models.configure import configure_db try: configure_db(settings['database'], 'sqlalchemy_') except KeyError: print _('No database configuration found') sys.exit(1) from vigilo.models.session import DBSession from vigilo.models import tables current_password = None current_user = pwd.getpwuid(os.getuid()) username = current_user.pw_name if len(args) > 0: username = args[0] msg = _("Changing Vigilo password for user '%s'.") logger.info(msg, username) print msg % username # Si l'utilisateur n'est pas "root" (UID 0), # alors on demande le mot de passe actuel. if current_user.pw_uid != 0: current_password = getpass.getpass(_("Enter current password: "******"Bad login or password.") sys.exit(1) if options.passfile: passfile = open(options.passfile, "r") new_password = new_password2 = passfile.readline().strip() passfile.close() else: new_password = getpass.getpass(_("Enter new password: "******"Confirm new password: "******"Sorry, passwords do not match.") sys.exit(1) # Si le nouveau mot de passe est le même # que l'ancien, il n'y a rien à faire. if current_password == new_password: print _("Password unchanged.") sys.exit(0) user.password = new_password try: DBSession.flush() transaction.commit() except Exception: # pylint: disable-msg=W0703 # W0703: Catch "Exception" msg = _("An exception occurred while updating password for user '%s'.") logger.exception(msg, username) print msg % username sys.exit(1) # Si on arrive ici, c'est que tout s'est bien passé. msg = _("Successfully updated password for user '%s'.") logger.info(msg, username) print msg % username sys.exit(0)