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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...