本文介绍了如何在excel文件中使用序列号列表作为输入并在RUNDECK中动态查询它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Excel文件中具有序列号列表.例如:456-098,456-098,428-098

Have list of SerialNumbers in Excel file.eg: 456-098 ,456-098,428-098

@ option.serialNumber @

@option.serialNumber@

我想使用API​​查看这些数字

i want to check these numbers using API

https://prcmf.uslp07.app.xvz.com/api/c7/parts?include=name&selector=name,price,country&number=488-099

我想在Excel中使用它的serialNumbers,并使用RUNDECK获取所有序列的结果

i want to use it serialNumbers from Excel and get result for all serials using RUNDECK

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

请帮助我如何在RUNDECK中使用它

Kindly Help how can i use this in RUNDECK

推荐答案

一个好的方法是使用 Fuzzytable (在Python脚本上).您可以获取数据,然后再通过Rundeck API将其传递给您的选项.我留下一个使用 this excel的Python代码示例示例文件:

A good way to do that is to use Fuzzytable on Python script. You can obtain the data and pass it later to your option via Rundeck API. I leave an example of Python code using this excel example file:

from openpyxl import load_workbook
from fuzzytable.main.sheetreader import ExcelReader

path = 'test.xlsx'
sheetname = 'table_top_left'
sheetreader = ExcelReader(path, sheetname)

row = sheetreader[1]

print(sheetreader.get_col(3,2))

以下脚本调用该Python代码,并随后使用以下值调用Rundeck API:

The following script call that Python code and later call Rundeck API with the values:

#!/bin/sh

# protocol
protocol="http"
format="json"

# basic rundeck info
rdeck_host="yourhostname"
rdeck_port="4440"
rdeck_api="35"
rdeck_token="heEUlrKvpPo4yES0dA7c4czVgDmZpt6s"

# specific api call info
rdeck_job="d75b11de-c272-402a-89cb-412e5f83e55f"

# get the values from excel file using fuzzytable
option_value=$(python3 getdata.py | tail -c +2 | head -c -2 | sed 's/[[:space:]]//g')

# values (only for debug)
echo $option_value

# api call
curl --location --request POST "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/job/$rdeck_job/run" \
  --header "Accept: application/$format" \
  --header "X-Rundeck-Auth-Token: $rdeck_token" \
  --header "Content-Type: application/$format" \
  --data "{ \"argString\":\"-mylist $option_value \" }"

使用此职位定义:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='mylist' value='1,2,3' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>d75b11de-c272-402a-89cb-412e5f83e55f</id>
    <loglevel>INFO</loglevel>
    <name>GetList</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <exec>echo ${option.mylist}</exec>
      </command>
    </sequence>
    <uuid>d75b11de-c272-402a-89cb-412e5f83e55f</uuid>
  </job>
</joblist>

最后,最后一个结果.

这篇关于如何在excel文件中使用序列号列表作为输入并在RUNDECK中动态查询它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 13:02