Beispiel #1
0
    def query2(self, sql, sql_params=None, database=None, dict_output=False):
        formatted_sql = format_sql(sql, sql_params)

        self.logger.debug('[INFLUXDB] Query2 {}'.format(
            re.sub('\s+', ' ', formatted_sql, flags=re.M)))

        try:
            db_res = self.client.query(formatted_sql, database=database)

        except Exception as e:
            for line in traceback.format_exc().splitlines():
                self.logger.error(line)

            raise

        else:
            is_list = isinstance(db_res, (list, tuple))
            db_res = toolkit.as_array(db_res)
            db_res_list = None
            if dict_output is False:
                db_res_list = [x.raw for x in db_res]
            else:
                db_res_list = [self.convert_to_dict(x) for x in db_res]

            if is_list:
                return db_res_list
            else:
                return db_res_list[0]
def get_config(c):
    servers = c.get('servers') or None
    if servers and isinstance(servers, (six.string_types, six.text_type)):
        servers = servers.split(',')

    servers = servers or '127.0.0.1:11211'
    servers = toolkit.as_array(servers)

    return servers
Beispiel #3
0
    def send_text(self, text, is_at_all=False, at_mobiles=[]):
        data = {"msgtype": "text", "at": {}}
        if not toolkit.is_none_or_white_space(text):
            data["text"] = {"content": text}

        if is_at_all:
            data["at"]["isAtAll"] = is_at_all

        if at_mobiles:
            at_mobiles = toolkit.as_array(at_mobiles)
            data["at"]["atMobiles"] = at_mobiles

        return self.client(data)
Beispiel #4
0
    def send_markdown(self, title, text, is_at_all=False, at_mobiles=[]):
        data = {"msgtype": "markdown", "markdown": {}, "at": {}}
        if not toolkit.is_none_or_white_space(
                title) and not toolkit.is_none_or_white_space(text):
            data['markdown']['title'] = title
            data['markdown']['text'] = text

        if is_at_all:
            data["at"]["isAtAll"] = is_at_all

        if at_mobiles:
            at_mobiles = toolkit.as_array(at_mobiles)
            data["at"]["atMobiles"] = at_mobiles

        return self.client(data)
def get_config(c):
    fixed_nsq_nodes = c.get('fixedNSQNodes') or c.get('servers') or None
    if fixed_nsq_nodes and isinstance(fixed_nsq_nodes,
                                      (six.string_types, six.text_type)):
        fixed_nsq_nodes = fixed_nsq_nodes.split(',')

    fixed_nsq_nodes = fixed_nsq_nodes or None
    fixed_nsq_nodes = toolkit.as_array(fixed_nsq_nodes)

    config = {
        'host': c.get('host') or '127.0.0.1',
        'port': c.get('port') or 4161,
        'protocol': c.get('protocol') or 'http',
        'timeout': c.get('timeout') or 3,
        'fixedNSQNodes': fixed_nsq_nodes,
    }
    return config
Beispiel #6
0
    def write_points(self, points, database=None):
        points = toolkit.as_array(points)
        if not points:
            return

        self.logger.debug('[INFLUXDB] Write: {} points'.format(len(points)))

        try:
            db_res = self.client.write_points(points, database=database)

        except Exception as e:
            for line in traceback.format_exc().splitlines():
                self.logger.error(line)

            raise

        else:
            return db_res
Beispiel #7
0
    def query(self, sql, bind_params=None, database=None, dict_output=False):
        formatted_query = sql + ' '
        if bind_params:
            for k, v in bind_params.items():
                _placeholder = u'\${}([^a-zA-Z0-9_-])'.format(k)
                _value = u'{}\\1'.format(v)

                if isinstance(v, (six.string_types, six.text_type)):
                    _value = u"'{}'".format(_value)

                formatted_query = re.sub(_placeholder, _value, formatted_query)

        formatted_query = formatted_query.strip()

        self.logger.debug('[INFLUXDB] Query {}'.format(
            re.sub('\s+', ' ', formatted_query, flags=re.M)))

        try:
            db_res = self.client.query(sql,
                                       bind_params=bind_params,
                                       database=database)

        except Exception as e:
            for line in traceback.format_exc().splitlines():
                self.logger.error(line)

            raise

        else:
            is_list = isinstance(db_res, (list, tuple))
            db_res = toolkit.as_array(db_res)
            db_res_list = None
            if dict_output is False:
                db_res_list = [x.raw for x in db_res]
            else:
                db_res_list = [self.convert_to_dict(x) for x in db_res]

            if is_list:
                return db_res_list
            else:
                return db_res_list[0]