Creating plugins¶
0. Restrictions¶
There is some restrictions on the create of the Plugin.
- All plugin executions should not be blocked by any conditions. If so, it would block the event-loop and carries ability to disturb the other plugins and the web service.
- All plugins have to pass all variables that is defined in the plugin initialization.
1. Decide which field types to use¶
You can use several types of graph that are currently available only the following:
line
: Line Graph.stack
: Stacked Column Chart.full-stack
: 100% stacked Column Chart.bar
: Simple Column Chart.
2. Let’s write a plugin script¶
import asyncio
from harpseal.plugin import Plugin
class YourPlugin(Plugin):
name = '(required) your-plugin-name' # The plugin name should be in alphabet, numberals and underline(_) only.
description = '(required) plugin description here'
priority = 0 # not implemented yet
every = 1 # every 1 minute. although it is not recommended to set this value in float, it's just okay.
def init(self):
# graph type definitions
self.field_types['a'] = 'line'
self.field_types['b'] = 'stack'
self.field_types['c'] = 'full-stack'
# field type definitions (`int` or `float`)
# one tuple(`()`) per one legend
self.fields['a'] = [('normal', int, ), ('abnormal', int, ), ]
self.fields['b'] = [('normal', float, ), ('abnormal', float, ), ]
self.fields['c'] = [('normal', float, ), ('abnormal', float, ), ]
@asyncio.coroutine
def provider(self): # data provider
data = self.data_form()
data['a'].set('normal', 100)
data['a'].set('abnormal', 150)
# ...
return data
-. The parent plugin class¶
-
class
harpseal.plugin.
Plugin
[source]¶ Bases:
object
Base plugin model
Usage:
import asyncio from harpseal.plugin import Plugin class YourPlugin(Plugin): name = '(required) your-plugin-name' description = '(required) plugin description here' priority = 0 # not yet implemented every = 1 # every 1 minute def init(self): # graph type definitions self.field_types['a'] = 'line' self.field_types['b'] = 'stack' self.field_types['c'] = 'full-stack' # field type definitions (`int` or `float`) self.fields['a'] = [('normal', int, ), ('abnormal', int, ), ] self.fields['b'] = [('normal', float, ), ('abnormal', float, ), ] self.fields['c'] = [('normal', float, ), ('abnormal', float, ), ] @asyncio.coroutine def provider(self): # data provider data = self.data_form() data['a'].set('normal', 100) data['a'].set('abnormal', 150) # ... return data
-
call
(command)[source]¶ Execute a command on the event-loop and then return the result when finished.
-
description
= ''¶ Plugin description
-
every
= 1¶ Plugin execution cycle (minutes)
-
field_types
= None¶ (
collections.defaultdict
) Model field type definitions (line, stack, full-stack, bar)
-
fields
= None¶ (
collections.defaultdict
) Model field definitions
-
last_executed_at
= None¶ (
datetime.datetime
) Last executed time
-
last_executed_result
= None¶ (
bool
) Last executed result
-
models
= None¶ (
dict
) Model definitions to be stored after executed init method
-
name
= ''¶ Plugin name
-
priority
= 0¶ Execution priority
-
properties
¶ Return the instance properties as a dict.
-