public
Created

Minion Alive Plugin sample

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.