public void ODataQuerySupportsTimeSpan() { var timeSpan = TimeSpan.FromMinutes(5); var filterString = FilterString.Generate <Parameters>(parameters => parameters.TimeGrain == timeSpan); Assert.Equal(filterString, "timeGrain eq duration'PT5M'"); }
private const double days = -10; //max = -90 (90 days of logs is stored by audit logs) static void Main(string[] args) { Console.WriteLine("Starting operations log export."); string token = GetAuthorizationHeader(); TokenCloudCredentials credentials = new TokenCloudCredentials(SubscriptionID, token); InsightsClient client = new InsightsClient(credentials); DateTime endDateTime = DateTime.Now; DateTime startDateTime = endDateTime.AddDays(days); string filterString = FilterString.Generate <ListEventsForResourceProviderParameters>(eventData => (eventData.EventTimestamp >= startDateTime) && (eventData.EventTimestamp <= endDateTime)); EventDataListResponse response = client.EventOperations.ListEvents(filterString, selectedProperties: null); List <EventData> logList = new List <EventData>(response.EventDataCollection.Value); while (!string.IsNullOrEmpty(response.EventDataCollection.NextLink)) { Console.WriteLine($"Retrieving page {response.EventDataCollection.NextLink}"); response = client.EventOperations.ListEventsNext(response.EventDataCollection.NextLink); logList.AddRange(response.EventDataCollection.Value); } ResourceManagementClient resClient = new ResourceManagementClient(credentials); Console.WriteLine($"Page retrieval completed, preparing to write to a file {CSVExportNamePath}."); ExportOpsLogToCSV(logList, resClient); Console.WriteLine("Export completed."); Console.WriteLine("Press any key to exit"); Console.ReadLine(); }
public void ListEventStatusCountSummaryItemsTest() { EventStatusCountSummaryItemCollection eventStatusCountSummaryItemCollection = GetEventStatusCountSummaryItemCollection(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(eventStatusCountSummaryItemCollection.ToJson()) }; var handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.OK }; var startTime = DateTimeOffset.Parse("2014-03-11T01:00:00.00Z"); var endTime = DateTimeOffset.Parse("2014-03-11T02:00:00.00Z"); var insightsClient = GetInsightsClient(handler); var filterString = FilterString.Generate <ListEventsParameters>( p => (p.EventTimestamp >= startTime) && (p.EventTimestamp < endTime)); var actualEventStatusCountSummaryResponse = insightsClient.EventOperations.ListEventStatusCountSummaryItemsAsync(filterString).Result; AreEqual(eventStatusCountSummaryItemCollection, actualEventStatusCountSummaryResponse.EventStatusCountSummaryItemCollection); }
public void ODataQuerySupportsEnum() { var timeSpan = TimeSpan.FromMinutes(5); var filterString = FilterString.Generate <Parameters>(parameters => parameters.EventChannels == EventChannels.Admin); Console.WriteLine(filterString); Assert.Equal(filterString, "eventChannels eq 'Admin'"); }
public void ODataQuerySupportsMethod() { var param = new InputParam1 { Value = "Microsoft.Web/sites" }; var filterString = FilterString.Generate <Param1>(parameters => parameters.AtScope() && parameters.AssignedTo(param.Value)); Assert.Equal("atScope() and assignedTo('Microsoft.Web%2Fsites')", filterString); }
static void Main(string[] args) { // Define the base URI for management operations Uri baseUri = new Uri("https://management.azure.com"); string token = GetAuthorizationHeader(); var startTime = DateTime.Now; var endTime = startTime.ToUniversalTime().AddHours(1.0).ToLocalTime(); var redisConnection = ""; ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(redisConnection); IDatabase cachedb = connection.GetDatabase(); for (int i = 0; i < 10; i++) { cachedb.StringIncrement(i.ToString()); Console.WriteLine("value=" + cachedb.StringGet(i.ToString())); } // Get the credentials // You can find instructions on how to get the token here: // http://msdn.microsoft.com/en-us/library/azure/dn790557.aspx SubscriptionCloudCredentials credentials = new TokenCloudCredentials(subscriptionId, token); // Create an instance of the InsightsClient from Microsoft.Azure.Insights InsightsClient client = new InsightsClient(credentials, baseUri); // Get the events for an Azure Resource (e.g. Website) (as described by the Azure Resource Manager APIs here:http://msdn.microsoft.com/en-us/library/azure/dn790569.aspx) // A resource URI looks like the following string: //"/subscriptions/########-####-####-####-############/resourceGroups/resourcegroupname1/providers/resourceprovider1/resourcename1" string resourceUri = string.Format("subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Cache/redis/{2}", subscriptionId, resourceGroupName, cacheName); //Define a FilterString string filterString = FilterString.Generate <ListEventsForResourceParameters>(eventData => (eventData.EventTimestamp >= startTime) && (eventData.EventTimestamp <= endTime) && (eventData.ResourceUri == resourceUri)); //Get the events logs EventDataListResponse response = client.EventOperations.ListEvents(filterString, selectedProperties: null); //Check the status code of the response Console.WriteLine("HTTP Status Code returned for the call:" + response.StatusCode); var response2 = client.MetricDefinitionOperations.GetMetricDefinitions(resourceUri, ""); var metrics = client.MetricOperations.GetMetrics(resourceUri, "startTime eq 2015-01-14T02:19:03.0712821Z and endTime eq 2015-01-14T03:19:03.0712821Z and timeGrain eq duration'PT5M'", response2.MetricDefinitionCollection.Value); Console.WriteLine("Print out the metrics logs"); foreach (var item in metrics.MetricCollection.Value) { Console.WriteLine(item.Name.Value + "--" + item.MetricValues.Count); } }
public void StartsWithWorksWihNullInODataFilter() { var param = new InputParam2 { Param = new InputParam1 { Value = null } }; var result = FilterString.Generate <Param1>(p => p.Foo.StartsWith(param.Param.Value)); Assert.Equal("", result); }
public void DefaultODataQueryTest() { var date = new DateTime(2013, 11, 5); var result = FilterString.Generate <Param1>(p => p.Foo == "foo" || p.Val <20 || p.Foo == "bar" && p.Val == null && p.Date> new DateTime(2004, 11, 5) && p.Date < date && p.Values.Contains("x")); string time1 = Uri.EscapeDataString("2004-11-05T08:00:00Z"); string time2 = Uri.EscapeDataString("2013-11-05T08:00:00Z"); string expected = string.Format("foo eq 'foo' or Val lt 20 or foo eq 'bar' and Val eq null and d gt '{0}' " + "and d lt '{1}' and vals/any(c: c eq 'x')", time1, time2); Assert.Equal(expected, result); }
/// <summary> /// Asynchronously gets a list of Azure health events. /// </summary> /// <returns></returns> public async Task <List <IHealthEvent> > GetHealthEventsAsync() { DateTime end; DateTime start; EventDataListResponse response; AzureHealthEvent healthEvent; List <AzureHealthEvent> healthEvents; string filter; try { end = DateTime.Now; start = DateTime.Now.AddDays(-7); healthEvents = new List <AzureHealthEvent>(); filter = FilterString.Generate <ListEventsForResourceProviderParameters>( eventData => (eventData.EventTimestamp >= start) && (eventData.EventTimestamp <= end) && (eventData.ResourceProvider == "Azure.Health") ); response = await Client.EventOperations.ListEventsAsync(filter, null); foreach (EventData data in response.EventDataCollection.Value) { healthEvent = new AzureHealthEvent() { Description = data.Description, EventTimestamp = data.EventTimestamp, ResourceGroupName = data.ResourceGroupName, ResourceId = data.ResourceId, ResourceProviderName = data.ResourceProviderName.Value, ResourceType = data.ResourceType.Value, Status = data.Level.ToString(), }; healthEvents.Add(healthEvent); } return(healthEvents.ToList <IHealthEvent>()); } finally { healthEvent = null; response = null; } }
/// <summary> /// Gets a list of health events for subscription. /// </summary> /// <returns>A list of health events for the given subscription.</returns> public async Task <List <IHealthEvent> > GetHealthEventsAsync() { DateTime queryEndDate; DateTime queryStartDate; IPage <EventData> events; ODataQuery <EventData> query; try { this.client.SubscriptionId = this.subscriptionId; queryEndDate = DateTime.UtcNow; queryStartDate = DateTime.UtcNow.AddMonths(-1); query = new ODataQuery <EventData>(FilterString.Generate <IncidentEvent>( eventData => (eventData.EventTimestamp >= queryStartDate) && (eventData.EventTimestamp <= queryEndDate) && (eventData.ResourceProvider == ResourceProviderName))); events = await this.client.Events.ListAsync(query); return(events.Select(x => new AzureHealthEvent { Description = x.Description, EventTimestamp = x.EventTimestamp, ResourceGroupName = x.ResourceGroupName, ResourceId = x.ResourceId, ResourceProviderName = x.ResourceProviderName.Value, ResourceType = x.ResourceType.Value, Status = x.Status.LocalizedValue }).ToList <IHealthEvent>()); } finally { events = null; query = null; } }