diff --git a/XenAdmin/Dialogs/PropertiesDialog.cs b/XenAdmin/Dialogs/PropertiesDialog.cs index a6dda37d7..b35caaf89 100755 --- a/XenAdmin/Dialogs/PropertiesDialog.cs +++ b/XenAdmin/Dialogs/PropertiesDialog.cs @@ -320,7 +320,7 @@ private void Build() } if (isHost || isPool) { - NRPEEditPage = new NRPEEditPage(isHost); + NRPEEditPage = new NRPEEditPage(); ShowTab(NRPEEditPage); } } diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.cs b/XenAdmin/SettingsPanels/NRPEEditPage.cs index d89080012..ccf22e2e3 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -45,12 +45,11 @@ public partial class NRPEEditPage : UserControl, IEditPage { 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 @@ public partial class NRPEEditPage : UserControl, IEditPage 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 @@ public string SubText 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 @@ public NRPEEditPage(bool isHost) CheckGroupDictByLabel.Add(checkGroup.NameCell.Value.ToString(), checkGroup); } - UpdateOtherComponentBasedEnableNRPECheckBox(false); + UpdateOtherComponentBasedEnableNRPECheckBox(); AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); AllowHostsTextBox.GotFocus += AllowHostsTextBox_GotFocus; @@ -146,11 +145,7 @@ public bool ValidToSave return true; } - bool valid = true; - if (!IsAllowHostsValid()) - { - valid = false; - } + bool valid = IsAllowHostsValid(); foreach (CheckGroup checkGroup in CheckGroupList) { @@ -189,7 +184,7 @@ public void ShowLocalValidationMessages() public void HideLocalValidationMessages() { - if (InvalidParamToolTip.Tag is Control ctrl && ctrl != null) + if (InvalidParamToolTip.Tag is Control ctrl) { InvalidParamToolTip.Hide(ctrl); } @@ -198,11 +193,12 @@ public void HideLocalValidationMessages() 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 @@ private void InitNRPEGeneralConfiguration() } NRPEOriginalConfig = (NRPEHostConfiguration) NRPECurrentConfig.Clone(); - UpdateOtherComponentBasedEnableNRPECheckBox(EnableNRPECheckBox.Checked); + UpdateOtherComponentBasedEnableNRPECheckBox(); } private void InitNRPEThreshold() @@ -326,24 +322,18 @@ private string AllowHostsWithoutLocalAddress(string allowHosts) 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 @@ private void UpdateOtherComponentBasedEnableNRPECheckBox(bool check) private void EnableNRPECheckBox_CheckedChanged(object sender, EventArgs e) { - UpdateOtherComponentBasedEnableNRPECheckBox(EnableNRPECheckBox.Checked); + UpdateOtherComponentBasedEnableNRPECheckBox(); } private void AllowHostsTextBox_GotFocus(object sender, EventArgs e) @@ -375,8 +365,9 @@ private void AllowHostsTextBox_LostFocus(object sender, EventArgs e) 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 @@ private void CheckDataGridView_BeginEdit(object sender, DataGridViewCellCancelEv 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; + } } } } diff --git a/XenModel/Actions/NRPE/NRPEHostConfiguration.cs b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs index c143a3cca..7f1e62098 100644 --- a/XenModel/Actions/NRPE/NRPEHostConfiguration.cs +++ b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs @@ -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 static readonly string DEBUG_ENABLE = "1"; - public static readonly string DEBUG_DISABLE = "0"; - - public static readonly string SSL_LOGGING_ENABLE = "0xff"; - public static readonly string SSL_LOGGING_DISABLE = "0x00"; + 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 const string DEBUG_ENABLE = "1"; + public const string DEBUG_DISABLE = "0"; + + 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 checkDict = new Dictionary(); - 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 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 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 @@ public object Clone() { NRPEHostConfiguration cloned = new NRPEHostConfiguration { - enableNRPE = enableNRPE, - allowHosts = allowHosts, - debug = debug, - sslLogging = sslLogging + EnableNRPE = EnableNRPE, + AllowHosts = AllowHosts, + Debug = Debug, + SslLogging = SslLogging }; return cloned; } diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index 4640a32ae..e387c153d 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -29078,6 +29078,15 @@ public static string NOW { } } + /// + /// Looks up a localized string similar to NRPE. + /// + public static string NRPE { + get { + return ResourceManager.GetString("NRPE", resourceCulture); + } + } + /// /// Looks up a localized string similar to Changing NRPE configuration.... /// @@ -29097,7 +29106,7 @@ public static string NRPE_ACTIVE { } /// - /// 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.. /// public static string NRPE_ALLOW_HOSTS_EMPTY_ERROR { get { @@ -29106,7 +29115,7 @@ public static string NRPE_ALLOW_HOSTS_EMPTY_ERROR { } /// - /// 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. /// public static string NRPE_ALLOW_HOSTS_ERROR_TITLE { get { @@ -29115,7 +29124,7 @@ public static string NRPE_ALLOW_HOSTS_ERROR_TITLE { } /// - /// 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. /// public static string NRPE_ALLOW_HOSTS_FORMAT_ERROR { get { @@ -29268,7 +29277,7 @@ public static string NRPE_THRESHOLD_RANGE_ERROR { } /// - /// 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.. /// public static string NRPE_THRESHOLD_SHOULD_BE_3_NUMBERS { get { @@ -29277,7 +29286,7 @@ public static string NRPE_THRESHOLD_SHOULD_BE_3_NUMBERS { } /// - /// 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.. /// public static string NRPE_THRESHOLD_SHOULD_BE_NUMBER { get { @@ -29295,7 +29304,7 @@ public static string NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY { } /// - /// 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.. /// public static string NRPE_THRESHOLD_WARNING_SHOULD_BIGGER_THAN_CRITICAL { get { diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index 55095208a..b4418b67c 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -10092,6 +10092,9 @@ When you configure an NFS storage repository, you simply provide the host name o Now + + NRPE + Changing NRPE configuration... @@ -10099,13 +10102,13 @@ When you configure an NFS storage repository, you simply provide the host name o NRPE service is active - Allow hosts should not be empty. + Monitoring servers should not be empty. - Allow hosts format is not correct + Monitoring servers format is not correct - Allow hosts should be comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com + Monitoring servers should be comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com Comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com @@ -10156,16 +10159,16 @@ When you configure an NFS storage repository, you simply provide the host name o Threshold value should range from {0} to {1}. - Threshold value should be 3 numbers separated with comma. + Threshold value should consist of 3 comma separated numbers. - Threshold value should be number. + Threshold value should be a number. Threshold value should not be empty. - Warning threshold should be bigger than critical threshold. + Warning threshold should be greater than critical threshold. Warning threshold should be less than critical threshold.