Skip to content
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

Closed
wants to merge 8 commits into from

Conversation

druizz90
Copy link
Contributor

@druizz90 druizz90 commented Apr 23, 2019

Hi team,

This PR closes API issue #152. I made a fix to adapt offset filter to this function.

# curl -u foo:bar -k -X GET "http://127.0.0.1:55000/experimental/ciscat/results?limit=2&offset=0&pretty"
{
   "error": 0,
   "data": {
      "items": [
         {
            "scan": {
               "id": 790125247,
               "time": "2019-04-23T16:19:36.720+02:00"
            },
            "error": 0,
            "profile": "xccdf_org.cisecurity.benchmarks_profile_Level_2_-_Server",
            "score": 52,
            "unknown": 0,
            "notchecked": 31,
            "benchmark": "CIS CentOS Linux 7 Benchmark",
            "pass": 99,
            "fail": 92,
            "agent_id": "000"
         },
         {
            "scan": {
               "id": 1744690172,
               "time": "2019-04-23T15:12:38.234+02:00"
            },
            "error": 0,
            "profile": "xccdf_org.cisecurity.benchmarks_profile_Level_2_-_Server",
            "score": 53,
            "unknown": 0,
            "notchecked": 31,
            "benchmark": "CIS CentOS Linux 7 Benchmark",
            "pass": 102,
            "fail": 89,
            "agent_id": "001"
         }
      ],
      "totalItems": 2
   }
}
# curl -u foo:bar -k -X GET "http://127.0.0.1:55000/experimental/ciscat/results?limit=2&offset=1&pretty"
{
   "error": 0,
   "data": {
      "items": [
         {
            "scan": {
               "id": 1744690172,
               "time": "2019-04-23T15:12:38.234+02:00"
            },
            "pass": 102,
            "notchecked": 31,
            "unknown": 0,
            "fail": 89,
            "benchmark": "CIS CentOS Linux 7 Benchmark",
            "profile": "xccdf_org.cisecurity.benchmarks_profile_Level_2_-_Server",
            "error": 0,
            "score": 53,
            "agent_id": "001"
         }
      ],
      "totalItems": 2
   }
}
# curl -u foo:bar -k -X GET "http://127.0.0.1:55000/experimental/ciscat/results?limit=2&offset=2&pretty"
{
   "error": 0,
   "data": {
      "items": [],
      "totalItems": 2
   }
}

Others experimental calls as experimental/syscollector/os and experimental/syscollector/hardware were fixed too:

# curl -u foo:bar "localhost:55000/experimental/syscollector/hardware?pretty"   
{
   "error": 0,
   "data": {
      "items": [
         {
            "cpu": {
               "cores": 1,
               "mhz": 2712,
               "name": "Intel Core Processor (Broadwell, no TSX, IBRS)"
            },
            "ram": {
               "free": 100912,
               "total": 498828,
               "usage": 80
            },
            "scan": {
               "id": 1454721960,
               "time": "2019/04/23 17:17:13"
            },
            "board_serial": "unknown",
            "agent_id": "000"
         },
         {
            "cpu": {
               "cores": 1,
               "mhz": 2712,
               "name": "Intel Core Processor (Broadwell, no TSX, IBRS)"
            },
            "ram": {
               "free": 6796,
               "total": 241292,
               "usage": 98
            },
            "scan": {
               "id": 206742532,
               "time": "2019/04/23 18:10:12"
            },
            "board_serial": "unknown",
            "agent_id": "001"
         }
      ],
      "totalItems": 2
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/hardware?offset=1&pretty"         
{
   "error": 0,
   "data": {
      "items": [
         {
            "cpu": {
               "cores": 1,
               "mhz": 2712,
               "name": "Intel Core Processor (Broadwell, no TSX, IBRS)"
            },
            "ram": {
               "free": 6796,
               "total": 241292,
               "usage": 98
            },
            "scan": {
               "id": 206742532,
               "time": "2019/04/23 18:10:12"
            },
            "board_serial": "unknown",
            "agent_id": "001"
         }
      ],
      "totalItems": 2
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/os?pretty"         
{
   "error": 0,
   "data": {
      "items": [
         {
            "os": {
               "major": "7",
               "minor": "6",
               "name": "CentOS Linux",
               "platform": "centos",
               "version": "7.6"
            },
            "scan": {
               "id": 2092711908,
               "time": "2019/04/23 17:17:13"
            },
            "hostname": "localhost.localdomain",
            "release": "3.10.0-957.1.3.el7.x86_64",
            "version": "#1 SMP Thu Nov 29 14:49:43 UTC 2018",
            "architecture": "x86_64",
            "sysname": "Linux",
            "agent_id": "000"
         },
         {
            "os": {
               "codename": "Core",
               "major": "7",
               "name": "CentOS Linux",
               "platform": "centos",
               "version": "7 (Core)"
            },
            "scan": {
               "id": 869051446,
               "time": "2019/04/23 18:10:12"
            },
            "hostname": "localhost.localdomain",
            "release": "3.10.0-862.11.6.el7.x86_64",
            "version": "#1 SMP Tue Aug 14 21:49:04 UTC 2018",
            "architecture": "x86_64",
            "sysname": "Linux",
            "agent_id": "001"
         }
      ],
      "totalItems": 2
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/os?offset=1&pretty"
{
   "error": 0,
   "data": {
      "items": [
         {
            "os": {
               "codename": "Core",
               "major": "7",
               "name": "CentOS Linux",
               "platform": "centos",
               "version": "7 (Core)"
            },
            "scan": {
               "id": 869051446,
               "time": "2019/04/23 18:10:12"
            },
            "version": "#1 SMP Tue Aug 14 21:49:04 UTC 2018",
            "sysname": "Linux",
            "architecture": "x86_64",
            "release": "3.10.0-862.11.6.el7.x86_64",
            "hostname": "localhost.localdomain",
            "agent_id": "001"
         }
      ],
      "totalItems": 2
   }
}

Best regards,

Demetrio.

@druizz90 druizz90 added type/bug Something isn't working module/api labels Apr 23, 2019
@druizz90 druizz90 added this to the 17th week milestone Apr 23, 2019
@druizz90 druizz90 requested a review from crd1985 April 23, 2019 16:00
@druizz90 druizz90 self-assigned this Apr 23, 2019
@druizz90 druizz90 changed the title Fix offset parameter in API call 'experimental/ciscat/results Fix offset parameter for experimental API calls Apr 23, 2019
@mgmacias95
Copy link
Contributor

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:

# curl -u foo:bar "localhost:55000/experimental/syscollector/packages?offset=550&limit=1&pretty"
{
   "error": 0,
   "data": {
      "items": [],
      "totalItems": 1045
   }
}

Best regards,
Marta

@crd1985 crd1985 removed this from the 17th week milestone Apr 25, 2019
@druizz90 druizz90 marked this pull request as ready for review May 13, 2019 14:40
Copy link
Contributor

@crd1985 crd1985 left a 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?

@druizz90
Copy link
Contributor Author

I updated issue wazuh/wazuh-api#152 with examples of experimental calls after applying this fix.

@druizz90
Copy link
Contributor Author

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 filterFilter: 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)

@druizz90
Copy link
Contributor Author

druizz90 commented May 23, 2019

PR update

This fix works when cluster is disabled.

When cluster is enabled, offset and limit parameters are applied before merging results and does not work properly.

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:

experimental/syscollector/os

Before
# curl -u foo:bar "localhost:55000/experimental/syscollector/os?pretty"
{
   "error": 0,
   "data": {
      "items": [
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 1290471424,
               "time": "2019/05/23 11:34:53"
            },
            "hostname": "673e4fe29ff7",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "sysname": "Linux",
            "release": "5.0.16-300.fc30.x86_64",
            "architecture": "x86_64",
            "agent_id": "000"
         },
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 566053441,
               "time": "2019/05/23 11:36:02"
            },
            "hostname": "b0803afae4e3",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "sysname": "Linux",
            "release": "5.0.16-300.fc30.x86_64",
            "architecture": "x86_64",
            "agent_id": "003"
         },
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 1645409083,
               "time": "2019/05/23 11:34:53"
            },
            "hostname": "aa8d74b964e9",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "sysname": "Linux",
            "release": "5.0.16-300.fc30.x86_64",
            "architecture": "x86_64",
            "agent_id": "000"
         },
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 683024323,
               "time": "2019/05/23 11:36:02"
            },
            "hostname": "e375dadfcf44",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "sysname": "Linux",
            "release": "5.0.16-300.fc30.x86_64",
            "architecture": "x86_64",
            "agent_id": "002"
         },
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 2027315863,
               "time": "2019/05/23 11:34:52"
            },
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "hostname": "b5c7c060620e",
            "release": "5.0.16-300.fc30.x86_64",
            "architecture": "x86_64",
            "sysname": "Linux",
            "agent_id": "000"
         },
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 1776818074,
               "time": "2019/05/23 11:36:01"
            },
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "hostname": "9b81936b58ed",
            "release": "5.0.16-300.fc30.x86_64",
            "architecture": "x86_64",
            "sysname": "Linux",
            "agent_id": "001"
         }
      ],
      "totalItems": 6
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/os?pretty&offset=2"
{
   "error": 0,
   "data": {
      "items": [],
      "totalItems": 0
   }
}
After
# curl -u foo:bar "localhost:55000/experimental/syscollector/os?pretty"
{
   "error": 0,
   "data": {
      "items": [
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 832517818,
               "time": "2019/05/23 16:32:25"
            },
            "release": "5.0.16-300.fc30.x86_64",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "architecture": "x86_64",
            "sysname": "Linux",
            "hostname": "fc8d374c214b",
            "agent_id": "000"
         },
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 686581434,
               "time": "2019/05/23 16:33:35"
            },
            "release": "5.0.16-300.fc30.x86_64",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "architecture": "x86_64",
            "sysname": "Linux",
            "hostname": "9aa354df8a83",
            "agent_id": "002"
         },
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 1223330411,
               "time": "2019/05/23 16:32:25"
            },
            "hostname": "abcd4e12ecea",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "sysname": "Linux",
            "release": "5.0.16-300.fc30.x86_64",
            "architecture": "x86_64",
            "agent_id": "000"
         },
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 1502027121,
               "time": "2019/05/23 16:33:35"
            },
            "hostname": "33bd84a09c9b",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "sysname": "Linux",
            "release": "5.0.16-300.fc30.x86_64",
            "architecture": "x86_64",
            "agent_id": "003"
         },
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 1619986067,
               "time": "2019/05/23 16:32:24"
            },
            "architecture": "x86_64",
            "hostname": "cdab78d60c78",
            "sysname": "Linux",
            "release": "5.0.16-300.fc30.x86_64",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "agent_id": "000"
         },
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 1925493204,
               "time": "2019/05/23 16:33:33"
            },
            "architecture": "x86_64",
            "hostname": "dcac85de3e71",
            "sysname": "Linux",
            "release": "5.0.16-300.fc30.x86_64",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "agent_id": "001"
         }
      ],
      "totalItems": 6
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/os?pretty&offset=5"
{
   "error": 0,
   "data": {
      "items": [
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 1925493204,
               "time": "2019/05/23 16:33:33"
            },
            "hostname": "dcac85de3e71",
            "release": "5.0.16-300.fc30.x86_64",
            "sysname": "Linux",
            "architecture": "x86_64",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "agent_id": "001"
         }
      ],
      "totalItems": 6
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/os?pretty&offset=3&limit=2"
{
   "error": 0,
   "data": {
      "items": [
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 1502027121,
               "time": "2019/05/23 16:33:35"
            },
            "hostname": "33bd84a09c9b",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "sysname": "Linux",
            "release": "5.0.16-300.fc30.x86_64",
            "architecture": "x86_64",
            "agent_id": "003"
         },
         {
            "os": {
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "version": "18.04.2 LTS (Bionic Beaver)"
            },
            "scan": {
               "id": 1619986067,
               "time": "2019/05/23 16:32:24"
            },
            "sysname": "Linux",
            "version": "#1 SMP Tue May 14 19:33:09 UTC 2019",
            "hostname": "cdab78d60c78",
            "architecture": "x86_64",
            "release": "5.0.16-300.fc30.x86_64",
            "agent_id": "000"
         }
      ],
      "totalItems": 6
   }
}

experimental/syscollector/hardware

Before
# curl -u foo:bar "localhost:55000/experimental/syscollector/hardware?pretty"
{
   "error": 0,
   "data": {
      "items": [
         {
            "cpu": {
               "cores": 4,
               "mhz": 1584.117,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 199960,
               "total": 7943700,
               "usage": 98
            },
            "scan": {
               "id": 365054558,
               "time": "2019/05/23 11:34:53"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "000"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 599.82,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 208908,
               "total": 7943700,
               "usage": 98
            },
            "scan": {
               "id": 816836068,
               "time": "2019/05/23 11:36:02"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "003"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 800.002,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 205332,
               "total": 7943700,
               "usage": 98
            },
            "scan": {
               "id": 1993352903,
               "time": "2019/05/23 11:34:53"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "000"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 654.219,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 217224,
               "total": 7943700,
               "usage": 98
            },
            "scan": {
               "id": 1467786203,
               "time": "2019/05/23 11:36:02"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "002"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 3032.693,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 286712,
               "total": 7943700,
               "usage": 97
            },
            "scan": {
               "id": 429558585,
               "time": "2019/05/23 11:34:52"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "000"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 757.419,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 209240,
               "total": 7943700,
               "usage": 98
            },
            "scan": {
               "id": 671479075,
               "time": "2019/05/23 11:36:01"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "001"
         }
      ],
      "totalItems": 6
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/hardware?pretty&offset=2"
{
   "error": 0,
   "data": {
      "items": [],
      "totalItems": 0
   }
}
After
# curl -u foo:bar "localhost:55000/experimental/syscollector/hardware?pretty"
{
   "error": 0,
   "data": {
      "items": [
         {
            "cpu": {
               "cores": 4,
               "mhz": 2709.512,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 433056,
               "total": 7943700,
               "usage": 95
            },
            "scan": {
               "id": 1180166620,
               "time": "2019/05/23 16:32:25"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "000"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 699.999,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 203620,
               "total": 7943700,
               "usage": 98
            },
            "scan": {
               "id": 775472181,
               "time": "2019/05/23 16:33:35"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "002"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 1984.469,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 431372,
               "total": 7943700,
               "usage": 95
            },
            "scan": {
               "id": 767837193,
               "time": "2019/05/23 16:32:25"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "000"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 699.999,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 203620,
               "total": 7943700,
               "usage": 98
            },
            "scan": {
               "id": 628286692,
               "time": "2019/05/23 16:33:35"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "003"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 767.579,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 435848,
               "total": 7943700,
               "usage": 95
            },
            "scan": {
               "id": 1651607066,
               "time": "2019/05/23 16:32:24"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "000"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 1587.236,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 217012,
               "total": 7943700,
               "usage": 98
            },
            "scan": {
               "id": 567486905,
               "time": "2019/05/23 16:33:33"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "001"
         }
      ],
      "totalItems": 6
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/hardware?pretty&offset=5"
{
   "error": 0,
   "data": {
      "items": [
         {
            "cpu": {
               "cores": 4,
               "mhz": 1587.236,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 217012,
               "total": 7943700,
               "usage": 98
            },
            "scan": {
               "id": 567486905,
               "time": "2019/05/23 16:33:33"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "001"
         }
      ],
      "totalItems": 6
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/hardware?pretty&offset=2&limit=3"
{
   "error": 0,
   "data": {
      "items": [
         {
            "cpu": {
               "cores": 4,
               "mhz": 1984.469,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 431372,
               "total": 7943700,
               "usage": 95
            },
            "scan": {
               "id": 767837193,
               "time": "2019/05/23 16:32:25"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "000"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 699.999,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 203620,
               "total": 7943700,
               "usage": 98
            },
            "scan": {
               "id": 628286692,
               "time": "2019/05/23 16:33:35"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "003"
         },
         {
            "cpu": {
               "cores": 4,
               "mhz": 767.579,
               "name": "Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz"
            },
            "ram": {
               "free": 435848,
               "total": 7943700,
               "usage": 95
            },
            "scan": {
               "id": 1651607066,
               "time": "2019/05/23 16:32:24"
            },
            "board_serial": "PM00R017AM000245",
            "agent_id": "000"
         }
      ],
      "totalItems": 6
   }
}

experimental/syscollector/netaddr

Before
# curl -u foo:bar "localhost:55000/experimental/syscollector/netaddr?pretty"
{
   "error": 0,
   "data": {
      "items": [
         {
            "proto": "ipv4",
            "scan_id": 888314665,
            "broadcast": "172.27.255.255",
            "netmask": "255.255.0.0",
            "iface": "eth0",
            "address": "172.27.0.5",
            "agent_id": "000"
         },
         {
            "proto": "ipv4",
            "scan_id": 1960689048,
            "broadcast": "172.27.255.255",
            "netmask": "255.255.0.0",
            "iface": "eth0",
            "address": "172.27.0.7",
            "agent_id": "003"
         },
         {
            "proto": "ipv4",
            "iface": "eth0",
            "broadcast": "172.27.255.255",
            "netmask": "255.255.0.0",
            "scan_id": 778678990,
            "address": "172.27.0.4",
            "agent_id": "000"
         },
         {
            "proto": "ipv4",
            "iface": "eth0",
            "broadcast": "172.27.255.255",
            "netmask": "255.255.0.0",
            "scan_id": 868443935,
            "address": "172.27.0.6",
            "agent_id": "002"
         },
         {
            "iface": "eth0",
            "address": "172.27.0.2",
            "proto": "ipv4",
            "scan_id": 827096261,
            "netmask": "255.255.0.0",
            "broadcast": "172.27.255.255",
            "agent_id": "000"
         },
         {
            "iface": "eth0",
            "address": "172.27.0.3",
            "proto": "ipv4",
            "scan_id": 1119695480,
            "netmask": "255.255.0.0",
            "broadcast": "172.27.255.255",
            "agent_id": "001"
         }
      ],
      "totalItems": 6
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/netaddr?pretty&offset=3"
{
   "error": 0,
   "data": {
      "items": [],
      "totalItems": 6
   }
}
After
# curl -u foo:bar "localhost:55000/experimental/syscollector/netaddr?pretty"
{
   "error": 0,
   "data": {
      "items": [
         {
            "address": "172.26.0.3",
            "scan_id": 58631636,
            "netmask": "255.255.0.0",
            "broadcast": "172.26.255.255",
            "iface": "eth0",
            "proto": "ipv4",
            "agent_id": "000"
         },
         {
            "address": "172.26.0.7",
            "scan_id": 1607499299,
            "netmask": "255.255.0.0",
            "broadcast": "172.26.255.255",
            "iface": "eth0",
            "proto": "ipv4",
            "agent_id": "003"
         },
         {
            "iface": "eth0",
            "address": "172.26.0.5",
            "broadcast": "172.26.255.255",
            "netmask": "255.255.0.0",
            "proto": "ipv4",
            "scan_id": 1825453634,
            "agent_id": "000"
         },
         {
            "iface": "eth0",
            "address": "172.26.0.6",
            "broadcast": "172.26.255.255",
            "netmask": "255.255.0.0",
            "proto": "ipv4",
            "scan_id": 380577421,
            "agent_id": "002"
         },
         {
            "address": "172.26.0.2",
            "broadcast": "172.26.255.255",
            "scan_id": 2032697563,
            "netmask": "255.255.0.0",
            "proto": "ipv4",
            "iface": "eth0",
            "agent_id": "000"
         },
         {
            "address": "172.26.0.4",
            "broadcast": "172.26.255.255",
            "scan_id": 452119902,
            "netmask": "255.255.0.0",
            "proto": "ipv4",
            "iface": "eth0",
            "agent_id": "001"
         }
      ],
      "totalItems": 6
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/netaddr?pretty&offset=5"
{
   "error": 0,
   "data": {
      "items": [
         {
            "netmask": "255.255.0.0",
            "address": "172.26.0.4",
            "broadcast": "172.26.255.255",
            "scan_id": 452119902,
            "iface": "eth0",
            "proto": "ipv4",
            "agent_id": "001"
         }
      ],
      "totalItems": 6
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/netaddr?pretty&offset=3&limit=2"
{
   "error": 0,
   "data": {
      "items": [
         {
            "iface": "eth0",
            "address": "172.26.0.6",
            "broadcast": "172.26.255.255",
            "netmask": "255.255.0.0",
            "proto": "ipv4",
            "scan_id": 380577421,
            "agent_id": "002"
         },
         {
            "proto": "ipv4",
            "address": "172.26.0.2",
            "iface": "eth0",
            "scan_id": 2032697563,
            "netmask": "255.255.0.0",
            "broadcast": "172.26.255.255",
            "agent_id": "000"
         }
      ],
      "totalItems": 6
   }
}

experimental/syscollector/packages

Before
# curl -u foo:bar "localhost:55000/experimental/syscollector/packages?pretty&limit=1"
{
   "error": 0,
   "data": {
      "items": [
         {
            "scan": {
               "id": 1792691566,
               "time": "2019/05/23 11:34:53"
            },
            "size": 32,
            "name": "libnpth0",
            "multiarch": "same",
            "version": "1.5-3",
            "description": "replacement for GNU Pth using system threads",
            "format": "deb",
            "architecture": "amd64",
            "priority": "optional",
            "section": "libs",
            "source": "npth",
            "vendor": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",
            "agent_id": "000"
         }
      ],
      "totalItems": 1389
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/packages?pretty&offset=900"
{
   "error": 0,
   "data": {
      "items": [],
      "totalItems": 1389
   }
}
After
# curl -u foo:bar "localhost:55000/calhost:55000/experimental/syscollector/packages?pretty&limit=1"
{
   "error": 0,
   "data": {
      "items": [
         {
            "scan": {
               "id": 1421488291,
               "time": "2019/05/23 10:51:02"
            },
            "name": "libquadmath0",
            "priority": "optional",
            "section": "libs",
            "size": 269,
            "source": "gcc-8",
            "description": "GCC Quad-Precision Math Library",
            "format": "deb",
            "version": "8.3.0-6ubuntu1~18.04",
            "vendor": "Ubuntu Core developers <ubuntu-devel-discuss@lists.ubuntu.com>",
            "multiarch": "same",
            "architecture": "amd64",
            "agent_id": "000"
         }
      ],
      "totalItems": 1389
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/packages?pretty&offset=1388"
{
   "error": 0,
   "data": {
      "items": [
         {
            "scan": {
               "id": 1163964002,
               "time": "2019/05/23 10:52:11"
            },
            "size": 44,
            "format": "deb",
            "name": "netbase",
            "priority": "important",
            "architecture": "all",
            "vendor": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",
            "multiarch": "foreign",
            "description": "Basic TCP/IP networking system",
            "version": "5.4",
            "section": "admin",
            "agent_id": "001"
         }
      ],
      "totalItems": 1389
   }
}
# curl -u foo:bar "localhost:55000/experimental/syscollector/packages?pretty&offset=588&limit=2"
{
   "error": 0,
   "data": {
      "items": [
         {
            "scan": {
               "id": 1662178753,
               "time": "2019/05/23 10:51:02"
            },
            "priority": "optional",
            "section": "libs",
            "architecture": "amd64",
            "version": "1.14.1-6",
            "format": "deb",
            "multiarch": "same",
            "name": "libgdbm5",
            "source": "gdbm",
            "description": "GNU dbm database routines (runtime version) ",
            "vendor": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",
            "size": 77,
            "agent_id": "000"
         },
         {
            "scan": {
               "id": 1662178753,
               "time": "2019/05/23 10:51:02"
            },
            "priority": "optional",
            "section": "python",
            "architecture": "all",
            "version": "39.0.1-2",
            "format": "deb",
            "multiarch": "foreign",
            "name": "python-pkg-resources",
            "source": "python-setuptools",
            "description": "Package Discovery and Resource Access using pkg_resources",
            "vendor": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",
            "size": 545,
            "agent_id": "000"
         }
      ],
      "totalItems": 1389
   }
}

# 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
Copy link
Contributor

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.

Copy link
Contributor Author

@druizz90 druizz90 May 28, 2019

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:

if len(nodes) > 1:

Thoughts?

@druizz90 druizz90 closed this Jun 3, 2019
@druizz90 druizz90 reopened this Jun 3, 2019
@druizz90 druizz90 requested a review from crd1985 June 3, 2019 09:25
@vikman90 vikman90 closed this Jul 17, 2020
@vikman90 vikman90 reopened this Jul 20, 2020
@vikman90 vikman90 changed the base branch from 3.10 to develop July 20, 2020 08:32
@davidjiglesias davidjiglesias deleted the fix-ciscat-pagination branch November 20, 2020 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/api type/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants