/ Syslog

How to generate lot of syslog messages?

I am in the process of testing several different centralised logging solutions like Splunk, LogLogic and Graylog2. All of them look very nice and almost all of them are good for the job. All of them look similar, some of them have different features, but what makes one stand out from each other is a performance.

I need something that is able to collect, index and effectively search through relatively huge amount of logs. During my testing I needed a tool that can generate lots of logs in short time just to see how the devices can handle it. Unfortunately I didn’t find anything useful so I’ve decided to write a little tool that generates a lot of random syslog messages in Python. Below is the result:

import argparse
import logging
import logging.handlers

levels = {
    'critical' : logging.CRITICAL,
    'error' : logging.ERROR,
    'warn' : logging.WARN,
    'info' : logging.INFO,
    'debug' : logging.DEBUG

# parse the options
parser = argparse.ArgumentParser()
parser.add_argument('-l', dest='level', required=True, choices=levels.keys())
parser.add_argument('-t', dest='timestamp', required=False, action='store_true')
parser.add_argument('-i', dest='ip', required=True)
args = parser.parse_args()

# setup logging handler
l = logging.getLogger()
l.addHandler(logging.handlers.SysLogHandler(address=(args.ip, 514), ))

if args.timestamp:
    msg = "Jun 08 10:46:06 "
    msg = ""

msg += "%ASA-1-666666: This is a new error message with timestamp"
l.log(levels[args.level], msg)
print("Logged %s: %s" % (levels[args.level], msg))