3 # Configures the collectd daemon.
4 # Source functions library
5 .
/etc
/init.d
/functions
6 .
/usr
/libexec
/ovirt-functions
8 trap '__st=$?; stop_log; exit $__st' 0
9 trap 'exit $?' 1 2 13 15
11 collectd_conf
="/etc/collectd.conf"
13 # Creates the collectd file based on the following inputs
14 # $1 ipaddress of remote collectd server
15 # $2 port of remote collectd server
16 # TODO implement and use Augeas lens
18 local collectd_server
=$1
19 local collectd_port
=$2
22 if [ -f $collectd_conf.
in ]; then
23 sed -e "s/@COLLECTD_SERVER@/$collectd_server/" \
24 -e "s/@COLLECTD_PORT@/$collectd_port/" $collectd_conf.
in \
27 echo "Failed to write $collectd_conf"; return 1
32 service collectd restart
39 collectd_server_port
=""
41 read -p "Please enter the IP address for the collectd server: "
42 if [ -n "$REPLY" ]; then
43 collectd_server_ip
=$REPLY
45 read -p "Please enter the collectd port used: "
48 if [[ $r =~ ^
[0-9]+$
]] && [[ $r -gt 0 ]]; then
49 collectd_server_port
=$REPLY
52 printf "Invalid port.\n"
57 printf "\nDisabling remote collectd.\n"
61 printf "\nCollectd will be configured as follows:"
62 printf "\n======================================"
63 if [ -n "$collectd_server_ip" ]; then
64 printf "\n Remote Server: $collectd_server_ip"
65 printf "\n Remote Port: $collectd_server_port"
70 ask_yes_or_no
"Is this correct ([Y]es/[N]o/[A]bort)?" true true
74 printf "\nSaving configuration.\n"
75 if [[ -n "$collectd_server_ip" ]] &&
76 [[ -n "$collectd_server_port" ]]; then
77 ovirt_collectd
$collectd_server_ip \
84 printf "\nRestarting collectd configuration.\n"
88 printf "\nAborting collectd configuration.\n"
96 # AUTO for auto-install
97 if [ "$1" = "AUTO" ]; then
98 if [ -z "$OVIRT_COLLECTD_SERVER" -o -z "$OVIRT_COLLECTD_PORT" ]; then
99 printf "\nAttempting to locate remote collectd server..."
100 find_srv collectd udp
101 if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then
102 printf "found! Using collectd server '$SRV_HOST:$SRV_PORT'.\n"
103 ovirt_collectd
$SRV_HOST $SRV_PORT
105 printf "not found!\n"
108 printf "\nUsing default collectd server '$OVIRT_COLLECTD_SERVER:$OVIRT_COLLECTD_PORT'.\n"
109 ovirt_collectd
$OVIRT_COLLECTD_SERVER $OVIRT_COLLECTD_PORT
112 printf "\n\n Collectd Configuration\n\n"