Created
December 19, 2014 01:15
-
-
Save bodepd/ddfeec73b99ed62fae64 to your computer and use it in GitHub Desktop.
log grabber
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import consulate | |
import sys | |
#import scp | |
import os | |
import time | |
class Processor: | |
def __init__(self, host='127.0.0.1', port=8500): | |
self.host = host | |
self.port = port | |
self._consul = None | |
self._kv = None | |
self.dir = time.time() | |
self.stats = {} | |
@property | |
def consul(self): | |
if not self._consul: | |
self._consul = session = consulate.Consulate(self.host, self.port) | |
return self._consul | |
def get_members(self): | |
return self.consul.agent.members() | |
def get_logs(self, members): | |
for m in members: | |
self.get_host_logs(m['Name'], m['Addr']) | |
def get_host_logs(self, name, addr): | |
hostdir = "%s/%s" % (self.dir, name) | |
if not os.path.exists(hostdir): | |
os.makedirs(hostdir) | |
os.system('scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no %s:%s %s/' % (addr, '/var/log/cloud-init-output.log', hostdir) ) | |
os.system('scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no %s:%s %s/' % (addr, '/var/log/syslog', hostdir) ) | |
def get_stats(self, name): | |
self.stats[name] = {} | |
hostdir = "%s/%s" % (self.dir, name) | |
cloud_init_log = "%s/%s" % (hostdir, '/var/log/cloud-init-output.log') | |
sys_log = "%s/%s" % (hostdir, '/var/log/syslog') | |
#f=open(cloud_init_log,'r') | |
#f_array = f.readlines() | |
#for l in f.readlines(): | |
# if l =~ /'modules:final' at (.*)/ | |
def main(argv=sys.argv[1:]): | |
p = Processor() | |
members = p.get_members() | |
p.get_logs(members) | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv[1:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment