--- a/bin/pvl.rrd-interfaces Sun Sep 07 14:21:56 2014 +0300
+++ b/bin/pvl.rrd-interfaces Sun Sep 07 14:22:47 2014 +0300
@@ -79,23 +79,27 @@
return options, args
-def sync_links (options, links, dir) :
+def sync_links (options, links, rrddir) :
"""
Sync given (collectd, name) symlinks in given dir.
"""
- log.info("%s", dir)
+ log.info("%s", rrddir)
- for path, name in links :
- link = os.path.join(dir, name)
+ for rrdpath, (domain, host, port) in links :
+ linkpath = os.path.join(rrddir,
+ hostreverse(domain) if options.reverse_host else domain,
+ hostreverse(host) if options.reverse_host else host,
+ port + '.rrd'
+ )
# sync
- if os.path.exists(link) :
+ if os.path.exists(linkpath) and os.path.readlink(linkpath) == rrdpath :
continue
- log.info("%s: %s: %s", dir, name, path)
+ log.info("%s: %s", linkpath, rrdpath)
- yield link, path
+ yield linkpath, rrdpath
def apply_links (options, links) :
"""
@@ -107,10 +111,8 @@
# do
if not os.path.exists(linkdir) :
- log.warn("mkdir: %s", linkdir)
- os.mkdir(linkdir)
-
- print path
+ log.warn("makedirs: %s", linkdir)
+ os.makedirs(linkdir)
os.symlink(path, link)
@@ -140,10 +142,9 @@
# output dir?
if options.rrd :
- rrd_domain = hostreverse(domain) if options.reverse_host else domain
- rrd = os.path.join(options.rrd, rrd_domain)
+ rrddir = options.rrd
else :
- rrd = basepath
+ rrddir = basepath
# generate links from spec
links = list(pvl.rrd.hosts.collectd_interfaces(options, open(txt),
@@ -151,15 +152,13 @@
collectd_plugin = options.collectd_plugin or collectd_plugin or COLLECTD_PLUGIN,
))
- if not os.path.exists(rrd) :
- log.warn("mkdir: %s", rrd)
+ if not os.path.exists(rrddir) :
+ log.error("given --rrd must already exist: %s", rrddir)
+ return 1
- if not options.noop :
- os.mkdir(rrd)
-
# sync missing links
links = list(sync_links(options, links,
- dir = rrd,
+ rrddir = rrddir,
))
# verbose