mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-10 01:17:42 +01:00
Add cbpi service logfile download via journalctl
This commit is contained in:
parent
206eff88f5
commit
563fae9359
4 changed files with 55 additions and 3 deletions
|
@ -1 +1 @@
|
|||
__version__ = "4.0.0.57"
|
||||
__version__ = "4.0.0.58"
|
||||
|
|
|
@ -109,7 +109,7 @@ class SatelliteController:
|
|||
async with AsyncExitStack() as stack:
|
||||
self.tasks = set()
|
||||
stack.push_async_callback(cancel_tasks, self.tasks)
|
||||
self.client = Client(self.host, port=self.port, username=self.username, password=self.password, will=Will(topic="cbpi/diconnect", payload="CBPi Server Disconnected"))
|
||||
self.client = Client(self.host, port=self.port, username=self.username, password=self.password, will=Will(topic="cbpi/disconnect", payload="CBPi Server Disconnected"))
|
||||
|
||||
await stack.enter_async_context(self.client)
|
||||
|
||||
|
|
|
@ -40,6 +40,24 @@ class SystemController:
|
|||
dir_name = pathlib.Path(os.path.join(".", 'config'))
|
||||
shutil.make_archive(output_filename, 'zip', dir_name)
|
||||
|
||||
async def downloadlog(self, logtime):
|
||||
filename = "cbpi4.log"
|
||||
fullname = pathlib.Path(os.path.join(".",filename))
|
||||
output_filename="cbpi4_log.zip"
|
||||
if logtime == "b":
|
||||
os.system('journalctl -b -u craftbeerpi.service > {}'.format(fullname))
|
||||
else:
|
||||
os.system('journalctl --since \"{} hours ago\" -u craftbeerpi.service > {}'.format(logtime, fullname))
|
||||
|
||||
zipObj=zipfile.ZipFile(output_filename , 'w', zipfile.ZIP_DEFLATED)
|
||||
zipObj.write(fullname)
|
||||
zipObj.close()
|
||||
os.remove(fullname)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def allowed_file(self, filename, extension):
|
||||
return '.' in filename and filename.rsplit('.', 1)[1] in set([extension])
|
||||
|
||||
|
|
|
@ -146,6 +146,40 @@ class SystemHttpEndpoints:
|
|||
await response.write_eof()
|
||||
return response
|
||||
|
||||
|
||||
@request_mapping("/log/{logtime}/", method="GET", name="BackupConfig", auth_required=False)
|
||||
async def downloadlog(self, request):
|
||||
"""
|
||||
---
|
||||
description: Zip and download craftbeerpi.service log
|
||||
tags:
|
||||
- System
|
||||
responses:
|
||||
"200":
|
||||
description: successful operation
|
||||
content: # Response body
|
||||
application/zip: # Media type
|
||||
"""
|
||||
logtime = request.match_info['logtime']
|
||||
await self.controller.downloadlog(logtime)
|
||||
filename = "cbpi4_log.zip"
|
||||
file_name = pathlib.Path(os.path.join(".", filename))
|
||||
|
||||
response = web.StreamResponse(
|
||||
status=200,
|
||||
reason='OK',
|
||||
headers={'Content-Type': 'application/zip'},
|
||||
)
|
||||
await response.prepare(request)
|
||||
with open(file_name, 'rb') as file:
|
||||
for line in file.readlines():
|
||||
await response.write(line)
|
||||
|
||||
await response.write_eof()
|
||||
os.remove(file_name)
|
||||
return response
|
||||
|
||||
|
||||
@request_mapping("/restore", method="POST", name="RestoreConfig", auth_required=False)
|
||||
async def restore(self, request):
|
||||
"""
|
||||
|
@ -192,4 +226,4 @@ class SystemHttpEndpoints:
|
|||
data = await request.post()
|
||||
logging.info("Data received")
|
||||
await self.controller.uploadSVG(data)
|
||||
return web.Response(status=200)
|
||||
return web.Response(status=200)
|
||||
|
|
Loading…
Reference in a new issue