async def get_stats(request, pretty=False, wait_for_complete=False, date=None): """Get manager's or local_node's stats. Returns Wazuh statistical information for the current or specified date. :param pretty: Show results in human-readable format :param wait_for_complete: Disable timeout response :param date: Selects the date for getting the statistical information. Format ISO 8601. """ if not date: date = datetime.datetime.today() else: date = deserialize_date(date) f_kwargs = {'date': date} dapi = DistributedAPI( f=stats.totals, f_kwargs=remove_nones_to_dict(f_kwargs), request_type='local_any', is_async=False, wait_for_complete=wait_for_complete, logger=logger, rbac_permissions=request['token_info']['rbac_policies']) data = raise_if_exc(await dapi.distribute_function()) return web.json_response(data=data, status=200, dumps=prettify if pretty else dumps)
async def get_stats_node(request, node_id, pretty=False, wait_for_complete=False, date=None): """Get a specified node's stats. Returns Wazuh statistical information in node {node_id} for the current or specified date. :param node_id: Cluster node name. :param pretty: Show results in human-readable format :param wait_for_complete: Disable timeout response :param date: Selects the date for getting the statistical information. Format YYYY-MM-DD. """ if not date: date = datetime.datetime.today() else: date = deserialize_date(date) f_kwargs = {'node_id': node_id, 'date': date} nodes = raise_if_exc(await get_system_nodes()) dapi = DistributedAPI( f=stats.totals, f_kwargs=remove_nones_to_dict(f_kwargs), request_type='distributed_master', is_async=False, wait_for_complete=wait_for_complete, logger=logger, rbac_permissions=request['token_info']['rbac_policies'], nodes=nodes) data = raise_if_exc(await dapi.distribute_function()) return web.json_response(data=data, status=200, dumps=prettify if pretty else dumps)
def test_deserialize_date_ko(mock_import): """Check that _deserialize_date function correctly handles expected exceptions""" result = util.deserialize_date('2020-06-24') assert not isinstance(result, date)
def test_deserialize_date(): """Check that _deserialize_date function transforms string into date""" result = util.deserialize_date('2020-06-24') assert isinstance(result, date)