HistoryΒΆ

The plugin history system allows developers to insert freeform text about the plugin, it’s activity and more. While we don’t recommend using history for generic logging, it is very useful when tracking write operations that your plugin takes, or key metrics that are worth persisting long term.

History records are stored in the PluginHistory table which has the following schema:

mysql> desc PluginHistory;
+--------------------+---------------------+------+-----+-------------------+----------------+
| Field              | Type                | Null | Key | Default           | Extra          |
+--------------------+---------------------+------+-----+-------------------+----------------+
| plugin_resource_id | varchar(255)        | NO   | MUL | NULL              |                |
| history_id         | bigint(20) unsigned | NO   | PRI | NULL              | auto_increment |
| action_id          | varchar(255)        | NO   |     | NULL              |                |
| timestamp          | timestamp           | NO   |     | CURRENT_TIMESTAMP |                |
| description        | varchar(255)        | NO   |     | NULL              |                |
| action_data        | mediumtext          | YES  |     | NULL              |                |
| resource_id        | varchar(255)        | YES  |     | NULL              |                |
+--------------------+---------------------+------+-----+-------------------+----------------+
7 rows in set (0.01 sec)

* plugin_resource_id - The resource ID of the plugin that wrote the history record
* history_id - An auto-incrementing ID field
* action_id - Freeform string that you can use to categorize your history events (eg: COMPLIANCE)
* timestamp - The time that the history event was recorded
* description - A description of the event
* action_data - An optional field that can be used to store JSON or other data specific to your event
* resource_id - An optional field to store the resource_id that the event relates to (eg: instance:5:us-east-1:i-1234abcd)

To create history events, simply import the DivvyPlugin resource from DivvyResource.Resources and use the format that’s included in the Python snippet below.

from DivvyResource.Resources import DivvyPlugin
DivvyPlugin.get_current_plugin().add_plugin_history(
    action_id='notify',
    description='Instance [%s] was restarted' % resource.get_resource_name(),
    action_data=None,
    resource_id=resource.resource_id.to_string())
../_images/plugin_history.jpg

Plugin history via the Plugin Management UI