Skip to content

Instantly share code, notes, and snippets.

@Lawouach
Created November 27, 2020 17:42
Show Gist options
  • Save Lawouach/1a07f972b20bfe72abab8d8f008ff5d3 to your computer and use it in GitHub Desktop.
Save Lawouach/1a07f972b20bfe72abab8d8f008ff5d3 to your computer and use it in GitHub Desktop.
{
"version": "1.0.0",
"title": "do stuff",
"description": "n/a",
"secrets": {
"myticketing": {
"token": "12345"
}
},
"controls": [
{
"name": "create-ticket",
"provider": {
"type": "python",
"module": "mynotifier",
"arguments": {
"ticketing_system_url": "https://httpbin.org/post"
}
}
}
],
"method": [
{
"type": "action",
"name": "say-hello",
"provider": {
"type": "process",
"path": "echo",
"arguments": "hello"
}
}
]
}
from chaoslib.types import Configuration, Experiment, Journal, Secrets
from logzero import logger
import requests
def after_experiment_control(context: Experiment, state: Journal,
ticketing_system_url: str,
configuration: Configuration = None,
secrets: Secrets = None) -> None:
"""
after-control of the experiment's execution
Called by the Chaos Toolkit after the experiment's completed. It passes the
journal of the execution. At that stage, the after control has no influence
over the execution however. Please see
https://docs.chaostoolkit.org/reference/api/journal/#journal-elements
for more information about the journal.
"""
r = requests.post(
ticketing_system_url,
headers={
"Authorization": "Bearer {}".format(
secrets.get("myticketing").get("token")
)
},
json={
"status": state.get("status")
}
)
logger.info(r.text)
if r.status_code > 399:
logger.debug("Failed to create ticket: {}".format(r.text))
@Lawouach
Copy link
Author

Simply copy those two files into the same directory, then install chaostoolkit and requests:

$ pip install chaostoolkit requests

Then run as follows:

$ export PYTHONPATH=`pwd`
$ chaos run experiment.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment