Minion Alive Plugin sample
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
class AlivePlugin(BlockingPlugin): | |
""" | |
This plugin checks if the site is alive or not. If any error occurs, the whole plan | |
will be aborted. This is useful to have as the first plugin in a workflow. Anything | |
non-200 will be seen as a fatal error. | |
""" | |
PLUGIN_NAME = "Alive" | |
PLUGIN_WEIGHT = "light" | |
FURTHER_INFO = [ { | |
"URL": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html", | |
"Title": "W3C - Status Code Definitions" } ], | |
REPORTS = { | |
"good": | |
{ | |
"Summary": "Site is reachable", | |
"Description": "The server has responded with {status_code} status_code. \ | |
This indicates the site is reachable.", | |
"Severity": "Info", | |
"URLs": [ {"URL": None, "Extra": None} ], | |
"FurtherInfo": FURTHER_INFO, | |
}, | |
"bad": | |
{ | |
"Summary": "Site could not be reached", | |
"Description": None, | |
"Severity": "Fatal", | |
"URLs": [ { "URL": None, "Extra": None} ], | |
"FurtherInfo": FURTHER_INFO, | |
} | |
} | |
def do_run(self): | |
try: | |
r = minion.curly.get(self.configuration['target'], connect_timeout=5, timeout=15) | |
r.raise_for_status() | |
issue = self._format_report('good', description_formats={'status_code': str(r.status)}) | |
self.report_issue(issue) | |
except minion.curly.BadResponseError as error: | |
issue = self._format_report('bad', description=str(error)) | |
self.report_issue(issue) | |
return AbstractPlugin.EXIT_STATE_ABORTED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment