You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] API len(cb.select(Sensor)) causes error when >1000 sensors #301
I am getting errors using select(Sensor) API, requiring paging for >1000
OS: Not applicable
Carbon Black Product: [Carbon Black EDR]
Python Version: 3.8
Describe the bug
I use cb.select(Sensor) to acquire a count of sensors using the API, I get an error if there are >1000 sensors. I would like to use released code rather than patching the SDK. Can you please provide a release that has SensorPaginatedQuery enabled? Thanks
v1.7.6 has been released with this fix.
Master branch and pypi: https://pypi.org/project/cbapi/1.7.6/
Any problems, please let us know.
Thanks for your contribution to get this fixed.
While v1.7.6 fixes the paging problem, another problem emerged which is quite severe for us. Retrieving the list of all sensors returns a different set on every invocation. Running the following script multiple times in a row produces a different set of unique hostnames. This problem only appeared after upgrading to v1.7.6 but downgrading to an earlier version is no longer an option due to the paging error that v1.7.6 fixed. The problem only appears when using cbapi. Querying the API endpoint directly delivers the correct amount of hosts every time
(All following hostnames removed on purpose)
(python_virtualenv) scriptbot@xxx:~/CB/CarbonBlackExporter> cat debug2.py
from cbapi.response.models import Sensor
from cbapi.response import CbEnterpriseResponseAPI
if __name__ == '__main__':
carbonblack = CbEnterpriseResponseAPI(profile='default')
cb_sensors = carbonblack.select(Sensor)
for cb_sensor in cb_sensors:
print(cb_sensor.hostname)
// This returns a different set of unique hostnames every time, albeit the TOTAL amount of hostnames stays constant!
(python_virtualenv) scriptbot@xxx:~/CB/CarbonBlackExporter> vi debug2.py
(python_virtualenv) scriptbot@xxx:~/CB/CarbonBlackExporter> python3 debug2.py | sort | uniq| wc -l
3161
(python_virtualenv) scriptbot@xxx:~/CB/CarbonBlackExporter> python3 debug2.py | sort | uniq| wc -l
3156
(python_virtualenv) scriptbot@xxx:~/CB/CarbonBlackExporter> python3 debug2.py | sort | uniq| wc -l
2992
(python_virtualenv) scriptbot@xxx:~/CB/CarbonBlackExporter> python3 debug2.py | sort | uniq| wc -l
3119
// This attempt produces the correct amount of 3259 hostnames
(python_virtualenv) scriptbot@xxx:~/CB/CarbonBlackExporter> curl https://xxx:8443/api/v1/sensor?start=1&rows=5000 -H "X-Auth-Token: mysecrettoken" | grep computer_name | sort | uniq | wc -l
3259
(python_virtualenv) scriptbot@xxx:~/CB/CarbonBlackExporter> curl https://xxx:8443/api/v1/sensor?start=1&rows=5000 -H "X-Auth-Token: mysecrettoken " | grep computer_name | sort | uniq | wc -l
3259
(python_virtualenv) scriptbot@xxx:~/CB/CarbonBlackExporter> curl https://xxx:8443/api/v1/sensor?start=1&rows=5000 -H "X-Auth-Token: mysecrettoken " | grep computer_name | sort | uniq | wc -l
3259
(python_virtualenv) scriptbot@xxx:~/CB/CarbonBlackExporter> curl https://xxx:8443/api/v1/sensor?start=1&rows=5000 -H "X-Auth-Token: mysecrettoken " | grep computer_name | sort | uniq | wc -l
3259
@OevreFlataeker I believe the issue you are running into is due to #67 pagination is using /api/v2/sensor I believe that still needs to be addressed in #67
Thanks @atchutameka - I second the assumption it has to do with the new paging handling. So we're out of luck for the time being until #67 is fixed as well?
Thanks @atchutameka - I second the assumption it has to do with the new paging handling. So we're out of luck for the time being until #67 is fixed as well?
Activity
cforbes-tw commentedon Dec 13, 2021
See also #67 the reason for the comment.
mlodic commentedon Dec 15, 2021
got the same error.
sevdog commentedon Dec 15, 2021
Note that this error is only raised by CB EDR Server 7.6.0, previous versions does not have this issue.
This change was not documented in the changelog.
kebringer-cb commentedon Dec 20, 2021
v1.7.6 has been released with this fix.
Master branch and pypi: https://pypi.org/project/cbapi/1.7.6/
Any problems, please let us know.
Thanks for your contribution to get this fixed.
OevreFlataeker commentedon Jan 18, 2022
While v1.7.6 fixes the paging problem, another problem emerged which is quite severe for us. Retrieving the list of all sensors returns a different set on every invocation. Running the following script multiple times in a row produces a different set of unique hostnames. This problem only appeared after upgrading to v1.7.6 but downgrading to an earlier version is no longer an option due to the paging error that v1.7.6 fixed. The problem only appears when using cbapi. Querying the API endpoint directly delivers the correct amount of hosts every time
atchutameka commentedon Jan 18, 2022
@OevreFlataeker I believe the issue you are running into is due to #67 pagination is using /api/v2/sensor I believe that still needs to be addressed in #67
OevreFlataeker commentedon Jan 18, 2022
Thanks @atchutameka - I second the assumption it has to do with the new paging handling. So we're out of luck for the time being until #67 is fixed as well?
zacharyestep commentedon Jan 28, 2022
Should be fixed in the next release
kebringer-cb commentedon Jan 28, 2022
v1.7.7 has been released with Zach's update to set the sort order.
OevreFlataeker commentedon Feb 4, 2022
Thank you, I confirm this has fixed the problem!
kebringer-cb commentedon Feb 7, 2022
Thanks for the confirmation!