python - 运行 Curl 命令并使用该状态在 RUNDECK 中使用 python 编写条件后获取 200 Ok 状态
问题描述
下面是 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 脚本,看看这个.
您可以在此处查看良好的数据传递说明。
推荐阅读
- python - 如何在单个熊猫数据框中组合多个股票 ohlc 数据?
- python - Seaborn Barplot - 显示值时不一致
- javascript - 在编辑时将数据从一个电子表格复制到另一个电子表格
- performance - 在运行时更改主题需要 StatefulWidget,但这不是非常昂贵吗?
- omnet++ - 不支持的 TraCI API 版本,建议使用 Sumo 版本 1.0.1 或 0.32.0
- selenium-webdriver - 是否可以使用 selenium chromedriver 检查网站上脚本的执行情况?
- c# - 我收到此错误 CS0400 在全局命名空间中找不到类型或命名空间名称“AjaxControlToolkit”(您是否缺少程序集参考。)
- python - 有人能告诉我解决这个 zigag 遍历问题的时间复杂度吗
- xml - 属性值中不允许未转义的“<”
- cuda - 使用 Numba 进行矩阵乘法时出现 CUDA 内存不足错误