Skip to content

Instantly share code, notes, and snippets.

@ygjb
Created July 25, 2013 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ygjb/6080431 to your computer and use it in GitHub Desktop.
Save ygjb/6080431 to your computer and use it in GitHub Desktop.
Minion Alive Plugin sample
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