pytbox 0.2.5__tar.gz → 0.2.7__tar.gz

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.

Files changed (89) hide show
  1. {pytbox-0.2.5/src/pytbox.egg-info → pytbox-0.2.7}/PKG-INFO +1 -1
  2. {pytbox-0.2.5 → pytbox-0.2.7}/pyproject.toml +1 -1
  3. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/database/victoriametrics.py +27 -1
  4. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/mingdao.py +3 -2
  5. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/network/meraki.py +81 -1
  6. {pytbox-0.2.5 → pytbox-0.2.7/src/pytbox.egg-info}/PKG-INFO +1 -1
  7. {pytbox-0.2.5 → pytbox-0.2.7}/tests/test_mingdao.py +4 -4
  8. {pytbox-0.2.5 → pytbox-0.2.7}/tests/test_victoriametrics.py +6 -2
  9. {pytbox-0.2.5 → pytbox-0.2.7}/MANIFEST.in +0 -0
  10. {pytbox-0.2.5 → pytbox-0.2.7}/README.md +0 -0
  11. {pytbox-0.2.5 → pytbox-0.2.7}/setup.cfg +0 -0
  12. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/alert/alert_handler.py +0 -0
  13. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/alert/ping.py +0 -0
  14. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/alicloud/sls.py +0 -0
  15. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/base.py +0 -0
  16. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/build_config.py +0 -0
  17. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/instances.toml +0 -0
  18. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/__init__.py +0 -0
  19. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.cpu/cpu.toml.j2 +0 -0
  20. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.disk/disk.toml.j2 +0 -0
  21. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.diskio/diskio.toml.j2 +0 -0
  22. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.dns_query/dns_query.toml.j2 +0 -0
  23. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.http_response/http_response.toml.j2 +0 -0
  24. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.mem/mem.toml.j2 +0 -0
  25. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.net/net.toml.j2 +0 -0
  26. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.net_response/net_response.toml.j2 +0 -0
  27. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.ping/ping.toml.j2 +0 -0
  28. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.prometheus/prometheus.toml.j2 +0 -0
  29. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.snmp/cisco_interface.toml.j2 +0 -0
  30. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.snmp/cisco_system.toml.j2 +0 -0
  31. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.snmp/h3c_interface.toml.j2 +0 -0
  32. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.snmp/h3c_system.toml.j2 +0 -0
  33. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.snmp/huawei_interface.toml.j2 +0 -0
  34. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.snmp/huawei_system.toml.j2 +0 -0
  35. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.snmp/ruijie_interface.toml.j2 +0 -0
  36. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.snmp/ruijie_system.toml.j2 +0 -0
  37. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/categraf/jinja2/input.vsphere/vsphere.toml.j2 +0 -0
  38. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/cli/__init__.py +0 -0
  39. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/cli/categraf/__init__.py +0 -0
  40. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/cli/categraf/commands.py +0 -0
  41. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/cli/commands/vm.py +0 -0
  42. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/cli/common/__init__.py +0 -0
  43. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/cli/common/options.py +0 -0
  44. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/cli/common/utils.py +0 -0
  45. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/cli/formatters/__init__.py +0 -0
  46. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/cli/formatters/output.py +0 -0
  47. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/cli/main.py +0 -0
  48. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/cli.py +0 -0
  49. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/common/__init__.py +0 -0
  50. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/database/mongo.py +0 -0
  51. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/dida365.py +0 -0
  52. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/excel.py +0 -0
  53. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/feishu/client.py +0 -0
  54. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/feishu/endpoints.py +0 -0
  55. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/feishu/errors.py +0 -0
  56. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/feishu/helpers.py +0 -0
  57. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/feishu/typing.py +0 -0
  58. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/log/logger.py +0 -0
  59. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/log/victorialog.py +0 -0
  60. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/mail/alimail.py +0 -0
  61. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/mail/client.py +0 -0
  62. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/mail/mail_detail.py +0 -0
  63. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/notion.py +0 -0
  64. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/onepassword_connect.py +0 -0
  65. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/onepassword_sa.py +0 -0
  66. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/pyjira.py +0 -0
  67. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/utils/cronjob.py +0 -0
  68. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/utils/env.py +0 -0
  69. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/utils/load_config.py +0 -0
  70. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/utils/load_vm_devfile.py +0 -0
  71. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/utils/response.py +0 -0
  72. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/utils/richutils.py +0 -0
  73. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/utils/timeutils.py +0 -0
  74. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/vmware.py +0 -0
  75. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox/win/ad.py +0 -0
  76. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox.egg-info/SOURCES.txt +0 -0
  77. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox.egg-info/dependency_links.txt +0 -0
  78. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox.egg-info/entry_points.txt +0 -0
  79. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox.egg-info/requires.txt +0 -0
  80. {pytbox-0.2.5 → pytbox-0.2.7}/src/pytbox.egg-info/top_level.txt +0 -0
  81. {pytbox-0.2.5 → pytbox-0.2.7}/tests/test_base.py +0 -0
  82. {pytbox-0.2.5 → pytbox-0.2.7}/tests/test_feishu.py +0 -0
  83. {pytbox-0.2.5 → pytbox-0.2.7}/tests/test_jira_connection.py +0 -0
  84. {pytbox-0.2.5 → pytbox-0.2.7}/tests/test_load_jsonfile.py +0 -0
  85. {pytbox-0.2.5 → pytbox-0.2.7}/tests/test_logger.py +0 -0
  86. {pytbox-0.2.5 → pytbox-0.2.7}/tests/test_notion.py +0 -0
  87. {pytbox-0.2.5 → pytbox-0.2.7}/tests/test_onepassword_connect.py +0 -0
  88. {pytbox-0.2.5 → pytbox-0.2.7}/tests/test_onepassword_sa.py +0 -0
  89. {pytbox-0.2.5 → pytbox-0.2.7}/tests/test_vmware.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytbox
3
- Version: 0.2.5
3
+ Version: 0.2.7
4
4
  Summary: A collection of Python integrations and utilities (Feishu, Dida365, VictoriaMetrics, ...)
5
5
  Author-email: mingming hou <houm01@foxmail.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pytbox"
7
- version = "0.2.5"
7
+ version = "0.2.7"
8
8
  description = "A collection of Python integrations and utilities (Feishu, Dida365, VictoriaMetrics, ...)"
9
9
  authors = [{ name = "mingming hou", email = "houm01@foxmail.com" }]
10
10
  license = "MIT"
@@ -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]
@@ -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({
@@ -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
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytbox
3
- Version: 0.2.5
3
+ Version: 0.2.7
4
4
  Summary: A collection of Python integrations and utilities (Feishu, Dida365, VictoriaMetrics, ...)
5
5
  Author-email: mingming hou <houm01@foxmail.com>
6
6
  License-Expression: MIT
@@ -25,10 +25,10 @@ def test_get_control_id():
25
25
 
26
26
  def test_get_work_record():
27
27
  r = mingdao.get_work_record(
28
- worksheet_id="64a77d4277649ebe61a9cb45",
29
- project_control_id="64a822be5760cf37a93d07ff",
30
- project_value="4b97c271-4997-4230-90be-28d5285f609b",
31
- complete_date_control_id="64a7e18c77649ebe61aad968",
28
+ worksheet_id="64a77d4277649ebe61a9cb45",
29
+ project_control_id="64a822be5760cf37a93d07ff",
30
+ project_value="4b97c271-4997-4230-90be-28d5285f609b",
31
+ complete_date_control_id="64a7e18c77649ebe61aad968",
32
32
  complete_date="上个月"
33
33
  )
34
34
  print(r)
@@ -22,7 +22,7 @@ def test_check_snmp_port_status():
22
22
  print(r)
23
23
 
24
24
 
25
- test_check_ping_result()
25
+ # test_check_ping_result()
26
26
 
27
27
  # r = vm.check_interface_avg_rate(direction='in', sysname='whcq-prod-coresw-s6720-254', ifname='XGigabitEthernet0/0/47', last_hours=24*30, last_minutes=5)
28
28
  # print(r)
@@ -40,4 +40,8 @@ if __name__ == "__main__":
40
40
  # test_check_ping_result()
41
41
  # test_check_snmp_port_status()
42
42
  # test_check_interface_avg_rate()
43
- pass
43
+ # pass
44
+ # print(r)
45
+ # cpu_usage = vm.get_vmware_cpu_usage(vcenter="10.200.10.20", esxhostname='10.200.10.10')
46
+ memory_usage = vm.get_vmware_memory_usage(vcenter="10.200.10.20", esxhostname='10.200.10.10')
47
+ print(memory_usage)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes