pvl/rrd/hosts.py
changeset 425 4e828d47421a
parent 235 a34e7260568b
child 428 956b3d4918bb
--- a/pvl/rrd/hosts.py	Sun Sep 07 14:21:56 2014 +0300
+++ b/pvl/rrd/hosts.py	Sun Sep 07 14:22:47 2014 +0300
@@ -53,6 +53,12 @@
                 host, node = host.split('=')
             else :
                 node = host
+
+            if '@' in node :
+                node, node_domain = node.split('@')
+            else:
+                # as for collectd host
+                node_domain = domain
             
             # host has domain in collectd?
             if domain :
@@ -62,56 +68,50 @@
             # keep host for following lines
             continue
 
-        iface = parts.pop(0)
+        instance = parts.pop(0)
  
         # possibly multiple tags..
         for tag in parts :
-            yield host, node, iface, tag
+            yield host, instance, (node_domain, node, tag)
 
 def map_interfaces (options, file):
     """
-        Read (hostname, interface}: (nodename, tag) pairs from file.
+        Read (hostname, instance}: (nodename, tag) pairs from file.
     """
 
-    for host, node, iface, tag in load(file) :
-        log.debug("%s/%s -> %s/%s", host, iface, node, tag)
-        yield (host, iface), (node, tag)
+    for host, instance, node_info in load(file) :
+        log.debug("%s/%s -> %s", host, instance, node_info)
+        yield (host, instance), node_info
 
 def collectd_interfaces (options, file, collectd_domain, collectd_plugin) :
     """
-        Read collectd (host, type-instance, name) items, and yield (collectd-rrd, out-rrd) tuples.
+        Read collectd (host, instance, (domain, node, tag)) items, and yield (collectd-rrd, node_info) tuples.
             
             file                - read host/ports from file
             collectd_domain     - append given domain to collectd hostname
             collectd_plugin     - use given collectd plugin's type-instances
     """
 
-    log.info("scanning %s/<host>.%s/%s/%s-<port>.rrd", options.collectd_rrd, collectd_domain, collectd_plugin, options.collectd_type)
+    log.info("%s/${host}.%s/%s/%s-${instance}.rrd", options.collectd_rrd, collectd_domain, collectd_plugin, options.collectd_type)
 
-    for collectd_host, interface_host, port, tag in load(file, domain=collectd_domain) :
-        # flip from DNS-ordering -> path-ordering
-        if options.reverse_host :
-            interface_host = hostreverse(interface_host)
-
+    for host, instance, node_info in load(file, domain=collectd_domain) :
         if options.collectd_instance == 'type' :
-            type = options.collectd_type + '-' + port
+            type = options.collectd_type + '-' + instance
         else :
             type = options.collectd_type
 
         if options.collectd_instance == 'plugin' :
-            plugin = collectd_plugin + '-' + port
+            plugin = collectd_plugin + '-' + instance
         else :
             plugin = collectd_plugin
 
-        collectd_rrd = os.path.join(options.collectd_rrd, collectd_host, plugin, type) + '.rrd'
+        rrd = os.path.join(options.collectd_rrd, host, plugin, type) + '.rrd'
 
-        if not os.path.exists(collectd_rrd) :
-            log.warn("%s/%s: missing collectd rrd: %s", collectd_host, port, collectd_rrd)
+        if not os.path.exists(rrd) :
+            log.warn("%s/%s: missing collectd rrd: %s", host, instance, rrd)
             continue
 
         # out
-        interface_rrd = os.path.join(interface_host, tag + '.rrd')
+        log.debug("%s: %s", rrd, node_info)
 
-        log.debug("%s: %s", interface_rrd, collectd_rrd)
-
-        yield collectd_rrd, interface_rrd
+        yield rrd, node_info