栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

小例子拾忆

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

小例子拾忆

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/224755.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号