-
Notifications
You must be signed in to change notification settings - Fork 14
/
server-naming-translator-general.sh
336 lines (274 loc) · 7.18 KB
/
server-naming-translator-general.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/bin/bash
# Author: dave.bechtel kingneutron@gmail , +%Y2022
# Utility script to translate server names to cloud service / physical location and type (sandbox, dev, prod, etc)
# Current version: 1.2 2022.0119.1300
# Requires: bash v3.2.57 or later
# NOTE set to 0 to disable "gt<1 ae<2 scg<3 d<4 01<5" helpful breakdown output
debugg=1
[ $debugg -gt 1 ] && set -e # Exit at first error
# failexit.mrg
function failexit () {
echo '! Something failed! Code: '"$1 $2" # code # (and optional description)
exit $1
}
#echo "** Server Translator -- Author: dave.bechtel kingneutron@gmail **"
# Azure cloud
# 3 chars for location, 3 for app, 3 for function, 2 for environment, 2 for server count
# ex. zgq xym mgm cs 01 == "Azure Gov Qual - Xymon - Management - Customer Services - 01"
# 1 2 3 4 5
zgq="Azure Gov Qual"
zgb="Azure Gov Bensonville"
sb="Sandbox"
de="Development"
np="NonProd"
cs="Customer Services"
pr="Production"
qa="Quality Assurance"
# AWS cloud
# 3 for location, 3 for app, 3 for function, 2 for env, 2 for server count
# ex. aw1 xym mgm ss 01 == "AWS Virginia - Xymon - Management - Shared Services - 01"
aw1="AWS Virginia"
ss="Shared Services"
te="Test"
# On-prem physical / VM
# 2 for location, 2 for app owner, 3 for function, 1 for env, 2 for server count
# Prefixes
ch="Chicago (on-prem)"
sa="San Antonio (on-prem)"
# Appowner
db="Database"
lx="Linux"
# server function
adm="AHE LINUX Gateway"
app="Application"
azs="Replication"
cfj="Confluence / JIRA"
dbe="Database"
dbg="Oracle Dataguard"
gms="Golden Master Server"
mgm="Management"
oem="OEM"
web="Webserver"
xym="XYMon Monitoring"
# Env
s="Sandbox"
d="Development"
t="Test"
q="QA"
p="Production"
h="Training"
#############################
# Functions
function transazure () {
# arg=zgqxymmgmcs01
# 111
# 0123456789012
# Print a helpful breakdown of parts
[ $debugg -gt 0 ] && echo ${arg:0:3}'<1 '${arg:3:3}'<2 '${arg:6:3}'<3 '${arg:9:2}'<4 '${arg:11:2}'<5 '
#zgq<1 xym<2 mgm<3 cs<4 01<5
part1=${arg:0:3}
part2=${arg:3:3}
part3=${arg:6:3}
part4=${arg:9:2}
part5=${arg:11:2}
case "$part1" in
zgq )
buildstr="$arg = $zgq -" ;;
zgb )
buildstr="$arg = $zgb -" ;;
esac
# 1-offs
case "$part2" in
bfg )
buildstr="$buildstr DoomBFG -" ;;
# xym )
# buildstr="$buildstr $xym -" ;;
# oem )
# buildstr="$buildstr $oem -" ;;
* )
# Fallthru
# REF: https://unix.stackexchange.com/questions/23111/what-is-the-eval-command-in-bash
# see if section EVALuates to already-defined var, populate if result = not blank
eval tmptest='$'$part2; [ "$tmptest" = "" ] ||buildstr="$buildstr $tmptest -"
esac
# case "$part3" in
# dbe )
# buildstr="$buildstr $dbe -" ;;
# mgm )
# buildstr="$buildstr $mgm -" ;;
# esac
eval tmptest='$'$part3; [ "$tmptest" = "" ] ||buildstr="$buildstr $tmptest -"
# case "$part4" in
# sb )
# buildstr="$buildstr $sb -" ;;
# de )
# buildstr="$buildstr $de -" ;;
# np )
# buildstr="$buildstr $np -" ;;
# cs )
# buildstr="$buildstr $cs -" ;;
# pr )
# buildstr="$buildstr $pr -" ;;
# qa )
# buildstr="$buildstr $qa -" ;;
# esac
eval tmptest='$'$part4; [ "$tmptest" = "" ] ||buildstr="$buildstr $tmptest -"
buildstr="$buildstr $part5"
echo "$buildstr"
exit 0;
}
function transamazon () {
# arg=aw1xymmgmss99
# 111
# 0123456789012
[ $debugg -gt 0 ] && echo ${arg:0:3}'<1 '${arg:3:3}'<2 '${arg:6:3}'<3 '${arg:9:2}'<4 '${arg:11:2}'<5 '
#aw1<1 xym<2 mgm<3 ss<4 01<5
part1=${arg:0:3}
part2=${arg:3:3}
part3=${arg:6:3}
part4=${arg:9:2}
part5=${arg:11:2}
case "$part1" in
aw1 )
buildstr="$arg = $aw1 -" ;;
esac
# case "$part2" in
# adm )
# buildstr="$buildstr $adm -" ;;
# xym )
# buildstr="$buildstr $xym -" ;;
# cfj )
# buildstr="$buildstr $cfj -" ;;
# esac
eval tmptest='$'$part2; [ "$tmptest" = "" ] ||buildstr="$buildstr $tmptest -"
# 1-offs
case "$part3" in
# mgm )
# buildstr="$buildstr $mgm -" ;;
# app )
# buildstr="$buildstr $app -" ;;
web )
buildstr="$buildstr Webserver -" ;;
* )
# Fallthru
eval tmptest='$'$part3; [ "$tmptest" = "" ] ||buildstr="$buildstr $tmptest -"
esac
# case "$part4" in
# sb )
# buildstr="$buildstr $sb -" ;;
# de )
# buildstr="$buildstr $de -" ;;
# np )
# buildstr="$buildstr $np -" ;;
# cs )
# buildstr="$buildstr $cs -" ;;
# ss )
# buildstr="$buildstr $ss -" ;;
# pr )
# buildstr="$buildstr $pr -" ;;
# te )
# buildstr="$buildstr $te -" ;;
# esac
eval tmptest='$'$part4; [ "$tmptest" = "" ] ||buildstr="$buildstr $tmptest -"
buildstr="$buildstr $part5"
echo "$buildstr"
exit 0;
}
function transonprem () {
# arg=chdbadmp99
# 1
# 01234567890
[ $debugg -gt 0 ] && echo ${arg:0:2}'<1 '${arg:2:2}'<2 '${arg:4:3}'<3 '${arg:7:1}'<4 '${arg:8:2}'<5 '
#ch<1 db<2 adm<3 p<4 01<5
part1=${arg:0:2}
part2=${arg:2:2}
part3=${arg:4:3}
part4=${arg:7:1}
part5=${arg:8:2}
#[ $debugg -gt 0 ] && echo "part1=$part1..gt=$gt"
case "$part1" in
ch )
buildstr="$arg = $ch -" ;;
sa )
buildstr="$arg = $sa -" ;;
esac
# case "$part2" in
# db )
# buildstr="$buildstr $db -" ;;
# lx )
# buildstr="$buildstr $lx -" ;;
# esac
eval tmptest='$'$part2; [ "$tmptest" = "" ] ||buildstr="$buildstr $tmptest -"
# case "$part3" in
# azs )
# buildstr="$buildstr $azs -" ;;
# dbg )
# buildstr="$buildstr $dbg -" ;;
# gms )
# buildstr="$buildstr $gms -" ;;
# web )
# buildstr="$buildstr $web -" ;;
# esac
eval tmptest='$'$part3; [ "$tmptest" = "" ] ||buildstr="$buildstr $tmptest -"
# case "$part4" in
# s )
# buildstr="$buildstr $s -" ;;
# d )
# buildstr="$buildstr $d -" ;;
# t )
# buildstr="$buildstr $t -" ;;
# q )
# buildstr="$buildstr $q -" ;;
# p )
# buildstr="$buildstr $p -" ;;
# h )
# buildstr="$buildstr $h -" ;;
# esac
eval tmptest='$'$part4; [ "$tmptest" = "" ] ||buildstr="$buildstr $tmptest -"
buildstr="$buildstr $part5"
echo "$buildstr"
exit 0;
}
#############################
# MAIN
arg="$1"
# ${string:position:length} ## 0-indexed!
prefix3=${arg:0:3}
prefix2=${arg:0:2}
case "$prefix3" in
zgq )
transazure ;;
zgb )
transazure ;;
aw1 )
transamazon ;;
esac
case "$prefix2" in
ch )
transonprem ;;
sa )
transonprem ;;
* )
# Fallthru
failexit 404 "Unknown server prefix - please add to code or correct input argument"
esac
exit;
# REF: https://tldp.org/LDP/abs/html/string-manipulation.html
# REF: https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_03.html
# REF: shared drive AHE Unix Onboarding docs "ServerList.txt" and ServerNamingConventions.txt
# Latest updates at top
2022.0119 (DONE) IDEA - refactored to use eval, generic version rev
# REF: https://unix.stackexchange.com/questions/23111/what-is-the-eval-command-in-bash
This saves A LOT on coding, and nearly no update-in-two-places unless 1-offs
v1.2
$ echo $sname
ssdsotweb01
# 1
#01234567890
web="Web Server"
part=${sname:6:3}; echo $part
web
#eval testt=$web; if blank, NOP OR printit
eval testt='$'$part; [ "$testt" = "" ] ||echo $testt
Web Server
#=============