Reputation: 35
I am trying to create a dashboard, for which i am getting all the details using API in Rundeck
and then want to write the data in Csv File,
here is an example trying to fetch data for weekly basis, which is not working [ error msg: {"error":true,"apiversion":35,"errorCode":"api.error.invalid.request","message":"Invalid API Request: /api/35/executions/1w"}
],kindly let me know what am i doing wrong to fetch details on weekly, monthly and daily basis
format
#!/bin/sh
protocol="http"
rdeck_host="machinexyz.local"
rdeck_port="4440"
rdeck_api="35"
rdeck_token="token"
rdeck_project="projectRun"
xy="1w"
curl -s --location --request GET "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/project/$rdeck_project/$xy" \
--header "Accept: application/json" \
--header "X-Rundeck-Auth-Token: $rdeck_token
Thanks
Upvotes: 0
Views: 1391
Reputation: 4380
Following the documentation you could use the recentFilter
parameter on your API call, I did an example (at the end I added the jq command to "beautify" the default output):
#!/bin/sh
# protocol
protocol="http"
# basic rundeck info
rdeck_host="localhost"
rdeck_port="4440"
rdeck_api="36"
rdeck_token="ni28E9M5s5H0s3kyCKQ0tbfPCI8jNZS1"
# specific api call info
rdeck_project="ProjectEXAMPLE"
time="1h"
# api call
curl -s --location --request GET "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/project/$rdeck_project/executions?recentFilter=$time" \
--header "Accept: application/json" \
--header "X-Rundeck-Auth-Token: $rdeck_token" \
--header "Content-Type: application/json" | jq
Output:
{
"paging": {
"count": 2,
"total": 2,
"offset": 0,
"max": 20
},
"executions": [
{
"id": 2,
"href": "http://localhost:4440/api/36/execution/2",
"permalink": "http://localhost:4440/project/ProjectEXAMPLE/execution/show/2",
"status": "succeeded",
"project": "ProjectEXAMPLE",
"executionType": "scheduled",
"user": "admin",
"date-started": {
"unixtime": 1608296400032,
"date": "2020-12-18T13:00:00Z"
},
"date-ended": {
"unixtime": 1608296400374,
"date": "2020-12-18T13:00:00Z"
},
"job": {
"id": "f2a837d2-1a9c-4387-89d7-0243bbfe6ba9",
"averageDuration": 590,
"name": "HelloWorld",
"group": "",
"project": "ProjectEXAMPLE",
"description": "",
"href": "http://localhost:4440/api/36/job/f2a837d2-1a9c-4387-89d7-0243bbfe6ba9",
"permalink": "http://localhost:4440/project/ProjectEXAMPLE/job/show/f2a837d2-1a9c-4387-89d7-0243bbfe6ba9"
},
"description": "echo \"hi\"",
"argstring": null,
"serverUUID": "94ac86b1-56e9-4bc3-9a4c-50cd7c8a5b59",
"successfulNodes": [
"localhost"
]
},
{
"id": 1,
"href": "http://localhost:4440/api/36/execution/1",
"permalink": "http://localhost:4440/project/ProjectEXAMPLE/execution/show/1",
"status": "succeeded",
"project": "ProjectEXAMPLE",
"executionType": "scheduled",
"user": "admin",
"date-started": {
"unixtime": 1608295800075,
"date": "2020-12-18T12:50:00Z"
},
"date-ended": {
"unixtime": 1608295800914,
"date": "2020-12-18T12:50:00Z"
},
"job": {
"id": "f2a837d2-1a9c-4387-89d7-0243bbfe6ba9",
"averageDuration": 590,
"name": "HelloWorld",
"group": "",
"project": "ProjectEXAMPLE",
"description": "",
"href": "http://localhost:4440/api/36/job/f2a837d2-1a9c-4387-89d7-0243bbfe6ba9",
"permalink": "http://localhost:4440/project/ProjectEXAMPLE/job/show/f2a837d2-1a9c-4387-89d7-0243bbfe6ba9"
},
"description": "echo \"hi\"",
"argstring": null,
"serverUUID": "94ac86b1-56e9-4bc3-9a4c-50cd7c8a5b59",
"successfulNodes": [
"localhost"
]
}
]
}
Upvotes: 1