diff --git a/scripts/show-changed b/scripts/show-changed new file mode 100755 index 0000000000..d62d70f5b7 --- /dev/null +++ b/scripts/show-changed @@ -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 + +