コード例 #1
0
ファイル: ec2_queue.py プロジェクト: globocom/cloudmon
    def __init__(self, owner, params, config):
        super(EC2Queue, self).__init__(config)
        # self.zabbix_api = zabbix_api
        self.type = 'ec2'
        self.config = config

        self.logger = logging.getLogger('cloudmon.ec2.queue')
        self.owner = owner
        if config['logging']['queue_log_file']:
            self.logger_queue = logging.getLogger('cloudstack_queue')
        else:
            self.logger_queue = False

        self.queue = params.get('queue', '')
        self.exchange = params.get('exchange', '')
        self.queue_creates = 0
        self.queue_updates = 0
        self.queue_deletes = 0
        params = pika.URLParameters(params['url'])

        for i in range(11):  # Almost never connects at first attempt
            try:
                channel = pika.BlockingConnection(params).channel()
                self.logger.info(
                    'Connected to the AWS EC2 Event Queue at %s attempt' %
                    (i + 1))
                break
            except pika.exceptions.ConnectionClosed:
                if i > 9:
                    self.logger.error(
                        'Failed to to connect to the AWS EC2 Event Queue.')
                    self.logger.error(traceback.format_exc())
                    return None
        try:
            for i in self.ROUTING_KEYS:
                channel.queue_bind(exchange=self.exchange,
                                   queue=self.queue,
                                   routing_key=i)
                self.logger.info(
                    'The following bind will be consumed: [%s, %s, %s]' %
                    (self.exchange, self.queue, i))
            self.channel = channel
        except Exception:
            self.logger.error(
                'Failed to create binds to the AWS EC2 Queue with params [%s, %s, %s]'
                % (self.exchange, self.queue, str(self.ROUTING_KEYS)))
            self.logger.error(traceback.format_exc())
            return None
コード例 #2
0
 def __init__(self, config):
     self.type = "cloudstack"
     self.threads_proj = []
     super(CloudStackConnector, self).__init__(config)
     self.logger = logging.getLogger("cloudmon." + self.type)
     self.monitored = self.config.get('monitored_instances', {})
     self.logger.info(
         "The following types of instance will be monitored as: %s",
         self.monitored)
     self.logger.info("Timeout for CloudStack HTTP(s) requests is %ss",
                      self.config['cloudstack']['timeout'])
     ssl_config = self.config['ssl']
     if ssl_config['verify_cloudstack'] and ssl_config['ca_bundle']:
         self.verify_cs = ssl_config['ca_bundle']
         self.logger.info(
             'All HTTPS requests to CloudStack are gonna be '
             'verified! Cert Bundle: %s', self.verify_cs)
     elif ssl_config['verify_cloudstack']:
         self.verify_cs = True
         self.logger.info(
             'All HTTPS requests to CloudStack are gonna be verified!')
     else:
         self.verify_cs = False
         self.logger.warning(
             'According to your configuration, all HTTPS requests to '
             'CloudStack are not gonna be verified!')
コード例 #3
0
ファイル: cloudstack.py プロジェクト: globocom/cloudmon
 def __init__(self, config):
     self.type = "cloudstack"
     self.threads_proj = []
     super(CloudStackConnector, self).__init__(config)
     self.logger = logging.getLogger("cloudmon." + self.type)
     self.monitored = self.config.get('monitored_instances', {})
     self.logger.info(
         "The following types of instance will be monitored as: %s",
         self.monitored
     )
     self.logger.info(
         "Timeout for CloudStack HTTP(s) requests is %ss",
         self.config['cloudstack']['timeout']
     )
     ssl_config = self.config['ssl']
     if ssl_config['verify_cloudstack'] and ssl_config['ca_bundle']:
         self.verify_cs = ssl_config['ca_bundle']
         self.logger.info(
             'All HTTPS requests to CloudStack are gonna be '
             'verified! Cert Bundle: %s',
             self.verify_cs
         )
     elif ssl_config['verify_cloudstack']:
         self.verify_cs = True
         self.logger.info(
             'All HTTPS requests to CloudStack are gonna be verified!'
         )
     else:
         self.verify_cs = False
         self.logger.warning(
             'According to your configuration, all HTTPS requests to '
             'CloudStack are not gonna be verified!'
         )
コード例 #4
0
 def __init__(self, config):
     self.type = 'ec2'
     super(EC2Connector, self).__init__(config)
     self.logger = logging.getLogger("cloudmon." + self.type)
     self.monitored = self.config.get('monitored_instances', {})
     self.logger.info(
         "The following types of instance will be monitored as: %s",
         self.monitored)
コード例 #5
0
ファイル: ec2.py プロジェクト: globocom/cloudmon
 def __init__(self, config):
     self.type = 'ec2'
     super(EC2Connector, self).__init__(config)
     self.logger = logging.getLogger("cloudmon." + self.type)
     self.monitored = self.config.get('monitored_instances', {})
     self.logger.info(
         "The following types of instance will be monitored as: %s",
         self.monitored
     )
コード例 #6
0
    def __init__(self, config):
        self.config = config
        self.connectors = {
            'cloudstack': CloudStackConnector(config),
            'ec2': EC2Connector(config),
        }
        self.socket = None
        self.threads = []

        self.logger = logging.getLogger('cloudmon.queue')
コード例 #7
0
ファイル: ec2_queue.py プロジェクト: globocom/cloudmon
    def __init__(self, owner, params, config):
        super(EC2Queue, self).__init__(config)
        # self.zabbix_api = zabbix_api
        self.type = 'ec2'
        self.config = config

        self.logger = logging.getLogger('cloudmon.ec2.queue')
        self.owner = owner
        if config['logging']['queue_log_file']:
            self.logger_queue = logging.getLogger('cloudstack_queue')
        else:
            self.logger_queue = False

        self.queue = params.get('queue', '')
        self.exchange = params.get('exchange', '')
        self.queue_creates = 0
        self.queue_updates = 0
        self.queue_deletes = 0
        params = pika.URLParameters(params['url'])

        for i in range(11):  # Almost never connects at first attempt
            try:
                channel = pika.BlockingConnection(params).channel()
                self.logger.info('Connected to the AWS EC2 Event Queue at %s attempt' %(i+1) )
                break
            except pika.exceptions.ConnectionClosed:
                if i > 9:
                    self.logger.error('Failed to to connect to the AWS EC2 Event Queue.')
                    self.logger.error(traceback.format_exc())
                    return None
        try:
            for i in self.ROUTING_KEYS:
                channel.queue_bind(
                    exchange=self.exchange,
                    queue=self.queue,
                    routing_key=i
                )
                self.logger.info('The following bind will be consumed: [%s, %s, %s]' % (self.exchange, self.queue, i) )
            self.channel = channel
        except Exception:
            self.logger.error('Failed to create binds to the AWS EC2 Queue with params [%s, %s, %s]' % (self.exchange, self.queue, str(self.ROUTING_KEYS)))
            self.logger.error(traceback.format_exc())
            return None
コード例 #8
0
ファイル: queue.py プロジェクト: globocom/cloudmon
    def __init__(self, config):
        self.config = config
        self.connectors = {
            'cloudstack': CloudStackConnector(config),
            'ec2': EC2Connector(config),
        }
        self.socket = None
        self.threads = []

        self.logger = logging.getLogger('cloudmon.queue')
コード例 #9
0
ファイル: cache.py プロジェクト: globocom/cloudmon
This module provides a Redis Cache object.
"""

import sys
import pickle
from functools import wraps

import redis

from cloudmon.connector.errors import CacheMiss, CacheError
# from errors import CacheMiss, CacheError

from cloudmon.utils.log import logging

logger = logging.getLogger(__name__)
# logger.setLevel(logging.getLevelName('DEBUG'))
# logger.addHandler(logging.StreamHandler(sys.stdout))


class Cache(object):
    """Redis Cache Object """

    SUPPORTED_FUNCS = {
        'listVirtualMachines': 'vms',
        'listRouters': 'vrouters',
        'listProjects': 'projects',
    }

    RESOURCES_TO_SESSION = {
        'VirtualMachine': 'vms',
コード例 #10
0
ファイル: zabbix.py プロジェクト: globocom/cloudmon
"""
zabbix
----------------------------------

Zabbix stuff for `cloudmon`.
"""

import re

from time import time, sleep
from pyzabbix import ZabbixAPI, ZabbixAPIException

from cloudmon.utils.log import logging

logger = logging.getLogger(__name__)

REQUEST_DELAY = 0.1


class ZabbixAPICM(ZabbixAPI):
    """This derived class is an extention to ZabbixAPI that adds a timer
    to not let the session expire"""

    def __init__(self,
                 server='http://localhost/zabbix',
                 session=None,
                 use_authenticate=False,
                 timeout=None,
                 session_expiration=7200):
        """This overrides the original ZabbixAPI __init__ method.