-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·76 lines (69 loc) · 2.14 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Example Usage
# ./run.sh --frequency 10 --debug true --sendopsgenie false --configfilename config.json.demo
frequency=${frequency:-30}
debug=${debug:-true}
sendopsgenie=${sendopsgenie:-false}
sendpagerduty=${sendpagerduty:-false}
configfilename=${configfilename:-config.json}
# credits - https://brianchildress.co/named-parameters-in-bash/
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
param="${1/--/}"
declare $param="$2"
# echo $1 $2 // Optional to see the parameter:value result
fi
shift
done
if [[ "$debug" == "true" ]]; then
debug="--debug"
else
debug=""
fi
# if want to send to pagerduty then validate the the url and opsgenie
if [[ "$sendpagerduty" == "true" ]]; then
CREDS_FILE=creds.json
if ! [ -f "$CREDS_FILE" ]; then
echo "ERROR: missing $CREDS_FILE"
exit 1
fi
sendpagerduty="--sendpagerduty"
PAGERDUTY_API_URL="--pdurl $(cat $CREDS_FILE | jq -r '.PAGERDUTY_API_URL')"
PAGERDUTY_INTEGRATION_KEY="--pdkey $(cat $CREDS_FILE | jq -r '.PAGERDUTY_INTEGRATION_KEY')"
else
sendpagerduty=""
fi
# if want to send to opsgenie then validate the the url and opsgenie
if [[ "$sendopsgenie" == "true" ]]; then
CREDS_FILE=creds.json
if ! [ -f "$CREDS_FILE" ]; then
echo "ERROR: missing $CREDS_FILE"
exit 1
fi
sendopsgenie="--sendopsgenie"
OPSGENIE_API_URL="--ogurl $(cat $CREDS_FILE | jq -r '.OPSGENIE_API_URL')"
OPSGENIE_API_TOKEN="--ogtoken $(cat $CREDS_FILE | jq -r '.OPSGENIE_API_TOKEN')"
else
sendopsgenie=""
fi
echo "================================================="
echo "running monitor"
echo ""
echo "LOOP FREQUENCY : $frequency"
echo "DEBUG SETTING : $debug"
echo "SEND OPSGENIE SETTING : $sendopsgenie"
echo "SEND PAGERDUTY SETTING : $sendpagerduty"
echo "OPSGENIE API_URL : $OPSGENIE_API_URL"
echo "PAGERDUTY_API_URL : $PAGERDUTY_API_URL"
echo "MONITORS CONFIG FILE : $configfilename"
echo "================================================="
python3 monitoring.py \
-f $frequency \
-c $configfilename \
$debug \
$sendopsgenie \
$OPSGENIE_API_URL \
$OPSGENIE_API_TOKEN \
$sendpagerduty \
$PAGERDUTY_API_URL \
$PAGERDUTY_INTEGRATION_KEY