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
|
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
|
-
+
-
-
-
-
-
-
-
-
-
-
-
+
|
#!/usr/bin/env python
# -*- Mode: Python; -*-
## Tiny Syslog Server in Python.
##
## This is a tiny syslog server that is able to receive UDP based syslog
## entries on a specified port and save them to a file.
## That's it... it does nothing else...
## There are a few configuration parameters.
import os
import sys, os, time, atexit
from signal import SIGTERM
import logging
import logging.handlers
import SocketServer
import datetime
from subprocess import call
import argparse
LOG_FILE = '/p/foundry/fdk-env/icfenv-logserver/icfenv_logit.log'
if os.environ['USER'] == 'bjbarcla':
LOG_FILE = "/nfs/pdx/disks/icf_env_disk001/bjbarcla/gwa/issues/mtdev/icebin/foo.log"
PID_FILE = LOG_FILE + ".pidfile"
server_config = os.path.realpath(os.path.join(os.path.dirname(__file__))) + "/logserver_icfenv.conf"
import os
import socket
## code to determine this host's IP on non-loopback interface
if os.name != "nt":
import fcntl
import struct
def get_interface_ip(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s',
|
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
-
+
-
-
-
-
-
-
|
def run(self):
"""
You should override this method when you subclass Daemon. It will be called after the process has been
daemonized by start() or restart().
"""
# setup logging module so that the log can be moved aside and will reopen for append
def log_setup(logfile):
log_handler = logging.handlers.WatchedFileHandler(logfile)
formatter = logging.Formatter(
'%(message)s','')
#formatter.converter = time.gmtime # if you want UTC time
log_handler.setFormatter(formatter)
logger = logging.getLogger()
logger.addHandler(log_handler)
logger.setLevel(logging.INFO)
#
# NO USER SERVICEABLE PARTS BELOW HERE...
#
class SyslogUDPHandler(SocketServer.BaseRequestHandler):
def handle(self):
data = bytes.decode(self.request[0].strip())
socket = self.request[1]
print( "%s : " % self.client_address[0], str(data))
timestamp = datetime.datetime.now().isoformat()
|