private static Tuple<string, string> GetAllResourceNameAndLocation(EventData eventEntry, string resourceGroupName, string resourceUri, ResourceManagementClient resclient)
        {
            Tuple<string, string> resultSet = new Tuple<string, string>(string.Empty, string.Empty);

            if (!string.IsNullOrWhiteSpace(resourceGroupName) && !string.IsNullOrWhiteSpace(resourceUri))
            {
                try
                {
                    ResourceListParameters reslist = new ResourceListParameters();

                    reslist.ResourceGroupName = eventEntry.ResourceGroupName;

                    ResourceListResult resresult = resclient.Resources.List(reslist);

                    foreach (GenericResourceExtended resource in resresult.Resources)
                    {
                        if (resource.Id == eventEntry.ResourceUri)
                        {
                            resultSet = new Tuple<string, string>(resource.Name, resource.Location);
                            break;
                        }
                    }
                }
                catch
                {
                    return resultSet;
                }
            }

            return resultSet;
        }
 /// <summary>
 /// Initializes a new instance of the EventData class.
 /// </summary>
 public PSEventDataNoDetails(EventData eventData)
 {
     this.Authorization = eventData.Authorization != null
         ? new PSEventDataAuthorization
         {
             Action = eventData.Authorization.Action,
             Condition = eventData.Authorization.Condition,
             Role = eventData.Authorization.Role,
             Scope = eventData.Authorization.Scope
         }
         : null;
     this.Caller = eventData.Caller;
     this.CorrelationId = eventData.CorrelationId;
     this.EventSource = eventData.EventSource.Value;
     this.EventTimestamp = eventData.EventTimestamp;
     this.OperationName = eventData.OperationName.Value;
     this.ResourceGroupName = eventData.ResourceGroupName;
     this.ResourceId = eventData.ResourceUri;
     this.Status = eventData.Status.Value;
     this.SubscriptionId = eventData.SubscriptionId;
     this.SubStatus = eventData.SubStatus.Value;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the EventData class.
 /// </summary>
 public PSEventData(EventData eventData)
 {
     this.Authorization = eventData.Authorization != null
         ? new PSEventDataAuthorization
         {
             Action = eventData.Authorization.Action,
             Condition = eventData.Authorization.Condition,
             Role = eventData.Authorization.Role,
             Scope = eventData.Authorization.Scope
         }
         : null;
     this.Caller = eventData.Caller;
     this.Claims = new PSDictionaryElement(eventData.Claims);
     this.CorrelationId = eventData.CorrelationId;
     this.Description = eventData.Description;
     this.EventChannels = eventData.Channels;
     this.EventDataId = eventData.EventDataId;
     this.EventName = eventData.EventName.Value;
     this.Category = eventData.Category.Value;
     this.EventTimestamp = eventData.EventTimestamp;
     this.HttpRequest = eventData.HttpRequest != null
         ? new PSEventDataHttpRequest
         {
             ClientId = eventData.HttpRequest.ClientRequestId,
             ClientIpAddress = eventData.HttpRequest.ClientIpAddress,
             Method = eventData.HttpRequest.Method,
             Url = eventData.HttpRequest.Uri
         }
         : null;
     this.Id = eventData.Id;
     this.Level = eventData.Level;
     this.OperationId = eventData.OperationId;
     this.OperationName = eventData.OperationName.Value;
     this.Properties = new PSDictionaryElement(eventData.Properties);
     this.ResourceGroupName = eventData.ResourceGroupName;
     this.ResourceProviderName = eventData.ResourceProviderName.Value;
     this.ResourceId = eventData.ResourceId;
     this.Status = eventData.Status.Value;
     this.SubmissionTimestamp = eventData.SubmissionTimestamp;
     this.SubscriptionId = eventData.SubscriptionId;
     this.SubStatus = eventData.SubStatus.Value;
 }
 /// <summary>
 /// A predicate to filter in/out the records from original list of records obtained from the SDK.
 /// <para>This method is intended to allow descendants of this class to further filter the results.</para>
 /// <para>An example of this is when the filtering is needed based on EventSource and ResourceUri at the same time. 
 /// The SDK does not allow these two fields to be in the query filter togheter. So the call should filter by one and then use this function to filter by the second one.</para>
 /// </summary>
 /// <param name="record">A record from the original list of records obtained from the sdk</param>
 /// <returns>true if the record should kept in the result, false if it should be filtered out</returns>
 protected override bool KeepTheRecord(EventData record)
 {
     return string.IsNullOrWhiteSpace(this.ResourceId) || string.Equals(record.ResourceId, this.ResourceId, StringComparison.OrdinalIgnoreCase);
 }
        private static Tuple<string, string, string> ParseOperationName(EventData eventEntry)
        {
            Tuple<string, string, string> resultSet = new Tuple<string, string, string>(string.Empty, string.Empty, string.Empty);

            if (eventEntry.ResourceProviderName == null)
            {
                return resultSet;
            }

            if (string.IsNullOrWhiteSpace(eventEntry.ResourceProviderName.Value))
            {
                if (eventEntry.ResourceProviderName.Value != "Azure.Health")
                {
                    if (eventEntry.OperationName.Value.Contains("/"))
                    {
                        string[] entry = eventEntry.OperationName.Value.ToLower().Replace("/action", "").Split('/');

                        string operationResProvider = entry[0].Replace("microsoft.", "");
                        string operationResType = entry[1];

                        StringBuilder operationTypeName = new StringBuilder();

                        if (entry.Length > 2)
                        {
                            for(int i = 2; i < entry.Length; i++)
                            {
                                operationTypeName.Append(entry[i]);
                                if (i < entry.Length)
                                {
                                    operationTypeName.Append("/");
                                }
                            }
                        }

                        resultSet = new Tuple<string, string, string>(operationResProvider, operationResType, operationTypeName.ToString());
                    }
                }
            }

            return resultSet;
        }
        private static Tuple<string, string, string, string, string, string> GetResourceProviderName(EventData eventEntry)
        {
            Tuple<string, string, string, string, string, string> resultSet =
                new Tuple<string, string, string, string, string, string>(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);

            if (eventEntry.ResourceProviderName == null)
            {
                return resultSet;
            }

            if (eventEntry.ResourceProviderName.Value == "Azure.Health")
            {
                string titleProp = eventEntry.Properties.ContainsKey("Title") ? eventEntry.Properties["Title"]?.Replace(',', ';').Replace(Environment.NewLine, string.Empty) : string.Empty;
                string serviceProp = eventEntry.Properties.ContainsKey("Service") ? eventEntry.Properties["Service"]?.Replace(',', ';').Replace(Environment.NewLine, string.Empty) : string.Empty;
                string regionProp = eventEntry.Properties.ContainsKey("Region") ? eventEntry.Properties["Region"]?.Replace(',', ';').Replace(Environment.NewLine, string.Empty) : string.Empty;
                string tranCommProp = eventEntry.Properties.ContainsKey("Transcript Of Communication") ? eventEntry.Properties["Transcript Of Communication"]?.Replace(',', ';').Replace(Environment.NewLine, string.Empty) : string.Empty;
                string incidentIDProp = eventEntry.Properties.ContainsKey("IncidentId") ? eventEntry.Properties["IncidentId"]?.Replace(',', ';').Replace(Environment.NewLine, string.Empty) : string.Empty;
                string incidentTypeProp = eventEntry.Properties.ContainsKey("IncidentType") ? eventEntry.Properties["IncidentType"]?.Replace(',', ';').Replace(Environment.NewLine, string.Empty) : string.Empty;

                resultSet = new Tuple<string, string, string, string, string, string>(titleProp, serviceProp, regionProp, tranCommProp, incidentIDProp, incidentTypeProp);
            }

            return resultSet;
        }
Exemplo n.º 7
0
 /// <summary>
 /// A predicate to filter in/out the records from original list of records obtained from the SDK.
 /// <para>This method is intended to allow descendants of this class to further filter the results.</para>
 /// <para>An example of this is when the filtering is needed based on EventSource and ResourceUri at the same time. 
 /// The SDK does not allow these two fields to be in the query filter togheter. So the call should filter by one and then use this function to filter by the second one.</para>
 /// </summary>
 /// <param name="record">A record from the original list of records obtained from the sdk</param>
 /// <returns>true if the record should kept in the result, false if it should be filtered out</returns>
 protected virtual bool KeepTheRecord(EventData record)
 {
     // Do not filter in this funtion, use a filter in the descendants only
     return true;
 }
        private static void AreEqual(EventData exp, EventData act)
        {
            if (exp != null)
            {
                AreEqual(exp.Authorization, act.Authorization);
                AreEqual(exp.Claims, act.Claims);
                Assert.Equal(exp.CorrelationId, act.CorrelationId);
                Assert.Equal(exp.Description, act.Description);
                Assert.Equal(exp.EventDataId, act.EventDataId);
                AreEqual(exp.EventName, act.EventName);
                AreEqual(exp.EventSource, act.EventSource);
                Assert.Equal(exp.EventTimestamp.ToUniversalTime(), act.EventTimestamp.ToUniversalTime());
                AreEqual(exp.HttpRequest, act.HttpRequest);
                Assert.Equal(exp.Level, act.Level);
                Assert.Equal(exp.OperationId, act.OperationId);
                AreEqual(exp.OperationName, act.OperationName);
                AreEqual(exp.Properties, act.Properties);
                Assert.Equal(exp.ResourceGroupName, act.ResourceGroupName);
                AreEqual(exp.ResourceProviderName, act.ResourceProviderName);
                Assert.Equal(exp.ResourceUri, act.ResourceUri);
                AreEqual(exp.Status, act.Status);
                AreEqual(exp.SubStatus, act.SubStatus);
                Assert.Equal(exp.SubmissionTimestamp.ToUniversalTime(), act.SubmissionTimestamp.ToUniversalTime());
                Assert.Equal(exp.SubscriptionId, act.SubscriptionId);

                // TODO: This cannot be verified for now. Should fix this in the next mmilestone.
                // Assert.Equal(exp.EventChannels, act.EventChannels);
            }
        }