Created
November 27, 2020 17:42
-
-
Save Lawouach/1a07f972b20bfe72abab8d8f008ff5d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simply copy those two files into the same directory, then install chaostoolkit and requests:
Then run as follows: