diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ogClient.py | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/ogClient.py b/src/ogClient.py index c4dcd7e..9f914c4 100644 --- a/src/ogClient.py +++ b/src/ogClient.py @@ -60,21 +60,47 @@ class ogClient: def send_event_hint(self, message): try: - event, action, user = message.split(" ") - logging.debug('Sending event: %s, %s, %s', event, action, user) + event = message.split(' ', 1)[0] except: - logging.warning('Error parsing session datagram') + logging.exception('Error parsing event from datagram') return - if (event != "session" or - action not in ['start', 'stop'] or - not user): - logging.warning('Invalid value in session datagram: %s', message) + if (self.mode == 'live' and + event not in ['boot', 'poweroff', 'reboot']): + logging.warning('Unsupported event for live mode') + logging.warning(f'Parsed event: {event}') + logging.warning(f'Received message: {message}') + return + elif (self.mode in ['windows', 'linux'] and + event != 'session'): + logging.warning('Unsupported event for windows/linux mode') + logging.warning(f'Received event: {message}') + return - payload = jsonBody({'event': event, 'action': action, 'user': user}) - response = restResponse(ogResponses.EARLY_HINTS, payload) - self.send(response.get()) - logging.debug('Sending event OK') + payload = jsonBody({'event': event}) + + if event == 'session': + try: + _, action, user = message.split(' ') + except: + logging.exception('Error parsing rest of session event datagram') + return + payload = jsonBody({'event': event, 'action': action, 'user': user}) + response = restResponse(ogResponses.EARLY_HINTS, payload) + self.send(response.get()) + elif event == 'boot': + request = restRequest() + try: + _, disk, partition = message.split(' ') + request.disk = disk + request.partition = partition + self.ogrest.operations.session(request, self.ogrest) + except: + logging.exception('Error parsing rest of boot event datagram') + elif event == 'poweroff': + self.ogrest.operations.poweroff() + elif event == 'reboot': + self.ogrest.operations.reboot() def cleanup(self): self.data = "" |