Implement time stamp and improve reporter syntax.

The directory access time used so far is modified on every
ansible run and independent of the ansible module/playbook.
This commit is contained in:
Andreas B. Mundt 2024-01-16 11:54:45 +01:00
parent 5ed4c2a135
commit aa8bc09ce6
4 changed files with 25 additions and 13 deletions

View file

@ -11,11 +11,11 @@ logdir="/tmp/collector"
mkdir -vp "$logdir"
nc -k -l -u -p "$port" | while read line ; do
sndr="${line%%:*}"
msg="${line#*: }"
sndr="${line%% *}"
msg="${line#* }"
if [[ "$sndr" =~ [a-z0-9]+ ]] ; then
if [[ "$msg" =~ ^-------\ .+\ -------$ ]] ; then
echo "$(date --rfc-3339=seconds) → Message from '$sndr' received."
echo "$(date --rfc-3339=seconds) → Report from '$sndr' received."
echo "$msg" > "$logdir/$sndr"
else
echo "$msg" >> "$logdir/$sndr"

View file

@ -29,14 +29,14 @@ find_outdated(){
while IFS= read -r -d '' file ; do
running=$(( running + 1 ))
$debug && echo -n "Processing host '$file' with IP address "
d="$(sed -nE "s/\s+drwx.+([0-9]{4}-[0-9]{2}-[0-9]{2} \S+).*/\1/p" "$file" | head -1)"
if [[ -z "$d" ]] || [[ $(date --date="$d" +%s) -lt $(date --date="$git_date" +%s) ]] ; then
d="$(sed -nE "s/^2\s+(\S.+)$/\1/p" "$file")"
if [[ -z "$d" ]] || \
[[ $(date --date="$d" +%s) -lt $(date --date="$git_date" +%s) ]] ; then
r='([0-9]{1,3}\.){3}[0-9]{1,3}'
ipa="$(sed -nE "s|^\s+default via.+ src ($r) metric.+|\1|p" "$file" | head -1)"
ipa="$(sed -nE "s/^3\s+default via.+ src ($r) metric.+/\1/p" "$file")"
if [[ -z "$ipa" ]] ; then
# FIXME: Outdated report format, trying fallback:
ipa="$(grep -E "\s+2: en" -A3 "$file" | \
sed -nE "s|.+inet (10\.190\.[[:digit:]]{1,3}\.[[:digit:]]{1,3})/.+|\1|p")"
# FIXME: Outdated report format, try fallback:
ipa="$(sed -nE "s|^.+default via.+ src ($r) metric.+|\1|p" "$file" | head -1)"
fi
$debug && echo "'$ipa'."
if ! grep -q "$ipa" "$dir/${git_date//T*/}" ; then