forked from ptierno/signalfx-collectd-configs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_helpers
247 lines (225 loc) · 7.37 KB
/
install_helpers
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
export LATEST_VER=5.5.0
vercomp () {
if [[ $1 == "$2" ]]
then
echo 0
return
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
echo 1
return
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
echo 2
return
fi
done
echo 0
}
check_for_err() {
if [ $? != 0 ]; then
printf "FAILED\n";
exit 1;
else
printf "$@";
fi
}
find_installed_collectd(){
for p in /opt/signalfx-collectd/sbin/collectd /usr/sbin/collectd "/usr/local/sbin/collectd"; do
if [ -x $p ]; then
COLLECTD=${p}
find_collectd_ver
break;
fi
done
}
find_collectd_ver() {
COLLECTD_VER=$(${COLLECTD} -h | sed -n 's/^collectd \([0-9\.]*\).*/\1/p')
if [ -z "$COLLECTD_VER" ]; then
echo "Failed to figure out CollectD version";
exit 2;
fi
}
determine_os() {
#variables used
selection=0
needed_rpm=null_rpm_link
needed_rpm_name=null_rpm_name
needed_package_name=null_package_name
#rpm file variables
centos_rpm="SignalFx-collectd_plugin-RPMs-centos-${release_type}-latest.noarch.rpm"
aws_linux_rpm="SignalFx-collectd_plugin-RPMs-AWS_EC2_Linux-${release_type}-latest.noarch.rpm"
#download location variables
centos="https://dl.signalfx.com/rpms/SignalFx-rpms/${release_type}/${centos_rpm}"
aws_linux="https://dl.signalfx.com/rpms/SignalFx-rpms/${release_type}/${aws_linux_rpm}"
signalfx_public_key_id="185894C15AE495F6"
#determine hostOS for newer versions of Linux
hostOS=$(cat /etc/*-release | grep PRETTY_NAME | grep -o '".*"' | sed 's/"//g' | sed -e 's/([^()]*)//g' | sed -e 's/[[:space:]]*$//')
if [ ! -f /etc/redhat-release ]
then
hostOS_2=null_os
else
#older versions of RPM based Linux that don't have version in PRETTY_NAME format
hostOS_2=$(head -c 16 /etc/redhat-release)
fi
#determine if the script is being run by root or not
user=$(whoami)
if [ "$user" == "root" ]; then
sudo=""
else
sudo="sudo"
fi
}
#RPM Based Linux Functions
#Install function for RPM collectd
install_rpm_plugin_procedure()
{
#download signalfx plugin rpm for collectd
printf "Downloading SignalFx plugin RPM\n"
curl $needed_rpm -o $needed_rpm_name
#install signalfx rpm for collectd
printf "Installing SignalFx plugin RPM\n"
$sudo yum -y install $needed_rpm_name
$sudo rm -f $needed_rpm_name
#install collectd from signalfx plugin rpm
printf "Installing signalfx-collectd-plugin\n"
$sudo yum -y install signalfx-collectd-plugin
FOUND=1
}
install_plugin() {
if [ -f /opt/signalfx-collectd-plugin/signalfx_metadata.py ]; then
printf "SignalFx collectd plugin already installed\n"
return
fi
determine_os
#take "hostOS" and match it up to OS and assign tasks
case $hostOS in
"CentOS Linux 7")
needed_rpm=$centos
needed_rpm_name=$centos_rpm
printf "Install will proceed for %s\n" "$hostOS"
install_rpm_plugin_procedure
;;
"CentOS Linux 6")
needed_rpm=$centos
needed_rpm_name=$centos_rpm
printf "Install will proceed for %s\n" "$hostOS"
install_rpm_plugin_procedure
;;
"Amazon Linux AMI 2014.09")
needed_rpm=$aws_linux
needed_rpm_name=$aws_linux_rpm
printf "Install will proceed for %s\n" "$hostOS"
install_rpm_plugin_procedure
;;
"Amazon Linux AMI 2015.03")
needed_rpm=$aws_linux
needed_rpm_name=$aws_linux_rpm
printf "Install will proceed for %s\n" "$hostOS"
install_rpm_plugin_procedure
;;
"Amazon Linux AMI 2015.09")
needed_rpm=$aws_linux
needed_rpm_name=$aws_linux_rpm
printf "Install will proceed for %s\n" "$hostOS"
install_rpm_plugin_procedure
;;
"Debian GNU/Linux 7")
needed_package_name="apt-transport-https"
printf "Install will proceed for %s\n" "$hostOS"
debian_distribution_name="wheezy"
install_debian_collectd_procedure
;;
"Debian GNU/Linux 8")
needed_package_name="apt-transport-https"
printf "Install will proceed for %s\n" "$hostOS"
debian_distribution_name="jessie"
install_debian_collectd_procedure
;;
"Ubuntu 15.04"*)
needed_package_name=software-properties-common
printf "Install will proceed for %s\n" "$hostOS"
debian_distribution_name="vivid"
install_debian_collectd_procedure
;;
"Ubuntu 14.04"*)
needed_package_name=software-properties-common
printf "Install will proceed for %s\n" "$hostOS"
debian_distribution_name="trusty"
install_debian_collectd_procedure
;;
"Ubuntu 12.04"* | "Ubuntu precise"*)
needed_package_name=python-software-properties
printf "Install will proceed for %s\n" "$hostOS"
debian_distribution_name="precise"
install_debian_collectd_procedure
;;
*)
case $hostOS_2 in
"CentOS release 6")
needed_rpm=$centos
needed_rpm_name=$centos_rpm
printf "Install will proceed for %s\n" "$hostOS_2"
install_rpm_plugin_procedure
;;
"Red Hat Enterpri")
needed_rpm=$centos
needed_rpm_name=$centos_rpm
printf "Install will proceed for %s\n" "$hostOS"
install_rpm_plugin_procedure
;;
*)
;;
esac
;;
esac
if [ -z "$FOUND" ]; then
printf "Unsupported OS, will not attempt to install plugin\n"
NO_PLUGIN=1
fi
}
#Debian Based Linux Functions
#Install function for debian based systems
install_debian_collectd_procedure()
{
#Installing dependent packages to later add signalfx plugin repo
printf "Installing source package to get SignalFx collectd plugin package\n"
$sudo apt-get -y install $needed_package_name
repo_link="https://dl.signalfx.com/debs/signalfx-collectd-plugin/${debian_distribution_name}/${release_type}"
if [ "$release_type" = "test" ]; then
printf "Getting SignalFx collectd package from test repo hosted at SignalFx\n"
echo "deb [trusted=yes] ${repo_link} /" | $sudo tee /etc/apt/sources.list.d/signalfx_collectd_plugin-${release_type}-${debian_distribution_name}.list > /dev/null
else
#Adding signalfx repo
printf "Getting SignalFx collectd package\n"
if [ "$debian_distribution_name" == "wheezy" ] || [ "$debian_distribution_name" == "jessie" ]; then
$sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $signalfx_public_key_id
echo "deb ${repo_link} /" | $sudo tee /etc/apt/sources.list.d/signalfx_collectd_plugin-${release_type}-${debian_distribution}.list > /dev/null
else
$sudo add-apt-repository -y ppa:signalfx/collectd-plugin-${release_type}
fi
fi
#Updating apt-get to reference the signalfx repo to install plugin
printf "Updating apt-get to reference new SignalFx plugin package\n"
$sudo apt-get -y update
#Installing signalfx collectd package and plugins
printf "Installing collectd and additional plugins\n"
$sudo apt-get -y install signalfx-collectd-plugin
FOUND=1
}