-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpsutil_disk_usage_alarm.py
More file actions
executable file
·44 lines (40 loc) · 1.67 KB
/
psutil_disk_usage_alarm.py
File metadata and controls
executable file
·44 lines (40 loc) · 1.67 KB
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
#!/usr/bin/python
import psutil
import json
import pycurl
import urllib
import socket
partitions = psutil.disk_partitions()
for partition in partitions :
if (partition.mountpoint == "/" or partition.mountpoint == "/home"):
device = partition.device
mount = partition.mountpoint
filesystype = partition.fstype
if(mount == "/") :
check_slash = psutil.disk_usage(mount)
if(check_slash.percent >= 1):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("gmail.com",80))
IP = s.getsockname()[0]
check_slash = [('IP',IP),('mount on',mount), ('total',check_slash.total), ('used',check_slash.used), ('free',check_slash.free), ('percent',check_slash.percent), ('filetype',filesystype), ('device',device)]
c = pycurl.Curl()
resp_data = urllib.urlencode(check_slash)
c.setopt(pycurl.URL, 'http://ryan.pakar/HDD-Monitoring/hdd_monitor/index.php/site/add_disk_alert')
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, resp_data)
c.perform()
c.close()
else :
check_slash_home = psutil.disk_usage(mount)
if(check_slash_home.percent >= 1):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("gmail.com",80))
IP = s.getsockname()[0]
check_slash_home = [('IP',IP),('mount on',mount), ('total',check_slash_home.total), ('used',check_slash_home.used), ('free',check_slash_home.free), ('percent',check_slash_home.percent), ('filetype',filesystype), ('device',device)]
c = pycurl.Curl()
resp_data = urllib.urlencode(check_slash_home)
c.setopt(pycurl.URL, 'http://ryan.pakar/HDD-Monitoring/hdd_monitor/index.php/site/add_disk_alert')
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, resp_data)
c.perform()
c.close()