-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelegraf.sh
executable file
·52 lines (45 loc) · 1.67 KB
/
telegraf.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
#!/usr/bin/env bash
source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"
# load the type system
import util/log util/exception util/tryCatch util/namedParameters
# load the standard library for basic types and type the system
import util/class
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Check to make sure script is running on CentOS/Redhat
if [ ! -f /etc/redhat-release ]; then
echo "This script is for CentOS"
exit
fi
# Influxdb repo
cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF
# Install telegraf
try {
yum install telegraf -y
} catch {
echo "Could not install telegraf!"
echo "Caught Exception:$(UI.Color.Red) $__BACKTRACE_COMMAND__ $(UI.Color.Default)"
echo "File: $__BACKTRACE_SOURCE__, Line: $__BACKTRACE_LINE__"
## printing a caught exception couldn't be simpler, as it's stored in "${__EXCEPTION__[@]}"
Exception::PrintException "${__EXCEPTION__[@]}"
}
# startup
try {
chkconfig telegraf on
} catch {
echo "Could not enable telegraf on system startup"
echo "Caught Exception:$(UI.Color.Red) $__BACKTRACE_COMMAND__ $(UI.Color.Default)"
echo "File: $__BACKTRACE_SOURCE__, Line: $__BACKTRACE_LINE__"
## printing a caught exception couldn't be simpler, as it's stored in "${__EXCEPTION__[@]}"
Exception::PrintException "${__EXCEPTION__[@]}"
}