├── README.md
├── notify_pushbullet.py
└── notify_pushover.py
/README.md:
--------------------------------------------------------------------------------
1 | # Zabbix alertscripts #
2 |
3 | 
4 |
5 | A nice and little collection of alerts scripts to be used with the [Zabbix](https://www.zabbix.com/) network monitoring solution.
6 |
7 | At the moment the available scripts are:
8 |
9 | * [**notify_pushbullet.py**](#pushbullet) - Send notifications using [Pushbullet](https://www.pushbullet.com/)
10 | * [**notify_pushover.py**](#pushover) - Send notifications using [Pushover](https://www.pushover.net/)
11 |
12 |
13 | ## notify_pushbullet.py ##
14 |
15 | Zabbix alert script to send notifications using [Pushbullet](https://www.pushbullet.com/)
16 |
17 | ### Requirements
18 | ```bash
19 | pip install pushbullet.py
20 | ```
21 | ### Usage
22 | ```
23 | usage: notify_pushbullet.py [-h] "AccessToken(|DeviceName)" "Subject" "Message"
24 |
25 | Send Zabbix notification to Pushbullet enabled devices.
26 |
27 | positional arguments:
28 | AccessToken(|DeviceName)
29 | Pushbullet Access Token that and optional DeviceName
30 | if targetting a specific device.
31 | Subject Subject you want to push to the device(s).
32 | Message Message you want to push to the device(s).
33 |
34 | optional arguments:
35 | -h, --help show this help message and exit
36 | ```
37 | ### Getting started
38 | You first need to register for an account at [Pushbullet](https://www.pushbullet.com/) and download/install the clients for your devices (Android/iOS/Windows...).
39 | You will then able to retrieve your *AccessToken* that you will need to provide in your zabbix user media configuration.
40 |
41 | Copy the *notify_pushbullet.py* script to your Zabbix alert scripts directory. Usually this is */usr/lib/zabbix/alertscripts* but configuration can differs depending on how you installed Zabbix. In doubt, check your *zabbix_server.conf*.
42 |
43 | ### Configure the media type
44 |
45 | Go to your Zabbix *Administration / Media types* screen and add a new media.
46 | Specify the name of the script in script name and check that the parameters are correct.
47 |
48 | 
49 |
50 | ### Configure the user media
51 |
52 | You will need then to add the media to your users. For this just edit an user and add a media selecting the one you just created before.
53 | Specify the Access Token in the *Send to* field.
54 |
55 | 
56 |
57 | If you have multiple devices on your Pushbullet account and want to target only one device, you can specify the device name in the *Send to* field separated from Access Token with a | .
58 |
59 | 
60 |
61 | And voila, you're ready to use Pushbullet notifications!
62 |
63 |
64 | ## notify_pushover.py ##
65 |
66 | Zabbix alert script to send notifications using [Pushover](https://www.pushover.net/)
67 |
68 | ### Requirements
69 | ```bash
70 | pip install python-pushover
71 | ```
72 | ### Usage
73 | ```
74 | usage: notify_pushover.py [-h] "UserKey|AppToken" "Subject" "Message"
75 |
76 | Send Zabbix notification to Pushover enabled devices.
77 |
78 | positional arguments:
79 | UserKey|AppToken Pushover User Key AND Application Token separated by |
80 | Subject Subject you want to push to the device(s).
81 | Message Message you want to push to the device(s).
82 |
83 | optional arguments:
84 | -h, --help show this help message and exit
85 | ```
86 | ### Getting started
87 | You first need to register for an account at [Pushover](https://www.pushover.net/) and download/install the clients for your devices (Android/iOS/Windows...).
88 | You will then able to retrieve your *UserKey* and *AppToken* that you will need to provide in your zabbix user media configuration.
89 |
90 | Copy the *notify_pushover.py* script to your Zabbix alert scripts directory. Usually this is */usr/lib/zabbix/alertscripts* but configuration can differs depending on how you installed Zabbix. In doubt, check your *zabbix_server.conf*.
91 |
92 | ### Configure the media type
93 |
94 | Go to your Zabbix *Administration / Media types* screen and add a new media.
95 | Specify the name of the script in script name and check that the parameters are correct.
96 |
97 | 
98 |
99 | ### Configure the user media
100 |
101 | You will need then to add the media to your users. For this just edit an user and add a media selecting the one you just created before.
102 | Specify the UserKey and AppToken in the *Send to* field, separated by a | .
103 |
104 | 
105 |
106 | And voila, you're ready to use Pushbullet notifications!
107 |
108 |
--------------------------------------------------------------------------------
/notify_pushbullet.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sriccio/zabbix-alertscripts/83be3b682094b69b3c6388bd23b3fd03da8feb60/notify_pushbullet.py
--------------------------------------------------------------------------------
/notify_pushover.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # Pushover notification script for Zabbix
5 | #
6 | # Author:
7 | # Sébastien RICCIO - sr@swisscenter.com
8 | #
9 | # Purpose:
10 | # Push zabbix notifications to Pushover enabled devices
11 | # See: https://pushover.net/
12 | #
13 | # Requirements:
14 | # pip install python-pushover
15 | #
16 | # Changelog:
17 | # 20170101 - First revision
18 | #
19 |
20 | import argparse
21 | import sys
22 | import time
23 | import pushover
24 |
25 | #
26 | # Settings
27 | #
28 | ENABLE_LOG = True
29 | LOG_FILE = "/var/log/zabbix/notify_pushover.log"
30 |
31 |
32 | #
33 | # Functions
34 | #
35 | def l(msg):
36 | """
37 | Send log line to stdout and to LOG_FILE if logging is enabled
38 | """
39 | msg = "[%s] %s" % (logTimeStamp(), msg)
40 |
41 | # Print to stdout
42 | print(msg)
43 |
44 | # Output to logfile
45 | if ENABLE_LOG:
46 | try:
47 | lf = open(LOG_FILE, 'a')
48 | lf.write("%s\n" % (msg))
49 |
50 | except (OSError) as exc:
51 | print("Error while trying to log event: %s" % rlb(str(exc)))
52 | return False
53 |
54 | lf.close()
55 |
56 | return True
57 |
58 |
59 | def logTimeStamp():
60 | """
61 | Return current date/time formatted for log output
62 | """
63 | return time.strftime('%a %b %d %H:%M:%S %Y')
64 |
65 |
66 | def rlb(thing):
67 | """
68 | Return thing with line breaks replaced by spaces
69 | """
70 | return thing.replace("\r", " ").replace("\n", " ")
71 |
72 | #
73 | # Main code
74 | #
75 |
76 | # Arguments parser
77 | parser = argparse.ArgumentParser(description='Send Zabbix notification to Pushover enabled devices.')
78 | parser.add_argument('apptoken', metavar=('AppToken'), type=str, help='Pushover Application Token')
79 | parser.add_argument('userkey', metavar=('UserKey'), type=str, help='Pushover User Key')
80 | parser.add_argument('subject', metavar=('Subject'), type=str, help='Subject you want to push to the device(s)')
81 | parser.add_argument('message', metavar=('Message'), type=str, help='Message you want to push to the device(s)')
82 |
83 | # Argument processing
84 | args = parser.parse_args()
85 | user_key = args.userkey
86 | app_token = args.apptoken
87 | subject = args.subject
88 | message = args.message
89 |
90 | #Check if AppToken has been supplied
91 | if not app_token:
92 | l("Error: you must supply an App Token")
93 | sys.exit(1)
94 |
95 | # Check if UserKey and AppToken has been supplied
96 | if not app_token:
97 | l("Error: you must supply a User Key")
98 | sys.exit(1)
99 |
100 | # Try to login with AcessToken
101 | try:
102 | po = pushover.Client(user_key, api_token=app_token)
103 | except (pushover.UserError) as exc:
104 | l("Error: Can't connect to Pushover with User Key [%s]." % user_key)
105 | sys.exit(1)
106 |
107 | # Try to send the notification
108 | try:
109 | po.send_message(message, title=subject)
110 | except (pushover.RequestError) as exc:
111 | l("Error: Can't send notification to Pushover devices: %s" % rlb(str(exc)))
112 | sys.exit(1)
113 |
114 | # Exit with success
115 | l("Success: Message sent with UserKey [%s] to AppToken [%s]" % (user_key, app_token))
116 | sys.exit(0)
117 |
--------------------------------------------------------------------------------