3 # vim: ts=4 sw=4 smarttab expandtab
13 logging.basicConfig(level=logging.INFO)
14 log = logging.getLogger(__name__)
16 auth_names = ['client.crash.%s' % socket.gethostname(),
21 parser = argparse.ArgumentParser()
23 '-p', '--path', default='/var/lib/ceph/crash',
24 help='base path to monitor for crash dumps')
26 '-d', '--delay', default=10.0, type=float,
27 help='minutes to delay between scans (0 to exit after one)',
31 help='ceph name to authenticate as (default: try client.crash, client.admin)')
32 return parser.parse_args()
38 pr = subprocess.Popen(
39 args=['timeout', '30', 'ceph',
41 'crash', 'post', '-i', '-'],
42 stdin=subprocess.PIPE,
43 stdout=subprocess.PIPE,
44 stderr=subprocess.PIPE,
46 f = open(os.path.join(path, 'meta'), 'rb')
47 stdout, stderr = pr.communicate(input=f.read())
51 log.warning('post %s as %s failed: %s' % (path, n, stderr))
57 def scrape_path(path):
58 for p in os.listdir(path):
59 crashpath = os.path.join(path, p)
60 metapath = os.path.join(crashpath, 'meta')
61 donepath = os.path.join(crashpath, 'done')
62 if os.path.isfile(metapath):
63 if not os.path.isfile(donepath):
64 # hang out just for a bit; either we interrupted the dump
65 # or the daemon crashed before finishing it
67 if not os.path.isfile(donepath):
69 # ok, we can process this one
70 rc = post_crash(crashpath)
72 os.rename(crashpath, os.path.join(path, 'posted/', p))
74 "posted %s and renamed %s -> %s " %
75 (metapath, p, os.path.join('posted/', p))
81 postdir = os.path.join(args.path, 'posted')
83 auth_names = [args.name]
85 while not os.path.isdir(postdir):
86 log.error("directory %s does not exist; please create" % postdir)
89 log.info("monitoring path %s, delay %ds" % (args.path, args.delay * 60.0))
91 scrape_path(args.path)
94 time.sleep(args.delay * 60)
97 if __name__ == "__main__":