(self, connection, rrd_path_root, whitelist, field_names, tags)
return res
Fetch metadata about each RRD in this Cacti DB, returning a list of
        tuples of (hostname, device_name, rrd_path).
Fetch metadata about each RRD in this Cacti DB, returning a list of
        tuples of (hostname, device_name, rrd_path).
Fetch metadata about each RRD in this Cacti DB returning a list of tuples of ( hostname device_name rrd_path ) .
def _fetch_rrd_meta(self, connection, rrd_path_root, whitelist, field_names, tags):
        """Fetch metadata about each RRD in this Cacti DB, returning a list of
        tuples of (hostname, device_name, rrd_path).
        """

        def _in_whitelist(rrd):
            path = rrd.replace('<path_rra>/', '')
            for pattern in whitelist:
                if fnmatch(path, pattern):
                    return True
            return False

        c = connection.cursor()

        and_parameters = " OR ".join(["hsc.field_name = '%s'" % field_name for field_name in field_names])

        # Check for the existence of the `host_snmp_cache` table
        rrd_query = """
            SELECT
                h.hostname as hostname,
                hsc.field_value as device_name,
                dt.data_source_path as rrd_path
            FROM data_local dl
                JOIN host h on dl.host_id = h.id
                JOIN data_template_data dt on dt.local_data_id = dl.id
                LEFT JOIN host_snmp_cache hsc on h.id = hsc.host_id
                    AND dl.snmp_index = hsc.snmp_index
            WHERE dt.data_source_path IS NOT NULL
            AND dt.data_source_path != ''
            AND ({} OR hsc.field_name is NULL) """.format(
            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))

        # Collect stats
        num_hosts = len(set([r[0] for r in res]))
        self.gauge('cacti.rrd.count', len(res), tags=tags)
        self.gauge('cacti.hosts.count', num_hosts, tags=tags)

        return res
def _fetch_rrd_meta ( self , connection , rrd_path_root , whitelist , field_names , tags ) : def _in_whitelist ( rrd ) : path = rrd . replace ( '<path_rra>/' , '' ) for pattern in whitelist : if fnmatch ( path , pattern ) : return True return False c = connection . cursor ( ) and_parameters = " OR " . join ( [ "hsc.field_name = '%s'" % field_name for field_name in field_names ] ) # Check for the existence of the `host_snmp_cache` table rrd_query = """
            SELECT
                h.hostname as hostname,
                hsc.field_value as device_name,
                dt.data_source_path as rrd_path
            FROM data_local dl
                JOIN host h on dl.host_id = h.id
                JOIN data_template_data dt on dt.local_data_id = dl.id
                LEFT JOIN host_snmp_cache hsc on h.id = hsc.host_id
                    AND dl.snmp_index = hsc.snmp_index
            WHERE dt.data_source_path IS NOT NULL
            AND dt.data_source_path != ''
            AND ({} OR hsc.field_name is NULL) """ . format ( 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 ) ) # Collect stats num_hosts = len ( set ( [ r [ 0 ] for r in res ] ) ) self . gauge ( 'cacti.rrd.count' , len ( res ) , tags = tags ) self . gauge ( 'cacti.hosts.count' , num_hosts , tags = tags ) return res