splunkctl 0.1.0__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.
Files changed (39) hide show
  1. splunkctl-0.1.0/LICENSE +190 -0
  2. splunkctl-0.1.0/PKG-INFO +118 -0
  3. splunkctl-0.1.0/README.md +91 -0
  4. splunkctl-0.1.0/pyproject.toml +96 -0
  5. splunkctl-0.1.0/setup.cfg +4 -0
  6. splunkctl-0.1.0/splunkctl/__init__.py +3 -0
  7. splunkctl-0.1.0/splunkctl/__main__.py +5 -0
  8. splunkctl-0.1.0/splunkctl/client.py +103 -0
  9. splunkctl-0.1.0/splunkctl/commands/__init__.py +0 -0
  10. splunkctl-0.1.0/splunkctl/commands/alerts.py +94 -0
  11. splunkctl-0.1.0/splunkctl/commands/apps.py +189 -0
  12. splunkctl-0.1.0/splunkctl/commands/commands_meta.py +72 -0
  13. splunkctl-0.1.0/splunkctl/commands/config_cmd.py +87 -0
  14. splunkctl-0.1.0/splunkctl/commands/dashboards.py +216 -0
  15. splunkctl-0.1.0/splunkctl/commands/indexes.py +199 -0
  16. splunkctl-0.1.0/splunkctl/commands/info.py +29 -0
  17. splunkctl-0.1.0/splunkctl/commands/inputs.py +204 -0
  18. splunkctl-0.1.0/splunkctl/commands/lookups.py +217 -0
  19. splunkctl-0.1.0/splunkctl/commands/parsers.py +177 -0
  20. splunkctl-0.1.0/splunkctl/commands/rules.py +266 -0
  21. splunkctl-0.1.0/splunkctl/commands/search.py +270 -0
  22. splunkctl-0.1.0/splunkctl/commands/skill_cmd.py +43 -0
  23. splunkctl-0.1.0/splunkctl/commands/users.py +211 -0
  24. splunkctl-0.1.0/splunkctl/config.py +82 -0
  25. splunkctl-0.1.0/splunkctl/guard.py +22 -0
  26. splunkctl-0.1.0/splunkctl/main.py +149 -0
  27. splunkctl-0.1.0/splunkctl/output.py +75 -0
  28. splunkctl-0.1.0/splunkctl/skill/SKILL.md +325 -0
  29. splunkctl-0.1.0/splunkctl.egg-info/PKG-INFO +118 -0
  30. splunkctl-0.1.0/splunkctl.egg-info/SOURCES.txt +37 -0
  31. splunkctl-0.1.0/splunkctl.egg-info/dependency_links.txt +1 -0
  32. splunkctl-0.1.0/splunkctl.egg-info/entry_points.txt +2 -0
  33. splunkctl-0.1.0/splunkctl.egg-info/requires.txt +4 -0
  34. splunkctl-0.1.0/splunkctl.egg-info/top_level.txt +1 -0
  35. splunkctl-0.1.0/tests/test_client.py +56 -0
  36. splunkctl-0.1.0/tests/test_config.py +80 -0
  37. splunkctl-0.1.0/tests/test_guard.py +40 -0
  38. splunkctl-0.1.0/tests/test_output.py +118 -0
  39. splunkctl-0.1.0/tests/test_version.py +7 -0
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 dannyota
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: splunkctl
3
+ Version: 0.1.0
4
+ Summary: CLI tool for Splunk Enterprise SIEM operations.
5
+ Author: dannyota
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/dannyota/splunkctl
8
+ Project-URL: Repository, https://github.com/dannyota/splunkctl
9
+ Project-URL: Issues, https://github.com/dannyota/splunkctl/issues
10
+ Keywords: splunk,siem,security,cli,detection,spl
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Security
18
+ Classifier: Topic :: System :: Systems Administration
19
+ Requires-Python: >=3.13
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: splunk-sdk>=2.1.0
23
+ Requires-Dist: click>=8.0
24
+ Requires-Dist: pyyaml>=6.0
25
+ Requires-Dist: tabulate>=0.9
26
+ Dynamic: license-file
27
+
28
+ # splunkctl
29
+
30
+ CLI tool for Splunk Enterprise SIEM operations.
31
+
32
+ Query, inspect, and manage a Splunk Enterprise instance from the terminal.
33
+ Built on the [splunk-sdk-python](https://github.com/dannyota/splunk-sdk-python)
34
+ fork with [Click](https://click.palletsprojects.com/).
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ pip install splunkctl
40
+ ```
41
+
42
+ Requires Python 3.13+.
43
+
44
+ ## Quick start
45
+
46
+ ```bash
47
+ splunkctl config init # interactive setup
48
+ splunkctl config test # verify connectivity
49
+ splunkctl search run 'index=main | head 10' # run a search
50
+ splunkctl rules list # list detection rules
51
+ splunkctl dashboards list # list dashboards
52
+ ```
53
+
54
+ ## Commands
55
+
56
+ | Group | Description |
57
+ |---|---|
58
+ | `config` | Setup, show config, test connectivity |
59
+ | `info` | Server info (version, OS, license) |
60
+ | `search` | Run, export, oneshot, job management |
61
+ | `rules` | Detection rules (saved searches) — full CRUD |
62
+ | `alerts` | Fired alerts, alert actions, suppression |
63
+ | `dashboards` | Dashboard CRUD (XML) |
64
+ | `indexes` | Index management |
65
+ | `inputs` | Data inputs (monitor, tcp, udp, script, http) |
66
+ | `lookups` | Lookup table CRUD (CSV) |
67
+ | `parsers` | Source types and field extractions |
68
+ | `apps` | App install, uninstall, update |
69
+ | `users` | User and role management |
70
+ | `commands` | Machine-readable command tree (JSON) |
71
+ | `skill` | Embedded agent operating guide |
72
+
73
+ ## Global flags
74
+
75
+ ```
76
+ --json Force JSON output
77
+ --format FMT Output format: table, json, csv, jsonl
78
+ --fields f1,f2 Project specific fields
79
+ --out FILE Write output to file
80
+ --yes / -y Apply mutations (skip dry-run preview)
81
+ --timeout N Request timeout in seconds (default 30)
82
+ --config FILE Config file path
83
+ --debug HTTP request/response logging
84
+ ```
85
+
86
+ ## Dry-run by default
87
+
88
+ All write operations preview what would change. Pass `--yes` to apply.
89
+
90
+ ```bash
91
+ splunkctl rules delete 'My Rule' # shows preview only
92
+ splunkctl rules delete 'My Rule' --yes # actually deletes
93
+ ```
94
+
95
+ ## Output formats
96
+
97
+ ```bash
98
+ splunkctl rules list # table (TTY) or JSON (pipe)
99
+ splunkctl rules list --json # force JSON
100
+ splunkctl rules list --format csv # CSV
101
+ splunkctl rules list --fields name,cron # project fields
102
+ splunkctl rules list --out rules.json # write to file
103
+ ```
104
+
105
+ ## Agent integration
106
+
107
+ splunkctl ships with an embedded operating guide for AI agents
108
+ (Claude Code, etc.):
109
+
110
+ ```bash
111
+ splunkctl skill # print the guide
112
+ splunkctl skill install # install to ~/.claude/skills/
113
+ splunkctl commands # JSON command tree for discovery
114
+ ```
115
+
116
+ ## License
117
+
118
+ Apache-2.0
@@ -0,0 +1,91 @@
1
+ # splunkctl
2
+
3
+ CLI tool for Splunk Enterprise SIEM operations.
4
+
5
+ Query, inspect, and manage a Splunk Enterprise instance from the terminal.
6
+ Built on the [splunk-sdk-python](https://github.com/dannyota/splunk-sdk-python)
7
+ fork with [Click](https://click.palletsprojects.com/).
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install splunkctl
13
+ ```
14
+
15
+ Requires Python 3.13+.
16
+
17
+ ## Quick start
18
+
19
+ ```bash
20
+ splunkctl config init # interactive setup
21
+ splunkctl config test # verify connectivity
22
+ splunkctl search run 'index=main | head 10' # run a search
23
+ splunkctl rules list # list detection rules
24
+ splunkctl dashboards list # list dashboards
25
+ ```
26
+
27
+ ## Commands
28
+
29
+ | Group | Description |
30
+ |---|---|
31
+ | `config` | Setup, show config, test connectivity |
32
+ | `info` | Server info (version, OS, license) |
33
+ | `search` | Run, export, oneshot, job management |
34
+ | `rules` | Detection rules (saved searches) — full CRUD |
35
+ | `alerts` | Fired alerts, alert actions, suppression |
36
+ | `dashboards` | Dashboard CRUD (XML) |
37
+ | `indexes` | Index management |
38
+ | `inputs` | Data inputs (monitor, tcp, udp, script, http) |
39
+ | `lookups` | Lookup table CRUD (CSV) |
40
+ | `parsers` | Source types and field extractions |
41
+ | `apps` | App install, uninstall, update |
42
+ | `users` | User and role management |
43
+ | `commands` | Machine-readable command tree (JSON) |
44
+ | `skill` | Embedded agent operating guide |
45
+
46
+ ## Global flags
47
+
48
+ ```
49
+ --json Force JSON output
50
+ --format FMT Output format: table, json, csv, jsonl
51
+ --fields f1,f2 Project specific fields
52
+ --out FILE Write output to file
53
+ --yes / -y Apply mutations (skip dry-run preview)
54
+ --timeout N Request timeout in seconds (default 30)
55
+ --config FILE Config file path
56
+ --debug HTTP request/response logging
57
+ ```
58
+
59
+ ## Dry-run by default
60
+
61
+ All write operations preview what would change. Pass `--yes` to apply.
62
+
63
+ ```bash
64
+ splunkctl rules delete 'My Rule' # shows preview only
65
+ splunkctl rules delete 'My Rule' --yes # actually deletes
66
+ ```
67
+
68
+ ## Output formats
69
+
70
+ ```bash
71
+ splunkctl rules list # table (TTY) or JSON (pipe)
72
+ splunkctl rules list --json # force JSON
73
+ splunkctl rules list --format csv # CSV
74
+ splunkctl rules list --fields name,cron # project fields
75
+ splunkctl rules list --out rules.json # write to file
76
+ ```
77
+
78
+ ## Agent integration
79
+
80
+ splunkctl ships with an embedded operating guide for AI agents
81
+ (Claude Code, etc.):
82
+
83
+ ```bash
84
+ splunkctl skill # print the guide
85
+ splunkctl skill install # install to ~/.claude/skills/
86
+ splunkctl commands # JSON command tree for discovery
87
+ ```
88
+
89
+ ## License
90
+
91
+ Apache-2.0
@@ -0,0 +1,96 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "splunkctl"
7
+ dynamic = ["version"]
8
+ description = "CLI tool for Splunk Enterprise SIEM operations."
9
+ readme = "README.md"
10
+ requires-python = ">=3.13"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "dannyota" }]
14
+ keywords = ["splunk", "siem", "security", "cli", "detection", "spl"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Environment :: Console",
18
+ "Intended Audience :: System Administrators",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Security",
23
+ "Topic :: System :: Systems Administration",
24
+ ]
25
+ dependencies = [
26
+ "splunk-sdk>=2.1.0",
27
+ "click>=8.0",
28
+ "pyyaml>=6.0",
29
+ "tabulate>=0.9",
30
+ ]
31
+
32
+ [project.scripts]
33
+ splunkctl = "splunkctl.main:cli"
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/dannyota/splunkctl"
37
+ Repository = "https://github.com/dannyota/splunkctl"
38
+ Issues = "https://github.com/dannyota/splunkctl/issues"
39
+
40
+ [tool.setuptools]
41
+ packages = ["splunkctl", "splunkctl.commands", "splunkctl.skill"]
42
+
43
+ [tool.setuptools.dynamic]
44
+ version = { attr = "splunkctl.__version__" }
45
+
46
+ [tool.setuptools.package-data]
47
+ "splunkctl.skill" = ["SKILL.md"]
48
+
49
+ # --- Ruff (lint + format) ---
50
+
51
+ [tool.ruff]
52
+ line-length = 88
53
+ target-version = "py313"
54
+
55
+ [tool.ruff.lint]
56
+ select = [
57
+ "E", # pycodestyle errors
58
+ "W", # pycodestyle warnings
59
+ "F", # pyflakes
60
+ "I", # isort
61
+ "D", # pydocstyle
62
+ "UP", # pyupgrade
63
+ "B", # flake8-bugbear
64
+ "S", # flake8-bandit (security)
65
+ ]
66
+ ignore = [
67
+ "D100", # missing module docstring
68
+ "D104", # missing public package docstring
69
+ "D203", # conflicts with D211
70
+ "D213", # conflicts with D212
71
+ ]
72
+
73
+ [tool.ruff.lint.pydocstyle]
74
+ convention = "google"
75
+
76
+ [tool.ruff.lint.per-file-ignores]
77
+ "tests/**/*.py" = ["S101", "S105", "D"]
78
+
79
+ # --- mypy (strict) ---
80
+
81
+ [tool.mypy]
82
+ python_version = "3.13"
83
+ strict = true
84
+ disallow_untyped_defs = true
85
+ warn_return_any = true
86
+ warn_unused_configs = true
87
+
88
+ [[tool.mypy.overrides]]
89
+ module = "splunklib.*"
90
+ ignore_missing_imports = true
91
+
92
+ # --- pytest ---
93
+
94
+ [tool.pytest.ini_options]
95
+ testpaths = ["tests"]
96
+ addopts = "--tb=short -q"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """CLI tool for Splunk Enterprise SIEM operations."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,5 @@
1
+ """Allow running as `python -m splunkctl`."""
2
+
3
+ from splunkctl.main import cli
4
+
5
+ cli()
@@ -0,0 +1,103 @@
1
+ """SDK wrapper — lazy connection and auth resolution."""
2
+
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+ import click
7
+ import splunklib.client as splunk_client
8
+
9
+ from splunkctl import config as cfg_mod
10
+
11
+
12
+ class SplunkClient:
13
+ """Lazy-initializing Splunk SDK client.
14
+
15
+ Connection is established on first access to ``.service``.
16
+ Help, config, and offline commands never trigger auth.
17
+ """
18
+
19
+ def __init__( # noqa: D107
20
+ self,
21
+ *,
22
+ config_path: Path | None = None,
23
+ host: str | None = None,
24
+ port: int | None = None,
25
+ username: str | None = None,
26
+ password: str | None = None,
27
+ token: str | None = None,
28
+ scheme: str | None = None,
29
+ app: str | None = None,
30
+ owner: str | None = None,
31
+ verify: bool | None = None,
32
+ timeout: int = 30,
33
+ debug: bool = False,
34
+ ) -> None:
35
+ self._config_path = config_path
36
+ self._overrides: dict[str, Any] = {
37
+ k: v
38
+ for k, v in {
39
+ "host": host,
40
+ "port": port,
41
+ "username": username,
42
+ "password": password,
43
+ "token": token,
44
+ "scheme": scheme,
45
+ "app": app,
46
+ "owner": owner,
47
+ "verify": verify,
48
+ }.items()
49
+ if v is not None
50
+ }
51
+ self._timeout = timeout
52
+ self._debug = debug
53
+ self._service: Any = None
54
+
55
+ @property
56
+ def service(self) -> Any:
57
+ """Connect on first access."""
58
+ if self._service is None:
59
+ if self._debug:
60
+ import logging
61
+
62
+ logging.basicConfig(level=logging.DEBUG)
63
+ logging.getLogger("splunklib").setLevel(logging.DEBUG)
64
+
65
+ cfg = cfg_mod.load(self._config_path)
66
+ cfg.update(self._overrides)
67
+
68
+ connect_args: dict[str, Any] = {
69
+ "host": cfg.get("host", "localhost"),
70
+ "port": int(cfg.get("port", 8089)),
71
+ "scheme": cfg.get("scheme", "https"),
72
+ }
73
+
74
+ if cfg.get("token"):
75
+ connect_args["splunkToken"] = cfg["token"]
76
+ else:
77
+ connect_args["username"] = cfg.get("username", "")
78
+ connect_args["password"] = cfg.get("password", "")
79
+
80
+ if cfg.get("app"):
81
+ connect_args["app"] = cfg["app"]
82
+ if cfg.get("owner"):
83
+ connect_args["owner"] = cfg["owner"]
84
+
85
+ if not cfg.get("verify", False):
86
+ connect_args["verify"] = False
87
+
88
+ if self._timeout:
89
+ connect_args["timeout"] = self._timeout
90
+
91
+ self._service = splunk_client.connect(**connect_args)
92
+
93
+ return self._service
94
+
95
+
96
+ def get_client(ctx: click.Context) -> SplunkClient:
97
+ """Build a SplunkClient from Click context. Does not connect."""
98
+ obj: dict[str, Any] = ctx.ensure_object(dict)
99
+ return SplunkClient(
100
+ config_path=Path(obj["config"]) if obj.get("config") else None,
101
+ timeout=obj.get("timeout", 30),
102
+ debug=obj.get("debug", False),
103
+ )
File without changes