{"id":11501,"date":"2023-03-03T10:29:05","date_gmt":"2023-03-03T02:29:05","guid":{"rendered":"https:\/\/www.lwops.cn\/?p=11501"},"modified":"2023-03-03T10:29:05","modified_gmt":"2023-03-03T02:29:05","slug":"zabbix%e8%87%aa%e5%8a%a8%e5%8f%91%e7%8e%b0%ef%bc%9apython-json%e6%a8%a1%e5%9d%97%e5%ba%94%e7%94%a8%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.lwops.cn\/index.php\/interflow\/technology\/11501","title":{"rendered":"zabbix\u81ea\u52a8\u53d1\u73b0\uff1apython-json\u6a21\u5757\u5e94\u7528\u4ecb\u7ecd"},"content":{"rendered":"\n
json\u6a21\u5757\u662fpython\u5185\u7f6e\u7684\u5e93\uff0c\u5176\u4e3b\u8981\u529f\u80fd\u662f\u5c06\u5e8f\u5217\u5316\u6570\u636e\u4ece\u6587\u4ef6\u91cc\u8bfb\u53d6\u51fa\u6765\u6216\u8005\u5b58\u5165\u6587\u4ef6\u3002\u8be5\u6a21\u5757\u6709\u56db\u4e2a\u65b9\u6cd5\uff1adump()\u3001load()\u3001dumps()\u3001loads()\uff0c<\/em><\/strong>\u5176\u4e2ddump\uff08\uff09\u662f\u5c06\u6570\u636e\u5b58\u5165\u6587\u4ef6\u4e2d\uff0cload\uff08\uff09\u662f\u7528\u4e8e\u8bfb\u53d6\u6587\u4ef6\uff1b\u800cdumps()\u548cloads()\u662f\u5bf9python\u5bf9\u8c61\u8fdb\u884c\u64cd\u4f5c\u3002dumps()\u662f\u5c06python\u5bf9\u8c61\u7f16\u7801\u6210json\u5b57\u7b26\u4e32\uff0cloads()\u662f\u5c06json\u5b57\u7b26\u4e32\u89e3\u7801\u6210python\u5bf9\u8c61\u3002<\/p>\n\n\n\n json\u6a21\u5757\u7684\u64cd\u4f5c\u4f7f\u7528\u76f8\u5bf9\u8f83\u4e3a\u7b80\u5355\uff0c\u5728\u4f7f\u7528\u7684\u65f6\u5019\u76f4\u63a5\u5bfc\u5165\u5c31\u53ef\u4ee5\u3002\u5728zabbix\u8fd0\u7ef4\u4e2d\uff0c\u5e38\u89c1\u7684\u81ea\u52a8\u53d1\u73b0<\/a>\u573a\u666f\uff0c\u4f7f\u7528python\u7684json\u6a21\u5757\uff0c\u5904\u7406\u8d77\u6570\u636e\uff0c\u4f1a\u975e\u5e38\u7684\u7b80\u5355\u3002<\/p>\n\n\n\n \u4ee5\u4e0b\u7ed3\u679c\uff0c\u4e3a\u8c03\u7528\u963f\u91cc\u4e91\u7684\u63a5\u53e3\u6570\u636e\u4f5c\u4e3a\u6f14\u793a\uff0c\u76f8\u5173\u654f\u611f\u6570\u636e\u5df2\u505a\u8131\u654f\u5904\u7406\u3002<\/p>\n\n\n\n {“data”: [{“{#PROJECT}”: “acs_slb_dashboard”, “{#INSTANCE_NANME}”: “a2d1f65d7fb1d468197ad23b”, “{#INSTANCE}”: “lb-bp1py79ytly0dlt”}, {“{#PROJECT}”: “acs_slb_dashboard”, “{#INSTANCE_NANME}”: “ManagedK8SSlbIntranet-cc5bc5d2683a44ae9b1a8eb”, “{#INSTANCE}”: “lb-bp1wjgyg379ynw61”}]}<\/p>\n\n\n\n \u5bf9\u6bd4shell\uff0cPython\u7684json\u6a21\u5757\u5728\u6570\u636e\u5904\u7406\u65b9\u9762\uff0c\u5176\u811a\u672c\u7684\u53ef\u8bfb\u6027\u3001\u7b80\u6d01\u6027\u90fd\u4f1a\u6709\u6240\u63d0\u5347\uff0c\u5e76\u4e14\u5904\u7406\u8fc7\u7a0b\u4e5f\u65e0\u9700\u82b1\u8d39\u8fc7\u591a\u7684\u4e8b\u4ef6\u5199\u5904\u7406\u8fc7\u7a0b\u7684\u4ee3\u7801\uff0c\u80fd\u6709\u6548\u63d0\u5347\u8fd0\u7ef4\u4eba\u5458\u7684\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n\n\n\n \u672c\u671f\u7684\u5206\u4eab\u5185\u5bb9\u5230\u8fd9\u5c31\u7ed3\u675f\u4e86\u3002\u5927\u5bb6\u597d\uff0c\u6211\u662f\u4e50\u4e50\uff0c\u4e13\u6ce8IT\u8fd0\u7ef4\u6280\u672f\u7814\u7a76\u4e0e\u5206\u4eab\uff0c\u5173\u6ce8\u6211\uff0c\u5b66\u4e60\u66f4\u591azabbix\u4f7f\u7528\u6280\u5de7\u3002\u540c\u65f6\u6b22\u8fce\u5c0f\u4f19\u4f34\u4eec\u5230\u4e50\u7ef4\u793e\u533a<\/u><\/a>\u7559\u8a00\u63d0\u95ee\u6216\u8005\u52a0\u5165\u6211\u4eeczabbix\u6280\u672f\u7b54\u7591QQ\u7fa4617295020\uff0c\u5171\u540c\u63a2\u8ba8zabbix\u6280\u672f\u95ee\u9898\u3002<\/p>\n\n\n\n\u4e8c\uff0e\u5e94\u7528\u573a\u666f\u793a\u4f8b<\/strong><\/h2>\n\n\n\n
2.1\u81ea\u52a8\u53d1\u73b0\u4e3b\u673a<\/strong><\/strong><\/h5>\n\n\n\n
2.1.1 python\u5904\u7406\u811a\u672c<\/strong><\/h5>\n\n\n\n
#!\/usr\/bin\/env python\r\n#coding=utf-8\r\nfrom aliyunsdkcore.client import AcsClient\r\nfrom aliyunsdkcore.acs_exception.exceptions import ClientException\r\nfrom aliyunsdkcore.acs_exception.exceptions import ServerException\r\nfrom aliyunsdkcore.auth.credentials import AccessKeyCredential\r\nfrom aliyunsdkcore.auth.credentials import StsTokenCredential\r\nfrom aliyunsdkslb.request.v20140515.DescribeLoadBalancersRequest import DescribeLoadBalancersRequest\r\nimport json\r\n# \u8fd9\u91cc\u586b ACCESS_KEY \u548cSECRET_KEY\r\ncredentials = AccessKeyCredential('', '')\r\n# use STS Token\r\n# credentials = StsTokenCredential('
2.2.2 \u8fd4\u56de\u7684\u539f\u59cb\u6570\u636e<\/strong><\/h5>\n\n\n\n
u'LoadBalancers': {u'LoadBalancer': [{u'BusinessStatus': u'Normal', u'CreateTimeStamp': 1665537209000, u'LoadBalancerStatus': u'active', u'PayType': u'PayOnDemand', u'InternetChargeType': u'4', u'VpcId': u'', u'RegionIdAlias': u'cn-hangzhou', u'Tags': {u'Tag': [{u'TagKey': u'ack.aliyun.com', u'TagValue': u'cc5bc5d2683a44ae9b1a8eb816'}, {u'TagKey': u'kubernetes.do.not.delete', u'TagValue': u'a2d1f65d7fb1d468197ad23ba183fc45'}]}, u'RegionId': u'cn-hangzhou', u'ResourceGroupId': u'rg-acfmxrtftvdl', u'InstanceChargeType': u'PayBySpec', u'VSwitchId': u'', u'InternetChargeTypeAlias': u'paybytraffic', u'Address': u'120.26.67.000', u'AddressIPVersion': u'ipv4', u'LoadBalancerSpec': u'slb.s1.small', u'LoadBalancerId': u'lb-bp1py79ytly0dl', u'AddressType': u'internet', u'MasterZoneId': u'cn-hangzhou-b', u'DeleteProtection': u'on', u'ModificationProtectionReason': u'managed.by.ack', u'SlaveZoneId': u'cn-hangzhou-g', u'Bandwidth': 5120, u'SpecBpsFlag': False, u'ModificationProtectionStatus': u'ConsoleProtection', u'NetworkType': u'classic', u'LoadBalancerName': u'a2d1f65d7fb1d468197ad23ba1', u'CreateTime': u'2022-10-12T09:13Z'}, {u'BusinessStatus': u'Normal', u'CreateTimeStamp': 1665480995000, u'LoadBalancerStatus': u'active', u'InternetChargeType': u'4', u'VpcId': u'vpc-bp1y7ysljuhh0mgz', u'RegionIdAlias': u'cn-hangzhou', u'Tags': {u'Tag': [{u'TagKey': u'ack.aliyun.com', u'TagValue': u'cc5bc5d2683a44ae9b1a8eb816'}]}, u'RegionId': u'cn-hangzhou', u'ResourceGroupId': u'rg-acfmxrtftvdlxuq', u'InstanceChargeType': u'PayBySpec', u'VSwitchId': u'vsw-bp19iupfrliiqgwjnnxoc', u'InternetChargeTypeAlias': u'paybytraffic', u'Address': u'192.168.33.000', u'AddressIPVersion': u'ipv4', u'LoadBalancerSpec': u'slb.s2.small', u'LoadBalancerId': u'lb-bp1wjgyg379yn', u'AddressType': u'intranet', u'MasterZoneId': u'cn-hangzhou-k', u'DeleteProtection': u'on', u'PayType': u'PayOnDemand', u'SlaveZoneId': u'cn-hangzhou-j', u'Bandwidth': 5120, u'SpecBpsFlag': False, u'ModificationProtectionStatus': u'ConsoleProtection', u'NetworkType': u'vpc', u'LoadBalancerName': u'ManagedK8SSlbIntranet-cc5bc5d2683a44ae9b1a8eb80', u'CreateTime': u'2022-10-11T17:36Z'}]}, u'TotalCount': 2, u'PageNumber': 1, u'RequestId': u'034B0F9E-87DE-59F4-9406-456B.', u'PageSize': 2}<\/code><\/pre>\n\n\n\n
2.2.3 \u5904\u7406\u540e\u7684\u6570\u636e<\/strong><\/h5>\n\n\n\n
\u4e09\uff0e\u7ed3\u8bba<\/strong><\/h2>\n\n\n\n