SWQL是SolaWinds查询语言,用于从Solarwinds获取数据
cisco_nodes_query = """
SELECT
n.Vendor,n.MachineType, n.NodeDescription,
n.IPAddress, n.Caption, n.Status
FROM Orion.Nodes n
WHERE n.Vendor LIKE "%rc1%"
ORDER BY n.IPAddress
我希望like子句输入由下面这样的变量输入
import requests
from orionsdk import SwisClient
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import csv
# Disable Insecure HTTPS Certificate Warnings
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
server = "solarwindsHost"
user = "apiuser"
pwd = "apipassword"
desc = rc1
# Build our SWQl Query
cisco_nodes_query = """
SELECT
n.Vendor,n.MachineType, n.NodeDescription,
n.IPAddress, n.Caption, n.Status
FROM Orion.Nodes n
WHERE n.NodeDescription LIKE '%"+ desc +"%'
ORDER BY n.IPAddress
def query_nodes(query, file_name):
# Create our SwisClient Object
swis = SwisClient(server, user, pwd)
# Initiate our Query and store the results
node_results = swis.query(query)["results"]
# Create a file object
file = open(file_name + ".csv", "w", newline='')
# Create our CSV Fields
fields = node_results[0].keys()
# Create our CSV.Dictwriter Object
writer = csv.DictWriter(file, fieldnames=fields)
# Write the headers to the csv file
writer.writeheader()
# Write the results to the csv file
writer.writerows(node_results)
# Optionally Print out the results to the terminal.
for node in node_results:
print("*" * 100)
for k, v in node.items():
print(k, "==", v)
query_nodes(cisco_nodes_query, "cisco_nodes")
作为,我在运行上述代码后出错 00客户端错误:无法解析url:https://solarwinds.17778/SolarWinds/InformationService/v3/Json/Query的属性d
目前没有回答
相关问题 更多 >
编程相关推荐