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} ' |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 52 | BEGIN { off = 0; fail = 0; exclusion = 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 | |
| 57 | / ERROR / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 58 | if (exception && !exclusion) { |
| 59 | print \$0; |
| 60 | exception = 0; |
| 61 | fail = 1; |
| 62 | } |
| 63 | exclusion = 0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 64 | } |
| 65 | / WARN / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 66 | if (exception && !exclusion) { |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 67 | print \$0; |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 68 | exception = 0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 69 | } |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 70 | exclusion = 0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 71 | } |
Thomas Vachuska | 2ec5aa9 | 2016-08-31 13:30:31 -0700 | [diff] [blame] | 72 | / INFO / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 73 | exception = 0; |
| 74 | exclusion = 0; |
Thomas Vachuska | 2ec5aa9 | 2016-08-31 13:30:31 -0700 | [diff] [blame] | 75 | } |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 76 | |
Thomas Vachuska | 27ece8f | 2016-11-11 10:03:11 -0800 | [diff] [blame^] | 77 | # Sanctioned exclusions for exceptions in the distributed stores; one pattern per exclusion |
| 78 | /org\.onosproject\.store\.service\..*Exception/ { exclusion = ignoreStoreExceptions; } |
| 79 | |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 80 | /^[a-zA-Z0-9.]*(Exception|Error)/ { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 81 | if (!exclusion) { |
| 82 | print trace; |
| 83 | print \$0; |
| 84 | exception = 1; |
| 85 | fail = 1; |
| 86 | trace = \"\"; |
| 87 | } |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Thomas Vachuska | 2ec5aa9 | 2016-08-31 13:30:31 -0700 | [diff] [blame] | 90 | /( at|Caused by:) / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 91 | trace = trace \"\n\" \$0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 92 | } |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 93 | |
| 94 | # Sanctioned exclusions for exceptions in third-party code; one pattern per exclusion |
| 95 | /at org\.apache\.felix\.scr\.impl\.ComponentRegistry\.getComponents\(ComponentRegistry\.java:199\)/ { exclusion = 1; } |
| 96 | /at org\.apache\.karaf\.service\.guard\.impl\.GuardProxyCatalog.1.run\(GuardProxyCatalog\.java:253\)/ { exclusion = 1; } |
| 97 | |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 98 | END { exit fail; } |
| 99 | ' > $aux |
| 100 | status=\$? |
| 101 | tac $aux && rm $aux |
| 102 | exit \$status |
| 103 | " |
| 104 | fi |