ezKit 1.7.8__py3-none-any.whl → 1.8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ezKit/bottle.py +7 -2
- ezKit/bottle_extensions.py +14 -18
- ezKit/database.py +104 -71
- ezKit/http.py +21 -22
- ezKit/mongo.py +3 -3
- ezKit/redis.py +5 -4
- ezKit/sendemail.py +0 -7
- ezKit/utils.py +2 -2
- {ezKit-1.7.8.dist-info → ezKit-1.8.0.dist-info}/METADATA +1 -1
- ezKit-1.8.0.dist-info/RECORD +17 -0
- ezKit/files.py +0 -348
- ezKit/plots.py +0 -155
- ezKit/qywx.py +0 -172
- ezKit/reports.py +0 -274
- ezKit/zabbix.py +0 -737
- ezKit-1.7.8.dist-info/RECORD +0 -22
- {ezKit-1.7.8.dist-info → ezKit-1.8.0.dist-info}/LICENSE +0 -0
- {ezKit-1.7.8.dist-info → ezKit-1.8.0.dist-info}/WHEEL +0 -0
- {ezKit-1.7.8.dist-info → ezKit-1.8.0.dist-info}/top_level.txt +0 -0
ezKit/reports.py
DELETED
@@ -1,274 +0,0 @@
|
|
1
|
-
from . import files, utils
|
2
|
-
|
3
|
-
'''
|
4
|
-
reports.logout()
|
5
|
-
|
6
|
-
生成报告完成以后, 退出 Zabbix
|
7
|
-
|
8
|
-
return _image
|
9
|
-
|
10
|
-
返回图片信息, 发邮件时使用
|
11
|
-
'''
|
12
|
-
|
13
|
-
class Reports(object):
|
14
|
-
|
15
|
-
# Zabbix Instance
|
16
|
-
_zabbix = None
|
17
|
-
|
18
|
-
# Files Instance
|
19
|
-
_files = None
|
20
|
-
|
21
|
-
# Image Object
|
22
|
-
_image_dir = '.'
|
23
|
-
_image_name_prefix = 'image'
|
24
|
-
|
25
|
-
def __init__(self, zabbix, markdown_file, html_file, image_dir, image_name_prefix):
|
26
|
-
''' Initiation '''
|
27
|
-
self._zabbix = zabbix
|
28
|
-
self._files = files.files(markdown_file, html_file)
|
29
|
-
self._image_dir = image_dir
|
30
|
-
self._image_name_prefix = image_name_prefix
|
31
|
-
|
32
|
-
def generic(
|
33
|
-
self,
|
34
|
-
pieces=None,
|
35
|
-
hosts=None,
|
36
|
-
time_from=None,
|
37
|
-
time_till=None,
|
38
|
-
item_keys=None,
|
39
|
-
data_type=None,
|
40
|
-
data_proc=None,
|
41
|
-
title=None,
|
42
|
-
description=None,
|
43
|
-
number_type=None,
|
44
|
-
number_unit=None,
|
45
|
-
number_handling=None,
|
46
|
-
table_header_title='Host',
|
47
|
-
table_header_data='Data',
|
48
|
-
sort_by_ip=None,
|
49
|
-
image_cid=None,
|
50
|
-
image_label=None,
|
51
|
-
image_kind=None
|
52
|
-
):
|
53
|
-
|
54
|
-
_history = []
|
55
|
-
|
56
|
-
if utils.v_true(item_keys, str):
|
57
|
-
_history = utils.retry(10, self._zabbix.get_history_by_item_key, hosts, time_from, time_till, item_keys, data_type)
|
58
|
-
|
59
|
-
if utils.v_true(item_keys, list):
|
60
|
-
for _item_key in item_keys:
|
61
|
-
_history_slice = utils.retry(10, self._zabbix.get_history_by_item_key, hosts, time_from, time_till, _item_key, data_type)
|
62
|
-
if _history_slice != None:
|
63
|
-
if callable(data_proc) == True:
|
64
|
-
_history_slice = data_proc(_history_slice)
|
65
|
-
_history += _history_slice
|
66
|
-
|
67
|
-
if _history != None:
|
68
|
-
|
69
|
-
_files_func = self._files.multiple_pieces
|
70
|
-
|
71
|
-
if pieces == 'single':
|
72
|
-
|
73
|
-
_files_func = self._files.single_piece
|
74
|
-
|
75
|
-
for _data in _history:
|
76
|
-
if len(_data['history']) > 0:
|
77
|
-
_history_last = max(_data['history'], key=lambda i: i['clock'])
|
78
|
-
_data['history'] = _history_last
|
79
|
-
|
80
|
-
_image = {
|
81
|
-
'cid': '{}'.format(image_cid),
|
82
|
-
'path': '{}/{}_{}.png'.format(self._image_dir, self._image_name_prefix, image_cid),
|
83
|
-
'label': image_label,
|
84
|
-
'kind': image_kind
|
85
|
-
}
|
86
|
-
|
87
|
-
_files_result = _files_func(
|
88
|
-
title=title,
|
89
|
-
description=description,
|
90
|
-
data=_history,
|
91
|
-
image=_image,
|
92
|
-
number_type=number_type,
|
93
|
-
number_unit=number_unit,
|
94
|
-
number_handling=number_handling,
|
95
|
-
table_header_title=table_header_title,
|
96
|
-
table_header_data=table_header_data,
|
97
|
-
sort_by_ip=sort_by_ip
|
98
|
-
)
|
99
|
-
|
100
|
-
if _files_result == True:
|
101
|
-
return _image
|
102
|
-
else:
|
103
|
-
return None
|
104
|
-
|
105
|
-
else:
|
106
|
-
|
107
|
-
return None
|
108
|
-
|
109
|
-
def system_interface(self, hosts, interfaces, time_from, time_till, direction='in'):
|
110
|
-
''' System Interface '''
|
111
|
-
|
112
|
-
_direction_name = 'Received'
|
113
|
-
_direction_alias = 'received'
|
114
|
-
_direction_info = '接收数据'
|
115
|
-
|
116
|
-
if direction == 'out':
|
117
|
-
_direction_name = 'Sent'
|
118
|
-
_direction_alias = 'sent'
|
119
|
-
_direction_info = '发送数据'
|
120
|
-
|
121
|
-
_history = utils.retry(10, self._zabbix.get_history_by_interface, hosts, interfaces, time_from, time_till, direction)
|
122
|
-
|
123
|
-
if utils.v_true(_history, list):
|
124
|
-
|
125
|
-
_image = {
|
126
|
-
'cid': 'system_interface_'.format(_direction_alias),
|
127
|
-
'path': '{}/{}_system_interface_{}.png'.format(self._image_dir, self._image_name_prefix, _direction_alias)
|
128
|
-
}
|
129
|
-
|
130
|
-
_ = self._files.multiple_pieces(
|
131
|
-
title='System Interface {}'.format(_direction_name),
|
132
|
-
description='说明: 网卡**{}**的速度'.format(_direction_info),
|
133
|
-
data=_history,
|
134
|
-
image=_image,
|
135
|
-
number_type='int',
|
136
|
-
number_unit='Kbps',
|
137
|
-
number_handling=utils.divisor_1000,
|
138
|
-
sort_by_ip=True
|
139
|
-
)
|
140
|
-
|
141
|
-
if _ == True:
|
142
|
-
return _image
|
143
|
-
else:
|
144
|
-
return None
|
145
|
-
|
146
|
-
else:
|
147
|
-
|
148
|
-
return None
|
149
|
-
|
150
|
-
def base_system(self, hosts, time_from, time_till, interfaces=None):
|
151
|
-
|
152
|
-
# Images
|
153
|
-
_images = []
|
154
|
-
|
155
|
-
# System CPU utilization
|
156
|
-
_image = self.generic(
|
157
|
-
hosts=hosts,
|
158
|
-
time_from=time_from,
|
159
|
-
time_till=time_till,
|
160
|
-
item_keys='system.cpu.util',
|
161
|
-
data_type=0,
|
162
|
-
title='System CPU utilization',
|
163
|
-
description='说明: 系统 CPU 使用率',
|
164
|
-
number_type='float',
|
165
|
-
number_unit='%',
|
166
|
-
sort_by_ip=True,
|
167
|
-
image_cid='system_cpu_utilization'
|
168
|
-
)
|
169
|
-
if _image != None:
|
170
|
-
_images.append(_image)
|
171
|
-
|
172
|
-
# System Memory utilization
|
173
|
-
_image = self.generic(
|
174
|
-
hosts=hosts,
|
175
|
-
time_from=time_from,
|
176
|
-
time_till=time_till,
|
177
|
-
item_keys='vm.memory.utilization',
|
178
|
-
data_type=0,
|
179
|
-
title='System Memory utilization',
|
180
|
-
description='说明: 系统 内存 使用率',
|
181
|
-
number_type='float',
|
182
|
-
number_unit='%',
|
183
|
-
sort_by_ip=True,
|
184
|
-
image_cid='system_memory_utilization'
|
185
|
-
)
|
186
|
-
if _image != None:
|
187
|
-
_images.append(_image)
|
188
|
-
|
189
|
-
# System root partition utilization
|
190
|
-
_image = self.generic(
|
191
|
-
pieces='single',
|
192
|
-
hosts=hosts,
|
193
|
-
time_from=time_from,
|
194
|
-
time_till=time_till,
|
195
|
-
item_keys='vfs.fs.size[/,pused]',
|
196
|
-
data_type=0,
|
197
|
-
title='System root partition utilization',
|
198
|
-
description='说明: 系统 根目录(/) 使用率',
|
199
|
-
number_type='float',
|
200
|
-
number_unit='%',
|
201
|
-
table_header_data='Used',
|
202
|
-
sort_by_ip=True,
|
203
|
-
image_cid='system_root_partition_utilization',
|
204
|
-
image_label='Used (%)',
|
205
|
-
image_kind='barh'
|
206
|
-
)
|
207
|
-
if _image != None:
|
208
|
-
_images.append(_image)
|
209
|
-
|
210
|
-
if interfaces != None:
|
211
|
-
|
212
|
-
# System Interface Received
|
213
|
-
_image = self.system_interface(hosts, interfaces, time_from, time_till, 'in')
|
214
|
-
if _image != None:
|
215
|
-
_images.append(_image)
|
216
|
-
|
217
|
-
# System Interface Sent
|
218
|
-
_image = self.system_interface(hosts, interfaces, time_from, time_till, 'out')
|
219
|
-
if _image != None:
|
220
|
-
_images.append(_image)
|
221
|
-
|
222
|
-
return _images
|
223
|
-
|
224
|
-
def base_generic(self, hosts, time_from, time_till, items=None):
|
225
|
-
|
226
|
-
# Images
|
227
|
-
_images = []
|
228
|
-
|
229
|
-
if items != None:
|
230
|
-
|
231
|
-
for _item in items:
|
232
|
-
|
233
|
-
# CPU utilization
|
234
|
-
_image = self.generic(
|
235
|
-
hosts=hosts,
|
236
|
-
time_from=time_from,
|
237
|
-
time_till=time_till,
|
238
|
-
item_keys=_item['keys'][0],
|
239
|
-
data_type=_item['types'][0],
|
240
|
-
data_proc=_item.get('data_proc'),
|
241
|
-
title='{} CPU utilization'.format(_item['name']),
|
242
|
-
description='说明: {} CPU 使用率'.format(_item['name']),
|
243
|
-
number_type='float',
|
244
|
-
number_unit='%',
|
245
|
-
table_header_title=_item.get('table_header_title', 'Host'),
|
246
|
-
table_header_data=_item.get('table_header_data', 'Data'),
|
247
|
-
sort_by_ip=True,
|
248
|
-
image_cid='{}_cpu_utilization'.format(_item['alias'])
|
249
|
-
)
|
250
|
-
if _image != None:
|
251
|
-
_images.append(_image)
|
252
|
-
|
253
|
-
# Memory used (RSS)
|
254
|
-
_image = self.generic(
|
255
|
-
hosts=hosts,
|
256
|
-
time_from=time_from,
|
257
|
-
time_till=time_till,
|
258
|
-
item_keys=_item['keys'][1],
|
259
|
-
data_type=_item['types'][1],
|
260
|
-
data_proc=_item.get('data_proc'),
|
261
|
-
title='{} Memory used (RSS)'.format(_item['name']),
|
262
|
-
description='说明: {} 内存 使用量'.format(_item['name']),
|
263
|
-
number_type='int',
|
264
|
-
number_unit='MB',
|
265
|
-
number_handling=utils.divisor_square_1024,
|
266
|
-
table_header_title=_item.get('table_header_title', 'Host'),
|
267
|
-
table_header_data=_item.get('table_header_data', 'Data'),
|
268
|
-
sort_by_ip=True,
|
269
|
-
image_cid='{}_memory_used_rss'.format(_item['alias'])
|
270
|
-
)
|
271
|
-
if _image != None:
|
272
|
-
_images.append(_image)
|
273
|
-
|
274
|
-
return _images
|