def __init__(self):
     super(MetricServiceReadThroughCache, self).__init__()
     from Products.Zuul.facades.metricfacade import METRIC_URL_PATH
     urlstart = getGlobalConfiguration().get('metric-url', 'http://localhost:8080')
     self._metric_url = '%s/%s' % (urlstart, METRIC_URL_PATH)
     self._returnset = 'LAST'
     self._metrics_key = 'metrics'
 def __init__(self):
     super(WildcardMetricServiceReadThroughCache, self).__init__()
     from Products.Zuul.facades.metricfacade import WILDCARD_URL_PATH
     urlstart = getGlobalConfiguration().get('metric-url', 'http://localhost:8080')
     self._metric_url = '%s/%s' % (urlstart, WILDCARD_URL_PATH)
     self._returnset = 'last'
     self._metrics_key = 'queries'
Ejemplo n.º 3
0
    def connect(self):
        if self.connection and self.connection.open:
            return

        from Products.ZenUtils.GlobalConfig import getGlobalConfiguration

        global_config = getGlobalConfiguration()
        connect_kwargs = {
            "host": global_config.get("zodb-host", "127.0.0.1"),
            "port": int(global_config.get("zodb-port", 3306)),
            "db": global_config.get("zodb-db", "zodb"),
            "user": global_config.get("zodb-user", "zenoss"),
            "passwd": global_config.get("zodb-password", "zenoss"),
        }

        # Using "localhost" as the MySQL host can cause the mysql library to
        # connect using the UNIX domain socket instead of the network. By
        # replacing localhost with 127.0.0.1 we force the network to be used.
        if connect_kwargs["host"] == "localhost":
            connect_kwargs["host"] = "127.0.0.1"

        self.connection = MySQLdb.connect(**connect_kwargs)
        self.connection.autocommit(True)

        if callable(self.onConnect):
            self.onConnect()
Ejemplo n.º 4
0
def main():
    """Scans through ZODB checking objects for dangling references"""

    execution_start = time.time()
    sys.path.append ("/opt/zenoss/Products/ZenModel")               # From ZEN-12160

    cli_options = parse_options()
    log = configure_logging('zodbscan')
    log.info("Command line options: %s" % (cli_options))
    if cli_options['debug']:
        log.setLevel(logging.DEBUG)

    # Attempt to get the zenoss.toolbox lock before any actions performed
    if not get_lock("zenoss.toolbox", log):
        sys.exit(1)

    number_of_issues = Counter(0)

    zodb_name = getGlobalConfiguration().get("zodb-db", "zodb")

    PKEReporter(zodb_name).run(log, number_of_issues)
    log.info("%d Dangling References were detected" % (number_of_issues.value()))

    print("[%s] Execution finished in %s\n" % (strftime("%Y-%m-%d %H:%M:%S", localtime()),
                                               datetime.timedelta(seconds=int(time.time() - execution_start))))
    log.info("zodbscan completed in %1.2f seconds" % (time.time() - execution_start))
    log.info("############################################################")

    if (number_of_issues.value() > 0):
        print("** WARNING ** Dangling Reference(s) were detected - Consult KB article at")
        print("      https://support.zenoss.com/hc/en-us/articles/203118175\n")
        sys.exit(1)
    else:
        sys.exit(0)
def remove_temp_transaction_docs():
    config = getGlobalConfiguration()
    solr_servers = config.get('solr-servers', 'localhost:8983')
    uid = "*{0}*".format(TX_SEPARATOR)
    query = {"uid" : uid}
    search_params=SearchParams(query)
    searcher = zope.component.createObject('ModelIndex', solr_servers)
    searcher.unindex_search(search_params)
Ejemplo n.º 6
0
def get_solr_config(test=False):
    config = getGlobalConfiguration()
    if test:
        return config.get('solr-test-server', 'localhost:8993')
    if not SOLR_CONFIG:
        SOLR_CONFIG.append(config.get('solr-servers', 'localhost:8983'))
        log.info("Loaded Solr config from global.conf. Solr Servers: {}".format(SOLR_CONFIG))
    return SOLR_CONFIG[0]
Ejemplo n.º 7
0
 def __call__(self):
     from Products.ZenUtils.GlobalConfig import getGlobalConfiguration
     config = getGlobalConfiguration()
     user = config.get('amqpuser', 'zenoss')
     password = config.get('amqppassword', 'zenoss')
     queueData = json.loads(requests.get('http://localhost:15672/api/queues/%2Fzenoss',
                                         auth=requests.auth.HTTPBasicAuth(user, password)).content)
     queueMaps = [dict(id=queue['name']) for queue in queueData if queue['durable']]
     self.request.response.write(json.dumps(dict(durableQueues=queueMaps)))
Ejemplo n.º 8
0
 def __init__(self, solr_servers, context):
     config = getGlobalConfiguration()
     self.model_index = zope.component.createObject('ModelIndex',
                                                    solr_servers)
     self.model_index.searcher.default_row_count = config.get(
         'solr-search-limit', DEFAULT_SEARCH_LIMIT)
     self.context = context
     self._current_transactions = {
     }  # { transaction_id : ModelCatalogTransactionState }
Ejemplo n.º 9
0
 def __init__(self, context):
     super(ZepFacade, self).__init__(context)
     config = getGlobalConfiguration()
     zep_url = config.get('zep-uri', 'http://localhost:8084')
     schema = getUtility(IQueueSchema)
     self.client = ZepServiceClient(zep_url, schema)
     self.configClient = ZepConfigClient(zep_url, schema)
     self.heartbeatClient = ZepHeartbeatClient(zep_url, schema)
     self._guidManager = IGUIDManager(context.dmd)
Ejemplo n.º 10
0
    def __init__(self, host=None, endpoint=None, timeout=None):
        host = host or getGlobalConfiguration().get(GLOBAL_ZING_CONNECTOR_URL) or DEFAULT_HOST
        endpoint = endpoint or getGlobalConfiguration().get(GLOBAL_ZING_CONNECTOR_ENDPOINT) or DEFAULT_ENDPOINT
        self.facts_url = urlparse.urljoin(host, endpoint)

        timeout = timeout or getGlobalConfiguration().get(GLOBAL_ZING_CONNECTOR_TIMEOUT) or DEFAULT_TIMEOUT
        self.timeout = timeout

        parts = urlparse.urlsplit(host)
        start = parts.netloc.rfind(":")
        if start != -1:
            newNetloc = parts.netloc[:start+1] + PING_PORT
        else:
            newNetloc = parts.netloc + ":" + PING_PORT

        l = list(parts)
        l[1] = newNetloc
        adminUrl = urlparse.urlunsplit(tuple(l))
        self.ping_url = urlparse.urljoin(adminUrl, PING_ENDPOINT)
Ejemplo n.º 11
0
    def __init__(self, context):
        super(MetricFacade, self).__init__(context)
        self._metric_url = getGlobalConfiguration().get('metric-url', 'http://localhost:8080/')

        self._cookies = cookielib.CookieJar()
        self._authorization = IAuthorizationTool( self.context)
        if _isRunningFromUI( context):
            self._credentials = self._authorization.extractCredentials( context.REQUEST)
        else:
            self._credentials = self._authorization.extractGlobalConfCredentials()
Ejemplo n.º 12
0
 def get_db_options(self):
     options = getattr(self.app, 'db_options', None)
     if options is not None:
         return options.__dict__
     # This path should never be hit except in testing, because
     # Globals.DB will have been set before this method is even called.
     # Having this lets us have zendmd open a new db so we can test in
     # process, if we comment out getting the database from Globals in
     # db() below.
     from Products.ZenUtils.GlobalConfig import getGlobalConfiguration
     return getGlobalConfiguration()
Ejemplo n.º 13
0
def getCSEConf():
    """Return a dictionary containing CSE configuration 
    """
    global _CSE_CONFIG
    if _CSE_CONFIG is not None and not all(_CSE_CONFIG.values()):
        d = {}
        config = getGlobalConfiguration()
        for k in _CSE_CONFIG:
            d[k] = config.get('cse-' + k)
        _CSE_CONFIG = d if all(d.values()) else {}
    return _CSE_CONFIG
Ejemplo n.º 14
0
    def __init__(self, context):
        super(TriggersFacade, self).__init__(context)

        self._guidManager = IGUIDManager(self._dmd)

        config = getGlobalConfiguration()
        schema = getUtility(IQueueSchema)
        self.triggers_service = TriggerServiceClient(config.get('zep_uri', 'http://localhost:8084'), schema)

        self.notificationPermissions = NotificationPermissionManager()
        self.triggerPermissions = TriggerPermissionManager()
Ejemplo n.º 15
0
    def __init__(self, context):
        super(TriggersFacade, self).__init__(context)

        self._guidManager = IGUIDManager(self._dmd)

        config = getGlobalConfiguration()
        schema = getUtility(IQueueSchema)
        self.triggers_service = TriggerServiceClient(config.get('zep_uri', 'http://localhost:8084'), schema)

        self.notificationPermissions = NotificationPermissionManager()
        self.triggerPermissions = TriggerPermissionManager()
Ejemplo n.º 16
0
 def get_db_options(self):
     options = getattr(self.app, 'db_options', None)
     if options is not None:
         return options.__dict__
     # This path should never be hit except in testing, because
     # Globals.DB will have been set before this method is even called.
     # Having this lets us have zendmd open a new db so we can test in
     # process, if we comment out getting the database from Globals in
     # db() below.
     from Products.ZenUtils.GlobalConfig import getGlobalConfiguration
     return getGlobalConfiguration()
Ejemplo n.º 17
0
def getCSEConf():
    """Return a dictionary containing CSE configuration 
    """
    global _CSE_CONFIG
    if _CSE_CONFIG is not None and not all(_CSE_CONFIG.values()):
        d = {}
        config = getGlobalConfiguration()
        for k in _CSE_CONFIG:
            d[k] = config.get('cse-' + k)
        _CSE_CONFIG = d if all(d.values()) else {}
    return _CSE_CONFIG
Ejemplo n.º 18
0
def load_db_config():
    """  Load zodb config from global.conf """
    global_conf = getGlobalConfiguration()
    db_conf = {}
    db_conf["HOST"] = global_conf.get("zodb-host", '127.0.0.1')
    if db_conf["HOST"] == "localhost":
        db_conf["HOST"] = "127.0.0.1"
    db_conf["PORT"] = int(global_conf.get("zodb-port", 13306))
    db_conf["USER"] = global_conf.get("zodb-user", "zenoss")
    db_conf["PASSWORD"] = global_conf.get("zodb-password", "zenoss")
    db_conf["DB"] = global_conf.get("zodb-db", "zodb")
    return db_conf
Ejemplo n.º 19
0
 def __call__(self):
     from Products.ZenUtils.GlobalConfig import getGlobalConfiguration
     config = getGlobalConfiguration()
     user = config.get('amqpuser', 'zenoss')
     password = config.get('amqppassword', 'zenoss')
     queueData = json.loads(
         requests.get('http://localhost:15672/api/queues/%2Fzenoss',
                      auth=requests.auth.HTTPBasicAuth(user,
                                                       password)).content)
     queueMaps = [
         dict(id=queue['name']) for queue in queueData if queue['durable']
     ]
     self.request.response.write(json.dumps(dict(durableQueues=queueMaps)))
Ejemplo n.º 20
0
    def __init__(self, host=None, endpoint=None, timeout=None):
        host = host or getGlobalConfiguration().get(
            GLOBAL_ZING_CONNECTOR_URL) or DEFAULT_HOST
        endpoint = endpoint or getGlobalConfiguration().get(
            GLOBAL_ZING_CONNECTOR_ENDPOINT) or DEFAULT_ENDPOINT
        self.facts_url = urlparse.urljoin(host, endpoint)

        timeout = timeout or getGlobalConfiguration().get(
            GLOBAL_ZING_CONNECTOR_TIMEOUT) or DEFAULT_TIMEOUT
        self.timeout = timeout

        parts = urlparse.urlsplit(host)
        start = parts.netloc.rfind(":")
        if start != -1:
            newNetloc = parts.netloc[:start + 1] + PING_PORT
        else:
            newNetloc = parts.netloc + ":" + PING_PORT

        l = list(parts)
        l[1] = newNetloc
        adminUrl = urlparse.urlunsplit(tuple(l))
        self.ping_url = urlparse.urljoin(adminUrl, PING_ENDPOINT)
Ejemplo n.º 21
0
 def __init__(self, userAgent):
     self._aggMapping = AGGREGATION_MAPPING
     urlstart = getGlobalConfiguration().get('metric-url', 'http://localhost:8080')
     self._metric_url = '%s/%s' % (urlstart, METRIC_URL_PATH)
     self._metric_url_v2 = '%s/%s' % (urlstart, WILDCARD_URL_PATH)
     creds = IAuthorizationTool(None).extractGlobalConfCredentials()
     auth = base64.b64encode('{login}:{password}'.format(**creds))
     self.agent = CookieAgent(Agent(reactor, pool=getPool(), connectTimeout=30), self.cookieJar)
     self._headers = Headers({
         'Authorization': ['basic %s' % auth],
         'content-type': ['application/json'],
         'User-Agent': ['Zenoss: %s' % userAgent]
     })
     self.onMetricsFetched = None
Ejemplo n.º 22
0
    def __init__(self, host=None, endpoint=None, timeout=None):
        host = (host or getGlobalConfiguration().get(GLOBAL_ZING_CONNECTOR_URL)
                or DEFAULT_HOST)
        endpoint = (
            endpoint
            or getGlobalConfiguration().get(GLOBAL_ZING_CONNECTOR_ENDPOINT)
            or DEFAULT_ENDPOINT)
        self.facts_url = urlparse.urljoin(host, endpoint)

        timeout = (timeout or
                   getGlobalConfiguration().get(GLOBAL_ZING_CONNECTOR_TIMEOUT)
                   or DEFAULT_TIMEOUT)

        if type(timeout) is not float:
            try:
                timeout = float(timeout)
            except Exception:
                log.error("could not coerce timeout to float: %s", timeout)

        self.timeout = timeout

        # admin port exists no longer
        self.ping_url = self.facts_url
Ejemplo n.º 23
0
def get_config(database=None):
    conf = getGlobalConfiguration()

    if database:
        conf["zodb-db"] = conf["mysqldb"] = database
    else:
        conf["mysqldb"] = conf.get("mysqldb", conf.get("zodb-db"))
        conf["zodb-db"] = conf.get("zodb-db", conf.get("mysqldb"))

    zodb_socket = conf.get("mysqlsocket", conf.get("zodb-socket"))

    if zodb_socket:
        conf["socket"] = "unix_socket %s" % zodb_socket
    else:
        conf["socket"] = ""

    newer_conf = {
        "zodb-host": conf.get("host"),
        "zodb-port": conf.get("port"),
        "zodb-db": conf.get("mysqldb"),
        "zodb-user": conf.get("mysqluser"),
        "zodb-password": conf.get("mysqlpasswd"),
    }

    newer_conf.update(conf)

    _storage_config = (
        """
        <relstorage>
            pack-gc true
            keep-history false
            <mysql>
                host %(zodb-host)s
                port %(zodb-port)s
                db %(zodb-db)s
                user %(zodb-user)s
                passwd %(zodb-password)s
                %(socket)s
            </mysql>
        </relstorage>
        """
        % newer_conf
    )

    with tempfile.NamedTemporaryFile() as configfile:
        configfile.write(_storage_config)
        configfile.flush()
        config, handler = ZConfig.loadConfig(schema, configfile.name)
        return config
Ejemplo n.º 24
0
def getAuth0Conf():
    """Return a dictionary containing Auth0 configuration or None
    """
    global _AUTH0_CONFIG
    if _AUTH0_CONFIG is not None and not all(_AUTH0_CONFIG.values()):
        d = {}
        config = getGlobalConfiguration()
        for k in _AUTH0_CONFIG:
            d[k] = config.get('auth0-' + k)
        if not all(d.values()) and any(d.values()):
            raise Exception('Auth0 config is missing values. Expecting: %s' % ', '.join(['auth0-%s' % value for value in _AUTH0_CONFIG.keys()]))
        _AUTH0_CONFIG = d if all(d.values()) else None
        # Whitelist is a comma separated array of strings
        if _AUTH0_CONFIG and _AUTH0_CONFIG['whitelist']:
            _AUTH0_CONFIG['whitelist'] = [s.strip() for s in _AUTH0_CONFIG['whitelist'].split(',') if s.strip() != '']
    return _AUTH0_CONFIG or None
Ejemplo n.º 25
0
def getAuth0Conf():
    """Return a dictionary containing Auth0 configuration or None
    """
    global _AUTH0_CONFIG
    if _AUTH0_CONFIG is not None and not all(_AUTH0_CONFIG.values()):
        d = {}
        config = getGlobalConfiguration()
        for k in _AUTH0_CONFIG:
            d[k] = config.get('auth0-' + k)
        if not all(d.values()) and any(d.values()):
            raise Exception('Auth0 config is missing values. Expecting: %s' % ', '.join(['auth0-%s' % value for value in _AUTH0_CONFIG.keys()]))
        _AUTH0_CONFIG = d if all(d.values()) else None
        # Whitelist is a comma separated array of strings
        if _AUTH0_CONFIG and _AUTH0_CONFIG['whitelist']:
            _AUTH0_CONFIG['whitelist'] = [s.strip() for s in _AUTH0_CONFIG['whitelist'].split(',') if s.strip() != '']
    return _AUTH0_CONFIG or None
Ejemplo n.º 26
0
 def __init__(self, userAgent):
     self._aggMapping = AGGREGATION_MAPPING
     urlstart = getGlobalConfiguration().get('metric-url',
                                             'http://localhost:8080')
     self._metric_url = '%s/%s' % (urlstart, METRIC_URL_PATH)
     self._metric_url_v2 = '%s/%s' % (urlstart, WILDCARD_URL_PATH)
     creds = IAuthorizationTool(None).extractGlobalConfCredentials()
     auth = base64.b64encode('{login}:{password}'.format(**creds))
     self.agent = CookieAgent(
         Agent(reactor, pool=getPool(), connectTimeout=30), self.cookieJar)
     self._headers = Headers({
         'Authorization': ['basic %s' % auth],
         'content-type': ['application/json'],
         'User-Agent': ['Zenoss: %s' % userAgent]
     })
     self.onMetricsFetched = None
Ejemplo n.º 27
0
    def __init__(self, context):
        super(MetricFacade, self).__init__(context)
        self._metric_url = getGlobalConfiguration().get('metric-url', 'http://localhost:8080/')

        self._req_session = requests.Session()
        self._authCookie = {}
        self._authorization = IAuthorizationTool(self.context)
        self._credentials = None
        if _isRunningFromUI( context):
            token = context.REQUEST.cookies.get('ZAuthToken', None)
            if token:
                self._authCookie = {'ZAuthToken': token}
            else:
                self._credentials = self._authorization.extractCredentials( context.REQUEST)
        else:
            self._credentials = self._authorization.extractGlobalConfCredentials()
Ejemplo n.º 28
0
def get_config(database=None):
    conf = getGlobalConfiguration()

    if database:
        conf['zodb-db'] = conf['mysqldb'] = database
    else:
        conf['mysqldb'] = conf.get('mysqldb', conf.get('zodb-db'))
        conf['zodb-db'] = conf.get('zodb-db', conf.get('mysqldb'))

    zodb_socket = conf.get('mysqlsocket',
                                   conf.get('zodb-socket'))

    if zodb_socket:
        conf['socket'] = 'unix_socket %s' % zodb_socket
    else:
        conf['socket'] = ''

    newer_conf = {
        'zodb-host': conf.get('host'),
        'zodb-port': conf.get('port'),
        'zodb-db': conf.get('mysqldb'),
        'zodb-user': conf.get('mysqluser'),
        'zodb-password': conf.get('mysqlpasswd')
    }

    newer_conf.update(conf)

    _storage_config = """
        <relstorage>
            pack-gc true
            keep-history false
            <mysql>
                host %(zodb-host)s
                port %(zodb-port)s
                db %(zodb-db)s
                user %(zodb-user)s
                passwd %(zodb-password)s
                %(socket)s
            </mysql>
        </relstorage>
        """ % newer_conf

    with tempfile.NamedTemporaryFile() as configfile:
        configfile.write(_storage_config)
        configfile.flush()
        config, handler = ZConfig.loadConfig(schema, configfile.name)
        return config
Ejemplo n.º 29
0
    def __init__(self, auth_token, credentials, global_credentials,
                 agent_suffix='python'):
        """Metric connection constructor.

        :param auth_token: ZAuthToken used for authentication
        :param credentials: current user credentials
        :param global_credentials: global user credentials
        :param agent_suffix: suffix to be added to user agent
        """
        self._metric_url = getGlobalConfiguration().get('metric-url',
                                                        DEFAULT_METRIC_URL)

        self._auth_token = auth_token
        self._credentials = credentials
        self._global_credentials = global_credentials

        self._req_session = self._init_session(agent_suffix)
Ejemplo n.º 30
0
def get_config(database=None):
    conf = getGlobalConfiguration()

    if database:
        conf['zodb-db'] = conf['mysqldb'] = database
    else:
        conf['mysqldb'] = conf.get('mysqldb', conf.get('zodb-db'))
        conf['zodb-db'] = conf.get('zodb-db', conf.get('mysqldb'))

    zodb_socket = conf.get('mysqlsocket', conf.get('zodb-socket'))

    if zodb_socket:
        conf['socket'] = 'unix_socket %s' % zodb_socket
    else:
        conf['socket'] = ''

    newer_conf = {
        'zodb-host': conf.get('host'),
        'zodb-port': conf.get('port'),
        'zodb-db': conf.get('mysqldb'),
        'zodb-user': conf.get('mysqluser'),
        'zodb-password': conf.get('mysqlpasswd')
    }

    newer_conf.update(conf)

    _storage_config = """
        <relstorage>
            pack-gc true
            keep-history false
            <mysql>
                host %(zodb-host)s
                port %(zodb-port)s
                db %(zodb-db)s
                user %(zodb-user)s
                passwd %(zodb-password)s
                %(socket)s
            </mysql>
        </relstorage>
        """ % newer_conf

    with tempfile.NamedTemporaryFile() as configfile:
        configfile.write(_storage_config)
        configfile.flush()
        config, handler = ZConfig.loadConfig(schema, configfile.name)
        return config
 def __init__(self):
     import requests
     self._requests = requests
     from Products.Zuul.facades.metricfacade import DATE_FORMAT, METRIC_URL_PATH, AGGREGATION_MAPPING
     self._datefmt = DATE_FORMAT
     self._aggMapping = AGGREGATION_MAPPING
     self._cache = {}
     self._targetKey = 'uuid'
     urlstart = getGlobalConfiguration().get('metric-url', 'http://localhost:8080')
     self._metric_url = '%s/%s' % (urlstart, METRIC_URL_PATH)
     from Products.Zuul.interfaces import IAuthorizationTool
     creds = IAuthorizationTool(None).extractGlobalConfCredentials()
     auth = base64.b64encode('{login}:{password}'.format(**creds))
     self._headers = {
         'Authorization': 'basic %s' % auth,
         'content-type': 'application/json'
     }
     self._cookies = cookielib.CookieJar()
Ejemplo n.º 32
0
    def __init__(self, context):
        super(MetricFacade, self).__init__(context)
        self._metric_url = getGlobalConfiguration().get(
            'metric-url', 'http://localhost:8080/')

        self._req_session = requests.Session()
        self._authCookie = {}
        self._authorization = IAuthorizationTool(self.context)
        self._credentials = None
        if _isRunningFromUI(context):
            token = context.REQUEST.cookies.get('ZAuthToken', None)
            if token:
                self._authCookie = {'ZAuthToken': token}
            else:
                self._credentials = self._authorization.extractCredentials(
                    context.REQUEST)
        else:
            self._credentials = self._authorization.extractGlobalConfCredentials(
            )
Ejemplo n.º 33
0
    def __init__(
        self,
        auth_token,
        credentials,
        global_credentials,
        agent_suffix="python",
    ):
        """Initialize a MetricConnection object.

        :param auth_token: ZAuthToken used for authentication
        :param credentials: current user credentials
        :param global_credentials: global user credentials
        :param agent_suffix: suffix to be added to user agent
        """
        self._metric_url = getGlobalConfiguration().get(
            "metric-url", DEFAULT_METRIC_URL)
        self._auth_token = auth_token
        self._credentials = credentials
        self._global_credentials = global_credentials
        self._req_session = self._init_session(agent_suffix)
Ejemplo n.º 34
0
    def __init__(self,
                 auth_token,
                 credentials,
                 global_credentials,
                 agent_suffix='python'):
        """Metric connection constructor.

        :param auth_token: ZAuthToken used for authentication
        :param credentials: current user credentials
        :param global_credentials: global user credentials
        :param agent_suffix: suffix to be added to user agent
        """
        self._metric_url = getGlobalConfiguration().get(
            'metric-url', DEFAULT_METRIC_URL)

        self._auth_token = auth_token
        self._credentials = credentials
        self._global_credentials = global_credentials

        self._req_session = self._init_session(agent_suffix)
Ejemplo n.º 35
0
 def __init__(self, local=True, host=_RABBIT_HOST, port=_RABBIT_PORT,
              user=_RABBIT_USERNAME, passwd=_RABBIT_PASSWORD,
              vhost=_RABBIT_VHOST, ssl=_RABBIT_SSL):
     if local:
         import Globals
         from Products.ZenUtils.GlobalConfig import getGlobalConfiguration
         global_conf = getGlobalConfiguration()
         ssl = global_conf.get('amqpusessl', '0')
         self.host = global_conf.get('amqphost', 'localhost')
         self.port = global_conf.get('amqpport', '5672')
         self.user = global_conf.get('amqpuser', 'zenoss')
         self.passwd = global_conf.get('amqppassword', 'zenoss')
         self.vhost = global_conf.get('amqpvhost', '/zenoss')
         self.ssl = (True if ssl in ('1', 'True', 'true') else False)
     else:
         self.host = host
         self.port = port
         self.user = user
         self.passwd = passwd
         self.vhost = vhost
         self.ssl = ssl
Ejemplo n.º 36
0
def _getConfig():
    """Return a dict containing the configuration for zenjobs."""
    conf = _default_configs.copy()
    conf.update(getGlobalConfiguration())

    app_conf_file = zenPath("etc", "zenjobs.conf")
    app_config_loader = ConfigLoader(app_conf_file, Config)
    try:
        conf.update(app_config_loader())
    except IOError as ex:
        # Re-raise exception if the error is not "File not found"
        if ex.errno != 2:
            raise

    # Convert the configuration value types to useable types.
    for key, cast in _xform.items():
        if key not in conf:
            continue
        conf[key] = cast(conf[key])

    return conf
Ejemplo n.º 37
0
    def getCacheClient(self):
        """
        getCacheClient returns a tuple (cache_client, timeout) for the given
        cache_key. The key is looked up in global.conf. If the application
        cache servers are not set or the cache_key is not found a (None, None)
        is returned.
        """
        if FunctionCache._CACHE_CLIENT == False:
            return None, None

        if FunctionCache._CONFIG is None:
            import Globals
            from Products.ZenUtils.GlobalConfig import getGlobalConfiguration
            FunctionCache._CONFIG = getGlobalConfiguration()

        if FunctionCache._CACHE_CLIENT is None:
            if 'applicationcache' in FunctionCache._CONFIG:
                FunctionCache._CACHE_CLIENT = memcache.Client(
                        FunctionCache._CONFIG['applicationcache'].split(","))
            elif 'zodb-cacheservers' in FunctionCache._CONFIG:
                FunctionCache._CACHE_CLIENT = memcache.Client(
                        FunctionCache._CONFIG['zodb-cacheservers'].split(","))
            else:
                FunctionCache._CACHE_CLIENT = False

        config_key = "applicationcache_%s" % self._cache_key
        if config_key in FunctionCache._CONFIG and FunctionCache._CACHE_CLIENT:
            try:
                return (FunctionCache._CACHE_CLIENT,
                        int(FunctionCache._CONFIG[config_key]))
            except ValueError:
                _LOG.warn("config_key %s found but value did not parse: %s" % \
                        (config_key, FunctionCache._CONFIG[config_key]))

        if FunctionCache._CACHE_CLIENT:
            if self._default_timeout is None:
                return FunctionCache._CACHE_CLIENT, None
            return FunctionCache._CACHE_CLIENT, int(self._default_timeout)

        return None, None
Ejemplo n.º 38
0
    def getCacheClient(self):
        """
        getCacheClient returns a tuple (cache_client, timeout) for the given
        cache_key. The key is looked up in global.conf. If the application
        cache servers are not set or the cache_key is not found a (None, None)
        is returned.
        """
        if FunctionCache._CACHE_CLIENT == False:
            return None, None

        if FunctionCache._CONFIG is None:
            import Globals
            from Products.ZenUtils.GlobalConfig import getGlobalConfiguration
            FunctionCache._CONFIG = getGlobalConfiguration()

        if FunctionCache._CACHE_CLIENT is None:
            if 'applicationcache' in FunctionCache._CONFIG:
                FunctionCache._CACHE_CLIENT = memcache.Client(
                    FunctionCache._CONFIG['applicationcache'].split(","))
            elif 'zodb-cacheservers' in FunctionCache._CONFIG:
                FunctionCache._CACHE_CLIENT = memcache.Client(
                    FunctionCache._CONFIG['zodb-cacheservers'].split(","))
            else:
                FunctionCache._CACHE_CLIENT = False

        config_key = "applicationcache_%s" % self._cache_key
        if config_key in FunctionCache._CONFIG and FunctionCache._CACHE_CLIENT:
            try:
                return (FunctionCache._CACHE_CLIENT,
                        int(FunctionCache._CONFIG[config_key]))
            except ValueError:
                _LOG.warn("config_key %s found but value did not parse: %s" % \
                        (config_key, FunctionCache._CONFIG[config_key]))

        if FunctionCache._CACHE_CLIENT:
            if self._default_timeout is None:
                return FunctionCache._CACHE_CLIENT, None
            return FunctionCache._CACHE_CLIENT, int(self._default_timeout)

        return None, None
Ejemplo n.º 39
0
def main():
    """Scans through ZODB checking objects for dangling references"""

    execution_start = time.time()
    sys.path.append ("/opt/zenoss/Products/ZenModel")               # From ZEN-12160
    scriptName = os.path.basename(__file__).split('.')[0]
    parser = ZenToolboxUtils.parse_options(scriptVersion, scriptName + scriptSummary + documentationURL)
    # Add in any specific parser arguments for %scriptName
    cli_options = vars(parser.parse_args())
    log, logFileName = ZenToolboxUtils.configure_logging(scriptName, scriptVersion, cli_options['tmpdir'])
    log.info("Command line options: %s" % (cli_options))
    if cli_options['debug']:
        log.setLevel(logging.DEBUG)

    print "\n[%s] Initializing %s v%s (detailed log at %s)" % \
          (time.strftime("%Y-%m-%d %H:%M:%S"), scriptName, scriptVersion, logFileName)

    # Attempt to get the zenoss.toolbox lock before any actions performed
    if not ZenToolboxUtils.get_lock("zenoss.toolbox", log):
        sys.exit(1)

    number_of_issues = ZenToolboxUtils.Counter(0)

    zodb_name = getGlobalConfiguration().get("zodb-db", "zodb")

    PKEReporter(zodb_name).run(log, number_of_issues)
    log.info("%d Dangling References were detected" % (number_of_issues.value()))

    print("[%s] Execution finished in %s\n" % (strftime("%Y-%m-%d %H:%M:%S", localtime()),
                                               datetime.timedelta(seconds=int(time.time() - execution_start))))
    log.info("zodbscan completed in %1.2f seconds" % (time.time() - execution_start))
    log.info("############################################################")

    if (number_of_issues.value() > 0):
        print("** WARNING ** Dangling Reference(s) were detected - Consult KB article at")
        print("      https://support.zenoss.com/hc/en-us/articles/203118175\n")
        sys.exit(1)
    else:
        sys.exit(0)
Ejemplo n.º 40
0
    def getMySQLVersion(self):
        """
        This function returns a Version-ready tuple. For use with the Version
        object, use extended call syntax:

            v = Version(*getMySQLVersion())
            v.full()
        """
        cfg = getGlobalConfiguration()
        params = {
                'host': cfg.get("zodb-host", "localhost"),
                'port': int(cfg.get("zodb-port", 3306)),
                'user': cfg.get("zodb-user", "zenoss"),
                'passwd': cfg.get("zodb-password", "zenoss"),
            }
        if "zodb-socket" in cfg:
            params["unix_socket"] = cfg["zodb-socket"]
        db = None
        useZenDS = os.environ.get("USE_ZENDS", False)
        name = "ZenDS" if useZenDS else "MySQL"
        try:
            db = MySQLdb.connect(**params)
            db.query("select version()")
            data = db.use_result().fetch_row()
            if data:
                regex = re.compile("([0-9]+)\.([0-9]+)\.([0-9]+)(.*)")
                versionstr = data[0][0]
                match = regex.match(versionstr)
                if match:
                    major, minor, micro, info = match.groups()
                    return Version(
                            name,
                            int(major), int(minor), int(micro), 0,
                            versionstr
                        )
            raise RuntimeError("Unable to determine %s version" % (name,))
        finally:
            if db:
                db.close()
Ejemplo n.º 41
0
def main():
    parser = OptionParser(usage=usage())
    options, args = parser.parse_args()

    if not args:
        print "No queues specified"
        parser.print_usage()
        sys.exit(1)

    # Nested import/functions to prevent unnecessary overhead when no
    # queues are specified
    import Globals
    from Products.ZenUtils.GlobalConfig import getGlobalConfiguration
    global_conf = getGlobalConfiguration()
    hostname = global_conf.get('amqphost', 'localhost')
    port = global_conf.get('amqpport', '5672')
    username = global_conf.get('amqpuser', 'zenoss')
    password = global_conf.get('amqppassword', 'zenoss')
    vhost = global_conf.get('amqpvhost', '/zenoss')
    ssl = global_conf.get('amqpusessl', '0')
    use_ssl = True if ssl in ('1', 'True', 'true') else False

    cxn = Connection(host="%s:%s" % (hostname, port),
                     userid=username,
                     password=password,
                     virtual_host=vhost,
                     ssl=use_ssl)

    with closing(cxn) as conn, closing(conn.channel()) as channel:
        for queue in args:
            print "Removing queue: %s" % queue
            try:
                channel.queue_delete(queue)
            except Exception as e:
                print "ERROR: Unable to remove %s; does it exist?" % queue
                sys.exit(1)
Ejemplo n.º 42
0
def main():
    parser = OptionParser(usage=usage())
    options, args = parser.parse_args()

    if not args:
        print "No queues specified"
        parser.print_usage()
        sys.exit(1)

    # Nested import/functions to prevent unnecessary overhead when no
    # queues are specified
    import Globals
    from Products.ZenUtils.GlobalConfig import getGlobalConfiguration
    global_conf = getGlobalConfiguration()
    hostname = global_conf.get('amqphost', 'localhost')
    port     = global_conf.get('amqpport', '5672')
    username = global_conf.get('amqpuser', 'zenoss')
    password = global_conf.get('amqppassword', 'zenoss')
    vhost    = global_conf.get('amqpvhost', '/zenoss')
    ssl      = global_conf.get('amqpusessl', '0')
    use_ssl  = True if ssl in ('1', 'True', 'true') else False

    cxn = Connection(host="%s:%s" % (hostname, port),
                      userid=username,
                      password=password,
                      virtual_host=vhost,
                      ssl=use_ssl)

    with closing(cxn) as conn, closing(conn.channel()) as channel:
        for queue in args:
            print "Removing queue: %s" % queue
            try:
                channel.queue_delete(queue)
            except Exception as e:
                print "ERROR: Unable to remove %s; does it exist?" % queue
                sys.exit(1)
Ejemplo n.º 43
0
from ZServer.PubCore.ZRendezvous import ZRendevous
import ZPublisher.interfaces

from Products.Zuul import interfaces
from Products.ZenModel.DataRoot import DataRoot
from Products.ZenUtils.cstat import CStat

_LOG = logging.getLogger('zen.stats')

from Products.ZenUtils.requestlogging.ZopeRequestLogger import ZopeRequestLogger

_request_logger = ZopeRequestLogger()

from Products.ZenUtils.GlobalConfig import getGlobalConfiguration

_request_threshold = float(getGlobalConfiguration().get(
    'zope-request-threshold', 5.0))


# hook in to Web Server's Request Events so that
# fine grained monitoring can be done
@component.adapter(ZPublisher.interfaces.IPubStart)
def logRequestStart(event):
    event.request._start = time.time()


@component.adapter(ZPublisher.interfaces.IPubAfterTraversal)
def logRequestStartAfterTraversal(event):
    # When IPubAfterTraversal is triggered the request body is available
    # in event.request
    try:
        _request_logger.log_request(event.request)
Ejemplo n.º 44
0
def _getZingConnectorClient():
    client_name = (getGlobalConfiguration().get(GLOBAL_ZING_CLIENT_NAME)
                   or DEFAULT_CLIENT)
    return createObject(client_name)
Ejemplo n.º 45
0
    def read_configuration(self):
        """
        Build a Celery configuration dictionary using global.conf.

        This configuration may be overwritten or augmented later by a daemon.
        """
        globalCfg = getGlobalConfiguration()
        amqpCfg = AMQPConfig()
        amqpCfg.update(globalCfg)

        config = {

            #######
            # APP #
            #######

            # Configure the value of the 'CELERYD_POOL_PUTLOCKS'.  When
            # True, it causes a temporary deadlock to occur during shutdown
            # when all workers are busy and there exists at least one
            # pending job. The deadlock is broken when a worker completes
            # its job. Setting 'CELERYD_POOL_PUTLOCKS' to False allows
            # shutdown to occur without waiting.
            "CELERYD_POOL_PUTLOCKS": False,

            #############
            # TRANSPORT #
            #############

            constants.BROKER_HOST: amqpCfg.host,
            constants.BROKER_PORT: amqpCfg.port,
            constants.BROKER_USER: amqpCfg.user,
            constants.BROKER_PASSWORD: amqpCfg.password,
            constants.BROKER_VHOST: amqpCfg.vhost,
            constants.BROKER_USE_SSL: amqpCfg.usessl,
            constants.ACK_LATE: True,

            ################
            # RESULT STORE #
            ################

            constants.RESULT_BACKEND: 'zodb',

            ###########
            # WORKERS #
            ###########

            # Default to 1 job per worker process
            constants.MAX_TASKS_PER_PROCESS: 1,
            # 2 job workers
            constants.NUM_WORKERS: 2,

            ###########
            # LOGGING #
            ###########

            # Handle logging ourselves
            constants.USE_CELERY_LOGGING: False,
            # Log file formats
            constants.LOG_FORMAT: "%(asctime)s %(levelname)s %(name)s: %(message)s",
            constants.TASK_LOG_FORMAT: "%(asctime)s %(levelname)s zen.Job: %(message)s",
            # Level at which stdout should be logged
            constants.STDOUT_LOG_LEVEL: 'INFO'
        }
        return config
Ejemplo n.º 46
0
 def __init__(self):
     self._global_conf = getGlobalConfiguration()
Ejemplo n.º 47
0
def register_cse_virtual_root():
    config = getGlobalConfiguration()
    prefix = config.get('cse-virtualroot', '')
    gsm = getGlobalSiteManager()
    gsm.registerUtility(CSEVirtualRoot(prefix), IVirtualRoot)
                                        BaseTask, TaskStates
from Products.ZenUtils.observable import ObservableMixin

from Products.ZenUtils.Utils import zenPath

from Products.ZenEvents.EventServer import Stats
from Products.ZenUtils.Utils import unused
from Products.ZenCollector.services.config import DeviceProxy

from ZenPacks.SteelHouseLabs.SplunkForwarder.services.SEFService import SEFService
unused(Globals, DeviceProxy)

COLLECTOR_NAME = 'splunkforwarder'
log = logging.getLogger("zen.%s" % COLLECTOR_NAME)

global_conf = getGlobalConfiguration()

splukloggerfile = global_conf.get('splunkLoggerFile', '/opt/zenoss/var/splunklogger')

exchange = 'events'
queue = 'eventForwarder'
passwd = global_conf.get('amqppassword', 'zenoss')
user = global_conf.get('amqpuser', 'zenoss')
vhost = global_conf.get('amqpvhost', '/zenoss')
port = int(global_conf.get('amqpport', '5672'))
host = global_conf.get('amqphost', 'localhost')


class SEFPrefs(object):
    zope.interface.implements(ICollectorPreferences)
Ejemplo n.º 49
0
 def __init__(self, verbose=False):
     self._verbose = verbose
     LOG.debug("Getting global conf")
     self._global_conf = getGlobalConfiguration()
Ejemplo n.º 50
0
 def __init__(self):
     self._global_conf = getGlobalConfiguration()
Ejemplo n.º 51
0
 def __init__(self, verbose=False):
     self._verbose = verbose
     LOG.debug("Getting global conf")
     self._global_conf = getGlobalConfiguration()
Ejemplo n.º 52
0
 def __init__(self):
     config = getGlobalConfiguration()
     schema = getUtility(IQueueSchema)
     zep_url = config.get('zep-uri', 'http://localhost:8084')
     self._configClient = ZepConfigClient(zep_url, schema)
     self._initialized = False
Ejemplo n.º 53
0
 def __init__(self):
     self.redis_url = getGlobalConfiguration().get('redis-url',
                                                   self.DEFAULT_REDIS_URL)
     self._redis_client = None
     self._redis_last_connection_attemp = 0
Ejemplo n.º 54
0
 def extractGlobalConfCredentials(self):
     conf = getGlobalConfiguration()
     login = conf.get('zauth-username', None)
     password = conf.get('zauth-password', None)
     return {'login':login, 'password':password}
Ejemplo n.º 55
0
from Globals import InitializeClass
from Monitor import Monitor
from Products.Jobber.jobs import SubprocessJob
from Products.ZenRelations.RelSchema import ToMany, ToOne
from Products.ZenUtils.Utils import basicAuthUrl, zenPath, binPath
from Products.ZenUtils.Utils import unused
from Products.ZenUtils.Utils import isXmlRpc
from Products.ZenUtils.Utils import executeCommand
from Products.ZenUtils.Utils import addXmlServerTimeout
from Products.ZenUtils.GlobalConfig import getGlobalConfiguration
from Products.ZenModel.ZDeviceLoader import DeviceCreationJob
from Products.ZenWidgets import messaging
from Products.ZenMessaging.audit import audit
from StatusColor import StatusColor

SUMMARY_COLLECTOR_REQUEST_TIMEOUT = float(getGlobalConfiguration().get(
    'collectorRequestTimeout', 5))

PERF_ROOT = None
"""
Prefix for renderurl if zenoss is running a reverse proxy on the master. Prefix will be stripped when appropriate and
requests for data will be made to the proxy server when appropriate.  Render url should be of the form "rev_proxy:/<path>" eg:
"rev_proxy:/mypath" where /mypath should be proxied to an appropriate zenrender/renderserver by the installed proxy server
"""
REVERSE_PROXY = "rev_proxy:"

ProxyConfig = namedtuple('ProxyConfig', ['useSSL', 'port'])


def performancePath(target):
    """
    Return the base directory where RRD performance files are kept.