Query API to return job run count (Job-Based Metrics)

196 views
Skip to first unread message

Tory Greco

unread,
Jan 14, 2021, 5:09:06 PM1/14/21
to rundeck-discuss
Hey all,

Does anyone here know of an easy way to query the API and have it succinctly return the total number of times a given job has run successfully? I am reading https://docs.rundeck.com/docs/api/rundeck-api.html and can currently gather things like job ids, but nothing really pops out as giving me an easy way to collect total run count per job.


Thanks!

rac...@rundeck.com

unread,
Jan 15, 2021, 8:40:47 AM1/15/21
to rundeck-discuss

Hi Tory,

You can do it using the Rundeck API, jq tool, and some standard UNIX tools.

You need to call only the succeeded jobs in this way:

curl -s --location --request GET 'http://localhost:4440/api/37/job/76026d48-b728-4181-bb3f-5447ebba4a71/executions?status=succeeded' \
--header 'Accept: application/json' \
--header 'X-Rundeck-Auth-Token: tMkuJrY109liJUXACcr30NvzX6ieaBYo' \
--header 'Content-Type: application/json'

Now, using jq, grep and wc to get the amount of succeeded executions:

curl -s --location --request GET 'http://localhost:4440/api/37/job/76026d48-b728-4181-bb3f-5447ebba4a71/executions?status=succeeded' \
--header 'Accept: application/json' \
--header 'X-Rundeck-Auth-Token: tMkuJrY109liJUXACcr30NvzX6ieaBYo' \
--header 'Content-Type: application/json' jq | grep "status" | wc -l

Of course, you can create a better script like:

host="localhost"
port="4440"
jobid="76026d48-b728-4181-bb3f-5447ebba4a71"
status="succeeded"
rdeck_token="tMkuJrY109liJUXACcr30NvzX6ieaBYo"

execs=$(curl -s --location --request GET "http://$host:$port/api/37/job/$jobid/executions?status=$status" \
--header "Accept: application/json" \
--header "X-Rundeck-Auth-Token: $rdeck_token" \
--header "Content-Type: application/json" | jq | grep "status" | wc -l)

echo "Succeeded excutions $execs"

Output (Activity panel):

Succeeded excutions 4

Hope it helps!

Tory Greco

unread,
Jan 15, 2021, 11:43:34 PM1/15/21
to rundeck-discuss
Thank you so much, that worked perfectly!
Reply all
Reply to author
Forward
0 new messages