forked from carbonblack/cbapi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_requests_cache_ng.py
More file actions
103 lines (79 loc) · 3.06 KB
/
create_requests_cache_ng.py
File metadata and controls
103 lines (79 loc) · 3.06 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
#
# The MIT License (MIT)
#
# Copyright (c) 2016 Carbon Black Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# -----------------------------------------------------------------------------
#
# last updated 2016-04-07 by Jason McFarland
#
import sys
import os
sys.path.append(os.path.dirname(__file__))
import requests_cache
import optparse
from cbapi.response.models import Process, Binary, Sensor, Feed, Watchlist, Investigation, User
from cbapi.response.rest_api import CbEnterpriseResponseAPI
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
def large_process_search():
processes = cb.select(Process).where('')
print("Number of process: ", len(processes))
def large_binary_search():
binaries = cb.select(Binary).where('')
print("Number of binaries: ", len(binaries))
def sensor_search():
sensors = cb.select(Sensor)
print("Number of sensors: ", len(sensors))
def watchlist_search():
watchlists = cb.select(Watchlist)
print("Number of watchlists: ", len(watchlists))
def feed_search():
feeds = cb.select(Feed)
print("Number of feeds: ", len(feeds))
def main(argv):
parser = build_cli_parser()
opts, args = parser.parse_args(argv)
if not opts.cache_name:
parser.print_help()
sys.exit(-1)
global cache_file_name
cache_file_name = opts.cache_name
requests_cache.install_cache(cache_file_name, allowable_methods=('GET', 'POST'))
global cb
cb = CbEnterpriseResponseAPI()
large_process_search()
large_binary_search()
sensor_search()
watchlist_search()
feed_search()
def build_cli_parser():
parser = optparse.OptionParser(usage="%prog [options]",
description="Create a cache of responses for regression testing")
#
# for each supported output type, add an option
#
parser.add_option("-f", "--cache", action="store", default="cache", dest="cache_name",
help="Cache sqlite file name")
return parser
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))