summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2018-05-15 09:29:37 +0000
committerBin Yang <bin.yang@windriver.com>2018-05-15 09:29:37 +0000
commit1737de6ec6ed4a744493594eb01f93c6032c84aa (patch)
treeb0a06badacad4cf3fcbfa176dd352ce10881b570
parent9eda64aed5d2127f53f8edad764019ea98e85458 (diff)
Encode the collected VM data into VES event
Change-Id: Icbf7408c627fe47e60a8bf2b3b45cb20baa5b313 Issue-ID: MULTICLOUD-230 Signed-off-by: Bin Yang <bin.yang@windriver.com>
-rw-r--r--windriver/titanium_cloud/vesagent/event_domain/fault_vm.py106
1 files changed, 104 insertions, 2 deletions
diff --git a/windriver/titanium_cloud/vesagent/event_domain/fault_vm.py b/windriver/titanium_cloud/vesagent/event_domain/fault_vm.py
index 72d99b73..308ef24c 100644
--- a/windriver/titanium_cloud/vesagent/event_domain/fault_vm.py
+++ b/windriver/titanium_cloud/vesagent/event_domain/fault_vm.py
@@ -176,7 +176,109 @@ def processBacklog_fault_vm(vesAgentConfig, vesAgentState, oneBacklog):
logger.info("return")
return
+
def data2event_fault_vm(oneBacklog, last_event, vm_data):
- this_event = {}
- return this_event
+ VES_EVENT_VERSION = 3.0
+ VES_EVENT_FAULT_VERSION = 2.0
+ VES_EVENT_FAULT_DOMAIN = "fault"
+
+ try:
+
+ if vm_status_is_fault(vm_data["server"]["status"]):
+ if last_event is not None \
+ and last_event['event']['commonEventHeader']['eventName'] == 'Fault_MultiCloud_VMFailure':
+ # asserted alarm already, so no need to assert it again
+ return None
+
+ eventName = "Fault_MultiCloud_VMFailure"
+ priority = "High"
+ eventSeverity = "CRITICAL"
+ alarmCondition = "Guest_Os_Failure"
+ vfStatus = "Active"
+ specificProblem = "AlarmOn"
+ eventType = ''
+ reportingEntityId = ''
+ reportingEntityName = ''
+ sequence = 0
+
+ startEpochMicrosec = int(time.time())
+ lastEpochMicrosec = int(time.time())
+
+ eventId = str(uuid.uuid4())
+ pass
+ else:
+ if last_event is None \
+ or last_event['event']['commonEventHeader']['eventName'] != 'Fault_MultiCloud_VMFailure':
+ # not assert alarm yet, so no need to clear it
+ return None
+
+
+ eventName = "Fault_MultiCloud_VMFailureCleared"
+ priority = "Normal"
+ eventSeverity = "NORMAL"
+ alarmCondition = "Vm_Restart"
+ vfStatus = "Active"
+ specificProblem = "AlarmOff"
+ eventType = ''
+ reportingEntityId = ''
+ reportingEntityName = ''
+ sequence = 0
+
+ startEpochMicrosec = last_event['event']['commonEventHeader']['startEpochMicrosec']
+ lastEpochMicrosec = int(time.time())
+ eventId = last_event['event']['commonEventHeader']['eventId']
+
+ pass
+
+ # now populate the event structure
+ this_event = {
+ 'event': {
+ 'commonEventHeader': {
+ 'version': VES_EVENT_VERSION,
+ 'eventName': eventName,
+ 'domain': VES_EVENT_FAULT_DOMAIN,
+ 'eventId': eventId,
+ 'eventType': eventType,
+ 'sourceId': vm_data["server"]['id'],
+ 'sourceName': vm_data["server"]['name'],
+ 'reportingEntityId': reportingEntityId,
+ 'reportingEntityName': reportingEntityName,
+ 'priority': priority,
+ 'startEpochMicrosec': startEpochMicrosec,
+ 'lastEpochMicrosec': lastEpochMicrosec,
+ 'sequence': sequence
+ },
+ 'faultFields': {
+ 'faultFieldsVersion': VES_EVENT_FAULT_VERSION,
+ 'eventSeverity': eventSeverity,
+ 'eventSourceType': 'virtualMachine',
+ 'alarmCondition': alarmCondition,
+ 'specificProblem': specificProblem,
+ 'vfStatus': 'Active'
+ }
+
+ }
+
+ }
+
+ return this_event
+
+ except Exception as e:
+ logger.error("exception:%s" % str(e))
+ return None
+
+
+def vm_status_is_fault(status):
+ '''
+ report VM fault when status falls into one of following state
+ ['ERROR', 'DELETED', 'PAUSED', 'REBUILD', 'RESCUE',
+ 'RESIZE','REVERT_RESIZE', 'SHELVED', 'SHELVED_OFFLOADED',
+ 'SHUTOFF', 'SOFT_DELETED','SUSPENDED', 'UNKNOWN', 'VERIFY_RESIZE']
+ :param status:
+ :return:
+ '''
+ if status in ['BUILD', 'ACTIVE', 'HARD_REBOOT', 'REBOOT', 'MIGRATING', 'PASSWORD']:
+ return False
+ else:
+ return True