bin/pvl.rrd-interfaces
changeset 430 e928258a1229
parent 426 b2078645456a
equal deleted inserted replaced
429:f1d0c5e0fdeb 430:e928258a1229
   117         os.symlink(path, link)
   117         os.symlink(path, link)
   118 
   118 
   119 def main (argv) :
   119 def main (argv) :
   120     options, args = parse_argv(argv)
   120     options, args = parse_argv(argv)
   121     
   121     
   122     for txt in args :
   122     for path in args :
   123         # <path>/<domain>-<plugin>.txt -> <path>/<domain>-<plugin>
   123         # <path>/<domain>-<plugin>.txt -> <path>/<domain>-<plugin>
   124         basepath, _ = os.path.splitext(txt)
   124         if '.txt' in path:
       
   125             basepath, _ = os.path.splitext(path)
       
   126         else:
       
   127             basepath = path
       
   128         
       
   129         # <path>/<domain> -> <domain>
       
   130         _, basename = os.path.split(basepath)
   125         
   131         
   126         # <path>/<domain>-<plugin> -> <path>/<domain>, <plugin>
   132         # <path>/<domain>-<plugin> -> <path>/<domain>, <plugin>
   127         if '-' in basepath :
   133         if '-' in basename :
   128             basepath, collectd_plugin = basepath.rsplit('-', 1)
   134             basename, collectd_plugin = basename.rsplit('-', 1)
   129         else :
   135         else :
   130             collectd_plugin = None
   136             collectd_plugin = None
   131 
       
   132         # <path>/<domain> -> <domain>
       
   133         _, basename = os.path.split(basepath)
       
   134         
   137         
   135         # domain?
   138         # domain?
   136         if options.domain is None :
   139         if options.domain is None :
   137             # reverse-order hostname
   140             # reverse-order hostname
   138             domain = hostreverse(basename)
   141             domain = hostreverse(basename)
   139         else :
   142         else :
   140             # may be ''
   143             # may be ''
   141             domain = options.domain
   144             domain = options.domain
   142         
   145         
   143         # output dir?
   146         # output dir?
   144         if options.rrd :
   147         if not options.rrd:
   145             rrddir = options.rrd
   148             log.error("no --rrd output dir given")
   146         else :
   149             return 1
   147             rrddir = basepath
   150 
       
   151         rrddir = options.rrd
   148 
   152 
   149         # generate links from spec
   153         # generate links from spec
   150         links = list(pvl.rrd.hosts.collectd_interfaces(options, open(txt),
   154         links = list(pvl.rrd.hosts.collectd_interfaces(options, open(path),
   151             collectd_domain     = domain,
   155             collectd_domain     = domain,
   152             collectd_plugin     = options.collectd_plugin or collectd_plugin or COLLECTD_PLUGIN,
   156             collectd_plugin     = options.collectd_plugin or collectd_plugin or COLLECTD_PLUGIN,
   153         ))
   157         ))
   154 
   158 
   155         if not os.path.exists(rrddir) :
   159         if not os.path.exists(rrddir) :