forked from HHS/TANF-app
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- open syslog port - add promtail config to accept syslog - add script to generate syslog
- Loading branch information
Showing
4 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python3 | ||
''' | ||
Syslog Generator | ||
Had a need to generate generic syslog messages to | ||
test open source logging solutions. | ||
''' | ||
|
||
import logging | ||
from logging.handlers import SysLogHandler | ||
import socket | ||
import argparse | ||
import random | ||
import sys | ||
import time | ||
from syslog_rfc5424_formatter import RFC5424Formatter | ||
|
||
logging.socket = socket | ||
|
||
""" | ||
Modify these variables to change the hostname, domainame, and tag | ||
that show up in the log messages. | ||
""" | ||
hostname = "host" | ||
domain_name = ".example.com" | ||
tag = ["kernel", "python", "ids", "ips"] | ||
syslog_level = ["info", "error", "warn", "critical"] | ||
|
||
def open_sample_log(sample_log): | ||
try: | ||
with open(sample_log, 'r') as sample_log_file: | ||
random_logs = random.choice(list(sample_log_file)) | ||
return random_logs | ||
except FileNotFoundError: | ||
print("[+] ERROR: Please specify valid filename") | ||
return sys.exit() | ||
|
||
def syslogs_sender(): | ||
# Initalize SysLogHandler | ||
logger = logging.getLogger() | ||
logger.setLevel(logging.INFO) | ||
syslog = SysLogHandler(address=('localhost', '5514'), socktype=socket.SOCK_STREAM) | ||
logger.addHandler(syslog) | ||
|
||
random_level = random.choice(syslog_level) | ||
message = open_sample_log("/var/log/system.log") | ||
formatter = RFC5424Formatter() | ||
syslog.setFormatter(formatter) | ||
getattr(logger, random_level)(message) | ||
|
||
logger.removeHandler(syslog) | ||
syslog.close() | ||
|
||
if __name__ == "__main__": | ||
try: | ||
while True: | ||
syslogs_sender() | ||
# time.sleep(1) | ||
except KeyboardInterrupt: | ||
# Use ctrl-c to stop the loop | ||
print("[+] Stopping syslog generator...") |