source: trunk/Monitoring/script/libIGCM_mock.sh @ 866

Last change on this file since 866 was 866, checked in by jripsl, 11 years ago

Add demo scenarios.

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#!/bin/bash
2
3##################################
4#  @program        smon
5#  @description    simulation monitor
6#  @copyright      Copyright “(c)2009 Centre National de la Recherche Scientifique CNRS.
7#                             All Rights Reserved”
8#  @svn_file       $Id: failover 2545 2013-02-01 09:58:10Z jripsl $
9#  @version        $Rev: 2545 $
10#  @lastrevision   $Date: 2013-02-01 10:58:10 +0100 (Fri, 01 Feb 2013) $
11#  @license        CeCILL (http://dods.ipsl.jussieu.fr/jripsl/smon/LICENSE)
12##################################
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
20stack_file=$1
21send_msg_cmd="/home/jripsl/snapshot/Monitoring/CNClient/sendAMQPMsg"
22scenario_dir=scenario
23g__mode="scenario"
24g__stackfile=
25g__scenario_file=
26
27# func
28
29curdate ()
30{
31    date '+%F %T'
32}
33
34msg ()
35{
36    l__code="$1"
37    l__msg="$2"
38
39    echo "$(curdate) - $l__code - $l__msg"
40}
41
42usage ()
43{
44        cat >&1 << EOF
45
46USAGE: $(basename $0) [-m mode] [-s scenario] [-l] [-t file]
47
48OPTIONS:
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
54EXAMPLES:
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>
67EOF
68        exit 2
69}
70
71list_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
83if [ $# -eq 0 ]; then
84        usage
85fi
86
87# parse args
88
89while getopts 'f:hlm:s:' OPTION
90do
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
116done
117
118# mode switch
119if [ "$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
158elif [ "$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
172else
173        msg "LIBIGCM-MOCK-ERR002" "incorrect mode"
174        exit 1
175fi
176
177exit 0
Note: See TracBrowser for help on using the repository browser.