This script is mainly used for Zabbix monitoring system hard disk only, for Windows and Linux systems, the return value of 0 is normal, there are several partitions of hard disk remaining less than 10G or less than 10% is the alarm threshold (except for Windows C-drive and Linux root partition):
Copy the Code code as follows:
#!/bin/env python
#-*-Coding:utf-8-*-
##########################################################
# @This script is used-to-check disk free space for Zabbix
# @Contact: wangwei03@jb51.net
# @Name: disk.py
# @Function: Check disk free space for Zabbix
# @Author: Wangwei
##########################################################
Import Platform
Import commands
Def w_disk ():
Import WMI
c = WMI. WMI ()
i = 0
For disk in C.win32_logicaldisk (drivetype=3):
A = Int (disk. FreeSpace)/(1024*1024*1024)
b = Int (100.0 * Long (disk). FreeSpace)/long (disk. Size))
If disk. Caption = = "C:":
if (a < 2) or (b < 10):
i + = 1
Else
i + = 0
Else
if (a <) or (b < 10):
i + = 1
Else
i + = 0
Print I
Def l_disk ():
Free = Commands.getstatusoutput (' df-h|grep dev|egrep-v "Tmp|var|shm" ')
List = Free[1].split (' \ n ')
i = 0
For disk in range (Len (list)):
VD = List[disk][6:8]
A = List[disk].split () [3]
If a[-1] = = ' T ':
a = Int (float (a[:-1])) *1024
Else
a = Int (float (a[:-1]))
b = 100-int (List[disk].split () [4][:-1])
if VD = = "Da":
if (a < 2) or (b < 10):
i + = 1
Else
i + = 0
Else
if (a <) or (b < 10):
i + = 1
Else
i + = 0
Print I
if __name__ = = "__main__":
OS = Platform.system ()
if os = = "Windows":
W_disk ()
elif OS = = "Linux":
L_disk ()