-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_server
65 lines (50 loc) · 1.64 KB
/
log_server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler
from configparser import ConfigParser
import sys, time
from enum import Enum
if len( sys.argv) != 1:
print ( "Usage: python log_server.py")
sys.exit( 0)
config = ConfigParser()
config.read( "/etc/log_server.cfg")
colour_tags = {
'red': '\033[31m',
'blue': '\033[34m',
'green': '\033[32m',
'cyan': '\033[36m'
}
class control_tags:
BOLD = '\033[1m'
ENDC = '\033[0m'
def log( colour, text):
ctime = time.strftime( "%X", time.localtime())
if colour == "default":
print( "%s: %s" % (ctime, text))
elif colour in colour_tags:
fmt = '%s: ' + colour_tags[colour] + control_tags.BOLD + '%s' + control_tags.ENDC
print( fmt % (ctime, text))
else:
return "Unknown colour '%s'" % (colour)
return ''
# Restrict to a particular path.
class RequestHandler( SimpleXMLRPCRequestHandler):
rpc_paths = ( '/RPC2',)
# Create server
server = SimpleXMLRPCServer( (config.get( 'common', 'server_ip'),
int( config.get( 'common', 'server_port'))),
requestHandler = RequestHandler,
logRequests = False)
server.register_introspection_functions()
# Register an instance; all the methods of the instance are
# published as XML-RPC methods.
class LogServer:
def __init__( self):
self.cookie = 0x123456;
self.refcount = {}
def Log( self, colour, text):
return log( colour, text)
server.register_instance( LogServer())
# Run the server's main loop
server.serve_forever()