TOM工具箱的Skip/Hopskotch代理模块
tom-scimma的Python项目详细描述
汤姆西玛
此模块添加Hopskotch和Skip 对TOM工具箱的支持。使用此模块,TOMs可以查询提交到Hopskotch流的警报,并将警报发布到Hopskotch。在
安装
将模块安装到您的TOM环境中:
pip install tom-scimma
将tom_scimma.scimma.SCIMMABroker
添加到汤姆的settings.py
中的TOM_ALERT_CLASSES
:
虽然跳过警报是公开的(目前),但您需要Hopskotch凭据才能提交警报。你可以注册
帐户here。添加适当的Skip和Hopskotch
项目settings.py
的凭据:
BROKERS={'SCIMMA':{'url':'http://skip.dev.hop.scimma.org','api_key':os.getenv('SKIP_API_KEY',''),'hopskotch_url':'dev.hop.scimma.org','hopskotch_username':os.getenv('HOPSKOTCH_USERNAME',''),'hopskotch_password':os.getenv('HOPSKOTCH_PASSWORD',''),'default_hopskotch_topic':''}}
可配置设置
url
:跳过请求的URL,即检索警报的URL。在
api_key
:用于使用Skip进行身份验证/授权的API密钥。当前未使用。在
hopskotch_url
:Hopskotch代理提交的URL,即提交警报。在
hopskotch_username
:用于验证Hopskotch的用户名。在
hopskotch_password
:用于验证Hopskotch的密码。在
default_hopskotch_topic
:未提供警报时提交警报的Hopskotch主题。在
可用的templatetags
尽管TOM工具箱提供了一个代理提交模板标签,tom_scimma
提供了一个额外的templatetag
包含主题的关键字参数。使用它
将tom_scimma
添加到您的settings.INSTALLED_APPS
:
INSTALLED_APPS=['django.contrib.admin','django.contrib.auth',...'tom_scimma']
然后,将scimma_extras
添加到所需模板的{% load ... %}
语句中:
{% load bootstrap4 targets_extras ... scimma_extras %}
最后,将所需的templatetag添加到模板中需要的位置:
{% submit_upstream_scimma_form target observation_record redirect_url topic_name %}
submit_upstream_to_scimma
按钮的签名和docstring如下:
```
def submit_upstream_scimma_form(target=None, observation_record=None, redirect_url=None, topic=None):
"""
Renders a button to submit an alert upstream to a broker. At least one of target/obs record should be given.
:param broker: The name of the broker to which the button will lead, as in the name field of the broker module.
:type broker: str
:param target: The target to be submitted as an alert, if any.
:type target: ``Target``
:param observation_record: The observation record to be submitted as an alert, if any.
:type observation_record: ``ObservationRecord``
:param topic: The topic to submit the alerts to.
:type topic: str
:param redirect_url:
:type redirect_url: str
"""
```
运行测试
要运行测试,请在virtualenv中运行以下命令:
python tom_scimma/tests/run_tests.py
- 项目
标签: