Skip to content

Commit 0c0c4ea

Browse files
committed
update search jobs to return type debug, error and warning
update the method of create config file now SWO send a notification in case of a config file already exists
1 parent f92bb99 commit 0c0c4ea

1 file changed

Lines changed: 31 additions & 8 deletions

File tree

swo.sh

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,38 @@ Help() {
2323
Switch Orchestrator
2424
Usage: swo [<args>]
2525
Arguments:
26-
-h | --help Display usage guide.
27-
-j | --job <JOBNUMBER> Search about a specific job.
26+
-h | --help Display usage guide.
27+
-c | --config Create config filep
28+
-a | --auth Get token from Switch dont forget the config file
29+
-j | --job <JOBNUMBER> Search about a specific job.
2830
switchOrchestrator loads configuration variables from:
2931
\$HOME/.config/switchOrchestrator/swo"
3032
exit 0
3133
}
3234

33-
install() {
34-
exec mkdir $SWITCH_CF_FOLDER
35+
createConf() {
36+
if [ ! -d "$SWITCH_CF_FOLDER" ]; then
37+
echo "Creating config folder in ${SWITCH_CF_FOLDER}..."
38+
exec mkdir $SWITCH_CF_FOLDER
39+
fi
40+
41+
cd $SWITCH_CF_FOLDER
42+
43+
if [ -f "$SWITCH_CF_FILE" ]; then
44+
echo "$SWITCH_CF_FILE exists."
45+
read -p "Are you sure that wanna replace your config? [Yy][Nn]" -n 1 -r
46+
if [[ $REPLY =~ [^Yy]$ ]]; then
47+
echo "Install failed"
48+
break
49+
fi
50+
cp $SWITCH_CF_FILE "${SWITCH_CF_FILE}_bkp"
51+
truncate -s 0 $SWITCH_CF_FILE
52+
fi
53+
54+
echo 'USER="XYZ"' >> $SWITCH_CF_FILE
55+
echo 'HASH_PASS="XXXXXXXXXXXXXXXX"' >> $SWITCH_CF_FILE
56+
echo 'SWITCH_IP="0.0.0.0"' >> $SWITCH_CF_FILE
57+
exit 0
3558
}
3659

3760
auth() {
@@ -53,14 +76,14 @@ auth() {
5376
}
5477

5578
searchJob() {
56-
JSON=$(curl -s --location --request GET "$SWITCH_ADR/api/v1/messages?type=info&message=$JOB_NUMBER&limit=100" -H 'Authorization: Bearer '$TOKEN)
79+
JSON=$(curl -s --location --request GET "$SWITCH_ADR/api/v1/messages?type=info&type=error&type=warning&type=debug&message=$JOB_NUMBER&limit=100" -H 'Authorization: Bearer '$TOKEN)
5780
status=$(jq '.status' <<< $JSON)
5881
if [ "$status" == "success" ]; then
5982
echo "Search failed"
6083
exit 1
6184
fi
6285
messages=$(jq '.messages' <<< $JSON)
63-
echo $messages | jq '[.[] | {timestamp,flow,job,element,message}] | sort_by(.timestamp)' | jtbl
86+
echo $messages | jq '[.[] | {type,flow,job,element,message,timestamp}] | sort_by(.timestamp)' | jtbl
6487
exit 0
6588
}
6689

@@ -95,8 +118,8 @@ if (($# > 0)); then
95118
auth
96119
shift
97120
;;
98-
-i | --install)
99-
install
121+
-c | --config)
122+
createConf
100123
;;
101124
-h | --help)
102125
Help

0 commit comments

Comments
 (0)