Skip to main content

Skip/Hopskotch broker module for the TOM Toolkit

Project description

pypi run-tests Codacy Badge Coverage Status

tom_scimma

This module adds Hopskotch and Skip support to the TOM Toolkit. Using this module, TOMs can query alerts submitted to the Hopskotch stream, and publish alerts to Hopskotch.

Installation

Install the module into your TOM environment:

pip install tom-scimma

Add tom_scimma.scimma.SCIMMABroker to the TOM_ALERT_CLASSES in your TOM's settings.py:

TOM_ALERT_CLASSES = [
    'tom_alerts.brokers.mars.MARSBroker',
    ...
    'tom_scimma.scimma.SCIMMABroker'
]

Though Skip alerts are public (for now), you'll need Hopskotch credentials to submit alerts. You can register for an account here. Add the appropriate Skip and Hopskotch credentials to your project's 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': ''
        }
    }

Configurable settings

url: The URL for Skip requests, i.e. for retrieving alerts.

api_key: The API key used to authenticate/authorize with Skip. Currently unused.

hopskotch_url: The URL for Hopskotch broker submissions, i.e. submitting alerts.

hopskotch_username: The username used to authenticate with Hopskotch.

hopskotch_password: The password used to authenticate with Hopskotch.

default_hopskotch_topic: The Hopskotch topic to submit alerts to when none is provided.

Available templatetags

Though the TOM Toolkit provides a broker submission templatetag, tom_scimma provides an additional templatetag that includes a keyword argument for topic. To use it,

Add tom_scimma to your settings.INSTALLED_APPS:

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        ...
        'tom_scimma'
    ]

Then, add scimma_extras to the {% load ... %} statement of your desired template:

    {% load bootstrap4 targets_extras ... scimma_extras %}

Finally, add your desired templatetag where you would like it in your template:

    {% submit_upstream_scimma_form target observation_record redirect_url topic_name %}

The signature and docstring of the submit_upstream_to_scimma button are as follows:

```
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
    """
```

Running the tests

In order to run the tests, run the following in your virtualenv:

python tom_scimma/tests/run_tests.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tom-scimma-1.1.6.tar.gz (25.4 kB view hashes)

Uploaded Source

Built Distribution

tom_scimma-1.1.6-py3-none-any.whl (24.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page