Michele Santuari | 02918e5 | 2017-06-06 16:36:25 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Checks the logs of the local ONOS instance and makes sure they are clean. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | function __usage() { |
| 7 | cat << _EOM_ |
| 8 | usage: $(basename $0) [--old|--ignore-store-exceptions] [node] |
| 9 | |
| 10 | options: |
| 11 | --ignore-store-exceptions |
| 12 | if specified, any store service exceptions are ignored |
| 13 | --old |
| 14 | if specified, the entire logs are searched for errors and exceptions; |
| 15 | otherwise logs are scanned only from the last server start-up |
| 16 | |
| 17 | node the cluster node whose logs to inspect; default is \$OCI |
| 18 | |
| 19 | summary: |
| 20 | Checks the logs of the remote ONOS instance and makes sure they are clean. |
| 21 | |
| 22 | _EOM_ |
| 23 | } |
| 24 | |
| 25 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 26 | . $ONOS_ROOT/tools/build/envDefaults |
| 27 | |
| 28 | # Process options |
| 29 | while [ -z $opts ] ; do |
| 30 | case "$1" in |
| 31 | --ignore-store-exceptions) export ise=1; shift;; |
| 32 | --old) export allLogs=1; shift;; |
| 33 | --*) __usage && exit 1;; |
| 34 | -h) __usage && exit 0;; |
| 35 | *) export opts=1;; |
| 36 | esac |
| 37 | done |
| 38 | |
| 39 | remote=$ONOS_USER@${1:-$OCI} |
| 40 | |
| 41 | LOG=/tmp/onos-$ONOS_POM_VERSION/apache-karaf-$KARAF_VERSION/data/log/karaf.log* |
| 42 | |
| 43 | aux=/tmp/log.$$ |
| 44 | |
| 45 | if [ -n "$allLogs" ]; then |
| 46 | egrep 'ERROR|Exception|Error' $LOG |
| 47 | |
| 48 | else |
| 49 | [ "uname" != 'Linux' ] && alias tac='tail -r' |
| 50 | tac $LOG | tr -d '\000' | awk -v ignoreStoreExceptions=${ise:-0} ' |
| 51 | BEGIN { off = 0; fail = 0; exclusion = 0; expected = 0; trace = "";} |
| 52 | / org.apache.karaf.main.lock.SimpleFileLock lock/ { |
| 53 | exit fail; |
| 54 | } |
| 55 | |
| 56 | # note: we are parsing log in reverse from the end |
| 57 | / EXPECTING_EXCEPTION_BEGIN/ { |
| 58 | print $0; |
| 59 | expected = 0; |
| 60 | } |
| 61 | |
| 62 | / EXPECTING_EXCEPTION_END/ { |
| 63 | print $0; |
| 64 | expected = 1; |
| 65 | } |
| 66 | |
| 67 | / ERROR / { |
| 68 | if (exception && !exclusion) { |
| 69 | print $0; |
| 70 | exception = 0; |
| 71 | |
| 72 | if (!expected) { |
| 73 | fail = 1; |
| 74 | } |
| 75 | } |
| 76 | exclusion = 0; |
| 77 | } |
| 78 | / WARN / { |
| 79 | if (exception && !exclusion) { |
| 80 | print $0; |
| 81 | exception = 0; |
| 82 | } |
| 83 | exclusion = 0; |
| 84 | } |
| 85 | / INFO / { |
| 86 | exception = 0; |
| 87 | exclusion = 0; |
| 88 | } |
| 89 | |
| 90 | # Sanctioned exclusions for exceptions in the distributed stores; one pattern per exclusion |
| 91 | /org\.onosproject\.store\.service\..*Exception/ { exclusion = ignoreStoreExceptions; } |
| 92 | |
| 93 | /^[a-zA-Z0-9.]*(Exception|Error)/ { |
| 94 | if (!exclusion) { |
| 95 | print trace; |
| 96 | print $0; |
| 97 | exception = 1; |
| 98 | if (!expected) { |
| 99 | fail = 1; |
| 100 | } |
| 101 | trace = ""; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /( at|Caused by:) / { |
| 106 | trace = trace "\n" $0; |
| 107 | } |
| 108 | |
| 109 | # Sanctioned exclusions for exceptions in third-party code; one pattern per exclusion |
| 110 | /at org\.apache\.felix\.scr\.impl\.ComponentRegistry\.getComponents\(ComponentRegistry\.java:199\)/ { exclusion = 1; } |
| 111 | /at org\.apache\.karaf\.service\.guard\.impl\.GuardProxyCatalog.1.run\(GuardProxyCatalog\.java:253\)/ { exclusion = 1; } |
| 112 | |
| 113 | END { exit fail; } |
| 114 | ' > $aux |
| 115 | status=$? |
| 116 | tac $aux && rm $aux |
| 117 | exit $status |
| 118 | fi |