pytbox 0.2.5__py3-none-any.whl → 0.2.7__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.
Potentially problematic release.
This version of pytbox might be problematic. Click here for more details.
- pytbox/database/victoriametrics.py +27 -1
- pytbox/mingdao.py +3 -2
- pytbox/network/meraki.py +81 -1
- {pytbox-0.2.5.dist-info → pytbox-0.2.7.dist-info}/METADATA +1 -1
- {pytbox-0.2.5.dist-info → pytbox-0.2.7.dist-info}/RECORD +8 -8
- {pytbox-0.2.5.dist-info → pytbox-0.2.7.dist-info}/WHEEL +0 -0
- {pytbox-0.2.5.dist-info → pytbox-0.2.7.dist-info}/entry_points.txt +0 -0
- {pytbox-0.2.5.dist-info → pytbox-0.2.7.dist-info}/top_level.txt +0 -0
|
@@ -374,4 +374,30 @@ class VictoriaMetrics:
|
|
|
374
374
|
labels['schedule_type'] = 'cron'
|
|
375
375
|
labels['schedule_cron'] = schedule_cron
|
|
376
376
|
r = self.insert(metric_name="cronjob_run_duration_seconds", labels=labels, value=duration_seconds)
|
|
377
|
-
return r
|
|
377
|
+
return r
|
|
378
|
+
|
|
379
|
+
def get_vmware_esxhostnames(self, vcenter: str=None) -> list:
|
|
380
|
+
'''
|
|
381
|
+
_summary_
|
|
382
|
+
'''
|
|
383
|
+
esxhostnames = []
|
|
384
|
+
query = f'vsphere_host_sys_uptime_latest{{vcenter="{vcenter}"}}'
|
|
385
|
+
metrics = self.query(query=query).data
|
|
386
|
+
for metric in metrics:
|
|
387
|
+
esxhostname = metric['metric']['esxhostname']
|
|
388
|
+
esxhostnames.append(esxhostname)
|
|
389
|
+
return esxhostnames
|
|
390
|
+
|
|
391
|
+
def get_vmware_cpu_usage(self, vcenter: str=None, esxhostname: str=None) -> float:
|
|
392
|
+
'''
|
|
393
|
+
_summary_
|
|
394
|
+
'''
|
|
395
|
+
query = f'vsphere_host_cpu_usage_average{{vcenter="{vcenter}", esxhostname="{esxhostname}"}}'
|
|
396
|
+
return self.query(query=query).data[0]['value'][1]
|
|
397
|
+
|
|
398
|
+
def get_vmware_memory_usage(self, vcenter: str=None, esxhostname: str=None) -> float:
|
|
399
|
+
'''
|
|
400
|
+
_summary_
|
|
401
|
+
'''
|
|
402
|
+
query = f'vsphere_host_mem_usage_average{{vcenter="{vcenter}", esxhostname="{esxhostname}"}}'
|
|
403
|
+
return self.query(query=query).data[0]['value'][1]
|
pytbox/mingdao.py
CHANGED
|
@@ -12,7 +12,7 @@ class Mingdao:
|
|
|
12
12
|
_summary_
|
|
13
13
|
'''
|
|
14
14
|
def __init__(self, app_key: str=None, sign: str=None, timeout: int=5):
|
|
15
|
-
self.base_url = "https://api.mingdao.com
|
|
15
|
+
self.base_url = "https://api.mingdao.com"
|
|
16
16
|
self.headers = {
|
|
17
17
|
'Content-Type': 'application/json;charset=UTF-8',
|
|
18
18
|
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'
|
|
@@ -20,7 +20,7 @@ class Mingdao:
|
|
|
20
20
|
self.timeout = timeout
|
|
21
21
|
self.app_key = app_key
|
|
22
22
|
self.sign = sign
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
def _build_api_request(self, api_url: str, method: Literal['GET', 'POST'], params: dict=None, body: dict=None, api_version: Literal['v1', 'v2']='v2'):
|
|
25
25
|
body['appKey'] = self.app_key
|
|
26
26
|
body['sign'] = self.sign
|
|
@@ -116,6 +116,7 @@ class Mingdao:
|
|
|
116
116
|
parse_control_id: bool=False,
|
|
117
117
|
page_size: int=100,
|
|
118
118
|
):
|
|
119
|
+
|
|
119
120
|
filters = []
|
|
120
121
|
if project_value:
|
|
121
122
|
filters.append({
|
pytbox/network/meraki.py
CHANGED
|
@@ -4,6 +4,7 @@ from typing import Any, Literal
|
|
|
4
4
|
import requests
|
|
5
5
|
from ..utils.response import ReturnResponse
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
class Meraki:
|
|
8
9
|
'''
|
|
9
10
|
Meraki Client
|
|
@@ -166,4 +167,83 @@ class Meraki:
|
|
|
166
167
|
params=params,
|
|
167
168
|
timeout=self.timeout
|
|
168
169
|
)
|
|
169
|
-
return ReturnResponse(code=0, msg=f"获取设备健康状态成功", data=r.json())
|
|
170
|
+
return ReturnResponse(code=0, msg=f"获取设备健康状态成功", data=r.json())
|
|
171
|
+
|
|
172
|
+
def reboot_device(self, serial: str) -> ReturnResponse:
|
|
173
|
+
'''
|
|
174
|
+
该接口 60s 只能执行一次
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
serial (str): _description_
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
ReturnResponse: _description_
|
|
181
|
+
'''
|
|
182
|
+
r = requests.post(
|
|
183
|
+
url=f"{self.base_url}/devices/{serial}/reboot",
|
|
184
|
+
headers=self.headers,
|
|
185
|
+
timeout=self.timeout
|
|
186
|
+
)
|
|
187
|
+
if r.status_code == 202 and r.json()['success'] == True:
|
|
188
|
+
return ReturnResponse(code=0, msg=f"重启 {serial} 成功", data=r.json())
|
|
189
|
+
|
|
190
|
+
try:
|
|
191
|
+
error_msg = r.json()['error']
|
|
192
|
+
except KeyError:
|
|
193
|
+
error_msg = r.json()
|
|
194
|
+
return ReturnResponse(code=1, msg=f"重启 {serial} 失败, 报错 {error_msg}", data=None)
|
|
195
|
+
|
|
196
|
+
def get_alerts(self):
|
|
197
|
+
# from datetime import datetime, timedelta
|
|
198
|
+
params = {}
|
|
199
|
+
params['tsStart'] = "2025-10-20T00:00:00Z"
|
|
200
|
+
params['tsEnd'] = "2025-10-30T00:00:00Z"
|
|
201
|
+
# # 获取昨天0:00的时间戳(秒)
|
|
202
|
+
# yesterday = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(days=1)
|
|
203
|
+
# ts_start = int(yesterday.timestamp()) * 1000
|
|
204
|
+
# params['tsStart'] = str(ts_start)
|
|
205
|
+
# print(params)
|
|
206
|
+
r = requests.get(
|
|
207
|
+
url=f"{self.base_url}/organizations/{self.organization_id}/assurance/alerts",
|
|
208
|
+
headers=self.headers,
|
|
209
|
+
timeout=self.timeout,
|
|
210
|
+
params=params
|
|
211
|
+
)
|
|
212
|
+
for i in r.json():
|
|
213
|
+
print(i)
|
|
214
|
+
# return ReturnResponse(code=0, msg="获取告警成功", data=r.json())
|
|
215
|
+
|
|
216
|
+
def get_network_events(self, network_id):
|
|
217
|
+
params = {}
|
|
218
|
+
params['productType'] = "wireless"
|
|
219
|
+
|
|
220
|
+
print(params)
|
|
221
|
+
r = requests.get(
|
|
222
|
+
url=f"{self.base_url}/networks/{network_id}/events",
|
|
223
|
+
headers=self.headers,
|
|
224
|
+
timeout=self.timeout,
|
|
225
|
+
params=params
|
|
226
|
+
)
|
|
227
|
+
if r.status_code == 200:
|
|
228
|
+
return ReturnResponse(code=0, msg=f"获取网络事件成功", data=r.json())
|
|
229
|
+
return ReturnResponse(code=1, msg=f"获取网络事件失败: {r.status_code} - {r.text}", data=None)
|
|
230
|
+
|
|
231
|
+
def get_wireless_failcounter(self, network_id: str, timespan: int=5*60, serial: str=None):
|
|
232
|
+
'''
|
|
233
|
+
https://developer.cisco.com/meraki/api-v1/get-network-wireless-failed-connections/
|
|
234
|
+
'''
|
|
235
|
+
params = {}
|
|
236
|
+
params['timespan'] = timespan
|
|
237
|
+
if serial:
|
|
238
|
+
params['serial'] = serial
|
|
239
|
+
|
|
240
|
+
r = requests.get(
|
|
241
|
+
url=f"{self.base_url}/networks/{network_id}/wireless/failedConnections",
|
|
242
|
+
headers=self.headers,
|
|
243
|
+
timeout=self.timeout,
|
|
244
|
+
params=params
|
|
245
|
+
)
|
|
246
|
+
if r.status_code == 200:
|
|
247
|
+
return ReturnResponse(code=0, msg=f"获取无线失败连接成功", data=r.json())
|
|
248
|
+
return ReturnResponse(code=1, msg=f"获取无线失败连接失败: {r.status_code} - {r.text}", data=None)
|
|
249
|
+
|
|
@@ -2,7 +2,7 @@ pytbox/base.py,sha256=WC_p_PYMMpNq-5JRLyZoD74k-d2EQVmO4VjTvnI7VqE,4541
|
|
|
2
2
|
pytbox/cli.py,sha256=N775a0GK80IT2lQC2KRYtkZpIiu9UjavZmaxgNUgJhQ,160
|
|
3
3
|
pytbox/dida365.py,sha256=pUMPB9AyLZpTTbaz2LbtzdEpyjvuGf4YlRrCvM5sbJo,10545
|
|
4
4
|
pytbox/excel.py,sha256=f5XBLCeJbGgxytoSwVhbk03WLTzz8Q3IJ_RZ2-r_w6A,2334
|
|
5
|
-
pytbox/mingdao.py,sha256=
|
|
5
|
+
pytbox/mingdao.py,sha256=afEFJ9NKPdsmAZ4trBEJKl66fMj3Z8TWfaOcomNGhzw,6042
|
|
6
6
|
pytbox/notion.py,sha256=GRPdZAtyG2I6M6pCFbdrTWDACaPsp1RAXrY_RpWYKus,26572
|
|
7
7
|
pytbox/onepassword_connect.py,sha256=nD3xTl1ykQ4ct_dCRRF138gXCtk-phPfKYXuOn-P7Z8,3064
|
|
8
8
|
pytbox/onepassword_sa.py,sha256=08iUcYud3aEHuQcUsem9bWNxdXKgaxFbMy9yvtr-DZQ,6995
|
|
@@ -45,7 +45,7 @@ pytbox/cli/formatters/__init__.py,sha256=4o85w4j-A-O1oBLvuE9q8AFiJ2C9rvB3MIKsy5V
|
|
|
45
45
|
pytbox/cli/formatters/output.py,sha256=h5WhZlQk1rjmxEj88Jy5ODLcv6L5zfGUhks_3AWIkKU,5455
|
|
46
46
|
pytbox/common/__init__.py,sha256=3JWfgCQZKZuSH5NCE7OCzKwq82pkyop9l7sH5YSNyfU,122
|
|
47
47
|
pytbox/database/mongo.py,sha256=AhJ9nCAQHKrrcL-ujeonOwEf3x2QkmT2VhoCdglqJmU,3478
|
|
48
|
-
pytbox/database/victoriametrics.py,sha256
|
|
48
|
+
pytbox/database/victoriametrics.py,sha256=vUv2sRTvtdIRiZWrbLmAp6mrey8bJKVZc3bRFBpFnok,15660
|
|
49
49
|
pytbox/feishu/client.py,sha256=kwGLseGT_iQUFmSqpuS2_77WmxtHstD64nXvktuQ3B4,5865
|
|
50
50
|
pytbox/feishu/endpoints.py,sha256=z3nPOZPC2JGDJlO7SusWBpRA33hZZ4Z-GBhI6F8L_u4,40240
|
|
51
51
|
pytbox/feishu/errors.py,sha256=79qFAHZw7jDj3gnWAjI1-W4tB0q1_aSfdjee4xzXeuI,1179
|
|
@@ -56,7 +56,7 @@ pytbox/log/victorialog.py,sha256=gffEiq38adv9sC5oZeMcyKghd3SGfRuqtZOFuqHQF6E,413
|
|
|
56
56
|
pytbox/mail/alimail.py,sha256=njKA3PUbIaiKFaxKvUObmklmEEHg2YA-O5rpgsgT5_w,5147
|
|
57
57
|
pytbox/mail/client.py,sha256=RNgWhhTXFTpD43U4p7hbmnfRdmltuZmbm890gaZTzhI,6278
|
|
58
58
|
pytbox/mail/mail_detail.py,sha256=6u8DK-7WzYPSuX6TdicSCh2Os_9Ou6Rn9xc6WRvv85M,699
|
|
59
|
-
pytbox/network/meraki.py,sha256=
|
|
59
|
+
pytbox/network/meraki.py,sha256=qyJZtpxDLMMjPkGvU_xEc603sRg_ZLH8cMP_pUL20jY,9102
|
|
60
60
|
pytbox/utils/cronjob.py,sha256=b17CY1fmaFTdQojicXAXHliov_JZdmT7cZhtO4v5sCo,3080
|
|
61
61
|
pytbox/utils/env.py,sha256=gD2-NyL3K3Vg1B1eGeD1hRtlSHPGgF8Oi9mchuQL6_o,646
|
|
62
62
|
pytbox/utils/load_config.py,sha256=R4pGerBinbewsym41hQ8Z-I5I7gepuEKODjIrli4C08,5043
|
|
@@ -65,8 +65,8 @@ pytbox/utils/response.py,sha256=kXjlwt0WVmLRam2eu1shzX2cQ7ux4cCQryaPGYwle5g,1247
|
|
|
65
65
|
pytbox/utils/richutils.py,sha256=OT9_q2Q1bthzB0g1GlhZVvM4ZAepJRKL6a_Vsr6vEqo,487
|
|
66
66
|
pytbox/utils/timeutils.py,sha256=uSKgwt20mVcgIGKLsH2tNum8v3rcpzgmBibPvyPQFgM,20433
|
|
67
67
|
pytbox/win/ad.py,sha256=-3pWfL3dElz-XoO4j4M9lrgu3KJtlhrS9gCWJBpafAU,1147
|
|
68
|
-
pytbox-0.2.
|
|
69
|
-
pytbox-0.2.
|
|
70
|
-
pytbox-0.2.
|
|
71
|
-
pytbox-0.2.
|
|
72
|
-
pytbox-0.2.
|
|
68
|
+
pytbox-0.2.7.dist-info/METADATA,sha256=zWSHsiovVdu04JNt1xHIpVXh7mNbf7_YTYAvtxgn1IM,6319
|
|
69
|
+
pytbox-0.2.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
70
|
+
pytbox-0.2.7.dist-info/entry_points.txt,sha256=YaTOJ2oPjOiv2SZwY0UC-UA9QS2phRH1oMvxGnxO0Js,43
|
|
71
|
+
pytbox-0.2.7.dist-info/top_level.txt,sha256=YADgWue-Oe128ptN3J2hS3GB0Ncc5uZaSUM3e1rwswE,7
|
|
72
|
+
pytbox-0.2.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|