-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfward_notifications.py
64 lines (61 loc) · 1.7 KB
/
fward_notifications.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import apprise
from apprise import NotifyType
from dataclasses import dataclass
global notifier
def create_apprise_object(configfile):
try:
apobj = apprise.Apprise()
# Read the configuration file
# And add on split lines.
with open(configfile, 'r') as f:
lines = f.readlines()
for line in lines:
apobj.add(line.strip())
return apobj
except Exception as e:
print(f'Failed to create apprise object: {e}')
return None
# Function that logs a message.
# It will also do a syslog if it is available.
def info(message, notifier=None):
print("[FWARD][INFO] " + message)
# Try to log to syslog
try:
import syslog
syslog.syslog(syslog.LOG_INFO, message)
except:
pass
if notifier:
notifier.notify(
body=message,
title='[LOG] Btrfs Monitor',
notify_type=NotifyType.INFO
)
def error(message, notifier=None):
print("[FWARD][ERROR] " + message)
# Try to log to syslog
try:
import syslog
syslog.syslog(syslog.LOG_ERR, message)
except:
pass
if notifier:
notifier.notify(
body=message,
title='[ERROR] Btrfs Monitor',
notify_type=NotifyType.FAILURE
)
def warn(message, notifier=None):
print("[FWARD][WARN] " + message)
# Try to log to syslog
try:
import syslog
syslog.syslog(syslog.LOG_WARNING, message)
except:
pass
if notifier:
notifier.notify(
body=message,
title='[WARNING] Btrfs Monitor',
notify_type=NotifyType.WARNING
)