Implement events logging feature

Record events (i.e. pluginhook's calls) as syslog entries and
provide a shortcut command to display the last part of the log
file.

A brief summary of the changes follows:

dokku:
 - New DOKKU_EVENTS_LOGFILE envvar to hold logfile location.

plugins/20_events/commands:
 - events output log entries, a tail's follow-like mode is
   provided too.
 - events:[on|off] enables/disables logging.
 - events:list lists events that are logged.

plugins/20_events/hook:
 - Generic hook that writes log entries. All the events are
   registered via symlink to this script.

plugins/common/functions:
 - dokku_log_event() writes log entries via logger.
 - dokku_log_pluginhook_call() formats log entries and writes
   them via dokku_log_event().
This commit is contained in:
Alessio Treglia
2015-06-26 13:14:04 +01:00
parent 48eca101f1
commit 783bb02b2c
33 changed files with 120 additions and 0 deletions

2
dokku
View File

@@ -10,6 +10,8 @@ export PLUGIN_PATH=${PLUGIN_PATH:="/var/lib/dokku/plugins"}
export DOKKU_NOT_IMPLEMENTED_EXIT=10
export DOKKU_VALID_EXIT=0
export DOKKU_EVENTS_LOGFILE=${DOKKU_EVENTS_LOGFILE:="/var/log/dokku.log"}
source "$PLUGIN_PATH/common/functions"
[[ -f $DOKKU_ROOT/dokkurc ]] && source $DOKKU_ROOT/dokkurc

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

54
plugins/20_events/commands Executable file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"
find "$l_plugin_dir" -type l -printf "%f " | sort
case "$1" in
events)
if [[ -f $DOKKU_EVENTS_LOGFILE ]] ; then
if [[ $2 == "-t" ]]; then
tail -f $DOKKU_EVENTS_LOGFILE
else
tail -n 100 $DOKKU_EVENTS_LOGFILE
fi
fi
;;
events:on)
echo "Enabling dokku events logger"
[[ -d $DOKKU_ROOT/.dokkurc ]] || mkdir -p $DOKKU_ROOT/.dokkurc
echo "export DOKKU_EVENTS=1" > $DOKKU_ROOT/.dokkurc/DOKKU_EVENTS
;;
events:off)
echo "Disabling dokku events logger"
rm -f $DOKKU_ROOT/.dokkurc/DOKKU_EVENTS
;;
events:list)
if [[ "$DOKKU_EVENTS" ]]; then
dokku_col_log_info2_quiet "Events currently logged"
for hook in $(find $(dirname $0) -type l -printf "%f " | sort) ; do
dokku_col_log_msg "$hook"
done
else
dokku_log_warn "Events logger disabled"
fi
;;
help | events:help)
cat && cat<<EOF
events [-t] Show the last events (-t follows)
events:list List logged events
events:on Enable events logger
events:off Disable events logger
EOF
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

5
plugins/20_events/hook Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"
[[ ! "$DOKKU_EVENTS" ]] || dokku_log_pluginhook_call "$(basename $0)" $@

20
plugins/20_events/install Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"
if [[ ! -f "$DOKKU_EVENTS_LOGFILE" ]]; then
touch "$DOKKU_EVENTS_LOGFILE"
# chown syslog:root might not work on SUSE
chown syslog:dokku "$DOKKU_EVENTS_LOGFILE"
chmod 664 "$DOKKU_EVENTS_LOGFILE"
fi
if [[ ! -f "$DOKKU_RSYSLOG_FILTER" ]]; then
cat >"$DOKKU_RSYSLOG_FILTER" <<EOF
:syslogtag, contains, "dokku" $DOKKU_EVENTS_LOGFILE
EOF
service rsyslog reload
[[ "$DOKKU_EVENTS" ]] && dokku_log_pluginhook_call "$(basename $0)" $@
exit 0

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

View File

@@ -0,0 +1 @@
hook

1
plugins/20_events/update Symbolic link
View File

@@ -0,0 +1 @@
hook

View File

@@ -90,6 +90,17 @@ dokku_log_fail() {
exit 1
}
dokku_log_event() {
logger -t dokku -i -- $@
}
dokku_log_pluginhook_call() {
local l_hook
l_hook="$1" ; shift
dokku_log_event "INVOKED: ${l_hook}( $@ )"
}
dokku_container_log_verbose_quiet() {
CID=$1;
shift