Hi Cyprien,
You can increase the token expiration time by modifying the
auth_token_exp_timeout value (in seconds), with an API call to
PUT /security/config. Check this for more details.
There is no way to completely disable token expiry, but you can greatly increase the value of the mentioned variable. However, keep in mind that automatic token expiration is a security feature that can be useful in case your token is leaked. It is more advisable to develop a mechanism in your script that automatically requests a new token if the current one expires.
As for your second question, you can use a tool like
jq to easily parse the received data.
For example, let's say that this the response you get when listing the agents through the API, and it's saved on file agents_status.json (just for demonstration purposes)
{
"data": {
"affected_items": [
{
"os": {
"arch": "x86_64",
"codename": "Bionic Beaver",
"major": "18",
"minor": "04",
"name": "Ubuntu",
"platform": "ubuntu",
"uname": "Linux |wazuh-master |5.4.0-52-generic |#57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 |x86_64",
"version": "18.04.4 LTS"
},
"manager": "wazuh-master",
"status": "active",
"node_name": "master-node",
"lastKeepAlive": "9999-12-31T23:59:59Z",
"ip": "127.0.0.1",
"id": "000",
"version": "Wazuh v4.0.0",
"name": "wazuh-master",
"registerIP": "127.0.0.1",
"dateAdd": "2020-10-26T09:52:01Z"
},
{
"status": "never_connected",
"node_name": "unknown",
"group": [
"default",
"group1",
"dbms"
],
"ip": "any",
"id": "009",
"name": "wazuh-agent9",
"registerIP": "any",
"dateAdd": "1970-01-01T00:00:00Z"
}
],
"total_affected_items": 2,
"total_failed_items": 0,
"failed_items": []
},
"message": "All selected agents information was returned",
"error": 0
}
Running this command:
cat agents_status.json | jq '.data.affected_items[] | .id + ":" + .status'
Will give you a line for each agent, with its id and its connection status:
"000:active"
"009:never_connected"
I hope this helps.
Regards!