ITPub博客

首页 > IT职业 > IT生活 > 【python小例子】小例子拾忆

【python小例子】小例子拾忆

IT生活 作者:dapan 时间:2021-09-09 09:26:54 0 删除 编辑

1)判断ip是否存在于zabbix中

思路:

1)使用user.login模拟登陆,获取authID

2)使用hostinterface.get获取主机hostid(要是使用主机名的话,可以使用host.get来获取hostid)

3)main函数实现:

    if __name__ == "__main__":

        file = raw_input("请输入文件名:")

        fp = open(file)

        hostname_list = fp.readlines()

        fp.close()

        hostids = []

        j = 0

     

        if os.path.exists('error_ip.txt'):

            os.remove('error_ip.txt')

        if os.path.exists('correct_ip.txt'):

            os.remove('correct_ip.txt')

     

        for i in hostname_list:

            hostname = i.strip().split(' ')[0]

            hostids.append(host_get(hostname))

             

            if hostids[j] == None:

                print hostids[j]

                fp1 = open('error_ip.txt','a')

                fp1.write(i)

                fp1.close()

            else:

                print hostids[j]

                fp2 = open('correct_ip.txt','a')

                fp2.write(i)

                fp2.close()

            j = j + 1

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/758/viewspace-2803121/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2020-08-07

  • 博文量
    4504
  • 访问量
    88057