Skip to content

Commit d9755d2

Browse files
committed
add time partitioning API support
1 parent 042ee4f commit d9755d2

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

src/cbapi/response/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
from .models import (
66
BannedHash, Site, ThrottleRule, Alert, Feed, Sensor, User, Watchlist, Investigation, ThreatReport, Binary, Process,
7-
SensorGroup, FeedAction, WatchlistAction, TaggedEvent
7+
SensorGroup, FeedAction, WatchlistAction, TaggedEvent, StoragePartition
88
)
99
from .rest_api import CbEnterpriseResponseAPI, CbResponseAPI

src/cbapi/response/models.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,43 @@
7070
# urlobject = '/api/v1/binary'
7171

7272

73+
class StoragePartitionQuery(SimpleQuery):
74+
@property
75+
def results(self):
76+
if not self._full_init:
77+
self._results = []
78+
for k,v in iteritems(self._cb.get_object(self._urlobject, default={})):
79+
t = self._doc_class.new_object(self._cb, v, full_doc=True)
80+
if self._match_query(t):
81+
self._results.append(t)
82+
self._results = self._sort(self._results)
83+
self._full_init = True
84+
85+
return self._results
86+
87+
88+
class StoragePartition(NewBaseModel):
89+
urlobject = "/api/v1/storage/events/partition"
90+
primary_key = "name"
91+
92+
@classmethod
93+
def _query_implementation(cls, cb):
94+
return StoragePartitionQuery(cls, cb)
95+
96+
def _refresh(self):
97+
# there is no GET method for a StoragePartition.
98+
return True
99+
100+
def delete(self):
101+
self._cb.delete_object("/api/v1/storage/events/{0}".format(self._model_unique_id))
102+
103+
def unmount(self):
104+
self._cb.post_object("/api/v1/storage/events/{0}/unmount".format(self._model_unique_id), None)
105+
106+
def mount(self):
107+
self._cb.post_object("/api/v1/storage/events/{0}/mount".format(self._model_unique_id), None)
108+
109+
73110
class BannedHash(MutableBaseModel, CreatableModelMixin):
74111
urlobject = "/api/v1/banning/blacklist"
75112
swagger_meta_file = "response/models/hash_blacklist.yaml"

src/cbapi/response/rest_api.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,17 @@ def from_ui(self, uri):
174174
def _request_lr_session(self, sensor_id):
175175
return self.live_response.request_session(sensor_id)
176176

177-
def _close_lr_session(self, sensor_id):
178-
return self.live_response.close_session(sensor_id)
177+
def create_new_partition(self):
178+
"""Create a new Solr time partition for event storage. Available in Cb Response 6.1 and above.
179+
This will force roll-over current hot partition into warm partition (by renaming it to a time-stamped name)
180+
and create a new hot partition ("writer").
181+
182+
:returns: Nothing if successful.
183+
:raises ApiError: if there was an error creating the new partition.
184+
:raises ServerError: if there was an error creating the new partition.
185+
"""
186+
self.post_object("/api/v1/storage/events/new_partition", None)
187+
179188

180189
class CbEnterpriseResponseAPI(CbResponseAPI):
181190
"""

0 commit comments

Comments
 (0)