Bryan Kearney
2008-Nov-06 14:40 UTC
[Ovirt-devel] [PATCH node] RSyslog configuration for standalone mode. It looks for a DNS service locator record by default, and lets the user override if desired
--- scripts/ovirt-config-logging | 124 ++++++++++++++++++++++++++++++++++++++++++ scripts/ovirt-config-setup | 7 ++- 2 files changed, 128 insertions(+), 3 deletions(-) diff --git a/scripts/ovirt-config-logging b/scripts/ovirt-config-logging index 8b13789..831dee5 100755 --- a/scripts/ovirt-config-logging +++ b/scripts/ovirt-config-logging @@ -1 +1,125 @@ +#!/bin/bash +# +# Configures the rsyslog daemon. +RSYSLOG_FILE="/etc/rsyslog.conf" + +# Creates the rsyslog file based on the following inputs +# $1 ipaddress of remote syslog server +# $2 port of remote syslog server +# $3 protocol (tcp or udp) +function ovirt_rsyslog { + +DELIM="" + +if [[ "$3" = "tcp" ]]; then + DELIM="@@" +else + DELIM="@" +fi + +cat > $RSYSLOG_FILE << EOF +#ovirt rsyslog config file + +#### MODULES #### +\$ModLoad imuxsock.so # provides support for local system logging (e.g. via logger command) +\$ModLoad imklog.so # provides kernel logging support (previously done by rklogd) + +#### GLOBAL DIRECTIVES #### +# Use default timestamp format +\$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat + +#### RULES #### +# Log anything (except mail) of level info or higher. +# Don't log private authentication messages! +*.info;mail.none;authpriv.none;cron.none /var/log/messages + +# The authpriv file has restricted access. +authpriv.* /var/log/secure + +# Log all the mail messages in one place. +mail.* -/var/log/maillog + +# Log cron stuff +cron.* /var/log/cron + +# Everybody gets emergency messages +*.emerg * + +# Save news errors of level crit and higher in a special file. +uucp,news.crit /var/log/spooler + +# Save boot messages also to boot.log +local7.* /var/log/boot.log + +\$WorkDirectory /var/spppl/rsyslog +\$ActionQueueFileName ovirtNode +\$ActionQueueMaxDiskSpace 10m +\$ActionQueueSaveOnShutdown on +\$ActionQueueType LinkedList +\$ActionResumeRetryCount -1 +*.* $DELIM$1:$2 +EOF + +/sbin/service rsyslog restart +} + +function prompt_user { + while true ; do + printf "\nWhat is the IP address or server name for the syslog server? " + read + SYSLOG_SERVER_IP=$REPLY + printf "\nWhat port does the syslog daemon run on? " + read + if [[ "$REPLY" =~ '^[0-9.]+$' ]]; then + SYSLOG_SERVER_PORT=$REPLY + NICS="$NICS Quit" + + PROTOCOLS="tcp udp" + PS3="Please select a the protocol to use: " + select SYSLOG_SERVER_PROTOCOL in $PROTOCOLS; + do + case $SYSLOG_SERVER_PROTOCOL in + "tcp") + break ;; + "udp") + break;; + esac + done + + printf "\nConfirm send all log messages to server '$SYSLOG_SERVER_IP' on port '$SYSLOG_SERVER_PORT' using protocol '$SYSLOG_SERVER_PROTOCOL' (Y/N)" + read + case $REPLY in + Y|y) + ovirt_rsyslog $SYSLOG_SERVER_IP $SYSLOG_SERVER_PORT $SYSLOG_SERVER_PROTOCOL + break + ;; + N|n) + printf "\nDiscarding settings" + break + ;; + esac + else + printf "\nInvalid port number" + fi + done + +} + +# check if we were called to attempt to default +# to remote logging +if [[ "$1" = "default" ]] ; then + printf "\nAttempting to locate remote syslog server..." + DEFAULT_SERVER=$(host -N 3 -t srv _syslog._udp | rev | awk '/VRS/ {print $1}' | cut -d. -f2- | rev) + DEFAULT_PORT=$(host -N 3 -t srv _syslog._udp | rev | awk '/VRS/ {print $2}' | cut -d. -f2- | rev) + if [[ "$DEFAULT_PORT" != "" ]] && [[ "$DEFAULT_SERVER" != "" ]] ; then + printf "found! Useing server '$DEFAULT_SERVER'.\n" + ovirt_rsyslog $DEFAULT_SERVER $DEFAULT_PORT "udp" + else + printf "not found!\n" + fi +else + prompt_user +fi + +exit 0 diff --git a/scripts/ovirt-config-setup b/scripts/ovirt-config-setup index 48cfcdd..7d3d900 100755 --- a/scripts/ovirt-config-setup +++ b/scripts/ovirt-config-setup @@ -4,13 +4,14 @@ PS3="Please select an option: " +#Attempt to default the syslog setting +ovirt-config-logging "default" + # TODO should we make this optional, based on whether the password was already set? PASSWORD_OPTION="Password" -LIST="Networking Storage Logging ${PASSWORD_OPTION} Quit" +LIST="Networking Storage Logging ${PASSWORD_OPTION} Done" CONTINUE=true - -printf "\n" while $CONTINUE; do select OPT in $LIST do -- 1.5.6.5