-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
63 lines (49 loc) · 2.54 KB
/
main.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from dockerpulse.cli import Dockerpulse
import argparse
from dotenv import load_dotenv
from dockerpulse.utils.slack import SlackNotifier
def config():
load_dotenv()
def main():
# START: ASCII Art
docker_ascii = r"""
$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $
$$$$$$$\ $$\ $$$$$$$\ $$\
$$ __$$\ $$ | $$ __$$\ $$ |
$$ | $$ | $$$$$$\ $$$$$$$\ $$ | $$\ $$$$$$\ $$$$$$\ $$ | $$ |$$\ $$\ $$ | $$$$$$$\ $$$$$$\
$$ | $$ |$$ __$$\ $$ _____|$$ | $$ |$$ __$$\ $$ __$$\ $$$$$$$ |$$ | $$ |$$ |$$ _____|$$ __$$\
$$ | $$ |$$ / $$ |$$ / $$$$$$ / $$$$$$$$ |$$ | \__|$$ ____/ $$ | $$ |$$ |\$$$$$$\ $$$$$$$$ |
$$ | $$ |$$ | $$ |$$ | $$ _$$< $$ ____|$$ | $$ | $$ | $$ |$$ | \____$$\ $$ ____|
$$$$$$$ |\$$$$$$ |\$$$$$$$\ $$ | \$$\ \$$$$$$$\ $$ | $$ | \$$$$$$ |$$ |$$$$$$$ |\$$$$$$$\
\_______/ \______/ \_______|\__| \__| \_______|\__| \__| \______/ \__|\_______/ \_______|
$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $
"""
print(docker_ascii)
# END: ASCII Art
parser = argparse.ArgumentParser(
prog='Dockerpulse CLI',
description='Dockerpulse CLI to detect anomalies in Docker containers and send alerts to Slack and output solution to stdout',
add_help=True)
parser.add_argument('-c', '--container',
help='Container ID', required=True)
parser.add_argument('-e', '--encoder',
help='Large Language Model Encoder', default='bert')
parser.add_argument('-p', '--parser',
help='Log Parser', default='drain')
parser.add_argument('-l', '--log-format',
help="Regex for log format", default=open('log_format.txt', 'r').read())
try:
args = parser.parse_args()
pulse = Dockerpulse(args.container, args.parser, args.log_format)
sol, anomaly, logs = pulse.analysis()
if anomaly:
print(f"{logs}\n\n Approximate Solution proposed: {sol}")
sn = SlackNotifier()
sn.send_notification(logs, sol)
else:
print("No anomaly detected")
except Exception as e:
print(e)
if __name__ == "__main__":
config()
main()