Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

user input - Take multiple variables as a combination from a excel file query it dynamically in Rundeck

having some of parts, Serials and Config IDs in excel File

Part    - Serial  - Config.  
223-234 -   345   - PLU9.   
904-567 -   987   - GJK0.   
232-589 -   890   - LOM7.  
230-978 -   356   - GJK0.  

i want to check these numbers using API dynamically, giving this file as input in rundeck

https://prcmf.uslp07.app.xvz.com/api/c7/parts?include=name&selector=name,price,country&part=223-234&serial=345&config=PLU9

i want the part,serial and Config to be dynamically changed and searched and get the output using python in Rundeck

https://prcmf.uslp07.app.xvz.com/api/c7/partsinclude=name&selector=name,price,country&[email protected]@&[email protected]@&[email protected]@

How can i use this in Rundeck?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use this python example code to pass any value to any options on a Rundeck job. Just change the "strings" variables to your values from any source (another API call, fuzzytable output, etc).

import requests

# host definition
rdeck_instance = "localhost"
rdeck_port = "4440"
rdeck_api = "35"
rdeck_token = "lL4CwBiHHmxirZtTUHDJEHu4ZGTontjX"
jobid = "f68e73cb-54e5-483e-b451-b7ae484c54fe"

# variable strings (for testing, in this case, you can put from the result from any source: another API call, fuzzy table output, etc.)
string1="one"
string2="two"
string3="three"

s = requests.Session()
r = s.post("http://" + rdeck_instance +  ":" + rdeck_port +"/api/" + rdeck_api + "/job/" + jobid + "/run?authtoken=" + rdeck_token, 
headers = {"Accept" : "application/json"}, 
data = { "argString" : "-opt1 {} -opt2 {} -opt3 {}".format(string1, string2, string3)})

# print data (for debug)
print ('######################')
print (r.status_code)
print (r.url)
print ('######################')

# json response
print(r.json()) 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...