- # Check the alarming functionlity that needs to be performed
- for message in self._consumer:
-
- values = json.loads(message.value)
- vim_type = values['vim_type'].lower()
-
- if vim_type == "openstack":
- log.info("Alarm action required: %s" % (message.topic))
-
- # Generate and auth_token and endpoint for request
- auth_token, endpoint = self.authenticate()
-
- if message.key == "create_alarm_request":
- # Configure/Update an alarm
- alarm_details = values['alarm_create_request']
-
- alarm_id, alarm_status = self.configure_alarm(
- endpoint, auth_token, alarm_details)
-
- # Generate a valid response message, send via producer
- try:
- if alarm_status is True:
- log.info("Alarm successfully created")
-
- resp_message = self._response.generate_response(
- 'create_alarm_response', status=alarm_status,
- alarm_id=alarm_id,
- cor_id=alarm_details['correlation_id'])
- log.info("Response Message: %s", resp_message)
- self._producer.create_alarm_response(
- 'create_alarm_resonse', resp_message,
- 'alarm_response')
- except Exception as exc:
- log.warn("Response creation failed: %s", exc)
-
- elif message.key == "list_alarm_request":
- # Check for a specifed: alarm_name, resource_uuid, severity
- # and generate the appropriate list
- list_details = values['alarm_list_request']
-
- alarm_list = self.list_alarms(
- endpoint, auth_token, list_details)
-
- try:
- # Generate and send a list response back
- resp_message = self._response.generate_response(
- 'list_alarm_response', alarm_list=alarm_list,
- cor_id=list_details['correlation_id'])
- log.info("Response Message: %s", resp_message)
- self._producer.list_alarm_response(
- 'list_alarm_response', resp_message,
- 'alarm_response')
- except Exception as exc:
- log.warn("Failed to send a valid response back.")
-
- elif message.key == "delete_alarm_request":
- request_details = values['alarm_delete_request']
- alarm_id = request_details['alarm_uuid']
-
- resp_status = self.delete_alarm(
- endpoint, auth_token, alarm_id)
-
- # Generate and send a response message
- try:
- resp_message = self._response.generate_response(
- 'delete_alarm_response', alarm_id=alarm_id,
- status=resp_status,
- cor_id=request_details['correlation_id'])
- log.info("Response message: %s", resp_message)
- self._producer.delete_alarm_response(
- 'delete_alarm_response', resp_message,
- 'alarm_response')
- except Exception as exc:
- log.warn("Failed to create delete reponse:%s", exc)
-
- elif message.key == "acknowledge_alarm":
- # Acknowledge that an alarm has been dealt with by the SO
- alarm_id = values['ack_details']['alarm_uuid']
-
- response = self.update_alarm_state(
- endpoint, auth_token, alarm_id)
-
- # Log if an alarm was reset
- if response is True:
- log.info("Acknowledged the alarm and cleared it.")
- else:
- log.warn("Failed to acknowledge/clear the alarm.")
-
- elif message.key == "update_alarm_request":
- # Update alarm configurations
- alarm_details = values['alarm_update_request']
-
- alarm_id, status = self.update_alarm(
- endpoint, auth_token, alarm_details)
-
- # Generate a response for an update request
- try:
- resp_message = self._response.generate_response(
- 'update_alarm_response', alarm_id=alarm_id,
- cor_id=alarm_details['correlation_id'],
- status=status)
- log.info("Response message: %s", resp_message)
- self._producer.update_alarm_response(
- 'update_alarm_response', resp_message,
- 'alarm_response')
- except Exception as exc:
- log.warn("Failed to send an update response:%s", exc)