Skip to content

Commit b5be655

Browse files
committed
Added storagespaces health provider
1 parent 651cf13 commit b5be655

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

promexp/providers/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
from .nvidia import NVIDIAProvider
33
from .storage import StorageProvider
44
from .network import NetworkProvider
5+
from .storagespaces import StorageSpacesProvider
56

67
registry = [
78
PSUtilProvider,
89
NVIDIAProvider,
910
StorageProvider,
10-
NetworkProvider
11+
NetworkProvider,
12+
StorageSpacesProvider,
1113
]

promexp/providers/storagespaces.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
__all__ = ["StorageSpacesProvider"]
2+
3+
import os
4+
import subprocess
5+
6+
from ..provider import BaseProvider
7+
8+
9+
def get_ss_status():
10+
c = subprocess.Popen([
11+
"powershell.exe",
12+
"Get-VirtualDisk | Format-Table FriendlyName,ResiliencySettingName,OperationalStatus, HealthStatus"
13+
],
14+
stderr=subprocess.PIPE,
15+
stdout=subprocess.PIPE
16+
)
17+
stdout, stderr = c.communicate()
18+
19+
bounds = False
20+
result = []
21+
for line in stdout.decode("utf-8").split("\n"):
22+
if line.startswith("---"):
23+
bounds = [0]
24+
while True:
25+
pos = line.find(" -", bounds[-1])
26+
if pos == -1:
27+
break
28+
bounds.append(pos+1)
29+
continue
30+
31+
if not bounds:
32+
continue
33+
34+
line = line.strip()
35+
if not line:
36+
continue
37+
38+
title = line[bounds[0]:bounds[1]].strip()
39+
mode = line[bounds[1]:bounds[2]].strip()
40+
status = line[bounds[2]:bounds[3]].strip()
41+
health = line[bounds[3]:].strip()
42+
43+
result.append({
44+
"title" : title,
45+
"mode" : mode,
46+
"status" : status,
47+
"health" : health
48+
})
49+
return result
50+
51+
52+
class StorageSpacesProvider(BaseProvider):
53+
name = "storagespaces"
54+
55+
def __init__(self, parent, settings):
56+
super(StorageSpacesProvider, self).__init__(parent, settings)
57+
58+
if os.name != "nt":
59+
self.disable()
60+
return
61+
62+
try:
63+
status = get_ss_status()
64+
except Exception:
65+
status = []
66+
67+
if not status:
68+
self.disable()
69+
70+
71+
def collect(self):
72+
try:
73+
status = get_ss_status()
74+
except Exception:
75+
status = []
76+
77+
78+
for sspace in status:
79+
tags = {
80+
"title" : sspace["title"],
81+
"mode" : sspace["mode"]
82+
}
83+
self.add("storage_space_healthy", int(sspace["health"] == "Healthy"), **tags)

0 commit comments

Comments
 (0)