Example #1
0
def record_user_action(cse_operation,
                       status=OperationStatus.SUCCESS,
                       message=None,
                       telemetry_settings=None):
    """Record CSE user action information in telemetry server.

    No exceptions should be leaked. Catch all exceptions and log them.

    :param CseOperation cse_operation:
    :param OperationStatus status: SUCCESS/FAILURE of the user action
    :param str message: any information about failure or custom message
    :param dict telemetry_settings: telemetry section CSE config->service
    """
    try:
        if not telemetry_settings:
            server_config = get_server_runtime_config()
            telemetry_settings = None if not server_config else \
                server_config.get_value_at('service.telemetry')

        if telemetry_settings:
            if telemetry_settings.get('enable'):
                payload = get_payload_for_user_action(cse_operation, status,
                                                      message)  # noqa: E501
                _send_data_to_telemetry_server(payload, telemetry_settings)
        else:
            LOGGER.debug('No telemetry settings found.')
    except Exception as err:
        LOGGER.warning(
            f"Error in recording user action information:{str(err)}",
            exc_info=True)  # noqa: E501
 def on_connection_closed(self, unused_connection, amqp_exception):
     self._channel = None
     if self._closing:
         self._connection.ioloop.stop()
     else:
         LOGGER.warning(f"Connection closed, reopening in 5 seconds: "
                        f"({str(amqp_exception)})")
         self._connection.ioloop.call_later(5, self.reconnect)
Example #3
0
 def close_channel(self):
     LOGGER.debug(f"Closing channel ({self._channel})")
     if self._channel.is_closed or self._channel.is_closing:
         LOGGER.warning(f"Channel ({self._channel}) is already closed")
         return
     try:
         self._channel.close()
     except pika.exceptions.ConnectionWrongStateError as cwse:
         LOGGER.warn(
             f"Trying to close channel with unexpected state: [{cwse}]")
Example #4
0
def _send_data_to_telemetry_server(payload, telemetry_settings):
    """Send the given payload to telemetry server.

    :param dict payload: json metadata about CSE operation
    :param dict telemetry_settings: telemetry section of config->service
    """
    try:
        vac_client = VacClient(base_url=telemetry_settings['vac_url'],
                               collector_id=telemetry_settings['collector_id'],
                               instance_id=telemetry_settings['instance_id'],
                               vcd_ceip_id=telemetry_settings['vcd_ceip_id'],
                               logger_debug=LOGGER)
        vac_client.send_data(payload)
    except Exception as err:
        LOGGER.warning(f"Error in sending data to VAC :{str(err)}",
                       exc_info=True)  # noqa: E501
def record_user_action_details(cse_operation, cse_params,
                               telemetry_settings=None):
    """Record CSE user operation details in telemetry server.

    No exception should be leaked. Catch all exceptions and log them.

    :param CseOperation cse_operation: CSE operation information
    :param dict cse_params: CSE operation parameters
    :param dict telemetry_settings: telemetry section of config->service
    """
    try:
        if not telemetry_settings:
            telemetry_settings = get_server_runtime_config()['service']['telemetry']  # noqa: E501

        if telemetry_settings['enable']:
            payload = OPERATION_TO_PAYLOAD_GENERATOR[cse_operation](cse_params)
            _send_data_to_telemetry_server(payload, telemetry_settings)
    except Exception as err:
        LOGGER.warning(f"Error in recording CSE operation details :{str(err)}")  # noqa: E501
Example #6
0
def get_sys_admin_client():
    server_config = get_server_runtime_config()
    if not server_config['vcd']['verify']:
        SERVER_LOGGER.warning("InsecureRequestWarning: Unverified HTTPS "
                              "request is being made. Adding certificate "
                              "verification is strongly advised.")
        requests.packages.urllib3.disable_warnings()
    log_filename = None
    log_wire = str_to_bool(server_config['service'].get('log_wire'))
    if log_wire:
        log_filename = SERVER_DEBUG_WIRELOG_FILEPATH
    client = vcd_client.Client(uri=server_config['vcd']['host'],
                               api_version=server_config['vcd']['api_version'],
                               verify_ssl_certs=server_config['vcd']['verify'],
                               log_file=log_filename,
                               log_requests=log_wire,
                               log_headers=log_wire,
                               log_bodies=log_wire)
    credentials = vcd_client.BasicLoginCredentials(
        server_config['vcd']['username'], SYSTEM_ORG_NAME,
        server_config['vcd']['password'])
    client.set_credentials(credentials)
    return client
Example #7
0
 def on_channel_closed(self, channel, amqp_exception):
     LOGGER.warning(f"Closing channel ({channel}) due to exception: "
                    f"({str(amqp_exception)})")
     if self._channel.is_closed or self._channel.is_closing:
         LOGGER.warning(f"Channel ({channel}) is already closed")
         return
     try:
         self._connection.close()
     except pika.exceptions.ConnectionWrongStateError as cwse:
         LOGGER.warning(f"Connection is closed or closing: ({cwse})")