Resolved 1698 - MON fails to collect metrics from an OpenStack VIM with metrics suppo...
[osm/MON.git] / osm_mon / core / response.py
1 # Copyright 2017 Intel Research and Development Ireland Limited
2 # *************************************************************
3
4 # This file is part of OSM Monitoring module
5 # All Rights Reserved to Intel Corporation
6
7 # Licensed under the Apache License, Version 2.0 (the "License"); you may
8 # not use this file except in compliance with the License. You may obtain
9 # a copy of the License at
10
11 # http://www.apache.org/licenses/LICENSE-2.0
12
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
17 # under the License.
18
19 # For those usages not covered by the Apache License, Version 2.0 please
20 # contact: helena.mcgough@intel.com or adrian.hoban@intel.com
21 ##
22 """Generate valid responses to send back to the SO."""
23
24 import logging
25
26 log = logging.getLogger(__name__)
27
28 schema_version = "1.1"
29
30
31 class ResponseBuilder(object):
32 """Generates responses for OpenStack plugin."""
33
34 def __init__(self):
35 """Initialize OpenStack Response instance."""
36
37 def generate_response(self, key, **kwargs) -> dict:
38 """Make call to appropriate response function."""
39 if key == "create_alarm_response":
40 message = self.create_alarm_response(**kwargs)
41 elif key == "delete_alarm_response":
42 message = self.delete_alarm_response(**kwargs)
43 elif key == "notify_alarm":
44 message = self.notify_alarm(**kwargs)
45 else:
46 log.warning("Failed to generate a valid response message.")
47 message = None
48
49 return message
50
51 def create_alarm_response(self, **kwargs) -> dict:
52 """Generate a response for a create alarm request."""
53 create_alarm_resp = {"schema_version": schema_version,
54 "schema_type": "create_alarm_response",
55 "alarm_create_response": {
56 "correlation_id": kwargs['cor_id'],
57 "alarm_uuid": kwargs['alarm_id'],
58 "status": kwargs['status']}}
59 return create_alarm_resp
60
61 def delete_alarm_response(self, **kwargs) -> dict:
62 """Generate a response for a delete alarm request."""
63 delete_alarm_resp = {"schema_version": schema_version,
64 "schema_type": "alarm_delete_response",
65 "alarm_delete_response": {
66 "correlation_id": kwargs['cor_id'],
67 "alarm_uuid": kwargs['alarm_id'],
68 "status": kwargs['status']}}
69 return delete_alarm_resp
70
71 def notify_alarm(self, **kwargs) -> dict:
72 """Generate a response to send alarm notifications."""
73 notify_alarm_resp = {"schema_version": schema_version,
74 "schema_type": "notify_alarm",
75 "notify_details": {
76 "alarm_uuid": kwargs['alarm_id'],
77 "metric_name": kwargs['metric_name'],
78 "threshold_value": kwargs['threshold_value'],
79 "operation": kwargs['operation'],
80 "severity": kwargs['sev'],
81 "status": kwargs['status'],
82 "start_date": kwargs['date'],
83 "tags": kwargs['tags']}}
84 return notify_alarm_resp