-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall_nrpe.sh
164 lines (148 loc) · 4.28 KB
/
install_nrpe.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
#!/bin/bash
#
# Copyright (C) 2016 - Dorance Martinez C
# Author: Dorance Martinez C [email protected]
# SPDX-License-Identifier: GPL-3.0+
#
# Descripcion: Script para installar nrpe
# Version: 0.2.2 - 9-jun-2018
# Validado en : Debian >=6, Ubuntu >=16, Centos >=6, openSuSE >=42
#
NRPE_version="3.2.1"
TEMP_PATH="/tmp/nagios_`date +%Y%m%d%H%M%S`"
INSTALL_PATH="/opt/nagios"
NAGIOS_USER="nagios"
linux_variant() {
if [ -f "/etc/debian_version" ]; then
if ! command_exists lsb_release ; then
apt-get install -y lsb-release
fi
distro=$(lsb_release -s -i | tr '[:upper:]' '[:lower:]')
flavour=$(lsb_release -s -c )
version=$(lsb_release -s -r | cut -d. -f1 )
elif [ -f "/etc/redhat-release" ]; then
distro="rh"
flavour=$(cat /etc/redhat-release | cut -d" " -f1 | tr '[:upper:]' '[:lower:]' )
version=$(cat /etc/redhat-release | grep -oE '[0-9]+\.[0-9]+' | cut -d. -f1 )
elif [ -f "/etc/SuSE-release" ]; then
distro="suse"
flavour=$(cat /etc/SuSE-release | head -1 | cut -d" " -f1 | tr '[:upper:]' '[:lower:]' )
version=$(cat /etc/SuSE-release | grep -i version | grep -oE '[0-9]+\.[0-9]+' | cut -d. -f1 )
else
distro="unknown"
fi
}
command_exists () {
type "$1" &> /dev/null ;
}
user_exist() {
if id "$1" >/dev/null 2>&1; then
echo "user $1 exists"
else
groupadd $1 ; useradd -m -d $2 -g $1 $1
fi
}
file_exist() {
if [ -f $1 ]; then
cp ${1} ${1}-backup_`date +%Y%m%d%H%M%S`
fi
}
debian() {
if [ $version -ge 8 ]; then
INIT_TYPE="systemd"
CMD_STARTUP="systemctl enable nrpe.service"
else
INIT_TYPE="sysv"
CMD_STARTUP="update-rc.d nrpe defaults"
fi
debian_ubuntu_pkgs &&
return 0
}
raspbian() {
debian
}
ubuntu() {
if [ $version -ge 16 ]; then
INIT_TYPE="systemd"
CMD_STARTUP="systemctl enable nrpe.service"
else
INIT_TYPE="sysv"
CMD_STARTUP="update-rc.d nrpe defaults"
fi
debian_ubuntu_pkgs &&
return 0
}
debian_ubuntu_pkgs() {
if [ "$nrpe_install" = "git" ]; then
if ! command_exists git ; then
apt-get install -y git
fi
fi
apt-get install -y wget gcc libssl-dev libkrb5-dev make fping &&
installar_nrpe &&
return 0
}
rh() {
if [ $version -ge 7 ]; then
INIT_TYPE="systemd"
CMD_STARTUP="systemctl enable nrpe.service"
else
INIT_TYPE="sysv"
CMD_STARTUP="chkconfig nrpe on"
fi
if [ "$nrpe_install" = "git" ]; then
if ! command_exists git ; then
yum install git -y
fi
fi
yum install -y wget gcc make fping krb5-devel openssl-devel &&
installar_nrpe &&
return 0
}
suse() {
if [ $version -ge 12 ]; then
INIT_TYPE="systemd"
CMD_STARTUP="systemctl enable nrpe.service"
else
INIT_TYPE="sysv"
CMD_STARTUP="chkconfig nrpe on"
fi
if [ "$nrpe_install" = "git" ]; then
if ! command_exists git ; then
zypper --non-interactive install git
fi
fi
zypper --non-interactive install wget gcc make fping krb5-devel libopenssl-devel
installar_nrpe &&
return 0
}
unknown() {
echo "Sorry, I can't identify your Linux version :( "
exit 1
}
installar_nrpe() {
user_exist ${NAGIOS_USER} ${INSTALL_PATH} &&
file_exist ${INSTALL_PATH}/etc/nrpe.cfg &&
if [ "$nrpe_install" = "git" ]; then
git clone https://github.com/NagiosEnterprises/nrpe.git ${TEMP_PATH}/nrpe-${NRPE_version}
else
mkdir -p ${TEMP_PATH} &&
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-${NRPE_version}/nrpe-${NRPE_version}.tar.gz -O ${TEMP_PATH}/nrpe-${NRPE_version}.tar.gz &&
tar -zxvf ${TEMP_PATH}/nrpe-${NRPE_version}.tar.gz -C ${TEMP_PATH}
fi
cd ${TEMP_PATH}/nrpe-${NRPE_version} && ./configure --prefix=${INSTALL_PATH} --enable-ssl --enable-command-args --with-nrpe-user=${NAGIOS_USER} --with-nrpe-group=${NAGIOS_USER} --with-nagios-user=${NAGIOS_USER} --with-nagios-group=${NAGIOS_USER} --with-opsys=linux --with-dist-type=${distro} --with-init-type=${INIT_TYPE} &&
mkdir -p /opt/nagios && chown -R ${NAGIOS_USER}: ${INSTALL_PATH} &&
make all && make install && make install-plugin && make install-daemon && make install-config && make install-init &&
mkdir -p ${INSTALL_PATH}/etc/nrpe/ &&
echo "include_dir=${INSTALL_PATH}/etc/nrpe" >>${INSTALL_PATH}/etc/nrpe.cfg &&
$CMD_STARTUP &&
return 0
}
run_core() {
linux_variant
$distro &&
rm -rf ${TEMP_PATH} &&
return 0
}
run_core &&
exit 0