Changeset 866 for trunk/Monitoring/script/libIGCM_mock.sh
- Timestamp:
- 06/09/13 23:52:36 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Monitoring/script/libIGCM_mock.sh
r854 r866 12 12 ################################## 13 13 14 # Notes 15 # - bash required version: 3+ 16 # - "=" and " " are used as delimiter in scenario file (be sure note to use it in fields data) 17 18 # init 19 14 20 stack_file=$1 15 send_msg="/home/jripsl/snapshot/Monitoring/CNClient/sendAMQPMsg" 21 send_msg_cmd="/home/jripsl/snapshot/Monitoring/CNClient/sendAMQPMsg" 22 scenario_dir=scenario 23 g__mode="scenario" 24 g__stackfile= 25 g__scenario_file= 16 26 17 if [ $# -lt 1 ]; then 18 echo "Usage $0 ../sample/stack_light" 27 # func 28 29 curdate () 30 { 31 date '+%F %T' 32 } 33 34 msg () 35 { 36 l__code="$1" 37 l__msg="$2" 38 39 echo "$(curdate) - $l__code - $l__msg" 40 } 41 42 usage () 43 { 44 cat >&1 << EOF 45 46 USAGE: $(basename $0) [-m mode] [-s scenario] [-l] [-t file] 47 48 OPTIONS: 49 -f set stack file 50 -l print scenarios list 51 -m set mode (if missing, "scenario" mode is used) 52 -s set scenario 53 54 EXAMPLES: 55 56 To parse a stack file and send corressponding messages, do: 57 58 $0 -m stackfile -f ../sample/stack_light 59 60 To list scenarios, do: 61 62 $0 -l 63 64 To run scenario <scenario>, do: 65 66 $0 -s <scenario> 67 EOF 68 exit 2 69 } 70 71 list_scenarios () 72 { 73 echo "" 74 echo "Scenarios list:" 75 echo "" 76 ls -1 $scenario_dir 77 echo "" 78 exit 2 79 } 80 81 # check 82 83 if [ $# -eq 0 ]; then 84 usage 85 fi 86 87 # parse args 88 89 while getopts 'f:hlm:s:' OPTION 90 do 91 case $OPTION in 92 f) g__stackfile="$OPTARG" 93 ;; 94 h) usage 95 ;; 96 l) list_scenarios 97 ;; 98 m) g__mode="$OPTARG" 99 ;; 100 s) l__scenario_file="$OPTARG" 101 102 if [[ "$l__scenario_file" =~ "*/*" ]]; then 103 # full/relative path was given with the filename 104 105 g__scenario_file="$l__scenario_file" 106 else 107 # only the filename was given 108 109 g__scenario_file="$scenario_dir/$l__scenario_file" 110 fi 111 112 ;; 113 ?) exit 1 # we come here when a required option argument is missing (bash getopts mecanism) 114 ;; 115 esac 116 done 117 118 # mode switch 119 if [ "$g__mode" = "scenario" ]; then 120 121 # check 122 if [ ! -f "$g__scenario_file" ]; then 123 msg "LIBIGCM-MOCK-ERR003" "scenario file not found" 124 exit 1 125 fi 126 127 N=0 128 while read LINE ; do 129 130 N=$((N+1)) 131 132 l__JSON_msg_buf= 133 134 # process fields (split on " " delimiter) 135 for field in "$LINE"; do 136 arr=(${LINE//=/ }) # process key/value (split on "=" delimiter) 137 key=${arr[0]} 138 val=${arr[1]} 139 140 # base64 encoding 141 142 # append to JSON message buffer 143 l__JSON_msg_buf=$l__JSON_msg_buf 144 145 done 146 147 # message base64 encoding 148 149 150 #callname=$(echo $line | awk -F" " '{print $4}' ) 151 152 # send AMQP message 153 #$send_msg_cmd localhost 5672 string "$callname" 154 echo 155 156 done < $g__scenario_file 157 158 elif [ "$g__mode" = "stackfile" ]; then 159 160 # check 161 if [ ! -f $stack_file ]; then 162 msg "LIBIGCM-MOCK-ERR001" "file not found" 163 exit 1 164 fi 165 166 IFS=$'\n' 167 for line in $(cat $stack_file); do 168 #echo $line | awk -F" " '{print $4}' 169 callname=$(echo $line | awk -F" " '{print $4}' ) 170 $send_msg_cmd localhost 5672 string "$callname" 171 done 172 else 173 msg "LIBIGCM-MOCK-ERR002" "incorrect mode" 19 174 exit 1 20 175 fi 21 176 22 IFS=$'\n' 23 for line in $(cat $stack_file); do 24 #echo $line | awk -F" " '{print $4}' 25 callname=$(echo $line | awk -F" " '{print $4}' ) 26 $send_msg localhost 5672 string "$callname" 27 done 177 exit 0
Note: See TracChangeset
for help on using the changeset viewer.