v1.0 it works. Gonna add it to crontab and see if anything blows up
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
# Poopballs
|
||||||
|
|
||||||
|
import json, re, requests, subprocess
|
||||||
|
|
||||||
|
WEBHOOK_URL = 'https://script.google.com/macros/s/AKfycbwgDA3qkwtRSR437gv0yGwvaIL19H3WcvtzX0eXV0D_MfOQtqrpy9-uJ1a6uF3gUIaxKw/exec'
|
||||||
|
PATTERN = r'\s+(?P<temp>\d+)\s+(?P<powerOnDays>\d+)\s+(?P<errCount>\d+)\s+(?P<fp>\d+)%\s+(?P<capacity>\d+.\d+)\s+(?P<serial>[A-Z\d]+)\s+(?P<device>[a-z/]+)\s+(?P<snapraidID>[a-z\d-]+)'
|
||||||
|
FIELD_NAMES = ['temp', 'powerOnDays', 'errCount', 'fp', 'capacity', 'serial', 'device', 'snapraidID']
|
||||||
|
results = []
|
||||||
|
|
||||||
|
|
||||||
|
def run_snapraid_smart():
|
||||||
|
try:
|
||||||
|
# Run the command "snapraid smart" using subprocess.run()
|
||||||
|
completed_process = subprocess.run(["snapraid", "smart"], capture_output=True, text=True, check=True)
|
||||||
|
|
||||||
|
# Check if the command was successful
|
||||||
|
if completed_process.returncode == 0:
|
||||||
|
return completed_process.stdout.strip()#.split('\n')[5:]
|
||||||
|
else:
|
||||||
|
return "Error executing SnapRAID SMART command."
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
return "Error executing SnapRAID SMART command: " + str(e)
|
||||||
|
|
||||||
|
# Call the function to run the SnapRAID SMART command and get the output
|
||||||
|
snapraid_smart_output = run_snapraid_smart()
|
||||||
|
matches = re.finditer(PATTERN, snapraid_smart_output)
|
||||||
|
|
||||||
|
for match in matches:
|
||||||
|
row = {
|
||||||
|
FIELD_NAMES[0]: match.group(FIELD_NAMES[0]),
|
||||||
|
FIELD_NAMES[1]: match.group(FIELD_NAMES[1]),
|
||||||
|
FIELD_NAMES[2]: match.group(FIELD_NAMES[2]),
|
||||||
|
FIELD_NAMES[3]: match.group(FIELD_NAMES[3]),
|
||||||
|
FIELD_NAMES[4]: match.group(FIELD_NAMES[4]),
|
||||||
|
FIELD_NAMES[5]: match.group(FIELD_NAMES[5]),
|
||||||
|
FIELD_NAMES[6]: match.group(FIELD_NAMES[6]),
|
||||||
|
FIELD_NAMES[7]: match.group(FIELD_NAMES[7])
|
||||||
|
}
|
||||||
|
results.append(row)
|
||||||
|
|
||||||
|
json_payload = json.dumps(results)
|
||||||
|
response = requests.post(WEBHOOK_URL, json=json_payload)
|
||||||
|
|
||||||
|
# Check if the request was successful (status code 200)
|
||||||
|
if response.status_code == 200:
|
||||||
|
print("POST request successful.", response.text)
|
||||||
|
else:
|
||||||
|
print("POST request failed:", response.status_code)
|
||||||
Reference in New Issue
Block a user