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.
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:
Your feedback encourages the volunteers in this community to continue contributing