简体   繁体   中英

Rundeck details of scheduled job

In rundeck (OpenSource v3.3.1 with H2SQL) is there any way to review the details of a Scheduled JOB? For us it is important to know the list of nodes where the job will be executed. I have searched in files and in H2 DB and I can´t get the nodes or the filter used to schedule the job.

You can see that on the "Activity" panel , click on any execution (scheduled or not), and click on "Log Output" you can see all job detailed info. Also, you can check the execution logs, usually at /var/lib/rundeck/logs/rundeck/<projectname>/job/<job-id>/logs path.

You can check more about this here .

UPDATE 1: you can use the forecast API call to check the jobs "to be executed", I leave a script that uses it:

#!/bin/sh

#############################################
echo "Insert the Rundeck Server hostname:"; read -r rundeckServer
echo -e "\nWhich port?:"; read -r rundeckPort
echo -e "\nCopy and Paste the Rundeck API Token:"; read -r rundeckApitoken

#############################################
# to run unatended mode, please comment the code above and uncomment the code below, and replace with your props
#############################################
# rundeckServer="node01.rundeck.local"
# rundeckPort="4440"
# rundeckApitoken="P0K0EvIAoWkAbmvj3JnlelmwaVhF5AJd"
#############################################
# Options Variables
#############################################
rundeckProtocol="http"
rundeckApiversion="31"
rundeckApiformat="json"
curlOptions="-s"
#############################################
echo
echo "The following Jobs are Scheduled:"
echo

for projectName in $(curl -X "GET" "$curlOptions" -H "Accept: application/$rundeckApiformat" -H "Content-Type: application/$rundeckApiformat" -H "X-Rundeck-Auth-Token: $rundeckApitoken" "$rundeckProtocol"://"$rundeckServer":"$rundeckPort"/api/"$rundeckApiversion"/projects|sed 's/,/\n/g'| grep name | cut -d ":" -f2 | tr -d '"')
    do
        for jobId in $(curl "$curlOptions" -X "GET" -H "Accept: application/$rundeckApiformat" -H "Content-Type: application/$rundeckApiformat" -H "X-Rundeck-Auth-Token: $rundeckApitoken" "$rundeckProtocol"://"$rundeckServer":"$rundeckPort"/api/"$rundeckApiversion"/project/"$projectName"/jobs | sed 's/,/\n/g' | grep id | cut -d ":" -f2 | tr -d '"')
            do
                output=$(curl "$curlOptions" -X "GET" -H "Accept: application/$rundeckApiformat" -H "Content-Type: application/$rundeckApiformat" -H "X-Rundeck-Auth-Token: $rundeckApitoken" "$rundeckProtocol"://"$rundeckServer":"$rundeckPort"/api/"$rundeckApiversion"/job/"$jobId"/forecast?time=7d | grep "futureScheduledExecutions")
                if [ -n "$output" ]
                    then
                        echo $output | sed -r 's/.+("href":".+),.+("futureScheduledExecutions":\[.+\]),.+("project":".+),("name":".+).+/\1\n\3\n\4\n\2/g'
                        echo
                fi
        done
done

UPDATE 2: I leave more simple forecast API call, (require jq ).

curl --location --request GET 'http://localhost:4440/api/35/job/your-job-id/forecast' --header 'Accept: application/json' --header 'X-Rundeck-Auth-Token: your-user-token' --header 'Content-Type: application/json' --data-raw '' | jq

That prints all info:

{
  "href": "http://localhost:4440/api/35/job/328789d1-986f-4aa2-9013-de8eb6b6df98",
  "id": "328789d1-986f-4aa2-9013-de8eb6b6df98",
  "scheduleEnabled": true,
  "scheduled": true,
  "enabled": true,
  "permalink": "http://localhost:4440/project/ProjectEXAMPLE/job/show/328789d1-986f-4aa2-9013-de8eb6b6df98",
  "group": null,
  "futureScheduledExecutions": [
    "2020-08-06T14:33:00Z"
  ],
  "description": "",
  "project": "ProjectEXAMPLE",
  "name": "ExampleJob"
}

UPDATE 3: Now combining the export job info and forecast API Call, you can get the job info and the nodes, I leave an example script:

#!/bin/sh

#####################################################
# rundeck instance values
server="localhost"
port="4440"
api="35"
jobid="328789d1-986f-4aa2-9013-de8eb6b6df98"
token="MhloqezoV3IygvOIA6yzE9TNlzYCbi4m"

info=$(curl -s --location --request GET "http://$server:$port/api/$api/job/$jobid/forecast" --header "Accept: application/json" --header "X-Rundeck-Auth-Token:$token" --header "Content-Type: application/json" | jq)

nodes=$(curl -s --location --request GET "http://$server:$port/api/$api/job/$jobid" --header "Accept: application/xml" --header "X-Rundeck-Auth-Token:$token" --header "Content-Type: application/xml" --data-raw "" | grep -oPm1 "(?<=<filter>)[^<]+")

echo "######################"
echo "Job information: $info"
echo "######################"
echo "Nodes: $nodes"
echo "######################"

With the following data:

######################
Job information: {
  "href": "http://localhost:4440/api/35/job/328789d1-986f-4aa2-9013-de8eb6b6df98",
  "id": "328789d1-986f-4aa2-9013-de8eb6b6df98",
  "scheduleEnabled": true,
  "scheduled": true,
  "enabled": true,
  "permalink": "http://localhost:4440/project/ProjectEXAMPLE/job/show/328789d1-986f-4aa2-9013-de8eb6b6df98",
  "group": null,
  "futureScheduledExecutions": [
    "2020-08-07T14:33:00Z"
  ],
  "description": "",
  "project": "ProjectEXAMPLE",
  "name": "ExampleJob"
}
######################
Nodes: localhost
######################

UPDATE 4: The job definition data are "distributed" on the database (H2 or anything else). So, for example, if you configure Rundeck against MySQL and you access the database using any tool, the node filter is saved in scheduled_execution table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM