forked from freddenis/dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exa-iblinkinfo.sh
138 lines (127 loc) · 5.61 KB
/
exa-iblinkinfo.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
#!/bin/bash
# Fred Denis -- July 2019 -- http://unknowndba.blogspot.com -- [email protected]
#
# Show a nice table of what is plugged from/to IB switches from the iblinkinfo command
# Need to be launched as root as iblinkinfo needs root privileges
#
# The current script version is still in DEV
#
# History :
#
# 201907?? - Fred Denis - Initial release
#
#
iblinkinfo --switches-only -l |\
awk 'BEGIN\
{ FS = "\"" ;
# Some colors
COLOR_BEGIN = "\033[1;" ;
COLOR_END = "\033[m" ;
RED = "31m" ;
GREEN = "32m" ;
YELLOW = "33m" ;
BLUE = "34m" ;
TEAL = "36m" ;
WHITE = "37m" ;
NORMAL = "0m" ;
BACK_LIGHTBLUE = "104m" ;
RED_BACKGROUND = "41m" ;
# Columns size
COL_HOST = 8 ;
COL_PORT = 8 ;
}
#
# A function to center the outputs with colors
#
function center( str, n, color, sep)
{ right = int((n - length(str)) / 2) ;
left = n - length(str) - right ;
return sprintf(COLOR_BEGIN color "%" left "s%s%" right "s" COLOR_END sep, "", str, "" ) ;
}
#
# A function that just print a "---" white line
#
function print_a_line(size)
{
if ( ! size)
{ size = COL_DB+COL_VER+(COL_NODE*n)+COL_TYPE+n+3 ;
}
printf("%s", COLOR_BEGIN WHITE) ;
for (k=1; k<=size; k++) {printf("%s", "-");} ;
printf("%s", COLOR_END"\n") ;
}
{ # Cleaned the data from the output
split ($2, a, " ") ;
ip = a[length(a)] ; # IP switch
name = a[length(a)-1] ; # IB name
if (length(name) > COL_HOST)
{ COL_HOST = length(name) ; # Column size
}
sub(/\/ */, "/", $3) ;
split ($3, a, " ") ;
switches[name] = id ;
id = a[1] ; # Switch ID
port = a[2] ; # Port
sub(/\[/, "", port) ;
if ($3 ~ /Down/)
{ idk1 = "" ;
idk2 = "" ;
} else {
idk1 = a[length(a)-2] ;
idk2 = a[length(a)-1] ;
sub(/\[/, "", idk2) ;
}
sub(")==>.*$", "", $3) ;
split($3, a, " ") ;
status = a[length(a)] ; # Status
sub("SUN DCS 36P QDR ", "", $4) ;
split ($4, a, " ") ;
to = a[1] ; # Connected to
sub(/\..*$/, "", to) ; # Remove the domain
info[id,port] = ip"|"name"|"id"|"port"|"status"|"to"|"idk1"|"idk2 ;
} END\
{ # Header
nb = asorti(switches, switches_sorted) ;
printf("\n") ;
printf("%s", center("Port", COL_PORT, WHITE, "|")) ;
COL_SWITCH = COL_HOST+COL_PORT+3 ;
for (i=1; i<=nb; i++)
{
switch_id = switches[switches_sorted[i]] ;
switch_name = switches_sorted[i] ;
split(info[switch_id,1], a, "|") ;
printf("%s", center(a[2]" ("switch_id")", COL_SWITCH, WHITE, "|"));
}
printf("\n") ;
print_a_line(COL_PORT*(nb+1)+COL_HOST*nb+nb*4) ;
for (j=1; j<=36; j++) # Switches have 36 ports
{
for (i=1; i<=nb; i++)
{
switch_id = switches[switches_sorted[i]] ;
switch_name = switches_sorted[i] ;
split(info[switch_id,j], a, "|") ;
COLOR = NORMAL ;
if (a[5] ~ /Active/)
{ COLOR = GREEN ;
}
if (i == 1) # Print the port
{ printf("%s", center(a[4], COL_PORT, WHITE, "|"));
}
if (a[7] != "")
{ idk = "("a[7]"/"a[8]")" ;
} else {
idk = "" ;
}
printf(COLOR_BEGIN COLOR " %-"COL_HOST"s " COLOR_END, a[6] );
printf(COLOR_BEGIN COLOR "%-"COL_PORT"s" COLOR_END " |", idk );
}
printf("\n") ;
}
print_a_line(COL_PORT*(nb+1)+COL_HOST*nb+nb*4) ;
printf("\n") ;
}
'
#********************************************************************************#
#* E N D O F S O U R C E *#
#********************************************************************************#