detectl 0.2.1__tar.gz → 0.2.2__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.
- {detectl-0.2.1 → detectl-0.2.2}/PKG-INFO +1 -1
- {detectl-0.2.1 → detectl-0.2.2}/detectl/__init__.py +1 -1
- {detectl-0.2.1 → detectl-0.2.2}/detectl/cli.py +58 -5
- {detectl-0.2.1 → detectl-0.2.2}/detectl.egg-info/PKG-INFO +1 -1
- {detectl-0.2.1 → detectl-0.2.2}/pyproject.toml +1 -1
- {detectl-0.2.1 → detectl-0.2.2}/tests/test_cli.py +18 -0
- {detectl-0.2.1 → detectl-0.2.2}/LICENSE +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/README.md +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/__main__.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/adapters/__init__.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/adapters/base.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/adapters/chronicle.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/adapters/crowdstrike.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/adapters/elastic.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/adapters/qradar.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/adapters/sentinel.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/adapters/splunk.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/adapters/sumologic.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/config.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/exceptions.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl/models.py +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl.egg-info/SOURCES.txt +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl.egg-info/dependency_links.txt +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl.egg-info/entry_points.txt +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl.egg-info/requires.txt +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/detectl.egg-info/top_level.txt +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/setup.cfg +0 -0
- {detectl-0.2.1 → detectl-0.2.2}/tests/test_config.py +0 -0
|
@@ -59,9 +59,7 @@ def _load_sigmux():
|
|
|
59
59
|
from sigmux.rule import SigmaRule
|
|
60
60
|
except ImportError as exc:
|
|
61
61
|
raise click.ClickException(
|
|
62
|
-
"rules create-from-sigma needs sigmux installed: pip install 'detectl[sigma]'
|
|
63
|
-
"(sigmux isn't on PyPI yet -- that extra installs it straight from "
|
|
64
|
-
"https://github.com/kylemain/sigmux)"
|
|
62
|
+
"rules create-from-sigma needs sigmux installed: pip install 'detectl[sigma]'"
|
|
65
63
|
) from exc
|
|
66
64
|
return SigmaRule, get_backend
|
|
67
65
|
|
|
@@ -78,6 +76,40 @@ def _load_rich():
|
|
|
78
76
|
return Console, Panel, Text
|
|
79
77
|
|
|
80
78
|
|
|
79
|
+
def _try_load_rich():
|
|
80
|
+
"""Soft-import counterpart to _load_rich(), for callers (like `targets`)
|
|
81
|
+
that should still work perfectly well without the optional `dryrun`
|
|
82
|
+
extra -- falls back to (None, None) instead of raising."""
|
|
83
|
+
try:
|
|
84
|
+
from rich.console import Console
|
|
85
|
+
from rich.table import Table
|
|
86
|
+
except ImportError:
|
|
87
|
+
return None, None
|
|
88
|
+
return Console, Table
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _stdout_is_tty() -> bool:
|
|
92
|
+
"""Broken out as its own function (rather than an inline sys.stdout.isatty()
|
|
93
|
+
call) purely so tests can patch it directly -- Click's CliRunner swaps
|
|
94
|
+
out sys.stdout for a captured buffer during invoke(), which would make
|
|
95
|
+
patching sys.stdout.isatty itself unreliable."""
|
|
96
|
+
return sys.stdout.isatty()
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# Display metadata for `targets` only -- purely cosmetic. Colors match
|
|
100
|
+
# sigmux's _TARGET_INFO exactly for the same platform, since sigmux's
|
|
101
|
+
# target names and detectl's platform names are the same 1:1 set.
|
|
102
|
+
_PLATFORM_INFO: Dict[str, Dict[str, str]] = {
|
|
103
|
+
"splunk": {"query": "Splunk SPL", "rules": "Saved searches / correlation searches", "color": "orange3"},
|
|
104
|
+
"elastic": {"query": "Elasticsearch Query DSL", "rules": "Detection Engine rules", "color": "gold3"},
|
|
105
|
+
"sentinel": {"query": "Microsoft Sentinel (KQL)", "rules": "Scheduled Analytics Rules", "color": "deep_sky_blue1"},
|
|
106
|
+
"crowdstrike": {"query": "CrowdStrike Falcon LogScale (LQL)", "rules": "Custom IOA rules", "color": "magenta1"},
|
|
107
|
+
"qradar": {"query": "IBM QRadar (AQL)", "rules": "CRE rule metadata (enable/disable/delete)", "color": "green3"},
|
|
108
|
+
"chronicle": {"query": "Google Chronicle (YARA-L 2.0)", "rules": "Rules (YARA-L text)", "color": "cyan1"},
|
|
109
|
+
"sumologic": {"query": "Sumo Logic search query", "rules": "Monitors Library", "color": "red3"},
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
81
113
|
def _append_field(body, sign: str, key: str, value: Any, style: str) -> None:
|
|
82
114
|
if isinstance(value, str) and "\n" in value:
|
|
83
115
|
body.append(f" {sign} {key}:\n", style=style)
|
|
@@ -145,9 +177,30 @@ def _adapter(ctx: click.Context) -> SIEMAdapter:
|
|
|
145
177
|
|
|
146
178
|
@main.command()
|
|
147
179
|
def targets():
|
|
148
|
-
"""List supported SIEM/EDR platforms.
|
|
180
|
+
"""List supported SIEM/EDR platforms.
|
|
181
|
+
|
|
182
|
+
Renders a colored table (matching sigmux's `targets` command) in an
|
|
183
|
+
interactive terminal. Falls back to a plain one-name-per-line list --
|
|
184
|
+
same as always -- when piped/redirected, or when rich isn't installed,
|
|
185
|
+
so `detectl targets | xargs ...`-style scripting still works exactly
|
|
186
|
+
as before.
|
|
187
|
+
"""
|
|
188
|
+
Console, Table = _try_load_rich() if _stdout_is_tty() else (None, None)
|
|
189
|
+
if Console is None:
|
|
190
|
+
for name in sorted(REGISTRY):
|
|
191
|
+
click.echo(name)
|
|
192
|
+
return
|
|
193
|
+
|
|
194
|
+
table = Table(title="detectl supported platforms", header_style="bold")
|
|
195
|
+
table.add_column("Platform", style="bold")
|
|
196
|
+
table.add_column("Ad-hoc query language")
|
|
197
|
+
table.add_column("Rules resource")
|
|
149
198
|
for name in sorted(REGISTRY):
|
|
150
|
-
|
|
199
|
+
info = _PLATFORM_INFO.get(name, {})
|
|
200
|
+
color = info.get("color", "white")
|
|
201
|
+
table.add_row(f"[{color}]{name}[/{color}]", info.get("query", "--"), info.get("rules", "--"))
|
|
202
|
+
|
|
203
|
+
Console().print(table)
|
|
151
204
|
|
|
152
205
|
|
|
153
206
|
@main.command("test-connection")
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "detectl"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.2"
|
|
8
8
|
description = "A CLI for managing detection rules, tuning lists, alerts, and ad-hoc queries across multiple SIEM/EDR platforms through one consistent interface."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -55,6 +55,24 @@ class TestCli(unittest.TestCase):
|
|
|
55
55
|
for name in ("splunk", "elastic", "sentinel", "crowdstrike"):
|
|
56
56
|
self.assertIn(name, result.output)
|
|
57
57
|
|
|
58
|
+
def test_targets_plain_list_when_not_a_tty(self):
|
|
59
|
+
# CliRunner's captured output isn't a real tty, so this is really
|
|
60
|
+
# just documenting/pinning the default (piped) behavior explicitly.
|
|
61
|
+
result = self.runner.invoke(main, ["targets"])
|
|
62
|
+
self.assertEqual(result.exit_code, 0)
|
|
63
|
+
lines = result.output.strip().splitlines()
|
|
64
|
+
self.assertEqual(sorted(lines), sorted(["splunk", "elastic", "sentinel", "crowdstrike", "qradar", "sumologic", "chronicle"]))
|
|
65
|
+
|
|
66
|
+
@patch("detectl.cli._stdout_is_tty", return_value=True)
|
|
67
|
+
def test_targets_renders_rich_table_when_tty(self, _mock_tty):
|
|
68
|
+
result = self.runner.invoke(main, ["targets"])
|
|
69
|
+
self.assertEqual(result.exit_code, 0)
|
|
70
|
+
self.assertIn("detectl supported platforms", result.output)
|
|
71
|
+
for name in ("splunk", "elastic", "sentinel", "crowdstrike", "qradar", "sumologic", "chronicle"):
|
|
72
|
+
self.assertIn(name, result.output)
|
|
73
|
+
self.assertIn("Ad-hoc query language", result.output)
|
|
74
|
+
self.assertIn("Rules resource", result.output)
|
|
75
|
+
|
|
58
76
|
def test_platform_required(self):
|
|
59
77
|
result = self.runner.invoke(main, ["rules", "list"])
|
|
60
78
|
self.assertNotEqual(result.exit_code, 0)
|
|
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
|
|
File without changes
|