-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus_media-gateways.py
More file actions
191 lines (175 loc) · 4.08 KB
/
status_media-gateways.py
File metadata and controls
191 lines (175 loc) · 4.08 KB
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
import os
import ossi
import re
import sys
import time
from colorama import Fore, Back
MAJOR = '6c02ff00'
MINOR = '6c03ff00'
WARNINGS = '6c04ff00'
TRUNKS = '6c08ff00'
STATIONS = '6c09ff00'
LINKS_UP = '6c0bff00'
LINKS_DOWN = '6c0aff00'
LOGINS = '6c0cff00'
GENERAL_INFORMATION = (
MAJOR,
MINOR,
WARNINGS,
TRUNKS,
STATIONS,
LINKS_UP,
LINKS_DOWN,
LOGINS,
)
MAPPING = {
MAJOR: 'Major',
MINOR: 'Minor',
WARNINGS: 'Warnings',
TRUNKS: 'Trunks',
STATIONS: 'Stations',
LINKS_UP: 'Links Up',
LINKS_DOWN: 'Links Down',
LOGINS: '# Logins',
'6c0fff01': 'MediaGate 1',
'6c0fff02': 'MediaGate 2',
'6c0fff03': 'MediaGate 3',
'6c0fff04': 'MediaGate 4',
'6c0fff05': 'MediaGate 5',
'6c0fff06': 'MediaGate 6',
'6c0fff07': 'MediaGate 7',
'6c0fff08': 'MediaGate 8',
'6c10ff09': 'MediaGate 9',
'6c10ff0a': 'MediaGate 10',
'6c10ff0b': 'MediaGate 11',
'6c10ff0c': 'MediaGate 12',
'6c10ff0d': 'MediaGate 13',
'6c10ff0e': 'MediaGate 14',
'6c10ff0f': 'MediaGate 15',
'6c10ff10': 'MediaGate 16',
'6c11ff11': 'MediaGate 17',
'6c11ff12': 'MediaGate 18',
'6c11ff13': 'MediaGate 19',
'6c11ff14': 'MediaGate 20',
'6c11ff15': 'MediaGate 21',
'6c11ff16': 'MediaGate 22',
'6c11ff17': 'MediaGate 23',
'6c11ff18': 'MediaGate 24',
'6c12ff19': 'MediaGate 25',
'6c12ff1a': 'MediaGate 26',
'6c12ff1b': 'MediaGate 27',
'6c12ff1c': 'MediaGate 28',
'6c12ff1d': 'MediaGate 29',
'6c12ff1e': 'MediaGate 30',
'6c12ff1f': 'MediaGate 31',
'6c12ff20': 'MediaGate 32',
'6c13ff21': 'MediaGate 33',
'6c13ff22': 'MediaGate 34',
'6c13ff23': 'MediaGate 35',
'6c13ff24': 'MediaGate 36',
'6c13ff25': 'MediaGate 37',
'6c13ff26': 'MediaGate 38',
'6c13ff27': 'MediaGate 39',
'6c13ff28': 'MediaGate 40',
}
# Gateway status constants
MG_MG = 'MG'
MG_Mj = 'Mj'
MG_Mn = 'Mn'
MG_Wn = 'Wn'
MG_Lk = 'Lk'
def parse_gate_info(gate_info):
"""
Args:
gate_info (str): output information about gateway.
Example: '29 0| 0| 1|up'
Returns:
dict: Separate information about gateway
Example: {
'MG': 29, # Gateway number (int)
'Mj': 0, # Counts of major alarms (int)
'Mn': 0, # Counts of minor alarms (int)
'Wn': 1, # Counts of warnings (int)
'Lk': True # Gateway status: up==True, other==False (bool)
}
"""
list_info = list(filter(None, re.split('[ |]', gate_info)))
link_status = True if list_info[4]=='up' else False
result = {
MG_MG: int(list_info[0]),
MG_Mj: int(list_info[1]),
MG_Mn: int(list_info[2]),
MG_Wn: int(list_info[3]),
MG_Lk: link_status
}
return result
def print_major_alarms(mj):
"""
Args:
mj (int): Counts of major alarms
Returns:
str: Colorized information by using colorama
"""
if mj > 0:
return Back.RED + Fore.WHITE + str(mj) + Fore.RESET + Back.RESET
else:
return Fore.GREEN + str(mj) + Fore.RESET
def print_minor_alarms(mn):
"""
Args:
mn (int): Counts of minor alarms
Returns:
str: Colorized information by using colorama
"""
if mn > 0:
return Fore.RED + str(mn) + Fore.RESET
else:
return Fore.GREEN + str(mn) + Fore.RESET
def print_warnings(wn):
"""
Args:
wn (int): Counts of warnings
Returns:
str: Colorized information by using colorama
"""
if wn > 0:
return Fore.YELLOW + str(wn) + Fore.RESET
else:
return Fore.GREEN + str(wn) + Fore.RESET
if __name__ == '__main__':
status = ossi.Ossi()
status.connect()
t = status.command('sta media-g')
parse = status.parse(t)
output = status.single_to_dict(parse)
general = {}
gates = []
for key in output:
if key in MAPPING:
if key in GENERAL_INFORMATION:
general.update({MAPPING[key]: output[key]})
elif output[key]:
gates.append(parse_gate_info(output[key]))
print('ALARMS SUMMARY')
for info in GENERAL_INFORMATION:
print('%s => %s' % (MAPPING[info], general[MAPPING[info]]))
print('\nGATEWAY STATUS')
for gate in gates:
if gate[MG_Lk]:
print('MG {MG}: {Mj} {Mn} {Wn}'.format(
MG=gate[MG_MG],
Mj=print_major_alarms(gate[MG_Mj]),
Mn=print_minor_alarms(gate[MG_Mn]),
Wn=print_warnings(gate[MG_Wn])
))
else:
print(
Back.RED +
Fore.WHITE +
'MG ' +
str(gate[MG_MG]) +
' is DOWN' +
Back.RESET +
Fore.RESET
)
status.disconnect()