Skip to content

Commit

Permalink
Merge pull request #221 from carbonblack/sensor-fix
Browse files Browse the repository at this point in the history
Sensor fix
  • Loading branch information
dly-cb authored Apr 8, 2020
2 parents 58a0766 + ba3c867 commit 420fa05
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python bindings for Carbon Black REST API

**Latest Version: 1.6.1**
**Latest Version: 1.6.2**

These are the new Python bindings for the Carbon Black Enterprise Response and Enterprise Protection REST APIs.
To learn more about the REST APIs, visit the Carbon Black Developer Network Website at https://developer.carbonblack.com.
Expand Down
8 changes: 8 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ CbAPI Changelog
===============
.. top-of-changelog (DO NOT REMOVE THIS COMMENT)
CbAPI 1.6.2 - Released April 08, 2020
-------------------------------------

Updates

* CB Response
* 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>`_.

CbAPI 1.6.1 - Released January 13, 2020
---------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# The short X.Y version.
version = u'1.6'
# The full version, including alpha/beta/rc tags.
release = u'1.6.1'
release = u'1.6.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

setup(
name='cbapi',
version='1.6.1',
version='1.6.2',
url='https://github.com/carbonblack/cbapi-python',
license='MIT',
author='Carbon Black',
Expand Down
2 changes: 1 addition & 1 deletion src/cbapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__author__ = 'Carbon Black Developer Network'
__license__ = 'MIT'
__copyright__ = 'Copyright 2018-2019 VMware Carbon Black'
__version__ = '1.6.1'
__version__ = '1.6.2'

# New API as of cbapi 0.9.0
from cbapi.response.rest_api import CbEnterpriseResponseAPI, CbResponseAPI
Expand Down
35 changes: 33 additions & 2 deletions src/cbapi/response/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,13 +818,18 @@ def unisolate(self, timeout=None):
return True

def _update_object(self):
# Workarounds for issuing a sensor queue flush in Cb Response 6.0
# 1st Workarounds for issuing a sensor queue flush in Cb Response 6.0
# - We only want to reflect back the event_log_flush_time if the user explicitly set it to a new value
# (therefore, set the event_log_flush_time to None if it isn't marked dirty)
# - The event_log_flush_time must be sent in RFC822 format (not ISO 8601) for Cb Response 6.x servers.
#
# Note that even though we delete the event_log_flush_time here, it'll get re-initialized when we GET
# the sensor after sending the PUT request.
#
# 2nd Workarounds for updating a sensor's ability to update attributes in Cb Response 7.1
# - Only allowed fields are: ['network_isolation_enabled', 'restart_queued', 'uninstall', 'liveresponse_init', 'group_id', 'notes', 'event_log_flush_time']
# - Instead of sending in entire sensorObject fields, we will only send in the above 7

if "event_log_flush_time" in self._dirty_attributes and self._info.get("event_log_flush_time",
None) is not None:
if self._cb.cb_server_version > LooseVersion("6.0.0"):
Expand All @@ -837,7 +842,33 @@ def _update_object(self):
else:
self._info["event_log_flush_time"] = None

return super(Sensor, self)._update_object()
if self.__class__.primary_key in self._dirty_attributes.keys() or self._model_unique_id is None:
new_object_info = deepcopy(self._info)
try:
if not self._new_object_needs_primary_key:
del(new_object_info[self.__class__.primary_key])
except Exception:
pass
log.debug("Creating a new {0:s} object".format(self.__class__.__name__))
ret = self._cb.api_json_request(self.__class__._new_object_http_method, self.urlobject,
data=new_object_info)
else:
log.debug("Updating {0:s} with unique ID {1:s}".format(self.__class__.__name__, str(self._model_unique_id)))
http_method = self.__class__._change_object_http_method

allowed_fields = {
'network_isolation_enabled': self._info['network_isolation_enabled'],
'restart_queued': self._info['restart_queued'],
'uninstall': self._info['uninstall'],
'group_id': self._info['group_id'],
'notes': self._info['notes'],
'event_log_flush_time': self._info['event_log_flush_time']
}

ret = self._cb.api_json_request(http_method, self._build_api_request_uri(http_method=http_method),
data=allowed_fields)

return self._refresh_if_needed(ret)


class SensorGroup(MutableBaseModel, CreatableModelMixin):
Expand Down

0 comments on commit 420fa05

Please sign in to comment.