Bryan Kearney
2008-Nov-07 18:58 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. Supports setting the maximum log file size. --- scripts/ovirt-config-logging | 139 ++++++++++++++++++++++++++++++++++++++++++ scripts/ovirt-config-setup | 2 + 2 files changed, 141 insertions(+), 0 deletions(-) diff --git a/scripts/ovirt-config-logging b/scripts/ovirt-config-logging index 8b13789..aab1dfe 100755 --- a/scripts/ovirt-config-logging +++ b/scripts/ovirt-config-logging @@ -1 +1,140 @@ +#!/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 + MAX_LOG_SIZE="10k" + printf "\nWhat is the max size for log files on this machine [10k]? " + read + if [[ "$REPLY" != "" ]]; then + MAX_LOG_SIZE=$REPLY + fi + 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 "\n" + printf "\nLogging will be configured as follows:" + printf "\n======================================" + printf "\n Max Logfile Size: $MAX_LOG_SIZE" + printf "\n Remote Server: $SYSLOG_SERVER_IP" + printf "\n Remote Port: $SYSLOG_SERVER_PORT" + printf "\n Logging Protocol: $SYSLOG_SERVER_PROTOCOL" + printf "\n" + printf "\nPlease confirm these changes (Y/N)" + read + case $REPLY in + Y|y) + ovirt_rsyslog $SYSLOG_SERVER_IP $SYSLOG_SERVER_PORT $SYSLOG_SERVER_PROTOCOL + sed -i -e "s/size=.*/size=$MAX_LOG_SIZE/" /etc/logrotate.d/ovirt-logrotate.conf + 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 8408d14..5850aa8 100755 --- a/scripts/ovirt-config-setup +++ b/scripts/ovirt-config-setup @@ -2,6 +2,8 @@ # # Entry point for configuring an oVirt node when running in standalone mode. +#Attempt to default the syslog setting +ovirt-config-logging "default" while true; do PS3="Please select an option: " # TODO should we make this optional, based on whether the password was already set? -- 1.5.6.5
Jim Meyering
2008-Nov-07 20:01 UTC
[Ovirt-devel] [PATCH node] RSyslog configuration for standalone mode.
Bryan Kearney <bkearney at redhat.com> wrote:> It looks for a DNS service locator record by default, and lets the > user override if desired. Supports setting the maximum log file size. > --- > scripts/ovirt-config-logging | 139 ++++++++++++++++++++++++++++++++++++++++++ > scripts/ovirt-config-setup | 2 + > 2 files changed, 141 insertions(+), 0 deletions(-) > > diff --git a/scripts/ovirt-config-logging b/scripts/ovirt-config-logging > index 8b13789..aab1dfe 100755 > --- a/scripts/ovirt-config-logging > +++ b/scripts/ovirt-config-logging > @@ -1 +1,140 @@ > +#!/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=""No need to initialize this.> +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/rsyslogShould that be "spool"?> +\$ActionQueueFileName ovirtNode > +\$ActionQueueMaxDiskSpace 10m > +\$ActionQueueSaveOnShutdown on > +\$ActionQueueType LinkedList > +\$ActionResumeRetryCount -1 > +*.* $DELIM$1:$2 > +EOF > + > +/sbin/service rsyslog restart > +} > + > +function prompt_user { > + while true ; do > + MAX_LOG_SIZE="10k" > + printf "\nWhat is the max size for log files on this machine [10k]? " > + read > + if [[ "$REPLY" != "" ]]; then > + MAX_LOG_SIZE=$REPLY > + fi > + 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.]+$' ]]; thenno need for "." in that range> + SYSLOG_SERVER_PORT=$REPLY > + NICS="$NICS Quit"You can remove that NICS= line. not used.> + PROTOCOLS="tcp udp" > + PS3="Please select a the protocol to use: "s/a //> + select SYSLOG_SERVER_PROTOCOL in $PROTOCOLS; > + do > + case $SYSLOG_SERVER_PROTOCOL in > + "tcp") > + break ;; > + "udp") > + break;; > + esac > + done > + > + printf "\n" > + printf "\nLogging will be configured as follows:" > + printf "\n======================================" > + printf "\n Max Logfile Size: $MAX_LOG_SIZE" > + printf "\n Remote Server: $SYSLOG_SERVER_IP" > + printf "\n Remote Port: $SYSLOG_SERVER_PORT" > + printf "\n Logging Protocol: $SYSLOG_SERVER_PROTOCOL" > + printf "\n" > + printf "\nPlease confirm these changes (Y/N)" > + read > + case $REPLY in > + Y|y) > + ovirt_rsyslog $SYSLOG_SERVER_IP $SYSLOG_SERVER_PORT $SYSLOG_SERVER_PROTOCOLPlease wrap long lines, e.g., ovirt_rsyslog \ $SYSLOG_SERVER_IP \ $SYSLOG_SERVER_PORT \ $SYSLOG_SERVER_PROTOCOL> + sed -i -e "s/size=.*/size=$MAX_LOG_SIZE/" /etc/logrotate.d/ovirt-logrotate.confSame here. And anchor the size= regexp, so as not to munge an "other_var_size=..." or commented out # size=... line. sed -i "s/^size=.*/size=$MAX_LOG_SIZE/" \ /etc/logrotate.d/ovirt-logrotate.conf> + break > + ;; > + N|n) > + printf "\nDiscarding settings"Put the \n at the end of the message, not at the beginning, here, since this isn't a prompt.> + break > + ;; > + esac > + else > + printf "\nInvalid port number"Likewise.> + 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)What does the output of that host command look like when there is such a record?> + if [[ "$DEFAULT_PORT" != "" ]] && [[ "$DEFAULT_SERVER" != "" ]] ; then > + printf "found! Useing server '$DEFAULT_SERVER'.\n"might as well include port #, too: printf "found! Using server:port '$DEFAULT_SERVER:$DEFAULT_PORT'.\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 8408d14..5850aa8 100755 > --- a/scripts/ovirt-config-setup > +++ b/scripts/ovirt-config-setup > @@ -2,6 +2,8 @@ > # > # Entry point for configuring an oVirt node when running in standalone mode. > > +#Attempt to default the syslog setting > +ovirt-config-logging "default" > while true; do > PS3="Please select an option: " > # TODO should we make this optional, based on whether the password was already set?
Bryan Kearney
2008-Nov-10 14:46 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. Supports setting the maximum log file size. Includes comments from Alan Pevec and Jim Meyering. --- scripts/ovirt-config-logging | 143 ++++++++++++++++++++++++++++++++++++++++++ scripts/ovirt-config-setup | 2 + 2 files changed, 145 insertions(+), 0 deletions(-) diff --git a/scripts/ovirt-config-logging b/scripts/ovirt-config-logging index 8b13789..fb5f96e 100755 --- a/scripts/ovirt-config-logging +++ b/scripts/ovirt-config-logging @@ -1 +1,144 @@ +#!/bin/bash +# +# Configures the rsyslog daemon. +# Source functions library +. /etc/init.d/functions +. /etc/init.d/ovirt-functions + + +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 { + +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/spool/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 + MAX_LOG_SIZE="10k" + printf "\nWhat is the max size for log files on this machine [10k]? " + read + if [[ "$REPLY" != "" ]]; then + MAX_LOG_SIZE=$REPLY + fi + 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 + + PROTOCOLS="tcp udp" + PS3="Please select the protocol to use: " + select SYSLOG_SERVER_PROTOCOL in $PROTOCOLS; + do + case $SYSLOG_SERVER_PROTOCOL in + "tcp") + break ;; + "udp") + break;; + esac + done + + printf "\n" + printf "\nLogging will be configured as follows:" + printf "\n======================================" + printf "\n Max Logfile Size: $MAX_LOG_SIZE" + printf "\n Remote Server: $SYSLOG_SERVER_IP" + printf "\n Remote Port: $SYSLOG_SERVER_PORT" + printf "\n Logging Protocol: $SYSLOG_SERVER_PROTOCOL" + printf "\n" + printf "\nPlease confirm these changes (Y/N)" + read + case $REPLY in + Y|y) + ovirt_rsyslog $SYSLOG_SERVER_IP \ + $SYSLOG_SERVER_PORT \ + $SYSLOG_SERVER_PROTOCOL + sed -i -e "s/^size=.*/size=$MAX_LOG_SIZE/" \ + /etc/logrotate.d/ovirt-logrotate.conf + break + ;; + N|n) + printf "Discarding settings\n" + break + ;; + esac + else + printf "Invalid port number\n" + 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..." + find_srv syslog udp + if [[ "$SRV_PORT" != "" ]] && [[ "$SRV_SERVER" != "" ]] ; then + printf "found! Useing server '$DEFAULT_SERVER:$DEFAULT_PORT'.\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 8408d14..5850aa8 100755 --- a/scripts/ovirt-config-setup +++ b/scripts/ovirt-config-setup @@ -2,6 +2,8 @@ # # Entry point for configuring an oVirt node when running in standalone mode. +#Attempt to default the syslog setting +ovirt-config-logging "default" while true; do PS3="Please select an option: " # TODO should we make this optional, based on whether the password was already set? -- 1.5.6.5