gatus
gatus copied to clipboard
Support JSONPath evaluation on all indexes of an array
I am attempting to parse an array.
{
"servers": [
{
"servername": "server1",
"serveractiveconn": 0,
"servertotalconn": 20,
"serverconnections": [],
"serverssl": 1,
"serversslinfo": "",
"serveractive": true,
"servererror": "",
"serverpriority": 0,
"serveroptional": 0,
"serverbps": "0 "
},
{
"servername": "server2",
"serveractiveconn": 0,
"servertotalconn": 60,
"serverconnections": [],
"serverssl": 1,
"serversslinfo": "",
"serveractive": true,
"servererror": "",
"serverpriority": 0,
"serveroptional": 0,
"serverbps": "0 "
},
{
"servername": "server2",
"serveractiveconn": 0,
"servertotalconn": 50,
"serverconnections": [],
"serverssl": 1,
"serversslinfo": "",
"serveractive": true,
"servererror": "",
"serverpriority": 0,
"serveroptional": 1,
"serverbps": "0 "
}
]
}
What I was hoping to get was if any of .servers[].servererror contained a value, that would be a bad condition.
len([BODY].status.servers[].servererror) == 0
This did not work and the only way I have found to make it work is by doing a test for each index of the array. Is there a better way?
Also, is there a better way to check that servererror is empty?
Unfortunately, 'wildcard' evaluation isn't currently supported. As you've mentioned, the best way to do this is by manually checking each index of the array:
conditions:
- "len([BODY].status.servers[0].servererror) == 0"
- "len([BODY].status.servers[1].servererror) == 0"
- "len([BODY].status.servers[2].servererror) == 0"
This is definitely subpar, especially if you have a dynamic number of servers, in which case I would recommend having an endpoint that allows retrieving a single server by name instead.
The alternative would be to add support for checking all values, which I think would be a good addition to Gatus:
conditions:
- "len([BODY].status.servers[*].servererror) == 0"
@TwiN Any news regarding support for JsonPath wildcard?
I have been using gatus for a few months now and i really like the simplicity of it.
I would like to have a central instance that polls each individual gatus (stage,qa,prod, multiple instances on each) and have a simple overview of current state.
The condition you mentioned in above comment would be perfect for this.
I have too many instances/endpoints to use remote instances experimental feature for this central instance.
I am quite inexperienced in golang, but with a little guidance im willing to try to implement the required changes myself and create a PR.
I especially like the len + wildcard combination to keep it as a "single" condition. i was thinking of having something like this as a condition (condition based on api/v1/endpoints/statuses
)
conditions:
- "len([BODY].[*].results[0].success == false) == 0"
I definitely do not want each endpoint to have its own "line" in the conditions because my instances check hundreds of endpoints each.