def test_humio_create_alert(requests_mock): """Tests that a humio alert can be fetched based on its id""" from Humio import Client, humio_create_alert mock_response = util_load_json("test_data/create_alert_results.json") requests_mock.post( "https://test.com/api/v1/repositories/sandbox/alerts", json=mock_response, status_code=201, ) client = Client(base_url="https://test.com", verify=False, proxies=None) args = { "queryString": "alert=true", "start": "24h", "name": "TestingAlert", "description": "Description of TestingAlert", "throttleTimeMillis": "3000000", "repository": "sandbox", "silenced": "false", "notifiers": "BTkuj8QArhIFMh_L39FoN0tnyTUEXplc", "labels": "", } _, outputs, _ = humio_create_alert(client, args, headers) assert outputs["Humio.Alert(val.id == obj.id)"] == mock_response
def test_humio_list_alerts(requests_mock): """Tests that a humio alerts can be listed""" from Humio import Client, humio_list_alerts mock_response = util_load_json("test_data/list_alerts_results.json") requests_mock.get( "https://test.com/api/v1/repositories/sandbox/alerts", json=mock_response ) client = Client(base_url="https://test.com", verify=False, proxies=None) args = {"repository": "sandbox"} _, outputs, _ = humio_list_alerts(client, args, headers) assert outputs["Humio.Alert(val.id == obj.id)"] == mock_response
def test_humio_get_notifier_by_id(requests_mock): """Tests that a humio alerts can be listed""" from Humio import Client, humio_get_notifier_by_id mock_response = util_load_json("test_data/notifier_by_id_results.json") requests_mock.get( "https://test.com/api/v1/repositories/sandbox/alertnotifiers/BTkuj8QArhIFMh_L39FoN0tnyTUEXplc", json=mock_response, ) client = Client(base_url="https://test.com", verify=False, proxies=None) args = {"repository": "sandbox", "id": "BTkuj8QArhIFMh_L39FoN0tnyTUEXplc"} _, outputs, _ = humio_get_notifier_by_id(client, args, headers) assert outputs["Humio.Notifier(val.id == obj.id)"] == mock_response
def test_humio_get_alert_by_id(requests_mock): """Tests that a humio alert can be fetched based on its id""" from Humio import Client, humio_get_alert_by_id mock_response = util_load_json("test_data/get_alert_by_id_results.json") requests_mock.get( "https://test.com/api/v1/repositories/sandbox/alerts/zNVae7vz-DH7GpeQUPfx1KXMGXGg7bf7", json=mock_response, ) client = Client(base_url="https://test.com", verify=False, proxies=None) args = {"repository": "sandbox", "id": "zNVae7vz-DH7GpeQUPfx1KXMGXGg7bf7"} _, outputs, _ = humio_get_alert_by_id(client, args, headers) assert outputs["Humio.Alert(val.id == obj.id)"] == mock_response
def test_humio_poll(requests_mock): """Tests that a humio queryjob can be polled""" from Humio import Client, humio_poll mock_response = util_load_json("test_data/poll_results.json") requests_mock.get( "https://test.com/api/v1/repositories/sandbox/queryjobs/testid", json=mock_response, ) client = Client(base_url="https://test.com", verify=False, proxies=None) args = {"id": "testid", "repository": "sandbox"} _, outputs, _ = humio_poll(client, args, headers) assert ( outputs["Humio.Result(val.job_id == obj.job_id)"]["events"] == mock_response["events"] )
def test_humio_query(requests_mock): """Tests that a humio query can be issued""" from Humio import Client, humio_query mock_response = util_load_json("test_data/query_results.json") requests_mock.post( "https://test.com/api/v1/repositories/sandbox/query", json=mock_response ) client = Client(base_url="https://test.com", verify=False, proxies=None) args = { "queryString": "test", "start": "24h", "end": "now", "isLive": "False", "timeZoneOffsetMinutes": 60, "repository": "sandbox", } _, outputs, _ = humio_query(client, args, headers) assert outputs == {"Humio.Query": [mock_response]}
def test_humio_query_job(requests_mock): """Tests that a humio queryjob can be issued""" from Humio import Client, humio_query_job mock_response = json.loads( """{"id": "1-xK13lC_jjtOYqPR1onSdlLm8","queryOnView": "<R:tail(limit=1.0)>"}""" ) requests_mock.post( "https://test.com/api/v1/repositories/sandbox/queryjobs", json=mock_response ) client = Client(base_url="https://test.com", verify=False, proxies=None) args = { "queryString": "tail(1)", "start": "24h", "end": "now", "isLive": "False", "timeZoneOffsetMinutes": 60, "repository": "sandbox", } _, outputs, _ = humio_query_job(client, args, headers) assert outputs["Humio.Job"]["id"] == mock_response["id"]