-
Notifications
You must be signed in to change notification settings - Fork 10
/
notify_operator.py
48 lines (44 loc) · 1.27 KB
/
notify_operator.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
#!/usr/bin/env python
'''
Simple script to send Bacula reports to Zabbix
Made by Pavel Selivanov <[email protected]>
Forked by Valen Tau <[email protected]>
Should be used in Bacula-dir config instead of mail command:
mail = <> = all, !skipped
mailcommand = "/etc/zabbix/bacula_notify.py %r %c"
operatorcommand = "/etc/zabbix/bacula_notify_operator.py %r <bacula-sd server name>"
Hostnames in Zabbix and Bacula must correspond
'''
import sys
import re
import os
import datetime
import subprocess
# Logging
import logging
logging.basicConfig(
format=u'%(levelname)-8s [%(asctime)s] %(message)s',
level=logging.DEBUG,
filename=u'/var/log/bacula/{0}.log'.format(os.path.basename(__file__))
)
logging.info('sys.argv: ')
for _str in sys.argv:
logging.info(_str)
# Handle incorrect call
if sys.version_info >= (3,):
logging.warn("Need python version 2 to run. Tested with python 2.6")
quit(1)
if len(sys.argv) < 3:
logging.warn(
"Usage: {0} ZABBIX_SERVER HOSTNAME CUSTOM_MESSAGE".format(sys.argv[0]))
quit(5)
# Settings
from conf import conf
command = "{0} -z {1} -s {2} -k 'bacula.custommessage' -o '{3}'".format(
conf['zabbix_sender'],
sys.argv[1],
conf['hostname'],
sys.stdin.read()
)
logging.info(command)
subprocess.call(command, shell=True)