mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-21 17:11:29 +01:00
Some corrections in wording, code style, C# usage, and null checks.
Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
This commit is contained in:
parent
a20ea5ab6e
commit
794e1f3fbd
@ -320,7 +320,7 @@ namespace XenAdmin.Dialogs
|
||||
}
|
||||
if (isHost || isPool)
|
||||
{
|
||||
NRPEEditPage = new NRPEEditPage(isHost);
|
||||
NRPEEditPage = new NRPEEditPage();
|
||||
ShowTab(NRPEEditPage);
|
||||
}
|
||||
}
|
||||
|
@ -45,12 +45,11 @@ namespace XenAdmin.SettingsPanels
|
||||
{
|
||||
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
|
||||
private static readonly Regex REGEX_IPV4 = new Regex("^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)");
|
||||
private static readonly Regex REGEX_IPV4_CIDR = new Regex("^([0-9]{1,3}\\.){3}[0-9]{1,3}(\\/([0-9]|[1-2][0-9]|3[0-2]))?$");
|
||||
private static readonly Regex REGEX_DOMAIN = new Regex("^(((?!-))(xn--|_)?[a-z0-9-]{0,61}[a-z0-9]{1,1}\\.)*(xn--)?([a-z0-9][a-z0-9\\-]{0,60}|[a-z0-9-]{1,30}\\.[a-z]{2,})$");
|
||||
|
||||
private readonly bool IsHost = true;
|
||||
private bool _isHost;
|
||||
|
||||
private IXenObject Clone;
|
||||
private readonly ToolTip InvalidParamToolTip;
|
||||
@ -62,11 +61,12 @@ namespace XenAdmin.SettingsPanels
|
||||
|
||||
private NRPEHostConfiguration NRPEOriginalConfig;
|
||||
private NRPEHostConfiguration NRPECurrentConfig;
|
||||
|
||||
public string SubText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsHost)
|
||||
if (_isHost)
|
||||
{
|
||||
return EnableNRPECheckBox.Checked ? Messages.NRPE_ACTIVE : Messages.NRPE_INACTIVE;
|
||||
}
|
||||
@ -79,11 +79,10 @@ namespace XenAdmin.SettingsPanels
|
||||
|
||||
public Image Image => Images.StaticImages._000_Module_h32bit_16;
|
||||
|
||||
public NRPEEditPage(bool isHost)
|
||||
public NRPEEditPage()
|
||||
{
|
||||
IsHost = isHost;
|
||||
InitializeComponent();
|
||||
Text = "NRPE";
|
||||
Text = Messages.NRPE;
|
||||
|
||||
NRPECurrentConfig = new NRPEHostConfiguration
|
||||
{
|
||||
@ -118,7 +117,7 @@ namespace XenAdmin.SettingsPanels
|
||||
CheckGroupDictByLabel.Add(checkGroup.NameCell.Value.ToString(), checkGroup);
|
||||
}
|
||||
|
||||
UpdateOtherComponentBasedEnableNRPECheckBox(false);
|
||||
UpdateOtherComponentBasedEnableNRPECheckBox();
|
||||
|
||||
AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark);
|
||||
AllowHostsTextBox.GotFocus += AllowHostsTextBox_GotFocus;
|
||||
@ -146,11 +145,7 @@ namespace XenAdmin.SettingsPanels
|
||||
return true;
|
||||
}
|
||||
|
||||
bool valid = true;
|
||||
if (!IsAllowHostsValid())
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
bool valid = IsAllowHostsValid();
|
||||
|
||||
foreach (CheckGroup checkGroup in CheckGroupList)
|
||||
{
|
||||
@ -189,7 +184,7 @@ namespace XenAdmin.SettingsPanels
|
||||
|
||||
public void HideLocalValidationMessages()
|
||||
{
|
||||
if (InvalidParamToolTip.Tag is Control ctrl && ctrl != null)
|
||||
if (InvalidParamToolTip.Tag is Control ctrl)
|
||||
{
|
||||
InvalidParamToolTip.Hide(ctrl);
|
||||
}
|
||||
@ -198,11 +193,12 @@ namespace XenAdmin.SettingsPanels
|
||||
public void SetXenObjects(IXenObject orig, IXenObject clone)
|
||||
{
|
||||
Clone = clone;
|
||||
_isHost = Clone is Host;
|
||||
|
||||
descLabelHost.Visible = IsHost;
|
||||
DescLabelPool.Visible = !IsHost;
|
||||
descLabelHost.Visible = _isHost;
|
||||
DescLabelPool.Visible = !_isHost;
|
||||
|
||||
if (IsHost)
|
||||
if (_isHost)
|
||||
{
|
||||
InitNRPEGeneralConfiguration();
|
||||
InitNRPEThreshold();
|
||||
@ -257,7 +253,7 @@ namespace XenAdmin.SettingsPanels
|
||||
}
|
||||
NRPEOriginalConfig = (NRPEHostConfiguration) NRPECurrentConfig.Clone();
|
||||
|
||||
UpdateOtherComponentBasedEnableNRPECheckBox(EnableNRPECheckBox.Checked);
|
||||
UpdateOtherComponentBasedEnableNRPECheckBox();
|
||||
}
|
||||
|
||||
private void InitNRPEThreshold()
|
||||
@ -326,24 +322,18 @@ namespace XenAdmin.SettingsPanels
|
||||
UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1);
|
||||
}
|
||||
|
||||
private void UpdateOtherComponentBasedEnableNRPECheckBox(bool check)
|
||||
private void UpdateOtherComponentBasedEnableNRPECheckBox()
|
||||
{
|
||||
if (check)
|
||||
if (EnableNRPECheckBox.Checked)
|
||||
{
|
||||
AllowHostsTextBox.Enabled = true;
|
||||
AllowHostsLabel.Enabled = true;
|
||||
DebugLogCheckBox.Enabled = true;
|
||||
SslDebugLogCheckBox.Enabled = true;
|
||||
GeneralConfigureGroupBox.Enabled = true;
|
||||
CheckDataGridView.Enabled = true;
|
||||
CheckDataGridView.BackgroundColor = Color.FromKnownColor(KnownColor.Window);
|
||||
CheckDataGridView.DefaultCellStyle.BackColor = Color.FromKnownColor(KnownColor.Window);
|
||||
}
|
||||
else
|
||||
{
|
||||
AllowHostsTextBox.Enabled = false;
|
||||
AllowHostsLabel.Enabled = false;
|
||||
DebugLogCheckBox.Enabled = false;
|
||||
SslDebugLogCheckBox.Enabled = false;
|
||||
GeneralConfigureGroupBox.Enabled = false;
|
||||
CheckDataGridView.Enabled = false;
|
||||
CheckDataGridView.BackgroundColor = Color.FromKnownColor(KnownColor.Control);
|
||||
CheckDataGridView.DefaultCellStyle.BackColor = Color.FromKnownColor(KnownColor.Control);
|
||||
@ -352,7 +342,7 @@ namespace XenAdmin.SettingsPanels
|
||||
|
||||
private void EnableNRPECheckBox_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
UpdateOtherComponentBasedEnableNRPECheckBox(EnableNRPECheckBox.Checked);
|
||||
UpdateOtherComponentBasedEnableNRPECheckBox();
|
||||
}
|
||||
|
||||
private void AllowHostsTextBox_GotFocus(object sender, EventArgs e)
|
||||
@ -375,8 +365,9 @@ namespace XenAdmin.SettingsPanels
|
||||
|
||||
private void CheckDataGridView_BeginEdit(object sender, DataGridViewCellCancelEventArgs e)
|
||||
{
|
||||
DataGridViewCell currentCell = CheckDataGridView.CurrentRow.Cells[e.ColumnIndex];
|
||||
if (!IsHost && currentCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark)))
|
||||
DataGridViewCell currentCell = CheckDataGridView.CurrentRow?.Cells[e.ColumnIndex];
|
||||
|
||||
if (currentCell != null && !_isHost && currentCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark)))
|
||||
{
|
||||
currentCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText);
|
||||
currentCell.Value = "";
|
||||
@ -385,13 +376,20 @@ namespace XenAdmin.SettingsPanels
|
||||
|
||||
private void CheckDataGridView_EndEdit(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
DataGridViewCell currentCell = CheckDataGridView.CurrentRow.Cells[e.ColumnIndex];
|
||||
if (!IsHost && currentCell.Value.ToString().Trim().Equals(""))
|
||||
DataGridViewCell currentCell = CheckDataGridView.CurrentRow?.Cells[e.ColumnIndex];
|
||||
|
||||
if (currentCell != null &&!_isHost && currentCell.Value.ToString().Trim().Equals(""))
|
||||
{
|
||||
currentCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark);
|
||||
CheckGroupDictByLabel.TryGetValue(CheckDataGridView.CurrentRow.Cells[0].Value.ToString(), out CheckGroup checkGroup);
|
||||
currentCell.Value = currentCell.ColumnIndex == 1 ?
|
||||
checkGroup.WarningThresholdDefault : (object)checkGroup.CriticalThresholdDefault;
|
||||
|
||||
if (checkGroup != null)
|
||||
{
|
||||
if (currentCell.ColumnIndex == WarningThresholdColumn.Index)
|
||||
currentCell.Value = checkGroup.WarningThresholdDefault;
|
||||
else if (currentCell.ColumnIndex == CriticalThresholdColumn.Index)
|
||||
currentCell.Value = checkGroup.CriticalThresholdDefault;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,55 +35,51 @@ namespace XenAdmin.Actions.NRPE
|
||||
{
|
||||
public class NRPEHostConfiguration : ICloneable
|
||||
{
|
||||
public static readonly string XAPI_NRPE_PLUGIN_NAME = "nrpe";
|
||||
public static readonly string XAPI_NRPE_STATUS = "status";
|
||||
public static readonly string XAPI_NRPE_GET_CONFIG = "get-config";
|
||||
public static readonly string XAPI_NRPE_GET_THRESHOLD = "get-threshold";
|
||||
public static readonly string XAPI_NRPE_ENABLE = "enable";
|
||||
public static readonly string XAPI_NRPE_DISABLE = "disable";
|
||||
public static readonly string XAPI_NRPE_SET_CONFIG = "set-config";
|
||||
public static readonly string XAPI_NRPE_SET_THRESHOLD = "set-threshold";
|
||||
public static readonly string XAPI_NRPE_RESTART = "restart";
|
||||
public const string XAPI_NRPE_PLUGIN_NAME = "nrpe";
|
||||
public const string XAPI_NRPE_STATUS = "status";
|
||||
public const string XAPI_NRPE_GET_CONFIG = "get-config";
|
||||
public const string XAPI_NRPE_GET_THRESHOLD = "get-threshold";
|
||||
public const string XAPI_NRPE_ENABLE = "enable";
|
||||
public const string XAPI_NRPE_DISABLE = "disable";
|
||||
public const string XAPI_NRPE_SET_CONFIG = "set-config";
|
||||
public const string XAPI_NRPE_SET_THRESHOLD = "set-threshold";
|
||||
public const string XAPI_NRPE_RESTART = "restart";
|
||||
|
||||
public static readonly string DEBUG_ENABLE = "1";
|
||||
public static readonly string DEBUG_DISABLE = "0";
|
||||
public const string DEBUG_ENABLE = "1";
|
||||
public const string DEBUG_DISABLE = "0";
|
||||
|
||||
public static readonly string SSL_LOGGING_ENABLE = "0xff";
|
||||
public static readonly string SSL_LOGGING_DISABLE = "0x00";
|
||||
public const string SSL_LOGGING_ENABLE = "0xff";
|
||||
public const string SSL_LOGGING_DISABLE = "0x00";
|
||||
|
||||
public static readonly string ALLOW_HOSTS_PLACE_HOLDER = Messages.NRPE_ALLOW_HOSTS_PLACE_HOLDER;
|
||||
|
||||
private bool enableNRPE;
|
||||
private string allowHosts;
|
||||
private bool debug;
|
||||
private bool sslLogging;
|
||||
private readonly Dictionary<string, Check> checkDict = new Dictionary<string, Check>();
|
||||
|
||||
public bool EnableNRPE { get => enableNRPE; set => enableNRPE = value; }
|
||||
public string AllowHosts { get => allowHosts; set => allowHosts = value; }
|
||||
public bool Debug { get => debug; set => debug = value; }
|
||||
public bool SslLogging { get => sslLogging; set => sslLogging = value; }
|
||||
public Dictionary<string, Check> CheckDict { get => checkDict; }
|
||||
public bool EnableNRPE { get; set; }
|
||||
|
||||
public string AllowHosts { get; set; }
|
||||
|
||||
public bool Debug { get; set; }
|
||||
|
||||
public bool SslLogging { get; set; }
|
||||
|
||||
public Dictionary<string, Check> CheckDict => checkDict;
|
||||
|
||||
public class Check
|
||||
{
|
||||
public string Name;
|
||||
public string WarningThreshold;
|
||||
public string CriticalThreshold;
|
||||
public string Name { get; }
|
||||
public string WarningThreshold { get; }
|
||||
public string CriticalThreshold{ get; }
|
||||
|
||||
public Check(string name, string warningThreshold, string criticalThreshold)
|
||||
{
|
||||
this.Name = name;
|
||||
this.WarningThreshold = warningThreshold;
|
||||
this.CriticalThreshold = criticalThreshold;
|
||||
Name = name;
|
||||
WarningThreshold = warningThreshold;
|
||||
CriticalThreshold = criticalThreshold;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public NRPEHostConfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
public void AddNRPECheck(Check checkItem)
|
||||
{
|
||||
checkDict.Add(checkItem.Name, checkItem);
|
||||
@ -98,10 +94,10 @@ namespace XenAdmin.Actions.NRPE
|
||||
{
|
||||
NRPEHostConfiguration cloned = new NRPEHostConfiguration
|
||||
{
|
||||
enableNRPE = enableNRPE,
|
||||
allowHosts = allowHosts,
|
||||
debug = debug,
|
||||
sslLogging = sslLogging
|
||||
EnableNRPE = EnableNRPE,
|
||||
AllowHosts = AllowHosts,
|
||||
Debug = Debug,
|
||||
SslLogging = SslLogging
|
||||
};
|
||||
return cloned;
|
||||
}
|
||||
|
21
XenModel/Messages.Designer.cs
generated
21
XenModel/Messages.Designer.cs
generated
@ -29078,6 +29078,15 @@ namespace XenAdmin {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to NRPE.
|
||||
/// </summary>
|
||||
public static string NRPE {
|
||||
get {
|
||||
return ResourceManager.GetString("NRPE", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Changing NRPE configuration....
|
||||
/// </summary>
|
||||
@ -29097,7 +29106,7 @@ namespace XenAdmin {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Allow hosts should not be empty..
|
||||
/// Looks up a localized string similar to Monitoring servers should not be empty..
|
||||
/// </summary>
|
||||
public static string NRPE_ALLOW_HOSTS_EMPTY_ERROR {
|
||||
get {
|
||||
@ -29106,7 +29115,7 @@ namespace XenAdmin {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Allow hosts format is not correct.
|
||||
/// Looks up a localized string similar to Monitoring servers format is not correct.
|
||||
/// </summary>
|
||||
public static string NRPE_ALLOW_HOSTS_ERROR_TITLE {
|
||||
get {
|
||||
@ -29115,7 +29124,7 @@ namespace XenAdmin {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Allow hosts should be comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com.
|
||||
/// Looks up a localized string similar to Monitoring servers should be comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com.
|
||||
/// </summary>
|
||||
public static string NRPE_ALLOW_HOSTS_FORMAT_ERROR {
|
||||
get {
|
||||
@ -29268,7 +29277,7 @@ namespace XenAdmin {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Threshold value should be 3 numbers separated with comma..
|
||||
/// Looks up a localized string similar to Threshold value should consist of 3 comma separated numbers..
|
||||
/// </summary>
|
||||
public static string NRPE_THRESHOLD_SHOULD_BE_3_NUMBERS {
|
||||
get {
|
||||
@ -29277,7 +29286,7 @@ namespace XenAdmin {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Threshold value should be number..
|
||||
/// Looks up a localized string similar to Threshold value should be a number..
|
||||
/// </summary>
|
||||
public static string NRPE_THRESHOLD_SHOULD_BE_NUMBER {
|
||||
get {
|
||||
@ -29295,7 +29304,7 @@ namespace XenAdmin {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Warning threshold should be bigger than critical threshold..
|
||||
/// Looks up a localized string similar to Warning threshold should be greater than critical threshold..
|
||||
/// </summary>
|
||||
public static string NRPE_THRESHOLD_WARNING_SHOULD_BIGGER_THAN_CRITICAL {
|
||||
get {
|
||||
|
@ -10092,6 +10092,9 @@ When you configure an NFS storage repository, you simply provide the host name o
|
||||
<data name="NOW" xml:space="preserve">
|
||||
<value>Now</value>
|
||||
</data>
|
||||
<data name="NRPE" xml:space="preserve">
|
||||
<value>NRPE</value>
|
||||
</data>
|
||||
<data name="NRPE_ACTION_CHANGING" xml:space="preserve">
|
||||
<value>Changing NRPE configuration...</value>
|
||||
</data>
|
||||
@ -10099,13 +10102,13 @@ When you configure an NFS storage repository, you simply provide the host name o
|
||||
<value>NRPE service is active</value>
|
||||
</data>
|
||||
<data name="NRPE_ALLOW_HOSTS_EMPTY_ERROR" xml:space="preserve">
|
||||
<value>Allow hosts should not be empty.</value>
|
||||
<value>Monitoring servers should not be empty.</value>
|
||||
</data>
|
||||
<data name="NRPE_ALLOW_HOSTS_ERROR_TITLE" xml:space="preserve">
|
||||
<value>Allow hosts format is not correct</value>
|
||||
<value>Monitoring servers format is not correct</value>
|
||||
</data>
|
||||
<data name="NRPE_ALLOW_HOSTS_FORMAT_ERROR" xml:space="preserve">
|
||||
<value>Allow hosts should be comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com</value>
|
||||
<value>Monitoring servers should be comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com</value>
|
||||
</data>
|
||||
<data name="NRPE_ALLOW_HOSTS_PLACE_HOLDER" xml:space="preserve">
|
||||
<value>Comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com</value>
|
||||
@ -10156,16 +10159,16 @@ When you configure an NFS storage repository, you simply provide the host name o
|
||||
<value>Threshold value should range from {0} to {1}.</value>
|
||||
</data>
|
||||
<data name="NRPE_THRESHOLD_SHOULD_BE_3_NUMBERS" xml:space="preserve">
|
||||
<value>Threshold value should be 3 numbers separated with comma.</value>
|
||||
<value>Threshold value should consist of 3 comma separated numbers.</value>
|
||||
</data>
|
||||
<data name="NRPE_THRESHOLD_SHOULD_BE_NUMBER" xml:space="preserve">
|
||||
<value>Threshold value should be number.</value>
|
||||
<value>Threshold value should be a number.</value>
|
||||
</data>
|
||||
<data name="NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY" xml:space="preserve">
|
||||
<value>Threshold value should not be empty.</value>
|
||||
</data>
|
||||
<data name="NRPE_THRESHOLD_WARNING_SHOULD_BIGGER_THAN_CRITICAL" xml:space="preserve">
|
||||
<value>Warning threshold should be bigger than critical threshold.</value>
|
||||
<value>Warning threshold should be greater than critical threshold.</value>
|
||||
</data>
|
||||
<data name="NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL" xml:space="preserve">
|
||||
<value>Warning threshold should be less than critical threshold.</value>
|
||||
|
Loading…
Reference in New Issue
Block a user