-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix offset parameter for experimental API calls #3159
Conversation
Hello @druizz90, I have my first agent with 547 elements: # curl -u foo:bar "localhost:55000/syscollector/000/packages?pretty&limit=1"
{
"error": 0,
"data": {
"items": [
{
"scan": {
"id": 458098423,
"time": "2019/04/24 08:42:11"
},
"size": 269,
"version": "8.2.0-1ubuntu2~18.04",
"description": "GCC Quad-Precision Math Library",
"multiarch": "same",
"vendor": "Ubuntu Core developers <ubuntu-devel-discuss@lists.ubuntu.com>",
"source": "gcc-8",
"name": "libquadmath0",
"architecture": "amd64",
"priority": "optional",
"section": "libs",
"format": "deb"
}
],
"totalItems": 547
}
} If I ask for the element 499, it correctly works: # curl -u foo:bar "localhost:55000/experimental/syscollector/packages?offset=499&limit=1&pretty"
{
"error": 0,
"data": {
"items": [
{
"scan": {
"id": 458098423,
"time": "2019/04/24 08:42:11"
},
"size": 533,
"priority": "optional",
"version": "0.17-1ubuntu1",
"name": "xdg-user-dirs",
"architecture": "amd64",
"description": "tool to manage well known user directories",
"multiarch": "foreign",
"vendor": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",
"section": "utils",
"format": "deb",
"agent_id": "000"
}
],
"totalItems": 1045
}
} But asking for an element higher than 547 will fail:
Best regards, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, could you provide mocha tests for experimental endpoints?
I updated issue wazuh/wazuh-api#152 with examples of |
Mocha tests# mocha test/test_syscollector.js --timeout=10000
Syscollector
GET/syscollector/:agent_id/os
✓ Request (254ms)
✓ Selector (282ms)
✓ Not allowed selector (307ms)
GET/syscollector/:agent_id/hardware
✓ Request (271ms)
✓ Selector (317ms)
✓ Not allowed selector (264ms)
GET/syscollector/:agent_id/packages
✓ Request (308ms)
✓ Selector (288ms)
✓ Not allowed selector (257ms)
✓ Pagination (863ms)
✓ Wrong limit
✓ Sort - (311ms)
✓ Sort + (247ms)
✓ Wrong Sort (260ms)
✓ Search (329ms)
✓ Filter: vendor (336ms)
✓ Filter: name (265ms)
✓ Filter: architecture (309ms)
✓ Filter: format (323ms)
✓ Wrong filter
GET/experimental/syscollector/packages
✓ Request (434ms)
✓ Selector (337ms)
✓ Not allowed selector (468ms)
✓ Pagination (496ms)
✓ Wrong limit
✓ Sort - (633ms)
✓ Sort + (652ms)
✓ Wrong Sort (305ms)
✓ Search (392ms)
✓ Filter: vendor (435ms)
✓ Filter: name (287ms)
✓ Filter: architecture (407ms)
✓ Filter: format (492ms)
✓ Wrong filter
GET/experimental/syscollector/os
✓ Request (270ms)
✓ Selector (571ms)
✓ Not allowed selector (284ms)
✓ Pagination (332ms)
✓ Wrong limit
✓ Search (282ms)
✓ Wrong filter
✓ Filter: architecture (278ms)
✓ Filter: os_name (473ms)
✓ Filter: release (292ms)
GET/experimental/syscollector/hardware
✓ Request (391ms)
✓ Selector (345ms)
✓ Not allowed selector (273ms)
✓ Pagination (300ms)
✓ Wrong limit
✓ Search (299ms)
✓ Wrong filter
✓ Wrong Sort (255ms)
✓ Filter: ram_total (481ms)
✓ Filter: cpu_cores (405ms)
✓ Filter: cpu_mhz (299ms)
✓ Filter: board_serial (474ms)
GET/experimental/syscollector/processes
✓ Request (504ms)
✓ Selector (283ms)
✓ Not allowed selector (270ms)
✓ Pagination (428ms)
✓ Wrong limit
✓ Search (355ms)
✓ Wrong filter
✓ Wrong Sort (267ms)
✓ Filter: state (338ms)
✓ Filter: ppid (316ms)
✓ Filter: egroup (325ms)
✓ Filter: euser (338ms)
✓ Filter: fgroup (320ms)
✓ Filter: name (280ms)
✓ Filter: nlwp (325ms)
✓ Filter: pgrp (295ms)
✓ Filter: priority (296ms)
✓ Filter: rgroup (354ms)
✓ Filter: ruser (352ms)
✓ Filter: sgroup (331ms)
✓ Filter: suser (368ms)
GET/experimental/syscollector/ports
✓ Request (278ms)
✓ Selector (287ms)
✓ Not allowed selector (288ms)
✓ Pagination (314ms)
✓ Wrong limit
✓ Search (293ms)
✓ Wrong filter
✓ Wrong Sort (274ms)
✓ Filter: protocol (304ms)
✓ Filter: local_ip (342ms)
✓ Filter: local_port (277ms)
✓ Filter: remote_ip (322ms)
✓ Filter: tx_queue (283ms)
✓ Filter: state (323ms)
GET/syscollector/netaddr
✓ Request (237ms)
✓ Selector (270ms)
✓ Not allowed selector (270ms)
✓ Pagination (316ms)
✓ Wrong limit
✓ Search (312ms)
✓ Wrong filter
✓ Wrong Sort (248ms)
✓ Filter: iface (350ms)
✓ Filter: proto (271ms)
✓ Filter: address (280ms)
✓ Filter: broadcast (320ms)
✓ Filter: netmask (456ms)
GET/experimental/syscollector/netproto
✓ Request (289ms)
✓ Selector (367ms)
✓ Not allowed selector (234ms)
✓ Pagination (290ms)
✓ Wrong limit
✓ Search (295ms)
✓ Wrong filter
✓ Wrong Sort (251ms)
✓ Filter: iface (313ms)
✓ Filter: type (314ms)
✓ Filter: gateway (274ms)
✓ Filter: dhcp (298ms)
GET/experimental/syscollector/netiface
✓ Request (350ms)
✓ Selector (509ms)
✓ Not allowed selector (254ms)
✓ Pagination (279ms)
✓ Wrong limit
✓ Search (255ms)
✓ Wrong filter
✓ Wrong Sort (256ms)
✓ Filter: name (244ms)
✓ Filter: type (275ms)
✓ Filter: state (308ms)
✓ Filter: mtu (670ms)
✓ Filter: tx_packets (273ms)
✓ Filter: rx_packets (239ms)
✓ Filter: tx_bytes (319ms)
✓ Filter: rx_bytes (298ms)
✓ Filter: tx_errors (350ms)
✓ Filter: rx_errors (326ms)
✓ Filter: tx_dropped (280ms)
✓ Filter: rx_dropped (259ms)
GET/syscollector/000/processes
✓ Request (259ms)
✓ Selector (303ms)
✓ Not allowed selector (297ms)
✓ Pagination (301ms)
✓ Wrong limit
✓ Search (292ms)
✓ Wrong filter
✓ Wrong Sort (291ms)
✓ Filter: state (266ms)
✓ Filter: ppid (271ms)
✓ Filter: egroup (366ms)
✓ Filter: euser (277ms)
✓ Filter: fgroup (326ms)
✓ Filter: name (260ms)
✓ Filter: nlwp (315ms)
✓ Filter: pgrp (258ms)
✓ Filter: priority (314ms)
✓ Filter: rgroup (312ms)
✓ Filter: ruser (269ms)
✓ Filter: sgroup (259ms)
✓ Filter: suser (313ms)
GET/syscollector/000/ports
✓ Request (375ms)
✓ Selector (581ms)
✓ Not allowed selector (406ms)
✓ Pagination (696ms)
✓ Wrong limit
✓ Search (265ms)
✓ Wrong filter
✓ Wrong Sort (284ms)
✓ Filter: protocol (271ms)
✓ Filter: local_ip (267ms)
✓ Filter: local_port (252ms)
✓ Filter: remote_ip (271ms)
✓ Filter: tx_queue (255ms)
✓ Filter: state (257ms)
GET/syscollector/000/netaddr
✓ Request (301ms)
✓ Selector (259ms)
✓ Not allowed selector (247ms)
✓ Pagination (297ms)
✓ Wrong limit
✓ Search (254ms)
✓ Wrong filter
✓ Wrong Sort (274ms)
✓ Filter: iface (251ms)
✓ Filter: proto (297ms)
✓ Filter: address (316ms)
✓ Filter: broadcast (289ms)
✓ Filter: netmask (242ms)
GET/syscollector/000/netproto
✓ Request (259ms)
✓ Selector (246ms)
✓ Not allowed selector (271ms)
✓ Pagination (253ms)
✓ Wrong limit
✓ Search (281ms)
✓ Wrong filter
✓ Wrong Sort (294ms)
✓ Filter: iface (323ms)
✓ Filter: type (314ms)
✓ Filter: gateway (288ms)
✓ Filter: dhcp (301ms)
GET/syscollector/000/netiface
✓ Request (256ms)
✓ Selector (283ms)
✓ Not allowed selector (261ms)
✓ Pagination (282ms)
✓ Wrong limit
✓ Search (267ms)
✓ Wrong filter
✓ Wrong Sort (303ms)
✓ Filter: name (271ms)
✓ Filter: type (319ms)
✓ Filter: state (268ms)
✓ Filter: mtu (344ms)
✓ Filter: tx_packets (266ms)
✓ Filter: rx_packets (270ms)
✓ Filter: tx_bytes (262ms)
✓ Filter: rx_bytes (324ms)
✓ Filter: tx_errors (281ms)
✓ Filter: rx_errors (308ms)
✓ Filter: tx_dropped (338ms)
✓ Filter: rx_dropped (266ms)
216 passing (1m) |
PR updateThis fix works when cluster is disabled. When cluster is enabled, I made a fix for applying these parameters when cluster is enabled after merge results. My environment has 3 managers and 3 agents. Each agent is reporting to a different node:
|
# apply offset parameter when merging results from nodes | ||
if 'offset' in self.input_json['arguments']: | ||
offset = self.input_json['arguments']['offset'] # save offset | ||
self.input_json['arguments']['offset'] = 0 # set offset=0 before distributing call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with this solution. I'm not sure it solves the problem. Actually I think it breaks the offset for the rest of endpoints.
We cannot risk the correctness of common endpoints just to fix the experimental ones. We should think another approach and then come back with a better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forward_request
method is called only on distributed_master
requests.
We have the following endpoints of distributed_master
type:
GET /cluster/:node_id/logs
GET /rootcheck/:agent_id/cis
GET /rootcheck/:agent_id
GET /rootcheck/:agent_id/pci
GET /sca/:agent_id/checks/:id
GET /sca/:agent_id
GET /syscollector/:agent_id/packages
GET /syscollector/:agent_id/processes
GET /syscollector/:agent_id/ports
GET /syscollector/:agent_id/netaddr
GET /syscollector/:agent_id/netiface
GET /syscollector/:agent_id/netproto
GET /ciscat/:agent_id/results
GET /experimental/syscollector/os
GET /experimental/syscollector/hardware
GET /experimental/syscollector/packages
GET /experimental/syscollector/processes
GET /experimental/syscollector/ports
GET /experimental/syscollector/netaddr
GET /experimental/syscollector/netproto
GET /experimental/syscollector/netiface
GET /experimental/ciscat/results
Only experimentals
calls merge results, so I think I should move the changes inside this conditional in order to avoid secondary effects and fix pagination in experimental
endpoints:
wazuh/framework/wazuh/cluster/dapi/dapi.py
Line 229 in 939481f
if len(nodes) > 1: |
Thoughts?
Hi team,
This PR closes API issue #152. I made a fix to adapt
offset
filter to this function.Others experimental calls as
experimental/syscollector/os
andexperimental/syscollector/hardware
were fixed too:Best regards,
Demetrio.