Skip to content

Commit 152e205

Browse files
committed
Updated splunk python SDK from 2.0.2 to 2.1.0 as per Splunk cloud compatibility requirements
1 parent 4cf5107 commit 152e205

File tree

7 files changed

+132
-9
lines changed

7 files changed

+132
-9
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ Shannon Davis (Splunk)
251251
Steven (malvidin on github)
252252

253253
# Release Notes
254+
## 2.4.4
255+
Updated splunk python SDK from 2.0.2 to 2.1.0 as per Splunk cloud compatibility requirements
256+
254257
## 2.4.3
255258
Updated splunk python SDK from 2.0.1 to 2.0.2 as per Splunk cloud compatibility requirements
256259

bin/lib/splunklib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ def setup_logging(level, log_format=DEFAULT_LOG_FORMAT, date_format=DEFAULT_DATE
3030
datefmt=date_format)
3131

3232

33-
__version_info__ = (2, 0, 2)
33+
__version_info__ = (2, 1, 0)
3434
__version__ = ".".join(map(str, __version_info__))

bin/lib/splunklib/binding.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ class Context:
465465
:type scheme: "https" or "http"
466466
:param verify: Enable (True) or disable (False) SSL verification for https connections.
467467
:type verify: ``Boolean``
468+
:param self_signed_certificate: Specifies if self signed certificate is used
469+
:type self_signed_certificate: ``Boolean``
468470
:param sharing: The sharing mode for the namespace (the default is "user").
469471
:type sharing: "global", "system", "app", or "user"
470472
:param owner: The owner context of the namespace (optional, the default is "None").
@@ -526,6 +528,7 @@ def __init__(self, handler=None, **kwargs):
526528
self.bearerToken = kwargs.get("splunkToken", "")
527529
self.autologin = kwargs.get("autologin", False)
528530
self.additional_headers = kwargs.get("headers", [])
531+
self._self_signed_certificate = kwargs.get("self_signed_certificate", True)
529532

530533
# Store any cookies in the self.http._cookies dict
531534
if "cookie" in kwargs and kwargs['cookie'] not in [None, _NoAuthenticationToken]:
@@ -604,7 +607,11 @@ def connect(self):
604607
"""
605608
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
606609
if self.scheme == "https":
607-
sock = ssl.wrap_socket(sock)
610+
context = ssl.create_default_context()
611+
context.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1
612+
context.check_hostname = not self._self_signed_certificate
613+
context.verify_mode = ssl.CERT_NONE if self._self_signed_certificate else ssl.CERT_REQUIRED
614+
sock = context.wrap_socket(sock, server_hostname=self.host)
608615
sock.connect((socket.gethostbyname(self.host), self.port))
609616
return sock
610617

bin/lib/splunklib/client.py

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
PATH_JOBS = "search/jobs/"
102102
PATH_JOBS_V2 = "search/v2/jobs/"
103103
PATH_LOGGER = "/services/server/logger/"
104+
PATH_MACROS = "configs/conf-macros/"
104105
PATH_MESSAGES = "messages/"
105106
PATH_MODULAR_INPUTS = "data/modular-inputs"
106107
PATH_ROLES = "authorization/roles/"
@@ -667,6 +668,15 @@ def saved_searches(self):
667668
"""
668669
return SavedSearches(self)
669670

671+
@property
672+
def macros(self):
673+
"""Returns the collection of macros.
674+
675+
:return: A :class:`Macros` collection of :class:`Macro`
676+
entities.
677+
"""
678+
return Macros(self)
679+
670680
@property
671681
def settings(self):
672682
"""Returns the configuration settings for this instance of Splunk.
@@ -3440,6 +3450,90 @@ def create(self, name, search, **kwargs):
34403450
return Collection.create(self, name, search=search, **kwargs)
34413451

34423452

3453+
class Macro(Entity):
3454+
"""This class represents a search macro."""
3455+
def __init__(self, service, path, **kwargs):
3456+
Entity.__init__(self, service, path, **kwargs)
3457+
3458+
@property
3459+
def args(self):
3460+
"""Returns the macro arguments.
3461+
:return: The macro arguments.
3462+
:rtype: ``string``
3463+
"""
3464+
return self._state.content.get('args', '')
3465+
3466+
@property
3467+
def definition(self):
3468+
"""Returns the macro definition.
3469+
:return: The macro definition.
3470+
:rtype: ``string``
3471+
"""
3472+
return self._state.content.get('definition', '')
3473+
3474+
@property
3475+
def errormsg(self):
3476+
"""Returns the validation error message for the macro.
3477+
:return: The validation error message for the macro.
3478+
:rtype: ``string``
3479+
"""
3480+
return self._state.content.get('errormsg', '')
3481+
3482+
@property
3483+
def iseval(self):
3484+
"""Returns the eval-based definition status of the macro.
3485+
:return: The iseval value for the macro.
3486+
:rtype: ``string``
3487+
"""
3488+
return self._state.content.get('iseval', '0')
3489+
3490+
def update(self, definition=None, **kwargs):
3491+
"""Updates the server with any changes you've made to the current macro
3492+
along with any additional arguments you specify.
3493+
:param `definition`: The macro definition (optional).
3494+
:type definition: ``string``
3495+
:param `kwargs`: Additional arguments (optional). Available parameters are:
3496+
'disabled', 'iseval', 'validation', and 'errormsg'.
3497+
:type kwargs: ``dict``
3498+
:return: The :class:`Macro`.
3499+
"""
3500+
# Updates to a macro *require* that the definition be
3501+
# passed, so we pass the current definition if a value wasn't
3502+
# provided by the caller.
3503+
if definition is None: definition = self.content.definition
3504+
Entity.update(self, definition=definition, **kwargs)
3505+
return self
3506+
3507+
@property
3508+
def validation(self):
3509+
"""Returns the validation expression for the macro.
3510+
:return: The validation expression for the macro.
3511+
:rtype: ``string``
3512+
"""
3513+
return self._state.content.get('validation', '')
3514+
3515+
3516+
class Macros(Collection):
3517+
"""This class represents a collection of macros. Retrieve this
3518+
collection using :meth:`Service.macros`."""
3519+
def __init__(self, service):
3520+
Collection.__init__(
3521+
self, service, PATH_MACROS, item=Macro)
3522+
3523+
def create(self, name, definition, **kwargs):
3524+
""" Creates a macro.
3525+
:param name: The name for the macro.
3526+
:type name: ``string``
3527+
:param definition: The macro definition.
3528+
:type definition: ``string``
3529+
:param kwargs: Additional arguments (optional). Available parameters are:
3530+
'disabled', 'iseval', 'validation', and 'errormsg'.
3531+
:type kwargs: ``dict``
3532+
:return: The :class:`Macros` collection.
3533+
"""
3534+
return Collection.create(self, name, definition=definition, **kwargs)
3535+
3536+
34433537
class Settings(Entity):
34443538
"""This class represents configuration settings for a Splunk service.
34453539
Retrieve this collection using :meth:`Service.settings`."""
@@ -3905,4 +3999,4 @@ def batch_save(self, *documents):
39053999
data = json.dumps(documents)
39064000

39074001
return json.loads(
3908-
self._post('batch_save', headers=KVStoreCollectionData.JSON_HEADER, body=data).body.read().decode('utf-8'))
4002+
self._post('batch_save', headers=KVStoreCollectionData.JSON_HEADER, body=data).body.read().decode('utf-8'))

bin/lib/splunklib/modularinput/event_writer.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# under the License.
1414

1515
import sys
16+
import traceback
1617

1718
from splunklib.utils import ensure_str
1819
from .event import ET
@@ -66,6 +67,25 @@ def log(self, severity, message):
6667
self._err.write(f"{severity} {message}\n")
6768
self._err.flush()
6869

70+
def log_exception(self, message, exception=None, severity=None):
71+
"""Logs messages about the exception thrown by this modular input to Splunk.
72+
These messages will show up in Splunk's internal logs.
73+
74+
:param message: ``string``, message to log.
75+
:param exception: ``Exception``, exception thrown by this modular input; if none, sys.exc_info() is used
76+
:param severity: ``string``, severity of message, see severities defined as class constants. Default severity: ERROR
77+
"""
78+
if exception is not None:
79+
tb_str = traceback.format_exception(type(exception), exception, exception.__traceback__)
80+
else:
81+
tb_str = traceback.format_exc()
82+
83+
if severity is None:
84+
severity = EventWriter.ERROR
85+
86+
self._err.write(("%s %s - %s" % (severity, message, tb_str)).replace("\n", " "))
87+
self._err.flush()
88+
6989
def write_xml_document(self, document):
7090
"""Writes a string representation of an
7191
``ElementTree`` object to the output stream.

bin/lib/splunklib/modularinput/script.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@ def run_script(self, args, event_writer, input_stream):
9191
event_writer.write_xml_document(root)
9292

9393
return 1
94-
err_string = "ERROR Invalid arguments to modular input script:" + ' '.join(
95-
args)
96-
event_writer._err.write(err_string)
94+
event_writer.log(EventWriter.ERROR, "Invalid arguments to modular input script:" + ' '.join(
95+
args))
9796
return 1
9897

9998
except Exception as e:
100-
event_writer.log(EventWriter.ERROR, str(e))
99+
event_writer.log_exception(str(e))
101100
return 1
102101

103102
@property

default/app.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ id = decrypt2
33

44
[install]
55
state = enabled
6-
build = 20240914
6+
build = 20241124
77

88
[ui]
99
label = DecryptCommands
@@ -12,4 +12,4 @@ is_visible = false
1212
[launcher]
1313
author = Gareth Anderson
1414
description = A library of common routines to analyze malware and data exfiltration communications (based on the work of Michael Zalewski).
15-
version = 2.4.3
15+
version = 2.4.4

0 commit comments

Comments
 (0)