-
Notifications
You must be signed in to change notification settings - Fork 5
Integ 3104/date filter #167
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,30 @@ def agents(): | |
| default=None, | ||
| help="Filter agents that have had agent health modified in the last N days (starting from midnight this morning), where N is the value of the parameter.", | ||
| ) | ||
| @click.option( | ||
| "--connected-in-last-days", | ||
| type=int, | ||
| default=None, | ||
| help="When specified, agents are filtered to include only those that have connected in the last N days (starting from midnight this morning), where N is the value of the parameter.", | ||
| ) | ||
| @click.option( | ||
| "--not-connected-in-last-days", | ||
| type=int, | ||
| default=None, | ||
| help="When specified, agents are filtered to include only those that have not connected in the last N days (starting from midnight this morning), where N is the value of the parameter.", | ||
| ) | ||
| @click.option( | ||
| "--serial-number", | ||
| type=str, | ||
| default=None, | ||
| help="When specified, returns agents that have this serial number.", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor; will more than one agent ever match a given serial number?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you can for example have multiple agent installs sequentially on the same machine (different guids, so different entries on our side, but each will have the same serial number). |
||
| ) | ||
| @click.option( | ||
| "--agent-os-types", | ||
| type=str, | ||
| default=None, | ||
| help="When specified, agents are filtered to include only those of the given OS types. Pass a comma-delimited list of the OS types you wish to search. OS types include the following: WINDOWS, MAC, LINUX.", | ||
| ) | ||
| @table_format_option | ||
| @columns_option | ||
| @logging_options | ||
|
|
@@ -74,6 +98,10 @@ def list_( | |
| healthy: bool = None, | ||
| unhealthy: str = None, | ||
| agent_health_modified_within_days: int = None, | ||
| connected_in_last_days: int = None, | ||
| not_connected_in_last_days: int = None, | ||
| serial_number: int = None, | ||
| agent_os_types: str = None, | ||
| format_: TableFormat = None, | ||
| columns: str = None, | ||
| ): | ||
|
|
@@ -91,13 +119,20 @@ def list_( | |
| ): # If the unhealthy value is FLAG_VALUE then we know the option was passed with no values | ||
| health_issues = unhealthy.split(",") | ||
|
|
||
| if agent_os_types: | ||
| agent_os_types = agent_os_types.split(",") | ||
|
|
||
| client = Client() | ||
|
|
||
| agents = client.agents.v1.iter_all( | ||
| active=active, | ||
| agent_healthy=agent_healthy, | ||
| agent_health_issue_types=health_issues, | ||
| agent_health_modified_in_last_days=agent_health_modified_within_days, | ||
| connected_in_last_days=connected_in_last_days, | ||
| not_connected_in_last_days=not_connected_in_last_days, | ||
| serial_number=serial_number, | ||
| agent_os_types=agent_os_types, | ||
| ) | ||
|
|
||
| if format_ == TableFormat.table: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,6 +200,122 @@ def test_get_page_when_agent_health_modified_in_last_days_passed_makes_expected_ | |
| assert page.total_count == len(page.agents) == 2 | ||
|
|
||
|
|
||
| def test_get_page_when_connected_in_last_days_passed_makes_expected_call( | ||
| httpserver_auth: HTTPServer, | ||
| ): | ||
| query = { | ||
| "connectedInLastDays": 7, | ||
| "srtKey": "NAME", | ||
| "srtDir": "ASC", | ||
| "pageSize": 500, | ||
| "page": 1, | ||
| } | ||
|
|
||
| agents_data = { | ||
| "agents": [TEST_AGENT_1, TEST_AGENT_2], | ||
| "totalCount": 2, | ||
| "pageSize": 500, | ||
| "page": 1, | ||
| } | ||
| httpserver_auth.expect_request( | ||
| uri="/v1/agents", method="GET", query_string=urlencode(query) | ||
| ).respond_with_json(agents_data) | ||
|
|
||
| client = Client() | ||
| page = client.agents.v1.get_page(connected_in_last_days=7) | ||
| assert isinstance(page, AgentsPage) | ||
| assert page.agents[0].json() == json.dumps(TEST_AGENT_1, separators=(",", ":")) | ||
| assert page.agents[1].json() == json.dumps(TEST_AGENT_2, separators=(",", ":")) | ||
| assert page.total_count == len(page.agents) == 2 | ||
|
|
||
|
|
||
| def test_get_page_when_not_connected_in_last_days_passed_makes_expected_call( | ||
| httpserver_auth: HTTPServer, | ||
| ): | ||
| query = { | ||
| "notConnectedInLastDays": 7, | ||
| "srtKey": "NAME", | ||
| "srtDir": "ASC", | ||
| "pageSize": 500, | ||
| "page": 1, | ||
| } | ||
|
|
||
| agents_data = { | ||
| "agents": [TEST_AGENT_1, TEST_AGENT_2], | ||
| "totalCount": 2, | ||
| "pageSize": 500, | ||
| "page": 1, | ||
| } | ||
| httpserver_auth.expect_request( | ||
| uri="/v1/agents", method="GET", query_string=urlencode(query) | ||
| ).respond_with_json(agents_data) | ||
|
|
||
| client = Client() | ||
| page = client.agents.v1.get_page(not_connected_in_last_days=7) | ||
| assert isinstance(page, AgentsPage) | ||
| assert page.agents[0].json() == json.dumps(TEST_AGENT_1, separators=(",", ":")) | ||
| assert page.agents[1].json() == json.dumps(TEST_AGENT_2, separators=(",", ":")) | ||
| assert page.total_count == len(page.agents) == 2 | ||
|
|
||
|
|
||
| def test_get_page_when_serial_number_passed_makes_expected_call( | ||
| httpserver_auth: HTTPServer, | ||
| ): | ||
| query = { | ||
| "serialNumber": "example", | ||
| "srtKey": "NAME", | ||
| "srtDir": "ASC", | ||
| "pageSize": 500, | ||
| "page": 1, | ||
| } | ||
|
|
||
| agents_data = { | ||
| "agents": [TEST_AGENT_1, TEST_AGENT_2], | ||
| "totalCount": 2, | ||
| "pageSize": 500, | ||
| "page": 1, | ||
| } | ||
| httpserver_auth.expect_request( | ||
| uri="/v1/agents", method="GET", query_string=urlencode(query) | ||
| ).respond_with_json(agents_data) | ||
|
|
||
| client = Client() | ||
| page = client.agents.v1.get_page(serial_number="example") | ||
| assert isinstance(page, AgentsPage) | ||
| assert page.agents[0].json() == json.dumps(TEST_AGENT_1, separators=(",", ":")) | ||
| assert page.agents[1].json() == json.dumps(TEST_AGENT_2, separators=(",", ":")) | ||
| assert page.total_count == len(page.agents) == 2 | ||
|
|
||
|
|
||
| def test_get_page_when_agent_os_types_passed_makes_expected_call( | ||
| httpserver_auth: HTTPServer, | ||
| ): | ||
| query = { | ||
| "anyOfAgentOsTypes": ["LINUX", "MAC"], | ||
| "srtKey": "NAME", | ||
| "srtDir": "ASC", | ||
| "pageSize": 500, | ||
| "page": 1, | ||
| } | ||
|
|
||
| agents_data = { | ||
| "agents": [TEST_AGENT_1, TEST_AGENT_2], | ||
| "totalCount": 2, | ||
| "pageSize": 500, | ||
| "page": 1, | ||
| } | ||
| httpserver_auth.expect_request( | ||
| uri="/v1/agents", method="GET", query_string=urlencode(query, doseq=True) | ||
| ).respond_with_json(agents_data) | ||
|
|
||
| client = Client() | ||
| page = client.agents.v1.get_page(agent_os_types=["LINUX", "MAC"]) | ||
| assert isinstance(page, AgentsPage) | ||
| assert page.agents[0].json() == json.dumps(TEST_AGENT_1, separators=(",", ":")) | ||
| assert page.agents[1].json() == json.dumps(TEST_AGENT_2, separators=(",", ":")) | ||
| assert page.total_count == len(page.agents) == 2 | ||
|
|
||
|
|
||
| def test_iter_all_when_default_params_returns_expected_data( | ||
| httpserver_auth: HTTPServer, | ||
| ): | ||
|
|
@@ -303,6 +419,7 @@ def test_cli_list_when_custom_params_makes_expected_call( | |
| ): | ||
| query = { | ||
| "active": True, | ||
| "notConnectedInLastDays": 5, | ||
| "agentHealthy": True, | ||
| "srtKey": "NAME", | ||
| "srtDir": "ASC", | ||
|
|
@@ -320,7 +437,17 @@ def test_cli_list_when_custom_params_makes_expected_call( | |
| uri="/v1/agents", method="GET", query_string=urlencode(query) | ||
| ).respond_with_json(agents_data) | ||
|
|
||
| result = runner.invoke(incydr, ["agents", "list", "--active", "--healthy"]) | ||
| result = runner.invoke( | ||
| incydr, | ||
| [ | ||
| "agents", | ||
| "list", | ||
| "--active", | ||
| "--healthy", | ||
| "--not-connected-in-last-days", | ||
| "5", | ||
| ], | ||
| ) | ||
| httpserver_auth.check() | ||
| assert result.exit_code == 0 | ||
|
|
||
|
|
@@ -381,6 +508,33 @@ def test_cli_list_when_unhealthy_option_passed_with_string_parses_issue_types_co | |
| assert result.exit_code == 0 | ||
|
|
||
|
|
||
| def test_cli_list_when_agent_os_types_passed_with_string_parses_os_types_correctly( | ||
| httpserver_auth: HTTPServer, runner | ||
| ): | ||
| query = [ | ||
| ("anyOfAgentOsTypes", "LINUX"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The query for the other one looked like this:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the way that we handle this is when a list is given, we pass the parameter twice, so the url ends up looking like Both work successfully in test and in practice. |
||
| ("anyOfAgentOsTypes", "MAC"), | ||
| ("srtKey", "NAME"), | ||
| ("srtDir", "ASC"), | ||
| ("pageSize", 500), | ||
| ("page", 1), | ||
| ] | ||
|
|
||
| agents_data = { | ||
| "agents": [TEST_AGENT_1, TEST_AGENT_2], | ||
| "totalCount": 2, | ||
| "pageSize": 500, | ||
| "page": 1, | ||
| } | ||
| httpserver_auth.expect_request( | ||
| uri="/v1/agents", method="GET", query_string=urlencode(query) | ||
| ).respond_with_json(agents_data) | ||
|
|
||
| result = runner.invoke(incydr, ["agents", "list", "--agent-os-types", "LINUX,MAC"]) | ||
| httpserver_auth.check() | ||
| assert result.exit_code == 0 | ||
|
|
||
|
|
||
| def test_cli_list_when_health_modified_days_option_passed_makes_expected_call( | ||
| httpserver_auth: HTTPServer, runner | ||
| ): | ||
|
|
||
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.
are --connected-in-last-days and --not-connected-in-last-days able to be used at the same time?
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.
Yes!