-
Notifications
You must be signed in to change notification settings - Fork 5
/
make_script.py
56 lines (47 loc) · 1.18 KB
/
make_script.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
#!python
import json
import os
TMP_FOLDER = "/tmp/vetr-collector"
SCRIPT_NAME = "vetr-collector.sh"
with open("./pkg/req/reqs.json") as f:
reqs = json.loads(f.read())
f = open(SCRIPT_NAME, "w")
f.writelines(
[
"#!/bin/bash\n",
"\n",
"rm -rf %s > /dev/null\n" % TMP_FOLDER,
"mkdir %s\n" % TMP_FOLDER,
"\n",
"# Fetch data from the API\n",
]
)
for req in reqs:
# icurl command
cmd = ["icurl -kG"]
cls = req["class"]
# url
cmd.append("https://localhost/api/class/%s.json" % cls)
for k, v in req.get("query", {}).items():
cmd.append("-d '%s=%s'" % (k, v))
# redirect output to file
pfx = req.get("prefix", cls)
cmd.append("> %s/%s.json" % (TMP_FOLDER, pfx))
cmd = " ".join(cmd)
f.writelines([cmd + "\n"])
f.writelines(
[
"\n",
"# Zip result\n",
"zip -mj ~/aci-vetr-data.zip %s/*.json\n" % TMP_FOLDER,
"\n",
"# Cleanup\n",
"\n",
"rm -rf %s\n" % TMP_FOLDER,
"\n",
"echo Collection complete\n",
"echo Please provide aci-vetr-data.zip to Cisco for analysis.\n",
]
)
f.close()
os.chmod(SCRIPT_NAME, 0o722)