I’m working on a Low-Level Discovery (LLD) script for Zabbix, which is set up as an “External” item. The script interacts with Aruba’s API to generate hosts for different clients based on their specific sites and devices.
The Aruba API requires authentication via access tokens, which expire after a set period. When the token expires, I need to refresh it using a refresh token. The challenge is that I manage API credentials for multiple clients (client ID, client secret, access token, and refresh token) in a shared .ini
file.
The script is executed simultaneously for different clients, each accessing their own section in the .ini
file. However, when the script runs concurrently (for example, for 5 clients at once), the tokens in the .ini
file sometimes get lost or overwritten, leading to issues in API authentication.
Here’s what I’ve tried:
- I implemented file locking using
fcntl
to prevent multiple processes from writing to the file at the same time. - Each client’s tokens are stored in a separate section of the
.ini
file, and each script execution is responsible for updating its own client’s section. - I expected file locking to prevent issues with tokens being overwritten, but despite using this approach, the tokens still sometimes get lost or corrupted when the script runs concurrently for multiple clients.
I expected the tokens to be safely updated and written to the .ini
file without any loss or corruption, but the issue persists. How can I better handle concurrent updates to the .ini
file to ensure tokens are updated correctly? Is there a better way to manage API tokens in this scenario?
Additional Information:
For anyone interested in reviewing the code, it’s available on my GitHub repository:
https://github.com/HorselessName/monitoramento-aruba
3