from pyhpecfm import system
from lib.actions import HpecfmBaseAction

class eventLookup(HpecfmBaseAction):
    def run(self):
        cfm_audits = system.get_audit_logs(self.client)
        if isinstance(cfm_audits, list):
            # Create a empty list for alarms
            event_data = []
            # Loop through cfm_audits and process EVENTS
            for event in cfm_audits:
                typex = event['record_type']
                if typex == 'EVENT':
                    # Build dictionary to add to list
                    out = {
                          'u_eventType': event['data']['event_type'],
                          'u_typex': event['record_type'],
                          'u_sev': event['severity'],
                          'u_uuid': event['uuid'],
                          'u_desc': event['description'],
                          'u_name' : event['data']['object_name'],
                          'u_typeo' : event['data']['object_type']
                          }
                    event_data.append(out)

            return (True, event_data)
        return (False, cfm_audits)
