

def _fetch_rrd_meta(self, connection, rrd_path_root, whitelist, field_names):
    ' Fetch metadata about each RRD in this Cacti DB, returning a list of\n            tuples of (hostname, device_name, rrd_path)\n        '

    def _in_whitelist(rrd):
        path = rrd.replace('<path_rra>/', '')
        for p in whitelist:
            if fnmatch(path, p):
                return True
        return False
    c = r.cursor()
    and_parameters = ' OR '.join([("hsc.field_name = '%s'" % field_name) for field_name in field_names])
    rrd_query = ("\n            SELECT\n                h.hostname as hostname,\n                hsc.field_value as device_name,\n                dt.data_source_path as rrd_path\n            FROM data_local dl\n                JOIN host h on dl.host_id = h.id\n                JOIN data_template_data dt on dt.local_data_id = dl.id\n                LEFT JOIN host_snmp_cache hsc on h.id = hsc.host_id\n                    AND dl.snmp_index = hsc.snmp_index\n            WHERE dt.data_source_path IS NOT NULL\n            AND dt.data_source_path != ''\n            AND (%s OR hsc.field_name is NULL) " % and_parameters)
    c.execute(rrd_query)
    res = []
    for (hostname, device_name, rrd_path) in c.fetchall():
        if ((not whitelist) or _in_whitelist(rrd_path)):
            if (hostname in ('localhost', '127.0.0.1')):
                hostname = self.hostname
            rrd_path = rrd_path.replace('<path_rra>', rrd_path_root)
            device_name = (device_name or None)
            res.append((hostname, device_name, rrd_path))
    num_hosts = len(set([r[0] for r in res]))
    self.gauge('cacti.rrd.count', len(res))
    self.gauge('cacti.hosts.count', num_hosts)
    return res

dataset/ETHPy150Open serverdensity/sd-agent/checks.d/cacti.py Cacti._fetch_rrd_meta/VarMisuse@68/146 `connection`->`r`