mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 07:19:18 +01:00
Alert the user if they haven't synced in a long time. Also:
- Alert sorting was not correct. - A dismissal request was sent to the server even if there were no server side messages to dismiss. Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
This commit is contained in:
parent
2774ea5c7f
commit
a557d83397
@ -96,9 +96,12 @@ namespace XenAdmin.Actions
|
||||
if (_alerts.Count > 0)
|
||||
midPoint = 100 * msgAlerts.Count / _alerts.Count;
|
||||
|
||||
RelatedTask = Message.async_destroy_many(Session, msgRefs);
|
||||
PollToCompletion(0, midPoint);
|
||||
Alert.RemoveAlert(a => msgAlerts.Contains(a));
|
||||
if (msgAlerts.Count > 0)
|
||||
{
|
||||
RelatedTask = Message.async_destroy_many(Session, msgRefs);
|
||||
PollToCompletion(0, midPoint);
|
||||
Alert.RemoveAlert(a => msgAlerts.Contains(a));
|
||||
}
|
||||
|
||||
for (var i = 0; i < otherAlerts.Count; i++)
|
||||
{
|
||||
|
@ -39,18 +39,13 @@ namespace XenAdmin.Alerts
|
||||
if (alert1 == null || alert2 == null)
|
||||
return 0;
|
||||
|
||||
int sortResult = 0;
|
||||
|
||||
if (IsVersionOrVersionUpdateAlert(alert1) && !IsVersionOrVersionUpdateAlert(alert2))
|
||||
sortResult = 1;
|
||||
return -1;
|
||||
|
||||
if (!IsVersionOrVersionUpdateAlert(alert1) && IsVersionOrVersionUpdateAlert(alert2))
|
||||
sortResult = -1;
|
||||
return 1;
|
||||
|
||||
if (sortResult == 0)
|
||||
sortResult = Alert.CompareOnDate(alert1, alert2);
|
||||
|
||||
return -sortResult;
|
||||
return -Alert.CompareOnDate(alert1, alert2); //descending date
|
||||
}
|
||||
|
||||
private bool IsVersionOrVersionUpdateAlert(Alert alert)
|
||||
|
159
XenAdmin/Alerts/Types/OutOfSyncWithCdnAlert.cs
Normal file
159
XenAdmin/Alerts/Types/OutOfSyncWithCdnAlert.cs
Normal file
@ -0,0 +1,159 @@
|
||||
/* Copyright (c) Cloud Software Group, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms,
|
||||
* with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the
|
||||
* following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using XenAdmin.Actions;
|
||||
using XenAdmin.Core;
|
||||
using XenAdmin.Dialogs.ServerUpdates;
|
||||
using XenAdmin.Network;
|
||||
using XenAPI;
|
||||
|
||||
|
||||
namespace XenAdmin.Alerts
|
||||
{
|
||||
public class OutOfSyncWithCdnAlert : Alert
|
||||
{
|
||||
private readonly int _outOfSyncDays;
|
||||
private readonly Pool _pool;
|
||||
|
||||
private OutOfSyncWithCdnAlert(Pool pool, DateTime timestamp)
|
||||
{
|
||||
_timestamp = timestamp;
|
||||
_pool = pool;
|
||||
Connection = _pool.Connection;
|
||||
|
||||
if (_timestamp - _pool.last_update_sync >= TimeSpan.FromDays(180))
|
||||
{
|
||||
_outOfSyncDays = 180;
|
||||
Priority = AlertPriority.Priority1;
|
||||
}
|
||||
else if (_timestamp - _pool.last_update_sync >= TimeSpan.FromDays(90))
|
||||
{
|
||||
_outOfSyncDays = 180;
|
||||
Priority = AlertPriority.Priority2;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryCreate(IXenConnection connection, out Alert alert)
|
||||
{
|
||||
if (Helpers.XapiEqualOrGreater_23_18_0(connection))
|
||||
{
|
||||
var pool = Helpers.GetPoolOfOne(connection);
|
||||
var timestamp = DateTime.UtcNow;
|
||||
|
||||
if (timestamp - pool.last_update_sync >= TimeSpan.FromDays(90))
|
||||
{
|
||||
alert = new OutOfSyncWithCdnAlert(pool, timestamp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
alert = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override AlertPriority Priority { get; }
|
||||
|
||||
public override string AppliesTo => Helpers.GetName(_pool);
|
||||
|
||||
public override string Description => Title;
|
||||
|
||||
public override Action FixLinkAction
|
||||
{
|
||||
get
|
||||
{
|
||||
return () =>
|
||||
{
|
||||
var syncAction = new SyncWithCdnAction(_pool);
|
||||
syncAction.Completed += a => Updates.CheckForCdnUpdates(a.Connection);
|
||||
syncAction.RunAsync();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override string FixLinkText => Messages.UPDATES_GENERAL_TAB_SYNC_NOW;
|
||||
|
||||
public override string HelpID => "TODO";
|
||||
|
||||
public override string Title => string.Format(Messages.ALERT_CDN_OUT_OF_SYNC_TITLE, _outOfSyncDays);
|
||||
}
|
||||
|
||||
|
||||
public class YumRepoNotConfiguredAlert : Alert
|
||||
{
|
||||
private readonly Pool _pool;
|
||||
|
||||
private YumRepoNotConfiguredAlert(Pool pool, DateTime timestamp)
|
||||
{
|
||||
_timestamp = timestamp;
|
||||
_pool = pool;
|
||||
Connection = _pool.Connection;
|
||||
}
|
||||
|
||||
public static bool TryCreate(IXenConnection connection, out Alert alert)
|
||||
{
|
||||
var pool = Helpers.GetPoolOfOne(connection);
|
||||
var timestamp = DateTime.UtcNow;
|
||||
|
||||
if (pool.repositories.Count == 0)
|
||||
{
|
||||
alert = new YumRepoNotConfiguredAlert(pool, timestamp);
|
||||
return true;
|
||||
}
|
||||
|
||||
alert = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override AlertPriority Priority => AlertPriority.Priority3;
|
||||
|
||||
public override string AppliesTo => Helpers.GetName(_pool);
|
||||
|
||||
public override string Description => Messages.ALERT_CDN_REPO_NOT_CONFIGURED_DESCRIPTION;
|
||||
|
||||
public override Action FixLinkAction
|
||||
{
|
||||
get
|
||||
{
|
||||
return () =>
|
||||
{
|
||||
using (var dialog = new ConfigUpdatesDialog())
|
||||
dialog.ShowDialog(Program.MainWindow);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override string FixLinkText => Messages.ALERT_CDN_REPO_NOT_CONFIGURED_ACTION_LINK;
|
||||
|
||||
public override string HelpID => "TODO";
|
||||
|
||||
public override string Title => string.Format(Messages.ALERT_CDN_REPO_NOT_CONFIGURED_TITLE, Connection.Name);
|
||||
}
|
||||
}
|
@ -1083,6 +1083,9 @@ namespace XenAdmin
|
||||
|
||||
if (Helpers.CloudOrGreater(connection))
|
||||
{
|
||||
if (YumRepoNotConfiguredAlert.TryCreate(connection, out var alert) || OutOfSyncWithCdnAlert.TryCreate(connection, out alert))
|
||||
Alert.AddAlert(alert);
|
||||
|
||||
Updates.CheckForCdnUpdates(coordinator.Connection);
|
||||
}
|
||||
else
|
||||
|
@ -648,11 +648,11 @@ namespace XenAdmin.TabPages
|
||||
|
||||
private void DismissAlerts(params Alert[] alerts)
|
||||
{
|
||||
var groups = from Alert alert in alerts
|
||||
where alert != null && alert.AllowedToDismiss()
|
||||
group alert by alert.Connection
|
||||
into g
|
||||
select new { Connection = g.Key, Alerts = g };
|
||||
var groups = (from Alert alert in alerts
|
||||
where alert != null && alert.AllowedToDismiss()
|
||||
group alert by alert.Connection
|
||||
into g
|
||||
select new { Connection = g.Key, Alerts = g }).ToList();
|
||||
|
||||
foreach (var g in groups)
|
||||
{
|
||||
|
@ -192,7 +192,7 @@ namespace XenAdmin.Alerts
|
||||
public string uuid;
|
||||
protected int _priority;
|
||||
|
||||
public Alert()
|
||||
protected Alert()
|
||||
{
|
||||
uuid = Guid.NewGuid().ToString();
|
||||
}
|
||||
|
38
XenModel/Messages.Designer.cs
generated
38
XenModel/Messages.Designer.cs
generated
@ -4984,6 +4984,42 @@ namespace XenAdmin {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You have not synchronized with the update channel in {0} days..
|
||||
/// </summary>
|
||||
public static string ALERT_CDN_OUT_OF_SYNC_TITLE {
|
||||
get {
|
||||
return ResourceManager.GetString("ALERT_CDN_OUT_OF_SYNC_TITLE", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Configure Updates.
|
||||
/// </summary>
|
||||
public static string ALERT_CDN_REPO_NOT_CONFIGURED_ACTION_LINK {
|
||||
get {
|
||||
return ResourceManager.GetString("ALERT_CDN_REPO_NOT_CONFIGURED_ACTION_LINK", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Configuring an update channel will allow your system to synchronize and retrieve available updates..
|
||||
/// </summary>
|
||||
public static string ALERT_CDN_REPO_NOT_CONFIGURED_DESCRIPTION {
|
||||
get {
|
||||
return ResourceManager.GetString("ALERT_CDN_REPO_NOT_CONFIGURED_DESCRIPTION", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You have not configured an update channel on '{0}'.
|
||||
/// </summary>
|
||||
public static string ALERT_CDN_REPO_NOT_CONFIGURED_TITLE {
|
||||
get {
|
||||
return ResourceManager.GetString("ALERT_CDN_REPO_NOT_CONFIGURED_TITLE", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to When CPU usage exceeds {0}% for {1} min(s).
|
||||
/// </summary>
|
||||
@ -37420,7 +37456,7 @@ namespace XenAdmin {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Configure updates....
|
||||
/// Looks up a localized string similar to Configure Updates....
|
||||
/// </summary>
|
||||
public static string UPDATES_GENERAL_TAB_CONFIG {
|
||||
get {
|
||||
|
@ -1831,6 +1831,18 @@ This alarm is set to be triggered when the total throughput exceeds {4}.</value>
|
||||
<data name="ALERT_CAP_LABEL" xml:space="preserve">
|
||||
<value>(Showing first {0} entries)</value>
|
||||
</data>
|
||||
<data name="ALERT_CDN_OUT_OF_SYNC_TITLE" xml:space="preserve">
|
||||
<value>You have not synchronized with the update channel in {0} days.</value>
|
||||
</data>
|
||||
<data name="ALERT_CDN_REPO_NOT_CONFIGURED_ACTION_LINK" xml:space="preserve">
|
||||
<value>Configure Updates</value>
|
||||
</data>
|
||||
<data name="ALERT_CDN_REPO_NOT_CONFIGURED_DESCRIPTION" xml:space="preserve">
|
||||
<value>Configuring an update channel will allow your system to synchronize and retrieve available updates.</value>
|
||||
</data>
|
||||
<data name="ALERT_CDN_REPO_NOT_CONFIGURED_TITLE" xml:space="preserve">
|
||||
<value>You have not configured an update channel on '{0}'</value>
|
||||
</data>
|
||||
<data name="ALERT_CPUS_SUB_TEXT" xml:space="preserve">
|
||||
<value>When CPU usage exceeds {0}% for {1} min(s)</value>
|
||||
</data>
|
||||
@ -12928,7 +12940,7 @@ Note that if RBAC is enabled, only updates which you have privileges to dismiss
|
||||
<value>Download {0}</value>
|
||||
</data>
|
||||
<data name="UPDATES_GENERAL_TAB_CONFIG" xml:space="preserve">
|
||||
<value>Configure updates...</value>
|
||||
<value>Configure Updates...</value>
|
||||
</data>
|
||||
<data name="UPDATES_GENERAL_TAB_ENFORCE_HOMOGENEITY" xml:space="preserve">
|
||||
<value>(full application required)</value>
|
||||
|
Loading…
Reference in New Issue
Block a user