Skip to content

Commit ff9c3dc

Browse files
committed
Add HECToken entity and HECTokens collection
1 parent b77f3f9 commit ff9c3dc

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

‎splunklib/client.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import socket
6565
from datetime import datetime, timedelta
6666
from time import sleep
67+
from typing import Any
6768
from urllib import parse
6869

6970
try:
@@ -109,6 +110,7 @@ def deprecated(message): # pyright: ignore[reportUnknownParameterType]
109110
PATH_DEPLOYMENT_SERVERCLASSES = "deployment/serverclass/"
110111
PATH_EVENT_TYPES = "saved/eventtypes/"
111112
PATH_FIRED_ALERTS = "alerts/fired_alerts/"
113+
PATH_HEC_TOKENS = "data/inputs/http/"
112114
PATH_INDEXES = "data/indexes/"
113115
PATH_INPUTS = "data/inputs/"
114116
PATH_JOBS = "search/jobs/"
@@ -498,6 +500,14 @@ def fired_alerts(self):
498500
"""
499501
return Collection(self, PATH_FIRED_ALERTS, item=AlertGroup)
500502

503+
@property
504+
def hec_tokens(self):
505+
"""Returns the collection of HTTP Event Collector tokens.
506+
507+
:return: A :class:`HECTokens` collection of :class:`HECToken` entities.
508+
"""
509+
return HECTokens(self)
510+
501511
@property
502512
def indexes(self):
503513
"""Returns the collection of indexes for this Splunk instance.
@@ -2126,6 +2136,39 @@ def count(self):
21262136
return int(self.content.get("triggered_alert_count", 0))
21272137

21282138

2139+
class HECToken(Entity):
2140+
"""This class represents an HTTP Event Collector token."""
2141+
2142+
def __init__(self, service: "Service", path: str, **kwargs: Any) -> None:
2143+
Entity.__init__(self, service, path, **kwargs)
2144+
2145+
def disable(self) -> "HECToken": # pyright: ignore[reportImplicitOverride]
2146+
"""Disables this HEC token.
2147+
2148+
:return: The :class:`HECToken`.
2149+
"""
2150+
self.post(disabled="1")
2151+
self.refresh()
2152+
return self
2153+
2154+
def enable(self) -> "HECToken": # pyright: ignore[reportImplicitOverride]
2155+
"""Enables this HEC token.
2156+
2157+
:return: The :class:`HECToken`.
2158+
"""
2159+
self.post(disabled="0")
2160+
self.refresh()
2161+
return self
2162+
2163+
2164+
class HECTokens(Collection):
2165+
"""This class represents a collection of HTTP Event Collector tokens.
2166+
Retrieve this collection using :meth:`Service.hec_tokens`."""
2167+
2168+
def __init__(self, service: "Service") -> None:
2169+
Collection.__init__(self, service, PATH_HEC_TOKENS, item=HECToken)
2170+
2171+
21292172
class Indexes(Collection):
21302173
"""This class contains the collection of indexes in this Splunk instance.
21312174
Retrieve this collection using :meth:`Service.indexes`.

‎tests/unit/test_hec_token.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright © 2011-2026 Splunk, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"): you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
from splunklib.client import (
16+
PATH_HEC_TOKENS,
17+
Collection,
18+
Entity,
19+
HECToken,
20+
HECTokens,
21+
)
22+
23+
24+
class TestHECToken:
25+
def test_is_entity_subclass(self) -> None:
26+
assert issubclass(HECToken, Entity)
27+
28+
def test_path_constant(self) -> None:
29+
assert PATH_HEC_TOKENS == "data/inputs/http/"
30+
31+
32+
class TestHECTokens:
33+
def test_is_collection_subclass(self) -> None:
34+
assert issubclass(HECTokens, Collection)

0 commit comments

Comments
 (0)