-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifications.py
executable file
·56 lines (42 loc) · 1.7 KB
/
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import yaml
import locale
import logging
import LogfileNotifications
from bothelper import TelegramBot
# German time formatting
try:
locale.setlocale(locale.LC_TIME, 'de_DE')
except locale.Error as exp:
try:
locale.setlocale(locale.LC_TIME, 'de_DE.utf8')
except locale.Error as exp:
pass
#######################################################################################
#######################################################################################
def main():
if len(sys.argv) < 2:
print('No config file given')
exit(1)
with open(sys.argv[1]) as fp:
config = yaml.safe_load(fp)
log_format = '%(asctime)s - [%(name)s] %(levelname)-5.5s - %(message)s'
log_formatter = logging.Formatter(log_format)
logging.basicConfig(level=config['logging']['level'],
format=log_format,
datefmt='%Y-%m-%d %H:%M:%S')
if 'file' in config['logging']:
file_handler = logging.FileHandler(config['logging']['file'])
file_handler.setFormatter(log_formatter)
logging.getLogger().addHandler(file_handler)
logging.info('Logfile monitoring running - version: ' + TelegramBot.get_version())
m = LogfileNotifications.Monitor(config)
# Set separate logging level for telegram bot (really excessive on DEBUG)
if 'telegram_bot_token' in config and 'telegram_level' in config['logging']:
logging.info('Changing log level of telegram bot to: ' + config['logging']['telegram_level'])
logging.getLogger("telegram").setLevel(config['logging']['telegram_level'])
m.loop()
if __name__ == '__main__':
main()