Update
This commit is contained in:
parent
3d493d084e
commit
354f9a2960
@ -47,6 +47,7 @@ class FSCLogger:
|
|||||||
self.token = None
|
self.token = None
|
||||||
self.chat_id = None
|
self.chat_id = None
|
||||||
self.base_url = None
|
self.base_url = None
|
||||||
|
self.logfile = None
|
||||||
self.log("starting")
|
self.log("starting")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -128,7 +129,63 @@ class FSCLogger:
|
|||||||
]
|
]
|
||||||
|
|
||||||
self.return_and_exit(Response(id=request.id, result=info))
|
self.return_and_exit(Response(id=request.id, result=info))
|
||||||
|
case 'SetConfig':
|
||||||
|
missing_fields = []
|
||||||
|
invalid_fields = []
|
||||||
|
|
||||||
|
if not request.params:
|
||||||
|
self.return_and_exit(Response(id=request.id, error="invalid config (missing parameters)"))
|
||||||
|
conf = request.params
|
||||||
|
|
||||||
|
# check for required fields
|
||||||
|
if not 'logfile' in conf:
|
||||||
|
missing_fields.append('logfile')
|
||||||
|
|
||||||
|
if len(missing_fields) > 0:
|
||||||
|
# return an error as at least one required field seems missing
|
||||||
|
self.return_and_exit(Response(id=request.id, error="invalid config (missing required field(s) '{}'"
|
||||||
|
")".format(', '.join(missing_fields))))
|
||||||
|
# validate fields
|
||||||
|
if len(conf['logfile']) < 4:
|
||||||
|
invalid_fields.append('logfile')
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
test = int(conf['logfile'])
|
||||||
|
except ValueError as _:
|
||||||
|
invalid_fields.append('logfile')
|
||||||
|
|
||||||
|
if len(invalid_fields) > 0:
|
||||||
|
# return an error as at least one field seems invalid
|
||||||
|
self.return_and_exit(Response(id=request.id, error="invalid config (invalid field(s) '{}'"
|
||||||
|
")".format(', '.join(invalid_fields))))
|
||||||
|
|
||||||
|
# set configuration to current instance
|
||||||
|
self.logfile = conf['logfile']
|
||||||
|
|
||||||
|
# all good
|
||||||
|
self.return_and_continue(Response(id=request.id))
|
||||||
|
case 'SendNotification':
|
||||||
|
# check for required payload
|
||||||
|
if not request.params:
|
||||||
|
self.return_and_exit(Response(id=request.id, error="invalid notification (missing parameters)"))
|
||||||
|
notification = request.params
|
||||||
|
|
||||||
|
# check if notification payload contains a linked object
|
||||||
|
if not 'object' in notification:
|
||||||
|
self.return_and_exit(Response(id=request.id, error="notification is missing its linked object."))
|
||||||
|
|
||||||
|
## Log to file
|
||||||
|
f = open(self.logfile, "a")
|
||||||
|
f.write("Now the file has more content!")
|
||||||
|
f.close()
|
||||||
|
self.log("getting data %s" % notification)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.return_and_continue(Response(id=request.id))
|
||||||
|
case _:
|
||||||
|
self.log("request method unknown: {}".format(request.method))
|
||||||
|
self.return_and_exit(Response(id=request.id, error="invalid request (method unknown)"))
|
||||||
|
|
||||||
# run entrypoint
|
# run entrypoint
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user