Example #1
0
    def __init__(self,
                 counter,
                 host,
                 port=6379,
                 db=0,
                 password=None,
                 socket_connect_timeout=1,
                 socket_timeout=5,
                 ssl=False,
                 ssl_cert_reqs='required'):
        if not host:
            raise ConfigurationError(
                'Redis wrapper improperly configured. Valid redis host is required!'
            )

        self._counter = counter('')
        self.__con = redis.StrictRedis(
            host,
            port,
            db,
            password,
            socket_connect_timeout=socket_connect_timeout,
            socket_timeout=socket_timeout,
            ssl=ssl,
            ssl_cert_reqs=ssl_cert_reqs)
Example #2
0
    def __init__(self, counter, host, port=6379, db=0, socket_connect_timeout=1, socket_timeout=5):
        if not host:
            raise ConfigurationError('Redis wrapper improperly configured. Valid redis host is required!')

        self._counter = counter('')
        self.__con = redis.StrictRedis(
            host, port, db, socket_connect_timeout=socket_connect_timeout, socket_timeout=socket_timeout)
Example #3
0
    def __init__(
        self,
        host=None,
        tls=True,
        krb5=False,
        user='******',
        password='',
        timeout=60,
        logger=None,
        counter=None,
    ):
        '''expects ready to use "partial" for counter (CounterWrapper)'''

        self.logger = logger or logging.getLogger()
        self._counter = counter('')
        self.use_tls = tls
        self.use_krb5 = krb5
        self.user_base_dn = ','.join(explode_dn(user)[1:])
        self.user_filter = '(' + explode_dn(user)[0] + ')'
        self.user_attrib = ['dn']
        # password auth
        self.bind_dn = user
        self.__password = password
        self.session = None
        self.host = host
        if self.host and len(self.host.split('.')) <= 1:
            # FIXME
            self.host += '.zalando'

        if not password and not krb5 and tls:
            raise ConfigurationError('LDAP password is not set properly!')
Example #4
0
 def __init__(self, read_key):
     self.__numeric_url = 'https://www.scalyr.com/api/numericQuery'
     self.__timeseries_url = 'https://www.scalyr.com/api/timeseriesQuery'
     self.__facet_url = 'https://www.scalyr.com/api/facetQuery'
     if not read_key:
         raise ConfigurationError('Scalyr read key is not set.')
     self.read_key = read_key
Example #5
0
    def __init__(self, host, timeout=10):
        if not host:
            raise ConfigurationError(
                'Whois wrapper improperly configured. Valid host is required!')

        self.host = host
        self.timeout = timeout
Example #6
0
    def __init__(self, counter, host, port=11211, socket_connect_timeout=1):
        if not host:
            raise ConfigurationError(
                'Memcached wrapper improperly configured. Valid memcached host is required!'
            )

        self.__con = Client((host, port))
        self._counter = counter('')
Example #7
0
    def __init__(self, host, port):
        if not host:
            raise ConfigurationError(
                'ZMON wrapper improperly configured. Valid redis host is required!'
            )

        self.__redis = redis.StrictRedis(host, port)
        self.logger = logger
Example #8
0
    def __init__(self, host, port=27017):
        if not host:
            raise ConfigurationError(
                'MongoDB improperly configured. host is invalid. Check entity["host"] value or set valid host.'
            )

        self.host = host
        self.port = port
Example #9
0
    def __init__(self, url=None, timeout=10, oauth2=False):
        if not url:
            raise ConfigurationError(
                'Elasticsearch plugin improperly configured. URL is required!')

        self.url = url
        self.timeout = timeout
        self.oauth2 = oauth2
        self._headers = {'User-Agent': get_user_agent()}
Example #10
0
    def __init__(self, url, oauth2=False):
        if not url:
            raise ConfigurationError('KairosDB wrapper improperly configured. URL is missing!')

        self.url = url

        self.__session = requests.Session()

        if oauth2:
            self.__session.headers.update({'Authorization': 'Bearer {}'.format(tokens.get('uid'))})
Example #11
0
    def query(self, host=None, recordtype=None, nameserver=None):
        if not self.host and not host:
            raise ConfigurationError('DNS wrapper improperly configured. Host is required!')

        if not recordtype:
            raise ConfigurationError('DNS wrapper improperly configure. Recordtype is required!')

        resolver = dns.resolver.Resolver()
        # Allow to use custom nameserver
        if nameserver:
            resolver.nameservers = nameserver

        query = resolver.query(host, recordtype)
        result = []

        for response in query:
            result.append(str(response).replace('"', ''))

        return result
Example #12
0
    def resolve(self, host=None):
        if not self.host and not host:
            raise ConfigurationError('DNS wrapper improperly configure. Host is required!')

        if not host:
            host = self.host

        try:
            result = socket.gethostbyname(host)
        except Exception, e:
            result = 'ERROR: ' + str(e)
Example #13
0
    def __init__(self, host, instance, http, jmx, counter):
        '''expects ready to use "partials" for http, jmx and counter'''

        if not host or not instance:
            raise ConfigurationError('Zomcat wrapper improperly configured. Valid host & instance are required!')

        self.host = host
        self.instance = instance
        self._http = http
        self._jmx = jmx
        # initialize counter with Redis connection
        self._counter = counter('')
Example #14
0
    def __init__(self, read_key, scalyr_region=None):
        scalyr_prefix = SCALYR_URL_PREFIX_US

        if scalyr_region == 'eu':
            scalyr_prefix = SCALYR_URL_PREFIX_EU

        self.__query_url = '{}/query'.format(scalyr_prefix)
        self.__numeric_url = '{}/numericQuery'.format(scalyr_prefix)
        self.__timeseries_url = '{}/timeseriesQuery'.format(scalyr_prefix)
        self.__facet_url = '{}/facetQuery'.format(scalyr_prefix)

        if not read_key:
            raise ConfigurationError('Scalyr read key is not set.')
        self.__read_key = read_key
Example #15
0
    def __init__(self, jmxqueryhost, jmxqueryport, host, port, timeout=5):
        if not jmxqueryhost or not jmxqueryport:
            raise ConfigurationError(
                'JMX wrapper improperly configured. Missing jmxqueryhost & jmxqueryport.'
            )

        # jmxquery running where?
        self.jmxquery_host = jmxqueryhost
        self.jmxquery_port = jmxqueryport

        self.host = host
        self.port = port

        self.timeout = timeout
        self._queries = []
Example #16
0
    def __init__(self, host, port, sid, user='******', password='', enabled=True):
        self._stmt = None
        self._dsn_tns = None
        self._enabled = enabled
        self.__cx_Oracle = None
        self.__conn = None
        self.__cursor = None

        if not host:
            raise ConfigurationError('Oracle wrapper improperly configured. Valid host is required!')

        if self._enabled:
            self.__cx_Oracle = _import_db_driver()
            port = (int(port) if port and str(port).isdigit() else DEFAULT_PORT)
            try:
                self._dsn_tns = self.__cx_Oracle.makedsn(host, port, sid)
                self.__conn = self.__cx_Oracle.connect(user, password, self._dsn_tns)
                self.__cursor = self.__conn.cursor()
            except Exception, e:
                raise DbError(str(e), operation='Connect to dsn={}'.format(self._dsn_tns)), None, sys.exc_info()[2]
Example #17
0
    def __init__(self,
                 service_url,
                 infrastructure_account,
                 verify=True,
                 oauth2=False):

        if not service_url:
            raise ConfigurationError(
                'EntitiesWrapper improperly configured. URL is missing!')

        self.infrastructure_account = infrastructure_account
        self.__service_url = urlparse.urljoin(service_url, 'api/v1/')
        self.__session = requests.Session()

        self.__session.headers.update({'User-Agent': get_user_agent()})
        self.__session.verify = verify

        if oauth2:
            self.__session.headers.update(
                {'Authorization': 'Bearer {}'.format(tokens.get('uid'))})
Example #18
0
    def __init__(self, url=None, check_id='', entities=None, oauth2=False):
        if not url:
            raise ConfigurationError(
                'History wrapper improperly configured. URL is required.')

        self.url = os.path.join(url, DATAPOINTS_ENDPOINT)
        self.check_id = check_id

        if not entities:
            self.entities = []
        elif type(entities) == list:
            self.entities = entities
        else:
            self.entities = [entities]

        self.__session = requests.Session()
        self.__session.headers.update({'Content-Type': 'application/json'})

        if oauth2:
            self.__session.headers.update(
                {'Authorization': 'Bearer {}'.format(tokens.get('uid'))})
Example #19
0
    def __init__(
        self,
        url,
        method='GET',
        params=None,
        base_url=None,
        timeout=10,
        max_retries=0,
        allow_redirects=None,
        verify=True,
        oauth2=False,
        oauth2_token_name='uid',
        headers=None,
    ):
        if method.lower() not in ('get', 'head'):
            raise CheckError(
                'Invalid method. Only GET and HEAD are supported!')

        if not base_url and not absolute_http_url(url):
            # More verbose error message!
            raise ConfigurationError(
                'HTTP wrapper improperly configured. Invalid base_url. Check entity["url"] or call with absolute url.'
            )

        self.url = (base_url + url if not absolute_http_url(url) else url)
        self.clean_url = None
        self.params = params
        self.timeout = timeout
        self.max_retries = max_retries
        self.verify = verify
        self._headers = headers or {}
        self.oauth2 = oauth2
        self.oauth2_token_name = oauth2_token_name
        self.__method = method.lower()

        self.allow_redirects = True if allow_redirects is None else allow_redirects
        if self.__method == 'head' and allow_redirects is None:
            self.allow_redirects = False

        self.__r = None
Example #20
0
    def __init__(self, bigquery_key, location='EU'):
        self._location = location

        if not bigquery_key:
            raise ConfigurationError('Bigquery key (bigquery_key) is not set.')
        self._bigquery_key = bigquery_key