{"id":490,"date":"2013-06-09T09:53:14","date_gmt":"2013-06-09T01:53:14","guid":{"rendered":"http:\/\/www.kiccleaf.com\/?p=490"},"modified":"2013-06-09T09:53:14","modified_gmt":"2013-06-09T01:53:14","slug":"python%e6%a3%80%e6%b5%8b%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%a1%ac%e7%9b%98%e4%bd%bf%e7%94%a8%e6%83%85%e5%86%b5%e3%80%90%e8%bd%ac%e3%80%91","status":"publish","type":"post","link":"http:\/\/www.kiccleaf.com\/?p=490","title":{"rendered":"Python\u68c0\u6d4b\u670d\u52a1\u5668\u786c\u76d8\u4f7f\u7528\u60c5\u51b5\u3010\u8f6c\u3011"},"content":{"rendered":"<p>\u6b64\u811a\u672c\u4e3b\u8981\u7528\u4e8ezabbix\u76d1\u63a7\u7cfb\u7edf\u786c\u76d8\u53ea\u7528\uff0c\u9002\u7528\u4e8ewindows\u548clinux\u7cfb\u7edf\uff0c\u8fd4\u56de\u503c\u4e3a0\u4e3a\u6b63\u5e38\uff0c\u6709\u51e0\u4e2a\u5206\u533a\u7684\u786c\u76d8\u5269\u4f59\u5c11\u4e8e10G\u6216\u4f4e\u4e8e10%\u5c31\u4e3a\u62a5\u8b66\u9600\u503c\uff08windows\u7684C\u76d8\u548clinux\u7684\u6839\u5206\u533a\u9664\u5916\uff09<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#!\/bin\/env python \r\n# -*- coding: utf-8 -*- \r\n########################################################## \r\n# @This script is used to check disk free space for zabbix \r\n# @Contact:      wangwei03@gyyx.cn \r\n# @Name:         disk.py \r\n# @Function:     check disk free space for zabbix \r\n# @Author:       wangwei \r\n########################################################## \r\nimport platform \r\nimport commands \r\n \r\ndef w_disk(): \r\n    import wmi \r\n    c = wmi.WMI () \r\n    i = 0 \r\n    for disk in c.Win32_LogicalDisk (DriveType=3): \r\n        a = int(disk.FreeSpace) \/ (1024*1024*1024) \r\n        b = int(100.0 * long (disk.FreeSpace) \/ long (disk.Size)) \r\n        if disk.Caption == &quot;C:&quot;: \r\n            if (a &lt; 2) or (b &lt; 10): \r\n                i += 1 \r\n            else: \r\n                i += 0 \r\n        else: \r\n            if (a &lt; 10) or (b &lt; 10): \r\n                i += 1 \r\n            else: \r\n                i += 0 \r\n    print i \r\n \r\ndef L_disk(): \r\n    free = commands.getstatusoutput('df -h|grep dev|egrep -v &quot;tmp|var|shm&quot;') \r\n    list = free&#x5B;1].split('\\n') \r\n    i = 0 \r\n    for disk in range(len(list)): \r\n        vd = list&#x5B;disk]&#x5B;6:8] \r\n        a = list&#x5B;disk].split()&#x5B;3] \r\n        if a&#x5B;-1] == 'T': \r\n            a = int(float(a&#x5B;:-1]))*1024 \r\n        else: \r\n            a = int(float(a&#x5B;:-1])) \r\n        b = 100 - int(list&#x5B;disk].split()&#x5B;4]&#x5B;:-1]) \r\n        if vd == &quot;da&quot;: \r\n            if (a &lt; 2) or (b &lt; 10): \r\n                i += 1 \r\n            else: \r\n                i += 0 \r\n        else: \r\n            if (a &lt; 10) or (b &lt; 10): \r\n                i += 1 \r\n            else: \r\n                i += 0 \r\n    print i \r\n \r\nif __name__ == &quot;__main__&quot;: \r\n    os = platform.system() \r\n    if os == &quot;Windows&quot;: \r\n        w_disk() \r\n    elif os == &quot;Linux&quot;: \r\n        L_disk() \r\n<\/pre>\n<p>\u8f6c\u81ea\uff1ahttp:\/\/wangwei007.blog.51cto.com\/68019\/741081<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6b64\u811a\u672c\u4e3b\u8981\u7528\u4e8ezabbix\u76d1\u63a7\u7cfb\u7edf\u786c\u76d8\u53ea\u7528\uff0c\u9002\u7528\u4e8e&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/www.kiccleaf.com\/?p=490\">Continue reading<span class=\"screen-reader-text\">Python\u68c0\u6d4b\u670d\u52a1\u5668\u786c\u76d8\u4f7f\u7528\u60c5\u51b5\u3010\u8f6c\u3011<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":5,"footnotes":""},"categories":[20],"tags":[95,110],"class_list":["post-490","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-110","entry"],"views":3861,"_links":{"self":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/posts\/490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=490"}],"version-history":[{"count":0,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/posts\/490\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=490"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}