Reformat MON to standardized format
[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 = {
54 "schema_version": schema_version,
55 "schema_type": "create_alarm_response",
56 "alarm_create_response": {
57 "correlation_id": kwargs["cor_id"],
58 "alarm_uuid": kwargs["alarm_id"],
59 "status": kwargs["status"],
60 },
61 }
62 return create_alarm_resp
63
64 def delete_alarm_response(self, **kwargs) -> dict:
65 """Generate a response for a delete alarm request."""
66 delete_alarm_resp = {
67 "schema_version": schema_version,
68 "schema_type": "alarm_delete_response",
69 "alarm_delete_response": {
70 "correlation_id": kwargs["cor_id"],
71 "alarm_uuid": kwargs["alarm_id"],
72 "status": kwargs["status"],
73 },
74 }
75 return delete_alarm_resp
76
77 def notify_alarm(self, **kwargs) -> dict:
78 """Generate a response to send alarm notifications."""
79 notify_alarm_resp = {
80 "schema_version": schema_version,
81 "schema_type": "notify_alarm",
82 "notify_details": {
83 "alarm_uuid": kwargs["alarm_id"],
84 "metric_name": kwargs["metric_name"],
85 "threshold_value": kwargs["threshold_value"],
86 "operation": kwargs["operation"],
87 "severity": kwargs["sev"],
88 "status": kwargs["status"],
89 "start_date": kwargs["date"],
90 "tags": kwargs["tags"],
91 },
92 }
93 return notify_alarm_resp