-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc_py.py
73 lines (56 loc) · 2.24 KB
/
calc_py.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
64
65
66
67
68
69
70
71
72
73
import os
fieldsPath = "YOUR CALCULATED FIELDS"
localPath = ""
propsLocalPath = ""
propsDefaultPath = ""
folder = ""
lineIndex = 0
visited = False
with open(fieldsPath, 'r') as file:
for line in file:
stripped_line = line.strip()
if stripped_line[:3] == 'app':
for i in range(lineIndex):
file.next()
for line in file:
if lineIndex == 0:
folder = stripped_line[4:]
stripped_line = line.strip()
if stripped_line[:3] == 'app' and lineIndex != 0:
folder = stripped_line[4:]
visited = False
continue
localPath = "$SPLUNK_HOME/etc/"+folder+"/local/"
propsLocalPath = "$SPLUNK_HOME/etc/"+folder+"/local/props.conf"
propsDefaultPath = "$SPLUNK_HOME/etc/"+folder+"/default/props.conf"
if os.path.exists(localPath) == True and os.path.exists(propsLocalPath) == True:
if visited == False:
os.system("cp -r "+propsLocalPath+" "+localPath+"props.conf.backup")
fileAdd = open(propsLocalPath, 'a')
fileAdd.write("\n"+stripped_line+"\n")
visited = True
else:
fileAdd = open(propsLocalPath, 'a')
fileAdd.write("\n"+stripped_line+"\n")
elif os.path.exists(localPath) == True and os.path.exists(propsLocalPath) == False:
os.system("cp -r "+propsDefaultPath+" "+localPath)
if visited == False:
os.system("cp -r "+propsLocalPath+" "+localPath+"props.conf.backup")
fileAdd = open(propsLocalPath, 'a')
fileAdd.write("\n"+stripped_line+"\n")
visited = True
else:
fileAdd = open(propsLocalPath, 'a')
fileAdd.write("\n"+stripped_line+"\n")
elif os.path.exists(localPath) == False and os.path.exists(propsLocalPath) == False:
os.system("mkdir "+localPath)
os.system("cp -r "+propsDefaultPath+" "+localPath)
if visited == False:
os.system("cp -r "+propsLocalPath+" "+localPath+"props.conf.backup")
fileAdd = open(propsLocalPath, 'a')
fileAdd.write("\n"+stripped_line+"\n")
visited = True
else:
fileAdd = open(propsLocalPath, 'a')
fileAdd.write("\n"+stripped_line+"\n")
lineIndex+=1