show-changed events in any given day or playbook run or set of runs
This commit is contained in:
parent
f4549c7a90
commit
fbedc5fb60
1 changed files with 71 additions and 0 deletions
71
scripts/show-changed
Executable file
71
scripts/show-changed
Executable file
|
@ -0,0 +1,71 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# view the ansible logs
|
||||||
|
# takes all the options of grep and passes them straight through - then parses the output so it looks better and readable
|
||||||
|
# should only be used on the .log files not the .info files. info files are flat readable
|
||||||
|
# example:
|
||||||
|
# show-changed -v today mirrorlist
|
||||||
|
|
||||||
|
|
||||||
|
logpath='/var/log/ansible'
|
||||||
|
search_terms="CHANGED|FAILED"
|
||||||
|
|
||||||
|
|
||||||
|
function search_logs ()
|
||||||
|
{
|
||||||
|
IFS='
|
||||||
|
'
|
||||||
|
|
||||||
|
for line in `grep -H -E $search_terms $@`
|
||||||
|
do
|
||||||
|
logpath=`echo $line| cut -d: -f1`
|
||||||
|
hostname=`basename $logpath`
|
||||||
|
dir=`dirname $logpath`
|
||||||
|
runtime=`basename $dir`
|
||||||
|
echo -n "$runtime - $hostname "
|
||||||
|
echo $line | cut -d: -f2-| cut -f3-4
|
||||||
|
json=`echo $line | cut -d: -f2- |cut -f5-`
|
||||||
|
echo $json| python -m json.tool 2>/dev/null >&2
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
echo "Error parsing json"
|
||||||
|
else
|
||||||
|
if [ "$verbose" == 'yes' ]; then
|
||||||
|
echo $json| python -m json.tool
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts ":v" opt; do
|
||||||
|
case $opt in
|
||||||
|
v)
|
||||||
|
export verbose='yes'
|
||||||
|
;;
|
||||||
|
\?)
|
||||||
|
echo "Invalid option: -$OPTARG" >&2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
shift $(( OPTIND - 1 ));
|
||||||
|
|
||||||
|
when='yesterday'
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
when=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ts=`date -d "$when" +%Y/%m/%d`
|
||||||
|
|
||||||
|
if [ -z "$2" ]; then
|
||||||
|
where='*'
|
||||||
|
else
|
||||||
|
where=$2
|
||||||
|
fi
|
||||||
|
|
||||||
|
for pb in $logpath/$where/; do
|
||||||
|
if [ -d $pb/$ts ]; then
|
||||||
|
search_logs $pb/$ts/*/*.log
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue