101
101
PATH_JOBS = "search/jobs/"
102
102
PATH_JOBS_V2 = "search/v2/jobs/"
103
103
PATH_LOGGER = "/services/server/logger/"
104
+ PATH_MACROS = "configs/conf-macros/"
104
105
PATH_MESSAGES = "messages/"
105
106
PATH_MODULAR_INPUTS = "data/modular-inputs"
106
107
PATH_ROLES = "authorization/roles/"
@@ -667,6 +668,15 @@ def saved_searches(self):
667
668
"""
668
669
return SavedSearches (self )
669
670
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
+
670
680
@property
671
681
def settings (self ):
672
682
"""Returns the configuration settings for this instance of Splunk.
@@ -3440,6 +3450,90 @@ def create(self, name, search, **kwargs):
3440
3450
return Collection .create (self , name , search = search , ** kwargs )
3441
3451
3442
3452
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
+
3443
3537
class Settings (Entity ):
3444
3538
"""This class represents configuration settings for a Splunk service.
3445
3539
Retrieve this collection using :meth:`Service.settings`."""
@@ -3905,4 +3999,4 @@ def batch_save(self, *documents):
3905
3999
data = json .dumps (documents )
3906
4000
3907
4001
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' ))
0 commit comments