data-ops-cli 0.3.0__tar.gz → 0.3.3__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.
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/PKG-INFO +2 -2
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/pyproject.toml +2 -2
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/data_ops_cli.egg-info/PKG-INFO +2 -2
- data_ops_cli-0.3.3/src/data_ops_cli.egg-info/requires.txt +7 -0
- data_ops_cli-0.3.3/src/dataops_cli/__init__.py +17 -0
- data_ops_cli-0.3.3/src/dataops_cli/_compat.py +81 -0
- data_ops_cli-0.3.3/src/dataops_cli/cli/__init__.py +9 -0
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/alarm.py +158 -47
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/api.py +29 -16
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/auth.py +30 -14
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/data_table.py +41 -22
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/dataset.py +45 -15
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/datasource.py +46 -15
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/dict_.py +27 -22
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/factory.py +20 -0
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/hazard.py +72 -30
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/metrics.py +15 -8
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/ref.py +55 -38
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/report.py +12 -8
- data_ops_cli-0.3.3/src/dataops_cli/cli/skill.py +340 -0
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/table.py +99 -54
- data_ops_cli-0.3.3/src/dataops_cli/cli/utils.py +96 -0
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/widget.py +114 -27
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/dataops_cli/cli/workflow.py +36 -20
- data_ops_cli-0.3.3/src/dataops_cli/exceptions.py +10 -0
- data_ops_cli-0.3.3/src/dataops_cli/runner.py +14 -0
- data_ops_cli-0.3.3/src/dataops_cli/schems.py +11 -0
- data_ops_cli-0.3.3/src/dataops_cli/sdk.py +14 -0
- data_ops_cli-0.3.3/src/dataops_cli/session.py +10 -0
- data_ops_cli-0.3.3/src/dataops_cli/utils.py +10 -0
- data_ops_cli-0.3.0/src/data_ops_cli.egg-info/requires.txt +0 -7
- data_ops_cli-0.3.0/src/dataops_cli/__init__.py +0 -11
- data_ops_cli-0.3.0/src/dataops_cli/_compat.py +0 -53
- data_ops_cli-0.3.0/src/dataops_cli/cli/__init__.py +0 -3
- data_ops_cli-0.3.0/src/dataops_cli/cli/skill.py +0 -303
- data_ops_cli-0.3.0/src/dataops_cli/cli/utils.py +0 -32
- data_ops_cli-0.3.0/src/dataops_cli/exceptions.py +0 -8
- data_ops_cli-0.3.0/src/dataops_cli/runner.py +0 -8
- data_ops_cli-0.3.0/src/dataops_cli/schems.py +0 -8
- data_ops_cli-0.3.0/src/dataops_cli/sdk.py +0 -8
- data_ops_cli-0.3.0/src/dataops_cli/session.py +0 -8
- data_ops_cli-0.3.0/src/dataops_cli/utils.py +0 -8
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/setup.cfg +0 -0
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/data_ops_cli.egg-info/SOURCES.txt +0 -0
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/data_ops_cli.egg-info/dependency_links.txt +0 -0
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/data_ops_cli.egg-info/entry_points.txt +0 -0
- {data_ops_cli-0.3.0 → data_ops_cli-0.3.3}/src/data_ops_cli.egg-info/top_level.txt +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: data-ops-cli
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: Command-line wrapper around dataops_sdk for the DataOps platform.
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
|
-
Requires-Dist:
|
|
6
|
+
Requires-Dist: dataops-sdk[runner]>=0.3.2
|
|
7
7
|
Requires-Dist: typer
|
|
8
8
|
Requires-Dist: rich
|
|
9
9
|
Provides-Extra: dev
|
|
@@ -8,7 +8,7 @@ dynamic = ["version"]
|
|
|
8
8
|
description = "Command-line wrapper around dataops_sdk for the DataOps platform."
|
|
9
9
|
requires-python = ">=3.11"
|
|
10
10
|
dependencies = [
|
|
11
|
-
"
|
|
11
|
+
"dataops-sdk[runner]>=0.3.2",
|
|
12
12
|
"typer",
|
|
13
13
|
"rich",
|
|
14
14
|
]
|
|
@@ -34,4 +34,4 @@ where = ["src"]
|
|
|
34
34
|
include = ["dataops_cli*"]
|
|
35
35
|
|
|
36
36
|
[tool.setuptools.package-data]
|
|
37
|
-
dataops_cli = ["py.typed"]
|
|
37
|
+
dataops_cli = ["py.typed"]
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: data-ops-cli
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: Command-line wrapper around dataops_sdk for the DataOps platform.
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
|
-
Requires-Dist:
|
|
6
|
+
Requires-Dist: dataops-sdk[runner]>=0.3.2
|
|
7
7
|
Requires-Dist: typer
|
|
8
8
|
Requires-Dist: rich
|
|
9
9
|
Provides-Extra: dev
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""CLI package for DataOps.
|
|
2
|
+
|
|
3
|
+
This package hosts the Typer-based ``data-ops-cli`` command line interface. It
|
|
4
|
+
groups command modules under :mod:`dataops_cli.cli` and re-exports the package
|
|
5
|
+
``__version__``. Platform functionality lives in the companion
|
|
6
|
+
``dataops_sdk`` package; the CLI itself only wires commands onto SDK services.
|
|
7
|
+
|
|
8
|
+
.. deprecated::
|
|
9
|
+
Importing the legacy top-level shims
|
|
10
|
+
(``dataops_cli.sdk`` / ``dataops_cli.schems`` / ``dataops_cli.runner`` /
|
|
11
|
+
``dataops_cli.exceptions`` / ``dataops_cli.session`` /
|
|
12
|
+
``dataops_cli.utils``) is deprecated; use ``dataops_sdk`` instead. The CLI
|
|
13
|
+
itself (``dataops_cli.cli``) is unaffected. These deprecation shims will be
|
|
14
|
+
removed in ``dataops_cli`` 1.0.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
__version__ = "0.3.3"
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Build a deprecation-shim module via PEP 562 ``__getattr__``.
|
|
2
|
+
|
|
3
|
+
This helper is used by the legacy top-level shims
|
|
4
|
+
(``dataops_cli.sdk`` / ``dataops_cli.schems`` / ``dataops_cli.runner`` /
|
|
5
|
+
``dataops_cli.exceptions`` / ``dataops_cli.session`` /
|
|
6
|
+
``dataops_cli.utils``). Each shim file's body is a single call to
|
|
7
|
+
:func:`make_shim`. The returned namespace exposes ``__all__`` and a
|
|
8
|
+
``__getattr__`` that proxies to the underlying ``dataops_sdk`` module while
|
|
9
|
+
emitting a single ``DeprecationWarning`` per attribute name (so logging stays
|
|
10
|
+
bounded).
|
|
11
|
+
|
|
12
|
+
.. deprecated::
|
|
13
|
+
The shim modules themselves are deprecated; new code should import from
|
|
14
|
+
``dataops_sdk`` directly. This helper module will be removed in
|
|
15
|
+
``dataops_cli`` 1.0.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import importlib
|
|
21
|
+
import sys
|
|
22
|
+
import warnings
|
|
23
|
+
from types import ModuleType
|
|
24
|
+
from typing import Any
|
|
25
|
+
|
|
26
|
+
# Mapping from legacy ``dataops_cli.*`` module paths to their ``dataops_sdk``
|
|
27
|
+
# replacements. Used by :func:`make_shim` to resolve the target module.
|
|
28
|
+
_OLD_TO_NEW = {
|
|
29
|
+
"dataops_cli.sdk": "dataops_sdk.services",
|
|
30
|
+
"dataops_cli.schems": "dataops_sdk.schemas",
|
|
31
|
+
"dataops_cli.runner": "dataops_sdk.runner",
|
|
32
|
+
"dataops_cli.exceptions": "dataops_sdk.exceptions",
|
|
33
|
+
"dataops_cli.session": "dataops_sdk.session",
|
|
34
|
+
"dataops_cli.utils": "dataops_sdk.utils",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def make_shim(old_path: str) -> ModuleType:
|
|
39
|
+
"""Create (and register in ``sys.modules``) a shim module proxying to ``new_path``.
|
|
40
|
+
|
|
41
|
+
The new module is wired with PEP 562 ``__getattr__`` so that attribute
|
|
42
|
+
access is lazily forwarded to ``dataops_sdk`` and emits a single
|
|
43
|
+
``DeprecationWarning`` per attribute name on first access. ``__all__`` and
|
|
44
|
+
``__dir__`` are forwarded from the target module so ``import *`` and
|
|
45
|
+
introspection behave naturally.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
old_path: The legacy module path (e.g. ``"dataops_cli.sdk"``). Must be
|
|
49
|
+
a key in :data:`_OLD_TO_NEW`.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
The freshly created proxy module, also registered in :data:`sys.modules`
|
|
53
|
+
under ``old_path``.
|
|
54
|
+
|
|
55
|
+
.. deprecated::
|
|
56
|
+
Only used to construct the legacy ``dataops_cli.*`` shims. Will be
|
|
57
|
+
removed in ``dataops_cli`` 1.0 alongside the shims themselves.
|
|
58
|
+
"""
|
|
59
|
+
new_path = _OLD_TO_NEW[old_path]
|
|
60
|
+
target = importlib.import_module(new_path)
|
|
61
|
+
warned: set[str] = set()
|
|
62
|
+
|
|
63
|
+
def __getattr__(name: str) -> Any:
|
|
64
|
+
"""PEP 562 attribute lookup that warns once per attribute name."""
|
|
65
|
+
if name not in warned:
|
|
66
|
+
warned.add(name)
|
|
67
|
+
warnings.warn(
|
|
68
|
+
f"Importing '{name}' from '{old_path}' is deprecated; "
|
|
69
|
+
f"import it from '{new_path}' instead. "
|
|
70
|
+
"This shim will be removed in dataops_cli 1.0.",
|
|
71
|
+
DeprecationWarning,
|
|
72
|
+
stacklevel=2,
|
|
73
|
+
)
|
|
74
|
+
return getattr(target, name)
|
|
75
|
+
|
|
76
|
+
module = ModuleType(old_path)
|
|
77
|
+
module.__getattr__ = __getattr__ # type: ignore[attr-defined]
|
|
78
|
+
module.__all__ = getattr(target, "__all__", []) # type: ignore[attr-defined]
|
|
79
|
+
module.__dir__ = lambda: list(dir(target)) # type: ignore[attr-defined]
|
|
80
|
+
sys.modules[old_path] = module
|
|
81
|
+
return module
|
|
@@ -7,14 +7,9 @@
|
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
import json
|
|
10
|
-
from typing import Annotated, Any
|
|
10
|
+
from typing import Annotated, Any
|
|
11
11
|
|
|
12
12
|
import typer
|
|
13
|
-
from pydantic_core import to_json
|
|
14
|
-
from rich.console import Console
|
|
15
|
-
from rich.table import Table
|
|
16
|
-
|
|
17
|
-
from dataops_cli.cli.utils import print_list
|
|
18
13
|
from dataops_sdk.exceptions import DataOpsError
|
|
19
14
|
from dataops_sdk.schemas.query import SqlQueryParam
|
|
20
15
|
from dataops_sdk.services.alarm import (
|
|
@@ -32,12 +27,17 @@ from dataops_sdk.services.alarm import (
|
|
|
32
27
|
service_list_alarm_rules,
|
|
33
28
|
service_list_alarm_specs,
|
|
34
29
|
)
|
|
30
|
+
from pydantic_core import to_json
|
|
31
|
+
from rich.console import Console
|
|
32
|
+
from rich.table import Table
|
|
33
|
+
|
|
34
|
+
from dataops_cli.cli.utils import print_list
|
|
35
35
|
|
|
36
36
|
# ---------------------------------------------------------------------------
|
|
37
37
|
# CLI 命令(薄包装,负责输出渲染)
|
|
38
38
|
# ---------------------------------------------------------------------------
|
|
39
39
|
|
|
40
|
-
alarm_typer = typer.Typer(name="alarm", help="
|
|
40
|
+
alarm_typer = typer.Typer(name="alarm", help="告警规则配置", no_args_is_help=True)
|
|
41
41
|
alarm_rule_typer = typer.Typer(name="rule", help="告警规则命令", no_args_is_help=True)
|
|
42
42
|
alarm_spec_typer = typer.Typer(name="spec", help="告警专业命令", no_args_is_help=True)
|
|
43
43
|
alarm_action_typer = typer.Typer(name="action", help="告警动作命令", no_args_is_help=True)
|
|
@@ -90,9 +90,21 @@ def _print_column_list(data: Any) -> None:
|
|
|
90
90
|
@rule_match_typer.command("count", help="查询告警匹配规则数量")
|
|
91
91
|
def count_alarm_rules_match(
|
|
92
92
|
spec: Annotated[list[str], typer.Option(help="专业值", default_factory=list)],
|
|
93
|
-
query: Annotated[
|
|
94
|
-
enabled: Annotated[
|
|
93
|
+
query: Annotated[str | None, typer.Option("-q", "--query", help="搜索关键字")] = None,
|
|
94
|
+
enabled: Annotated[bool | None, typer.Option(help="启用状态")] = None,
|
|
95
95
|
):
|
|
96
|
+
"""查询告警匹配规则数量。
|
|
97
|
+
|
|
98
|
+
按专业、关键字与启用状态进行过滤,返回匹配规则的总数。
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
spec: 专业值列表,多个值会同时参与匹配。
|
|
102
|
+
query: 可选关键字,用于模糊搜索。
|
|
103
|
+
enabled: 可选启用状态过滤;为 ``True`` / ``False`` 时严格匹配。
|
|
104
|
+
|
|
105
|
+
Examples:
|
|
106
|
+
>>> data-ops-cli alarm rule match count --spec MY_SPEC
|
|
107
|
+
"""
|
|
96
108
|
try:
|
|
97
109
|
total = service_count_alarm_rule_matches(query, enabled, spec)
|
|
98
110
|
except DataOpsError as e:
|
|
@@ -104,13 +116,27 @@ def count_alarm_rules_match(
|
|
|
104
116
|
@rule_match_typer.command("list", help="查询告警匹配规则")
|
|
105
117
|
def list_alarm_rules_match(
|
|
106
118
|
spec: Annotated[list[str], typer.Option(help="专业值", default_factory=list)],
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
query: Annotated[
|
|
110
|
-
enabled: Annotated[
|
|
119
|
+
page_num: Annotated[int, typer.Option("-n", "--page-num", help="页码")] = 0,
|
|
120
|
+
page_size: Annotated[int, typer.Option("-s", "--page-size", help="每页大小")] = 20,
|
|
121
|
+
query: Annotated[str | None, typer.Option("-q", "--query", help="搜索关键字")] = None,
|
|
122
|
+
enabled: Annotated[bool | None, typer.Option(help="启用状态")] = None,
|
|
111
123
|
):
|
|
124
|
+
"""查询告警匹配规则列表。
|
|
125
|
+
|
|
126
|
+
按专业、关键字与启用状态过滤告警匹配规则,并以平面表格形式输出。
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
spec: 专业值列表,多个值同时参与匹配。
|
|
130
|
+
page: 页码(从 0 开始)。
|
|
131
|
+
size: 每页条数。
|
|
132
|
+
query: 可选关键字。
|
|
133
|
+
enabled: 可选启用状态过滤。
|
|
134
|
+
|
|
135
|
+
Examples:
|
|
136
|
+
>>> data-ops-cli alarm rule match list --spec MY_SPEC --page 0 --size 20
|
|
137
|
+
"""
|
|
112
138
|
try:
|
|
113
|
-
group_nodes = service_list_alarm_rule_matches(
|
|
139
|
+
group_nodes = service_list_alarm_rule_matches(page_num, page_size, query, enabled, spec)
|
|
114
140
|
except DataOpsError as e:
|
|
115
141
|
typer.echo(f"错误: {e.message}")
|
|
116
142
|
raise typer.Exit(code=1) from None
|
|
@@ -145,17 +171,30 @@ def list_alarm_rules_match(
|
|
|
145
171
|
|
|
146
172
|
@alarm_spec_typer.command("list", help="查询告警专业")
|
|
147
173
|
def list_alarm_specs(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
query: Annotated[
|
|
151
|
-
active: Annotated[
|
|
174
|
+
page_num: Annotated[int, typer.Option("-n", "--page-num", help="页码")] = 0,
|
|
175
|
+
page_size: Annotated[int, typer.Option("-s", "--page-size", help="每页大小")] = 20,
|
|
176
|
+
query: Annotated[str | None, typer.Option("-q", "--query", help="搜索关键字")] = None,
|
|
177
|
+
active: Annotated[bool | None, typer.Option(help="启用状态")] = None,
|
|
152
178
|
):
|
|
179
|
+
"""查询告警专业列表。
|
|
180
|
+
|
|
181
|
+
按关键字与启用状态过滤告警专业(spec),输出标题、值、行业等基础字段。
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
page: 页码(从 0 开始)。
|
|
185
|
+
size: 每页条数。
|
|
186
|
+
query: 可选关键字。
|
|
187
|
+
active: 可选启用状态过滤。
|
|
188
|
+
|
|
189
|
+
Examples:
|
|
190
|
+
>>> data-ops-cli alarm spec list -q "网元"
|
|
191
|
+
"""
|
|
153
192
|
query_param = SqlQueryParam()
|
|
154
193
|
if active is not None:
|
|
155
194
|
query_param.varMap["isEnabled"] = "1" if active else "0"
|
|
156
195
|
if query:
|
|
157
196
|
query_param.add_like("title", query, "mrl")
|
|
158
|
-
group_nodes = service_list_alarm_specs(
|
|
197
|
+
group_nodes = service_list_alarm_specs(page_num, page_size, query_param)
|
|
159
198
|
|
|
160
199
|
print_list(
|
|
161
200
|
["专业名称", "值", "行业", "启用状态", "创建人", "更新时间"],
|
|
@@ -175,21 +214,43 @@ def list_alarm_specs(
|
|
|
175
214
|
|
|
176
215
|
@alarm_spec_typer.command("count", help="查询告警专业数量")
|
|
177
216
|
def count_alarm_specs(
|
|
178
|
-
query: Annotated[
|
|
179
|
-
enabled: Annotated[
|
|
217
|
+
query: Annotated[str | None, typer.Option("-q", "--query", help="搜索关键字")] = None,
|
|
218
|
+
enabled: Annotated[bool | None, typer.Option(help="启用状态")] = None,
|
|
180
219
|
):
|
|
220
|
+
"""查询告警专业的总数。
|
|
221
|
+
|
|
222
|
+
Args:
|
|
223
|
+
query: 可选关键字。
|
|
224
|
+
enabled: 可选启用状态过滤。
|
|
225
|
+
|
|
226
|
+
Examples:
|
|
227
|
+
>>> data-ops-cli alarm spec count
|
|
228
|
+
"""
|
|
181
229
|
total = service_count_alarm_specs(query, enabled)
|
|
182
230
|
print(total)
|
|
183
231
|
|
|
184
232
|
|
|
185
233
|
@alarm_rule_typer.command("list", help="查询告警规则")
|
|
186
234
|
def list_alarm_rules(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
query: Annotated[
|
|
190
|
-
enabled: Annotated[
|
|
235
|
+
page_num: Annotated[int, typer.Option("-n", "--page-num", help="页码")] = 0,
|
|
236
|
+
page_size: Annotated[int, typer.Option("-s", "--page-size", help="每页大小")] = 20,
|
|
237
|
+
query: Annotated[str | None, typer.Option("-q", "--query", help="搜索关键字")] = None,
|
|
238
|
+
enabled: Annotated[bool | None, typer.Option(help="启用状态")] = None,
|
|
191
239
|
):
|
|
192
|
-
|
|
240
|
+
"""查询告警规则列表。
|
|
241
|
+
|
|
242
|
+
按关键字与启用状态过滤告警规则,并以平面表格输出名称、值与启用状态。
|
|
243
|
+
|
|
244
|
+
Args:
|
|
245
|
+
page: 页码(从 0 开始)。
|
|
246
|
+
size: 每页条数。
|
|
247
|
+
query: 可选关键字。
|
|
248
|
+
enabled: 可选启用状态过滤。
|
|
249
|
+
|
|
250
|
+
Examples:
|
|
251
|
+
>>> data-ops-cli alarm rule list -q "电压"
|
|
252
|
+
"""
|
|
253
|
+
group_nodes = service_list_alarm_rules(page_num, page_size, query, enabled)
|
|
193
254
|
|
|
194
255
|
print_list(
|
|
195
256
|
["规则名称", "值", "启用状态", "创建人", "更新时间"],
|
|
@@ -208,9 +269,18 @@ def list_alarm_rules(
|
|
|
208
269
|
|
|
209
270
|
@alarm_spec_typer.command("count", help="查询告警规则数量")
|
|
210
271
|
def count_alarm_specs(
|
|
211
|
-
query: Annotated[
|
|
212
|
-
enabled: Annotated[
|
|
272
|
+
query: Annotated[str | None, typer.Option("-q", "--query", help="搜索关键字")] = None,
|
|
273
|
+
enabled: Annotated[bool | None, typer.Option(help="启用状态")] = None,
|
|
213
274
|
):
|
|
275
|
+
"""查询告警规则的总数。
|
|
276
|
+
|
|
277
|
+
Args:
|
|
278
|
+
query: 可选关键字。
|
|
279
|
+
enabled: 可选启用状态过滤。
|
|
280
|
+
|
|
281
|
+
Examples:
|
|
282
|
+
>>> data-ops-cli alarm rule count
|
|
283
|
+
"""
|
|
214
284
|
total = service_count_alarm_rules(query, enabled)
|
|
215
285
|
print(total)
|
|
216
286
|
|
|
@@ -218,13 +288,27 @@ def count_alarm_specs(
|
|
|
218
288
|
@alarm_action_typer.command("list", help="查询告警动作")
|
|
219
289
|
def list_alarm_actions(
|
|
220
290
|
rule: Annotated[list[str], typer.Option(help="专业值", default_factory=list)],
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
query: Annotated[
|
|
224
|
-
enabled: Annotated[
|
|
291
|
+
page_num: Annotated[int, typer.Option("-n", "--page-num", help="页码")] = 0,
|
|
292
|
+
page_size: Annotated[int, typer.Option("-s", "--page-size", help="每页大小")] = 20,
|
|
293
|
+
query: Annotated[str | None, typer.Option("-q", "--query", help="搜索关键字")] = None,
|
|
294
|
+
enabled: Annotated[bool | None, typer.Option(help="启用状态")] = None,
|
|
225
295
|
):
|
|
296
|
+
"""查询告警动作列表。
|
|
297
|
+
|
|
298
|
+
按所属规则、关键字与启用状态过滤告警动作,并以平面表格输出。
|
|
299
|
+
|
|
300
|
+
Args:
|
|
301
|
+
rule: 所属规则编码列表。
|
|
302
|
+
page: 页码(从 0 开始)。
|
|
303
|
+
size: 每页条数。
|
|
304
|
+
query: 可选关键字。
|
|
305
|
+
enabled: 可选启用状态过滤。
|
|
306
|
+
|
|
307
|
+
Examples:
|
|
308
|
+
>>> data-ops-cli alarm action list --rule MY_RULE
|
|
309
|
+
"""
|
|
226
310
|
try:
|
|
227
|
-
group_nodes = service_list_alarm_action(
|
|
311
|
+
group_nodes = service_list_alarm_action(page_num, page_size, query, enabled, rule)
|
|
228
312
|
except DataOpsError as e:
|
|
229
313
|
typer.echo(f"错误: {e.message}")
|
|
230
314
|
raise typer.Exit(code=1) from None
|
|
@@ -258,9 +342,19 @@ def list_alarm_actions(
|
|
|
258
342
|
@alarm_action_typer.command("count", help="查询告警动作数量")
|
|
259
343
|
def count_alarm_actions(
|
|
260
344
|
rule: Annotated[list[str], typer.Option(help="专业值", default_factory=list)],
|
|
261
|
-
query: Annotated[
|
|
262
|
-
enabled: Annotated[
|
|
345
|
+
query: Annotated[str | None, typer.Option("-q", "--query", help="搜索关键字")] = None,
|
|
346
|
+
enabled: Annotated[bool | None, typer.Option(help="启用状态")] = None,
|
|
263
347
|
):
|
|
348
|
+
"""查询告警动作的总数。
|
|
349
|
+
|
|
350
|
+
Args:
|
|
351
|
+
rule: 所属规则编码列表。
|
|
352
|
+
query: 可选关键字。
|
|
353
|
+
enabled: 可选启用状态过滤。
|
|
354
|
+
|
|
355
|
+
Examples:
|
|
356
|
+
>>> data-ops-cli alarm action count --rule MY_RULE
|
|
357
|
+
"""
|
|
264
358
|
try:
|
|
265
359
|
total = service_count_alarm_action(query, enabled, rule)
|
|
266
360
|
except DataOpsError as e:
|
|
@@ -271,9 +365,11 @@ def count_alarm_actions(
|
|
|
271
365
|
|
|
272
366
|
@alarm_rule_typer.command("enums")
|
|
273
367
|
def get_alarm_rule_enums() -> None:
|
|
274
|
-
"""
|
|
368
|
+
"""获取告警规则枚举配置。
|
|
275
369
|
|
|
276
|
-
|
|
370
|
+
后端返回 ``dict`` 时以两列 ``key/value`` 表渲染;其他结构以 JSON 形式输出。
|
|
371
|
+
|
|
372
|
+
Examples:
|
|
277
373
|
>>> data-ops-cli alarm rule enums
|
|
278
374
|
"""
|
|
279
375
|
try:
|
|
@@ -300,9 +396,14 @@ def get_alarm_rule_enums() -> None:
|
|
|
300
396
|
def find_meta_by_codes(
|
|
301
397
|
codes: Annotated[list[str], typer.Argument(help="告警规则编码列表")],
|
|
302
398
|
) -> None:
|
|
303
|
-
"""
|
|
399
|
+
"""根据告警规则编码批量查询关联元数据。
|
|
400
|
+
|
|
401
|
+
以 JSON 格式输出查询结果,便于人工检视或管道后续处理。
|
|
402
|
+
|
|
403
|
+
Args:
|
|
404
|
+
codes: 告警规则编码列表。
|
|
304
405
|
|
|
305
|
-
|
|
406
|
+
Examples:
|
|
306
407
|
>>> data-ops-cli alarm rule find-meta-by-codes code1 code2
|
|
307
408
|
"""
|
|
308
409
|
try:
|
|
@@ -318,9 +419,12 @@ def find_meta_by_codes(
|
|
|
318
419
|
def get_alarm_table_columns(
|
|
319
420
|
spec_type: Annotated[str, typer.Argument(help="告警规格类型")],
|
|
320
421
|
) -> None:
|
|
321
|
-
"""获取指定 specType
|
|
422
|
+
"""获取指定 specType 对应的告警表列定义。
|
|
322
423
|
|
|
323
|
-
|
|
424
|
+
Args:
|
|
425
|
+
spec_type: 告警规格类型编码。
|
|
426
|
+
|
|
427
|
+
Examples:
|
|
324
428
|
>>> data-ops-cli alarm rule alarm-columns MY_SPEC_TYPE
|
|
325
429
|
"""
|
|
326
430
|
try:
|
|
@@ -336,9 +440,12 @@ def get_alarm_table_columns(
|
|
|
336
440
|
def get_rel_table_columns(
|
|
337
441
|
code: Annotated[str, typer.Argument(help="告警规则编码")],
|
|
338
442
|
) -> None:
|
|
339
|
-
"""
|
|
443
|
+
"""获取指定告警规则关联表的列定义。
|
|
444
|
+
|
|
445
|
+
Args:
|
|
446
|
+
code: 告警规则编码。
|
|
340
447
|
|
|
341
|
-
|
|
448
|
+
Examples:
|
|
342
449
|
>>> data-ops-cli alarm rule rel-columns rule_code_001
|
|
343
450
|
"""
|
|
344
451
|
try:
|
|
@@ -358,12 +465,16 @@ def find_alarm_table_data(
|
|
|
358
465
|
typer.Option(help="查询条件 JSON 字符串"),
|
|
359
466
|
] = None,
|
|
360
467
|
) -> None:
|
|
361
|
-
"""
|
|
468
|
+
"""查询指定数据源中告警表的实际数据(由告警规则写入的记录,非实时告警)。
|
|
362
469
|
|
|
363
|
-
|
|
364
|
-
>>> data-ops-cli alarm rule data --code rule_code_001
|
|
470
|
+
``--query`` 接收 JSON 字符串并解析为 dict 后透传给 SDK。
|
|
365
471
|
|
|
366
|
-
|
|
472
|
+
Args:
|
|
473
|
+
code: 告警规则编码。
|
|
474
|
+
query: 可选 JSON 字符串,表示查询条件。
|
|
475
|
+
|
|
476
|
+
Examples:
|
|
477
|
+
>>> data-ops-cli alarm rule data --code rule_code_001
|
|
367
478
|
>>> data-ops-cli alarm rule data --code rule_code_001 --query '{"date":"2026-07-16"}'
|
|
368
479
|
"""
|
|
369
480
|
try:
|
|
@@ -6,17 +6,17 @@
|
|
|
6
6
|
- CLI 命令:基于服务层的薄包装,负责格式化输出
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
-
import shutil
|
|
10
9
|
from typing import Annotated
|
|
11
10
|
|
|
12
11
|
import typer
|
|
13
|
-
|
|
14
12
|
from dataops_sdk.exceptions import DataOpsError
|
|
15
13
|
from dataops_sdk.schemas import MetaType
|
|
16
14
|
from dataops_sdk.services.api import service_get_api_by_code
|
|
17
15
|
from dataops_sdk.services.meta import release_list_list
|
|
18
16
|
from dataops_sdk.utils import filter_nodes_by_pattern
|
|
19
17
|
|
|
18
|
+
from dataops_cli.cli.utils import print_list
|
|
19
|
+
|
|
20
20
|
# ---------------------------------------------------------------------------
|
|
21
21
|
# 常量
|
|
22
22
|
# ---------------------------------------------------------------------------
|
|
@@ -46,7 +46,11 @@ api_typer = typer.Typer(
|
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
def _first_line(text: str) -> str:
|
|
49
|
-
"""
|
|
49
|
+
"""取文本的第一行。
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
text: 多行字符串。
|
|
53
|
+
"""
|
|
50
54
|
return text.split("\n")[0]
|
|
51
55
|
|
|
52
56
|
|
|
@@ -56,11 +60,14 @@ def list_apis(
|
|
|
56
60
|
str | None, typer.Option("-q", "--query", help="按名称/标题/备注正则过滤")
|
|
57
61
|
] = None,
|
|
58
62
|
) -> None:
|
|
59
|
-
"""列出所有 API
|
|
63
|
+
"""列出所有 API 接口。
|
|
60
64
|
|
|
61
65
|
从元数据服务获取 API 接口列表,支持通过正则表达式按名称、标题或备注进行过滤。
|
|
62
66
|
|
|
63
|
-
|
|
67
|
+
Args:
|
|
68
|
+
query: 可选正则表达式,按名称/标题/备注过滤。
|
|
69
|
+
|
|
70
|
+
Examples:
|
|
64
71
|
列出所有 API 接口
|
|
65
72
|
>>> data-ops-cli api list
|
|
66
73
|
|
|
@@ -81,14 +88,10 @@ def list_apis(
|
|
|
81
88
|
print("(无结果)")
|
|
82
89
|
return
|
|
83
90
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
title = node.TITLE
|
|
89
|
-
remark_raw = node.REMARK or ""
|
|
90
|
-
remark = _first_line(remark_raw.strip())
|
|
91
|
-
print(code, title, remark)
|
|
91
|
+
print_list(
|
|
92
|
+
["code", "title", "remark"],
|
|
93
|
+
[[node.CODE, node.TITLE, _first_line(node.REMARK or "")] for node in group_nodes],
|
|
94
|
+
)
|
|
92
95
|
|
|
93
96
|
|
|
94
97
|
@api_typer.command("detail", rich_help_panel="API 查询", no_args_is_help=True)
|
|
@@ -99,11 +102,15 @@ def get_api_detail(
|
|
|
99
102
|
typer.Option("-s", "--simplify", help="仅显示基本信息,不展示请求/响应参数"),
|
|
100
103
|
] = False,
|
|
101
104
|
) -> None:
|
|
102
|
-
"""获取 API
|
|
105
|
+
"""获取 API 接口详情。
|
|
103
106
|
|
|
104
107
|
根据 API 接口编码获取详细信息,包括请求方法、路径、状态、请求参数和响应参数。
|
|
105
108
|
|
|
106
|
-
|
|
109
|
+
Args:
|
|
110
|
+
code: API 接口编码。
|
|
111
|
+
simplify: 是否仅显示基本信息(不展示请求/响应参数)。
|
|
112
|
+
|
|
113
|
+
Examples:
|
|
107
114
|
获取 API 接口完整信息
|
|
108
115
|
>>> data-ops-cli api detail user_login
|
|
109
116
|
|
|
@@ -207,7 +214,13 @@ def get_api_detail(
|
|
|
207
214
|
|
|
208
215
|
|
|
209
216
|
def _print_params_tree(params: list[dict], indent: int = 0, prefix: str = "") -> None:
|
|
210
|
-
"""
|
|
217
|
+
"""递归打印参数树结构。
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
params: 参数节点列表。
|
|
221
|
+
indent: 当前缩进空格数。
|
|
222
|
+
prefix: 每行前缀。
|
|
223
|
+
"""
|
|
211
224
|
for p in params:
|
|
212
225
|
ptype = p.get("type", "?")
|
|
213
226
|
name = p.get("name", "?")
|