本文共 2040 字,大约阅读时间需要 6 分钟。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #!/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格式。
下面是脚本的执行结果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | { "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" } ] } |