-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CP-44372: Integrate NRPE UI with backend interface #3226
Merged
kc284
merged 10 commits into
xenserver:feature/nrpe
from
BengangY:private/bengangy/CP-44371
Oct 24, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
177090a
CP-44372: Integrate NRPE UI with backend interface
a087a53
Some layout and wording tweaks.
kc284 596a83d
Moved NRPE related files to the same folder.
kc284 b2f8efa
Some corrections in wording, code style, C# usage, and null checks.
kc284 52da131
Rename private instance class fields name, add parameters changing ch…
BengangY 02988d1
For pool, add a CheckBox for decide if to sync the NRPE configuration…
BengangY 6c81585
All the configurations of host in a pool are the same. Fix some revie…
BengangY c06defe
Check NRPE plugin before showing properties dialog.
BengangY c5a11dc
Resolve NRPE code review comments from Tina.
BengangY f06fb0f
Resolve NRPE code review comments from Tina.
BengangY File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
/* 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 const decimal THRESHOLD_MINIMUM = 0.01M; | ||
private const decimal THRESHOLD_MAXIMUM = 100M; | ||
|
||
public string Name { get; } | ||
|
||
public DataGridViewRow CheckThresholdRow { get; } | ||
|
||
public DataGridViewTextBoxCell NameCell { get; } | ||
|
||
public DataGridViewTextBoxCell WarningThresholdCell { get; } | ||
|
||
public DataGridViewTextBoxCell CriticalThresholdCell { get; } | ||
|
||
public CheckGroup(string name, string labelName) | ||
{ | ||
Name = name; | ||
NameCell = new DataGridViewTextBoxCell { Value = labelName }; | ||
WarningThresholdCell = new DataGridViewTextBoxCell { Value = "" }; | ||
CriticalThresholdCell = new DataGridViewTextBoxCell { Value = "" }; | ||
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 = ""; | ||
|
||
return CheckEachValue(WarningThresholdCell) && | ||
CheckEachValue(CriticalThresholdCell) && | ||
CompareWarningAndCritical(); | ||
} | ||
|
||
protected virtual 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; | ||
} | ||
} | ||
} | ||
|
||
public class FreeCheckGroup : CheckGroup | ||
{ | ||
public FreeCheckGroup(string name, string labelName) | ||
: base(name, labelName) | ||
{ | ||
} | ||
|
||
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 | ||
{ | ||
public HostLoadCheckGroup(string name, string labelName) | ||
: base(name, labelName) | ||
{ | ||
} | ||
} | ||
|
||
public class Dom0LoadCheckGroup : CheckGroup | ||
{ | ||
public Dom0LoadCheckGroup(string name, string labelName) | ||
: base(name, labelName) | ||
{ | ||
} | ||
|
||
protected override bool CompareWarningAndCritical() | ||
{ | ||
string[] warningArray = WarningThresholdCell.Value.ToString().Split(','); | ||
string[] criticalArray = CriticalThresholdCell.Value.ToString().Split(','); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
decimal.TryParse(warningArray[i].Trim(), out decimal warningDecimal); | ||
decimal.TryParse(criticalArray[i].Trim(), out decimal criticalDecimal); | ||
if (warningDecimal > criticalDecimal) | ||
{ | ||
WarningThresholdCell.ErrorText = | ||
string.Format(Messages.NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL); | ||
return false; | ||
} | ||
} | ||
|
||
WarningThresholdCell.ErrorText = ""; | ||
return true; | ||
} | ||
|
||
protected override bool CheckEachValue(DataGridViewTextBoxCell cell) | ||
{ | ||
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 = ""; | ||
return true; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
isPoolOrStandalone
correct here? This means that if someone wants to set different settings for only one host in a multi-host pool, they cannot do it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's correct. Have confirmed with Enzo that NRPE page will be shown for a pool and standalone host, not shown for a host in a multi-host pool.