-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzabbix-pushsafer-centOS.sh
92 lines (74 loc) · 2.05 KB
/
zabbix-pushsafer-centOS.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Pushsafer notification script for Zabbix
#
# Author:
# Pushsafer.com Kevin Siml - [email protected]
#
# Purpose:
# Push zabbix notifications to Pushsafer enabled devices
# See: https://www.pushsafer.com
#
# Requirements:
# pip install python-pushsafer
#
import argparse
import sys
import time
import pushsafer
from pushsafer import init, Client
#
# Settings
#
ENABLE_LOG = True
LOG_FILE = "/var/log/zabbix/pushsafer.log"
#
# Functions
#
def l(msg):
"""
Send log line to stdout and to LOG_FILE if logging is enabled
"""
msg = "[%s] %s" % (logTimeStamp(), msg)
# Print to stdout
print(msg)
# Output to logfile
if ENABLE_LOG:
try:
lf = open(LOG_FILE, 'a')
lf.write("%s\n" % (msg))
except (OSError) as exc:
print("Error while trying to log event: %s" % rlb(str(exc)))
return False
lf.close()
return True
def logTimeStamp():
"""
Return current date/time formatted for log output
"""
return time.strftime('%a %b %d %H:%M:%S %Y')
def rlb(thing):
"""
Return thing with line breaks replaced by spaces
"""
return thing.replace("\r", " ").replace("\n", " ")
#
# Main code
#
# Arguments parser
parser = argparse.ArgumentParser(description='Send Zabbix notification to Pushsafer')
parser.add_argument('privatekey', metavar=('Private or Alias Key'), type=str, help='Pushsafer Private or Alias Key')
parser.add_argument('subject', metavar=('Subject'), type=str, help='Subject you want to push to the device(s).')
parser.add_argument('message', metavar=('Message'), type=str, help='Message you want to push to the device(s).')
# Argument processing
args = parser.parse_args()
privatekey = args.privatekey
subject = args.subject
message = args.message
# Try to send the notification
init(privatekey)
Client("").send_message(message, subject, "", "", "", "", "", "", "", "", "", "", "", "", "", "")
# Exit with success
l("Success: Message sent with Private Key [%s]: " % (privatekey))
sys.exit(0)