I added some fields to some existing code, and all was well. Just added a few more, and BAM. I've looked this over forever, but being a newbie to Python, I see NOTHING. The code generates syslog messages, and the new fields were added around "rtp_lapse*" . Any clues???
#!/usr/bin/python
__author__ = 'GMS'
import socket
import datetime
import time
import random
import math
import signal
stop = False
def handler(signum, frame):
print ('Signal handler called with signal'), signum
global stop
stop = True
time.sleep(30)
# Set the signal handler and a 5-second alarm
signal.signal(signal.SIGINT, handler)
# Read Global Cell Ids into a list
global_cell_ids = []
global_cell_id_count = 0
wfile = open('globalcellids_volte.csv', 'r')
for line in wfile:
row = line.rsplit('\n')
# print 'row: ', row
global_cell_ids.append(row[0])
global_cell_id_count += 1
wfile.close()
# 20 percentage syslog
syslog_count = global_cell_id_count * 20 / 100
UDP_IP = "127.0.0.1"
UDP_PORT = 10516
gtp_ver = '2'
loc_type = '4'
hostname = socket.gethostname()
sock = None
# Infinite Loop
while not stop:
# Get the timestamp
now = datetime.datetime.now()
timestamp = now.strftime("%b %d %X")
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except socket.error as msg:
print (timestamp), msg
sock = None
continue
try:
sock.connect((UDP_IP, UDP_PORT))
except socket.error as msg:
print (timestamp), msg
sock.close()
sock = None
continue
else:
if sock is not None:
log_cell_id = []
send = True
for i in range(0, syslog_count):
# index = random.randint(0, global_cell_id_count-1)
index = random.randint(0, 400)
while log_cell_id.count(index) != 0:
index = random.randint(0, 400)
#index = random.randint(0, global_cell_id_count-1)
log_cell_id.append(index)
row = global_cell_ids[index]
cols = row.split(',')
t_int = 30000
ul_data_vol = int(random.randint(50, 200))
dl_data_vol = int(random.randint(50, 200))
ul_volte_vol = int(random.randint(28, 40))
dl_volte_vol = int(random.randint(28, 40))
rtp_lapses1 = int(random.randint(0, 8))
rtp_lapses2 = int(random.randint(0, 8))
rtp_lapses3 = int(random.randint(0, 8))
rtp_lapses4 = int(random.randint(0, 8))
rtp_lapses5 = int(random.randint(0, 8))
rtp_lapses6 = int(random.randint(0, 8))
rtp_lapses7 = int(random.randint(0, 8))
rtp_lapses8 = int(random.randint(0, 8))
rtp_lapses9 = int(random.randint(0, 8))
rtp_lapses10 = int(random.randint(0, 8))
total_segments = 1000
pkt_loss_seconds = int(random.randint(0, 15))
rtp_call_seconds = int(random.randint(0, 15))
rtp_calls_analyzed = int(random.randint(0, 15))
rtp_calls_detected = int(random.randint(0, 15))
fmt_syslog = timestamp + ' ' + hostname + ' gtp_ver=' + gtp_ver
fmt_syslog += ' loc_type=' + loc_type + ' cell_id=' + cols[0]
fmt_syslog += ' ul_data_vol=' + str(ul_data_vol) + ' dl_data_vol=' + str(dl_data_vol)
fmt_syslog += ' ul_volte_vol=' + str(ul_volte_vol) + ' dl_volte_vol=' + str(dl_volte_vol)
fmt_syslog += ' rtp_lapses1=' + str(rtp_lapses1)
fmt_syslog += ' rtp_lapses2=' + str(rtp_lapses2)
fmt_syslog += ' rtp_lapses3=' + str(rtp_lapses3)
fmt_syslog += ' rtp_lapses4=' + str(rtp_lapses4)
fmt_syslog += ' rtp_lapses5=' + str(rtp_lapses5)
fmt_syslog += ' rtp_lapses6=' + str(rtp_lapses6)
fmt_syslog += ' rtp_lapses7=' + str(rtp_lapses7)
fmt_syslog += ' rtp_lapses8=' + str(rtp_lapses8)
fmt_syslog += ' rtp_lapses9=' + str(rtp_lapses9)
fmt_syslog += ' rtp_lapses10=' + str(rtp_lapses10)
fmt_syslog += ' total_segments=' + str(total_segments)
fmt_syslog += ' pkt_loss_seconds=' + str(pkt_loss_seconds)
fmt_syslog += ' rtp_call_seconds=' + str(rtp_call_seconds)
fmt_syslog += ' rtp_calls_analyzed=' + str(rtp_calls_analyzed)
fmt_syslog += ' rtp_calls_detected=' + str(rtp_calls_detected)
try:
if send:
sock.send(fmt_syslog)
except socket.error as msg:
print (timestamp), msg
send = False
sock.close()
sock = None
break
if sock is not None:
sock.close()
"""
Sleep for 30 seconds and generate syslog again
"""
time.sleep(30)