-
Notifications
You must be signed in to change notification settings - Fork 18
/
nagiosautoupdate-ubuntu.sh
executable file
·158 lines (140 loc) · 5.7 KB
/
nagiosautoupdate-ubuntu.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
#!/bin/sh
#
# Mise à jour automatique de Nagios sous Ubuntu/Debian
# Nicolas Hennion aka Nicolargo
# Script libre: GPLv3
#
# Syntaxe: # sudo ./nagiosautoupdate-ubuntu.sh
#
# !!!
# !!! Works fine but better use the Python script nagiosautoupdate.py
# !!!
version="4.0.2_01"
nagios_core_version="4"
nagios_core_subversion="4.0.2"
nagios_plugins_version="1.5"
nrpe_version="2.15"
nagios_user="nagios"
nagios_group="nagios"
###################################
# Do not touch code under this line
apt="apt-get -q -y --force-yes"
wget="wget --no-check-certificate -c"
# Fonction: installation
update() {
# Backup
echo "----------------------------------------------------"
echo "Archivage de la configuration existante"
echo "Si les choses se passe mal, on restore avec:"
echo "# cd /"
echo "# sudo tar zxvf ./nagios-backup.tgz"
echo "----------------------------------------------------"
cd /tmp
tar zcvfh ./nagios-backup.tgz /usr/local/nagios --exclude var/archives
# Pre-requis
echo "----------------------------------------------------"
echo "Installation de pre-requis / Configuration Postfix"
echo "----------------------------------------------------"
$apt install libperl-dev
$apt install libssl-dev
# Recuperation des sources
cd /tmp
mkdir src
cd src
echo "----------------------------------------------------"
echo "Telechargement des sources"
echo "Nagios Core version: $nagios_core_subversion"
echo "Nagios Plugin version: $nagios_plugins_version"
echo "NRPE version: $nrpe_version"
echo "----------------------------------------------------"
$wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-$nagios_core_subversion.tar.gz
$wget https://www.nagios-plugins.org/download/nagios-plugins-$nagios_plugins_version.tar.gz
$wget http://surfnet.dl.sourceforge.net/sourceforge/nagios/nrpe-$nrpe_version.tar.gz
# Compilation de Nagios Core
echo "----------------------------------------------------"
echo "Compilation de Nagios Core"
echo "Nagios user: $nagios_user"
echo "Nagios group: $nagios_group"
echo "----------------------------------------------------"
cd /tmp/src
tar zxvf nagios-$nagios_core_subversion.tar.gz
cd nagios-$nagios_core_subversion
./configure --with-nagios-user=$nagios_user --with-nagios-group=$nagios_group --with-command-user=$nagios_user --with-command-group=$nagios_group --enable-event-broker --enable-nanosleep --enable-embedded-perl --with-perlcache
make all
make fullinstall
echo "----------------------------------------------------"
echo "Hack for Nagios 4.0 and 4.0.1"
echo "Solve following issue on daemon script"
echo "----------------------------------------------------"
apt-get install daemon
if [ ! -e /etc/rc.d/init.d/functions ];
then
sudo sed -i 's/^\.\ \/etc\/rc.d\/init.d\/functions$/\.\ \/lib\/lsb\/init-functions/g' /etc/init.d/nagios
sudo sed -i 's/status\ /status_of_proc\ /g' /etc/init.d/nagios
sudo sed -i 's/daemon\ --user=\$user\ \$exec\ -ud\ \$config/daemon\ --user=\$user\ --\ \$exec\ -d\ \$config/g' /etc/init.d/nagios
sudo sed -i 's/\/var\/lock\/subsys\/\$prog/\/var\/lock\/\$prog/g' /etc/init.d/nagios
sudo sed -i 's/\/sbin\/service\ nagios\ configtest/\/usr\/sbin\/service\ nagios\ configtest/g' /etc/init.d/nagios
sudo sed -i 's/\"\ \=\=\ \"/\"\ \=\ \"/g' /etc/init.d/nagios
sudo sed -i 's/\#\#killproc\ \-p\ \$\{pidfile\}\ \-d\ 10/killproc\ \-p \$\{pidfile\}/g' /etc/init.d/nagios
sudo sed -i 's/runuser/su/g' /etc/init.d/nagios
fi
# Compilation de Nagios plugins
echo "----------------------------------------------------"
echo "Compilation de Nagios plugins"
echo "Nagios user: $nagios_user"
echo "Nagios group: $nagios_group"
echo "----------------------------------------------------"
cd /tmp/src
tar zxvf nagios-plugins-$nagios_plugins_version.tar.gz
cd nagios-plugins-$nagios_plugins_version
./configure --with-nagios-user=$nagios_user --with-nagios-group=$nagios_group
make
make install
make install-root
# Compilation de NRPE
echo "----------------------------------------------------"
echo "Compilation du plugin NRPE"
echo "Nagios user: $nagios_user"
echo "Nagios group: $nagios_group"
echo "----------------------------------------------------"
cd /tmp/src
tar zxvf nrpe-$nrpe_version.tar.gz
cd nrpe-$nrpe_version
./configure --with-nagios-user=$nagios_user --with-nagios-group=$nagios_group
make all
make install-plugin
# On fixe les droits
chown -R $nagios_user:$nagios_group /usr/local/nagios
# On supprime les fichiers temporaires
cd /tmp
rm -rf ./src
}
# Fonction: Verifie si Nagios les fichiers de conf sont OK
check() {
echo "----------------------------------------------------"
echo "Verification des fichiers de configuration de Nagios"
echo "----------------------------------------------------"
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
}
# Fonction: Lancement de Nagios
restart() {
echo "----------------------------------------------------"
echo "Redemarrage de Nagios / NRPE"
echo "----------------------------------------------------"
/etc/init.d/nagios-nrpe-server restart
/etc/init.d/nagios restart
}
# Programme principal
if [ "$(id -u)" != "0" ]; then
echo "Il faut les droits d'administration pour lancer ce script."
echo "Syntaxe: sudo $0"
exit 1
fi
if [ ! -x /usr/local/nagios/bin/nagios ]; then
echo "Nagios n'est pas installé sur votre système."
echo "Pour installer Nagios, utilisez le script nagiosautoinstall-ubuntu.sh"
exit 1
fi
update
check
restart