pytbox 0.0.9__py3-none-any.whl → 0.1.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.
Potentially problematic release.
This version of pytbox might be problematic. Click here for more details.
- pytbox/categraf/build_config.py +73 -19
- pytbox/categraf/instances.toml +20 -1
- pytbox/categraf/jinja2/input.dns_query/dns_query.toml.j2 +12 -0
- pytbox/categraf/jinja2/input.net_response/net_response.toml.j2 +9 -0
- pytbox/categraf/jinja2/input.snmp/h3c_interface.toml.j2 +96 -0
- pytbox/categraf/jinja2/input.snmp/h3c_system.toml.j2 +41 -0
- {pytbox-0.0.9.dist-info → pytbox-0.1.0.dist-info}/METADATA +1 -1
- {pytbox-0.0.9.dist-info → pytbox-0.1.0.dist-info}/RECORD +11 -9
- {pytbox-0.0.9.dist-info → pytbox-0.1.0.dist-info}/WHEEL +0 -0
- {pytbox-0.0.9.dist-info → pytbox-0.1.0.dist-info}/entry_points.txt +0 -0
- {pytbox-0.0.9.dist-info → pytbox-0.1.0.dist-info}/top_level.txt +0 -0
pytbox/categraf/build_config.py
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import os
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from pytbox.utils.load_config import load_config_by_file
|
|
6
|
-
|
|
6
|
+
from glob import glob
|
|
7
|
+
import os
|
|
7
8
|
from jinja2 import Environment, FileSystemLoader
|
|
8
9
|
|
|
9
10
|
|
|
@@ -61,7 +62,6 @@ class BuildConfig:
|
|
|
61
62
|
def vsphere(self):
|
|
62
63
|
template = self._get_template('input.vsphere/vsphere.toml.j2')
|
|
63
64
|
instances = self.instances['vsphere']['instance']
|
|
64
|
-
print(instances)
|
|
65
65
|
render_data = template.render(instances=instances)
|
|
66
66
|
target_dir = Path(self.output_dir) / 'input.vsphere'
|
|
67
67
|
if not target_dir.exists():
|
|
@@ -71,21 +71,75 @@ class BuildConfig:
|
|
|
71
71
|
|
|
72
72
|
def http_response(self):
|
|
73
73
|
template = self._get_template('input.http_response/http_response.toml.j2')
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
target_dir.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
if self.instances.get('http_response'):
|
|
75
|
+
instances = self.instances['http_response']['instance']
|
|
76
|
+
render_data = template.render(instances=instances)
|
|
77
|
+
target_dir = Path(self.output_dir) / 'input.http_response'
|
|
78
|
+
if not target_dir.exists():
|
|
79
|
+
target_dir.mkdir(parents=True, exist_ok=True)
|
|
80
|
+
with open(Path(self.output_dir) / 'input.http_response' / 'http_response.toml', 'w', encoding='utf-8') as f:
|
|
81
|
+
f.write(render_data)
|
|
82
|
+
|
|
83
|
+
def net_response(self):
|
|
84
|
+
template = self._get_template('input.net_response/net_response.toml.j2')
|
|
85
|
+
if self.instances.get('net_response'):
|
|
86
|
+
instances = self.instances['net_response']['instance']
|
|
87
|
+
render_data = template.render(instances=instances)
|
|
88
|
+
target_dir = Path(self.output_dir) / 'input.net_response'
|
|
89
|
+
if not target_dir.exists():
|
|
90
|
+
target_dir.mkdir(parents=True, exist_ok=True)
|
|
91
|
+
with open(Path(self.output_dir) / 'input.net_response' / 'net_response.toml', 'w', encoding='utf-8') as f:
|
|
92
|
+
f.write(render_data)
|
|
93
|
+
|
|
94
|
+
def dns_query(self):
|
|
95
|
+
template = self._get_template('input.dns_query/dns_query.toml.j2')
|
|
96
|
+
if self.instances.get('dns_query'):
|
|
97
|
+
instances = self.instances['dns_query']['instance']
|
|
98
|
+
render_data = template.render(instances=instances)
|
|
99
|
+
target_dir = Path(self.output_dir) / 'input.dns_query'
|
|
100
|
+
if not target_dir.exists():
|
|
101
|
+
target_dir.mkdir(parents=True, exist_ok=True)
|
|
102
|
+
with open(Path(self.output_dir) / 'input.dns_query' / 'dns_query.toml', 'w', encoding='utf-8') as f:
|
|
103
|
+
f.write(render_data)
|
|
104
|
+
|
|
105
|
+
def snmp(self):
|
|
106
|
+
if self.instances.get('snmp'):
|
|
107
|
+
device_types = self.instances['snmp']['instances']
|
|
108
|
+
for device_type in device_types:
|
|
109
|
+
instances = self.instances['snmp']['instances'][device_type]
|
|
110
|
+
jinja2_dir = Path(jinja2_path) / 'input.snmp'
|
|
111
|
+
device_templates = glob(str(jinja2_dir / f'{device_type}_*.toml.j2'))
|
|
112
|
+
if not device_templates:
|
|
113
|
+
continue
|
|
114
|
+
|
|
115
|
+
for tmpl_path in device_templates:
|
|
116
|
+
tmpl_name = os.path.basename(tmpl_path)
|
|
117
|
+
# 例如 h3c_system.toml.j2 -> h3c_system
|
|
118
|
+
base_name = tmpl_name.replace('.toml.j2', '')
|
|
119
|
+
|
|
120
|
+
template = self._get_template(f'input.snmp/{tmpl_name}')
|
|
121
|
+
# 修复数据结构:模板期望的是数组,每个元素是字典
|
|
122
|
+
# instances 是 [{"udp://10.1.1.1:161": {...}, "udp://10.1.1.2:161": {...}}, ...]
|
|
123
|
+
render_data = template.render(instances=instances)
|
|
124
|
+
|
|
125
|
+
target_dir = Path(self.output_dir) / 'input.snmp'
|
|
126
|
+
if not target_dir.exists():
|
|
127
|
+
target_dir.mkdir(parents=True, exist_ok=True)
|
|
128
|
+
|
|
129
|
+
output_file = target_dir / f'{base_name}.toml'
|
|
130
|
+
with open(output_file, 'w', encoding='utf-8') as f:
|
|
131
|
+
f.write(render_data)
|
|
132
|
+
|
|
82
133
|
def run(self):
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
self.http_response()
|
|
134
|
+
self.common('cpu')
|
|
135
|
+
self.common('mem')
|
|
136
|
+
self.common('net')
|
|
137
|
+
self.common('disk')
|
|
138
|
+
self.common('diskio')
|
|
139
|
+
self.vsphere()
|
|
140
|
+
self.ping()
|
|
141
|
+
self.prometheus()
|
|
142
|
+
self.http_response()
|
|
143
|
+
self.net_response()
|
|
144
|
+
self.dns_query()
|
|
145
|
+
self.snmp()
|
pytbox/categraf/instances.toml
CHANGED
|
@@ -13,4 +13,23 @@
|
|
|
13
13
|
|
|
14
14
|
[http_response]
|
|
15
15
|
[[http_response.instance]]
|
|
16
|
-
"https://www.baidu.com" = { name = "x", env = "prod" }
|
|
16
|
+
"https://www.baidu.com" = { name = "x", env = "prod" }
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
[net_response]
|
|
20
|
+
[[net_response.instance]]
|
|
21
|
+
"124.74.245.90:8443" = { name = "x", env = "prod" }
|
|
22
|
+
|
|
23
|
+
[dns_query]
|
|
24
|
+
[[dns_query.instance]]
|
|
25
|
+
"119.29.29.29_baidu.com" = { dns_server = "119.29.29.29", domains = "www.baidu.com", labels = { name = "x", env = "prod" } }
|
|
26
|
+
|
|
27
|
+
[snmp]
|
|
28
|
+
[[snmp.instances.h3c]]
|
|
29
|
+
"10.1.1.1:161" = { version = 2, community = "public" }
|
|
30
|
+
"10.1.1.2:161" = { version = 2, community = "public" }
|
|
31
|
+
"10.1.1.3:161" = { version = 3, sec_name = "sec", auth_protocol = "SHA", auth_password = "pass01", priv_protocol = "AES", priv_password = "pass02", sec_level = "authPriv" }
|
|
32
|
+
|
|
33
|
+
# [[snmp.instances.huawei]]
|
|
34
|
+
# "udp://172.16.1.1:161" = { version = 2, community = "public"}
|
|
35
|
+
# "udp://172.16.1.2:161" = { version = 2, community = "public"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{% for instance in instances %}
|
|
2
|
+
{% for name, data in instance.items() %}
|
|
3
|
+
[[instances]]
|
|
4
|
+
# append some labels for series
|
|
5
|
+
labels = { {% for k, v in data['labels'].items() %}{% if not loop.first %}, {% endif %}{% if k.isidentifier() %}{{ k }}{% else %}"{{ k }}"{% endif %} = "{{ v }}"{% endfor %} }
|
|
6
|
+
servers = ["{{ data['dns_server'] }}"]
|
|
7
|
+
## Domains or subdomains to query.
|
|
8
|
+
domains = ["{{ data['domains'] }}"]
|
|
9
|
+
record_type = "A"
|
|
10
|
+
timeout = 2
|
|
11
|
+
{% endfor %}
|
|
12
|
+
{% endfor %}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{% for instance in instances %}
|
|
2
|
+
{% for target, labels in instance.items() %}
|
|
3
|
+
[[instances]]
|
|
4
|
+
targets = [
|
|
5
|
+
"{{ target }}"
|
|
6
|
+
]
|
|
7
|
+
labels = { {% for k, v in labels.items() %}{% if not loop.first %}, {% endif %}{% if k.isidentifier() %}{{ k }}{% else %}"{{ k }}"{% endif %} = "{{ v }}"{% endfor %} }
|
|
8
|
+
{% endfor %}
|
|
9
|
+
{% endfor %}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{% for instance in instances %}
|
|
2
|
+
{% for agent, detail in instance.items() %}
|
|
3
|
+
[[instances]]
|
|
4
|
+
agents = [
|
|
5
|
+
"udp://{{agent}}"
|
|
6
|
+
]
|
|
7
|
+
{% if detail.version == 2 %}
|
|
8
|
+
version = {{detail.version}}
|
|
9
|
+
community = "{{detail.community}}"
|
|
10
|
+
{% endif %}
|
|
11
|
+
{% if detail.version == 3 %}
|
|
12
|
+
version = {{detail.version}}
|
|
13
|
+
sec_name = "{{detail.sec_name}}"
|
|
14
|
+
auth_protocol = "{{detail.auth_protocol}}"
|
|
15
|
+
auth_password = "{{detail.auth_password}}"
|
|
16
|
+
priv_protocol = "{{detail.priv_protocol}}"
|
|
17
|
+
priv_password = "{{detail.priv_password}}"
|
|
18
|
+
sec_level = "{{detail.sec_level}}"
|
|
19
|
+
{% endif %}
|
|
20
|
+
timeout = "5s"
|
|
21
|
+
retries = 3
|
|
22
|
+
path = ["/usr/share/snmp/mibs"]
|
|
23
|
+
translator = "gosmi"
|
|
24
|
+
max_repetitions = 50
|
|
25
|
+
|
|
26
|
+
[[instances.field]]
|
|
27
|
+
name = "sysName"
|
|
28
|
+
oid = "1.3.6.1.2.1.1.5.0"
|
|
29
|
+
is_tag = true
|
|
30
|
+
|
|
31
|
+
[[instances.table]]
|
|
32
|
+
name = "interface"
|
|
33
|
+
inherit_tags = ["sysName"]
|
|
34
|
+
index_as_tag = true
|
|
35
|
+
|
|
36
|
+
[[instances.table.field]]
|
|
37
|
+
name = "ifIndex"
|
|
38
|
+
oid = "1.3.6.1.2.1.2.2.1.1"
|
|
39
|
+
is_tag = true
|
|
40
|
+
|
|
41
|
+
[[instances.table.field]]
|
|
42
|
+
name = "ifName"
|
|
43
|
+
oid = "1.3.6.1.2.1.31.1.1.1.1"
|
|
44
|
+
is_tag = true
|
|
45
|
+
|
|
46
|
+
[[instances.table.field]]
|
|
47
|
+
name = "ifDescr"
|
|
48
|
+
oid = "1.3.6.1.2.1.2.2.1.2"
|
|
49
|
+
is_tag = true
|
|
50
|
+
|
|
51
|
+
[[instances.table.field]]
|
|
52
|
+
name = "ifSpeed"
|
|
53
|
+
oid = "1.3.6.1.2.1.2.2.1.5"
|
|
54
|
+
# is_tag = true
|
|
55
|
+
|
|
56
|
+
[[instances.table.field]]
|
|
57
|
+
name = "ifAdminStatus"
|
|
58
|
+
oid = "1.3.6.1.2.1.2.2.1.7"
|
|
59
|
+
# is_tag = true
|
|
60
|
+
|
|
61
|
+
[[instances.table.field]]
|
|
62
|
+
name = "ifOperStatus"
|
|
63
|
+
oid = "1.3.6.1.2.1.2.2.1.8"
|
|
64
|
+
# is_tag = true
|
|
65
|
+
|
|
66
|
+
[[instances.table.field]]
|
|
67
|
+
name = "ifInDiscards"
|
|
68
|
+
oid = "1.3.6.1.2.1.2.2.1.13"
|
|
69
|
+
|
|
70
|
+
[[instances.table.field]]
|
|
71
|
+
name = "ifInErrors"
|
|
72
|
+
oid = "1.3.6.1.2.1.2.2.1.14"
|
|
73
|
+
|
|
74
|
+
[[instances.table.field]]
|
|
75
|
+
name = "ifOutDiscards"
|
|
76
|
+
oid = "1.3.6.1.2.1.2.2.1.19"
|
|
77
|
+
|
|
78
|
+
[[instances.table.field]]
|
|
79
|
+
name = "ifOutErrors"
|
|
80
|
+
oid = "1.3.6.1.2.1.2.2.1.20"
|
|
81
|
+
|
|
82
|
+
[[instances.table.field]]
|
|
83
|
+
name = "ifAlias"
|
|
84
|
+
oid = "1.3.6.1.2.1.31.1.1.1.18"
|
|
85
|
+
is_tag = true
|
|
86
|
+
|
|
87
|
+
[[instances.table.field]]
|
|
88
|
+
name = "ifHCInOctets"
|
|
89
|
+
oid = "1.3.6.1.2.1.31.1.1.1.6"
|
|
90
|
+
|
|
91
|
+
[[instances.table.field]]
|
|
92
|
+
name = "ifHCOutOctets"
|
|
93
|
+
oid = "1.3.6.1.2.1.31.1.1.1.10"
|
|
94
|
+
|
|
95
|
+
{% endfor %}
|
|
96
|
+
{% endfor %}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{% for instance in instances %}
|
|
2
|
+
{% for agent, detail in instance.items() %}
|
|
3
|
+
[[instances]]
|
|
4
|
+
agents = [
|
|
5
|
+
"udp://{{agent}}"
|
|
6
|
+
]
|
|
7
|
+
{% if detail.version == 2 %}
|
|
8
|
+
version = {{detail.version}}
|
|
9
|
+
community = "{{detail.community}}"
|
|
10
|
+
{% endif %}
|
|
11
|
+
{% if detail.version == 3 %}
|
|
12
|
+
version = {{detail.version}}
|
|
13
|
+
sec_name = "{{detail.sec_name}}"
|
|
14
|
+
auth_protocol = "{{detail.auth_protocol}}"
|
|
15
|
+
auth_password = "{{detail.auth_password}}"
|
|
16
|
+
priv_protocol = "{{detail.priv_protocol}}"
|
|
17
|
+
priv_password = "{{detail.priv_password}}"
|
|
18
|
+
sec_level = "{{detail.sec_level}}"
|
|
19
|
+
{% endif %}
|
|
20
|
+
timeout = "5s"
|
|
21
|
+
retries = 3
|
|
22
|
+
path = ["/usr/share/snmp/mibs"]
|
|
23
|
+
translator = "gosmi"
|
|
24
|
+
max_repetitions = 50
|
|
25
|
+
|
|
26
|
+
[[instances.field]]
|
|
27
|
+
name = "sysName"
|
|
28
|
+
oid = "1.3.6.1.2.1.1.5.0"
|
|
29
|
+
is_tag = true
|
|
30
|
+
|
|
31
|
+
[[instances.field]]
|
|
32
|
+
oid = "1.3.6.1.2.1.1.1.0"
|
|
33
|
+
name = "sysDescr"
|
|
34
|
+
is_tag = true
|
|
35
|
+
|
|
36
|
+
[[instances.field]]
|
|
37
|
+
oid = "1.3.6.1.2.1.1.3.0"
|
|
38
|
+
name = "sysUpTime"
|
|
39
|
+
conversion = "float(2)"
|
|
40
|
+
{% endfor %}
|
|
41
|
+
{% endfor %}
|
|
@@ -6,19 +6,21 @@ pytbox/onepassword_sa.py,sha256=08iUcYud3aEHuQcUsem9bWNxdXKgaxFbMy9yvtr-DZQ,6995
|
|
|
6
6
|
pytbox/alert/alert_handler.py,sha256=FePPQS4LyGphSJ0QMv0_pLWaXxEqsRlcTKMfUjtsNfk,5048
|
|
7
7
|
pytbox/alert/ping.py,sha256=g36X0U3U8ndZqfpVIcuoxJJ0X5gST3I_IwjTQC1roHA,779
|
|
8
8
|
pytbox/alicloud/sls.py,sha256=UR4GdI86dCKAFI2xt_1DELu7q743dpd3xrYtuNpfC5A,4065
|
|
9
|
-
pytbox/categraf/build_config.py,sha256=
|
|
10
|
-
pytbox/categraf/instances.toml,sha256=
|
|
9
|
+
pytbox/categraf/build_config.py,sha256=sm1knLDN2PAuOj4ljxfFCESDa2a4Orcj0x8P1-wTK1c,6323
|
|
10
|
+
pytbox/categraf/instances.toml,sha256=1fTjEZUDGb600RPdBYof_XtkTuUUePmhPB-Tn7u_3G0,1165
|
|
11
11
|
pytbox/categraf/jinja2/__init__.py,sha256=Epm01j8Oujeg4Sk5GgHMvgKIZ6h3BTx-MGmuMgIjUMo,150
|
|
12
12
|
pytbox/categraf/jinja2/input.cpu/cpu.toml.j2,sha256=wxpyLDNvz2ViZK-0a4EgH35Zsg82CwMwijOtT0nBfTI,92
|
|
13
13
|
pytbox/categraf/jinja2/input.disk/disk.toml.j2,sha256=kOWwVF6u7x2huLVa4eBIOhC8R13DXmw0PD9o3HXwEZo,420
|
|
14
14
|
pytbox/categraf/jinja2/input.diskio/diskio.toml.j2,sha256=33E4L1mkUkJOocUsSgpW5zoFCzvx5ogfbnm2jkwzLx8,227
|
|
15
|
-
pytbox/categraf/jinja2/input.dns_query/dns_query.toml.j2,sha256
|
|
15
|
+
pytbox/categraf/jinja2/input.dns_query/dns_query.toml.j2,sha256=-oMkIMtCg4zq_oGENrm9aUzUzVkWmgxPSrGlwo2k2Pc,461
|
|
16
16
|
pytbox/categraf/jinja2/input.http_response/http_response.toml.j2,sha256=Qp1EOxx7TC7_cH69KqMVwbfCKrD5xbbVO2drVdkvo6s,317
|
|
17
17
|
pytbox/categraf/jinja2/input.mem/mem.toml.j2,sha256=_-qJyE0K_76IMehbN1xq1hi9vY1Y1Jp4TuITzaLjCg4,116
|
|
18
18
|
pytbox/categraf/jinja2/input.net/net.toml.j2,sha256=yodVoT1f7bcuNMFFmAvc7WhORUsTnM92IhpWQHXfY_U,279
|
|
19
|
-
pytbox/categraf/jinja2/input.net_response/net_response.toml.j2,sha256=
|
|
19
|
+
pytbox/categraf/jinja2/input.net_response/net_response.toml.j2,sha256=Qp1EOxx7TC7_cH69KqMVwbfCKrD5xbbVO2drVdkvo6s,317
|
|
20
20
|
pytbox/categraf/jinja2/input.ping/ping.toml.j2,sha256=UCRy_IVoI_FDQxfsDpGS-aZJasFG1sf67ScN9U8YVIo,344
|
|
21
21
|
pytbox/categraf/jinja2/input.prometheus/prometheus.toml.j2,sha256=6ax30L1sAUreojlzf0v26GzOAiheCP0Lj7n5IIjgco0,384
|
|
22
|
+
pytbox/categraf/jinja2/input.snmp/h3c_interface.toml.j2,sha256=pamihAFrsnoKgeR6gw6i7fJYX9VnNmxiRcBdYnRsy9Y,1930
|
|
23
|
+
pytbox/categraf/jinja2/input.snmp/h3c_system.toml.j2,sha256=W0zYf1OZ_oil8n9Pe1Bhl3NtVJQPvLETv6GAp1sRVl0,914
|
|
22
24
|
pytbox/categraf/jinja2/input.vsphere/vsphere.toml.j2,sha256=7SCo8DSh5Uuy-7MeWw-soy6sqblK54k6K2WWSlimELk,8396
|
|
23
25
|
pytbox/cli/__init__.py,sha256=5ID4-oXrMsHFcfDsQeXDYeThPOuQ1Fl2x2kHWfgfOEw,67
|
|
24
26
|
pytbox/cli/main.py,sha256=S-DBp-1d0BCpvZ7jRE3bYmhKSiPpCJHFGsbdVF485BY,322
|
|
@@ -45,8 +47,8 @@ pytbox/utils/ping_checker.py,sha256=Nqnn8clbgv-5l0PgxcTOldg8mkMKrFn4TvPL-rYUUGg,
|
|
|
45
47
|
pytbox/utils/response.py,sha256=kXjlwt0WVmLRam2eu1shzX2cQ7ux4cCQryaPGYwle5g,1247
|
|
46
48
|
pytbox/utils/richutils.py,sha256=OT9_q2Q1bthzB0g1GlhZVvM4ZAepJRKL6a_Vsr6vEqo,487
|
|
47
49
|
pytbox/utils/timeutils.py,sha256=XbK2KB-SVi7agNqoQN7i40wysrZvrGuwebViv1Cw-Ok,20226
|
|
48
|
-
pytbox-0.0.
|
|
49
|
-
pytbox-0.0.
|
|
50
|
-
pytbox-0.0.
|
|
51
|
-
pytbox-0.0.
|
|
52
|
-
pytbox-0.0.
|
|
50
|
+
pytbox-0.1.0.dist-info/METADATA,sha256=JdN0lGZwixetlK_LpIuAU23ABRFjtyZv40lb05DraWo,6256
|
|
51
|
+
pytbox-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
52
|
+
pytbox-0.1.0.dist-info/entry_points.txt,sha256=YaTOJ2oPjOiv2SZwY0UC-UA9QS2phRH1oMvxGnxO0Js,43
|
|
53
|
+
pytbox-0.1.0.dist-info/top_level.txt,sha256=YADgWue-Oe128ptN3J2hS3GB0Ncc5uZaSUM3e1rwswE,7
|
|
54
|
+
pytbox-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|