Ahenk/opt/ahenk/base/messaging/Messaging.py

52 lines
1.7 KiB
Python
Raw Normal View History

2016-02-16 17:50:37 +02:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
2016-02-16 17:50:37 +02:00
import sys,pwd,os
import datetime,json
sys.path.append('../..')
from base.Scope import Scope
2016-02-16 17:50:37 +02:00
class Messaging(object):
2016-02-16 17:50:37 +02:00
2016-02-21 03:24:54 +02:00
def __init__(self):
2016-03-08 18:05:42 +02:00
scope = Scope().getInstance()
self.logger = scope.getLogger()
self.configurationManager = scope.getConfigurationManager()
self.event_manger=scope.getEventManager()
2016-03-08 18:05:42 +02:00
#TODO can use sh commands for getting username and timestamp
def login_msg(self):
data = {}
2016-03-08 18:05:42 +02:00
data['type'] = 'LOGIN'
data['username'] = str(pwd.getpwuid( os.getuid() )[ 0 ])
data['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))
json_data = json.dumps(data)
return json_data
def logout_msg(self):
data = {}
2016-03-08 18:05:42 +02:00
data['type'] = 'LOGOUT'
data['username'] = str(pwd.getpwuid( os.getuid() )[ 0 ])
data['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))
json_data = json.dumps(data)
return json_data
def get_policies_msg(self):
data = {}
2016-03-08 18:05:42 +02:00
data['type'] = 'GET_POLICIES'
data['username'] = str(pwd.getpwuid( os.getuid() )[ 0 ])
data['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))
json_data = json.dumps(data)
return json_data
def unregister_msg(self):
data = {}
2016-03-08 18:05:42 +02:00
data['type'] = 'UNREGISTER'
data['username'] = str(pwd.getpwuid( os.getuid() )[ 0 ])
data['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))
json_data = json.dumps(data)
return json_data