action python-script

Specifies a Python file that runs when a trigger condition occurs.

Syntax

action python-script file-name
no action python-script file-name

Parameters

file-name
Specifies a Python script file-name. Valid values range from 4 through 32 characters (including the .py extension). The first character must be alphabetic.

Modes

Event-handler configuration mode

Usage Guidelines

You can assign only one action to a given event-handler profile.

You can also specify the Python file as part of the event-handler command.

To change the file assigned to a profile, you do not need to enter the no form of this command. You only need to enter action python-script file-name, specifying the new file name.

Running this command copies the Python script file from the flash:// directory to the database. After specifying a file for all relevant event-handler profiles, you can delete it from the flash:// directory.

If the event-handler for which you are modifying this command is active on the device, the changes take effect with no need to de-activate and re-activate the event-handler.

A Python event-handler script runs only if all of the following occur:
  • Using the copy command, copy the Python file to the flash:// location on the device.
  • Using the event-handler command, create an event-handler profile.
  • In configuration mode for that profile:
    • Using the trigger command, create one or more triggers.
    • Using the action command, specify the Python script that will be triggered.
  • Using the event-handler activate command, activate an instance of the event handler.
  • The trigger event occurs.

If an event-handler profile is not activated, the no form of this command deletes its action.

Examples

The following example specifies Python files for two event-handler profiles.

device# configure terminal
device(config)# event-handler eventHandler1
device(config-event-handler-eventHandler1)# action python-script example.py
device(config-event-handler-eventHandler1)# event-handler eventHandler2 
device(config-event-handler-eventHandler2)# action python-script example2.py