picomon_watchdog.py 775 Bytes
Newer Older
1
import subprocess
2 3 4 5
import sys
import os
import importlib
from picomon import config
6
from picomon import mails
7 8


9 10
# launch picomon
retcode = subprocess.call(["python3", "picomon.py"] + sys.argv[1:])
11

Colomban Wendling's avatar
Colomban Wendling committed
12 13
# load config file (unprotected, will trigger exceptions if problems but real
#                   picomon beforehand)
14 15 16
configfile = "config.py"

if "-c" in sys.argv:
Colomban Wendling's avatar
Colomban Wendling committed
17
    configfile = sys.argv[sys.argv.index("-c")+1]
18
if "--config" in sys.argv:
Colomban Wendling's avatar
Colomban Wendling committed
19
    configfile = sys.argv[sys.argv.index("--config")+1]
20 21

sys.path.append(os.path.dirname(configfile))
Colomban Wendling's avatar
Colomban Wendling committed
22
filename = os.path.basename(configfile)
23 24 25 26
base, ext = os.path.splitext(filename)
importlib.import_module(base)

# send warning
27 28
mails.send_email(config.emails.watchdog_subject,
                 "Picomon exited with status %s" % retcode)