def test_send_logtest_msg(create_message_mock, close_mock, send_mock, init_mock, params): """Test `send_logtest_msg` function from module core.logtest. Parameters ---------- message : dict Message that will be sent to the logtest socket. """ expected_response = {'response': True} with patch('wazuh.core.logtest.WazuhSocketJSON.receive', return_value=expected_response): response = send_logtest_msg(**params) init_mock.assert_called_with(LOGTEST_SOCKET) create_message_mock.assert_called_with(origin={'name': 'Logtest', 'module': 'api/framework'}, **params) assert response == expected_response
def test_send_logtest_msg(create_message_mock, close_mock, send_mock, init_mock, params): """Test `send_logtest_msg` function from module core.logtest. Parameters ---------- params : dict Params that will be sent to the logtest socket. """ expected_response = {'data': {'response': True, 'output': {'timestamp': '1970-01-01T00:00:00.000000+0000'}}} with patch('wazuh.core.logtest.WazuhSocketJSON.receive', return_value=expected_response): response = send_logtest_msg(**params) init_mock.assert_called_with(LOGTEST_SOCKET) create_message_mock.assert_called_with(origin={'name': 'Logtest', 'module': 'framework'}, **params) assert response == expected_response
def run_logtest(token=None, event=None, log_format=None, location=None): """Get the logtest output after sending a JSON to its socket. Parameters ---------- token : str, optional Logtest session token. Default `None` event : str Log event. log_format : str Log format. location : str Log location. Raises ------ WazuhError(7000) If there are more kwargs than expected. Returns ------- dict Logtest response after analyzing the event. """ local_vars = locals() # Token is not required if local_vars['token'] is None: del local_vars['token'] response = send_logtest_msg(command='log_processing', parameters=local_vars) if response['error'] != 0: raise WazuhError(code=7000, extra_message=response.get( 'message', 'Could not parse error message')) return response
def end_logtest_session(token: str = None): """End the logtest session for the introduced token. Parameters ---------- token : str Logtest session token. Returns ------- dict Logtest response to the message. """ if token is None: raise WazuhError(7001) response = send_logtest_msg(command='remove_session', parameters={'token': token}) if response['error'] != 0: raise WazuhError(code=7000, extra_message=response.get( 'message', 'Could not parse error message')) return response