-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicinga-host.sh
executable file
·164 lines (150 loc) · 3.53 KB
/
icinga-host.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env bash
set -u
#Required parameters:
# -d LONGDATETIME ($icinga.long_date_time$)
# -l HOSTNAME ($host.name$)
# -n HOSTDISPLAYNAME ($host.display_name$)
# -o HOSTOUTPUT ($host.output$)
# -r USEREMAIL ($user.email$)
# -s HOSTSTATE ($host.state$)
# -t NOTIFICATIONTYPE ($notification.type$)
#
#Optional parameters:
# -4 HOSTADDRESS ($address$)
# -6 HOSTADDRESS6 ($address6$)
# -X HOSTNOTES ($host.notes$)
# -b NOTIFICATIONAUTHORNAME ($notification.author$)
# -c NOTIFICATIONCOMMENT ($notification.comment$)
# -i ICINGAWEB2URL ($notification_icingaweb2url$, Default: unset)
# -f MAILFROM ($notification_mailfrom$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE))
# -v ($notification_sendtosyslog$, Default: false)
longdatetime=""
hostname=""
hostdisplayname=""
hostoutput=""
useremail=""
hoststate=""
notificationtype=""
hostaddress=""
hostaddress6=""
hostnotes=""
notificationauthorname=""
notificationcomment=""
icingaweb2url=""
mailfrom=""
verbose=0
OPTS=$(getopt -o d:l:n:o:r:s:t:4:6:X:b:c:i:f:v -l longdatetime:,hostname:,hostdisplayname:,hostoutput:,useremail:,hoststate:,notificationtype:,hostaddress:,hostaddress6:,hostnotes:,notificationauthorname:,notificationcomment:,icingaweb2url:,mailfrom,verbose -- "$@")
eval set -- $OPTS
while [ true ]
do
case "$1" in
-d|--longdatetime)
longdatetime="$2"
shift 2
;;
-l|--hostname)
hostname="$2"
shift 2
;;
-n|--hostdisplayname)
hostdisplayname="$2"
shift 2
;;
-o|--hostoutput)
hostoutput="$2"
shift 2
;;
-r|--useremail)
useremail="$2"
shift 2
;;
-s|--hoststate)
hoststate="$2"
shift 2
;;
-t|--notificationtype)
notificationtype="$2"
shift 2
;;
-4|--hostaddress)
hostaddress="$2"
shift 2
;;
-6|--hostaddress6)
hostaddress6="$2"
shift 2
;;
-X|--hostnotes)
hostnotes="$2"
shift 2
;;
-b|--notificationauthorname)
notificationauthorname="$2"
shift 2
;;
-c|--notificationcomment)
notificationcomment="$2"
shift 2
;;
-o|--icingaweb2url)
icingaweb2url="$2"
shift 2
;;
-f|--mailfrom)
mailfrom="$2"
shift 2
;;
-v|--verbose)
verbose=1
shift
;;
-h|--help)
say_help
shift
exit 0
;;
--)
shift
break
;;
*)
echo "Option '$1' is not recognized"
exit 1
;;
esac
done
if [ -z "$longdatetime" ]
then
echo "Parameter -d / --longdatetime is mandatory"
exit 1
fi
if [ -z "$hostname" ]
then
echo "Parameter -l / --longdatetime is mandatory"
exit 1
fi
if [ -z "$hostdisplayname" ]
then
echo "Parameter -n / --hostdisplayname is mandatory"
exit 1
fi
if [ -z "$hostoutput" ]
then
echo "Parameter -o / --hostoutput is mandatory"
exit 1
fi
if [ -z "$useremail" ]
then
echo "Parameter -r / --useremail is mandatory"
exit 1
fi
if [ -z "$hoststate" ]
then
echo "Parameter -s / --hoststate is mandatory"
exit 1
fi
if [ -z "$notificationtype" ]
then
echo "Parameter -t / --notificationtype is mandatory"
exit 1
fi