-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·135 lines (102 loc) · 2.54 KB
/
install.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
set -eou pipefail
CONST_CHAT_SLACK="slack"
CONST_CHAT_MATTERMOST="mattermost"
# DEFAULT VALUES
DEFAULT_CHAT="$CONST_CHAT_SLACK"
DEFAULT_CHAT_URL="https://slack.com/api/chat.postMessage"
DEFAULT_CHAT_API_TOKEN="supersecrettoken"
DEFAULT_ZABBIX_ADDRESS="localhost"
RED='\033[0;31m'
BRED='\033[1;31m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
warn() {
printf "${YELLOW}[WARN]${NC} $1\n" >&2
}
err() {
printf "${RED}[ERRO]${NC} $1\n" >&2
}
cri() {
printf "${BRED}[CRIT]${NC} $1\n" >&2
}
info() {
printf "${CYAN}[INFO]${NC} $1\n" >&2
}
log() {
printf "$1\n" >&2
}
set_chat() {
local text
local selected_messenger
text=$(cat <<-EOL
${CYAN}[1] Choose the type of messenger.${NC}
${BOLD}-> (1) ${DEFAULT_CHAT}${NC}
(2) mattermost
Write the number of selected messenger or
any key if you want to use default selection
EOL
)
log "$text"
IFS="$\n" read -r selected_messenger
if [ "$selected_messenger" = "2" ]; then
DEFAULT_CHAT=$CONST_CHAT_MATTERMOST
fi
log "Your choice is: ${BOLD}$DEFAULT_CHAT${NC}\n"
}
set_chat_url() {
local text
local address
text=$(cat <<-EOL
${CYAN}[2] Write address of the ${DEFAULT_CHAT} messenger\n${NC}
EOL
)
log "$text"
if [ "$DEFAULT_CHAT" = "$CONST_CHAT_SLACK" ]; then
text=$(cat <<-EOL
For slack the address has already configured.
The address is: ${BOLD}${YELLOW}${DEFAULT_CHAT_URL}${NC}${NC}
And you dont't need to change it.
Howewer if you want change the behaivor of
the webhook script you may change it in
result configuration file after the
installation will have finished.
EOL
)
log "$text"
fi
if [ "$DEFAULT_CHAT" = "$CONST_CHAT_MATTERMOST" ]; then
printf "Messenger address: " >&2
IFS="$\n" read -r address
printf "$address\n"
fi
}
set_chat_token() {
local text
local token
text=$(cat <<-EOL
${CYAN}[3] Set up access API token for ${DEFAULT_CHAT} messenger\n${NC}
EOL
)
log "$text"
text=$(cat <<-EOL
Write the access API token which provided by ${DEFAULT_CHAT}.
For ${CONST_CHAT_SLACK} you can find it on page ${YELLOW}https://api.slack.com/apps/APPID/oauth?${NC}
For ${CONST_CHAT_MATTERMOST} it's not necessary to provide the access token
because messages will send through webhook mechanism.
EOL
)
log "$text"
printf "Access token: " >&2
IFS="$\n" read -r token
if [[ -z "${token// }" ]]; then
DEFAULT_CHAT_API_TOKEN=""
return
fi
DEFAULT_CHAT_API_TOKEN=$token
}
set_chat
set_chat_url
set_chat_token