public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] patch: emergemail feature in functions.sh
@ 2003-08-19  5:37 Owen Gunden
  2003-08-19  5:44 ` Jon Portnoy
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Owen Gunden @ 2003-08-19  5:37 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 769 bytes --]

Hi,

Attached is a small patch for the file functions.sh (part of baselayout)
which implements the feature "emergemail" (set in /etc/make.conf FEATURES).
When this feature is turned on (and an mta is present), all einfo, ewarn,
and eerror messages are emailed to root.

This is useful if you upgrade or install multiple packages at once, and you
don't want to miss any important messages that go whizzing by.

There is a major flaw with the current implementation.  Namely, you get an
email for _every_ invocation of einfo, ewarn, or error.  The way those
functions are commonly used (repeated calls for multi-line messages) makes
avoiding this flaw quite difficult without rather sweeping changes to the
design of emerge/ebuild.

Comments or suggestions welcome.
Owen

[-- Attachment #2: functions.sh.patch --]
[-- Type: text/plain, Size: 1695 bytes --]

--- functions-old.sh	2003-08-18 21:49:35.000000000 -0400
+++ functions.sh	2003-08-19 01:23:25.000000000 -0400
@@ -121,6 +121,31 @@
 	BRACKET=$'\e[34;01m'
 fi
 
+# void emergemail(char *severity, char *message)
+#
+#	send mail to root with the given message (if possible)
+#	severity is either "information" (for einfo),
+#					   "warning" (for ewarn),
+#					or "error" (for eerror).
+#
+emergemail() {
+	SEVERITY=$1
+	MESSAGE=$2
+	if echo ${FEATURES} | grep -iq emergemail; then
+		if [ -x /usr/sbin/sendmail ]; then
+			echo -e "Subject: ${SEVERITY} from emerge of ${P}\n\n${MESSAGE}" \
+						| /usr/sbin/sendmail root 
+		else
+			# don't you dare try to use ewarn here :)
+			echo -e " ${WARN}*${NORMAL} the emergemail feature was unable to"
+			echo -e " ${WARN}*${NORMAL} find /usr/sbin/sendmail.  You must have"
+			echo -e " ${WARN}*${NORMAL} a Mail Transfer Agent (MTA) such as"
+			echo -e " ${WARN}*${NORMAL} postfix, exim, ssmtp, etc. to use this"
+			echo -e " ${WARN}*${NORMAL} feature."
+		fi
+	fi
+}
+
 # void esyslog(char* priority, char* tag, char* message)
 #
 #    use the system logger to log a message
@@ -153,6 +178,8 @@
 		echo -e " ${GOOD}*${NORMAL} ${*}"
 	fi
 
+	emergemail information "${*}"
+
 	return 0
 }
 
@@ -166,6 +193,8 @@
 		echo -ne " ${GOOD}*${NORMAL} ${*}"
 	fi
 
+	emergemail information "${*}"
+
 	return 0
 }
 
@@ -181,6 +210,8 @@
 		echo -e " ${WARN}*${NORMAL} ${*}"
 	fi
 
+	emergemail warning "${*}"
+
 	# Log warnings to system log
 	esyslog "daemon.warning" "rc-scripts" "${*}"
 
@@ -199,6 +230,8 @@
 		echo -e " ${BAD}*${NORMAL} ${*}"
 	fi
 
+	emergemail error "${*}"
+
 	# Log errors to system log
 	esyslog "daemon.err" "rc-scripts" "${*}"
 


[-- Attachment #3: Type: text/plain, Size: 37 bytes --]

--
gentoo-dev@gentoo.org mailing list

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] patch: emergemail feature in functions.sh
  2003-08-19  5:37 [gentoo-dev] patch: emergemail feature in functions.sh Owen Gunden
@ 2003-08-19  5:44 ` Jon Portnoy
  2003-08-19  5:54 ` Mike Frysinger
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Jon Portnoy @ 2003-08-19  5:44 UTC (permalink / raw
  To: gentoo-dev; +Cc: portage-dev

On Tue, Aug 19, 2003 at 01:37:23AM -0400, Owen Gunden wrote:
> Hi,
> 
> Attached is a small patch for the file functions.sh (part of baselayout)
> which implements the feature "emergemail" (set in /etc/make.conf FEATURES).
> When this feature is turned on (and an mta is present), all einfo, ewarn,
> and eerror messages are emailed to root.
> 
> This is useful if you upgrade or install multiple packages at once, and you
> don't want to miss any important messages that go whizzing by.
> 
> There is a major flaw with the current implementation.  Namely, you get an
> email for _every_ invocation of einfo, ewarn, or error.  The way those
> functions are commonly used (repeated calls for multi-line messages) makes
> avoiding this flaw quite difficult without rather sweeping changes to the
> design of emerge/ebuild.
> 
> Comments or suggestions welcome.

I haven't had time to look at or test the code, but I really love the 
concept. I'd love to see it integrated into Portage.

-- 
Jon Portnoy
avenj/irc.freenode.net

--
gentoo-dev@gentoo.org mailing list


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] patch: emergemail feature in functions.sh
  2003-08-19  5:37 [gentoo-dev] patch: emergemail feature in functions.sh Owen Gunden
  2003-08-19  5:44 ` Jon Portnoy
@ 2003-08-19  5:54 ` Mike Frysinger
  2003-08-19  6:50 ` Karsten Schulz
  2003-08-19 13:05 ` Thomas de Grenier de Latour
  3 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2003-08-19  5:54 UTC (permalink / raw
  To: gentoo-dev

On Tuesday 19 August 2003 01:37, Owen Gunden wrote:
> Comments or suggestions welcome.

cool idea ... perhaps you'd like to review Bug 11359 (pkg_postinst/pkg_preinst 
ewarn/einfo logging) and Bug 1184 (Ideas from Sorcerer Linux) ...

once you do and if you enhance the script some more, i'd suggest posting it to 
one of those bugs or making a new one
-mike

--
gentoo-dev@gentoo.org mailing list


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] patch: emergemail feature in functions.sh
  2003-08-19  5:37 [gentoo-dev] patch: emergemail feature in functions.sh Owen Gunden
  2003-08-19  5:44 ` Jon Portnoy
  2003-08-19  5:54 ` Mike Frysinger
@ 2003-08-19  6:50 ` Karsten Schulz
  2003-08-19  8:34   ` Owen Gunden
  2003-08-19 23:53   ` Owen Gunden
  2003-08-19 13:05 ` Thomas de Grenier de Latour
  3 siblings, 2 replies; 7+ messages in thread
From: Karsten Schulz @ 2003-08-19  6:50 UTC (permalink / raw
  To: gentoo-dev

Am Dienstag, 19. August 2003 07:37 schrieb Owen Gunden:
> When this feature is turned on (and an mta
> is present), all einfo, ewarn, and eerror messages are emailed to
> root.

I like that idea!

> There is a major flaw with the current implementation.  Namely, you
> get an email for _every_ invocation of einfo, ewarn, or error.

what about collection all einfo/ewarn/eerror output in an ENV variable 
(or in a temporary file) and send them in one mail to root after each 
stage of the emerge process (compile, install, ...)?

You will get this functionality, when your 'emergemail' function only 
collects the data (and does not send it at this time) and you enter a 
line 'trap sendallmsg EXIT' at the beginning of functions.sh. This will 
call the 'sendallmsg' function, when the shell, which executes 
'functions.sh', exits (which happens after each stage of the emerge 
process)
The new function 'sendallmsg' has to mail the collected einfos (like 
emergemail does it now).

Example (not tested!):
= snip ===================================================
trap sendallmsg EXIT
....
sendallmsg() {
	if [ -x /usr/sbin/sendmail ]; then
		echo -e "${MYMESSAGES}" | /usr/sbin/sendmail root
		unset MYMESSAGES
	else
		# don't you dare try to use ewarn here :)
		echo -e " ${WARN}*${NORMAL} the emergemail feature was unable to"
		echo -e " ${WARN}*${NORMAL} find /usr/sbin/sendmail.  You must have"
		echo -e " ${WARN}*${NORMAL} a Mail Transfer Agent (MTA) such as"
		echo -e " ${WARN}*${NORMAL} postfix, exim, ssmtp, etc. to use this"
		echo -e " ${WARN}*${NORMAL} feature."
	fi
}

emergemail() {
	SEVERITY=$1
	MESSAGE=$2
	if echo ${FEATURES} | grep -iq emergemail; then
		MYMESSAGES="${MYMESSAGES}\n${SEVERITY} ${MESSAGE}"
	fi
}

= snip ===================================================
The EXIT trap is not used by other scripts in /sbin/* and 
/usr/lib/portage/bin/*, so I hope, it is ok to set it in 
/sbin/functions.sh!

have fun!
Karsten


--
gentoo-dev@gentoo.org mailing list


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] patch: emergemail feature in functions.sh
  2003-08-19  6:50 ` Karsten Schulz
@ 2003-08-19  8:34   ` Owen Gunden
  2003-08-19 23:53   ` Owen Gunden
  1 sibling, 0 replies; 7+ messages in thread
From: Owen Gunden @ 2003-08-19  8:34 UTC (permalink / raw
  To: gentoo-dev

On Tue, Aug 19, 2003 at 08:50:43AM +0200, Karsten Schulz wrote:
> You will get this functionality, when your 'emergemail' function only 
> collects the data (and does not send it at this time) and you enter a 
> line 'trap sendallmsg EXIT' at the beginning of functions.sh. This will 
> call the 'sendallmsg' function, when the shell, which executes 
> 'functions.sh', exits (which happens after each stage of the emerge 
> process)

I didn't know about this.  I will definitely investigate, and thanks for
the tip!  But gotta get some sleep first :).

Owen

--
gentoo-dev@gentoo.org mailing list


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] patch: emergemail feature in functions.sh
  2003-08-19  5:37 [gentoo-dev] patch: emergemail feature in functions.sh Owen Gunden
                   ` (2 preceding siblings ...)
  2003-08-19  6:50 ` Karsten Schulz
@ 2003-08-19 13:05 ` Thomas de Grenier de Latour
  3 siblings, 0 replies; 7+ messages in thread
From: Thomas de Grenier de Latour @ 2003-08-19 13:05 UTC (permalink / raw
  To: gentoo-dev

On Tue, 19 Aug 2003 01:37:23 -0400
Owen Gunden <ogunden@stwing.upenn.edu> wrote:

> This is useful if you upgrade or install multiple packages at once,
> and you don't want to miss any important messages that go whizzing by.

Just in case it can be useful to someone, I've written a small script to
retrieve einfos in emerge log files (the ones in PORT_LOGDIR):

>>> "portlog-info" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#!/bin/bash
# Usage: "portlog-info [pkg-name]"

PORT_LOGDIR="`sed -n s:^PORT_LOGDIR=::p /etc/make.conf`"
if [ -d "${PORT_LOGDIR}" ]
then
	cd ${PORT_LOGDIR}
else
	echo "PORT_LOGDIR not found."
	exit 1
fi

for logfile in $( ls *$1* 2> /dev/null )
do 
	if [ 0 -ne "`cat -v ${logfile} | grep -c "^\ \^\[\[..;01m\*"`" ]
	then 
		echo -n "########## "
		echo -n ${logfile} | sed -e s:"^[0-9]*-":: -e s:".log$"::
		echo " ##########" 
		sed -n -e "
		/^\ \o033\[..;01m\*/{ 
		i
		p
		n
		:block
		/^\ \o033\[..;01m\*/{
		p
		n
		b block
		}
		}" ${logfile}
		echo
	fi
done
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Note that:
 - I've assumed that the logs have colors (NOCOLOR=false)
 - I'm not a sed guru and have written this with a sed manual in the
hands but I would be interrested by a shorter syntax for the "retrieve
blocks of consecutive matching lines and separate them by a blank line"

-- 
TGL.

--
gentoo-dev@gentoo.org mailing list


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-dev] patch: emergemail feature in functions.sh
  2003-08-19  6:50 ` Karsten Schulz
  2003-08-19  8:34   ` Owen Gunden
@ 2003-08-19 23:53   ` Owen Gunden
  1 sibling, 0 replies; 7+ messages in thread
From: Owen Gunden @ 2003-08-19 23:53 UTC (permalink / raw
  To: gentoo-dev

On Tue, Aug 19, 2003 at 08:50:43AM +0200, Karsten Schulz wrote:
> what about collection all einfo/ewarn/eerror output in an ENV variable 
> (or in a temporary file) and send them in one mail to root after each 
> stage of the emerge process (compile, install, ...)?

I took Karsten's advice and produced a new patch which doesn't have the
major limitation of my last one.  I've used it with a couple emerges
already and I'm totally hooked :).  See [1] for discussion and the patch.

Owen

References:
1. http://bugs.gentoo.org/show_bug.cgi?id=11359

--
gentoo-dev@gentoo.org mailing list


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-08-19 23:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-19  5:37 [gentoo-dev] patch: emergemail feature in functions.sh Owen Gunden
2003-08-19  5:44 ` Jon Portnoy
2003-08-19  5:54 ` Mike Frysinger
2003-08-19  6:50 ` Karsten Schulz
2003-08-19  8:34   ` Owen Gunden
2003-08-19 23:53   ` Owen Gunden
2003-08-19 13:05 ` Thomas de Grenier de Latour

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox