Fixes loading of vim config in OpenStack plugin
[osm/MON.git] / osm_mon / plugins / vRealiseOps / mon_plugin_vrops.py
index 309cec9..17f4fbd 100644 (file)
 ##
 
 """
 ##
 
 """
-Montoring metrics & creating Alarm definations in vROPs
+Monitoring metrics & creating Alarm definitions in vROPs
 """
 
 import requests
 import logging
 """
 
 import requests
 import logging
-from pyvcloud.vcloudair import VCA
+
+from pyvcloud.vcd.client import BasicLoginCredentials
+from pyvcloud.vcd.client import Client
+API_VERSION = '5.9'
+
 from xml.etree import ElementTree as XmlElementTree
 import traceback
 import time
 from xml.etree import ElementTree as XmlElementTree
 import traceback
 import time
@@ -131,8 +135,16 @@ class MonPlugin():
         if not metric_key_params:
             self.logger.warn("Metric not supported: {}".format(config_dict['metric_name']))
             return None
         if not metric_key_params:
             self.logger.warn("Metric not supported: {}".format(config_dict['metric_name']))
             return None
-        #2) create symptom definition
+
+        #1.2) Check if alarm definition already exists
         vrops_alarm_name = def_a_params['vrops_alarm']+ '-' + config_dict['resource_uuid']
         vrops_alarm_name = def_a_params['vrops_alarm']+ '-' + config_dict['resource_uuid']
+        alert_def_list = self.get_alarm_defination_by_name(vrops_alarm_name)
+        if alert_def_list:
+            self.logger.warn("Alarm already exists: {}. Try updating by update_alarm_request"\
+                            .format(vrops_alarm_name))
+            return None
+
+        #2) create symptom definition
         symptom_params ={'cancel_cycles': (def_a_params['cancel_period']/300)*def_a_params['cancel_cycles'],
                         'wait_cycles': (def_a_params['period']/300)*def_a_params['evaluation'],
                         'resource_kind_key': def_a_params['resource_kind'],
         symptom_params ={'cancel_cycles': (def_a_params['cancel_period']/300)*def_a_params['cancel_cycles'],
                         'wait_cycles': (def_a_params['period']/300)*def_a_params['evaluation'],
                         'resource_kind_key': def_a_params['resource_kind'],
@@ -152,7 +164,7 @@ class MonPlugin():
         #To Do - Get type & subtypes for all 5 alarms
         alarm_params = {'name':vrops_alarm_name,
                         'description':config_dict['description']\
         #To Do - Get type & subtypes for all 5 alarms
         alarm_params = {'name':vrops_alarm_name,
                         'description':config_dict['description']\
-                        if config_dict['description'] is not None else config_dict['alarm_name'],
+                        if config_dict.has_key('description') and config_dict['description'] is not None else config_dict['alarm_name'],
                         'adapterKindKey':def_a_params['adapter_kind'],
                         'resourceKindKey':def_a_params['resource_kind'],
                         'waitCycles':1, 'cancelCycles':1,
                         'adapterKindKey':def_a_params['adapter_kind'],
                         'resourceKindKey':def_a_params['resource_kind'],
                         'waitCycles':1, 'cancelCycles':1,
@@ -195,7 +207,7 @@ class MonPlugin():
         """
         Read the default config parameters from plugin specific file stored with plugin file.
         Params:
         """
         Read the default config parameters from plugin specific file stored with plugin file.
         Params:
-            metric_alarm_name: Name of the alarm, whose congif params to be read from the config file.
+            metric_alarm_name: Name of the alarm, whose config parameters to be read from the config file.
         """
         a_params = {}
         try:
         """
         a_params = {}
         try:
@@ -244,45 +256,42 @@ class MonPlugin():
 
         try:
             api_url = '/suite-api/api/symptomdefinitions'
 
         try:
             api_url = '/suite-api/api/symptomdefinitions'
-            headers = {'Content-Type': 'application/xml'}
-            data = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-                        <ops:symptom-definition cancelCycles="{0:s}" waitCycles="{1:s}"
-                            resourceKindKey="{2:s}" adapterKindKey="{3:s}"
-                            xmlns:xs="http://www.w3.org/2001/XMLSchema"
-                            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-                            xmlns:ops="http://webservice.vmware.com/vRealizeOpsMgr/1.0/">
-                            <ops:name>{4:s}</ops:name>
-                            <ops:state severity="{5:s}">
-                                <ops:condition xsi:type="ops:htCondition">
-                                    <ops:key>{6:s}</ops:key>
-                                    <ops:operator>{7:s}</ops:operator>
-                                    <ops:value>{8:s}</ops:value>
-                                    <ops:valueType>NUMERIC</ops:valueType>
-                                    <ops:instanced>false</ops:instanced>
-                                    <ops:thresholdType>STATIC</ops:thresholdType>
-                                </ops:condition>
-                            </ops:state>
-                        </ops:symptom-definition>"""\
-                        .format(str(symptom_params['cancel_cycles']),str(symptom_params['wait_cycles']),
-                                symptom_params['resource_kind_key'], symptom_params['adapter_kind_key'],
-                                symptom_params['symptom_name'],symptom_params['severity'],
-                                symptom_params['metric_key'],symptom_params['operation'],
-                                str(symptom_params['threshold_value']))
+            headers = {'Content-Type': 'application/json','Accept': 'application/json'}
+            data = {
+                        "id": None,
+                        "name": symptom_params['symptom_name'],
+                        "adapterKindKey": symptom_params['adapter_kind_key'],
+                        "resourceKindKey": symptom_params['resource_kind_key'],
+                        "waitCycles": symptom_params['wait_cycles'],
+                        "cancelCycles": symptom_params['cancel_cycles'],
+                        "state": {
+                            "severity": symptom_params['severity'],
+                            "condition": {
+                                "type": "CONDITION_HT",
+                                "key": symptom_params['metric_key'],
+                                "operator": symptom_params['operation'],
+                                "value": symptom_params['threshold_value'],
+                                "valueType": "NUMERIC",
+                                "instanced": False,
+                                "thresholdType": "STATIC"
+                            }
+                        }
+                    }
 
             resp = requests.post(self.vrops_site + api_url,
                                  auth=(self.vrops_user, self.vrops_password),
                                  headers=headers,
                                  verify = False,
 
             resp = requests.post(self.vrops_site + api_url,
                                  auth=(self.vrops_user, self.vrops_password),
                                  headers=headers,
                                  verify = False,
-                                 data=data)
+                                 data=json.dumps(data))
 
             if resp.status_code != 201:
                 self.logger.warn("Failed to create Symptom definition: {}, response {}"\
                         .format(symptom_params['symptom_name'], resp.content))
                 return None
 
 
             if resp.status_code != 201:
                 self.logger.warn("Failed to create Symptom definition: {}, response {}"\
                         .format(symptom_params['symptom_name'], resp.content))
                 return None
 
-            symptom_xmlroot = XmlElementTree.fromstring(resp.content)
-            if symptom_xmlroot is not None and 'id' in symptom_xmlroot.attrib:
-                symptom_id = symptom_xmlroot.attrib['id']
+            resp_data = json.loads(resp.content)
+            if resp_data.get('id') is not None:
+                symptom_id = resp_data['id']
 
             return symptom_id
 
 
             return symptom_id
 
@@ -314,57 +323,49 @@ class MonPlugin():
 
         try:
             api_url = '/suite-api/api/alertdefinitions'
 
         try:
             api_url = '/suite-api/api/alertdefinitions'
-            headers = {'Content-Type': 'application/xml'}
-            data = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-                        <ops:alert-definition xmlns:xs="http://www.w3.org/2001/XMLSchema"
-                            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-                            xmlns:ops="http://webservice.vmware.com/vRealizeOpsMgr/1.0/">
-                            <ops:name>{0:s}</ops:name>
-                            <ops:description>{1:s}</ops:description>
-                            <ops:adapterKindKey>{2:s}</ops:adapterKindKey>
-                            <ops:resourceKindKey>{3:s}</ops:resourceKindKey>
-                            <ops:waitCycles>1</ops:waitCycles>
-                            <ops:cancelCycles>1</ops:cancelCycles>
-                            <ops:type>{4:s}</ops:type>
-                            <ops:subType>{5:s}</ops:subType>
-                            <ops:states>
-                                <ops:state severity="{6:s}">
-                                    <ops:symptom-set>
-                                        <ops:symptomDefinitionIds>
-                                            <ops:symptomDefinitionId>{7:s}</ops:symptomDefinitionId>
-                                        </ops:symptomDefinitionIds>
-                                        <ops:relation>SELF</ops:relation>
-                                        <ops:aggregation>ALL</ops:aggregation>
-                                        <ops:symptomSetOperator>AND</ops:symptomSetOperator>
-                                    </ops:symptom-set>
-                                    <ops:impact>
-                                        <ops:impactType>BADGE</ops:impactType>
-                                        <ops:detail>{8:s}</ops:detail>
-                                    </ops:impact>
-                                </ops:state>
-                            </ops:states>
-                        </ops:alert-definition>"""\
-                        .format(alarm_params['name'],alarm_params['description'],
-                                alarm_params['adapterKindKey'],alarm_params['resourceKindKey'],
-                                str(alarm_params['type']),str(alarm_params['subType']),
-                                alarm_params['severity'],alarm_params['symptomDefinitionId'],
-                                alarm_params['impact'])
+            headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
+            data = {
+                        "name": alarm_params['name'],
+                        "description": alarm_params['description'],
+                        "adapterKindKey": alarm_params['adapterKindKey'],
+                        "resourceKindKey": alarm_params['resourceKindKey'],
+                        "waitCycles": 1,
+                        "cancelCycles": 1,
+                        "type": alarm_params['type'],
+                        "subType": alarm_params['subType'],
+                        "states": [
+                            {
+                                "severity": alarm_params['severity'],
+                                "base-symptom-set":
+                                    {
+                                        "type": "SYMPTOM_SET",
+                                        "relation": "SELF",
+                                        "aggregation": "ALL",
+                                        "symptomSetOperator": "AND",
+                                        "symptomDefinitionIds": [alarm_params['symptomDefinitionId']]
+                                    },
+                                "impact": {
+                                    "impactType": "BADGE",
+                                    "detail": alarm_params['impact']
+                                }
+                            }
+                        ]
+                    }
 
             resp = requests.post(self.vrops_site + api_url,
                                  auth=(self.vrops_user, self.vrops_password),
                                  headers=headers,
                                  verify = False,
 
             resp = requests.post(self.vrops_site + api_url,
                                  auth=(self.vrops_user, self.vrops_password),
                                  headers=headers,
                                  verify = False,
-                                 data=data)
+                                 data=json.dumps(data))
 
             if resp.status_code != 201:
                 self.logger.warn("Failed to create Alarm definition: {}, response {}"\
                         .format(alarm_params['name'], resp.content))
                 return None
 
 
             if resp.status_code != 201:
                 self.logger.warn("Failed to create Alarm definition: {}, response {}"\
                         .format(alarm_params['name'], resp.content))
                 return None
 
-            alarm_xmlroot = XmlElementTree.fromstring(resp.content)
-            for child in alarm_xmlroot:
-                if child.tag.split("}")[1] == 'id':
-                    alarm_uuid = child.text
+            resp_data = json.loads(resp.content)
+            if resp_data.get('id') is not None:
+                alarm_uuid = resp_data['id']
 
             return alarm_uuid
 
 
             return alarm_uuid
 
@@ -395,26 +396,35 @@ class MonPlugin():
             cert = load_certificate(FILETYPE_PEM, cert_file_string)
             certificate = cert.digest("sha1")
             api_url = '/suite-api/api/alertplugins'
             cert = load_certificate(FILETYPE_PEM, cert_file_string)
             certificate = cert.digest("sha1")
             api_url = '/suite-api/api/alertplugins'
-            headers = {'Content-Type': 'application/xml'}
-            data =   """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-                        <ops:notification-plugin version="0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
-                            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-                            xmlns:ops="http://webservice.vmware.com/vRealizeOpsMgr/1.0/">
-                            <ops:pluginTypeId>RestPlugin</ops:pluginTypeId>
-                            <ops:name>{0:s}</ops:name>
-                            <ops:configValues>
-                                <ops:configValue name="Url">{1:s}</ops:configValue>
-                                <ops:configValue name="Content-type">application/json</ops:configValue>
-                                <ops:configValue name="Certificate">{2:s}</ops:configValue>
-                                <ops:configValue name="ConnectionCount">20</ops:configValue>
-                            </ops:configValues>
-                        </ops:notification-plugin>""".format(plugin_name, webhook_url, certificate)
+            headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
+            data = {
+                        "pluginTypeId": "RestPlugin",
+                        "name": plugin_name,
+                        "configValues": [
+                            {
+                                "name": "Url",
+                                "value": webhook_url
+                            },
+                            {
+                                "name": "Content-type",
+                                "value": "application/json"
+                            },
+                            {
+                                "name": "Certificate",
+                                "value": certificate
+                            },
+                            {
+                                "name": "ConnectionCount",
+                                "value": "20"
+                            }
+                        ]
+                    }
 
             resp = requests.post(self.vrops_site + api_url,
                                  auth=(self.vrops_user, self.vrops_password),
                                  headers=headers,
                                  verify = False,
 
             resp = requests.post(self.vrops_site + api_url,
                                  auth=(self.vrops_user, self.vrops_password),
                                  headers=headers,
                                  verify = False,
-                                 data=data)
+                                 data=json.dumps(data))
 
             if resp.status_code is not 201:
                 self.logger.warn("Failed to create REST Plugin: {} for url: {}, \nresponse code: {},"\
 
             if resp.status_code is not 201:
                 self.logger.warn("Failed to create REST Plugin: {} for url: {}, \nresponse code: {},"\
@@ -422,11 +432,9 @@ class MonPlugin():
                             resp.status_code, resp.content))
                 return None
 
                             resp.status_code, resp.content))
                 return None
 
-            plugin_xmlroot = XmlElementTree.fromstring(resp.content)
-            if plugin_xmlroot is not None:
-                for child in plugin_xmlroot:
-                    if child.tag.split("}")[1] == 'pluginId':
-                        plugin_id = plugin_xmlroot.find('{http://webservice.vmware.com/vRealizeOpsMgr/1.0/}pluginId').text
+            resp_data = json.loads(resp.content)
+            if resp_data.get('pluginId') is not None:
+                plugin_id = resp_data['pluginId']
 
             if plugin_id is None:
                 self.logger.warn("Failed to get REST Plugin ID for {}, url: {}".format(plugin_name, webhook_url))
 
             if plugin_id is None:
                 self.logger.warn("Failed to get REST Plugin ID for {}, url: {}".format(plugin_name, webhook_url))
@@ -448,8 +456,7 @@ class MonPlugin():
         plugin_id = None
         #Find the REST Plugin id details for - MON_module_REST_Plugin
         api_url = '/suite-api/api/alertplugins'
         plugin_id = None
         #Find the REST Plugin id details for - MON_module_REST_Plugin
         api_url = '/suite-api/api/alertplugins'
-        headers = {'Accept': 'application/xml'}
-        namespace = {'params':"http://webservice.vmware.com/vRealizeOpsMgr/1.0/"}
+        headers = {'Accept': 'application/json'}
 
         resp = requests.get(self.vrops_site + api_url,
                             auth=(self.vrops_user, self.vrops_password),
 
         resp = requests.get(self.vrops_site + api_url,
                             auth=(self.vrops_user, self.vrops_password),
@@ -461,15 +468,14 @@ class MonPlugin():
             return None
 
         # Look for specific plugin & parse pluginId for 'MON_module_REST_Plugin'
             return None
 
         # Look for specific plugin & parse pluginId for 'MON_module_REST_Plugin'
-        xmlroot_resp = XmlElementTree.fromstring(resp.content)
-        for notify_plugin in xmlroot_resp.findall('params:notification-plugin',namespace):
-            if notify_plugin.find('params:name',namespace) is not None and\
-                notify_plugin.find('params:pluginId',namespace) is not None:
-                if notify_plugin.find('params:name',namespace).text == plugin_name:
-                    plugin_id = notify_plugin.find('params:pluginId',namespace).text
+        plugins_list = json.loads(resp.content)
+        if plugins_list.get('notificationPluginInstances') is not None:
+            for notify_plugin in plugins_list['notificationPluginInstances']:
+                if notify_plugin.get('name') is not None and notify_plugin['name'] == plugin_name:
+                    plugin_id = notify_plugin.get('pluginId')
 
         if plugin_id is None:
 
         if plugin_id is None:
-            self.logger.warn("REST plugin {} not found".format('MON_module_REST_Plugin'))
+            self.logger.warn("REST plugin {} not found".format(plugin_name))
             return None
         else:
             self.logger.info("Found REST Plugin: {}".format(plugin_name))
             return None
         else:
             self.logger.info("Found REST Plugin: {}".format(plugin_name))
@@ -530,27 +536,24 @@ class MonPlugin():
 
         #2) Create Alarm notification rule
         api_url = '/suite-api/api/notifications/rules'
 
         #2) Create Alarm notification rule
         api_url = '/suite-api/api/notifications/rules'
-        headers = {'Content-Type': 'application/xml'}
-        data = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-                    <ops:notification-rule xmlns:xs="http://www.w3.org/2001/XMLSchema"
-                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-                        xmlns:ops="http://webservice.vmware.com/vRealizeOpsMgr/1.0/">
-                        <ops:name>{0:s}</ops:name>
-                        <ops:pluginId>{1:s}</ops:pluginId>
-                        <ops:resourceFilter resourceId="{2:s}">
-                            <ops:matchResourceIdOnly>true</ops:matchResourceIdOnly>
-                        </ops:resourceFilter>
-                        <ops:alertDefinitionIdFilters>
-                            <ops:values>{3:s}</ops:values>
-                        </ops:alertDefinitionIdFilters>
-                    </ops:notification-rule>"""\
-                    .format(notification_name, plugin_id, resource_id, alarm_id)
+        headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
+        data = {
+                    "name" : notification_name,
+                    "pluginId" : plugin_id,
+                    "resourceFilter": {
+                        "matchResourceIdOnly": True,
+                        "resourceId": resource_id
+                        },
+                    "alertDefinitionIdFilters" : {
+                    "values" : [ alarm_id ]
+                    }
+                }
 
         resp = requests.post(self.vrops_site + api_url,
                              auth=(self.vrops_user, self.vrops_password),
                              headers=headers,
                              verify = False,
 
         resp = requests.post(self.vrops_site + api_url,
                              auth=(self.vrops_user, self.vrops_password),
                              headers=headers,
                              verify = False,
-                             data=data)
+                             data=json.dumps(data))
 
         if resp.status_code is not 201:
             self.logger.warn("Failed to create Alarm notification rule {} for {} alarm."\
 
         if resp.status_code is not 201:
             self.logger.warn("Failed to create Alarm notification rule {} for {} alarm."\
@@ -559,9 +562,9 @@ class MonPlugin():
             return None
 
         #parse notification id from response
             return None
 
         #parse notification id from response
-        xmlroot_resp = XmlElementTree.fromstring(resp.content)
-        if xmlroot_resp is not None and 'id' in xmlroot_resp.attrib:
-            notification_id = xmlroot_resp.attrib.get('id')
+        resp_data = json.loads(resp.content)
+        if resp_data.get('id') is not None:
+            notification_id = resp_data['id']
 
         self.logger.info("Created Alarm notification rule {} for {} alarm.".format(notification_name, alarm_name))
         return notification_id
 
         self.logger.info("Created Alarm notification rule {} for {} alarm.".format(notification_name, alarm_name))
         return notification_id
@@ -598,20 +601,23 @@ class MonPlugin():
         parsed_respond = {}
         vca = None
 
         parsed_respond = {}
         vca = None
 
-        vca = self.connect_as_admin()
-
-        if not vca:
-            self.logger.warn("connect() to vCD is failed")
         if vapp_uuid is None:
             return None
 
         if vapp_uuid is None:
             return None
 
-        url_list = [vca.host, '/api/vApp/vapp-', vapp_uuid]
+        vca = self.connect_as_admin()
+        if not vca:
+            self.logger.warn("Failed to connect to vCD")
+            return parsed_respond
+
+        url_list = [self.vcloud_site, '/api/vApp/vapp-', vapp_uuid]
         get_vapp_restcall = ''.join(url_list)
 
         get_vapp_restcall = ''.join(url_list)
 
-        if vca.vcloud_session and vca.vcloud_session.organization:
+        if vca._session:
+            headers = {'Accept':'application/*+xml;version=' + API_VERSION,
+                       'x-vcloud-authorization': vca._session.headers['x-vcloud-authorization']}
             response = requests.get(get_vapp_restcall,
             response = requests.get(get_vapp_restcall,
-                                    headers=vca.vcloud_session.get_vcloud_headers(),
-                                    verify=vca.verify)
+                                    headers=headers,
+                                    verify=False)
 
             if response.status_code != 200:
                 self.logger.warn("REST API call {} failed. Return status code {}"\
 
             if response.status_code != 200:
                 self.logger.warn("REST API call {} failed. Return status code {}"\
@@ -654,23 +660,19 @@ class MonPlugin():
                 The return vca object that letter can be used to connect to vcloud direct as admin for provider vdc
         """
 
                 The return vca object that letter can be used to connect to vcloud direct as admin for provider vdc
         """
 
-        self.logger.info("Logging in to a VCD org as admin.")
+        self.logger.debug("Logging into vCD org as admin.")
 
 
-        vca_admin = VCA(host=self.vcloud_site,
-                        username=self.admin_username,
-                        service_type='standalone',
-                        version='5.9',
-                        verify=False,
-                        log=False)
-        result = vca_admin.login(password=self.admin_password, org='System')
-        if not result:
-            self.logger.warn("Can't connect to a vCloud director as: {}".format(self.admin_username))
-        result = vca_admin.login(token=vca_admin.token, org='System', org_url=vca_admin.vcloud_session.org_url)
-        if result is True:
-            self.logger.info("Successfully logged to a vcloud direct org: {} as user: {}"\
-                        .format('System', self.admin_username))
+        try:
+            host = self.vcloud_site
+            org = 'System'
+            client_as_admin = Client(host, verify_ssl_certs=False)
+            client_as_admin.set_credentials(BasicLoginCredentials(self.admin_username, org,\
+                                                                  self.admin_password))
+        except Exception as e:
+            self.logger.warn("Can't connect to a vCloud director as: {} with exception {}"\
+                             .format(self.admin_username, e))
 
 
-        return vca_admin
+        return client_as_admin
 
 
     def get_vm_resource_id(self, vm_moref_id):
 
 
     def get_vm_resource_id(self, vm_moref_id):
@@ -679,37 +681,42 @@ class MonPlugin():
         if vm_moref_id is None:
             return None
 
         if vm_moref_id is None:
             return None
 
-        api_url = '/suite-api/api/resources'
-        headers = {'Accept': 'application/xml'}
-        namespace = {'params':"http://webservice.vmware.com/vRealizeOpsMgr/1.0/"}
+        api_url = '/suite-api/api/resources?resourceKind=VirtualMachine'
+        headers = {'Accept': 'application/json'}
 
         resp = requests.get(self.vrops_site + api_url,
                             auth=(self.vrops_user, self.vrops_password),
                             verify = False, headers = headers)
 
         if resp.status_code is not 200:
 
         resp = requests.get(self.vrops_site + api_url,
                             auth=(self.vrops_user, self.vrops_password),
                             verify = False, headers = headers)
 
         if resp.status_code is not 200:
-            self.logger.warn("Failed to get resource details from vROPs for {}\nResponse code:{}\nResponse Content: {}"\
-                    .format(vm_moref_id, resp.status_code, resp.content))
+            self.logger.warn("Failed to get resource details from vROPs for {}"\
+                             "\nResponse code:{}\nResponse Content: {}"\
+                             .format(vm_moref_id, resp.status_code, resp.content))
             return None
 
             return None
 
+        vm_resource_id = None
         try:
         try:
-            xmlroot_respond = XmlElementTree.fromstring(resp.content)
-            for resource in xmlroot_respond.findall('params:resource',namespace):
-                if resource is not None:
-                    resource_key = resource.find('params:resourceKey',namespace)
-                    if resource_key is not None:
-                        if resource_key.find('params:adapterKindKey',namespace).text == 'VMWARE' and \
-                        resource_key.find('params:resourceKindKey',namespace).text == 'VirtualMachine':
-                            for child in resource_key:
-                                if child.tag.split('}')[1]=='resourceIdentifiers':
-                                    resourceIdentifiers = child
-                                    for r_id in resourceIdentifiers:
-                                        if r_id.find('params:value',namespace).text == vm_moref_id:
-                                            self.logger.info("Found Resource ID : {} in vROPs for {}"\
-                                                    .format(resource.attrib['identifier'], vm_moref_id))
-                                            return resource.attrib['identifier']
+            resp_data = json.loads(resp.content)
+            if resp_data.get('resourceList') is not None:
+                resource_list = resp_data.get('resourceList')
+                for resource in resource_list:
+                    if resource.get('resourceKey') is not None:
+                        resource_details = resource['resourceKey']
+                        if resource_details.get('resourceIdentifiers') is not None:
+                            resource_identifiers = resource_details['resourceIdentifiers']
+                            for resource_identifier in resource_identifiers:
+                                if resource_identifier['identifierType']['name']=='VMEntityObjectID':
+                                    if resource_identifier.get('value') is not None and \
+                                        resource_identifier['value']==vm_moref_id:
+                                        vm_resource_id = resource['identifier']
+                                        self.logger.info("Found VM resource ID: {} for vm_moref_id: {}"\
+                                                         .format(vm_resource_id, vm_moref_id))
+
         except Exception as exp:
         except Exception as exp:
-            self.logger.warn("Error in parsing {}\n{}".format(exp, traceback.format_exc()))
+            self.logger.warn("get_vm_resource_id: Error in parsing {}\n{}"\
+                             .format(exp, traceback.format_exc()))
+
+        return vm_resource_id
 
 
     def get_metrics_data(self, metric={}):
 
 
     def get_metrics_data(self, metric={}):
@@ -725,20 +732,20 @@ class MonPlugin():
             'metric_name': Normalized name of metric (string)
             'resource_uuid': Resource UUID (string)
             'tenant_id': tenent id name in which the resource is present in string format
             'metric_name': Normalized name of metric (string)
             'resource_uuid': Resource UUID (string)
             'tenant_id': tenent id name in which the resource is present in string format
-            'metrics_data': Dictionary containing time_series & metric_series data.
+            'metrics_data': Dictionary containing time_series & metrics_series data.
                 'time_series': List of individual time stamp values in msec
                 'time_series': List of individual time stamp values in msec
-                'metric_series': List of individual metrics data values
+                'metrics_series': List of individual metrics data values
         Raises an exception upon error or when network is not found
         """
         return_data = {}
         Raises an exception upon error or when network is not found
         """
         return_data = {}
-        return_data['schema_version'] = 1.0
+        return_data['schema_version'] = "1.0"
         return_data['schema_type'] = 'read_metric_data_response'
         return_data['metric_name'] = metric['metric_name']
         #To do - No metric_uuid in vROPs, thus returning '0'
         return_data['metric_uuid'] = '0'
         return_data['correlation_id'] = metric['correlation_id']
         return_data['resource_uuid'] = metric['resource_uuid']
         return_data['schema_type'] = 'read_metric_data_response'
         return_data['metric_name'] = metric['metric_name']
         #To do - No metric_uuid in vROPs, thus returning '0'
         return_data['metric_uuid'] = '0'
         return_data['correlation_id'] = metric['correlation_id']
         return_data['resource_uuid'] = metric['resource_uuid']
-        return_data['metrics_data'] = {'time_series':[], 'metric_series':[]}
+        return_data['metrics_data'] = {'time_series':[], 'metrics_series':[]}
         #To do - Need confirmation about uuid & id
         if 'tenant_uuid' in metric and metric['tenant_uuid'] is not None:
             return_data['tenant_uuid'] = metric['tenant_uuid']
         #To do - Need confirmation about uuid & id
         if 'tenant_uuid' in metric and metric['tenant_uuid'] is not None:
             return_data['tenant_uuid'] = metric['tenant_uuid']
@@ -762,12 +769,12 @@ class MonPlugin():
         #2.a) Find vm_moref_id from vApp uuid in vCD
         vm_moref_id = self.get_vm_moref_id(metric['resource_uuid'])
         if vm_moref_id is None:
         #2.a) Find vm_moref_id from vApp uuid in vCD
         vm_moref_id = self.get_vm_moref_id(metric['resource_uuid'])
         if vm_moref_id is None:
-            self.logger.warn("Failed to find vm morefid for vApp in vCD: {}".format(config_dict['resource_uuid']))
+            self.logger.warn("Failed to find vm morefid for vApp in vCD: {}".format(metric['resource_uuid']))
             return return_data
         #2.b) Based on vm_moref_id, find VM's corresponding resource_id in vROPs to set notification
         resource_id = self.get_vm_resource_id(vm_moref_id)
         if resource_id is None:
             return return_data
         #2.b) Based on vm_moref_id, find VM's corresponding resource_id in vROPs to set notification
         resource_id = self.get_vm_resource_id(vm_moref_id)
         if resource_id is None:
-            self.logger.warn("Failed to find resource in vROPs: {}".format(config_dict['resource_uuid']))
+            self.logger.warn("Failed to find resource in vROPs: {}".format(metric['resource_uuid']))
             return return_data
 
         #3) Calculate begin & end time for period & period unit
             return return_data
 
         #3) Calculate begin & end time for period & period unit
@@ -810,7 +817,7 @@ class MonPlugin():
                                 if stat_keys == 'timestamps':
                                     metrics_data['time_series'] = stat_list_v[0]['timestamps']
                                 if stat_keys == 'data':
                                 if stat_keys == 'timestamps':
                                     metrics_data['time_series'] = stat_list_v[0]['timestamps']
                                 if stat_keys == 'data':
-                                    metrics_data['metric_series'] = stat_list_v[0]['data']
+                                    metrics_data['metrics_series'] = stat_list_v[0]['data']
 
         return_data['metrics_data'] = metrics_data
 
 
         return_data['metrics_data'] = metrics_data
 
@@ -819,6 +826,9 @@ class MonPlugin():
     def update_alarm_configuration(self, new_alarm_config):
         """Update alarm configuration (i.e. Symptom & alarm) as per request
         """
     def update_alarm_configuration(self, new_alarm_config):
         """Update alarm configuration (i.e. Symptom & alarm) as per request
         """
+        if new_alarm_config.get('alarm_uuid') is None:
+            self.logger.warn("alarm_uuid is required to update an Alarm")
+            return None
         #1) Get Alarm details from it's uuid & find the symptom defination
         alarm_details_json, alarm_details = self.get_alarm_defination_details(new_alarm_config['alarm_uuid'])
         if alarm_details_json is None:
         #1) Get Alarm details from it's uuid & find the symptom defination
         alarm_details_json, alarm_details = self.get_alarm_defination_details(new_alarm_config['alarm_uuid'])
         if alarm_details_json is None:
@@ -879,13 +889,51 @@ class MonPlugin():
                 alarm_details['type'] = json_data['type']
                 alarm_details['sub_type'] = json_data['subType']
                 alarm_details['symptom_definition_id'] = json_data['states'][0]['base-symptom-set']['symptomDefinitionIds'][0]
                 alarm_details['type'] = json_data['type']
                 alarm_details['sub_type'] = json_data['subType']
                 alarm_details['symptom_definition_id'] = json_data['states'][0]['base-symptom-set']['symptomDefinitionIds'][0]
-        except exception as exp:
+        except Exception as exp:
             self.logger.warn("Exception while retriving alarm defination details: {}".format(exp))
             return None, None
 
         return json_data, alarm_details
 
 
             self.logger.warn("Exception while retriving alarm defination details: {}".format(exp))
             return None, None
 
         return json_data, alarm_details
 
 
+    def get_alarm_defination_by_name(self, alarm_name):
+        """Get alarm details based on alarm name
+        """
+        status = False
+        alert_match_list = []
+
+        if alarm_name is None:
+            self.logger.warn("get_alarm_defination_by_name: Alarm name not provided")
+            return alert_match_list
+
+        json_data = {}
+        api_url = '/suite-api/api/alertdefinitions'
+        headers = {'Accept': 'application/json'}
+
+        resp = requests.get(self.vrops_site + api_url,
+                            auth=(self.vrops_user, self.vrops_password),
+                            verify = False, headers = headers)
+
+        if resp.status_code is not 200:
+            self.logger.warn("get_alarm_defination_by_name: Error in response: {}\nResponse code:{}"\
+                    "\nResponse Content: {}".format(alarm_name, resp.status_code, resp.content))
+            return alert_match_list
+
+        try:
+            json_data = json.loads(resp.content)
+            if json_data['alertDefinitions'] is not None:
+                alerts_list = json_data['alertDefinitions']
+                alert_match_list = filter(lambda alert: alert['name'] == alarm_name, alerts_list)
+                status = False if not alert_match_list else True
+                #self.logger.debug("Found alert_match_list: {}for larm_name: {},\nstatus: {}".format(alert_match_list, alarm_name,status))
+
+            return alert_match_list
+
+        except Exception as exp:
+            self.logger.warn("Exception while searching alarm defination: {}".format(exp))
+            return alert_match_list
+
+
     def update_symptom_defination(self, symptom_uuid, new_alarm_config):
         """Update symptom defination based on new alarm input configuration
         """
     def update_symptom_defination(self, symptom_uuid, new_alarm_config):
         """Update symptom defination based on new alarm input configuration
         """
@@ -980,13 +1028,13 @@ class MonPlugin():
                              data=data)
 
         if resp.status_code != 200:
                              data=data)
 
         if resp.status_code != 200:
-            self.logger.warn("Failed to create Symptom definition: {}, response code {}, response content: {}"\
-                    .format(symptom_uuid, resp.status_code, resp.content))
+            self.logger.warn("Failed to update Alarm definition: {}, response code {}, response content: {}"\
+                    .format(alarm_details_json['id'], resp.status_code, resp.content))
             return None
         else:
             parsed_alarm_details = json.loads(resp.content)
             alarm_def_uuid = parsed_alarm_details['id'].split('-', 1)[1]
             return None
         else:
             parsed_alarm_details = json.loads(resp.content)
             alarm_def_uuid = parsed_alarm_details['id'].split('-', 1)[1]
-            self.logger.info("Successfully updated Alarm defination: {}".format(alarm_def_uuid))
+            self.logger.info("Successfully updated Alarm definition: {}".format(alarm_def_uuid))
             return alarm_def_uuid
 
     def delete_alarm_configuration(self, delete_alarm_req_dict):
             return alarm_def_uuid
 
     def delete_alarm_configuration(self, delete_alarm_req_dict):
@@ -995,17 +1043,17 @@ class MonPlugin():
         if delete_alarm_req_dict['alarm_uuid'] is None:
             self.logger.info("delete_alarm_configuration: Alarm UUID not provided")
             return None
         if delete_alarm_req_dict['alarm_uuid'] is None:
             self.logger.info("delete_alarm_configuration: Alarm UUID not provided")
             return None
-        #1)Get alarm & symptom defination details
+        #1)Get alarm & symptom definition details
         alarm_details_json, alarm_details = self.get_alarm_defination_details(delete_alarm_req_dict['alarm_uuid'])
         if alarm_details is None or alarm_details_json is None:
             return None
 
         alarm_details_json, alarm_details = self.get_alarm_defination_details(delete_alarm_req_dict['alarm_uuid'])
         if alarm_details is None or alarm_details_json is None:
             return None
 
-        #2) Delete alarm notfication
+        #2) Delete alarm notification
         rule_id = self.delete_notification_rule(alarm_details['alarm_name'])
         if rule_id is None:
             return None
 
         rule_id = self.delete_notification_rule(alarm_details['alarm_name'])
         if rule_id is None:
             return None
 
-        #3) Delete alarm configuraion
+        #3) Delete alarm configuration
         alarm_id = self.delete_alarm_defination(alarm_details['alarm_id'])
         if alarm_id is None:
             return None
         alarm_id = self.delete_alarm_defination(alarm_details['alarm_id'])
         if alarm_id is None:
             return None
@@ -1050,7 +1098,7 @@ class MonPlugin():
 
         if resp.status_code is not 200:
             self.logger.warn("Failed to get notification rules details for {}"\
 
         if resp.status_code is not 200:
             self.logger.warn("Failed to get notification rules details for {}"\
-                    .format(delete_alarm_req_dict['alarm_name']))
+                    .format(alarm_name))
             return None
 
         notifications = json.loads(resp.content)
             return None
 
         notifications = json.loads(resp.content)
@@ -1064,7 +1112,7 @@ class MonPlugin():
                     return notification_id
 
             self.logger.warn("Notification id to be deleted not found for {}"\
                     return notification_id
 
             self.logger.warn("Notification id to be deleted not found for {}"\
-                            .format(notification_id, alarm_name))
+                            .format(alarm_name))
             return None
 
     def delete_alarm_defination(self, alarm_id):
             return None
 
     def delete_alarm_defination(self, alarm_id):
@@ -1130,7 +1178,8 @@ class MonPlugin():
         #TO Do - Need to add filtering of alarms based on Severity & alarm name
 
         triggered_alarms_list = []
         #TO Do - Need to add filtering of alarms based on Severity & alarm name
 
         triggered_alarms_list = []
-        if list_alarm_input['resource_uuid'] is None:
+        if list_alarm_input.get('resource_uuid') is None:
+            self.logger.warn("Resource UUID is required to get triggered alarms list")
             return triggered_alarms_list
 
         #1)Find vROPs resource ID using RO resource UUID
             return triggered_alarms_list
 
         #1)Find vROPs resource ID using RO resource UUID
@@ -1170,8 +1219,8 @@ class MonPlugin():
                             verify = False, headers = headers)
 
         if resp.status_code is not 200:
                             verify = False, headers = headers)
 
         if resp.status_code is not 200:
-            self.logger.warn("Failed to get notification rules details for {}"\
-                    .format(delete_alarm_req_dict['alarm_name']))
+            self.logger.warn("Failed to get triggered alarms for {}"\
+                    .format(ro_resource_uuid))
             return None
 
         all_alerts = json.loads(resp.content)
             return None
 
         all_alerts = json.loads(resp.content)