Splunk Enterprise

How to get the hook when disabling or deleting the inputs in splunk add on

TestUser
Loves-to-Learn Lots

I have developed splunk python add on using splunk ucc. Here I have a handling needed when input got disabled or deleted. 

How to get the hook when splunk input got deleted or disabled.

 

Same case how to get the hook, when the configuration got deleted.

 

When i checked many forum posts, splunk does not provides the default hook for these deletion handlings.

Labels (1)
0 Karma

livehybrid
SplunkTrust
SplunkTrust

Hi @TestUser 

If you look in your bin directory, you'll have your rest handler file which will be something like <app_name>_rh_<input_name>.py - Note that this may only be in the packaged version of the app, if so copy it to your barebones app folder so its used when you do a ucc-gen build.

In there you probably have:

from splunktaucclib.rest_handler.admin_external import AdminExternalHandler

This handler is where you can overwrite what happens on deletion (for example).

Extend the default AdminExternalHandler with something like this:

class MyAdminExternalHandler(AdminExternalHandler):
# Below are the defaults - which you can overwrite

    def handleEdit(self, confInfo):
        disabled = self.payload.get("disabled")
        if disabled is None:
            self.edit_hook(
                session_key=self.getSessionKey(),
                config_name=self._get_name(),
                stanza_id=self.callerArgs.id,
                payload=self.payload,
            )
            return self.handler.update(
                self.callerArgs.id,
                self.payload,
            )
        elif is_true(disabled):
            return self.handler.disable(self.callerArgs.id)
        else:
            return self.handler.enable(self.callerArgs.id)

    def handleRemove(self, confInfo):
        self.delete_hook(
            session_key=self.getSessionKey(),
            config_name=self._get_name(),
            stanza_id=self.callerArgs.id,
        )
        return self.handler.delete(self.callerArgs.id)

Then update the end of the file, change AdminExternalHandler for your extended class name (e.g. MyAdminExternalHandler):

if __name__ == '__main__':
    logging.getLogger().addHandler(logging.NullHandler())
    admin_external.handle(
        endpoint,
        handler=AdminExternalHandler,
    )

 

🌟 Did this answer help you? If so, please consider:

  • Adding karma to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...