/// <summary> /// Determine if the virtual machine has previously been notified /// The last_notified value is used against the current time to check that it has not /// had notifications within the duration in settings /// </summary> /// <returns>bool</returns> public bool NotifiedWithinTimePeriod() { bool result = false; // Use a notification object to determine if the group already exists in the table // for this time period // NotificationDelay previousNotification = (NotificationDelay) notificationDelay.Get( // new string[] { subscriptionId, virtualMachine.ResourceGroupName, "virtualMachine", virtualMachine.Name }, // new string[] { "subscription", "group_name", "type", "name" } // ); // Create a dictionary of fields and values for the query Dictionary <string, dynamic> criteria = new Dictionary <string, dynamic>(); criteria.Add("subscription_id", subscriptionId); criteria.Add("group_name", resourceGroup.GetName()); criteria.Add("type", "virtual_machine"); criteria.Add("name", virtualMachine.Name); Response response = notificationDelay.Get(criteria); NotificationDelay previousNotification = response.GetData(); if (previousNotification != null) { int delay = Convert.ToInt32(settings.First(s => s.name == "notify_delay").value); result = Utilities.DelayExpired(previousNotification.last_notified, delay, timeNowUtc); // if (result) // { // logger.LogDebug("{0} - {1}: last notified {2} seconds ago", virtualMachine.ResourceGroupName, virtualMachine.Name, elapsed.ToString()); // } } return(result); }
/// <summary> /// Determine if the resource group has previously been notified /// The last_notified value is used against the current time to check that it has not /// had notifications within the duration in settings /// </summary> /// <returns></returns> private bool NotifiedWithinTimePeriod() { bool result = false; // Use a notification object to determine if the group already exists in the table // for this time period // NotificationDelay previousNotification = (NotificationDelay) notificationDelay.Get( // new string[] { subscriptionId, resourceGroup.Name, "resourceGroup" }, // new string[] { "subscription", "group_name", "type" } // ); // Create a dictionary of fields and values for the query Dictionary <string, dynamic> criteria = new Dictionary <string, dynamic>(); criteria.Add("subscription_id", subscriptionId); criteria.Add("group_name", resourceGroup.Name); criteria.Add("type", "resourceGroup"); NotificationDelay nd = new NotificationDelay(_backend, _logger); Response response = nd.Get(criteria); dynamic data = response.GetData(); if (data.Count == 1) { // determine how many seconds have elapsed since the last notification //int elapsed = (DateTime.UtcNow - previousNotification.last_notified).Seconds; // get the notification delay //int notifyDelay = Convert.ToInt32(settings.First(s => s.name == "notify_delay").value); //result = elapsed > notifyDelay; NotificationDelay previousNotification = (NotificationDelay)data.First(); int delay = Convert.ToInt32(settings.First(s => s.name == "notify_delay").value); result = Utilities.DelayExpired(previousNotification.last_notified, delay, timeNowUtc); // if (result) // { // _logger.Debug("Last notified {elapsed} seconds ago: {group}", elapsed.ToString(), resourceGroup.Name); // } } return(result); }