Forum Discussion

Ryan_'s avatar
Ryan_
Icon for Nimbostratus rankNimbostratus
May 10, 2023

Health Monitor using API token

I am checking a server using an API, using curl it succeeds but it takes two steps. First I request a bearer token by sending username and password, I then recieve a token valid for 300 seconds. I then pass that token to the api page and get a reponse with text I can match against for health monitoring. The API wont accept basic auth unfortunately.

I am a bit stuck as to how I can translate this into a health monitor though, if anyone can help it would be appreciated it. I presume I need an external monitor as there would be no way to pass the token as a variable to my post request right?

here is a basic overview from the cli I have trimmed outputs:

 

Get a token:

curl -k --request POST --url https://192.168.1.1/api/v1/token --data "grant_type=password&username=myusername&password=pass123"

repsonds with:
"access_token":"123mytoken123","token_type":"bearer","expires_in":300"}

Send a second request
curl -kH "Authorization: Bearer 123mytoken123" "https://192.168.1.1/api/v1/serverstatus"

responds with:
{"ThisNode":1,"ServerStatus":"Alive","ServerHasError":false}