-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnagclient.sh
228 lines (197 loc) · 7.7 KB
/
nagclient.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
#!/bin/bash
#Author: Nemanja Djuric
#Function defs
# Check for root, quit if not present with a warning.
if [ "$(id -u)" != "0" ];
then
echo "\nScript needs to be run as root. Please elevate and run again!"
exit 1
else
echo "\nScript running as root. Starting..."
fi
function setup_centos(){
#Begin of Epel-repo install block. Version check and if exist.
echo "Welcome to the Nagios Client installer. First, lets check if installation exist and remove it."
yum -y remove nagios-plugins-all
yum -y remove nrpe
yum -y remove lm_sensors
echo "Installing fresh installation"
osversion=$(cat /etc/redhat-release | grep -oE '[0-9]+\.[0-9]+'|cut -d"." -f1)
echo ${osversion}
if [ ${osversion} -eq 5 ];then
echo "Checking/Installing Epel repository, Nagios Plugins, Nrpe, Lmsensors and Hdd temperateure module."
echo "Starting nrpe daemon and adding it to the chkconfig for autoboot functionality."
cd /root
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm
rpm -Uvh epel-release-latest-5*.rpm
yum -y --enablerepo="epel" install nagios-plugins-all nrpe lm_sensors hddtemp
service nrpe restart
chkconfig nrpe on
fi
if [ ${osversion} -eq 6 ];then
echo "Checking/Installing Epel repository, Nagios Plugins, Nrpe, Lmsensors and Hdd temperateure module."
echo "Starting nrpe daemon and adding it to the chkconfig for autoboot functionality."
cd /root
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh epel-release-latest-6*.rpm
yum -y --enablerepo="epel" install nagios-plugins-all nrpe lm_sensors hddtemp
service nrpe restart
chkconfig nrpe on
fi
if [ ${osversion} -eq 7 ];then
echo "Checking/Installing Epel repository CentOS 7, Nagios Plugins, Nrpe, Lmsensors and Hdd temperateure module."
echo "Starting nrpe daemon and adding it to the chkconfig for autoboot functionality."
cd /root
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh epel-release-latest-7*.rpm
yum -y --enablerepo="epel" install nagios-plugins-all nrpe lm_sensors hddtemp
systemctl restart nrpe
systemctl enable nrpe
echo "NOTE: On few CentOS 7 version's I've noticed that PID in nrpe.cfg needs to be changed from /var/run/nrpe.pid to /var/run/nrpe/nrpe.pid"
echo " Make sure to check systemctl status nrpe when this is installed to check if daemon is started properly."
else
echo "ERROR: Unknown OS Version detected. Aborting Install "
fi
if [ ${osversion} -eq 8 ];then
echo "Checking/Installing Epel repository CentOS 8, Nagios Plugins, Nrpe, Lmsensors and Hdd temperateure module."
echo "Starting nrpe daemon and adding it to the chkconfig for autoboot functionality."
cd /root
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
rpm -Uvh epel-release-latest-8*.rpm
yum install dnf-plugins-core
yum config-manager --set-enabled powertools
dnf install perl-Import-Into
yum install perl-utf8-all
yum install compat-openssl10
yum -y --enablerepo="epel" install nagios-plugins-all nrpe lm_sensors hddtemp
systemctl restart nrpe
systemctl enable nrpe
echo "NOTE: On few CentOS 8 version's I've noticed that PID in nrpe.cfg needs to be changed from /var/run/nrpe.pid to /var/run/nrpe/nrpe.pid"
echo " Make sure to check systemctl status nrpe when this is installed to check if daemon is started properly."
else
echo "ERROR: Unknown OS Version detected. Aborting Install "
fi
#Configuration block
echo "NOTE: What type of server is this? KVM/XEN, OpenVZ or Dedicated?"
echo "Please enter type as (1 - cloud, 2 - vz or 3 - dedi):"
read stype
if [ ${stype} -eq 1 ];then
rm -f /etc/nagios/nrpe.cfg ;
echo "Getting nrpe.cfg file with installed commands.."
wget -O /etc/nagios/nrpe.cfg http://repo.nemanja.io/nrpe.cfg
echo "Complete!"
fi
if [ ${stype} -eq 2 ];then
rm -f /etc/nagios/nrpe.cfg ;
echo "Getting nrpe.cfg file with installed commands.."
wget -O /etc/nagios/nrpe.cfg http://repo.nemanja.io/nrpe-vz.cfg
echo "Complete!"
fi
if [ ${stype} -eq 3 ];then
rm -f /etc/nagios/nrpe.cfg ;
echo "Getting nrpe.cfg file with installed commands.."
wget -O /etc/nagios/nrpe.cfg http://repo.nemanja.io/nrpe-dedi.cfg &&
echo "Complete!"
fi
echo "Adding Nagios username to /etc/sudoers file with limited access only to /usr/lib64/nagios/plugins/ folder."
sed -i '$ a nagios ALL=(ALL) NOPASSWD: /usr/lib64/nagios/plugins/' /etc/sudoers ;
sed -i '$ a nrpe ALL=(ALL) NOPASSWD: /usr/lib64/nagios/plugins/' /etc/sudoers ;
echo "Complete!"
echo "Removing requiretty from /etc/sudoers.. Sudo and Nagios cannot work with this together."
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
echo "Complete!"
echo "Removing current plugins installed in /usr/lib64/nagios/plugins folder and installing ours."
rm -f /usr/lib64/nagios/plugins/* ;
wget -O /etc/nagios/plugins.tar http://repo.nemanja.io/plugins.tar ;
tar -xvf /etc/nagios/plugins.tar -C /usr/lib64/nagios/plugins
echo "Complete!"
echo "Restarting Nrpe Daemon..."
service nrpe stop || systemctl stop nrpe
service nrpe start || systemctl start nrpe
echo "Mission completed! You can review what commands are enabled in /etc/nagios/nrpe.cfg file."
echo "Thank you for using Nagios Client installer for CentOS/RHEL."
}
setup_ubuntu(){
echo "Welcome to the Nagios Client installer (for Debian/Ubuntu). First, lets check if installation exist and remove it."
if [ ! -d /etc/nagios ];then
apt-get -y remove nagios-nrpe-server ;
apt-get -y remove nagios-plugins ;
apt-get -y remove lm-sensors
else
echo "Checking/Installing Nagios Plugins, Nrpe, Lmsensors and Hdd temperateure module."
echo "Starting nrpe daemon."
apt-get -y install nagios-nrpe-server nagios-plugins lm-sensors unzip vim hddtemp ;
echo "Starting nrpe daemon."
fi
#Configuration block
echo "NOTE: What type of server is this? KVM/XEN, OpenVZ or Dedicated?"
echo "Please enter type as (1 - cloud, 2 - vz or 3 - dedi):"
read stype
if [ ${stype} -eq 1 ];then
rm -f /etc/nagios/nrpe.cfg ;
echo "Getting nrpe.cfg file with installed commands.."
wget -O /etc/nagios/nrpe.cfg http://repo.nemanja.io/nrpe.cfg
echo "Complete!"
fi
if [ ${stype} -eq 2 ];then
rm -f /etc/nagios/nrpe.cfg ;
echo "Getting nrpe.cfg file with installed commands.."
wget -O /etc/nagios/nrpe.cfg http://repo.nemanja.io/nrpe-vz.cfg
echo "Complete!"
fi
if [ ${stype} -eq 3 ];then
rm -f /etc/nagios/nrpe.cfg &&
echo "Getting nrpe.cfg file with installed commands.."
wget -O /etc/nagios/nrpe.cfg http://repo.nemanja.io/nrpe-dedi.cfg ;
echo "Complete!"
fi
echo "Adding Nagios username to /etc/sudoers file with limited access only to /usr/lib64/nagios/plugins/ folder."
sed -i '$ a nagios ALL=(ALL) NOPASSWD: /usr/lib64/nagios/plugins/' /etc/sudoers ;
echo "Complete!"
echo "Removing requiretty from /etc/sudoers.. Sudo and Nagios cannot work with this together."
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
echo "Complete!"
echo "Removing current plugins installed in /usr/lib64/nagios/plugins folder and installing ours."
rm -f /usr/lib64/nagios/plugins/* &&
wget -O /etc/nagios/plugins.tar http://repo.nemanja.io/plugins.tar ;
tar -xvf /etc/nagios/plugins.tar -C /usr/lib64/nagios/plugins
echo "Complete!"
echo "Restarting Nrpe Daemon..."
/etc/init.d/nagios-nrpe-server restart
echo "Complete!"
echo "Adding port 5666 to firewall"
ufw allow 5666/tcp
echo "Complete!"
echo "Mission completed! You can review what commands are enabled in /etc/nagios/nrpe.cfg file."
echo "Thank you for using Nagios Client installer for CentOS/RHEL."
}
auto_setup(){
read -p "Are you sure you want to continue? <y/N> " prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
then
if [ -f /etc/redhat-release ]; then
setup_centos
fi
if [ -f /etc/lsb-release ]; then
setup_ubuntu
fi
else
exit 0
fi
}
#End Function defs
if [ ! -z $1 ];then
case $1 in
centos)
setup_centos
;;
ubuntu)
setup_ubuntu
;;
*)
auto_setup
;;
esac
else
auto_setup
fi