示例#1
0
 def load_config(self, config_path):
     """ The config file will be loaded from the path given with the -c
         option path when running the script. If no -c option given it will
         also look for config.ini in:
             - local himlarcli root
             - /etc/himlarcli/
         If no config is found it will exit.
     """
     if config_path and not os.path.isfile(config_path):
         self.log_error("Could not find config file: {}".format(config_path), 1)
     elif not config_path:
         self.config_path = None
         local_config = utils.get_abs_path('config.ini')
         etc_config = '/etc/himlarcli/config.ini'
         if os.path.isfile(local_config):
             self.config_path = local_config
         else:
             if os.path.isfile(etc_config):
                 self.config_path = etc_config
         if not self.config_path:
             msg = "Config file not found in default locations:\n  {}\n  {}"
             self.log_error(msg.format(local_config, etc_config), 1)
     else:
         self.config_path = config_path
     return utils.get_config(self.config_path)
示例#2
0
文件: client.py 项目: tanzr/himlarcli
    def __init__(self, config_path, debug, log=None, region=None):
        self.config_path = config_path
        self.config = utils.get_config(config_path)
        self.logger = utils.get_logger(__name__, self.config, debug, log)
        self.logger.debug('=> config file: %s' % config_path)
        self.debug = debug
        self.dry_run = False

        openstack = self.get_config_section('openstack')
        auth = v3.Password(auth_url=openstack['auth_url'],
                           username=openstack['username'],
                           password=openstack['password'],
                           project_name=openstack['project_name'],
                           user_domain_name=openstack['default_domain'],
                           project_domain_name=openstack['default_domain'])

        if 'keystone_cachain' in openstack:
            self.sess = session.Session(auth=auth,
                                        verify=openstack['keystone_cachain'])
        else:
            self.sess = session.Session(auth=auth)

        if region:
            self.region = region
        else:
            self.region = self.get_config('openstack', 'region')
示例#3
0
    def __init__(self, config_path, debug, log=None, region=None):
        self.config_path = config_path
        self.config = utils.get_config(config_path)
        self.logger = utils.get_logger(__name__, self.config, debug, log)
        self.logger.debug('=> config file: %s' % config_path)
        self.debug = debug
        self.dry_run = False

        openstack = self.get_config_section('openstack')
        auth = v3.Password(auth_url=openstack['auth_url'],
                           username=openstack['username'],
                           password=openstack['password'],
                           project_name=openstack['project_name'],
                           user_domain_name=openstack['default_domain'],
                           project_domain_name=openstack['default_domain'])

        if 'keystone_cachain' in openstack:
            self.sess = session.Session(auth=auth,
                                        verify=openstack['keystone_cachain'])
        else:
            self.sess = session.Session(auth=auth)

        if region:
            self.region = region
        else:
            self.region = self.get_config('openstack', 'region')
示例#4
0
 def __init__(self, config_path, debug, log=False):
     self.config_path = config_path
     self.config = utils.get_config(config_path)
     self.logger = utils.get_logger(__name__, self.config, debug, log)
     self.logger.debug('=> config file: %s', config_path)
     self.debug = debug
     self.db = self.__get_config('state', 'db')
     self.connect()
     # Make sure all tables exists
     self.__create_tables()
示例#5
0
文件: notify.py 项目: tanzr/himlarcli
 def __init__(self, config_path, debug=False, log=None):
     debug_level = 1 if debug else 0
     self.config_path = config_path
     self.config = utils.get_config(config_path)
     self.logger = utils.get_logger(__name__, self.config, debug, log)
     self.logger.debug('=> config file: %s' % config_path)
     self.debug = debug
     self.dry_run = False
     self.ksclient = None
     self.server = smtplib.SMTP(self.get_config('mail', 'smtp'), 25)
     self.server.set_debuglevel(debug_level)
     self.server.starttls()
示例#6
0
    def __init__(self, config_path, debug=False, version='1', log=None):
        self.config = utils.get_config(config_path)
        self.logger = utils.get_logger(__name__, self.config, debug, log)
        config = self.get_config_section('foreman')
        self.logger.debug('=> config file: %s' % config_path)
        self.logger.debug('=> foreman url: %s' % config['url'])

        self.foreman = Foreman(config['url'],
                               (config['user'], config['password']),
                               api_version=2,
                               version=version,
                               verify=False)
示例#7
0
 def __init__(self, config_path, debug=False, log=None):
     debug_level = 1 if debug else 0
     self.config_path = config_path
     self.config = utils.get_config(config_path)
     self.logger = utils.get_logger(__name__, self.config, debug, log)
     self.logger.debug('=> config file: %s' % config_path)
     self.debug = debug
     self.dry_run = False
     self.ksclient = None
     self.server = smtplib.SMTP(self.get_config('mail', 'smtp'), 25)
     self.server.set_debuglevel(debug_level)
     self.server.starttls()
示例#8
0
def config_file(config_path):
    config_template = utils.get_abs_path('tests/config.yaml')
    config = utils.get_config(config_path)
    with open(config_template) as template:
        try:
            tests = yaml.full_load(template)
        except yaml.YAMLError as e:
            print e
    for section, options in tests.iteritems():
        if not config.has_section(section):
            print "Missing section [%s]" % section
            sys.exit(1)
        for i in options:
            if not config.has_option(section, i):
                print "Missing option %s in section [%s]" % (i, section)
                sys.exit(1)
示例#9
0
def config_file(config_path):
    config_template = utils.get_abs_path('tests/config.yaml')
    config = utils.get_config(config_path)
    with open(config_template) as template:
        try:
            tests = yaml.load(template)
        except yaml.YAMLError as e:
            print e
    for section, options in tests.iteritems():
        if not config.has_section(section):
            print "Missing section [%s]" % section
            sys.exit(1)
        for i in options:
            if not config.has_option(section, i):
                print "Missing option %s in section [%s]" % (i,section)
                sys.exit(1)
示例#10
0
    def __init__(self, config_path, debug, log=None):
        self.config = utils.get_config(config_path)
        self.logger = utils.get_logger(__name__, self.config, debug, log)
        self.logger.debug('=> config file: %s', config_path)
        self.dry_run = False
        self.debug = debug
        credentials = pika.PlainCredentials(
            username=self.__get_config('rabbitmq', 'username'),
            password=self.__get_config('rabbitmq', 'password'))

        parameters = pika.ConnectionParameters(
            host=self.__get_config('rabbitmq', 'host'),
            virtual_host=self.__get_config('rabbitmq', 'vhost'),
            credentials=credentials,
            connection_attempts=5,
            retry_delay=30,
            socket_timeout=10,
            blocked_connection_timeout=20,
            heartbeat_interval=10)
        self.connection = pika.BlockingConnection(parameters)
示例#11
0
    parser.toggle_show('dry-run')
    parser.toggle_show('format')
    parser.toggle_show('config')
    parser.add_actions({'start': 'start',
                        'stop': 'stop',
                        'restart': 'restart',
                        'status': 'status'})
    parser.add_opt_args({'-f': {'sub': 'start',
                                'dest': 'foreground',
                                'const': True,
                                'default': False,
                                'action': 'store_const'}})
    options = parser.parse_args()

    # Config with defaults that services.ini overrides
    config = himutils.get_config('services.ini')
    log_file = utils.get_config(config, sname, 'log_file', '/var/log/%s.log' % sname)
    loglevel = utils.get_config(config, sname, 'loglevel', 'INFO')
    pidfile = utils.get_config(config, sname, 'pidfile', '/var/run/%s.pid' % sname)
    workingdir = utils.get_config(config, sname, 'workingdir', '/opt/himlarservice')
    himlarcli_config = utils.get_config(config, sname, 'himlarcli_config',
                                        '/etc/himlarcli/config.ini')
    signal_map = {
        signal.SIGTERM: shutdown,
        signal.SIGPIPE: shutdown,
        signal.SIGINT: shutdown}
    stdout = sys.stdout if options.debug else None
    stderr = sys.stderr if options.debug else None
    if hasattr(options, 'foreground'):
        detatch = True if not options.foreground else False
    else:
示例#12
0
#!/usr/bin/env python
import utils
import httplib
import statsd
from himlarcli import utils as himutils
import socket

desc = 'Do a remote check of web services'
options = utils.get_options(desc, hosts=False, debug=True)

# Himmlar config
config = himutils.get_config(options.config)
region = config.get('openstack', 'region')
logger = himutils.get_logger(__name__, config, options.debug)

# statsd
statsd_server = config.get('statsd', 'server')
statsd_port = config.get('statsd', 'port')
prefix = 'uh-iaas.%s.checks' % region
statsd = statsd.StatsClient(statsd_server, statsd_port, prefix=prefix)

# Services to check
services = himutils.load_region_config('config/checks',
                                       region=region,
                                       log=logger)

for name, check in sorted(services['checks'].iteritems()):
    if 'timeout' in check:
        timeout = check['timeout']
    else:
        timeout = 10