pytbox 0.1.8__tar.gz → 0.1.9__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 (84) hide show
  1. {pytbox-0.1.8/src/pytbox.egg-info → pytbox-0.1.9}/PKG-INFO +1 -1
  2. {pytbox-0.1.8 → pytbox-0.1.9}/pyproject.toml +1 -1
  3. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/alert/alert_handler.py +25 -7
  4. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/base.py +0 -2
  5. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/database/mongo.py +1 -1
  6. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/database/victoriametrics.py +5 -2
  7. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/mail/client.py +4 -0
  8. {pytbox-0.1.8 → pytbox-0.1.9/src/pytbox.egg-info}/PKG-INFO +1 -1
  9. {pytbox-0.1.8 → pytbox-0.1.9}/MANIFEST.in +0 -0
  10. {pytbox-0.1.8 → pytbox-0.1.9}/README.md +0 -0
  11. {pytbox-0.1.8 → pytbox-0.1.9}/setup.cfg +0 -0
  12. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/alert/ping.py +0 -0
  13. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/alicloud/sls.py +0 -0
  14. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/build_config.py +0 -0
  15. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/instances.toml +0 -0
  16. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/__init__.py +0 -0
  17. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.cpu/cpu.toml.j2 +0 -0
  18. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.disk/disk.toml.j2 +0 -0
  19. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.diskio/diskio.toml.j2 +0 -0
  20. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.dns_query/dns_query.toml.j2 +0 -0
  21. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.http_response/http_response.toml.j2 +0 -0
  22. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.mem/mem.toml.j2 +0 -0
  23. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.net/net.toml.j2 +0 -0
  24. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.net_response/net_response.toml.j2 +0 -0
  25. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.ping/ping.toml.j2 +0 -0
  26. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.prometheus/prometheus.toml.j2 +0 -0
  27. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.snmp/cisco_interface.toml.j2 +0 -0
  28. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.snmp/cisco_system.toml.j2 +0 -0
  29. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.snmp/h3c_interface.toml.j2 +0 -0
  30. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.snmp/h3c_system.toml.j2 +0 -0
  31. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.snmp/huawei_interface.toml.j2 +0 -0
  32. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.snmp/huawei_system.toml.j2 +0 -0
  33. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.snmp/ruijie_interface.toml.j2 +0 -0
  34. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.snmp/ruijie_system.toml.j2 +0 -0
  35. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/categraf/jinja2/input.vsphere/vsphere.toml.j2 +0 -0
  36. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/cli/__init__.py +0 -0
  37. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/cli/categraf/__init__.py +0 -0
  38. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/cli/categraf/commands.py +0 -0
  39. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/cli/commands/vm.py +0 -0
  40. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/cli/common/__init__.py +0 -0
  41. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/cli/common/options.py +0 -0
  42. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/cli/common/utils.py +0 -0
  43. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/cli/formatters/__init__.py +0 -0
  44. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/cli/formatters/output.py +0 -0
  45. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/cli/main.py +0 -0
  46. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/cli.py +0 -0
  47. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/common/__init__.py +0 -0
  48. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/dida365.py +0 -0
  49. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/excel.py +0 -0
  50. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/feishu/client.py +0 -0
  51. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/feishu/endpoints.py +0 -0
  52. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/feishu/errors.py +0 -0
  53. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/feishu/helpers.py +0 -0
  54. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/feishu/typing.py +0 -0
  55. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/log/logger.py +0 -0
  56. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/log/victorialog.py +0 -0
  57. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/mail/alimail.py +0 -0
  58. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/mail/mail_detail.py +0 -0
  59. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/network/meraki.py +0 -0
  60. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/onepassword_connect.py +0 -0
  61. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/onepassword_sa.py +0 -0
  62. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/pyjira.py +0 -0
  63. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/utils/cronjob.py +0 -0
  64. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/utils/env.py +0 -0
  65. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/utils/load_config.py +0 -0
  66. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/utils/load_vm_devfile.py +0 -0
  67. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/utils/response.py +0 -0
  68. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/utils/richutils.py +0 -0
  69. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/utils/timeutils.py +0 -0
  70. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/vmware.py +0 -0
  71. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox/win/ad.py +0 -0
  72. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox.egg-info/SOURCES.txt +0 -0
  73. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox.egg-info/dependency_links.txt +0 -0
  74. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox.egg-info/entry_points.txt +0 -0
  75. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox.egg-info/requires.txt +0 -0
  76. {pytbox-0.1.8 → pytbox-0.1.9}/src/pytbox.egg-info/top_level.txt +0 -0
  77. {pytbox-0.1.8 → pytbox-0.1.9}/tests/test_base.py +0 -0
  78. {pytbox-0.1.8 → pytbox-0.1.9}/tests/test_feishu.py +0 -0
  79. {pytbox-0.1.8 → pytbox-0.1.9}/tests/test_load_jsonfile.py +0 -0
  80. {pytbox-0.1.8 → pytbox-0.1.9}/tests/test_logger.py +0 -0
  81. {pytbox-0.1.8 → pytbox-0.1.9}/tests/test_onepassword_connect.py +0 -0
  82. {pytbox-0.1.8 → pytbox-0.1.9}/tests/test_onepassword_sa.py +0 -0
  83. {pytbox-0.1.8 → pytbox-0.1.9}/tests/test_victoriametrics.py +0 -0
  84. {pytbox-0.1.8 → pytbox-0.1.9}/tests/test_vmware.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytbox
3
- Version: 0.1.8
3
+ Version: 0.1.9
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.1.8"
7
+ version = "0.1.9"
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"
@@ -7,6 +7,7 @@ from ..database.mongo import Mongo
7
7
  from ..feishu.client import Client as FeishuClient
8
8
  from ..dida365 import Dida365
9
9
  from ..utils.timeutils import TimeUtils
10
+ from ..mail.client import MailClient
10
11
 
11
12
 
12
13
  class AlertHandler:
@@ -15,12 +16,16 @@ class AlertHandler:
15
16
  config: dict=None,
16
17
  mongo_client: Mongo=None,
17
18
  feishu_client: FeishuClient=None,
18
- dida_client: Dida365=None
19
+ dida_client: Dida365=None,
20
+ mail_client: MailClient=None,
21
+ env: Literal['dev', 'prod']='prod'
19
22
  ):
20
23
  self.config = config
21
24
  self.mongo = mongo_client
22
25
  self.feishu = feishu_client
23
26
  self.dida = dida_client
27
+ self.mail = mail_client
28
+ self.env = env
24
29
 
25
30
  def send_alert(self,
26
31
  event_id: str=None,
@@ -34,7 +39,7 @@ class AlertHandler:
34
39
  suggestion: str='',
35
40
  troubleshot: str='暂无',
36
41
  mongo_id: str=None
37
- ):
42
+ ):
38
43
 
39
44
  if not event_id:
40
45
  event_id = str(uuid.uuid4())
@@ -62,11 +67,11 @@ class AlertHandler:
62
67
  update = {"$set": { "resolved_time": event_time}}
63
68
  self.mongo.collection.update_one(filter_doc, update)
64
69
  alarm_time = self.mongo.collection.find_one(filter_doc, {'event_time': 1})['event_time']
65
-
70
+
66
71
  content = [
67
72
  f'**事件名称**: {event_name}',
68
73
  f'**告警时间**: {TimeUtils.convert_timeobj_to_str(timeobj=event_time, timezone_offset=0) if event_type == "trigger" else TimeUtils.convert_timeobj_to_str(timeobj=alarm_time, timezone_offset=8)}',
69
- f'**事件内容**: {event_content}',
74
+ f'**事件内容**: {event_content + " 已恢复" if event_type == "resolved" else event_content}',
70
75
  f'**告警实例**: {entity_name}',
71
76
  f'**建议**: {suggestion}',
72
77
  f'**故障排查**: {troubleshot}',
@@ -78,17 +83,30 @@ class AlertHandler:
78
83
 
79
84
  if self.config['feishu']['enable_alert']:
80
85
  self.feishu.extensions.send_message_notify(
86
+ receive_id=self.config['feishu']['receive_id'],
81
87
  color='red' if event_type == "trigger" else 'green',
82
- title=event_content,
88
+ title=event_content + " 已恢复" if event_type == "resolved" else event_content,
83
89
  priority=priority,
84
- sub_title="",
90
+ sub_title='测试告警, 无需处理' if self.env == 'dev' else '',
85
91
  content='\n'.join(content)
86
92
  )
87
93
 
94
+ if self.config['mail']['enable_mail']:
95
+ if event_type == "trigger":
96
+ self.mail.send_mail(
97
+ receiver=[self.config['mail']['mail_address']],
98
+ subject=f'{self.config['mail']['subject_trigger']}, {event_content}',
99
+ contents=f'event_content:{event_content}, alarm_time: {str(event_time)}, event_id: {event_id}, alarm_name: {event_name}, entity_name: {entity_name}, priority: {priority}, automate_ts: {troubleshot}, suggestion: {suggestion}'
100
+ )
101
+ else:
102
+ self.mail.send_mail(
103
+ receiver=[self.config['mail']['mail_address']],
104
+ subject=f'{self.config['mail']['subject_resolved']}, {event_content}',
105
+ contents=f'event_content:{event_content}, alarm_time: {str(TimeUtils.get_now_time_mongo())}, event_id: {event_id}, alarm_name: {event_name}, entity_name: {entity_name}, priority: {priority}, automate_ts: {troubleshot}, suggestion: {suggestion}')
106
+
88
107
  if self.config['dida']['enable_alert']:
89
108
  if event_type == "trigger":
90
109
  res = self.dida.task_create(
91
-
92
110
  project_id=self.config['dida']['alert_project_id'],
93
111
  title=event_content,
94
112
  content='\n'.join(content),
@@ -8,7 +8,6 @@ from pytbox.feishu.client import Client as FeishuClient
8
8
  from pytbox.dida365 import Dida365
9
9
  from pytbox.alert.alert_handler import AlertHandler
10
10
  from pytbox.log.logger import AppLogger
11
- from pytbox.win.ad import ADClient
12
11
  from pytbox.network.meraki import Meraki
13
12
  from pytbox.utils.env import get_env_by_os_environment
14
13
  from pytbox.vmware import VMwareClient
@@ -110,6 +109,5 @@ sls = AliCloudSls(
110
109
  logstore=config['alicloud']['account1']['logstore']
111
110
  )
112
111
 
113
-
114
112
  def get_cronjob_counter(app_type='', app='', comment=None, schedule_interval=None, schedule_cron=None):
115
113
  return cronjob_counter(vm=vm, log=get_logger('cronjob_counter'), app_type=app_type, app=app, comment=comment, schedule_interval=schedule_interval, schedule_cron=schedule_cron)
@@ -80,7 +80,7 @@ class Mongo:
80
80
  alarm_list = []
81
81
  for result in results:
82
82
  duration_minute = '持续 ' + str(int((result['resolved_time'] - result['event_time']).total_seconds() / 60)) + ' 分钟'
83
- alarm_list.append('触发告警: ' + TimeUtils.convert_timeobj_to_str(timeobj=result['event_time']) + ' ' + duration_minute)
83
+ alarm_list.append('触发时间: ' + TimeUtils.convert_timeobj_to_str(timeobj=result['event_time']) + ' ' + duration_minute)
84
84
 
85
85
  alarm_str = '\n'.join(alarm_list)
86
86
 
@@ -230,7 +230,7 @@ class VictoriaMetrics:
230
230
  rate = r.data[0]['value'][1]
231
231
  return int(float(rate))
232
232
 
233
- def check_snmp_port_status(self, sysname: str=None, if_name: str=None, last_minute: int=5) -> ReturnResponse:
233
+ def check_snmp_port_status(self, sysname: str=None, if_name: str=None, last_minute: int=5, dev_file: str=None) -> ReturnResponse:
234
234
  '''
235
235
  查询端口状态
236
236
  status code 可参考 SNMP 文件 https://mibbrowser.online/mibdb_search.php?mib=IF-MIB
@@ -245,7 +245,10 @@ class VictoriaMetrics:
245
245
  code: 0, msg: , data: up,down
246
246
  '''
247
247
  q = f"""avg_over_time(snmp_interface_ifOperStatus{{sysName="{sysname}", ifName="{if_name}"}}[{last_minute}m])"""
248
- r = self.query(query=q)
248
+ if self.env == 'dev':
249
+ r = load_dev_file(dev_file)
250
+ else:
251
+ r = self.query(query=q)
249
252
  if r.code == 0:
250
253
  status_code = int(r.data[0]['value'][1])
251
254
  if status_code == 1:
@@ -27,6 +27,10 @@ class MailClient:
27
27
  elif 'foxmail.com' in mail_address:
28
28
  self.smtp_address = 'smtp.qq.com'
29
29
  self.imap_address = 'imap.qq.com'
30
+
31
+ elif 'mail' in mail_address and 'cn' in mail_address:
32
+ self.smtp_address = "smtpdm.aliyun.com"
33
+ self.imap_address = ""
30
34
 
31
35
  else:
32
36
  raise ValueError(f'不支持的邮箱地址: {mail_address}')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytbox
3
- Version: 0.1.8
3
+ Version: 0.1.9
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
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