Commit 6c8d5c52 authored by Kristopher Ruzic's avatar Kristopher Ruzic

Now uploads log files

Uses a slapos webrunner as the server. Pretty simple but it does its job. Can be set as a cron for every 5 seconds, or I'll add a sleep()
parent f1fe241b
#!/usr/bin/python2.7 #!/usr/bin/python2.7
import os
import sys import sys
import time import time
import requests import requests
...@@ -26,16 +27,40 @@ def dir_date(): ...@@ -26,16 +27,40 @@ def dir_date():
class uploader(): class uploader():
url = 'http://[2001:67c:1254:e:a9::bafb]:9000/post' url = 'http://[2001:67c:1254:e:a9::bafb]:9000/post'
# takes a file name and contents to append. Generates server file_path (where it should be saved on server) # takes a file name and contents to append. Generates server file_path (where it should be saved on server)
def upload_file(self, file_name, contents): def upload_file(self, file_name, contents):
values = {'file_path': dir_date() + file_name, 'contents': contents} values = {'file_path': dir_date() + file_name, 'contents': contents}
r = requests.post(self.url, data=values) r = requests.post(self.url, data=values)
def scan_files(files):
try:
with open("lines", 'r') as myfile:
software_line = myfile.readlines()
except:
software_line = [0] * len(files)
with open("lines", 'w'):
pass
place = 0
for f in files:
print software_line[place]
print software_line
with open(f, 'r') as myfile:
new_lines = myfile.readlines()[software_line[place]:]
with open("lines", 'a') as myfile:
myfile.write(str(software_line[place]) + str(len(new_lines)))
print "Uploading " + f + "..."
c.upload_file(os.path.basename(f), new_lines)
print f + " finished uploading!"
place += 1
print "Files uploaded"
if __name__ == "__main__": if __name__ == "__main__":
c = uploader() c = uploader()
c.upload_file("blah", "new test content") files = ["/opt/slapos/log/slapos-node-software.log", "/opt/slapos/log/slapos-node-format.log", "/opt/slapos/log/slapos-node-instance.log"]
scan_files(files)
# event_handler = MyHandler() # event_handler = MyHandler()
# observer = Observer() # observer = Observer()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment