-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjntfy.py
More file actions
45 lines (37 loc) · 1.14 KB
/
Copy pathjntfy.py
File metadata and controls
45 lines (37 loc) · 1.14 KB
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
#!/usr/bin/env python3
from systemd import journal
from time import sleep
import requests
notify = {
'service': 'https://ntfy.sh/',
'topic': '' #should probably be a random generated token as technichly a password if info is sensitive.
}
# Add more triggers if needed
# syntax 'text to search for':'Message to send'
triggerText = {
'find1':'send1',
'find2':'send2',
'find3':'send3'
}
def main():
j = journal.Reader()
j.seek_tail()
j.get_previous()
if (notify['topic'] == ''):
print ('notify[topic] is empty, please set a topic in the script')
return
while True:
event = j.wait(-1)
if event == journal.APPEND:
for entry in j:
searchTrigger(entry['MESSAGE'])
def sendNotification(sendMessage):
requests.post(notify['service'] + notify['topic'],
data=sendMessage,
)
def searchTrigger(logEntry):
for triggerKey, triggerValue in triggerText.items() :
if (logEntry.find(triggerKey) != -1):
sendNotification(triggerValue)
if __name__ == '__main__':
main()