gpt4 book ai didi

python - 运行Curl Command并使用该状态后在RUNDECK中使用python编写条件来获取200 Ok状态

转载 作者:行者123 更新时间:2023-12-03 08:40:31 25 4
gpt4 key购买 nike

下面是CURL命令,它给出了在RUNDECK中运行的状态
url = "curl -kv https://vn2-lpgdmt-capp99.rno.vzon.com:8990/health/check"
我的代码如下:

payload={}
Headers={ i have defined here }

response = requests.request("GET", url, headers=headers, data = payload,verify=False)
status = response.status_code
print(status)
response_val = response.json()
response_val = json.dumps(response_val)

if status != 200 :
print('********Error in Response***********')
print('Status :'+ str(status))
print('********Please check for Rundeck Options,URL*********')
print(response.content)
else:
for pattern in part:
if re.search(pattern, response_val):
print('Data Found for ServerNo :'+ pattern)
else:
print('No Data Found for ServerNo :'+ pattern)
print('**************************************************************************')

我想给出多个curl命令并检查所有这些服务器的状态, if status is 200 ok then send msg saying Heartbeat Good, if not Hearbeat is Dead" Error
友善的帮助

最佳答案

您可以在第一步(在bash上)生成数据值,然后在第二步(在python上)生成数据值,我留下一个工作定义示例:

<joblist>
<job>
<context>
<options preserveOrder='true'>
<option name='node' value='myhost' />
</options>
</context>
<defaultTab>nodes</defaultTab>
<description></description>
<executionEnabled>true</executionEnabled>
<id>145d3f4e-44fc-4e25-9759-bf9d8867ef20</id>
<loglevel>INFO</loglevel>
<name>DataPassingDemo</name>
<nodeFilterEditable>false</nodeFilterEditable>
<plugins />
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<description>get the code and save it on data variable</description>
<fileExtension>.sh</fileExtension>
<plugins>
<LogFilter type='key-value-data'>
<config>
<invalidKeyPattern>\s|\$|\{|\}|\\</invalidKeyPattern>
<logData>true</logData>
<regex>^(CODE)\s*=\s*(.+)$</regex>
</config>
</LogFilter>
</plugins>
<script><![CDATA[response=$(curl --write-out %{http_code} --silent --output /dev/null http://@option.node@:4440)
echo "CODE=$response"]]></script>
<scriptargs />
<scriptinterpreter>/bin/bash</scriptinterpreter>
</command>
<command>
<description>your python 3 logic</description>
<fileExtension>.py</fileExtension>
<script><![CDATA[# get the data value
print("The code is: " + str(@data.CODE@))

# and you can do anything with @job.threadcount@
if (@data.CODE@ == 302):
print ("Server OK")
else:
print ("Check the instance")]]></script>
<scriptargs />
<scriptinterpreter>python3</scriptinterpreter>
</command>
</sequence>
<uuid>145d3f4e-44fc-4e25-9759-bf9d8867ef20</uuid>
</job>
</joblist>


另一种方法是通过urllib将所有进程留给python脚本,看看 this

您可以检查一个好的数据传递说明 here

关于python - 运行Curl Command并使用该状态后在RUNDECK中使用python编写条件来获取200 Ok状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61952749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com