Beispiel #1
0
        private string GetActionableEventsDataFilterType(ActionableEventsFilter eventsFilter)
        {
            string filterType = "byfile";

            // Check which filter is used to determine the best PartitionKey or RowKey or field
            if (eventsFilter == null)
            {
                return("byfile");
            }

            // File path only check
            if ((eventsFilter.filepath != null && eventsFilter.filepath.Trim() != string.Empty) &&
                (eventsFilter.datefrom == null || eventsFilter.datefrom.Trim() == string.Empty) &&
                (eventsFilter.dateto == null || eventsFilter.dateto.Trim() == string.Empty) &&
                (eventsFilter.userids == null || eventsFilter.userids.Count == 0))
            {
                return("byfile");
            }

            if ((eventsFilter.datefrom != null && eventsFilter.datefrom.Trim() != string.Empty) ||
                (eventsFilter.dateto != null && eventsFilter.dateto.Trim() != string.Empty))
            {
                return("bydate");
            }

            if ((eventsFilter.datefrom != null && eventsFilter.datefrom.Trim() != string.Empty) ||
                (eventsFilter.dateto != null && eventsFilter.dateto.Trim() != string.Empty))
            {
                return("byuser");
            }

            return(filterType);
        }
Beispiel #2
0
        public IActionResult GetActionableEventsByDate([FromQuery] string filter, [FromHeader] string CPDataPaging)
        {
            int    pageCount    = 0;
            string thisPageId   = string.Empty;
            string nextPageId   = string.Empty;
            string entityAsJson = "";

            try
            {
                _logger.LogInformation("CPAPI: GetActionableEvents");

                // Get filter requests
                ActionableEventsFilter eventsFilter = new ActionableEventsFilter();
                if (filter != null && filter != string.Empty)
                {
                    _logger.LogDebug("Deserializing filter of length: " + filter.Length);
                    string filterDecoded = System.Net.WebUtility.HtmlDecode(filter);
                    filterDecoded = System.Net.WebUtility.UrlDecode(filterDecoded);
                    eventsFilter  = JsonConvert.DeserializeObject <ActionableEventsFilter>(filterDecoded);
                }

                // Validate the date entries
                if (eventsFilter.datefrom.Trim() == string.Empty && eventsFilter.dateto.Trim() == string.Empty)
                {
                    return(StatusCode((int)System.Net.HttpStatusCode.BadRequest));
                }

                // Get the filters
                List <DataFactory.Filter> filters = GetActionableEventsDataFilter(eventsFilter);

                // Get any Paging data requests
                POCO.DataPaging dataPaging = new POCO.DataPaging();
                if (CPDataPaging != null && CPDataPaging != string.Empty)
                {
                    _logger.LogDebug("Deserializing datapaging of length: " + CPDataPaging.Length);
                    string pagingDecoded = System.Net.WebUtility.HtmlDecode(CPDataPaging);
                    pagingDecoded = System.Net.WebUtility.UrlDecode(pagingDecoded);
                    dataPaging    = JsonConvert.DeserializeObject <POCO.DataPaging>(pagingDecoded);
                }

                // Load the data
                DataFactory.DataConfig         datacfg    = Utils.GetDataConfig();
                List <POCO.O365.AuditLogEntry> logEntries = new List <POCO.O365.AuditLogEntry>();

                // Check for data page request token
                if (dataPaging != null && dataPaging.thisPageId != null && dataPaging.thisPageId != string.Empty)
                {
                    thisPageId = dataPaging.thisPageId;
                }

                // Get the data
                int rowsToRequest = Utils.GetMaxRows() - logEntries.Count;
                logEntries = DataFactory.O365.AuditLog.GetActionableEvents(datacfg, "bydate", filters, thisPageId, rowsToRequest, out nextPageId);

                // Sort the data by descending date
                logEntries.Sort((x, y) => DateTime.Compare(y.CreationDateTime, x.CreationDateTime));

                // Check if a data page has been specified
                PagedData paged = new PagedData();
                paged.data         = logEntries;
                paged.totalRecords = logEntries.Count;
                paged.nextPageId   = nextPageId;

                entityAsJson = JsonConvert.SerializeObject(paged, Formatting.Indented);
            }
            catch (Exception ex)
            {
                string exceptionMsg = "Record GET exception: " + ex.Message;
                //log.Info("Exception occurred extracting text from uploaded file \r\nError: " + ex.Message);
                if (ex.InnerException != null)
                {
                    exceptionMsg = exceptionMsg + "[" + ex.InnerException.Message + "]";
                }

                _logger.LogError(exceptionMsg);
                return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError));
            }

            ObjectResult result = new ObjectResult(entityAsJson);

            return(result);
        }
Beispiel #3
0
        private List <DataFactory.Filter> GetActionableEventsDataFilter(ActionableEventsFilter eventsFilter)
        {
            List <DataFactory.Filter> filters = new List <DataFactory.Filter>();

            if (eventsFilter == null)
            {
                return(filters);
            }

            // Check which filter type
            string filterType = GetActionableEventsDataFilterType(eventsFilter);

            string fileFieldName = string.Empty;
            string dateFieldName = string.Empty;
            string userFieldName = string.Empty;

            switch (filterType)
            {
            case "byfile":
                fileFieldName = "PartitionKey";
                dateFieldName = "CreationTime";
                userFieldName = "UserId";
                break;

            case "bydate":
                fileFieldName = "RowKey";
                dateFieldName = "PartitionKey";
                userFieldName = "UserId";
                break;

            case "byuser":
                fileFieldName = "RowKey";
                dateFieldName = "CreationTime";
                userFieldName = "PartitionKey";
                break;

            default:
                break;
            }

            // Check if a file path has been provided
            if (eventsFilter.filepath != null && eventsFilter.filepath.Trim() != string.Empty)
            {
                DataFactory.Filter fileFilter = new DataFactory.Filter(fileFieldName, eventsFilter.filepath.Trim(), "ge");
                filters.Add(fileFilter);
                fileFilter = new DataFactory.Filter(fileFieldName, Utils.CleanTableKey(Utils.GetLessThanFilter(eventsFilter.filepath.Trim())), "lt");
                filters.Add(fileFilter);
            }

            // Check if both date ranges have been provided
            if ((eventsFilter.datefrom != null && eventsFilter.datefrom.Trim() != string.Empty) &&
                (eventsFilter.dateto != null && eventsFilter.dateto.Trim() != string.Empty))
            {
                // Check if the dates are the same
                if (eventsFilter.datefrom.Trim() == eventsFilter.dateto.Trim())
                {
                    // Set an equal filter for the date
                    DataFactory.Filter date = new DataFactory.Filter(dateFieldName, Utils.CleanTableKey(eventsFilter.datefrom.Trim()), "ge");
                    filters.Add(date);
                    DataFactory.Filter toDate = new DataFactory.Filter(dateFieldName, Utils.GetLessThanFilter(Utils.CleanTableKey(eventsFilter.dateto.Trim())), "lt");
                    filters.Add(toDate);
                }
                else
                {
                    // Set a range filter
                    DataFactory.Filter fromDate = new DataFactory.Filter(dateFieldName, Utils.CleanTableKey(eventsFilter.datefrom.Trim()), "ge");
                    filters.Add(fromDate);
                    DataFactory.Filter toDate = new DataFactory.Filter(dateFieldName, Utils.CleanTableKey(eventsFilter.dateto.Trim()), "le");
                    filters.Add(toDate);
                }
            }
            // Check if either date ranges have been provided
            else
            {
                // Check if From date is set
                if (eventsFilter.datefrom != null && eventsFilter.datefrom.Trim() != string.Empty)
                {
                    // Only set a ge filter
                    DataFactory.Filter fromDate = new DataFactory.Filter(dateFieldName, Utils.CleanTableKey(eventsFilter.datefrom.Trim()), "ge");
                    filters.Add(fromDate);
                }
                // Check if To date is set
                if (eventsFilter.dateto != null && eventsFilter.dateto.Trim() != string.Empty)
                {
                    // Only set a ge filter
                    DataFactory.Filter toDate = new DataFactory.Filter(dateFieldName, Utils.CleanTableKey(eventsFilter.dateto.Trim()), "le");
                    filters.Add(toDate);
                }
            }

            foreach (string userid in eventsFilter.userids)
            {
                if (userid.Trim() != string.Empty)
                {
                    DataFactory.Filter userFilter = new DataFactory.Filter(userFieldName, Utils.CleanTableKey(userid.Trim()), "eq");
                    filters.Add(userFilter);
                }
            }

            foreach (string operation in eventsFilter.operations)
            {
                if (operation.Trim() != string.Empty)
                {
                    DataFactory.Filter opFilter = new DataFactory.Filter("Operation", operation, "eq");
                    filters.Add(opFilter);
                }
            }

            foreach (string workload in eventsFilter.workloads)
            {
                if (workload.Trim() != string.Empty)
                {
                    DataFactory.Filter wlFilter = new DataFactory.Filter("Workload", workload, "eq");
                    filters.Add(wlFilter);
                }
            }

            return(filters);
        }