Skip to content

Callback functions

Micah J. Martin edited this page Apr 16, 2019 · 5 revisions

Detcord implements several callback functions so that you may have tasks executed at certain times. An example use case (and the reason why its implemented) is for logging. You may log whenever detcord does anything.

The four callbacks implemented by detcord are:

Implementing the callbacks

You may implement any of the callbacks by defining the functions in your detfile.

Note: The begin and end callbacks are called from bin/detonate. The action and action_fail are called from the @action decorator. The decorator calls __main__.on_detcord_action(). If you are loading detcord through your own python code, try to make sure that you call begin and end and import action and action_fail from the detfile.

on_detcord_begin(*args, **kwargs)

This callback is called right before the first @action is run. This function is called in detonate right before it starts executing actions.

def on_detcord_begin(detfile="", hosts=[], actions=[], threading=False):

Arguments

  • detfile (str): The file location of the detfile that is being called
  • hosts (list): An array of the hosts that the actions are being run against
  • actions (list): An array of the actions that are being run
  • threading (bool): Whether or not the actions are being threaded

on_detcord_action(*args, **kwargs)

This callback is called whenever an @action is completed.

return_value will always be None unless silent is specified in the environment.

def on_detcord_action(host="", action="", return_value=None):

Arguments

  • host (str): The name of the host that the action was run against
  • action (str): The name of the action that was being run
  • return_value (obj): The return value of the function.None

on_detcord_action_fail(*args, **kwargs)

This callback is called whenever an @action fails.

def on_detcord_action_fail(host="", action="", exception=None):

Arguments

  • host (str): The name of the host that the action was run against
  • action (str): The name of the action that was being run
  • exception (Exception): The exception that was raised by the action

on_detcord_end(*args, **kwargs)

This callback is called whenever a detfile is finished running.

def on_detcord_end(detfile=""):

Arguments

  • detfile (str): The file location of the detfile that was called