-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsumo_adder.py
executable file
·63 lines (46 loc) · 1.72 KB
/
sumo_adder.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Designed to add sumo logic lines to multiple csv files at once because anything else is too hard. Pass it the ip and
site. It does the rest.
Just 'ls >> /path/to/file/filename.txt' at the cli to make a list.
"""
import argparse
def add_sumo(ip, site):
"""
Writes to existing csv files
:param ip: IP Address of sumo box
:param site: Physical site identifier
:return: Nothing, just make the files as necessary
"""
with open("file.txt", "r") as f:
servers = f.readlines()
servers = [i.strip("\n") for i in servers]
for i in servers:
with open(f"staging/extdata/fqdn/product.{site}.domain.com/{i}", "a") as f:
f.write(f"\n# Sumo Logic config\n"
f"syslog_sumo_proto,tcp\n"
f"syslog_sumo_ip_address,{ip}\n"
f"syslog_sumo_ip_port,5140\n")
return None
def create_parser():
"""
Create the parser and arguments.
:return: parser
"""
parser = argparse.ArgumentParser(description="Quickly make yaml multiple files with the ip and optional "
"mysql/moebius entries.")
parser.add_argument("-i", "--ip", dest='ip', help="SUMO IP", type=str, required=True)
parser.add_argument("-s", "--site", dest="site", help="Site", type=str, required=True)
return parser
def handle_args(args=None):
"""
If args are not provided or all required not present, call create_parser and print help info.
"""
if args is None:
parser = create_parser()
args = parser.parse_args()
if args.ip and args.site:
add_sumo(args.ip, args.site)
if __name__ == '__main__':
handle_args()