Skip to content

Commit 913156f

Browse files
committed
First commit, tested from command line
0 parents  commit 913156f

6 files changed

+121
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*~

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Mike G
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Sendgrid Zabbix Alert
2+
=====================
3+
Work in progress, basically an alertscript called by Zabbix server
4+
that uses sendgrid to send a message
5+
6+
Requirements:
7+
-------------
8+
9+
### Software
10+
* curl
11+
* zabbix server
12+
* bash
13+
14+
### Configuration file
15+
16+
Configuration is sourced from /etc/zabbix/sendgrid_zabbix_alert.conf
17+
to set MAILFROMADDR, MAILFROMNAME and SENDGRID_API_KEY. See
18+
sendgrid_zabbix_alert.conf.example for more information
19+
20+
### Zabbix configuration
21+
22+
Normally alert scripts are here /usr/lib/zabbix/alertscripts
23+
AlertScriptsPath can be set to a location for custom alert scripts
24+
in zabbix_server.conf
25+
26+
Check the Zabbix documentions for Custom alert scripts.
27+
28+
When calling the alertscript, Zabbix sets the following parameters
29+
MAILTO=$1
30+
MAILSUBJECT=$2
31+
MAILBODY=$3
32+
33+
Parameters can be customized. (See custom alert scripts)
34+
35+
### Installation
36+
37+
Assuming default settings:
38+
39+
Set variables in
40+
/etc/zabbix/sendgrid_zabbix_alert.conf
41+
42+
Copy sendgrid_zabbix_alert.sh to /usr/lib/zabbix/alertscripts
43+
44+
There is also a file to help debug your alert parameters
45+
test_zabbix_alert.sh

sendgrid_zabbix_alert.conf.example

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Where the mail should be send from
2+
MAILFROMADDR="[email protected]"
3+
4+
# The name of the mailer
5+
MAILFROMNAME="Zabbix Alert Script"
6+
7+
# Your sendgrid api key
8+
SENDGRID_API_KEY="abc123"
9+

sendgrid_zabbix_alert.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
#
3+
4+
# define the following in settings in this
5+
source /etc/zabbix/sendgrid_zabbix_alert.conf
6+
#MAILFROMADDR=
7+
#MAILFROMNAME=
8+
#SENDGRID_API_KEY=
9+
10+
# By default alert scripts are here /usr/lib/zabbix/alertscripts
11+
# AlertScriptsPath can be set in zabbix_server.conf
12+
13+
# Zabbix sets the following parameters when calling the alertscript
14+
MAILTO=$1
15+
MAILSUBJECT=$2
16+
MAILBODY=$3
17+
18+
#curl --trace-ascii curltrace --request POST \
19+
curl --request POST \
20+
--url https://api.sendgrid.com/v3/mail/send \
21+
--header 'Authorization: Bearer '$SENDGRID_API_KEY'' \
22+
--header 'Content-Type: application/json' \
23+
--data '{"personalizations": [{"to": [{"email": "'"$MAILTO"'"}]}], \
24+
"from": {"email": "'"$MAILFROMADDR"'"}, \
25+
"subject": "'"$MAILSUBJECT"'", \
26+
"content": [{"type": "text/plain","value": "'"$MAILBODY"'"}], \
27+
"tracking_settings": { \
28+
"click_tracking": { "enable": false}, \
29+
"open_tracking": { "enable": false} \
30+
} \
31+
}'

test_zabbix_alert.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
#
3+
# append date and parameters to LOGFILE
4+
# LOGFILE must by writeable but the user running the script
5+
6+
LOGFILE="/tmp/test_zabbix_alert.log"
7+
PAR_COUNT=1
8+
9+
echo "$(date --rfc-3339=sec) Received $# parameters" >> $LOGFILE
10+
for PARAMETER in "$@"
11+
do
12+
echo "Parameter# $PAR_COUNT: $PARAMETER" >> $LOGFILE
13+
(( PAR_COUNT++ ))
14+
done

0 commit comments

Comments
 (0)