python - 我的python脚本中的变量没有被设置
问题描述
我有一个 python 脚本,它使用 pyzabbix 模块来查询 Zabbix 的 API。我有一个带有主机名的文本文件,我想在脚本中循环,但没有设置 hosts 变量。不知道我做错了什么。
from pyzabbix import ZabbixAPI, ZabbixAPIException
import sys
# The hostname at which the Zabbix web interface is available
ZABBIX_SERVER = 'https://zabbix.example.org'
zapi = ZabbixAPI(ZABBIX_SERVER)
zapi.session.verify = False
# Login to the Zabbix API
zapi.login('Admin', 'password')
infile = open("data.txt", "r")
for line in infile:
host_name = line
hosts = zapi.host.get(filter={"host": host_name}, selectInterfaces=["interfaceid"])
if hosts:
host_id = hosts[0]["hostid"]
print("Found host id {0}".format(host_id))
else:
print("No hosts found")
infile.close()
解决方案
推荐阅读
- three.js - three.js:阴影中的明亮边缘
- php - 基于字符串搜索和重构解析字符串
- azure - 初始密码更改后,在 AzureAD B2C 中使用“forceChangePasswordNextLogin”创建的本地帐户无法再登录
- python - Python 通过函数调用链传递参数
- javascript - 自定义对象事件
- oracle - 在存储过程中添加异常
- css - 站点最大宽度在 Internet Explorer 中不起作用
- javascript - 从数组 onClick 渲染一个对象
- javascript - 如何在 JavaScript 中设置全局变量和全局函数
- java - 在 android studio 中创建单位转换应用程序时帮助解决问题