tom | 82d6bde | 2014-09-23 17:33:58 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 2 | # ----------------------------------------------------------------------------- |
tom | 82d6bde | 2014-09-23 17:33:58 -0700 | [diff] [blame] | 3 | # Checks the logs of the remote ONOS instance and makes sure they are clean. |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 4 | # ----------------------------------------------------------------------------- |
tom | 82d6bde | 2014-09-23 17:33:58 -0700 | [diff] [blame] | 5 | |
Ayaka Koshibe | bad156d | 2015-09-18 17:30:14 -0700 | [diff] [blame] | 6 | function __usage() { |
| 7 | cat << _EOM_ |
Thomas Vachuska | 27ece8f | 2016-11-11 10:03:11 -0800 | [diff] [blame] | 8 | usage: $(basename $0) [--old|--ignore-store-exceptions] [node] |
Ayaka Koshibe | bad156d | 2015-09-18 17:30:14 -0700 | [diff] [blame] | 9 | |
| 10 | options: |
Thomas Vachuska | 27ece8f | 2016-11-11 10:03:11 -0800 | [diff] [blame] | 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 |
Ayaka Koshibe | bad156d | 2015-09-18 17:30:14 -0700 | [diff] [blame] | 18 | |
| 19 | summary: |
| 20 | Checks the logs of the remote ONOS instance and makes sure they are clean. |
| 21 | |
| 22 | _EOM_ |
| 23 | } |
| 24 | |
tom | 82d6bde | 2014-09-23 17:33:58 -0700 | [diff] [blame] | 25 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 26 | . $ONOS_ROOT/tools/build/envDefaults |
| 27 | |
Thomas Vachuska | 27ece8f | 2016-11-11 10:03:11 -0800 | [diff] [blame] | 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 | |
tom | 82d6bde | 2014-09-23 17:33:58 -0700 | [diff] [blame] | 39 | remote=$ONOS_USER@${1:-$OCI} |
| 40 | |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 41 | LOG=$ONOS_INSTALL_DIR/log/karaf.log* |
tom | 82d6bde | 2014-09-23 17:33:58 -0700 | [diff] [blame] | 42 | |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 43 | aux=/tmp/log.$$ |
| 44 | |
Thomas Vachuska | 27ece8f | 2016-11-11 10:03:11 -0800 | [diff] [blame] | 45 | if [ -n "$allLogs" ]; then |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 46 | ssh $remote "egrep 'ERROR|Exception|Error' $LOG" |
| 47 | |
| 48 | else |
| 49 | ssh $remote " |
Ayaka Koshibe | bad156d | 2015-09-18 17:30:14 -0700 | [diff] [blame] | 50 | [ "'`uname`'" != "'"Linux"'" ] && alias tac='tail -r' |
Thomas Vachuska | 27ece8f | 2016-11-11 10:03:11 -0800 | [diff] [blame] | 51 | tac $LOG | tr -d '\000' | awk -v ignoreStoreExceptions=${ise:-0} ' |
Yuta HIGUCHI | df5eeb1 | 2017-05-05 21:19:02 -0700 | [diff] [blame] | 52 | BEGIN { off = 0; fail = 0; exclusion = 0; expected = 0; trace = \"\";} |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 53 | / org.apache.karaf.main.lock.SimpleFileLock lock/ { |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 54 | exit fail; |
| 55 | } |
| 56 | |
Yuta HIGUCHI | df5eeb1 | 2017-05-05 21:19:02 -0700 | [diff] [blame] | 57 | # note: we are parsing log in reverse from the end |
| 58 | / EXPECTING_EXCEPTION_BEGIN/ { |
| 59 | print \$0; |
| 60 | expected = 0; |
| 61 | } |
| 62 | |
| 63 | / EXPECTING_EXCEPTION_END/ { |
| 64 | print \$0; |
| 65 | expected = 1; |
| 66 | } |
| 67 | |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 68 | / ERROR / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 69 | if (exception && !exclusion) { |
| 70 | print \$0; |
| 71 | exception = 0; |
Yuta HIGUCHI | df5eeb1 | 2017-05-05 21:19:02 -0700 | [diff] [blame] | 72 | |
| 73 | if (!expected) { |
| 74 | fail = 1; |
| 75 | } |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 76 | } |
| 77 | exclusion = 0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 78 | } |
| 79 | / WARN / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 80 | if (exception && !exclusion) { |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 81 | print \$0; |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 82 | exception = 0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 83 | } |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 84 | exclusion = 0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 85 | } |
Thomas Vachuska | 2ec5aa9 | 2016-08-31 13:30:31 -0700 | [diff] [blame] | 86 | / INFO / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 87 | exception = 0; |
| 88 | exclusion = 0; |
Thomas Vachuska | 2ec5aa9 | 2016-08-31 13:30:31 -0700 | [diff] [blame] | 89 | } |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 90 | |
Thomas Vachuska | 27ece8f | 2016-11-11 10:03:11 -0800 | [diff] [blame] | 91 | # Sanctioned exclusions for exceptions in the distributed stores; one pattern per exclusion |
| 92 | /org\.onosproject\.store\.service\..*Exception/ { exclusion = ignoreStoreExceptions; } |
| 93 | |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 94 | /^[a-zA-Z0-9.]*(Exception|Error)/ { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 95 | if (!exclusion) { |
| 96 | print trace; |
| 97 | print \$0; |
| 98 | exception = 1; |
Yuta HIGUCHI | df5eeb1 | 2017-05-05 21:19:02 -0700 | [diff] [blame] | 99 | if (!expected) { |
| 100 | fail = 1; |
| 101 | } |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 102 | trace = \"\"; |
| 103 | } |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Thomas Vachuska | 2ec5aa9 | 2016-08-31 13:30:31 -0700 | [diff] [blame] | 106 | /( at|Caused by:) / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 107 | trace = trace \"\n\" \$0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 108 | } |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 109 | |
| 110 | # Sanctioned exclusions for exceptions in third-party code; one pattern per exclusion |
Thomas Vachuska | 09fee5f | 2018-10-31 15:23:20 -0700 | [diff] [blame] | 111 | /at org\.apache\.felix\.scr\.impl\.ComponentRegistry\.getComponentHolders\(ComponentRegistry\.java:356\)/ { exclusion = 1; } |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 112 | /at org\.apache\.karaf\.service\.guard\.impl\.GuardProxyCatalog.1.run\(GuardProxyCatalog\.java:253\)/ { exclusion = 1; } |
Ray Milkey | c7e3163 | 2019-01-02 20:33:34 +0000 | [diff] [blame] | 113 | /at org\.apache\.sshd\.server\.SshServer\.start/ { exclusion = 1; } |
Ray Milkey | 887c1ca | 2019-02-12 16:55:49 -0800 | [diff] [blame] | 114 | /at org\.apache\.felix\.scr\.impl\.ComponentRegistry\.getComponentHolders/ { exclusion = 1; } |
Ray Milkey | bde9b39 | 2019-03-14 10:48:10 -0700 | [diff] [blame] | 115 | /at org\.apache\.felix\.framework\.Felix/ { exclusion = 1; } |
Ray Milkey | 5f5db1f | 2020-01-31 16:25:57 -0800 | [diff] [blame] | 116 | /at org\.apache\.karaf\.util\.tracker\.BaseActivator\.getTrackedService/ { exclusion = 1; } |
| 117 | |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 118 | |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 119 | END { exit fail; } |
| 120 | ' > $aux |
| 121 | status=\$? |
| 122 | tac $aux && rm $aux |
| 123 | exit \$status |
| 124 | " |
| 125 | fi |