wazuh / wazuh-api

Wazuh - RESTful API
https://wazuh.com
GNU General Public License v2.0
69 stars 57 forks source link

Add support for API queries in CIS-CAT and Syscollector #361

Closed mgmacias95 closed 5 years ago

mgmacias95 commented 5 years ago

Hello team,

This PR adds API support for https://github.com/wazuh/wazuh/pull/2973.

Tests:

  Syscollector
    GET/syscollector/:agent_id/os
      ✓ Request (564ms)
      ✓ Selector (566ms)
      ✓ Not allowed selector (565ms)
    GET/syscollector/:agent_id/hardware
      ✓ Request (565ms)
      ✓ Selector (674ms)
      ✓ Not allowed selector (714ms)
    GET/syscollector/:agent_id/packages
      ✓ Request (750ms)
      ✓ Selector (605ms)
      ✓ Not allowed selector (558ms)
      ✓ Pagination (568ms)
      ✓ Wrong limit
      ✓ Sort - (586ms)
      ✓ Sort + (697ms)
      ✓ Wrong Sort (1083ms)
      ✓ Search (986ms)
      1) Filter: vendor
      ✓ Filter: name (605ms)
      ✓ Filter: architecture (735ms)
      ✓ Filter: format (677ms)
      ✓ Wrong filter
      ✓ Query (773ms)
    GET/experimental/syscollector/packages
      ✓ Request (735ms)
      ✓ Selector (358ms)
      ✓ Not allowed selector (313ms)
      ✓ Pagination (281ms)
      ✓ Wrong limit
      ✓ Sort - (293ms)
      ✓ Sort + (288ms)
      ✓ Wrong Sort (290ms)
      ✓ Search (657ms)
      2) Filter: vendor
      ✓ Filter: name (406ms)
      ✓ Filter: architecture (585ms)
      ✓ Filter: format (626ms)
      ✓ Wrong filter
      ✓ Query (492ms)
    GET/experimental/syscollector/os
      ✓ Request (311ms)
      ✓ Selector (300ms)
      ✓ Not allowed selector (280ms)
      ✓ Pagination (288ms)
      ✓ Wrong limit
      ✓ Search (327ms)
      ✓ Wrong filter
      ✓ Filter: architecture (313ms)
      ✓ Filter: os_name (303ms)
      ✓ Filter: release (326ms)
      ✓ Query (303ms)
    GET/experimental/syscollector/hardware
      ✓ Request (288ms)
      ✓ Selector (297ms)
      ✓ Not allowed selector (340ms)
      ✓ Pagination (381ms)
      ✓ Wrong limit
      ✓ Search (342ms)
      ✓ Wrong filter
      ✓ Wrong Sort (306ms)
      ✓ Filter: ram_total (347ms)
      ✓ Filter: cpu_cores (585ms)
      ✓ Filter: cpu_mhz (561ms)
      ✓ Filter: board_serial (390ms)
      ✓ Query (373ms)
    GET/experimental/syscollector/processes
      ✓ Request (526ms)
      ✓ Selector (370ms)
      ✓ Not allowed selector (296ms)
      ✓ Pagination (306ms)
      ✓ Wrong limit
      ✓ Search (591ms)
      ✓ Wrong filter
      ✓ Wrong Sort (381ms)
      ✓ Filter: state (360ms)
      ✓ Filter: ppid (380ms)
      ✓ Filter: egroup (321ms)
      ✓ Filter: euser (373ms)
      ✓ Filter: fgroup (342ms)
      ✓ Filter: name (322ms)
      ✓ Filter: nlwp (309ms)
      ✓ Filter: pgrp (397ms)
      ✓ Filter: priority (346ms)
      ✓ Filter: rgroup (323ms)
      ✓ Filter: ruser (326ms)
      ✓ Filter: sgroup (310ms)
      ✓ Filter: suser (338ms)
      ✓ Query (308ms)
    GET/experimental/syscollector/ports
      ✓ Request (317ms)
      ✓ Selector (341ms)
      ✓ Not allowed selector (341ms)
      ✓ Pagination (444ms)
      ✓ Wrong limit
      ✓ Search (430ms)
      ✓ Wrong filter
      ✓ Wrong Sort (296ms)
      ✓ Filter: protocol (348ms)
      ✓ Filter: local_ip (323ms)
      ✓ Filter: local_port (354ms)
      ✓ Filter: remote_ip (307ms)
      ✓ Filter: tx_queue (323ms)
      ✓ Filter: state (369ms)
      ✓ Query (335ms)
    GET/syscollector/netaddr
      ✓ Request (310ms)
      ✓ Selector (281ms)
      ✓ Not allowed selector (272ms)
      ✓ Pagination (289ms)
      ✓ Wrong limit
      ✓ Search (307ms)
      ✓ Wrong filter
      ✓ Wrong Sort (291ms)
      ✓ Filter: iface (297ms)
      ✓ Filter: proto (307ms)
      ✓ Filter: address (299ms)
      ✓ Filter: broadcast (290ms)
      ✓ Filter: netmask (291ms)
      ✓ Query (280ms)
    GET/experimental/syscollector/netproto
      ✓ Request (323ms)
      ✓ Selector (368ms)
      ✓ Not allowed selector (305ms)
      ✓ Pagination (328ms)
      ✓ Wrong limit
      ✓ Search (323ms)
      ✓ Wrong filter
      ✓ Wrong Sort (313ms)
      ✓ Filter: iface (309ms)
      ✓ Filter: type (319ms)
      ✓ Filter: gateway (330ms)
      ✓ Filter: dhcp (329ms)
      ✓ Query (361ms)
    GET/experimental/syscollector/netiface
      ✓ Request (402ms)
      ✓ Selector (411ms)
      ✓ Not allowed selector (342ms)
      ✓ Pagination (431ms)
      ✓ Wrong limit
      ✓ Search (422ms)
      ✓ Wrong filter
      ✓ Wrong Sort (465ms)
      ✓ Filter: name (507ms)
      ✓ Filter: type (431ms)
      ✓ Filter: state (535ms)
      ✓ Filter: mtu (438ms)
      ✓ Filter: tx_packets (462ms)
      ✓ Filter: rx_packets (433ms)
      ✓ Filter: tx_bytes (765ms)
      ✓ Filter: rx_bytes (645ms)
      ✓ Filter: tx_errors (640ms)
      ✓ Filter: rx_errors (677ms)
      ✓ Filter: tx_dropped (693ms)
      ✓ Filter: rx_dropped (399ms)
      ✓ Query (325ms)
    GET/syscollector/000/processes
      ✓ Request (306ms)
      ✓ Selector (272ms)
      ✓ Not allowed selector (261ms)
      ✓ Pagination (272ms)
      ✓ Wrong limit
      ✓ Search (312ms)
      ✓ Wrong filter
      ✓ Wrong Sort (281ms)
      ✓ Filter: state (280ms)
      ✓ Filter: ppid (294ms)
      ✓ Filter: egroup (285ms)
      ✓ Filter: euser (284ms)
      ✓ Filter: fgroup (278ms)
      ✓ Filter: name (282ms)
      ✓ Filter: nlwp (285ms)
      ✓ Filter: pgrp (292ms)
      ✓ Filter: priority (279ms)
      ✓ Filter: rgroup (288ms)
      ✓ Filter: ruser (285ms)
      ✓ Filter: sgroup (288ms)
      ✓ Filter: suser (279ms)
      ✓ Query (300ms)
    GET/syscollector/000/ports
      ✓ Request (291ms)
      ✓ Selector (311ms)
      ✓ Not allowed selector (295ms)
      ✓ Pagination (278ms)
      ✓ Wrong limit
      ✓ Search (345ms)
      ✓ Wrong filter
      ✓ Wrong Sort (444ms)
      ✓ Filter: protocol (286ms)
      ✓ Filter: local_ip (426ms)
      ✓ Filter: local_port (365ms)
      ✓ Filter: remote_ip (430ms)
      ✓ Filter: tx_queue (282ms)
      ✓ Filter: state (293ms)
      ✓ Query (439ms)
    GET/syscollector/000/netaddr
      ✓ Request (340ms)
      ✓ Selector (314ms)
      ✓ Not allowed selector (291ms)
      ✓ Pagination (399ms)
      ✓ Wrong limit
      ✓ Search (478ms)
      ✓ Wrong filter
      ✓ Wrong Sort (462ms)
      ✓ Filter: iface (414ms)
      ✓ Filter: proto (570ms)
      ✓ Filter: address (618ms)
      ✓ Filter: broadcast (578ms)
      ✓ Filter: netmask (610ms)
      ✓ Query (681ms)
    GET/syscollector/000/netproto
      ✓ Request (330ms)
      ✓ Selector (321ms)
      ✓ Not allowed selector (317ms)
      ✓ Pagination (316ms)
      ✓ Wrong limit
      ✓ Search (430ms)
      ✓ Wrong filter
      ✓ Wrong Sort (666ms)
      ✓ Filter: iface (534ms)
      ✓ Filter: type (500ms)
      ✓ Filter: gateway (320ms)
      ✓ Filter: dhcp (301ms)
      ✓ Query (294ms)
    GET/syscollector/000/netiface
      ✓ Request (303ms)
      ✓ Selector (313ms)
      ✓ Not allowed selector (494ms)
      ✓ Pagination (299ms)
      ✓ Wrong limit
      ✓ Search (284ms)
      ✓ Wrong filter
      ✓ Wrong Sort (279ms)
      ✓ Filter: name (304ms)
      ✓ Filter: type (323ms)
      ✓ Filter: state (279ms)
      ✓ Filter: mtu (286ms)
      ✓ Filter: tx_packets (395ms)
      ✓ Filter: rx_packets (469ms)
      ✓ Filter: tx_bytes (319ms)
      ✓ Filter: rx_bytes (358ms)
      ✓ Filter: tx_errors (415ms)
      ✓ Filter: rx_errors (322ms)
      ✓ Filter: tx_dropped (302ms)
      ✓ Filter: rx_dropped (276ms)
      ✓ Query (288ms)

  228 passing (2m)
  2 failing

  1) Syscollector
       GET/syscollector/:agent_id/packages
         Filter: vendor:
     Error: expected 200 "OK", got 400 "Bad Request"
      at Test._assertStatus (/home/vagrant/node_modules/supertest/lib/test.js:268:12)
      at Test._assertFunction (/home/vagrant/node_modules/supertest/lib/test.js:283:11)
      at Test.assert (/home/vagrant/node_modules/supertest/lib/test.js:173:18)
      at localAssert (/home/vagrant/node_modules/supertest/lib/test.js:131:12)
      at /home/vagrant/node_modules/supertest/lib/test.js:128:5
      at Test.Request.callback (/home/vagrant/node_modules/superagent/lib/node/index.js:728:3)
      at parser (/home/vagrant/node_modules/superagent/lib/node/index.js:916:18)
      at IncomingMessage.res.on (/home/vagrant/node_modules/superagent/lib/node/parsers/json.js:19:7)
      at endReadableNT (_stream_readable.js:1064:12)
      at _combinedTickCallback (internal/process/next_tick.js:139:11)
      at process._tickCallback (internal/process/next_tick.js:181:9)

  2) Syscollector
       GET/experimental/syscollector/packages
         Filter: vendor:
     Error: expected 200 "OK", got 400 "Bad Request"
      at Test._assertStatus (/home/vagrant/node_modules/supertest/lib/test.js:268:12)
      at Test._assertFunction (/home/vagrant/node_modules/supertest/lib/test.js:283:11)
      at Test.assert (/home/vagrant/node_modules/supertest/lib/test.js:173:18)
      at localAssert (/home/vagrant/node_modules/supertest/lib/test.js:131:12)
      at /home/vagrant/node_modules/supertest/lib/test.js:128:5
      at Test.Request.callback (/home/vagrant/node_modules/superagent/lib/node/index.js:728:3)
      at parser (/home/vagrant/node_modules/superagent/lib/node/index.js:916:18)
      at IncomingMessage.res.on (/home/vagrant/node_modules/superagent/lib/node/parsers/json.js:19:7)
      at endReadableNT (_stream_readable.js:1064:12)
      at _combinedTickCallback (internal/process/next_tick.js:139:11)
      at process._tickCallback (internal/process/next_tick.js:181:9)

Best regards, Marta

crd1985 commented 5 years ago

Replaced by https://github.com/wazuh/wazuh-api/pull/422