Added network monitoring script
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"server": "192.168.0.5"
|
||||||
|
}
|
||||||
Executable
+27
@@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
import subprocess
|
||||||
|
from subprocess import CalledProcessError
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import logging.handlers as Handlers
|
||||||
|
|
||||||
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
log = logging.getLogger()
|
||||||
|
log.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
file = open('config.json', mode='r')
|
||||||
|
config = json.loads(file.read())
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
log.info("Pinging server " + config['server'])
|
||||||
|
output = subprocess.check_output(['ping', '-c', '5', config['server']], stderr=subprocess.STDOUT)
|
||||||
|
log.info("Ping OK")
|
||||||
|
time.sleep(5)
|
||||||
|
except CalledProcessError as e:
|
||||||
|
log.error(e.output.decode('ascii', 'ignore'))
|
||||||
|
log.error("Will reboot now")
|
||||||
Reference in New Issue
Block a user