Add test.py

This commit is contained in:
p53209761 2022-10-19 16:49:16 +08:00
parent 8e361efc9d
commit 120982df55
1 changed files with 42 additions and 0 deletions

42
test.py Normal file
View File

@ -0,0 +1,42 @@
import datetime
from faker import Faker
import time
fake = Faker(locale="zh_CN")
def write_log(path, log):
with open(file=path, mode="a", encoding="utf-8") as f:
if isinstance(log, str):
f.write(log)
if isinstance(log, list):
for line in log:
f.write(line)
for i in range(2):
time.sleep(1)
current_time = datetime.datetime.now()
nginx_log = f'{current_time.strftime("%Y/%m/%d %H:%M:%S")} [error] 32#32: ngnix:{fake.address()}, client: 127.0.0.1, server: n9e.example.com, request: "GET /favicon.ico HTTP/1.1", host: "127.0.0.1", referrer: "http://127.0.0.1/api/mon/bi/configs"\n'
nginx_path = r"C:\logstash-7.16.2-windows-x86_64\logstash-7.16.2\error-log-example\nginx.log"
minio_log = 'API: SYSTEM()\n' \
f'Time: {current_time.strftime("%H:%M:%S CST %m/%d/%Y")}\n' \
f'DeploymentID: {fake.md5(raw_output=False)}\n' \
f'Error:{fake.address()}\r'
minio_path = r"C:\logstash-7.16.2-windows-x86_64\logstash-7.16.2\error-log-example\minio.log"
elasticsearch_log = f"[{current_time.strftime('%Y-%m-%dT%H:%M:%S')},687][ERROR]es: {fake.address()}\n"
elasticsearch_path = r"C:\logstash-7.16.2-windows-x86_64\logstash-7.16.2\error-log-example\elasticsearch.log"
cassandra_log = f"WARN [main] {current_time.strftime('%Y-%m-%d %H:%M:%S')},656 cassandra: {fake.address()} \n"
cassandra_path = r"C:\logstash-7.16.2-windows-x86_64\logstash-7.16.2\error-log-example\cassandra_error.log"
# write_log(nginx_path, nginx_log)
write_log(minio_path, minio_log)
# write_log(elasticsearch_path, elasticsearch_log)
# write_log(cassandra_path, cassandra_log)