Skip to content

Instantly share code, notes, and snippets.

@braoru
Created April 15, 2016 08:04
Show Gist options
  • Save braoru/991f963347316a240be1eee9cdae07e0 to your computer and use it in GitHub Desktop.
Save braoru/991f963347316a240be1eee9cdae07e0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2013:
# Sébastien Pasche, sebastien.pasche@leshop.ch
#
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
author = "Sebastien Pasche"
maintainer = "Sebastien Pasche"
version = "0.0.1"
import optparse
import sys
import os
import traceback
import logging
from collections import namedtuple
from pprint import pprint
from datadiff import diff
from operator import itemgetter
# Ok try to load our directory to load the plugin utils.
my_dir = os.path.dirname(__file__)
sys.path.insert(0, my_dir)
try:
from haproxy.stats import HAProxyStats
except ImportError:
print("ERROR : this plugin needs the local haproxy helpers lib. Please install it")
sys.exit(2)
# Settings
# -------
# Logging
logging.basicConfig(
format='%(asctime)s %(name)s %(levelname)s %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p'
)
logger = logging.getLogger("haproxy_config_check")
# OPT parsing
# -----------
parser = optparse.OptionParser(
"%prog [options]", version="%prog " + version)
usage = """%prog [options]
blabla
"""
parser = optparse.OptionParser(usage=usage)
# Das component
##
parser.add_option('--component-hostname',
dest="component_hostname",
help='default component hostname: Ex : int-albatros.internal.leshop.ch')
parser.add_option('-s', '--http-scheme',
dest="scheme", default="https",
help='HTTP scheme to connect to. Default : https://')
if __name__ == '__main__':
debug = True
if debug:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.CRITICAL)
status = "OK"
try:
#Get check data
##
#Check logic
##
except Exception as e:
logger.debug(e)
the_type, value, tb = sys.exc_info()
if debug:
traceback.print_tb(tb)
print("Error: {m}".format(m=e))
sys.exit(2)
finally:
if status == "Critical":
sys.exit(2)
if status == "Warning":
sys.exit(1)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment