ovirt-node 2.2.0 release
[ovirt-node.git] / scripts / ovirt-config-logging
blobe296ac4103afd5f093d2c6317b21d438af828ea3
1 #!/bin/bash
3 # Configures the rsyslog 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 if ! is_local_storage_configured; then
12 printf "Local storage must be configured prior to configuring the logging system.\n"
13 exit 99
16 RSYSLOG_FILE="/etc/rsyslog.conf"
18 # Creates the rsyslog file based on the following inputs
19 # $1 ipaddress of remote syslog server
20 # $2 port of remote syslog server
21 # $3 protocol (tcp or udp)
22 # TODO implement and use Augeas lens
23 function ovirt_rsyslog {
25 if [ "$3" = "tcp" ]; then
26 DELIM="@@"
27 else DELIM="@"
30 cat > $RSYSLOG_FILE << EOF
31 #ovirt rsyslog config file
33 #### MODULES ####
34 \$ModLoad imuxsock.so # provides support for local system logging (e.g. via logger command)
35 \$ModLoad imklog.so # provides kernel logging support (previously done by rklogd)
37 #### GLOBAL DIRECTIVES ####
38 # Use default timestamp format
39 \$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
41 #### RULES ####
42 # Log anything (except mail) of level info or higher.
43 # Don't log private authentication messages!
44 *.info;mail.none;authpriv.none;cron.none /var/log/messages
46 # The authpriv file has restricted access.
47 authpriv.* /var/log/secure
49 # Log all the mail messages in one place.
50 mail.* -/var/log/maillog
52 # Log cron stuff
53 cron.* /var/log/cron
55 # Everybody gets emergency messages
56 *.emerg *
58 # Save news errors of level crit and higher in a special file.
59 uucp,news.crit /var/log/spooler
61 # Save boot messages also to boot.log
62 local7.* /var/log/boot.log
64 \$WorkDirectory /var/spool/rsyslog
65 \$ActionQueueFileName ovirtNode
66 \$ActionQueueMaxDiskSpace 10m
67 \$ActionQueueSaveOnShutdown on
68 \$ActionQueueType LinkedList
69 \$ActionResumeRetryCount -1
70 *.* $DELIM$1:$2
71 EOF
73 start_log
74 /sbin/service rsyslog restart
75 stop_log
78 function is_numeric {
79 printf "$1" | grep -q -E '^[0-9]+$'
82 function prompt_user {
83 while true ; do
84 max_log_size="1024"
85 syslog_server_ip=""
86 syslog_server_port=""
88 while true; do
89 printf "\n"
90 read -p "What is the max size, in kilobytes, for local log files (def. ${max_log_size}k)? "
92 if [ -n "$REPLY" ]; then
93 r=$REPLY
94 if [[ $r =~ ^[0-9]+$ ]] && [[ $r -gt 0 ]]; then
95 max_log_size=$r
96 printf "\nMaximum logging size will be ${max_log_size}k.\n"
97 break
98 else
99 printf "\nInvalid input.\n"
101 else
102 printf "\nLeaving log size as ${max_log_size}k.\n"
103 break
105 done
107 printf "\n"
108 read -p "What is the IP address for the syslog server, hit Enter to skip? "
109 if [ -n "$REPLY" ]; then
110 syslog_server_ip=$REPLY
111 while true; do
112 read -p "Please enter the remote logging port used: "
113 r=$REPLY
114 if [ -n "$r" ]; then
115 if [[ $r =~ ^[0-9]+$ ]] && [[ $r -gt 0 ]]; then
116 syslog_server_port=$REPLY
117 break
118 else
119 printf "Invalid port.\n"
122 done
124 printf "\n"
125 while true; do
126 read -p "Remote logging uses [t]cp or [u]dp? "
127 r=$(echo $REPLY|tr '[[:lower:]]' '[[:upper:]]')
128 if [ "$r" == "T" ]; then syslog_server_protocol="tcp"; break; fi
129 if [ "$r" == "U" ]; then syslog_server_protocol="udp"; break; fi
130 # else
131 printf "Invalid input.\n"
132 done
133 else
134 printf "\nDisabling remote logging.\n"
137 printf "\n"
138 printf "\nLogging will be configured as follows:"
139 printf "\n======================================"
140 printf "\n Max Logfile Size: $max_log_size"
141 if [ -n "$syslog_server_ip" ]; then
142 printf "\n Remote Server: $syslog_server_ip"
143 printf "\n Remote Port: $syslog_server_port"
144 printf "\n Logging Protocol: $syslog_server_protocol"
146 printf "\n"
147 printf "\n"
148 while true; do
149 ask_yes_or_no "Is this correct ([Y]es/[N]o/[A]bort)?" true true
150 case $? in
152 printf "\nSaving configuration.\n"
153 if [[ -n "$syslog_server_ip" ]] &&
154 [[ -n "$syslog_server_port" ]] &&
155 [[ -n "$syslog_server_protocol" ]]; then
156 ovirt_rsyslog $syslog_server_ip \
157 $syslog_server_port \
158 $syslog_server_protocol
160 sed -c -i -e "s/size.*/size ${max_log_size}k/" \
161 /etc/logrotate.d/ovirt-node
162 return
165 printf "\nRestarting logging configuration.\n"
166 break
169 printf "\nAborting logging configuration.\n"
170 return
172 esac
173 done
174 done
177 function ovirt_netconsole {
178 augtool <<EOF
179 set /files/etc/sysconfig/netconsole/SYSLOGADDR $OVIRT_NETCONSOLE_SERVER
180 set /files/etc/sysconfig/netconsole/SYSLOGPORT $OVIRT_NETCONSOLE_PORT
182 ovirt_store_config /etc/sysconfig/netconsole
184 # AUTO for auto-install
185 if [ "$1" = "AUTO" ]; then
186 if [ -z "$OVIRT_SYSLOG_SERVER" -o -z "$OVIRT_SYSLOG_PORT" ]; then
187 printf "\nAttempting to locate remote syslog server..."
188 find_srv syslog udp
189 if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then
190 printf "found! Using syslog server '$SRV_HOST:$SRV_PORT'.\n"
191 ovirt_rsyslog $SRV_HOST $SRV_PORT udp
192 else
193 printf "not found!\n"
195 else
196 printf "\nUsing default syslog server '$OVIRT_SYSLOG_SERVER:$OVIRT_SYSLOG_PORT'.\n"
197 ovirt_rsyslog $OVIRT_SYSLOG_SERVER $OVIRT_SYSLOG_PORT udp
199 if [ -n "$OVIRT_NETCONSOLE_SERVER" -a -n "$OVIRT_NETCONSOLE_PORT" ]; then
200 printf "\nConfiguring netconsole server..."
201 ovirt_netconsole
203 else
204 printf "\n\n Logging Configuration\n\n"
205 prompt_user