-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfeed_report_stats.py
executable file
·66 lines (52 loc) · 2.23 KB
/
feed_report_stats.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
__author__ = 'bwolfson'
import sys
import optparse
# in the github repo, cbapi is not in the example directory
sys.path.append('../src/cbapi')
import cbapi
def build_cli_parser():
parser = optparse.OptionParser(usage="%prog [options]", description="Get the a report's info from a configured feed")
# for each supported output type, add an option
#
parser.add_option("-c", "--cburl", action="store", default=None, dest="server_url",
help="CB server's URL. e.g., http://127.0.0.1 ")
parser.add_option("-a", "--apitoken", action="store", default=None, dest="token",
help="API Token for Carbon Black server")
parser.add_option("-n", "--no-ssl-verify", action="store_false", default=True, dest="ssl_verify",
help="Do not verify server SSL certificate.")
parser.add_option("-i", "--id", action="store", default=None, dest="id",
help="Feed id")
parser.add_option("-r", "--report_id", action = "store", default = None, dest = "reportid",
help = "Report id")
return parser
def main(argv):
parser = build_cli_parser()
opts, args = parser.parse_args(argv)
if not opts.server_url or not opts.token or not opts.id or not opts.reportid:
print "Missing required param; run with --help for usage"
sys.exit(-1)
# build a cbapi object
#
cb = cbapi.CbApi(opts.server_url, token=opts.token, ssl_verify=opts.ssl_verify)
curr_feeds = cb.feed_enum()
feed_does_exist = False
for feed in curr_feeds:
if int(feed['id']) == int(opts.id):
feed_does_exist = True
if not feed_does_exist:
print "No feed with id %s found" % opts.id
sys.exit(-1)
curr_reports = cb.feed_report_enum(opts.id)
report_does_exist = False
for report in curr_reports:
if opts.reportid == report['id']:
report_does_exist = True
if not report_does_exist:
print "No report with id %s found" % opts.reportid
sys.exit(-1)
# get the feed's report stats
stats = cb.feed_report_stats(opts.id, opts.reportid)
for key in stats.keys():
print "%-22s : %s" % (key, stats[key])
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))