Skip to content

Commit

Permalink
CP-43264: Handle new alert for CSS agreement expiry.
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
  • Loading branch information
kc284 committed Jul 20, 2023
1 parent e5719a8 commit c470fde
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 85 deletions.
14 changes: 14 additions & 0 deletions XenAdmin/Alerts/AlertExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,19 @@ public static string GetUpdateDetailsCSVQuotes(this Alert a)
date.EscapeQuotes(),
a.WebPageLabel.EscapeQuotes());
}

public static string GetGuiDate(DateTime? dateTime)
{
string date = string.Empty;

Program.Invoke(Program.MainWindow,
() =>
{
if (dateTime.HasValue)
date = HelpersGUI.DateTimeToString(dateTime.Value.ToLocalTime(), Messages.DATEFORMAT_DMY_HM, true);
});

return date;
}
}
}
29 changes: 9 additions & 20 deletions XenAdmin/Alerts/Types/CertificateAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,32 +158,35 @@ public override string Description
{
case Message.MessageType.POOL_CA_CERTIFICATE_EXPIRED:
var pool1 = Helpers.GetPoolOfOne(Connection);
return string.Format(Messages.CERTIFICATE_CA_ALERT_EXPIRED_DESCIRPTION, objectName, pool1.Name(), GetExpiryDate());
return string.Format(Messages.CERTIFICATE_CA_ALERT_EXPIRED_DESCIRPTION, objectName, pool1.Name(),
AlertExtensions.GetGuiDate(_certificateExpiryDate));

case Message.MessageType.POOL_CA_CERTIFICATE_EXPIRING_07:
case Message.MessageType.POOL_CA_CERTIFICATE_EXPIRING_14:
case Message.MessageType.POOL_CA_CERTIFICATE_EXPIRING_30:
var pool2 = Helpers.GetPoolOfOne(Connection);
return string.Format(Messages.CERTIFICATE_CA_ALERT_EXPIRING_DESCRIPTION,
objectName, pool2.Name(), GetExpiryDate());
objectName, pool2.Name(), AlertExtensions.GetGuiDate(_certificateExpiryDate));

case Message.MessageType.HOST_INTERNAL_CERTIFICATE_EXPIRED:
return string.Format(Messages.CERTIFICATE_HOST_INTERNAL_ALERT_EXPIRED_DESCIRPTION, objectName, GetExpiryDate());
return string.Format(Messages.CERTIFICATE_HOST_INTERNAL_ALERT_EXPIRED_DESCIRPTION,
objectName, AlertExtensions.GetGuiDate(_certificateExpiryDate));

case Message.MessageType.HOST_INTERNAL_CERTIFICATE_EXPIRING_07:
case Message.MessageType.HOST_INTERNAL_CERTIFICATE_EXPIRING_14:
case Message.MessageType.HOST_INTERNAL_CERTIFICATE_EXPIRING_30:
return string.Format(Messages.CERTIFICATE_HOST_INTERNAL_ALERT_EXPIRING_DESCRIPTION,
objectName, GetExpiryDate());
objectName, AlertExtensions.GetGuiDate(_certificateExpiryDate));

case Message.MessageType.HOST_SERVER_CERTIFICATE_EXPIRED:
return string.Format(Messages.CERTIFICATE_HOST_ALERT_EXPIRED_DESCIRPTION, objectName, GetExpiryDate());
return string.Format(Messages.CERTIFICATE_HOST_ALERT_EXPIRED_DESCIRPTION, objectName,
AlertExtensions.GetGuiDate(_certificateExpiryDate));

case Message.MessageType.HOST_SERVER_CERTIFICATE_EXPIRING_07:
case Message.MessageType.HOST_SERVER_CERTIFICATE_EXPIRING_14:
case Message.MessageType.HOST_SERVER_CERTIFICATE_EXPIRING_30:
return string.Format(Messages.CERTIFICATE_HOST_ALERT_EXPIRING_DESCRIPTION,
objectName, GetExpiryDate());
objectName, AlertExtensions.GetGuiDate(_certificateExpiryDate));

default:
return base.Title;
Expand Down Expand Up @@ -237,19 +240,5 @@ public override string FixLinkText
public override string HelpID => "CertificateAlert";

public override string HelpLinkText => Messages.ALERT_GENERIC_HELP;

private string GetExpiryDate()
{
string date = string.Empty;

Program.Invoke(Program.MainWindow,
() =>
{
if (_certificateExpiryDate.HasValue)
date = HelpersGUI.DateTimeToString(_certificateExpiryDate.Value.ToLocalTime(), Messages.DATEFORMAT_DMY_HM, true);
});

return date;
}
}
}
108 changes: 108 additions & 0 deletions XenAdmin/Alerts/Types/CssExpiryAlert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* 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 System.Diagnostics;
using System.Xml;
using XenAPI;


namespace XenAdmin.Alerts
{
public class CssExpiryAlert : MessageAlert
{
private readonly DateTime? _cssExpiryDate;
private readonly string _title;
private readonly string _description;

public CssExpiryAlert(Message m)
: base(m)
{
try
{
var doc = new XmlDocument();
doc.LoadXml(m.body);
var nodes = doc.GetElementsByTagName("date");

if (nodes.Count > 0 && Util.TryParseIso8601DateTime(nodes[0].InnerText, out var result))
_cssExpiryDate = result;
}
catch
{
//ignore
}

switch (Message.Type)
{
case Message.MessageType.UPDATES_FEATURE_EXPIRED:
_title = Messages.ALERT_CSS_EXPIRED_TITLE;
_description = string.Format(Messages.ALERT_CSS_EXPIRED_DESCIRPTION, AlertExtensions.GetGuiDate(_cssExpiryDate));
break;

case Message.MessageType.UPDATES_FEATURE_EXPIRING_CRITICAL:
case Message.MessageType.UPDATES_FEATURE_EXPIRING_MAJOR:
case Message.MessageType.UPDATES_FEATURE_EXPIRING_WARNING:

if (_cssExpiryDate.HasValue && _cssExpiryDate.Value > Timestamp)
{
var eta = _cssExpiryDate.Value - Timestamp;

if (eta.TotalDays >= 1)
_title = string.Format(Messages.ALERT_CSS_EXPIRING_TITLE_DAYS, Math.Round(eta.TotalDays, MidpointRounding.AwayFromZero));

else if (eta.TotalHours >= 1)
_title = string.Format(Messages.ALERT_CSS_EXPIRING_TITLE_HOURS, Math.Round(eta.TotalHours, MidpointRounding.AwayFromZero));

else if (eta.TotalMinutes >= 1)
_title = string.Format(Messages.ALERT_CSS_EXPIRING_TITLE_MINUTES, Math.Round(eta.TotalMinutes, MidpointRounding.AwayFromZero));
}
else
{
_title = Messages.ALERT_CSS_EXPIRED_TITLE;
}

_description = string.Format(Messages.ALERT_CSS_EXPIRING_DESCRIPTION, AlertExtensions.GetGuiDate(_cssExpiryDate));
break;
}
}

public override string Title => string.IsNullOrEmpty(_title) ? base.Title : _title;

public override string Description => string.IsNullOrEmpty(_description) ? base.Title : _description;

public override Action FixLinkAction => () => Process.Start(InvisibleMessages.CSS_URL);

public override string FixLinkText => Messages.ALERT_CSS_EXPIRED_LINK_TEXT;

public override string HelpID => "CssExpiryAlert";

public override string HelpLinkText => Messages.ALERT_GENERIC_HELP;
}
}
16 changes: 1 addition & 15 deletions XenAdmin/Alerts/Types/FailedLoginAttemptAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,6 @@ private class Offender
public string Originator { get; set;}
public string Username { get; set;}
public string Useragent { get; set;}

private string GetFriendlyDate()
{
string date = string.Empty;

Program.Invoke(Program.MainWindow,
() =>
{
if (Date.HasValue)
date = HelpersGUI.DateTimeToString(Date.Value.ToLocalTime(), Messages.DATEFORMAT_DMY_HM, true);
});

return date;
}

public override string ToString()
{
Expand All @@ -197,7 +183,7 @@ public override string ToString()
if (Number > 0)
entries.Add(string.Format(Messages.ALERT_FAILED_LOGIN_ATTEMPT_OFFENDER_NUMBER, Number));

var friendlyDate = GetFriendlyDate();
var friendlyDate = AlertExtensions.GetGuiDate(Date);
if (!string.IsNullOrEmpty(friendlyDate))
entries.Add(string.Format(Messages.ALERT_FAILED_LOGIN_ATTEMPT_OFFENDER_DATE, friendlyDate));

Expand Down
61 changes: 11 additions & 50 deletions XenAdmin/Alerts/Types/HotfixEligibilityAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class HotfixEligibilityAlert: Alert
public HotfixEligibilityAlert(IXenConnection connection, XenServerVersion version)
{
Connection = connection;
this.Version = version;
Version = version;
pool = Helpers.GetPoolOfOne(connection);
_timestamp = DateTime.Now;
}
Expand All @@ -67,7 +67,7 @@ public override string Title
// all + the EOL date is known -> "Approaching EOL" alert
case hotfix_eligibility.all when Version.EolDate != DateTime.MinValue:
return string.Format(Messages.HOTFIX_ELIGIBILITY_ALERT_TITLE_APPROACHING_EOL,
productVersionText, GetEolDate());
productVersionText, AlertExtensions.GetGuiDate(Version.EolDate));

// premium + unlicensed host -> "EOL for express customers" alert
case hotfix_eligibility.premium when unlicensed:
Expand All @@ -76,7 +76,7 @@ public override string Title
// premium + licensed host and the EOL date is known -> "Approaching EOL" alert
case hotfix_eligibility.premium when Version.EolDate != DateTime.MinValue:
return string.Format(Messages.HOTFIX_ELIGIBILITY_ALERT_TITLE_APPROACHING_EOL,
productVersionText, GetEolDate());
productVersionText, AlertExtensions.GetGuiDate(Version.EolDate));

// cu -> "EOL for express customers" / "CU for licensed customers" alert
case hotfix_eligibility.cu when pool.IsFreeLicenseOrExpired():
Expand Down Expand Up @@ -113,36 +113,36 @@ public override string Description
// all + the EOL date is known -> "Approaching EOL" alert
case hotfix_eligibility.all when unlicensed && Version.EolDate != DateTime.MinValue:
return string.Format(Messages.HOTFIX_ELIGIBILITY_ALERT_DESCRIPTION_APPROACHING_EOL_FREE,
productVersionText, GetEolDate(), versionText);
productVersionText, AlertExtensions.GetGuiDate(Version.EolDate), versionText);
case hotfix_eligibility.all when Version.EolDate != DateTime.MinValue:
return string.Format(Messages.HOTFIX_ELIGIBILITY_ALERT_DESCRIPTION_APPROACHING_EOL,
productVersionText, GetEolDate(), versionText);
productVersionText, AlertExtensions.GetGuiDate(Version.EolDate), versionText);

// premium + unlicensed host -> "EOL for express customers" alert
case hotfix_eligibility.premium when unlicensed && Version.HotfixEligibilityPremiumDate != DateTime.MinValue:
return string.Format(Messages.HOTFIX_ELIGIBILITY_ALERT_DESCRIPTION_FREE,
productVersionText, GetPremiumDate());
productVersionText, AlertExtensions.GetGuiDate(Version.HotfixEligibilityPremiumDate));

// premium + licensed host and the EOL date is known -> "Approaching EOL" alert
case hotfix_eligibility.premium when !unlicensed && Version.EolDate != DateTime.MinValue:
return string.Format(Messages.HOTFIX_ELIGIBILITY_ALERT_DESCRIPTION_APPROACHING_EOL,
productVersionText, GetEolDate(), versionText);
productVersionText, AlertExtensions.GetGuiDate(Version.EolDate), versionText);

// cu -> "EOL for express customers" / "CU for licensed customers" alert
case hotfix_eligibility.cu when unlicensed && Version.HotfixEligibilityPremiumDate != DateTime.MinValue:
return string.Format(Messages.HOTFIX_ELIGIBILITY_ALERT_DESCRIPTION_FREE,
productVersionText, GetPremiumDate());
productVersionText, AlertExtensions.GetGuiDate(Version.HotfixEligibilityPremiumDate));
case hotfix_eligibility.cu when !unlicensed && Version.HotfixEligibilityNoneDate != DateTime.MinValue:
return string.Format(Messages.HOTFIX_ELIGIBILITY_ALERT_DESCRIPTION_CU, productVersionText,
GetNoneDate(), versionText);
AlertExtensions.GetGuiDate(Version.HotfixEligibilityNoneDate), versionText);

// none -> EOL alert
case hotfix_eligibility.none when unlicensed && Version.EolDate != DateTime.MinValue:
return string.Format(Messages.HOTFIX_ELIGIBILITY_ALERT_DESCRIPTION_EOL_FREE,
productVersionText, GetEolDate());
productVersionText, AlertExtensions.GetGuiDate(Version.EolDate));
case hotfix_eligibility.none when Version.EolDate != DateTime.MinValue:
return string.Format(Messages.HOTFIX_ELIGIBILITY_ALERT_DESCRIPTION_EOL,
productVersionText, GetEolDate());
productVersionText, AlertExtensions.GetGuiDate(Version.EolDate));

// everything else
default:
Expand Down Expand Up @@ -201,44 +201,5 @@ public static bool IsAlertNeeded(hotfix_eligibility hotfixEligibility, XenServer
return false;
}
}


private string GetEolDate()
{
string date = string.Empty;

Program.Invoke(Program.MainWindow, () =>
{
date = HelpersGUI.DateTimeToString(Version.EolDate.ToLocalTime(), Messages.DATEFORMAT_DMY, true);
});

return date;
}

private string GetPremiumDate()
{
string date = string.Empty;

Program.Invoke(Program.MainWindow, () =>
{
date = HelpersGUI.DateTimeToString(Version.HotfixEligibilityPremiumDate.ToLocalTime(),
Messages.DATEFORMAT_DMY, true);
});

return date;
}

private string GetNoneDate()
{
string date = string.Empty;

Program.Invoke(Program.MainWindow, () =>
{
date = HelpersGUI.DateTimeToString(Version.HotfixEligibilityNoneDate.ToLocalTime(),
Messages.DATEFORMAT_DMY, true);
});

return date;
}
}
}
6 changes: 6 additions & 0 deletions XenAdmin/Alerts/Types/MessageAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ public static Alert ParseMessage(Message msg)
case Message.MessageType.HOST_INTERNAL_CERTIFICATE_EXPIRING_30:
return new CertificateAlert(msg);

case Message.MessageType.UPDATES_FEATURE_EXPIRED:
case Message.MessageType.UPDATES_FEATURE_EXPIRING_CRITICAL:
case Message.MessageType.UPDATES_FEATURE_EXPIRING_MAJOR:
case Message.MessageType.UPDATES_FEATURE_EXPIRING_WARNING:
return new CssExpiryAlert(msg);

case Message.MessageType.FAILED_LOGIN_ATTEMPTS:
return new FailedLoginAttemptAlert(msg);
default:
Expand Down
3 changes: 3 additions & 0 deletions XenAdmin/Help/HelpManager.resx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@
<data name="CrossPoolMigrateWizard_TransferNetworkPane" xml:space="preserve">
<value>vms-relocate</value>
</data>
<data name="CssExpiryAlert" xml:space="preserve">
<value></value>
</data>
<data name="CustomFieldsDialog" xml:space="preserve">
<value>resources-customfields</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions XenAdmin/XenAdmin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<Compile Include="Actions\GUIActions\SaveDataSourceStateAction.cs" />
<Compile Include="Actions\GUIActions\SearchAction.cs" />
<Compile Include="Alerts\NewVersionPriorityAlertComparer.cs" />
<Compile Include="Alerts\Types\CssExpiryAlert.cs" />
<Compile Include="Alerts\Types\FailedLoginAttemptAlert.cs" />
<Compile Include="Alerts\Types\CertificateAlert.cs" />
<Compile Include="Alerts\Types\AlarmMessageAlert.cs" />
Expand Down
9 changes: 9 additions & 0 deletions XenModel/InvisibleMessages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions XenModel/InvisibleMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="CLIENT_ID_URL" xml:space="preserve">
<value>https://support.citrix.com/xencenterclientiddownload</value>
</data>
<data name="CSS_URL" xml:space="preserve">
<value>https://www.citrix.com/support/programs/</value>
</data>
<data name="DEPRECATION_URL" xml:space="preserve">
<value>http://docs.citrix.com/en-us/citrix-hypervisor/whats-new/removed-features.html</value>
</data>
Expand Down
Loading

0 comments on commit c470fde

Please sign in to comment.