Files
NetworkManager/contrib/scripts/NM-log
Thomas Haller 7573594a21 platform: merge nm_platform_*_delete() delete functions
It only makes sense to call delete() with NMPObjects that
we obtained from the platform cache. Otherwise, if we didn't
get it from the cache in the first place, we wouldn't know
what to delete.

Hence, the input argument is (almost) always an NMPObject
in the first place. That is different from add(), where
we might create a new specific NMPlatform* instance on the
stack. For add() it makes slightly more sense to have different
functions depending on the type. For delete(), it doesn't.
2017-12-11 10:30:26 +01:00

69 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# Util to pretty-print logfile of NetworkManager
#
# Unless setting NM_LOG_NO_COLOR it will colorize the output.
# Suppress coloring with:
# $ NM_LOG_NO_COLOR=1 NM-log ...
#
# If called without arguments, it either reads from stdin (if not
# connected to a terminal) or it shows the journal content.
#
# If called with first argument "j", it always shows the journal content.
#
# You can pass multiple filenames.
if [[ "$_" == "$0" ]]; then
NM_not_sourced=1
else
unset NM_not_sourced
fi
NM-show-journal() {
local since="$(systemctl show NetworkManager | sed -n 's/^ExecMainStartTimestamp=\(.*\) [A-Z0-9]\+$/\1/p')"
if [[ "$since" == "" ]]; then
echo "error detecting NM. Is it running?"
systemctl status NetworkManager
else
journalctl -o short-precise --since "$since" -b 0 -u NetworkManager "$@"
fi
}
NM-colorize() {
if [[ "$NM_LOG_NO_COLOR" == "" ]]; then
# poor man's coloring using grep.
# TODO: do it somehow better (and more efficient).
sed 's/\r$//' | \
GREP_COLOR='01;31' grep -a --color=always '^\|^\(.* \)\?<\(warn> \|error>\) \[[0-9.]*\]' | \
GREP_COLOR='01;33' grep -a --color=always '^\|^\(.* \)\?<info> \[[0-9.]*\]\( .*\<is starting\>.*$\)\?' | \
GREP_COLOR='01;37' grep -a --color=always '^\|\<platform: signal: .*$' | \
GREP_COLOR='01;34' grep -a --color=always '^\|\<platform\(-linux\)\?: link: \(add\|adding\|change\|setting\|deleting\) \|\<platform: address: \(deleting\|adding or updating\) IPv. address:\? \|\<platform: \(route\|ip4-route\|ip6-route\|qdisc\|tfilter\): \([a-z]\+\|adding or updating\|new\[0x[0-9A-Za-z]*\]\) \|\<platform-linux: sysctl: setting ' | \
GREP_COLOR='01;35' grep -a --color=always '^\|\<audit: .*$' | \
GREP_COLOR='01;32' grep -a --color=always '^\|\<device (.*): state change: '
else
/usr/bin/cat -
fi
}
NM-log() {
(
if [ "$1" == "j" ]; then
shift
NM-show-journal "$@"
elif [ "$#" -eq 0 -a -t 0 ]; then
NM-show-journal
else
a="${1--}"
shift
/usr/bin/less "$a" "$@"
fi
) | \
NM-colorize | \
LESS=FRSXM less -R
}
if [[ "$NM_not_sourced" != "" ]]; then
NM-log "$@"
fi