Add ability to download system logs
This commit is contained in:
parent
5c7a9d0daf
commit
4ca877c1d4
9 changed files with 78 additions and 19 deletions
|
@ -23,12 +23,14 @@ import features
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
LOGS_PATH = "/var/log/%s/current"
|
||||
SERVICES_PATH = "conf/init/"
|
||||
|
||||
def get_immediate_subdirectories(directory):
|
||||
return [name for name in os.listdir(directory) if os.path.isdir(os.path.join(directory, name))]
|
||||
|
||||
def get_services():
|
||||
services = set(get_immediate_subdirectories(app.config['SYSTEM_SERVICES_PATH']))
|
||||
services = services - set(app.config['SYSTEM_SERVICE_BLACKLIST'])
|
||||
return services
|
||||
|
||||
|
||||
@resource('/v1/superuser/systemlogs/<service>')
|
||||
@internal_only
|
||||
|
@ -39,12 +41,11 @@ class SuperUserGetLogsForService(ApiResource):
|
|||
def get(self, service):
|
||||
""" Returns the logs for the specific service. """
|
||||
if SuperUserPermission().can():
|
||||
services = get_immediate_subdirectories(SERVICES_PATH)
|
||||
if not service in services:
|
||||
if not service in get_services():
|
||||
abort(404)
|
||||
|
||||
try:
|
||||
with open(LOGS_PATH % service, 'r') as f:
|
||||
with open(app.config['SYSTEM_SERVICE_LOGS_PATH'] % service, 'r') as f:
|
||||
logs = f.read()
|
||||
except Exception as ex:
|
||||
logger.exception('Cannot read logs')
|
||||
|
@ -67,7 +68,7 @@ class SuperUserSystemLogServices(ApiResource):
|
|||
""" List the system logs for the current system. """
|
||||
if SuperUserPermission().can():
|
||||
return {
|
||||
'services': get_immediate_subdirectories(SERVICES_PATH)
|
||||
'services': list(get_services())
|
||||
}
|
||||
|
||||
abort(403)
|
||||
|
|
Reference in a new issue