-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatus.py
228 lines (217 loc) · 9.32 KB
/
status.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
import csv
import logging
import os
import sys
from filer import get_filers
def write_status(self, p_filename, all_tenants):
"""Save and write Filer status information to given filename."""
get_list = ['config',
'status',
'proc/cloudsync',
'proc/time/',
'proc/storage/summary',
'proc/perfMonitor']
for filer in get_filers(self, all_tenants):
info = filer.api.get_multi('/', get_list)
tenant = filer.session().user.tenant
sync_id = info.proc.cloudsync.serviceStatus.id
try:
selfScanIntervalInHours = info.config.cloudsync.selfScanVerificationIntervalInHours
except AttributeError:
selfScanIntervalInHours = 'Not Applicable'
uploadingFiles = info.proc.cloudsync.serviceStatus.uploadingFiles
scanningFiles = info.proc.cloudsync.serviceStatus.scanningFiles
try:
selfVerificationscanningFiles = info.proc.cloudsync.serviceStatus.selfVerificationScanningFiles
except AttributeError:
selfVerificationscanningFiles = 'Not Applicable'
CurrentFirmware = info.status.device.runningFirmware
try:
MetaLogMaxSize = info.config.logging.metalog.maxFileSizeMB
except AttributeError:
try:
MetaLogMaxSize = info.config.logging.log2File.maxFileSizeMB
except AttributeError:
MetaLogMaxSize = 'Not Applicable'
try:
MetaLogMaxFiles = info.config.logging.metalog.maxfiles
except AttributeError:
try:
MetaLogMaxFiles = info.config.logging.log2File.maxfiles
except AttributeError:
MetaLogMaxFiles = 'Not Applicable'
try:
AuditLogsStatus = filer.cli.run_command('show /config/logging/files/mode')
except AttributeError:
AuditLogsStatus = 'Not Applicable'
try:
DeviceLocation = filer.cli.run_command('show /config/device/location')
except AttributeError:
AuditLogsStatus = 'Not Applicable'
try:
AuditLogsPath = filer.cli.run_command('show /config/logging/files/path')
except AttributeError:
AuditLogsStatus = 'Not Applicable'
try:
MetaLogs = filer.cli.run_command('dbg level')
MetaLogs1 = MetaLogs[-28:-18]
except AttributeError:
MetaLogs1 = 'Not Applicable'
try:
MetaLogs = filer.cli.run_command('dbg level')
except AttributeError:
MetaLogs = 'Not Applicable'
try:
ad_mapping = filer.cli.run_command('show /config/fileservices/cifs/idMapping/map')
except AttributeError:
ad_mapping = 'Not Applicable'
License = filer.licenses.get()
# License = info.config.device.activeLicenseType
SN = info.status.device.SerialNumber
MAC = info.status.device.MacAddress
IP1 = info.status.network.ports[0].ip.address
DNS1 = info.status.network.ports[0].ip.DNSServer1
DNS2 = info.status.network.ports[0].ip.DNSServer2
try:
storageThresholdPercentTrigger = info.config.cloudsync.cloudExtender.storageThresholdPercentTrigger
except AttributeError:
storageThresholdPercentTrigger = 'Not Applicable'
uptime = info.proc.time.uptime
curr_cpu = info.proc.perfMonitor.current.cpu
curr_mem = info.proc.perfMonitor.current.memUsage
_total = info.proc.storage.summary.totalVolumeSpace
_used = info.proc.storage.summary.usedVolumeSpace
_free = info.proc.storage.summary.freeVolumeSpace
volume = (f"Total: {_total} Used: {_used} Free: {_free}")
# dbg_level = filer.support.set_debug_level()
# MetaLogs1 = dbg_level[-28:-18]
Alerts = info.config.logging.alert
TimeServer = info.config.time
_mode = TimeServer.NTPMode
_zone = TimeServer.TimeZone
_servers = TimeServer.NTPServer
time = (f"Mode: {_mode} Zone: {_zone} Servers: {_servers}")
def get_max_cpu(samples=info.proc.perfMonitor.samples):
"""Return the max CPU usage recorded in last few hours."""
cpu_history = []
for i in samples:
cpu_history.append(i.cpu)
max_cpu = format(max(cpu_history))
return f"{max_cpu}%"
def get_max_memory(samples=info.proc.perfMonitor.samples):
"""Return the max memory usage recorded in last few hours."""
memory_history = []
for i in samples:
memory_history.append(i.memUsage)
max_memory = format(max(memory_history))
return f"{max_memory}%"
def get_ad_status(result=info.status.fileservices.cifs.joinStatus):
"""
Parse domain join value and return the Domain Join Status as string.
joinStatus: -1 = workgroup, 0 = OK, 2 = Failed
"""
if result == 0:
return 'Ok'
if result == -1:
return 'Workgroup'
if result == 2:
return 'Failed'
return result
with open(p_filename, mode='a', newline='', encoding="utf-8-sig") as gatewayList:
gateway_writer = csv.writer(gatewayList,
dialect='excel',
delimiter=',',
quotechar='"',
quoting=csv.QUOTE_MINIMAL)
gateway_writer.writerow([
tenant,
filer.name,
sync_id,
selfScanIntervalInHours,
uploadingFiles,
scanningFiles,
selfVerificationscanningFiles,
MetaLogs1,
AuditLogsStatus,
DeviceLocation,
AuditLogsPath,
MetaLogMaxSize,
MetaLogMaxFiles,
CurrentFirmware,
License,
storageThresholdPercentTrigger,
volume,
SN,
MAC,
IP1,
DNS1,
DNS2,
get_ad_status(),
ad_mapping,
Alerts,
time,
uptime,
f"CPU: {curr_cpu}% Mem: {curr_mem}%",
get_max_cpu(),
get_max_memory()
])
self.logout()
def write_header(p_filename):
"""Write CSV header to given filename parameter """
try:
with open(p_filename, mode='a', newline='', encoding="utf-8-sig") as gatewayList:
gateway_writer = csv.writer(
gatewayList,
dialect='excel',
delimiter=',',
quotechar='"',
quoting=csv.QUOTE_MINIMAL
)
gateway_writer.writerow(['Tenant',
'Filer Name',
'CloudSync Status',
'selfScanIntervalInHours',
'uploadingFiles',
'scanningFiles',
'selfVerificationscanningFiles',
'MetaLogsSetting',
'AuditLogsStatus',
'DeviceLocation',
'AuditLogsPath',
'MetaLogMaxSize',
'MetaLogMaxFiles',
'CurrentFirmware',
'License',
'EvictionPercentage',
'CurrentVolumeStorage',
'SN',
'MAC',
'IP Config',
'DNS Server1',
'DNS Server2',
'AD Domain Status',
'AD Mapping',
'Alerts',
'TimeServer',
'uptime',
'Current Performance',
'Max CPU',
'Max Memory'
])
except FileNotFoundError as error:
logging.error(error)
logging.info("ERROR: Unable to open filename specified: %s", p_filename)
sys.exit("Make sure you entered a valid file name and it exists")
def run_status(self, filename, all_tenants):
"""Log start/end of task and call main function."""
logging.info('Starting status task')
if os.path.exists(filename):
logging.info('Appending to existing file.')
else:
logging.debug('File does not exist. Creating it.')
write_header(filename)
try:
write_status(self, filename, all_tenants)
except Exception as e:
logging.warning("An error occurred: " + str(e))
logging.info('Finished status task.')