#!/usr/bin/python import requests,json ip_list=[] data_json={} url = ‘http://cmdb.cheyaoshicorp.com/api/ecs‘ r = requests.get(url) ecss = json.loads(r.text) for I in ecss: ip_dic={} host_ip = I.get(‘ip‘) ip_dic["{#IP}"]=host_ip ip_list.append(ip_dic) data_json[‘data‘]=ip_list result = json.dumps(data_json,sort_keys=True, indent=4) print result
上面的脚本是LLD监控的第一步 ==> 将监控对象做成Json格式。
下面是脚本的执行结果
{ "data": [ { "{#IP}": "10.47.57.66" }, { "{#IP}": "10.47.102.185" }, { "{#IP}": "10.168.218.84" }, { "{#IP}": "10.46.77.142" }, { "{#IP}": "10.46.72.44" }, { "{#IP}": "10.47.50.103" }, { "{#IP}": "10.46.73.48" }, { "{#IP}": "10.51.35.112" }, { "{#IP}": "10.47.49.170" }, { "{#IP}": "10.46.77.206" }, { "{#IP}": "10.46.71.215" }, { "{#IP}": "10.46.64.227" }, { "{#IP}": "10.174.33.182" }, { "{#IP}": "10.47.49.247" }, { "{#IP}": "10.47.48.244" }, { "{#IP}": "10.25.1.98" }, { "{#IP}": "10.117.51.126" }, { "{#IP}": "10.47.50.246" }, { "{#IP}": "10.173.232.173" }, { "{#IP}": "10.47.89.96" }, { "{#IP}": "10.175.192.16" }, { "{#IP}": "10.173.232.156" }, { "{#IP}": "10.174.110.132" }, { "{#IP}": "10.173.161.220" }, { "{#IP}": "10.174.107.151" }, { "{#IP}": "10.46.75.201" }, { "{#IP}": "10.46.68.71" }, { "{#IP}": "10.47.107.82" }, { "{#IP}": "10.47.75.182" }, { "{#IP}": "10.46.77.227" }, { "{#IP}": "10.46.76.37" }, { "{#IP}": "10.45.23.211" }, { "{#IP}": "10.47.106.145" }, { "{#IP}": "10.47.98.9" }, { "{#IP}": "10.47.91.172" }, { "{#IP}": "10.46.73.241" }, { "{#IP}": "10.46.73.8" }, { "{#IP}": "10.46.69.177" } ] }
本文出自 “zengestudy” 博客,请务必保留此出处http://zengestudy.blog.51cto.com/1702365/1791129
原文地址:http://zengestudy.blog.51cto.com/1702365/1791129