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_ |
| 8 | |
| 9 | usage: |
| 10 | $(basename $0) [node] ['old'] |
| 11 | |
| 12 | options: |
| 13 | - [node] : The node whose logs to inspect. The default is \$OCI. |
| 14 | - ['old'] : If 'old' is specified, the logs are simply searched for errors |
| 15 | and exceptions, and they are displayed. |
| 16 | |
| 17 | summary: |
| 18 | Checks the logs of the remote ONOS instance and makes sure they are clean. |
| 19 | |
| 20 | _EOM_ |
| 21 | } |
| 22 | |
| 23 | [ "$1" = "-h" ] && __usage && exit 0 |
| 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 | |
| 28 | remote=$ONOS_USER@${1:-$OCI} |
| 29 | |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 30 | LOG=$ONOS_INSTALL_DIR/log/karaf.log* |
tom | 82d6bde | 2014-09-23 17:33:58 -0700 | [diff] [blame] | 31 | |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 32 | aux=/tmp/log.$$ |
| 33 | |
| 34 | if [ "$2" = "old" ]; then |
| 35 | ssh $remote "egrep 'ERROR|Exception|Error' $LOG" |
| 36 | |
| 37 | else |
| 38 | ssh $remote " |
Ayaka Koshibe | bad156d | 2015-09-18 17:30:14 -0700 | [diff] [blame] | 39 | [ "'`uname`'" != "'"Linux"'" ] && alias tac='tail -r' |
Thomas Vachuska | 2ec5aa9 | 2016-08-31 13:30:31 -0700 | [diff] [blame] | 40 | tac $LOG | tr -d '\000' | awk ' |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 41 | BEGIN { off = 0; fail = 0; exclusion = 0; trace = \"\";} |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 42 | / org.apache.karaf.main.lock.SimpleFileLock lock/ { |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 43 | exit fail; |
| 44 | } |
| 45 | |
| 46 | / ERROR / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 47 | if (exception && !exclusion) { |
| 48 | print \$0; |
| 49 | exception = 0; |
| 50 | fail = 1; |
| 51 | } |
| 52 | exclusion = 0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 53 | } |
| 54 | / WARN / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 55 | if (exception && !exclusion) { |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 56 | print \$0; |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 57 | exception = 0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 58 | } |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 59 | exclusion = 0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 60 | } |
Thomas Vachuska | 2ec5aa9 | 2016-08-31 13:30:31 -0700 | [diff] [blame] | 61 | / INFO / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 62 | exception = 0; |
| 63 | exclusion = 0; |
Thomas Vachuska | 2ec5aa9 | 2016-08-31 13:30:31 -0700 | [diff] [blame] | 64 | } |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 65 | |
| 66 | /^[a-zA-Z0-9.]*(Exception|Error)/ { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 67 | if (!exclusion) { |
| 68 | print trace; |
| 69 | print \$0; |
| 70 | exception = 1; |
| 71 | fail = 1; |
| 72 | trace = \"\"; |
| 73 | } |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Thomas Vachuska | 2ec5aa9 | 2016-08-31 13:30:31 -0700 | [diff] [blame] | 76 | /( at|Caused by:) / { |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 77 | trace = trace \"\n\" \$0; |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 78 | } |
Thomas Vachuska | 128cffb | 2016-10-24 13:04:46 -0700 | [diff] [blame] | 79 | |
| 80 | # Sanctioned exclusions for exceptions in third-party code; one pattern per exclusion |
| 81 | /at org\.apache\.felix\.scr\.impl\.ComponentRegistry\.getComponents\(ComponentRegistry\.java:199\)/ { exclusion = 1; } |
| 82 | /at org\.apache\.karaf\.service\.guard\.impl\.GuardProxyCatalog.1.run\(GuardProxyCatalog\.java:253\)/ { exclusion = 1; } |
| 83 | |
Thomas Vachuska | 77a9a44 | 2015-05-19 17:35:52 -0700 | [diff] [blame] | 84 | END { exit fail; } |
| 85 | ' > $aux |
| 86 | status=\$? |
| 87 | tac $aux && rm $aux |
| 88 | exit \$status |
| 89 | " |
| 90 | fi |