Skip to content

Commit 420fa05

Browse files
authored
Merge pull request #221 from carbonblack/sensor-fix
Sensor fix
2 parents 58a0766 + ba3c867 commit 420fa05

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Python bindings for Carbon Black REST API
22

3-
**Latest Version: 1.6.1**
3+
**Latest Version: 1.6.2**
44

55
These are the new Python bindings for the Carbon Black Enterprise Response and Enterprise Protection REST APIs.
66
To learn more about the REST APIs, visit the Carbon Black Developer Network Website at https://developer.carbonblack.com.

docs/changelog.rst

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ CbAPI Changelog
22
===============
33
.. top-of-changelog (DO NOT REMOVE THIS COMMENT)
44
5+
CbAPI 1.6.2 - Released April 08, 2020
6+
-------------------------------------
7+
8+
Updates
9+
10+
* CB Response
11+
* Changes to align with limits placed on the sensor update function in CB Response 7.1.0. Release notes are available on User Exchange, the ID is `CB 28683 <https://community.carbonblack.com/t5/Documentation-Downloads/CB-Response-7-1-0-Server-Release-Notes/ta-p/88027>`_.
12+
513
CbAPI 1.6.1 - Released January 13, 2020
614
---------------------------------------
715

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
# The short X.Y version.
6262
version = u'1.6'
6363
# The full version, including alpha/beta/rc tags.
64-
release = u'1.6.1'
64+
release = u'1.6.2'
6565

6666
# The language for content autogenerated by Sphinx. Refer to documentation
6767
# for a list of supported languages.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
setup(
4343
name='cbapi',
44-
version='1.6.1',
44+
version='1.6.2',
4545
url='https://github.com/carbonblack/cbapi-python',
4646
license='MIT',
4747
author='Carbon Black',

src/cbapi/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = 'Carbon Black Developer Network'
77
__license__ = 'MIT'
88
__copyright__ = 'Copyright 2018-2019 VMware Carbon Black'
9-
__version__ = '1.6.1'
9+
__version__ = '1.6.2'
1010

1111
# New API as of cbapi 0.9.0
1212
from cbapi.response.rest_api import CbEnterpriseResponseAPI, CbResponseAPI

src/cbapi/response/models.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -818,13 +818,18 @@ def unisolate(self, timeout=None):
818818
return True
819819

820820
def _update_object(self):
821-
# Workarounds for issuing a sensor queue flush in Cb Response 6.0
821+
# 1st Workarounds for issuing a sensor queue flush in Cb Response 6.0
822822
# - We only want to reflect back the event_log_flush_time if the user explicitly set it to a new value
823823
# (therefore, set the event_log_flush_time to None if it isn't marked dirty)
824824
# - The event_log_flush_time must be sent in RFC822 format (not ISO 8601) for Cb Response 6.x servers.
825825
#
826826
# Note that even though we delete the event_log_flush_time here, it'll get re-initialized when we GET
827827
# the sensor after sending the PUT request.
828+
#
829+
# 2nd Workarounds for updating a sensor's ability to update attributes in Cb Response 7.1
830+
# - Only allowed fields are: ['network_isolation_enabled', 'restart_queued', 'uninstall', 'liveresponse_init', 'group_id', 'notes', 'event_log_flush_time']
831+
# - Instead of sending in entire sensorObject fields, we will only send in the above 7
832+
828833
if "event_log_flush_time" in self._dirty_attributes and self._info.get("event_log_flush_time",
829834
None) is not None:
830835
if self._cb.cb_server_version > LooseVersion("6.0.0"):
@@ -837,7 +842,33 @@ def _update_object(self):
837842
else:
838843
self._info["event_log_flush_time"] = None
839844

840-
return super(Sensor, self)._update_object()
845+
if self.__class__.primary_key in self._dirty_attributes.keys() or self._model_unique_id is None:
846+
new_object_info = deepcopy(self._info)
847+
try:
848+
if not self._new_object_needs_primary_key:
849+
del(new_object_info[self.__class__.primary_key])
850+
except Exception:
851+
pass
852+
log.debug("Creating a new {0:s} object".format(self.__class__.__name__))
853+
ret = self._cb.api_json_request(self.__class__._new_object_http_method, self.urlobject,
854+
data=new_object_info)
855+
else:
856+
log.debug("Updating {0:s} with unique ID {1:s}".format(self.__class__.__name__, str(self._model_unique_id)))
857+
http_method = self.__class__._change_object_http_method
858+
859+
allowed_fields = {
860+
'network_isolation_enabled': self._info['network_isolation_enabled'],
861+
'restart_queued': self._info['restart_queued'],
862+
'uninstall': self._info['uninstall'],
863+
'group_id': self._info['group_id'],
864+
'notes': self._info['notes'],
865+
'event_log_flush_time': self._info['event_log_flush_time']
866+
}
867+
868+
ret = self._cb.api_json_request(http_method, self._build_api_request_uri(http_method=http_method),
869+
data=allowed_fields)
870+
871+
return self._refresh_if_needed(ret)
841872

842873

843874
class SensorGroup(MutableBaseModel, CreatableModelMixin):

0 commit comments

Comments
 (0)