forked from midacts/NagiosCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnagioscore.sh
executable file
·339 lines (299 loc) · 9.7 KB
/
nagioscore.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/bin/bash
# Nagios Core 4.0.5 Install on Debian Wheezy
# Author: John McCarthy
# <http://www.midactstech.blogspot.com> <https://www.github.com/Midacts>
# Date: 23rd of May, 2014
# Version 1.2
#
# To God only wise, be glory through Jesus Christ forever. Amen.
# Romans 16:27, I Corinthians 15:1-4
#------------------------------------------------------
######## VARIABLES ########
nagios_version=4.0.6
plugin_version=2.0.1
nrpe_version=2.15
######## FUNCTIONS ########
function nagiosCore()
{
#Add Nagios Users and Groups
echo
echo -e '\e[01;34m+++ Adding Nagios Users and Groups...\e[0m'
echo
groupadd -g 9000 nagios
groupadd -g 9001 nagcmd
useradd -u 9000 -g nagios -G nagcmd -d /usr/local/nagios -c 'Nagios Admin' nagios
adduser www-data nagcmd
echo
echo -e '\e[01;37;42mThe Nagios users and groups have been successfully added!\e[0m'
#Install Require Packages
echo
echo -e '\e[01;34m+++ Installing Prerequisite Packages...\e[0m'
echo
apt-get update
apt-get install -y apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev libssl-dev
echo
echo -e '\e[01;37;42mThe Prerequisite Packages were successfully installed!\e[0m'
#Download latest Nagios Core Version
echo
echo -e '\e[01;34m+++ Downloading the Latest Nagios Core files...\e[0m'
echo
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-$nagios_version.tar.gz
echo -e '\e[01;37;42mThe Nagios Core installation files were successfully downloaded!\e[0m'
#Untarring the Nagios Core File
echo
echo -e '\e[01;34m+++ Untarrring the Nagios Core files...\e[0m'
tar xzf nagios-$nagios_version.tar.gz
cd nagios-$nagios_version
echo
echo -e '\e[01;37;42mThe Nagios Core installation files were successfully untarred!\e[0m'
#Configure and Install Nagios Core
echo
echo -e '\e[01;34m+++ Installing Nagios Core...\e[0m'
echo
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
echo -e '\e[01;37;42mNagios Core has been successfully installed!\e[0m'
}
function webUIpassword()
{
#Create a user to access the Nagios Web UI
echo
echo -e '\e[33mChoose your Nagios Web UI Username\e[0m'
read webUser
# Use this command to add subsequent users later on (eliminate the '-c' switch, which creates the file)
# htpasswd /usr/local/nagios/etc/htpasswd.users username
# **NOTE** users will only see hots/services for which they are contacts <http://nagios.sourceforge.net/docs/nagioscore/3/en/cgiauth.html>
htpasswd -c /usr/local/nagios/etc/htpasswd.users $webUser
#Changes the Ownership of the htpasswd.users file
chown nagios:nagcmd /usr/local/nagios/etc/htpasswd.users
echo
echo -e '\e[01;37;42mNagios Web UI Username and password successfully created!\e[0m'
}
function nagiosBoot()
{
#Enabling nagios to start at boot time
echo
echo -e '\e[01;34m+++ Enabling Nagios to Start at boot time...\e[0m'
echo
update-rc.d nagios defaults
#Restart the Nagios service
service nagios restart
echo
echo -e '\e[01;37;42mNagios has been configured to start at boot time!\e[0m'
}
function nagiosPlugin()
{
#Download the Latest Nagios Plugin Files
echo
echo -e '\e[01;34m+++ Downloading the Nagios Plugin Files...\e[0m'
echo
wget https://www.nagios-plugins.org/download/nagios-plugins-$plugin_version.tar.gz
echo -e '\e[01;37;42mThe Latest Nagios Plugins have been acquired!\e[0m'
#Untarring the Nagios Plugin File
echo
echo -e '\e[01;34m+++ Untarrring the Nagios plugin files...\e[0m'
tar xzf nagios-plugins-$plugin_version.tar.gz
cd nagios-plugins-$plugin_version
echo
echo -e '\e[01;37;42mThe Nagios plugin files were successfully untarred!\e[0m'
#Configure and Install Nagios Plugins
echo
echo -e '\e[01;34m+++ Installing Nagios Plugins...\e[0m'
echo
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules --enable-libtap
make
make install
echo
echo -e '\e[01;37;42mThe Nagios Plugins have been successfully installed!\e[0m'
}
function nrpe()
{
#Download latest NRPE Files
echo
echo -e '\e[01;34m+++ Downloading the Latest NRPE files...\e[0m'
echo
wget http://sourceforge.net/projects/nagios/files/nrpe-$nrpe_version.tar.gz
echo -e '\e[01;37;42mThe NRPE installation files were successfully downloaded!\e[0m'
#Untarring the NRPE File
echo
echo -e '\e[01;34m+++ Untarrring the Nagios Core files...\e[0m'
tar xzf nrpe-$nrpe_version.tar.gz
cd nrpe-$nrpe_version
echo
echo -e '\e[01;37;42mThe NRPE installation files were successfully untarred!\e[0m'
#Configure and Install NRPE
#http://askubuntu.com/questions/133184/nagios-nrpe-installation-errorconfigure-error-cannot-find-ssl-libraries
echo
echo -e '\e[01;34m+++ Installing NRPE...\e[0m'
echo
./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu
make
make all
make install
make install-plugin
make install-daemon
make install-daemon-config
# Copy NRPE Init Script and Make It Executable
cp init-script.debian /etc/init.d/nrpe
chmod 700 /etc/init.d/nrpe
# Start the NRPE Daemon
/etc/init.d/nrpe start
# Make NRPE Start at Boot Time
update-rc.d nrpe defaults
echo
echo -e '\e[01;37;42mNRPE has been successfully installed!\e[0m'
}
function emailNotifications()
{
#Install Require Packages
echo
echo -e '\e[01;34m+++ Installing Prerequisite Packages...\e[0m'
echo
apt-get install -y sendmail-bin sendmail heirloom-mailx
echo
echo -e '\e[01;37;42mThe Rrerequisite Packages for Nagios Notifications were successfully installed!\e[0m'
}
function webSSL()
{
#Make Your Self-signed Certificates
echo
echo -e '\e[33mChoose your Certificates Name\e[0m'
read CERT
mkdir /etc/apache2/ssl
cd /etc/apache2/ssl
openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout $CERT.key -out $CERT.crt
a2enmod ssl
#Configure /etc/apache2/conf.d/nagios.conf
sed -i 's/# SSLRequireSSL/ SSLRequireSSL/g' /etc/apache2/conf.d/nagios.conf
#Configure /etc/apache2/sites-available/nagios
echo
echo -e '\e[33mChoose your Server Admin Email Address\e[0m'
read EMAIL
cat <<EOF > /etc/apache2/sites-available/nagios
<VirtualHost *:443>
ServerAdmin $EMAIL
ServerName $CERT.crt
DocumentRoot /var/www/$CERT
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/$CERT>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/$CERT.crt
SSLCertificateKeyFile /etc/apache2/ssl/$CERT.key
</VirtualHost>
EOF
# Enable the nagios site
a2ensite nagios
#Make DirectoryRoot Directory
mkdir /var/www/$CERT
#Restart Your Apache2 Service
service apache2 restart
}
#This Function is Used to Call its Corresponding Function
function doAll()
{
#Calls Function 'nagioscore'
echo -e "\e[33m=== Install Nagios Core ? (y/n)\e[0m"
read yesno
if [ "$yesno" = "y" ]; then
nagiosCore
fi
#Calls Function 'webUIpassword'
echo
echo -e "\e[33m=== Add Nagios Web UI Password ? (y/n)\e[0m"
read yesno
if [ "$yesno" = "y" ]; then
webUIpassword
fi
#Calls Function 'nagiosBoot'
echo
echo -e "\e[33m=== Start Nagios Server at Boot Time ? (y/n)\e[0m"
read yesno
if [ "$yesno" = "y" ]; then
nagiosBoot
fi
#Calls Function 'nagiosPlugin'
echo
echo -e "\e[33m=== Install the Nagios Plugins ? (y/n)\e[0m"
read yesno
if [ "$yesno" = "y" ]; then
nagiosPlugin
fi
#Calls Function 'nrpe'
echo
echo -e "\e[33m=== Install NRPE ? (y/n)\e[0m"
read yesno
if [ "$yesno" = "y" ]; then
nrpe
fi
#Calls Function 'emailNotifications'
echo
echo -e "\e[33m=== Edit Nagios Email Notification Settings ? (y/n)\e[0m"
read yesno
if [ "$yesno" = "y" ]; then
emailNotifications
fi
#Calls Function 'webSSL'
echo
echo -e "\e[33m=== Configure Nagios Web UI to use SSL (HTTPS) ? (y/n)\e[0m"
read yesno
if [ "$yesno" = "y" ]; then
webSSL
fi
#End of Script Congratulations, Farewell and Additional Information
clear
FARE=$(cat << 'EOD'
\e[01;37;42mWell done! You have completed your Nagios Core Installation!\e[0m
\e[01;37;42mProceed to your Nagios web UI, http://fqdn/nagios\e[0m
\e[30;01mCheckout similar material at midactstech.blogspot.com and github.com/Midacts\e[0m
\e[01;37m########################\e[0m
\e[01;37m#\e[0m \e[31mI Corinthians 15:1-4\e[0m \e[01;37m#\e[0m
\e[01;37m########################\e[0m
EOD
)
#Calls the End of Script variable
echo -e "$FARE"
echo
echo
exit 0
}
# Check privileges
[ $(whoami) == "root" ] || die "You need to run this script as root."
# Welcome to the script
clear
echo
echo
echo -e ' \e[01;37;42mWelcome to Midacts Mystery'\''s Nagios Core Installer!\e[0m'
echo
echo
case "$go" in
core)
nagiosCore ;;
webPass)
webUIpassword ;;
boot)
nagiosBoot ;;
plugin)
nagiosPlugin ;;
nrpe)
nrpe ;;
email)
emailNotifications ;;
ssl)
webSSL ;;
* )
doAll ;;
esac
exit 0