def get_handler(conf, *args): """ :params args: handler requiremnets params The following parameters must be specified in 'args' by order: param 1: zcp configs param 2: a keystone client instance param 3: a nova client instance param 4: a zabbix handler instance """ cfg = conf if conf else conf.Conf() polling_handler = cfg.read_option('zcp_configs', 'polling_handler', 'mongodb') if polling_handler not in SUPPORTED_HANDLERS: LOG.error('%s not in supported handlers %s' % (polling_handler, SUPPORTED_HANDLERS.keys())) raise exceptions.NotImplementedError try: module = __import__(SUPPORTED_HANDLERS.get(polling_handler), fromlist=['zcp']) return module.get_handler(conf, *args) except ImportError or ValueError as e: LOG.error('Module %s not found in Python package %s' % (SUPPORTED_HANDLERS.get('polling_handler'), 'zcp')) raise except AttributeError or TypeError as e: msg = getattr(e, 'msg', '') or getattr(e, 'message', '') LOG.error(msg) raise except Exception as e: raise
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging import pika import time from zcp.common import conf LOG = logging.getLogger(__name__) cfg = conf.Conf() hosts = cfg.read_option('os_rabbitmq', 'rabbit_hosts') user = cfg.read_option('os_rabbitmq', 'rabbit_user') passwd = cfg.read_option('os_rabbitmq', 'rabbit_pass') port = cfg.read_option('os_rabbitmq', 'rabbit_port') vh = cfg.read_option('os_rabbitmq', 'rabbit_virtual_host') max_retries = int(cfg.read_option('os_rabbitmq', 'max_retries', -1)) retry_interval = int(cfg.read_option('os_rabbitmq', 'retry_interval', 5)) def connection(): connect = None connection_state = False attemps = 0 MAX_RETRIES = max_retries * len(hosts.split(','))
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging import functools from ceilometerclient.v2 import client as clm_clientv20 from zcp.common import conf CONF = conf.Conf() LOG = logging.getLogger(__name__) def logged(func): @functools.wraps(func) def with_logging(*args, **kwargs): try: return func(*args, **kwargs) except Exception, ex: msg = getattr(ex, 'message', None) or \ getattr(ex, 'msg', '') LOG.error(msg) raise return with_logging
import logging import multiprocessing from zcp.common import log from zcp.common import conf from zcp.task.polling.base_handler import HandlerAdapter from zcp.task import nova_handler from zcp.task import keystone_handler from zcp.keystone_client import Client from zcp.nova_client import Client as nova_Client from zcp import messaging from zcp import zabbix_handler log.init_log() LOG = logging.getLogger(__name__) conf_file = conf.Conf() def init_zcp(processes): """ Method used to initialize the Zabbix-Ceilometer Proxy """ # Creation of the Auth keystone-dedicated authentication class # Responsible for managing domain and project related requests ks_client = Client(conf_file) nv_client = nova_Client(conf_file) # Creation of the Zabbix Handler class # Responsible for the communication with Zabbix zabbix_hdl = zabbix_handler.ZabbixHandler( conf_file.read_option('zabbix_configs', 'zabbix_admin_user'),
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from logging.config import fileConfig import os from zcp.exceptions import LogConfigurationNotFound from zcp.common import conf cfg_file = conf.Conf() log_dir = cfg_file.read_option('log', 'log_dir') log_file = cfg_file.read_option('log', 'log_file') def init_log(): log_path = os.path.join(log_dir, log_file) try: fileConfig(log_path) except Exception: msg = "Please configure correctly and be sure file log path exists!" raise LogConfigurationNotFound(msg) else: logger = logging.getLogger() logger.debug('Start initializing ZCP log...')