ovirt-node 2.2.0 release
[ovirt-node.git] / scripts / ovirt-config-collectd
blobaf0770cce95dc82514b0150f5141366e8b185649
1 #!/bin/bash
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
17 ovirt_collectd() {
18 local collectd_server=$1
19 local collectd_port=$2
21 start_log
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 \
25 > $collectd_conf
26 if [ $? -ne 0 ]; then
27 echo "Failed to write $collectd_conf"; return 1
31 chkconfig collectd on
32 service collectd restart
33 stop_log
36 prompt_user() {
37 while true ; do
38 collectd_server_ip=""
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
44 while true; do
45 read -p "Please enter the collectd port used: "
46 r=$REPLY
47 if [ -n "$r" ]; then
48 if [[ $r =~ ^[0-9]+$ ]] && [[ $r -gt 0 ]]; then
49 collectd_server_port=$REPLY
50 break
51 else
52 printf "Invalid port.\n"
55 done
56 else
57 printf "\nDisabling remote collectd.\n"
60 printf "\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"
67 printf "\n"
68 printf "\n"
69 while true; do
70 ask_yes_or_no "Is this correct ([Y]es/[N]o/[A]bort)?" true true
71 rc=$?
72 case $rc in
74 printf "\nSaving configuration.\n"
75 if [[ -n "$collectd_server_ip" ]] &&
76 [[ -n "$collectd_server_port" ]]; then
77 ovirt_collectd $collectd_server_ip \
78 $collectd_server_port
80 return
84 printf "\nRestarting collectd configuration.\n"
85 break
88 printf "\nAborting collectd configuration.\n"
89 return
91 esac
92 done
93 done
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
104 else
105 printf "not found!\n"
107 else
108 printf "\nUsing default collectd server '$OVIRT_COLLECTD_SERVER:$OVIRT_COLLECTD_PORT'.\n"
109 ovirt_collectd $OVIRT_COLLECTD_SERVER $OVIRT_COLLECTD_PORT
111 else
112 printf "\n\n Collectd Configuration\n\n"
113 prompt_user