-
Notifications
You must be signed in to change notification settings - Fork 7
/
GetConfig.py
264 lines (192 loc) · 7.88 KB
/
GetConfig.py
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
# coding:utf-8
from collections import OrderedDict as Odd
try:
import configparser as cp
except Exception:
import ConfigParser as cp
name_of_config_file = 'Config.ini'
def read_config_file():
objCFG = cp.ConfigParser(allow_no_value=True)
objCFG.read(name_of_config_file)
return objCFG
# FolderSetting
collection = 'collections'
swporterr = 'SWPorterr'
trace = 'Trace'
traceanalyse = 'TraceAnalyse'
cfgbackup = 'CFGBackup'
PeriodicCheck = 'PeriodicCheck'
# MessageLogging
msglevel = '1'
# PCEngineCommand
PCEngineCommand_list = ['vpd',
'conmgr status',
'mirror',
'group',
'map',
'drvstate',
'history',
'sfp all']
# PCSANSwitchCommand
PCSANSwitchCommand_list = ['ipaddrshow',
'switchstatusshow',
'switchshow',
'porterrshow',
'nsshow',
'zoneshow',
'cfgshow']
# TraceRegular
TraceRegular2 = [['abts_received',
"r'(.*)- Port (A1|A2) reports (ABTS received):\s.*(initiator #)(\d+).*(0x.{6})\s?'"],
['abts_frame',
"r'(.*)(P0|P1|P2|P3): (ABTS frame received from port ID )(0x.{6})\s(.*(Initiator number)=(\d+)\s?)?(\s.*)?'"],
['queuefull',
"r'(.*)(- Port )(A1|A2)(.*Queue Fulls:\s.*initiator #)(\d+)(.*)(0x.{6})\s?'"],
['linkerror',
"r'(.*)(P1|P2|P3|P4): (.*)\((type = )(.*)\)( for our own port)'"],
['driveblocked',
"r'(.*) RE: (RE-IOCB) (4504), (address) = (.*),.*\s.*(target_number )(0x.{4}).*.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s(.*)'"],
['abortcaw',
"r'.*(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (.*) - (Aborted Compare and Write command:)\s.*(Drive )(0x.{4}).*(IOCB #)(\d*), (received )(\d*)(.*\s)(.*)'"],
['unwanted_hba',
"r'.*(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (.*) - (Port) (A1|A2|B1|B2) (reports initiator arrived:)\s.*(Unwanted initiator at Port ID) (0x.{6}), (WWPN) = (.{16})'"],
['link_error',
"r'(\d{2}:\d{2}\.\d{3}\_\d{3}) (P0|P1|P2|P3): (Link error)(.*)'"],
['from_unwant_hba',
"r'(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (.*), (.*) - (Port) (A1|A2|B1|B2) (reports ABTS received):\s.*(From unwanted initiator at Port ID) (.{8})'"],
['lost_connection',
"r'\s*(\w{3,6}day), (\d{1,2}/\d{1,2}/20\d{1,2}), (\d{1,2}:\d{1,2}:\d{1,2}) - (Port) (A1|A2|B1|B2) (\w+) (\d+) (bytes of) (\w+) (data):\s+(From drive connection) (\d+) = (drive) #(\d+) (at Port ID) (0x\d{6})'"]]
class EngineConfig(object):
"""docstring for EngineConfig"""
def __init__(self):
# super(EngineConfig, self).__init__()
self.cfg = read_config_file()
self.oddEngines = self._odd_engines()
def _odd_engines(self):
oddEngines = Odd()
for engine in self.cfg.items('Engines'):
oddEngines[engine[0]] = engine[1]
return oddEngines
def list_engines_alias(self):
return self.oddEngines.keys()
def list_engines_IP(self):
return self.oddEngines.values()
def telnet_port(self):
return self.cfg.getint('EngineSetting', 'telnet_port')
def FTP_port(self):
return self.cfg.getint('EngineSetting', 'ftp_port')
def password(self):
return str(self.cfg.get('EngineSetting', 'password'))
def trace_level(self):
return self.cfg.getint('EngineSetting', 'trace_level')
class DBConfig(object):
"""docstring for DBConfig"""
def __init__(self):
# super(DBConfig, self).__init__()
self.cfg = read_config_file()
def host(self):
return self.cfg.get('DBSetting', 'host')
def port(self):
return self.cfg.getint('DBSetting', 'port')
def name(self):
return self.cfg.get('DBSetting', 'name')
class SwitchConfig(object):
"""docstring for SwitchConfig"""
def __init__(self):
self.cfg = read_config_file()
self.oddSWAlias = self._odd_switches_Alias()
self.oddSWPort = self._odd_switches_Ports()
def _odd_switches_Alias(self):
oddSWAlias = Odd()
for sw in self.cfg.items('SANSwitches'):
oddSWAlias[sw[0]] = sw[1]
return oddSWAlias
def _odd_switches_Ports(self):
oddSWPort = Odd()
for sw in self.cfg.items('SANSwitchePorts'):
oddSWPort[sw[0]] = eval(sw[1])
return oddSWPort
def list_switch_alias(self):
return self.oddSWAlias.keys()
def list_switch_IP(self):
return self.oddSWAlias.values()
def list_switch_ports(self):
return self.oddSWPort.values()
def SSH_port(self):
return self.cfg.getint('SANSwitcheSetting', 'ssh_port')
def username(self):
return str(self.cfg.get('SANSwitcheSetting', 'username'))
def password(self):
return str(self.cfg.get('SANSwitcheSetting', 'password'))
def threshold_total(self):
lstThreshold = []
# level1 = self.cfg.getint('Threshold', 'SWTotal_increase_Notify')
level2 = self.cfg.getint('Threshold', 'SWTotal_increase_Warning')
level3 = self.cfg.getint('Threshold', 'SWTotal_increase_Alarm')
# lstThreshold.append(level1)
lstThreshold.append(level2)
lstThreshold.append(level3)
return tuple(lstThreshold)
class EmailConfig(object):
"""docstring for EmailConfig"""
def __init__(self):
self.cfg = read_config_file()
def email_host(self):
return str(self.cfg.get('EmailSetting', 'host'))
# port of mail server
def email_host_port(self):
return self.cfg.getint('EmailSetting', 'host_port')
def email_password(self):
return str(self.cfg.get('EmailSetting', 'password'))
def email_sender(self):
return str(self.cfg.get('EmailSetting', 'sender'))
def email_receiver(self):
return str(self.cfg.get('EmailSetting', 'receiver'))
def email_sub(self):
return str(self.cfg.get('EmailSetting', 'email_sub'))
# Whether to Turn off Mail Function
def email_enable(self):
return self.cfg.get('EmailSetting', 'enable')
class Setting(object):
"""docstring for Setting"""
def __init__(self):
self.cfg = read_config_file()
def message_level(self):
return msglevel
def interval_web_refresh(self):
return self.cfg.getint('Interval', 'web_refresh')
def interval_haap_update(self):
return self.cfg.getint('Interval', 'haap_update')
def interval_sansw_update(self):
return self.cfg.getint('Interval', 'sansw_update')
def interval_warning_check(self):
return self.cfg.getint('Interval', 'warning_check')
def folder_collection(self):
return collection
def folder_swporterr(self):
return swporterr
def folder_trace(self):
return trace
def folder_traceanalyse(self):
return traceanalyse
def folder_cfgbackup(self):
return cfgbackup
def folder_PeriodicCheck(self):
return PeriodicCheck
def PCEngineCommand(self):
return PCEngineCommand_list
def PCSANSwitchCommand(self):
return PCSANSwitchCommand_list
def oddRegularTrace(self):
oddRegularTrace = Odd()
for i in TraceRegular2:
oddRegularTrace[i[0]] = i[1]
return oddRegularTrace
class General(object):
"""docstring for General"""
def __init__(self):
self.cfg = read_config_file()
def get_PRODUCT(self):
return str(self.cfg.get('General', 'PRODUCT'))
if __name__ == '__main__':
pass