Skip to content

Commit

Permalink
CP-44372: Integrate NRPE UI with backend interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Bengang Yuan authored and BengangY committed Sep 21, 2023
1 parent 9470e20 commit 53fdfa0
Show file tree
Hide file tree
Showing 15 changed files with 2,151 additions and 1 deletion.
6 changes: 6 additions & 0 deletions XenAdmin/Dialogs/PropertiesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public partial class PropertiesDialog : VerticallyTabbedDialog
private ClusteringEditPage ClusteringEditPage;
private SrReadCachingEditPage SrReadCachingEditPage;
private PoolAdvancedEditPage _poolAdvancedEditPage;
private NRPEEditPage NRPEEditPage;
#endregion

private readonly IXenObject _xenObjectBefore, _xenObjectCopy;
Expand Down Expand Up @@ -317,6 +318,11 @@ private void Build()
dialog.ShowDialog(Program.MainWindow);
}
}
if (isHost || isPool)
{
NRPEEditPage = new NRPEEditPage(isHost);
ShowTab(NRPEEditPage);
}
}
finally
{
Expand Down
1 change: 1 addition & 0 deletions XenAdmin/Images.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ public static class StaticImages
public static Bitmap _000_NewStorage_h32bit_32 = Properties.Resources._000_NewStorage_h32bit_32;
public static Bitmap _000_NewVirtualAppliance_h32bit_16 = Properties.Resources._000_NewVirtualAppliance_h32bit_16;
public static Bitmap _000_NewVirtualAppliance_h32bit_32 = Properties.Resources._000_NewVirtualAppliance_h32bit_32;
public static Bitmap _000_NRPE_h32bit_16 = Properties.Resources._000_NRPE_h32bit_16;
public static Bitmap _000_Optimize_h32bit_16 = Properties.Resources._000_Optimize_h32bit_16;
public static Bitmap _000_Patch_h32bit_16 = Properties.Resources._000_Patch_h32bit_16;
public static Bitmap _000_Patch_h32bit_32 = Properties.Resources._000_Patch_h32bit_32;
Expand Down
Binary file added XenAdmin/Images/000_NRPE_h32bit_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions XenAdmin/Properties/Resources.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 XenAdmin/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1159,4 +1159,7 @@
<data name="rpm_package" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Images\rpm_package.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="_000_NRPE_h32bit_16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Images\000_NRPE_h32bit_16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
260 changes: 260 additions & 0 deletions XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
/* 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.Drawing;
using System.Windows.Forms;

namespace XenAdmin.SettingsPanels
{
public partial class NRPEEditPage
{

public class CheckGroup
{
private static readonly string DEFAULT_CHECK_WARNING_THRESHOLD = "80";
private static readonly string DEFAULT_CHECK_CRITICAL_THRESHOLD = "90";

private readonly decimal THRESHOLD_MINIMUM = 0.1M;
private readonly decimal THRESHOLD_MAXIMUM = 100M;

private string name;
private string warningThresholdDefault;
private string criticalThresholdDefault;

protected DataGridViewRow checkThresholdRow;
protected DataGridViewTextBoxCell nameCell;
protected DataGridViewTextBoxCell warningThresholdCell;
protected DataGridViewTextBoxCell criticalThresholdCell;

public string Name { get => name; set => name = value; }
public string WarningThresholdDefault { get => warningThresholdDefault; set => warningThresholdDefault = value; }
public string CriticalThresholdDefault { get => criticalThresholdDefault; set => criticalThresholdDefault = value; }
public DataGridViewRow CheckThresholdRow { get => checkThresholdRow; set => checkThresholdRow = value; }
public DataGridViewTextBoxCell NameCell { get => nameCell; set => nameCell = value; }
public DataGridViewTextBoxCell WarningThresholdCell { get => warningThresholdCell; set => warningThresholdCell = value; }
public DataGridViewTextBoxCell CriticalThresholdCell { get => criticalThresholdCell; set => criticalThresholdCell = value; }

public CheckGroup(string name, string labelName, string warningThresholdDefaultValue, string criticalThresholdDefaultValue)
{
InitCheckGroup(name, labelName, warningThresholdDefaultValue, criticalThresholdDefaultValue);
}

public CheckGroup(string name, string labelName)
{
InitCheckGroup(name, labelName, DEFAULT_CHECK_WARNING_THRESHOLD, DEFAULT_CHECK_CRITICAL_THRESHOLD);
}

private void InitCheckGroup(string name, string labelName, string warningThresholdDefaultValue, string criticalThresholdDefaultValue)
{
Name = name;
nameCell = new DataGridViewTextBoxCell { Value = labelName };
warningThresholdDefault = warningThresholdDefaultValue;
criticalThresholdDefault = criticalThresholdDefaultValue;
warningThresholdCell = new DataGridViewTextBoxCell { Value = warningThresholdDefaultValue };
criticalThresholdCell = new DataGridViewTextBoxCell { Value = criticalThresholdDefaultValue };
checkThresholdRow = new DataGridViewRow();
checkThresholdRow.Cells.AddRange(nameCell, warningThresholdCell, criticalThresholdCell);
checkThresholdRow.DefaultCellStyle.Format = "N2";
checkThresholdRow.DefaultCellStyle.NullValue = 0;
warningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark);
criticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark);
}

public void UpdateThreshold(string warningThreshold, string criticalThreshold)
{
warningThresholdCell.Value = warningThreshold;
criticalThresholdCell.Value = criticalThreshold;
warningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText);
criticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText);
}

public virtual bool CheckValue()
{
warningThresholdCell.ErrorText = "";
criticalThresholdCell.ErrorText = "";
checkThresholdRow.DataGridView.ShowCellToolTips = false;

if (IsEmptyForPool())
{
return true;
}

if (CheckEachValue(warningThresholdCell) &&
CheckEachValue(criticalThresholdCell) &&
CompareWarningAndCritical() &&
CheckModifyAllForPool())
{
return true;
}

checkThresholdRow.DataGridView.ShowCellToolTips = true;
return false;
}

private bool IsEmptyForPool()
{
return warningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark))
&& criticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark));
}

private bool CheckEachValue(DataGridViewTextBoxCell cell)
{
string thresholdStr = cell.Value.ToString().Trim();
if (thresholdStr.Equals(""))
{
cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY);
return false;
}
if (!decimal.TryParse(thresholdStr, out decimal threshold))
{
cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_BE_NUMBER);
return false;
}
if (threshold < THRESHOLD_MINIMUM || threshold > THRESHOLD_MAXIMUM)
{
cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_RANGE_ERROR, THRESHOLD_MINIMUM, THRESHOLD_MAXIMUM);
return false;
}
cell.ErrorText = "";
return true;
}

protected virtual bool CompareWarningAndCritical()
{
decimal.TryParse(warningThresholdCell.Value.ToString().Trim(), out decimal warningDecimal);
decimal.TryParse(criticalThresholdCell.Value.ToString().Trim(), out decimal criticalDecimal);
if (warningDecimal < criticalDecimal)
{
warningThresholdCell.ErrorText = "";
return true;
}
else
{
warningThresholdCell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL);
return false;
}
}

private bool CheckModifyAllForPool()
{
if (warningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText))
&& criticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark)))
{
criticalThresholdCell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY);
return false;
}
else if (warningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark))
&& criticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText)))
{
warningThresholdCell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY);
return false;
}
return true;
}
}

public class FreeCheckGroup : CheckGroup
{
private static readonly string DEFAULT_CHECK_WARNING_THRESHOLD = "20";
private static readonly string DEFAULT_CHECK_CRITICAL_THRESHOLD = "10";

public FreeCheckGroup(string name, string labelName)
: base(name, labelName, DEFAULT_CHECK_WARNING_THRESHOLD, DEFAULT_CHECK_CRITICAL_THRESHOLD)
{
}

protected override bool CompareWarningAndCritical()
{
decimal.TryParse(warningThresholdCell.Value.ToString().Trim(), out decimal warningDecimal);
decimal.TryParse(criticalThresholdCell.Value.ToString().Trim(), out decimal criticalDecimal);
if (warningDecimal > criticalDecimal)
{
warningThresholdCell.ErrorText = "";
return true;
}
else
{
warningThresholdCell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_WARNING_SHOULD_BIGGER_THAN_CRITICAL);
return false;
}
}

}

public class HostLoadCheckGroup : CheckGroup
{
private static readonly string DEFAULT_CHECK_WARNING_THRESHOLD = "3";
private static readonly string DEFAULT_CHECK_CRITICAL_THRESHOLD = "4";

public HostLoadCheckGroup(string name, string labelName)
: base(name, labelName, DEFAULT_CHECK_WARNING_THRESHOLD, DEFAULT_CHECK_CRITICAL_THRESHOLD)
{
}
}

public class Dom0LoadCheckGroup : CheckGroup
{
private static readonly string DEFAULT_CHECK_WARNING_THRESHOLD = "2.7,2.6,2.5";
private static readonly string DEFAULT_CHECK_CRITICAL_THRESHOLD = "3.2,3.1,3";

public Dom0LoadCheckGroup(string name, string labelName)
: base(name, labelName, DEFAULT_CHECK_WARNING_THRESHOLD, DEFAULT_CHECK_CRITICAL_THRESHOLD)
{
}

public override bool CheckValue()
{
return (CheckEachValue(warningThresholdCell) && CheckEachValue(criticalThresholdCell));
}

private bool CheckEachValue(DataGridViewTextBoxCell cell)
{
checkThresholdRow.DataGridView.ShowCellToolTips = true;
cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_BE_3_NUMBERS);
string[] loadArray = cell.Value.ToString().Split(',');
if (loadArray.Length != 3)
{
return false;
}
foreach (string load in loadArray)
{
bool isDecimal = decimal.TryParse(load, out _);
if (!isDecimal)
{
return false;
}
}
cell.ErrorText = "";
checkThresholdRow.DataGridView.ShowCellToolTips = false;
return true;
}
}
}
}
Loading

0 comments on commit 53fdfa0

Please sign in to comment.