From 177090a64f47fae0b10f4a2c84781a545e8f4d9e Mon Sep 17 00:00:00 2001 From: Bengang Yuan Date: Thu, 14 Sep 2023 14:49:46 +0800 Subject: [PATCH 01/10] CP-44372: Integrate NRPE UI with backend interface --- XenAdmin/Dialogs/PropertiesDialog.cs | 6 + .../SettingsPanels/NRPEEditPage.CheckGroup.cs | 273 ++++++++ .../SettingsPanels/NRPEEditPage.Designer.cs | 229 +++++++ XenAdmin/SettingsPanels/NRPEEditPage.cs | 397 +++++++++++ XenAdmin/SettingsPanels/NRPEEditPage.resx | 615 ++++++++++++++++++ XenAdmin/XenAdmin.csproj | 14 + XenModel/Actions/Host/NRPEUpdateAction.cs | 191 ++++++ XenModel/Messages.Designer.cs | 234 +++++++ XenModel/Messages.resx | 78 +++ XenModel/NRPE/NRPEHostConfiguration.cs | 109 ++++ XenModel/XenModel.csproj | 2 + 11 files changed, 2148 insertions(+) create mode 100644 XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs create mode 100644 XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs create mode 100644 XenAdmin/SettingsPanels/NRPEEditPage.cs create mode 100644 XenAdmin/SettingsPanels/NRPEEditPage.resx create mode 100644 XenModel/Actions/Host/NRPEUpdateAction.cs create mode 100644 XenModel/NRPE/NRPEHostConfiguration.cs diff --git a/XenAdmin/Dialogs/PropertiesDialog.cs b/XenAdmin/Dialogs/PropertiesDialog.cs index 94f72f9f4..a6dda37d7 100755 --- a/XenAdmin/Dialogs/PropertiesDialog.cs +++ b/XenAdmin/Dialogs/PropertiesDialog.cs @@ -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; @@ -317,6 +318,11 @@ private void Build() dialog.ShowDialog(Program.MainWindow); } } + if (isHost || isPool) + { + NRPEEditPage = new NRPEEditPage(isHost); + ShowTab(NRPEEditPage); + } } finally { diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs b/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs new file mode 100644 index 000000000..3a779a3bd --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs @@ -0,0 +1,273 @@ +/* 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)); + } + + 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; + } + } + + 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) + { + } + + 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) + { + 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; + } + } + } +} diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs new file mode 100644 index 000000000..d5bcfdf00 --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs @@ -0,0 +1,229 @@ +using System.Windows.Forms; +using DataGridView = System.Windows.Forms.DataGridView; + +namespace XenAdmin.SettingsPanels +{ + partial class NRPEEditPage + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NRPEEditPage)); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + this.NRPETableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.PoolTipsTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.PoolTipsPicture = new System.Windows.Forms.PictureBox(); + this.PoolTipsLabel = new System.Windows.Forms.Label(); + this.DescLabel = new System.Windows.Forms.Label(); + this.GeneralConfigureGroupBox = new System.Windows.Forms.GroupBox(); + this.GeneralConfigTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.EnableNRPECheckBox = new System.Windows.Forms.CheckBox(); + this.AllowHostsLabel = new System.Windows.Forms.Label(); + this.AllowHostsTextBox = new System.Windows.Forms.TextBox(); + this.DebugLogCheckBox = new System.Windows.Forms.CheckBox(); + this.SslDebugLogCheckBox = new System.Windows.Forms.CheckBox(); + this.CheckDataGridView = new System.Windows.Forms.DataGridView(); + this.CheckColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.WarningThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.CriticalThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.NRPETableLayoutPanel.SuspendLayout(); + this.PoolTipsTableLayoutPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.PoolTipsPicture)).BeginInit(); + this.GeneralConfigureGroupBox.SuspendLayout(); + this.GeneralConfigTableLayoutPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).BeginInit(); + this.SuspendLayout(); + // + // NRPETableLayoutPanel + // + resources.ApplyResources(this.NRPETableLayoutPanel, "NRPETableLayoutPanel"); + this.NRPETableLayoutPanel.Controls.Add(this.PoolTipsTableLayoutPanel, 0, 4); + this.NRPETableLayoutPanel.Controls.Add(this.DescLabel, 0, 0); + this.NRPETableLayoutPanel.Controls.Add(this.GeneralConfigureGroupBox, 0, 1); + this.NRPETableLayoutPanel.Controls.Add(this.CheckDataGridView, 0, 2); + this.NRPETableLayoutPanel.Name = "NRPETableLayoutPanel"; + // + // PoolTipsTableLayoutPanel + // + resources.ApplyResources(this.PoolTipsTableLayoutPanel, "PoolTipsTableLayoutPanel"); + this.PoolTipsTableLayoutPanel.Controls.Add(this.PoolTipsPicture, 0, 0); + this.PoolTipsTableLayoutPanel.Controls.Add(this.PoolTipsLabel, 1, 0); + this.PoolTipsTableLayoutPanel.Name = "PoolTipsTableLayoutPanel"; + // + // PoolTipsPicture + // + resources.ApplyResources(this.PoolTipsPicture, "PoolTipsPicture"); + this.PoolTipsPicture.Image = global::XenAdmin.Properties.Resources._000_Info3_h32bit_16; + this.PoolTipsPicture.Name = "PoolTipsPicture"; + this.PoolTipsPicture.TabStop = false; + // + // PoolTipsLabel + // + resources.ApplyResources(this.PoolTipsLabel, "PoolTipsLabel"); + this.PoolTipsLabel.Name = "PoolTipsLabel"; + // + // DescLabel + // + resources.ApplyResources(this.DescLabel, "DescLabel"); + this.DescLabel.Name = "DescLabel"; + // + // GeneralConfigureGroupBox + // + resources.ApplyResources(this.GeneralConfigureGroupBox, "GeneralConfigureGroupBox"); + this.GeneralConfigureGroupBox.Controls.Add(this.GeneralConfigTableLayoutPanel); + this.GeneralConfigureGroupBox.Name = "GeneralConfigureGroupBox"; + this.GeneralConfigureGroupBox.TabStop = false; + // + // GeneralConfigTableLayoutPanel + // + resources.ApplyResources(this.GeneralConfigTableLayoutPanel, "GeneralConfigTableLayoutPanel"); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.EnableNRPECheckBox, 0, 1); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.AllowHostsLabel, 0, 2); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.AllowHostsTextBox, 1, 2); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.DebugLogCheckBox, 0, 3); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.SslDebugLogCheckBox, 0, 4); + this.GeneralConfigTableLayoutPanel.Name = "GeneralConfigTableLayoutPanel"; + // + // EnableNRPECheckBox + // + resources.ApplyResources(this.EnableNRPECheckBox, "EnableNRPECheckBox"); + this.GeneralConfigTableLayoutPanel.SetColumnSpan(this.EnableNRPECheckBox, 2); + this.EnableNRPECheckBox.Name = "EnableNRPECheckBox"; + this.EnableNRPECheckBox.UseVisualStyleBackColor = true; + this.EnableNRPECheckBox.CheckedChanged += new System.EventHandler(this.EnableNRPECheckBox_CheckedChanged); + // + // AllowHostsLabel + // + resources.ApplyResources(this.AllowHostsLabel, "AllowHostsLabel"); + this.AllowHostsLabel.Name = "AllowHostsLabel"; + // + // AllowHostsTextBox + // + resources.ApplyResources(this.AllowHostsTextBox, "AllowHostsTextBox"); + this.AllowHostsTextBox.Name = "AllowHostsTextBox"; + // + // DebugLogCheckBox + // + resources.ApplyResources(this.DebugLogCheckBox, "DebugLogCheckBox"); + this.GeneralConfigTableLayoutPanel.SetColumnSpan(this.DebugLogCheckBox, 2); + this.DebugLogCheckBox.Name = "DebugLogCheckBox"; + this.DebugLogCheckBox.UseVisualStyleBackColor = true; + // + // SslDebugLogCheckBox + // + resources.ApplyResources(this.SslDebugLogCheckBox, "SslDebugLogCheckBox"); + this.GeneralConfigTableLayoutPanel.SetColumnSpan(this.SslDebugLogCheckBox, 2); + this.SslDebugLogCheckBox.Name = "SslDebugLogCheckBox"; + this.SslDebugLogCheckBox.UseVisualStyleBackColor = true; + // + // CheckDataGridView + // + this.CheckDataGridView.AllowUserToAddRows = false; + this.CheckDataGridView.AllowUserToDeleteRows = false; + this.CheckDataGridView.AllowUserToResizeRows = false; + resources.ApplyResources(this.CheckDataGridView, "CheckDataGridView"); + this.CheckDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.CheckDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; + this.CheckDataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.CheckDataGridView.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.CheckDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.CheckColumn, + this.WarningThresholdColumn, + this.CriticalThresholdColumn}); + this.CheckDataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; + this.CheckDataGridView.EnableHeadersVisualStyles = false; + this.CheckDataGridView.MultiSelect = false; + this.CheckDataGridView.Name = "CheckDataGridView"; + this.CheckDataGridView.RowHeadersVisible = false; + this.CheckDataGridView.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.CheckDataGridView_BeginEdit); + this.CheckDataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.CheckDataGridView_EndEdit); + // + // CheckColumn + // + this.CheckColumn.FillWeight = 103.4483F; + resources.ApplyResources(this.CheckColumn, "CheckColumn"); + this.CheckColumn.Name = "CheckColumn"; + this.CheckColumn.ReadOnly = true; + // + // WarningThresholdColumn + // + dataGridViewCellStyle1.Format = "N2"; + dataGridViewCellStyle1.NullValue = null; + this.WarningThresholdColumn.DefaultCellStyle = dataGridViewCellStyle1; + this.WarningThresholdColumn.FillWeight = 98.27586F; + resources.ApplyResources(this.WarningThresholdColumn, "WarningThresholdColumn"); + this.WarningThresholdColumn.Name = "WarningThresholdColumn"; + // + // CriticalThresholdColumn + // + this.CriticalThresholdColumn.FillWeight = 98.27586F; + resources.ApplyResources(this.CriticalThresholdColumn, "CriticalThresholdColumn"); + this.CriticalThresholdColumn.Name = "CriticalThresholdColumn"; + // + // NRPEEditPage + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.Controls.Add(this.NRPETableLayoutPanel); + this.Name = "NRPEEditPage"; + this.NRPETableLayoutPanel.ResumeLayout(false); + this.NRPETableLayoutPanel.PerformLayout(); + this.PoolTipsTableLayoutPanel.ResumeLayout(false); + this.PoolTipsTableLayoutPanel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.PoolTipsPicture)).EndInit(); + this.GeneralConfigureGroupBox.ResumeLayout(false); + this.GeneralConfigTableLayoutPanel.ResumeLayout(false); + this.GeneralConfigTableLayoutPanel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private TableLayoutPanel NRPETableLayoutPanel; + + private Label DescLabel; + + private GroupBox GeneralConfigureGroupBox; + private TableLayoutPanel GeneralConfigTableLayoutPanel; + + private CheckBox EnableNRPECheckBox; + private Label AllowHostsLabel; + private TextBox AllowHostsTextBox; + private CheckBox DebugLogCheckBox; + private CheckBox SslDebugLogCheckBox; + + private DataGridView CheckDataGridView; + private DataGridViewTextBoxColumn CheckColumn; + private DataGridViewTextBoxColumn WarningThresholdColumn; + private DataGridViewTextBoxColumn CriticalThresholdColumn; + + private TableLayoutPanel PoolTipsTableLayoutPanel; + private PictureBox PoolTipsPicture; + private Label PoolTipsLabel; + } +} \ No newline at end of file diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.cs b/XenAdmin/SettingsPanels/NRPEEditPage.cs new file mode 100644 index 000000000..b33406a67 --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -0,0 +1,397 @@ +/* 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.Drawing; +using System.Windows.Forms; +using XenAPI; +using XenAdmin.Actions; +using System.Collections.Generic; +using XenAdmin.Core; +using System.Text.RegularExpressions; + +namespace XenAdmin.SettingsPanels +{ + 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 IXenObject Clone; + private readonly ToolTip InvalidParamToolTip; + private string InvalidParamToolTipText = ""; + + private readonly List CheckGroupList = new List(); + private readonly Dictionary CheckGroupDictByName = new Dictionary(); + private readonly Dictionary CheckGroupDictByLabel = new Dictionary(); + + private NRPEHostConfiguration NRPEOriginalConfig; + private NRPEHostConfiguration NRPECurrentConfig; + public string SubText + { + get + { + if (IsHost) + { + return EnableNRPECheckBox.Checked ? Messages.NRPE_ACTIVE : Messages.NRPE_INACTIVE; + } + else + { + return Messages.NRPE_BATCH_CONFIGURATION; + } + } + } + + public Image Image => Images.StaticImages._000_EnablePowerControl_h32bit_16; + + public NRPEEditPage(bool isHost) + { + IsHost = isHost; + InitializeComponent(); + Text = "NRPE"; + + NRPECurrentConfig = new NRPEHostConfiguration + { + EnableNRPE = false, + AllowHosts = NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER, + Debug = false, + SslLogging = false + }; + NRPEOriginalConfig = (NRPEHostConfiguration) NRPECurrentConfig.Clone(); + + EnableNRPECheckBox.DataBindings.Add("Checked", NRPECurrentConfig, "enableNRPE"); + AllowHostsTextBox.DataBindings.Add("Text", NRPECurrentConfig, "allowHosts"); + DebugLogCheckBox.DataBindings.Add("Checked", NRPECurrentConfig, "debug"); + SslDebugLogCheckBox.DataBindings.Add("Checked", NRPECurrentConfig, "sslLogging"); + + CheckGroupList.Add(new HostLoadCheckGroup("check_host_load", Messages.NRPE_CHECK_HOST_LOAD)); + CheckGroupList.Add(new CheckGroup("check_host_cpu", Messages.NRPE_CHECK_HOST_CPU)); + CheckGroupList.Add(new CheckGroup("check_host_memory", Messages.NRPE_CHECK_HOST_MEMORY)); + CheckGroupList.Add(new CheckGroup("check_vgpu", Messages.NRPE_CHECK_VGPU)); + CheckGroupList.Add(new CheckGroup("check_vgpu_memory", Messages.NRPE_CHECK_VGPU_MEMORY)); + CheckGroupList.Add(new Dom0LoadCheckGroup("check_load", Messages.NRPE_CHECK_LOAD)); + CheckGroupList.Add(new CheckGroup("check_cpu", Messages.NRPE_CHECK_CPU)); + CheckGroupList.Add(new CheckGroup("check_memory", Messages.NRPE_CHECK_MEMORY)); + CheckGroupList.Add(new FreeCheckGroup("check_swap", Messages.NRPE_CHECK_SWAP)); + CheckGroupList.Add(new FreeCheckGroup("check_disk_root", Messages.NRPE_CHECK_DISK_ROOT)); + CheckGroupList.Add(new FreeCheckGroup("check_disk_log", Messages.NRPE_CHECK_DISK_LOG)); + + foreach (CheckGroup checkGroup in CheckGroupList) + { + CheckDataGridView.Rows.Add(checkGroup.CheckThresholdRow); + CheckGroupDictByName.Add(checkGroup.Name, checkGroup); + CheckGroupDictByLabel.Add(checkGroup.NameCell.Value.ToString(), checkGroup); + } + + UpdateOtherComponentBasedEnableNRPECheckBox(false); + + AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + AllowHostsTextBox.GotFocus += AllowHostsTextBox_GotFocus; + AllowHostsTextBox.LostFocus += AllowHostsTextBox_LostFocus; + + if (isHost) + { + PoolTipsPicture.Hide(); + PoolTipsLabel.Hide(); + } + InvalidParamToolTip = new ToolTip + { + IsBalloon = true, + ToolTipIcon = ToolTipIcon.Warning, + ToolTipTitle = Messages.INVALID_PARAMETER, + Tag = AllowHostsTextBox + }; + } + + public bool ValidToSave + { + get + { + InvalidParamToolTipText = ""; + InvalidParamToolTip.ToolTipTitle = ""; + CheckDataGridView.ShowCellToolTips = false; + + if (!EnableNRPECheckBox.Checked) + { + return true; + } + + bool valid = true; + if (!IsAllowHostsValid()) + { + valid = false; + } + + foreach (CheckGroup checkGroup in CheckGroupList) + { + if (!checkGroup.CheckValue()) + { + valid = false; + } + } + return valid; + } + } + + public bool HasChanged + { + get + { + return true; + } + } + + public void Cleanup() + { + } + + public void ShowLocalValidationMessages() + { + if (InvalidParamToolTip.Tag is Control ctrl) + { + InvalidParamToolTip.Hide(ctrl); + if (!InvalidParamToolTipText.Equals("")) + { + HelpersGUI.ShowBalloonMessage(ctrl, InvalidParamToolTip, InvalidParamToolTipText); + } + } + } + + public void HideLocalValidationMessages() + { + if (InvalidParamToolTip.Tag is Control ctrl && ctrl != null) + { + InvalidParamToolTip.Hide(ctrl); + } + } + + public void SetXenObjects(IXenObject orig, IXenObject clone) + { + Clone = clone; + if (IsHost) + { + InitNRPEGeneralConfiguration(); + InitNRPEThreshold(); + } + } + + public AsyncAction SaveSettings() + { + foreach (KeyValuePair item in CheckGroupDictByName) + { + if (item.Value.WarningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText)) + && item.Value.CriticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText))) + { + NRPECurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(item.Key, + item.Value.WarningThresholdCell.Value.ToString(), item.Value.CriticalThresholdCell.Value.ToString())); + } + } + return new NRPEUpdateAction(Clone, NRPECurrentConfig, NRPEOriginalConfig, false); + } + + private void InitNRPEGeneralConfiguration() + { + string status = Host.call_plugin(Clone.Connection.Session, Clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_STATUS, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_STATUS, status); + NRPECurrentConfig.EnableNRPE = status.Trim().Equals("active enabled"); + + string nrpeConfig = Host.call_plugin(Clone.Connection.Session, Clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, nrpeConfig); + + string[] nrpeConfigArray = nrpeConfig.Split('\n'); + foreach (string nrpeConfigItem in nrpeConfigArray) + { + if (nrpeConfigItem.Trim().StartsWith("allowed_hosts:")) + { + string allowHosts = nrpeConfigItem.Replace("allowed_hosts:", "").Trim(); + NRPECurrentConfig.AllowHosts = AllowHostsWithoutLocalAddress(allowHosts); + AllowHostsTextBox.ForeColor = AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ? + Color.FromKnownColor(KnownColor.ControlDark) : Color.FromKnownColor(KnownColor.ControlText); + } + else if (nrpeConfigItem.Trim().StartsWith("debug:")) + { + string enableDebug = nrpeConfigItem.Replace("debug:", "").Trim(); + NRPECurrentConfig.Debug = enableDebug.Equals(NRPEHostConfiguration.DEBUG_ENABLE); + } + else if (nrpeConfigItem.Trim().StartsWith("ssl_logging:")) + { + string enableSslLogging = nrpeConfigItem.Replace("ssl_logging:", "").Trim(); + NRPECurrentConfig.SslLogging = enableSslLogging.Equals(NRPEHostConfiguration.SSL_LOGGING_ENABLE); + } + } + NRPEOriginalConfig = (NRPEHostConfiguration) NRPECurrentConfig.Clone(); + + UpdateOtherComponentBasedEnableNRPECheckBox(EnableNRPECheckBox.Checked); + } + + private void InitNRPEThreshold() + { + string nrpeThreshold = Host.call_plugin(Clone.Connection.Session, Clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, nrpeThreshold); + + string[] nrpeThresholdArray = nrpeThreshold.Split('\n'); + foreach (string nrpeThresholdItem in nrpeThresholdArray) + { + // Return string format for each line: check_cpu warning threshold - 50 critical threshold - 80 + string[] thresholdRtnArray = nrpeThresholdItem.Split(' '); + string checkName = thresholdRtnArray[0]; + if (CheckGroupDictByName.TryGetValue(thresholdRtnArray[0], out CheckGroup thresholdCheck)) + { + string warningThreshold = thresholdRtnArray[4]; + string criticalThreshold = thresholdRtnArray[8]; + thresholdCheck.UpdateThreshold(warningThreshold, criticalThreshold); + NRPEOriginalConfig.AddNRPECheck(new NRPEHostConfiguration.Check(checkName, warningThreshold, criticalThreshold)); + } + } + } + + private bool IsAllowHostsValid() + { + InvalidParamToolTip.ToolTipTitle = Messages.NRPE_ALLOW_HOSTS_ERROR_TITLE; + InvalidParamToolTip.Tag = AllowHostsTextBox; + CheckDataGridView.ShowCellToolTips = true; + + string str = AllowHostsTextBox.Text; + if (str.Trim().Length == 0 || str.Trim().Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER)) + { + InvalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_EMPTY_ERROR; + return false; + } + + string[] hostArray = str.Split(','); + foreach (string host in hostArray) + { + if (!REGEX_IPV4.Match(host.Trim()).Success && + !REGEX_IPV4_CIDR.Match(host.Trim()).Success && + !REGEX_DOMAIN.Match(host.Trim()).Success) + { + InvalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR; + return false; + } + } + CheckDataGridView.ShowCellToolTips = false; + return true; + } + + private string AllowHostsWithoutLocalAddress(string allowHosts) + { + string UpdatedAllowHosts = ""; + string[] AllowHostArray = allowHosts.Split(','); + foreach (string allowHost in AllowHostArray) + { + if (!allowHost.Trim().Equals("127.0.0.1") && + !allowHost.Trim().Equals("::1")) + { + UpdatedAllowHosts += allowHost + ","; + } + } + return UpdatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER : + UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1); + } + + private void UpdateOtherComponentBasedEnableNRPECheckBox(bool check) + { + if (check) + { + AllowHostsTextBox.Enabled = true; + AllowHostsLabel.Enabled = true; + DebugLogCheckBox.Enabled = true; + SslDebugLogCheckBox.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; + CheckDataGridView.Enabled = false; + CheckDataGridView.BackgroundColor = Color.FromKnownColor(KnownColor.Control); + CheckDataGridView.DefaultCellStyle.BackColor = Color.FromKnownColor(KnownColor.Control); + } + } + + private void EnableNRPECheckBox_CheckedChanged(object sender, EventArgs e) + { + UpdateOtherComponentBasedEnableNRPECheckBox(EnableNRPECheckBox.Checked); + } + + private void AllowHostsTextBox_GotFocus(object sender, EventArgs e) + { + if (AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER)) + { + AllowHostsTextBox.Text = ""; + AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + } + } + + private void AllowHostsTextBox_LostFocus(object sender, EventArgs e) + { + if (string.IsNullOrWhiteSpace(AllowHostsTextBox.Text)) + { + AllowHostsTextBox.Text = NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER; + AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + } + } + + 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))) + { + currentCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + currentCell.Value = ""; + } + } + + private void CheckDataGridView_EndEdit(object sender, DataGridViewCellEventArgs e) + { + DataGridViewCell currentCell = CheckDataGridView.CurrentRow.Cells[e.ColumnIndex]; + if (!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; + } + } + } +} diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.resx b/XenAdmin/SettingsPanels/NRPEEditPage.resx new file mode 100644 index 000000000..1359a1cf6 --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.resx @@ -0,0 +1,615 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Top, Left, Right + + + + True + + + 1 + + + Top, Left, Right + + + True + + + 2 + + + Left + + + + + + NoControl + + + + + + + 0, 7 + + + 0, 0, 0, 0 + + + 18, 17 + + + 17 + + + PoolTipsPicture + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + PoolTipsTableLayoutPanel + + + 0 + + + Top, Bottom, Left, Right + + + True + + + NoControl + + + 23, 3 + + + 3, 3, 3, 3 + + + 600, 0 + + + 600, 26 + + + 16 + + + For the pool properties, there will not be showing the real configuration values in every host. When clicking OK, NRPE configuration and check threshold will be sent to all the hosts in this pool. + + + MiddleLeft + + + PoolTipsLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + PoolTipsTableLayoutPanel + + + 1 + + + 3, 407 + + + 1 + + + 641, 32 + + + 5 + + + PoolTipsTableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="PoolTipsPicture" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="PoolTipsLabel" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="Absolute,20,AutoSize,0" /><Rows Styles="Percent,100" /></TableLayoutSettings> + + + Top, Bottom, Left, Right + + + True + + + NoControl + + + 3, 0 + + + 641, 26 + + + 5 + + + NRPE (Nagios Remote Plugin Excutor) allow you to execute Nagios plugins on a remote host. You can modify NRPE general configuration and NRPE Check threshold in this page. + + + DescLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 1 + + + Top, Bottom, Left, Right + + + Top, Bottom, Left, Right + + + 2 + + + Top, Left, Right + + + True + + + NoControl + + + 3, 3 + + + 636, 17 + + + 0 + + + Enable NRPE + + + EnableNRPECheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 0 + + + NoControl + + + 3, 23 + + + 100, 24 + + + 1 + + + Allow Hosts: + + + MiddleLeft + + + AllowHostsLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 1 + + + Left, Right + + + 120, 25 + + + 3, 0, 20, 0 + + + 502, 20 + + + 2 + + + AllowHostsTextBox + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 2 + + + Top, Left, Right + + + True + + + NoControl + + + 3, 50 + + + 636, 17 + + + 3 + + + Record debugging message to syslog + + + DebugLogCheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 3 + + + Top, Left, Right + + + True + + + NoControl + + + 3, 73 + + + 636, 17 + + + 4 + + + Record SSL message to syslog + + + SslDebugLogCheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 4 + + + 10, 12 + + + 3, 3, 3, 0 + + + 6 + + + 642, 93 + + + 13 + + + GeneralConfigTableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigureGroupBox + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="EnableNRPECheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="AllowHostsLabel" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="AllowHostsTextBox" Row="2" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="DebugLogCheckBox" Row="3" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="SslDebugLogCheckBox" Row="4" RowSpan="1" Column="0" ColumnSpan="2" /></Controls><Columns Styles="Percent,18.36735,Percent,81.63265" /><Rows Styles="Absolute,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0" /></TableLayoutSettings> + + + 3, 29 + + + 3, 0, 3, 0 + + + 641, 118 + + + 7 + + + General Configuration + + + GeneralConfigureGroupBox + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 2 + + + Top, Left, Right + + + Check + + + 220 + + + True + + + Warning Threshold + + + 140 + + + True + + + Critical Threshold + + + 140 + + + 3, 153 + + + 641, 248 + + + 15 + + + CheckDataGridView + + + System.Windows.Forms.DataGridView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 3 + + + 0, 0 + + + 3, 10, 3, 3 + + + 5 + + + 647, 442 + + + 4 + + + NRPETableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="PoolTipsTableLayoutPanel" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="DescLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="GeneralConfigureGroupBox" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="CheckDataGridView" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0" /></TableLayoutSettings> + + + True + + + 96, 96 + + + True + + + 650, 621 + + + CheckColumn + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + WarningThresholdColumn + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + CriticalThresholdColumn + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPEEditPage + + + System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/XenAdmin/XenAdmin.csproj b/XenAdmin/XenAdmin.csproj index 6f449aa5c..d0338e5fc 100755 --- a/XenAdmin/XenAdmin.csproj +++ b/XenAdmin/XenAdmin.csproj @@ -477,6 +477,16 @@ NetworkOptionsEditPage.cs + + UserControl + + + NRPEEditPage.cs + + + NRPEEditPage.cs + UserControl + UserControl @@ -2104,6 +2114,10 @@ Designer HostPowerONEditPage.cs + + NRPEEditPage.cs + Designer + Designer PerfmonAlertOptionsPage.cs diff --git a/XenModel/Actions/Host/NRPEUpdateAction.cs b/XenModel/Actions/Host/NRPEUpdateAction.cs new file mode 100644 index 000000000..38eefe94b --- /dev/null +++ b/XenModel/Actions/Host/NRPEUpdateAction.cs @@ -0,0 +1,191 @@ +/* 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.Collections.Generic; +using System.Linq; +using XenAPI; + + +namespace XenAdmin.Actions +{ + public class NRPEUpdateAction : AsyncAction + { + private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + private readonly NRPEHostConfiguration NRPEOriginalConfig; // NRPE configuration fetched from host + private readonly NRPEHostConfiguration NRPEHostConfiguration; // NRPE configuration after user modified + + private readonly IXenObject Clone; + + public NRPEUpdateAction(IXenObject host, NRPEHostConfiguration nrpeHostConfiguration, NRPEHostConfiguration nrpeOriginalConfig, bool suppressHistory) + : base(host.Connection, Messages.ACTION_CHANGE_POWER_ON, Messages.NRPE_ACTION_CHANGING, suppressHistory) + { + Clone = host; + NRPEHostConfiguration = nrpeHostConfiguration; + NRPEOriginalConfig = nrpeOriginalConfig; + } + + protected override void Run() + { + if (Clone is Host) + { + SetNRPEConfigureForHost(); + } + else + { + SetNRPEConfigureForPool(); + } + } + + private void SetNRPEConfigureForHost() + { + // Enable/Disable NRPE + if (!NRPEHostConfiguration.EnableNRPE == NRPEOriginalConfig.EnableNRPE) + { + SetNRPEStatus(Clone, NRPEHostConfiguration.EnableNRPE); + } + if (!NRPEHostConfiguration.EnableNRPE) // If disable, return + { + return; + } + + // NRPE General Configuration + if (!NRPEHostConfiguration.AllowHosts.Equals(NRPEOriginalConfig.AllowHosts) + || !NRPEHostConfiguration.Debug.Equals(NRPEOriginalConfig.Debug) + || !NRPEHostConfiguration.SslLogging.Equals(NRPEOriginalConfig.SslLogging)) + { + SetNRPEGeneralConfiguration(Clone, NRPEHostConfiguration.AllowHosts, NRPEHostConfiguration.Debug, NRPEHostConfiguration.SslLogging); + } + + // NRPE Check Threshold + foreach (KeyValuePair kvp in NRPEHostConfiguration.CheckDict) + { + NRPEHostConfiguration.Check CurrentCheck = kvp.Value; + NRPEOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); + if (CurrentCheck != null && OriginalCheck != null + && (!CurrentCheck.WarningThreshold.Equals(OriginalCheck.WarningThreshold) + || !CurrentCheck.CriticalThreshold.Equals(OriginalCheck.CriticalThreshold))) + { + SetNRPEThreshold(Clone, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold); + } + } + + RestartNRPE(Clone); + } + + private void SetNRPEConfigureForPool() + { + List hostList = null; + if (Clone is Pool p) + { + hostList = p.Connection.Cache.Hosts.ToList(); + } + + hostList.ForEach(host => + { + // Enable/Disable NRPE + SetNRPEStatus(host, NRPEHostConfiguration.EnableNRPE); + if (!NRPEHostConfiguration.EnableNRPE) // If disable, return + { + return; + } + + // NRPE General Configuration + SetNRPEGeneralConfiguration(host, NRPEHostConfiguration.AllowHosts, NRPEHostConfiguration.Debug, NRPEHostConfiguration.SslLogging); + + // NRPE Check Threshold + foreach (KeyValuePair kvp in NRPEHostConfiguration.CheckDict) + { + NRPEHostConfiguration.Check CurrentCheck = kvp.Value; + NRPEOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); + if (CurrentCheck != null) + { + SetNRPEThreshold(host, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold); + } + } + + RestartNRPE(host); + }); + } + + private void SetNRPEStatus(IXenObject host, bool enableNRPE) + { + string nrpeUpdateStatusMethod = enableNRPE ? + NRPEHostConfiguration.XAPI_NRPE_ENABLE : NRPEHostConfiguration.XAPI_NRPE_DISABLE; + string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + nrpeUpdateStatusMethod, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", nrpeUpdateStatusMethod, result); + } + + private void SetNRPEGeneralConfiguration(IXenObject host, string allowHosts, bool debug, bool sslLogging) + { + Dictionary ConfigArgDict = new Dictionary + { + { "allowed_hosts", "127.0.0.1,::1," + (allowHosts.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ? "" : allowHosts) }, + { "debug", debug ? NRPEHostConfiguration.DEBUG_ENABLE : NRPEHostConfiguration.DEBUG_DISABLE }, + { "ssl_logging", sslLogging ? NRPEHostConfiguration.SSL_LOGGING_ENABLE : NRPEHostConfiguration.SSL_LOGGING_DISABLE} + }; + string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_SET_CONFIG, ConfigArgDict); + log.InfoFormat("Execute nrpe {0}, allowed_hosts={1}, debug={2}, ssl_logging={3}, return: {4}", + NRPEHostConfiguration.XAPI_NRPE_SET_CONFIG, + NRPEHostConfiguration.AllowHosts, + NRPEHostConfiguration.Debug, + NRPEHostConfiguration.SslLogging, + result); + } + + private void SetNRPEThreshold(IXenObject host, string checkName, string warningThreshold, string criticalThreshold) + { + Dictionary ThresholdArgDict = new Dictionary + { + { checkName, null }, + { "w", warningThreshold }, + { "c", criticalThreshold } + }; + string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_SET_THRESHOLD, ThresholdArgDict); + log.InfoFormat("Execute nrpe {0}, check={1}, w={2}, c={3}, return: {4}", + NRPEHostConfiguration.XAPI_NRPE_SET_THRESHOLD, + checkName, + warningThreshold, + criticalThreshold, + result); + } + + // After modified NRPE configuration, we need to restart NRPE to take effect + private void RestartNRPE(IXenObject host) + { + string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_RESTART, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_RESTART, result); + } + } +} diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index 2d47ae38c..4640a32ae 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -29078,6 +29078,240 @@ public static string NOW { } } + /// + /// Looks up a localized string similar to Changing NRPE configuration.... + /// + public static string NRPE_ACTION_CHANGING { + get { + return ResourceManager.GetString("NRPE_ACTION_CHANGING", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to NRPE service is active. + /// + public static string NRPE_ACTIVE { + get { + return ResourceManager.GetString("NRPE_ACTIVE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Allow hosts should not be empty.. + /// + public static string NRPE_ALLOW_HOSTS_EMPTY_ERROR { + get { + return ResourceManager.GetString("NRPE_ALLOW_HOSTS_EMPTY_ERROR", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Allow hosts format is not correct. + /// + public static string NRPE_ALLOW_HOSTS_ERROR_TITLE { + get { + return ResourceManager.GetString("NRPE_ALLOW_HOSTS_ERROR_TITLE", resourceCulture); + } + } + + /// + /// 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. + /// + public static string NRPE_ALLOW_HOSTS_FORMAT_ERROR { + get { + return ResourceManager.GetString("NRPE_ALLOW_HOSTS_FORMAT_ERROR", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com. + /// + public static string NRPE_ALLOW_HOSTS_PLACE_HOLDER { + get { + return ResourceManager.GetString("NRPE_ALLOW_HOSTS_PLACE_HOLDER", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to NRPE batch configuration. + /// + public static string NRPE_BATCH_CONFIGURATION { + get { + return ResourceManager.GetString("NRPE_BATCH_CONFIGURATION", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 CPU Usage (%). + /// + public static string NRPE_CHECK_CPU { + get { + return ResourceManager.GetString("NRPE_CHECK_CPU", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 Log Partition Free Space (%). + /// + public static string NRPE_CHECK_DISK_LOG { + get { + return ResourceManager.GetString("NRPE_CHECK_DISK_LOG", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 Root Partition Free Space (%). + /// + public static string NRPE_CHECK_DISK_ROOT { + get { + return ResourceManager.GetString("NRPE_CHECK_DISK_ROOT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host CPU Usage (%). + /// + public static string NRPE_CHECK_HOST_CPU { + get { + return ResourceManager.GetString("NRPE_CHECK_HOST_CPU", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host CPU Load. + /// + public static string NRPE_CHECK_HOST_LOAD { + get { + return ResourceManager.GetString("NRPE_CHECK_HOST_LOAD", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host Memory Usage (%). + /// + public static string NRPE_CHECK_HOST_MEMORY { + get { + return ResourceManager.GetString("NRPE_CHECK_HOST_MEMORY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 CPU Load. + /// + public static string NRPE_CHECK_LOAD { + get { + return ResourceManager.GetString("NRPE_CHECK_LOAD", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 Memory Usage (%). + /// + public static string NRPE_CHECK_MEMORY { + get { + return ResourceManager.GetString("NRPE_CHECK_MEMORY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 Free Swap (%). + /// + public static string NRPE_CHECK_SWAP { + get { + return ResourceManager.GetString("NRPE_CHECK_SWAP", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host vGPU Memory Usage (%). + /// + public static string NRPE_CHECK_VGPU { + get { + return ResourceManager.GetString("NRPE_CHECK_VGPU", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host vGPU Usage (%). + /// + public static string NRPE_CHECK_VGPU_MEMORY { + get { + return ResourceManager.GetString("NRPE_CHECK_VGPU_MEMORY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to NRPE Configuration. + /// + public static string NRPE_EDIT_PAGE_TEXT { + get { + return ResourceManager.GetString("NRPE_EDIT_PAGE_TEXT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to NRPE service is inactive. + /// + public static string NRPE_INACTIVE { + get { + return ResourceManager.GetString("NRPE_INACTIVE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Threshold value should range from {0} to {1}.. + /// + public static string NRPE_THRESHOLD_RANGE_ERROR { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_RANGE_ERROR", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Threshold value should be 3 numbers separated with comma.. + /// + public static string NRPE_THRESHOLD_SHOULD_BE_3_NUMBERS { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_SHOULD_BE_3_NUMBERS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Threshold value should be number.. + /// + public static string NRPE_THRESHOLD_SHOULD_BE_NUMBER { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_SHOULD_BE_NUMBER", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Threshold value should not be empty.. + /// + public static string NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Warning threshold should be bigger than critical threshold.. + /// + public static string NRPE_THRESHOLD_WARNING_SHOULD_BIGGER_THAN_CRITICAL { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_WARNING_SHOULD_BIGGER_THAN_CRITICAL", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Warning threshold should be less than critical threshold.. + /// + public static string NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL", resourceCulture); + } + } + /// /// Looks up a localized string similar to Number of snapshots to keep. /// diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index 2e4f0691d..55095208a 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -10092,6 +10092,84 @@ When you configure an NFS storage repository, you simply provide the host name o Now + + Changing NRPE configuration... + + + NRPE service is active + + + Allow hosts should not be empty. + + + Allow hosts format is not correct + + + Allow hosts 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 + + + NRPE batch configuration + + + Dom0 CPU Usage (%) + + + Dom0 Log Partition Free Space (%) + + + Dom0 Root Partition Free Space (%) + + + Host CPU Usage (%) + + + Host CPU Load + + + Host Memory Usage (%) + + + Dom0 CPU Load + + + Dom0 Memory Usage (%) + + + Dom0 Free Swap (%) + + + Host vGPU Memory Usage (%) + + + Host vGPU Usage (%) + + + NRPE Configuration + + + NRPE service is inactive + + + Threshold value should range from {0} to {1}. + + + Threshold value should be 3 numbers separated with comma. + + + Threshold value should be number. + + + Threshold value should not be empty. + + + Warning threshold should be bigger than critical threshold. + + + Warning threshold should be less than critical threshold. + Number of snapshots to keep diff --git a/XenModel/NRPE/NRPEHostConfiguration.cs b/XenModel/NRPE/NRPEHostConfiguration.cs new file mode 100644 index 000000000..597556aac --- /dev/null +++ b/XenModel/NRPE/NRPEHostConfiguration.cs @@ -0,0 +1,109 @@ +/* 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.Collections.Generic; + +namespace XenAdmin +{ + 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 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 class Check + { + public string Name; + public string WarningThreshold; + public string CriticalThreshold; + + public Check(string name, string warningThreshold, string criticalThreshold) + { + this.Name = name; + this.WarningThreshold = warningThreshold; + this.CriticalThreshold = criticalThreshold; + } + + } + + public NRPEHostConfiguration() + { + } + + public void AddNRPECheck(Check checkItem) + { + checkDict.Add(checkItem.Name, checkItem); + } + + public bool GetNRPECheck(string name, out Check check) + { + return checkDict.TryGetValue(name, out check); + } + + public object Clone() + { + NRPEHostConfiguration cloned = new NRPEHostConfiguration + { + enableNRPE = enableNRPE, + allowHosts = allowHosts, + debug = debug, + sslLogging = sslLogging + }; + return cloned; + } + } +} diff --git a/XenModel/XenModel.csproj b/XenModel/XenModel.csproj index 13349a2b8..949403fbd 100755 --- a/XenModel/XenModel.csproj +++ b/XenModel/XenModel.csproj @@ -88,6 +88,7 @@ + @@ -198,6 +199,7 @@ + From a087a53b4c5efe520363cb9c6b54c8c634d550da Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Wed, 27 Sep 2023 13:01:46 +0100 Subject: [PATCH 02/10] Some layout and wording tweaks. Signed-off-by: Konstantina Chremmou --- .../SettingsPanels/NRPEEditPage.Designer.cs | 136 +++---- XenAdmin/SettingsPanels/NRPEEditPage.cs | 11 +- XenAdmin/SettingsPanels/NRPEEditPage.resx | 345 +++++++----------- XenAdmin/XenAdmin.csproj | 1 - 4 files changed, 192 insertions(+), 301 deletions(-) diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs index d5bcfdf00..5a157e6e7 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs @@ -1,6 +1,3 @@ -using System.Windows.Forms; -using DataGridView = System.Windows.Forms.DataGridView; - namespace XenAdmin.SettingsPanels { partial class NRPEEditPage @@ -32,26 +29,21 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NRPEEditPage)); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); this.NRPETableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); - this.PoolTipsTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); - this.PoolTipsPicture = new System.Windows.Forms.PictureBox(); - this.PoolTipsLabel = new System.Windows.Forms.Label(); - this.DescLabel = new System.Windows.Forms.Label(); + this.EnableNRPECheckBox = new System.Windows.Forms.CheckBox(); + this.DescLabelPool = new XenAdmin.Controls.Common.AutoHeightLabel(); + this.descLabelHost = new XenAdmin.Controls.Common.AutoHeightLabel(); this.GeneralConfigureGroupBox = new System.Windows.Forms.GroupBox(); this.GeneralConfigTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); - this.EnableNRPECheckBox = new System.Windows.Forms.CheckBox(); this.AllowHostsLabel = new System.Windows.Forms.Label(); this.AllowHostsTextBox = new System.Windows.Forms.TextBox(); this.DebugLogCheckBox = new System.Windows.Forms.CheckBox(); this.SslDebugLogCheckBox = new System.Windows.Forms.CheckBox(); - this.CheckDataGridView = new System.Windows.Forms.DataGridView(); + this.CheckDataGridView = new XenAdmin.Controls.DataGridViewEx.DataGridViewEx(); this.CheckColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.WarningThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.CriticalThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.NRPETableLayoutPanel.SuspendLayout(); - this.PoolTipsTableLayoutPanel.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.PoolTipsPicture)).BeginInit(); this.GeneralConfigureGroupBox.SuspendLayout(); this.GeneralConfigTableLayoutPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).BeginInit(); @@ -60,61 +52,46 @@ private void InitializeComponent() // NRPETableLayoutPanel // resources.ApplyResources(this.NRPETableLayoutPanel, "NRPETableLayoutPanel"); - this.NRPETableLayoutPanel.Controls.Add(this.PoolTipsTableLayoutPanel, 0, 4); - this.NRPETableLayoutPanel.Controls.Add(this.DescLabel, 0, 0); - this.NRPETableLayoutPanel.Controls.Add(this.GeneralConfigureGroupBox, 0, 1); - this.NRPETableLayoutPanel.Controls.Add(this.CheckDataGridView, 0, 2); + this.NRPETableLayoutPanel.Controls.Add(this.EnableNRPECheckBox, 0, 2); + this.NRPETableLayoutPanel.Controls.Add(this.DescLabelPool, 0, 0); + this.NRPETableLayoutPanel.Controls.Add(this.descLabelHost, 0, 1); + this.NRPETableLayoutPanel.Controls.Add(this.GeneralConfigureGroupBox, 0, 3); + this.NRPETableLayoutPanel.Controls.Add(this.CheckDataGridView, 0, 4); this.NRPETableLayoutPanel.Name = "NRPETableLayoutPanel"; // - // PoolTipsTableLayoutPanel - // - resources.ApplyResources(this.PoolTipsTableLayoutPanel, "PoolTipsTableLayoutPanel"); - this.PoolTipsTableLayoutPanel.Controls.Add(this.PoolTipsPicture, 0, 0); - this.PoolTipsTableLayoutPanel.Controls.Add(this.PoolTipsLabel, 1, 0); - this.PoolTipsTableLayoutPanel.Name = "PoolTipsTableLayoutPanel"; - // - // PoolTipsPicture + // EnableNRPECheckBox // - resources.ApplyResources(this.PoolTipsPicture, "PoolTipsPicture"); - this.PoolTipsPicture.Image = global::XenAdmin.Properties.Resources._000_Info3_h32bit_16; - this.PoolTipsPicture.Name = "PoolTipsPicture"; - this.PoolTipsPicture.TabStop = false; + resources.ApplyResources(this.EnableNRPECheckBox, "EnableNRPECheckBox"); + this.EnableNRPECheckBox.Name = "EnableNRPECheckBox"; + this.EnableNRPECheckBox.UseVisualStyleBackColor = true; + this.EnableNRPECheckBox.CheckedChanged += new System.EventHandler(this.EnableNRPECheckBox_CheckedChanged); // - // PoolTipsLabel + // DescLabelPool // - resources.ApplyResources(this.PoolTipsLabel, "PoolTipsLabel"); - this.PoolTipsLabel.Name = "PoolTipsLabel"; + resources.ApplyResources(this.DescLabelPool, "DescLabelPool"); + this.DescLabelPool.Name = "DescLabelPool"; // - // DescLabel + // descLabelHost // - resources.ApplyResources(this.DescLabel, "DescLabel"); - this.DescLabel.Name = "DescLabel"; + resources.ApplyResources(this.descLabelHost, "descLabelHost"); + this.descLabelHost.Name = "descLabelHost"; // // GeneralConfigureGroupBox // - resources.ApplyResources(this.GeneralConfigureGroupBox, "GeneralConfigureGroupBox"); this.GeneralConfigureGroupBox.Controls.Add(this.GeneralConfigTableLayoutPanel); + resources.ApplyResources(this.GeneralConfigureGroupBox, "GeneralConfigureGroupBox"); this.GeneralConfigureGroupBox.Name = "GeneralConfigureGroupBox"; this.GeneralConfigureGroupBox.TabStop = false; // // GeneralConfigTableLayoutPanel // resources.ApplyResources(this.GeneralConfigTableLayoutPanel, "GeneralConfigTableLayoutPanel"); - this.GeneralConfigTableLayoutPanel.Controls.Add(this.EnableNRPECheckBox, 0, 1); - this.GeneralConfigTableLayoutPanel.Controls.Add(this.AllowHostsLabel, 0, 2); - this.GeneralConfigTableLayoutPanel.Controls.Add(this.AllowHostsTextBox, 1, 2); - this.GeneralConfigTableLayoutPanel.Controls.Add(this.DebugLogCheckBox, 0, 3); - this.GeneralConfigTableLayoutPanel.Controls.Add(this.SslDebugLogCheckBox, 0, 4); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.AllowHostsLabel, 0, 0); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.AllowHostsTextBox, 1, 0); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.DebugLogCheckBox, 0, 1); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.SslDebugLogCheckBox, 0, 2); this.GeneralConfigTableLayoutPanel.Name = "GeneralConfigTableLayoutPanel"; // - // EnableNRPECheckBox - // - resources.ApplyResources(this.EnableNRPECheckBox, "EnableNRPECheckBox"); - this.GeneralConfigTableLayoutPanel.SetColumnSpan(this.EnableNRPECheckBox, 2); - this.EnableNRPECheckBox.Name = "EnableNRPECheckBox"; - this.EnableNRPECheckBox.UseVisualStyleBackColor = true; - this.EnableNRPECheckBox.CheckedChanged += new System.EventHandler(this.EnableNRPECheckBox_CheckedChanged); - // // AllowHostsLabel // resources.ApplyResources(this.AllowHostsLabel, "AllowHostsLabel"); @@ -141,45 +118,37 @@ private void InitializeComponent() // // CheckDataGridView // - this.CheckDataGridView.AllowUserToAddRows = false; - this.CheckDataGridView.AllowUserToDeleteRows = false; - this.CheckDataGridView.AllowUserToResizeRows = false; - resources.ApplyResources(this.CheckDataGridView, "CheckDataGridView"); - this.CheckDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; - this.CheckDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; this.CheckDataGridView.BackgroundColor = System.Drawing.SystemColors.Window; - this.CheckDataGridView.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.CheckDataGridView.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None; + this.CheckDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; this.CheckDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.CheckColumn, this.WarningThresholdColumn, this.CriticalThresholdColumn}); + resources.ApplyResources(this.CheckDataGridView, "CheckDataGridView"); this.CheckDataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; - this.CheckDataGridView.EnableHeadersVisualStyles = false; - this.CheckDataGridView.MultiSelect = false; this.CheckDataGridView.Name = "CheckDataGridView"; - this.CheckDataGridView.RowHeadersVisible = false; + this.CheckDataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; + this.CheckDataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; this.CheckDataGridView.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.CheckDataGridView_BeginEdit); this.CheckDataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.CheckDataGridView_EndEdit); // // CheckColumn // - this.CheckColumn.FillWeight = 103.4483F; + this.CheckColumn.FillWeight = 40F; resources.ApplyResources(this.CheckColumn, "CheckColumn"); this.CheckColumn.Name = "CheckColumn"; this.CheckColumn.ReadOnly = true; // // WarningThresholdColumn // - dataGridViewCellStyle1.Format = "N2"; - dataGridViewCellStyle1.NullValue = null; - this.WarningThresholdColumn.DefaultCellStyle = dataGridViewCellStyle1; - this.WarningThresholdColumn.FillWeight = 98.27586F; + this.WarningThresholdColumn.FillWeight = 30F; resources.ApplyResources(this.WarningThresholdColumn, "WarningThresholdColumn"); this.WarningThresholdColumn.Name = "WarningThresholdColumn"; // // CriticalThresholdColumn // - this.CriticalThresholdColumn.FillWeight = 98.27586F; + this.CriticalThresholdColumn.FillWeight = 30F; resources.ApplyResources(this.CriticalThresholdColumn, "CriticalThresholdColumn"); this.CriticalThresholdColumn.Name = "CriticalThresholdColumn"; // @@ -191,10 +160,8 @@ private void InitializeComponent() this.Name = "NRPEEditPage"; this.NRPETableLayoutPanel.ResumeLayout(false); this.NRPETableLayoutPanel.PerformLayout(); - this.PoolTipsTableLayoutPanel.ResumeLayout(false); - this.PoolTipsTableLayoutPanel.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.PoolTipsPicture)).EndInit(); this.GeneralConfigureGroupBox.ResumeLayout(false); + this.GeneralConfigureGroupBox.PerformLayout(); this.GeneralConfigTableLayoutPanel.ResumeLayout(false); this.GeneralConfigTableLayoutPanel.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).EndInit(); @@ -204,26 +171,19 @@ private void InitializeComponent() } #endregion - private TableLayoutPanel NRPETableLayoutPanel; - - private Label DescLabel; - - private GroupBox GeneralConfigureGroupBox; - private TableLayoutPanel GeneralConfigTableLayoutPanel; - - private CheckBox EnableNRPECheckBox; - private Label AllowHostsLabel; - private TextBox AllowHostsTextBox; - private CheckBox DebugLogCheckBox; - private CheckBox SslDebugLogCheckBox; - - private DataGridView CheckDataGridView; - private DataGridViewTextBoxColumn CheckColumn; - private DataGridViewTextBoxColumn WarningThresholdColumn; - private DataGridViewTextBoxColumn CriticalThresholdColumn; - - private TableLayoutPanel PoolTipsTableLayoutPanel; - private PictureBox PoolTipsPicture; - private Label PoolTipsLabel; + private System.Windows.Forms.TableLayoutPanel NRPETableLayoutPanel; + private XenAdmin.Controls.Common.AutoHeightLabel DescLabelPool; + private System.Windows.Forms.GroupBox GeneralConfigureGroupBox; + private System.Windows.Forms.TableLayoutPanel GeneralConfigTableLayoutPanel; + private System.Windows.Forms.CheckBox EnableNRPECheckBox; + private System.Windows.Forms.Label AllowHostsLabel; + private System.Windows.Forms.TextBox AllowHostsTextBox; + private System.Windows.Forms.CheckBox DebugLogCheckBox; + private System.Windows.Forms.CheckBox SslDebugLogCheckBox; + private Controls.DataGridViewEx.DataGridViewEx CheckDataGridView; + private Controls.Common.AutoHeightLabel descLabelHost; + private System.Windows.Forms.DataGridViewTextBoxColumn CheckColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn WarningThresholdColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn CriticalThresholdColumn; } } \ No newline at end of file diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.cs b/XenAdmin/SettingsPanels/NRPEEditPage.cs index b33406a67..eae55f6b1 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -75,7 +75,7 @@ public string SubText } } - public Image Image => Images.StaticImages._000_EnablePowerControl_h32bit_16; + public Image Image => Images.StaticImages._000_Module_h32bit_16; public NRPEEditPage(bool isHost) { @@ -122,11 +122,6 @@ public NRPEEditPage(bool isHost) AllowHostsTextBox.GotFocus += AllowHostsTextBox_GotFocus; AllowHostsTextBox.LostFocus += AllowHostsTextBox_LostFocus; - if (isHost) - { - PoolTipsPicture.Hide(); - PoolTipsLabel.Hide(); - } InvalidParamToolTip = new ToolTip { IsBalloon = true, @@ -201,6 +196,10 @@ public void HideLocalValidationMessages() public void SetXenObjects(IXenObject orig, IXenObject clone) { Clone = clone; + + descLabelHost.Visible = IsHost; + DescLabelPool.Visible = !IsHost; + if (IsHost) { InitNRPEGeneralConfiguration(); diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.resx b/XenAdmin/SettingsPanels/NRPEEditPage.resx index 1359a1cf6..434ae8216 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.resx +++ b/XenAdmin/SettingsPanels/NRPEEditPage.resx @@ -117,10 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Top, Left, Right - True @@ -128,213 +124,144 @@ 1 - - Top, Left, Right - - + True - - 2 - - - Left - - - - - + + NoControl - - - - - 0, 7 - - - 0, 0, 0, 0 - - - 18, 17 - - - 17 - - - PoolTipsPicture - - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - PoolTipsTableLayoutPanel - - - 0 - - - Top, Bottom, Left, Right + + 3, 88 - - True + + 3, 3, 3, 8 - - NoControl + + 3, 0, 0, 0 - - 23, 3 + + 95, 17 - - 3, 3, 3, 3 + + 2 - - 600, 0 + + &Enable NRPE - - 600, 26 + + EnableNRPECheckBox - - 16 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - For the pool properties, there will not be showing the real configuration values in every host. When clicking OK, NRPE configuration and check threshold will be sent to all the hosts in this pool. + + NRPETableLayoutPanel - - MiddleLeft + + 0 - - PoolTipsLabel + + True - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Fill - - PoolTipsTableLayoutPanel + + NoControl - - 1 + + 3, 0 - - 3, 407 + + 3, 0, 3, 10 - - 1 + + 644, 39 - - 641, 32 + + 0 - - 5 + + Nagios Remote Plugin Executor (NRPE) allows you to monitor remotely resource metrics on the servers of your pool. +This page does not offer an overview of the NRPE configuration and metric threshold settings of the pool servers. Use it only to apply your chosen configuration and threshold settings to all servers in the pool. - - PoolTipsTableLayoutPanel + + DescLabelPool - - System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + XenAdmin.Controls.Common.AutoHeightLabel, [XenCenter], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - + NRPETableLayoutPanel - - 0 - - - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="PoolTipsPicture" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="PoolTipsLabel" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="Absolute,20,AutoSize,0" /><Rows Styles="Percent,100" /></TableLayoutSettings> - - - Top, Bottom, Left, Right + + 1 - + True - - NoControl + + Fill - - 3, 0 + + 3, 49 - - 641, 26 + + 3, 0, 3, 10 - - 5 + + 644, 26 - - NRPE (Nagios Remote Plugin Excutor) allow you to execute Nagios plugins on a remote host. You can modify NRPE general configuration and NRPE Check threshold in this page. + + 1 - - DescLabel + + Nagios Remote Plugin Executor (NRPE) allows you to monitor remotely resource metrics on the servers of your pool. +Use this page to review and modify the NRPE configuration and metric threshold settings used for this server. - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + descLabelHost - + + XenAdmin.Controls.Common.AutoHeightLabel, [XenCenter], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + NRPETableLayoutPanel - - 1 + + 2 - - Top, Bottom, Left, Right + + True - - Top, Bottom, Left, Right + + GrowAndShrink 2 - - Top, Left, Right + + Left - + True - - NoControl - - - 3, 3 - - - 636, 17 - - - 0 - - - Enable NRPE - - - EnableNRPECheckBox - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - GeneralConfigTableLayoutPanel - - - 0 - NoControl - 3, 23 + 3, 6 - 100, 24 + 96, 13 - 1 + 0 - Allow Hosts: - - - MiddleLeft + &Monitoring servers: AllowHostsLabel @@ -346,22 +273,19 @@ GeneralConfigTableLayoutPanel - 1 + 0 Left, Right - 120, 25 - - - 3, 0, 20, 0 + 105, 3 - 502, 20 + 530, 20 - 2 + 1 AllowHostsTextBox @@ -373,10 +297,7 @@ GeneralConfigTableLayoutPanel - 2 - - - Top, Left, Right + 1 True @@ -385,16 +306,19 @@ NoControl - 3, 50 + 3, 29 + + + 3, 0, 0, 0 - 636, 17 + 211, 17 - 3 + 2 - Record debugging message to syslog + Record &debugging messages to syslog DebugLogCheckBox @@ -406,10 +330,7 @@ GeneralConfigTableLayoutPanel - 3 - - - Top, Left, Right + 2 True @@ -418,16 +339,19 @@ NoControl - 3, 73 + 3, 52 + + + 3, 0, 0, 0 - 636, 17 + 181, 17 - 4 + 3 - Record SSL message to syslog + Record &SSL messages to syslog SslDebugLogCheckBox @@ -439,22 +363,22 @@ GeneralConfigTableLayoutPanel - 4 + 3 - - 10, 12 + + Top - - 3, 3, 3, 0 + + 3, 16 - 6 + 3 - 642, 93 + 638, 72 - 13 + 0 GeneralConfigTableLayoutPanel @@ -469,19 +393,25 @@ 0 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="EnableNRPECheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="AllowHostsLabel" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="AllowHostsTextBox" Row="2" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="DebugLogCheckBox" Row="3" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="SslDebugLogCheckBox" Row="4" RowSpan="1" Column="0" ColumnSpan="2" /></Controls><Columns Styles="Percent,18.36735,Percent,81.63265" /><Rows Styles="Absolute,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="AllowHostsLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="AllowHostsTextBox" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="DebugLogCheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="SslDebugLogCheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="2" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,Absolute,20" /></TableLayoutSettings> + + + Fill - 3, 29 + 3, 116 + + + 3, 3, 3, 10 - 3, 0, 3, 0 + 3, 3, 3, 0 - 641, 118 + 644, 100 - 7 + 3 General Configuration @@ -496,16 +426,13 @@ NRPETableLayoutPanel - 2 - - - Top, Left, Right + 3 - Check + Metric - 220 + 100 True @@ -514,7 +441,7 @@ Warning Threshold - 140 + 100 True @@ -523,28 +450,34 @@ Critical Threshold - 140 + 100 + + + Fill - 3, 153 + 3, 229 - 641, 248 + 644, 305 - 15 + 4 CheckDataGridView - System.Windows.Forms.DataGridView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + XenAdmin.Controls.DataGridViewEx.DataGridViewEx, [XenCenter], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null NRPETableLayoutPanel - 3 + 4 + + + Fill 0, 0 @@ -556,10 +489,10 @@ 5 - 647, 442 + 650, 537 - 4 + 0 NRPETableLayoutPanel @@ -574,7 +507,7 @@ 0 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="PoolTipsTableLayoutPanel" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="DescLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="GeneralConfigureGroupBox" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="CheckDataGridView" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="EnableNRPECheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="DescLabelPool" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="descLabelHost" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="GeneralConfigureGroupBox" Row="3" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="CheckDataGridView" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Percent,100" /></TableLayoutSettings> True @@ -586,7 +519,7 @@ True - 650, 621 + 650, 537 CheckColumn diff --git a/XenAdmin/XenAdmin.csproj b/XenAdmin/XenAdmin.csproj index d0338e5fc..3930e9eef 100755 --- a/XenAdmin/XenAdmin.csproj +++ b/XenAdmin/XenAdmin.csproj @@ -484,7 +484,6 @@ NRPEEditPage.cs - NRPEEditPage.cs UserControl From 596a83dd68a43e37f6d70fa4536adc02743040bd Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Wed, 27 Sep 2023 19:05:27 +0100 Subject: [PATCH 03/10] Moved NRPE related files to the same folder. Signed-off-by: Konstantina Chremmou --- XenAdmin/SettingsPanels/NRPEEditPage.cs | 8 +++++--- XenModel/{ => Actions}/NRPE/NRPEHostConfiguration.cs | 2 +- XenModel/Actions/{Host => NRPE}/NRPEUpdateAction.cs | 2 +- XenModel/XenModel.csproj | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) rename XenModel/{ => Actions}/NRPE/NRPEHostConfiguration.cs (96%) rename XenModel/Actions/{Host => NRPE}/NRPEUpdateAction.cs (97%) diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.cs b/XenAdmin/SettingsPanels/NRPEEditPage.cs index eae55f6b1..d89080012 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -29,13 +29,15 @@ */ using System; +using System.Collections.Generic; using System.Drawing; +using System.Text.RegularExpressions; using System.Windows.Forms; -using XenAPI; using XenAdmin.Actions; -using System.Collections.Generic; using XenAdmin.Core; -using System.Text.RegularExpressions; +using XenAdmin.Actions.NRPE; +using XenAPI; + namespace XenAdmin.SettingsPanels { diff --git a/XenModel/NRPE/NRPEHostConfiguration.cs b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs similarity index 96% rename from XenModel/NRPE/NRPEHostConfiguration.cs rename to XenModel/Actions/NRPE/NRPEHostConfiguration.cs index 597556aac..c143a3cca 100644 --- a/XenModel/NRPE/NRPEHostConfiguration.cs +++ b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs @@ -31,7 +31,7 @@ using System; using System.Collections.Generic; -namespace XenAdmin +namespace XenAdmin.Actions.NRPE { public class NRPEHostConfiguration : ICloneable { diff --git a/XenModel/Actions/Host/NRPEUpdateAction.cs b/XenModel/Actions/NRPE/NRPEUpdateAction.cs similarity index 97% rename from XenModel/Actions/Host/NRPEUpdateAction.cs rename to XenModel/Actions/NRPE/NRPEUpdateAction.cs index 38eefe94b..05cb749db 100644 --- a/XenModel/Actions/Host/NRPEUpdateAction.cs +++ b/XenModel/Actions/NRPE/NRPEUpdateAction.cs @@ -33,7 +33,7 @@ using XenAPI; -namespace XenAdmin.Actions +namespace XenAdmin.Actions.NRPE { public class NRPEUpdateAction : AsyncAction { diff --git a/XenModel/XenModel.csproj b/XenModel/XenModel.csproj index 949403fbd..2850c5ca4 100755 --- a/XenModel/XenModel.csproj +++ b/XenModel/XenModel.csproj @@ -88,7 +88,7 @@ - + @@ -199,7 +199,7 @@ - + From b2f8efa59dd564da7e6b83b7e5b68df6c08c357f Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Thu, 28 Sep 2023 13:22:46 +0100 Subject: [PATCH 04/10] Some corrections in wording, code style, C# usage, and null checks. Signed-off-by: Konstantina Chremmou --- XenAdmin/Dialogs/PropertiesDialog.cs | 2 +- XenAdmin/SettingsPanels/NRPEEditPage.cs | 66 +++++++++-------- .../Actions/NRPE/NRPEHostConfiguration.cs | 72 +++++++++---------- XenModel/Messages.Designer.cs | 21 ++++-- XenModel/Messages.resx | 15 ++-- 5 files changed, 91 insertions(+), 85 deletions(-) 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. From 52da131eb81d5664da369b194f0f2e7c6ba5cbc2 Mon Sep 17 00:00:00 2001 From: Bengang Yuan Date: Sun, 8 Oct 2023 16:03:18 +0800 Subject: [PATCH 05/10] Rename private instance class fields name, add parameters changing check, etc. --- XenAdmin/Dialogs/PropertiesDialog.cs | 3 +- .../SettingsPanels/NRPEEditPage.CheckGroup.cs | 273 ----------- .../SettingsPanels/NRPEEditPage.Designer.cs | 65 ++- XenAdmin/SettingsPanels/NRPEEditPage.cs | 443 +++++++++++------- XenAdmin/SettingsPanels/NRPEEditPage.resx | 285 +++++++---- XenAdmin/XenAdmin.csproj | 3 - XenModel/Actions/NRPE/CheckGroup.cs | 267 +++++++++++ .../Actions/NRPE/NRPEHostConfiguration.cs | 27 +- XenModel/Actions/NRPE/NRPERetrieveAction.cs | 163 +++++++ XenModel/Actions/NRPE/NRPEUpdateAction.cs | 56 +-- XenModel/Messages.Designer.cs | 47 +- XenModel/Messages.resx | 19 +- XenModel/XenModel.csproj | 3 + 13 files changed, 1069 insertions(+), 585 deletions(-) delete mode 100644 XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs create mode 100644 XenModel/Actions/NRPE/CheckGroup.cs create mode 100644 XenModel/Actions/NRPE/NRPERetrieveAction.cs diff --git a/XenAdmin/Dialogs/PropertiesDialog.cs b/XenAdmin/Dialogs/PropertiesDialog.cs index b35caaf89..8c6f9de77 100755 --- a/XenAdmin/Dialogs/PropertiesDialog.cs +++ b/XenAdmin/Dialogs/PropertiesDialog.cs @@ -318,7 +318,8 @@ private void Build() dialog.ShowDialog(Program.MainWindow); } } - if (isHost || isPool) + if ((isHost || isPool) && + (connection.Session.IsLocalSuperuser || connection.Session.Roles.Any(r => r.name_label == Role.MR_ROLE_POOL_ADMIN))) { NRPEEditPage = new NRPEEditPage(); ShowTab(NRPEEditPage); diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs b/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs deleted file mode 100644 index 3a779a3bd..000000000 --- a/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs +++ /dev/null @@ -1,273 +0,0 @@ -/* 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)); - } - - 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; - } - } - - 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) - { - } - - 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) - { - 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; - } - } - } -} diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs index 5a157e6e7..a3fcc3103 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs @@ -30,9 +30,9 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NRPEEditPage)); this.NRPETableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); - this.EnableNRPECheckBox = new System.Windows.Forms.CheckBox(); this.DescLabelPool = new XenAdmin.Controls.Common.AutoHeightLabel(); - this.descLabelHost = new XenAdmin.Controls.Common.AutoHeightLabel(); + this.DescLabelHost = new XenAdmin.Controls.Common.AutoHeightLabel(); + this.EnableNRPECheckBox = new System.Windows.Forms.CheckBox(); this.GeneralConfigureGroupBox = new System.Windows.Forms.GroupBox(); this.GeneralConfigTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.AllowHostsLabel = new System.Windows.Forms.Label(); @@ -43,38 +43,44 @@ private void InitializeComponent() this.CheckColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.WarningThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.CriticalThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.RetrieveNRPEPanel = new System.Windows.Forms.TableLayoutPanel(); + this.RetrieveNRPELabel = new System.Windows.Forms.Label(); + this.RetrieveNRPEPicture = new System.Windows.Forms.PictureBox(); this.NRPETableLayoutPanel.SuspendLayout(); this.GeneralConfigureGroupBox.SuspendLayout(); this.GeneralConfigTableLayoutPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).BeginInit(); + this.RetrieveNRPEPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.RetrieveNRPEPicture)).BeginInit(); this.SuspendLayout(); // // NRPETableLayoutPanel // resources.ApplyResources(this.NRPETableLayoutPanel, "NRPETableLayoutPanel"); - this.NRPETableLayoutPanel.Controls.Add(this.EnableNRPECheckBox, 0, 2); this.NRPETableLayoutPanel.Controls.Add(this.DescLabelPool, 0, 0); - this.NRPETableLayoutPanel.Controls.Add(this.descLabelHost, 0, 1); + this.NRPETableLayoutPanel.Controls.Add(this.DescLabelHost, 0, 1); + this.NRPETableLayoutPanel.Controls.Add(this.EnableNRPECheckBox, 0, 2); this.NRPETableLayoutPanel.Controls.Add(this.GeneralConfigureGroupBox, 0, 3); this.NRPETableLayoutPanel.Controls.Add(this.CheckDataGridView, 0, 4); + this.NRPETableLayoutPanel.Controls.Add(this.RetrieveNRPEPanel, 0, 5); this.NRPETableLayoutPanel.Name = "NRPETableLayoutPanel"; // - // EnableNRPECheckBox - // - resources.ApplyResources(this.EnableNRPECheckBox, "EnableNRPECheckBox"); - this.EnableNRPECheckBox.Name = "EnableNRPECheckBox"; - this.EnableNRPECheckBox.UseVisualStyleBackColor = true; - this.EnableNRPECheckBox.CheckedChanged += new System.EventHandler(this.EnableNRPECheckBox_CheckedChanged); - // // DescLabelPool // resources.ApplyResources(this.DescLabelPool, "DescLabelPool"); this.DescLabelPool.Name = "DescLabelPool"; // - // descLabelHost + // DescLabelHost + // + resources.ApplyResources(this.DescLabelHost, "DescLabelHost"); + this.DescLabelHost.Name = "DescLabelHost"; + // + // EnableNRPECheckBox // - resources.ApplyResources(this.descLabelHost, "descLabelHost"); - this.descLabelHost.Name = "descLabelHost"; + resources.ApplyResources(this.EnableNRPECheckBox, "EnableNRPECheckBox"); + this.EnableNRPECheckBox.Name = "EnableNRPECheckBox"; + this.EnableNRPECheckBox.UseVisualStyleBackColor = true; + this.EnableNRPECheckBox.CheckedChanged += new System.EventHandler(this.EnableNRPECheckBox_CheckedChanged); // // GeneralConfigureGroupBox // @@ -120,12 +126,12 @@ private void InitializeComponent() // this.CheckDataGridView.BackgroundColor = System.Drawing.SystemColors.Window; this.CheckDataGridView.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None; + resources.ApplyResources(this.CheckDataGridView, "CheckDataGridView"); this.CheckDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; this.CheckDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.CheckColumn, this.WarningThresholdColumn, this.CriticalThresholdColumn}); - resources.ApplyResources(this.CheckDataGridView, "CheckDataGridView"); this.CheckDataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; this.CheckDataGridView.Name = "CheckDataGridView"; this.CheckDataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; @@ -152,6 +158,24 @@ private void InitializeComponent() resources.ApplyResources(this.CriticalThresholdColumn, "CriticalThresholdColumn"); this.CriticalThresholdColumn.Name = "CriticalThresholdColumn"; // + // RetrieveNRPEPanel + // + resources.ApplyResources(this.RetrieveNRPEPanel, "RetrieveNRPEPanel"); + this.RetrieveNRPEPanel.Controls.Add(this.RetrieveNRPELabel, 1, 0); + this.RetrieveNRPEPanel.Controls.Add(this.RetrieveNRPEPicture, 0, 0); + this.RetrieveNRPEPanel.Name = "RetrieveNRPEPanel"; + // + // RetrieveNRPELabel + // + resources.ApplyResources(this.RetrieveNRPELabel, "RetrieveNRPELabel"); + this.RetrieveNRPELabel.Name = "RetrieveNRPELabel"; + // + // RetrieveNRPEPicture + // + resources.ApplyResources(this.RetrieveNRPEPicture, "RetrieveNRPEPicture"); + this.RetrieveNRPEPicture.Name = "RetrieveNRPEPicture"; + this.RetrieveNRPEPicture.TabStop = false; + // // NRPEEditPage // resources.ApplyResources(this, "$this"); @@ -165,8 +189,9 @@ private void InitializeComponent() this.GeneralConfigTableLayoutPanel.ResumeLayout(false); this.GeneralConfigTableLayoutPanel.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).EndInit(); + this.RetrieveNRPEPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.RetrieveNRPEPicture)).EndInit(); this.ResumeLayout(false); - this.PerformLayout(); } @@ -181,9 +206,13 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox DebugLogCheckBox; private System.Windows.Forms.CheckBox SslDebugLogCheckBox; private Controls.DataGridViewEx.DataGridViewEx CheckDataGridView; - private Controls.Common.AutoHeightLabel descLabelHost; + private Controls.Common.AutoHeightLabel DescLabelHost; private System.Windows.Forms.DataGridViewTextBoxColumn CheckColumn; private System.Windows.Forms.DataGridViewTextBoxColumn WarningThresholdColumn; private System.Windows.Forms.DataGridViewTextBoxColumn CriticalThresholdColumn; + private System.Windows.Forms.Label RetrieveNRPELabel; + private System.Windows.Forms.TableLayoutPanel RetrieveNRPEPanel; + private System.Windows.Forms.PictureBox RetrieveNRPEPicture; } -} \ No newline at end of file +} + \ No newline at end of file diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.cs b/XenAdmin/SettingsPanels/NRPEEditPage.cs index ccf22e2e3..819366428 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -37,7 +37,7 @@ using XenAdmin.Core; using XenAdmin.Actions.NRPE; using XenAPI; - +using System.Linq; namespace XenAdmin.SettingsPanels { @@ -51,31 +51,16 @@ public partial class NRPEEditPage : UserControl, IEditPage private bool _isHost; - private IXenObject Clone; - private readonly ToolTip InvalidParamToolTip; - private string InvalidParamToolTipText = ""; - - private readonly List CheckGroupList = new List(); - private readonly Dictionary CheckGroupDictByName = new Dictionary(); - private readonly Dictionary CheckGroupDictByLabel = new Dictionary(); + private IXenObject _clone; + private readonly ToolTip _invalidParamToolTip; + private string _invalidParamToolTipText = ""; - private NRPEHostConfiguration NRPEOriginalConfig; - private NRPEHostConfiguration NRPECurrentConfig; + private readonly List _checkGroupList = new List(); + private readonly Dictionary _checkGroupDictByName = new Dictionary(); + private readonly Dictionary _checkGroupDictByLabel = new Dictionary(); - public string SubText - { - get - { - if (_isHost) - { - return EnableNRPECheckBox.Checked ? Messages.NRPE_ACTIVE : Messages.NRPE_INACTIVE; - } - else - { - return Messages.NRPE_BATCH_CONFIGURATION; - } - } - } + private NRPEHostConfiguration _nrpeOriginalConfig; + private NRPEHostConfiguration _nrpeCurrentConfig; public Image Image => Images.StaticImages._000_Module_h32bit_16; @@ -84,61 +69,70 @@ public NRPEEditPage() InitializeComponent(); Text = Messages.NRPE; - NRPECurrentConfig = new NRPEHostConfiguration + _nrpeOriginalConfig = new NRPEHostConfiguration { EnableNRPE = false, AllowHosts = NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER, Debug = false, SslLogging = false }; - NRPEOriginalConfig = (NRPEHostConfiguration) NRPECurrentConfig.Clone(); - - EnableNRPECheckBox.DataBindings.Add("Checked", NRPECurrentConfig, "enableNRPE"); - AllowHostsTextBox.DataBindings.Add("Text", NRPECurrentConfig, "allowHosts"); - DebugLogCheckBox.DataBindings.Add("Checked", NRPECurrentConfig, "debug"); - SslDebugLogCheckBox.DataBindings.Add("Checked", NRPECurrentConfig, "sslLogging"); - - CheckGroupList.Add(new HostLoadCheckGroup("check_host_load", Messages.NRPE_CHECK_HOST_LOAD)); - CheckGroupList.Add(new CheckGroup("check_host_cpu", Messages.NRPE_CHECK_HOST_CPU)); - CheckGroupList.Add(new CheckGroup("check_host_memory", Messages.NRPE_CHECK_HOST_MEMORY)); - CheckGroupList.Add(new CheckGroup("check_vgpu", Messages.NRPE_CHECK_VGPU)); - CheckGroupList.Add(new CheckGroup("check_vgpu_memory", Messages.NRPE_CHECK_VGPU_MEMORY)); - CheckGroupList.Add(new Dom0LoadCheckGroup("check_load", Messages.NRPE_CHECK_LOAD)); - CheckGroupList.Add(new CheckGroup("check_cpu", Messages.NRPE_CHECK_CPU)); - CheckGroupList.Add(new CheckGroup("check_memory", Messages.NRPE_CHECK_MEMORY)); - CheckGroupList.Add(new FreeCheckGroup("check_swap", Messages.NRPE_CHECK_SWAP)); - CheckGroupList.Add(new FreeCheckGroup("check_disk_root", Messages.NRPE_CHECK_DISK_ROOT)); - CheckGroupList.Add(new FreeCheckGroup("check_disk_log", Messages.NRPE_CHECK_DISK_LOG)); - - foreach (CheckGroup checkGroup in CheckGroupList) + + _checkGroupList.Add(new HostLoadCheckGroup("check_host_load", Messages.NRPE_CHECK_HOST_LOAD)); + _checkGroupList.Add(new CheckGroup("check_host_cpu", Messages.NRPE_CHECK_HOST_CPU)); + _checkGroupList.Add(new CheckGroup("check_host_memory", Messages.NRPE_CHECK_HOST_MEMORY)); + _checkGroupList.Add(new CheckGroup("check_vgpu", Messages.NRPE_CHECK_VGPU)); + _checkGroupList.Add(new CheckGroup("check_vgpu_memory", Messages.NRPE_CHECK_VGPU_MEMORY)); + _checkGroupList.Add(new Dom0LoadCheckGroup("check_load", Messages.NRPE_CHECK_LOAD)); + _checkGroupList.Add(new CheckGroup("check_cpu", Messages.NRPE_CHECK_CPU)); + _checkGroupList.Add(new CheckGroup("check_memory", Messages.NRPE_CHECK_MEMORY)); + _checkGroupList.Add(new FreeCheckGroup("check_swap", Messages.NRPE_CHECK_SWAP)); + _checkGroupList.Add(new FreeCheckGroup("check_disk_root", Messages.NRPE_CHECK_DISK_ROOT)); + _checkGroupList.Add(new FreeCheckGroup("check_disk_log", Messages.NRPE_CHECK_DISK_LOG)); + + foreach (CheckGroup checkGroup in _checkGroupList) { CheckDataGridView.Rows.Add(checkGroup.CheckThresholdRow); - CheckGroupDictByName.Add(checkGroup.Name, checkGroup); - CheckGroupDictByLabel.Add(checkGroup.NameCell.Value.ToString(), checkGroup); + _checkGroupDictByName.Add(checkGroup.Name, checkGroup); + _checkGroupDictByLabel.Add(checkGroup.NameCell.Value.ToString(), checkGroup); } - UpdateOtherComponentBasedEnableNRPECheckBox(); - AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); AllowHostsTextBox.GotFocus += AllowHostsTextBox_GotFocus; AllowHostsTextBox.LostFocus += AllowHostsTextBox_LostFocus; - InvalidParamToolTip = new ToolTip + _invalidParamToolTip = new ToolTip { IsBalloon = true, ToolTipIcon = ToolTipIcon.Warning, ToolTipTitle = Messages.INVALID_PARAMETER, Tag = AllowHostsTextBox }; + DisableAllComponent(); + } + + public string SubText + { + get + { + if (_isHost) + { + return Messages.NRPE_EDIT_PAGE_TEXT; + } + else + { + return Messages.NRPE_BATCH_CONFIGURATION; + } + } } public bool ValidToSave { get { - InvalidParamToolTipText = ""; - InvalidParamToolTip.ToolTipTitle = ""; + _invalidParamToolTipText = ""; + _invalidParamToolTip.ToolTipTitle = ""; CheckDataGridView.ShowCellToolTips = false; + CheckDataGridView.ShowCellErrors = false; if (!EnableNRPECheckBox.Checked) { @@ -147,10 +141,12 @@ public bool ValidToSave bool valid = IsAllowHostsValid(); - foreach (CheckGroup checkGroup in CheckGroupList) + foreach (CheckGroup checkGroup in _checkGroupList) { if (!checkGroup.CheckValue()) { + CheckDataGridView.ShowCellToolTips = true; + CheckDataGridView.ShowCellErrors = true; valid = false; } } @@ -162,7 +158,15 @@ public bool HasChanged { get { - return true; + UpdateCurrentNRPEConfiguration(); + if (_isHost) + { + return IsNRPEConfigurationChanged(); + } + else + { + return true; + } } } @@ -172,171 +176,269 @@ public void Cleanup() public void ShowLocalValidationMessages() { - if (InvalidParamToolTip.Tag is Control ctrl) + if (_invalidParamToolTip.Tag is Control ctrl) { - InvalidParamToolTip.Hide(ctrl); - if (!InvalidParamToolTipText.Equals("")) + _invalidParamToolTip.Hide(ctrl); + if (!_invalidParamToolTipText.Equals("")) { - HelpersGUI.ShowBalloonMessage(ctrl, InvalidParamToolTip, InvalidParamToolTipText); + HelpersGUI.ShowBalloonMessage(ctrl, _invalidParamToolTip, _invalidParamToolTipText); } } } public void HideLocalValidationMessages() { - if (InvalidParamToolTip.Tag is Control ctrl) + if (_invalidParamToolTip.Tag is Control ctrl) { - InvalidParamToolTip.Hide(ctrl); + _invalidParamToolTip.Hide(ctrl); } } - public void SetXenObjects(IXenObject orig, IXenObject clone) + public AsyncAction SaveSettings() { - Clone = clone; - _isHost = Clone is Host; - - descLabelHost.Visible = _isHost; - DescLabelPool.Visible = !_isHost; - - if (_isHost) - { - InitNRPEGeneralConfiguration(); - InitNRPEThreshold(); - } + return new NRPEUpdateAction(_clone, _nrpeCurrentConfig, _nrpeOriginalConfig, true); } - public AsyncAction SaveSettings() + public bool IsNRPEAvailable(IXenObject clone) { - foreach (KeyValuePair item in CheckGroupDictByName) + IXenObject checkHost; + if (clone is Host h) { - if (item.Value.WarningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText)) - && item.Value.CriticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText))) - { - NRPECurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(item.Key, - item.Value.WarningThresholdCell.Value.ToString(), item.Value.CriticalThresholdCell.Value.ToString())); - } + checkHost = h; } - return new NRPEUpdateAction(Clone, NRPECurrentConfig, NRPEOriginalConfig, false); + else if (clone is Pool p) + { + List hostList = p.Connection.Cache.Hosts.ToList(); + checkHost = hostList[0]; + } + else + { + return false; + } + try + { + Host.call_plugin(checkHost.Connection.Session, checkHost.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, null); + } + catch (Exception e) + { + log.InfoFormat("Execute NRPE plugin failed, failed reason: {0}. It may not support NRPE.", e.Message); + return false; + } + return true; } - private void InitNRPEGeneralConfiguration() + public void SetXenObjects(IXenObject orig, IXenObject clone) { - string status = Host.call_plugin(Clone.Connection.Session, Clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, - NRPEHostConfiguration.XAPI_NRPE_STATUS, null); - log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_STATUS, status); - NRPECurrentConfig.EnableNRPE = status.Trim().Equals("active enabled"); - - string nrpeConfig = Host.call_plugin(Clone.Connection.Session, Clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, - NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, null); - log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, nrpeConfig); + _clone = clone; + _isHost = _clone is Host; - string[] nrpeConfigArray = nrpeConfig.Split('\n'); - foreach (string nrpeConfigItem in nrpeConfigArray) - { - if (nrpeConfigItem.Trim().StartsWith("allowed_hosts:")) - { - string allowHosts = nrpeConfigItem.Replace("allowed_hosts:", "").Trim(); - NRPECurrentConfig.AllowHosts = AllowHostsWithoutLocalAddress(allowHosts); - AllowHostsTextBox.ForeColor = AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ? - Color.FromKnownColor(KnownColor.ControlDark) : Color.FromKnownColor(KnownColor.ControlText); - } - else if (nrpeConfigItem.Trim().StartsWith("debug:")) - { - string enableDebug = nrpeConfigItem.Replace("debug:", "").Trim(); - NRPECurrentConfig.Debug = enableDebug.Equals(NRPEHostConfiguration.DEBUG_ENABLE); - } - else if (nrpeConfigItem.Trim().StartsWith("ssl_logging:")) - { - string enableSslLogging = nrpeConfigItem.Replace("ssl_logging:", "").Trim(); - NRPECurrentConfig.SslLogging = enableSslLogging.Equals(NRPEHostConfiguration.SSL_LOGGING_ENABLE); - } - } - NRPEOriginalConfig = (NRPEHostConfiguration) NRPECurrentConfig.Clone(); + DescLabelHost.Visible = _isHost; + DescLabelPool.Visible = !_isHost; + UpdateRetrievingNRPETip(NRPEHostConfiguration.RetrieveNRPEStatus.Retrieving); + DisableAllComponent(); - UpdateOtherComponentBasedEnableNRPECheckBox(); + NRPERetrieveAction action = new NRPERetrieveAction(_clone, _nrpeOriginalConfig, _checkGroupDictByName, true); + action.Completed += ActionCompleted; + action.RunAsync(); } - private void InitNRPEThreshold() + private void ActionCompleted(ActionBase sender) { - string nrpeThreshold = Host.call_plugin(Clone.Connection.Session, Clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, - NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, null); - log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, nrpeThreshold); + Program.Invoke(this.Parent, UpdateRetrieveStatus); + } - string[] nrpeThresholdArray = nrpeThreshold.Split('\n'); - foreach (string nrpeThresholdItem in nrpeThresholdArray) + private void UpdateRetrieveStatus() + { + if (_nrpeOriginalConfig.Status == NRPEHostConfiguration.RetrieveNRPEStatus.Successful) { - // Return string format for each line: check_cpu warning threshold - 50 critical threshold - 80 - string[] thresholdRtnArray = nrpeThresholdItem.Split(' '); - string checkName = thresholdRtnArray[0]; - if (CheckGroupDictByName.TryGetValue(thresholdRtnArray[0], out CheckGroup thresholdCheck)) - { - string warningThreshold = thresholdRtnArray[4]; - string criticalThreshold = thresholdRtnArray[8]; - thresholdCheck.UpdateThreshold(warningThreshold, criticalThreshold); - NRPEOriginalConfig.AddNRPECheck(new NRPEHostConfiguration.Check(checkName, warningThreshold, criticalThreshold)); - } + AllowHostsTextBox.ForeColor = AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ? + Color.FromKnownColor(KnownColor.ControlDark) : Color.FromKnownColor(KnownColor.ControlText); + UpdateOtherComponentBasedEnableNRPECheckBox(); + UpdateComponentBasedConfiguration(); } + UpdateRetrievingNRPETip(_nrpeOriginalConfig.Status); } - private bool IsAllowHostsValid() + private void UpdateRetrievingNRPETip(NRPEHostConfiguration.RetrieveNRPEStatus status) { - InvalidParamToolTip.ToolTipTitle = Messages.NRPE_ALLOW_HOSTS_ERROR_TITLE; - InvalidParamToolTip.Tag = AllowHostsTextBox; - CheckDataGridView.ShowCellToolTips = true; - - string str = AllowHostsTextBox.Text; - if (str.Trim().Length == 0 || str.Trim().Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER)) + switch (status) { - InvalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_EMPTY_ERROR; - return false; + case NRPEHostConfiguration.RetrieveNRPEStatus.Retrieving: + RetrieveNRPELabel.Text = Messages.NRPE_RETRIEVING_CONFIGURATION; + RetrieveNRPEPicture.Image = Images.StaticImages.ajax_loader; + RetrieveNRPEPicture.Visible = true; + break; + case NRPEHostConfiguration.RetrieveNRPEStatus.Successful: + RetrieveNRPELabel.Text = ""; + RetrieveNRPEPicture.Image = Images.StaticImages._000_Tick_h32bit_16; + RetrieveNRPEPicture.Visible = false; + break; + case NRPEHostConfiguration.RetrieveNRPEStatus.Failed: + RetrieveNRPELabel.Text = Messages.NRPE_RETRIEVE_FAILED; + RetrieveNRPEPicture.Image = Images.StaticImages._000_error_h32bit_16; + RetrieveNRPEPicture.Visible = true; + break; + case NRPEHostConfiguration.RetrieveNRPEStatus.Unsupport: + RetrieveNRPELabel.Text = Messages.NRPE_UNSUPPORT; + RetrieveNRPEPicture.Image = Images.StaticImages._000_error_h32bit_16; + RetrieveNRPEPicture.Visible = true; + break; + default: + break; } + } - string[] hostArray = str.Split(','); - foreach (string host in hostArray) + private void DisableAllComponent() + { + EnableNRPECheckBox.Enabled = false; + GeneralConfigureGroupBox.Enabled = false; + CheckDataGridView.Enabled = false; + } + + private bool IsAllowHostsValid() + { + _invalidParamToolTip.ToolTipTitle = Messages.NRPE_ALLOW_HOSTS_ERROR_TITLE; + _invalidParamToolTip.Tag = AllowHostsTextBox; + CheckDataGridView.ShowCellToolTips = true; + + string str = AllowHostsTextBox.Text; + if (str.Trim().Length == 0 || str.Trim().Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER)) + { + _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_EMPTY_ERROR; + return false; + } + + string[] hostArray = str.Split(','); + for ( int i = 0; i < hostArray.Length; i++ ) + { + if (!REGEX_IPV4.Match(hostArray[i].Trim()).Success && + !REGEX_IPV4_CIDR.Match(hostArray[i].Trim()).Success && + !REGEX_DOMAIN.Match(hostArray[i].Trim()).Success) + { + _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR; + return false; + } + for ( int j = 0; j < i; j++ ) + { + if (hostArray[i].Trim().Equals(hostArray[j].Trim())) + { + _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_SAME_ADDRESS; + return false; + } + } + } + foreach (string host in hostArray) + { + if (!REGEX_IPV4.Match(host.Trim()).Success && + !REGEX_IPV4_CIDR.Match(host.Trim()).Success && + !REGEX_DOMAIN.Match(host.Trim()).Success) + { + _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR; + return false; + } + } + CheckDataGridView.ShowCellToolTips = false; + return true; + } + + private string AllowHostsWithoutLocalAddress(string allowHosts) + { + string UpdatedAllowHosts = ""; + string[] AllowHostArray = allowHosts.Split(','); + foreach (string allowHost in AllowHostArray) + { + if (!allowHost.Trim().Equals("127.0.0.1") && + !allowHost.Trim().Equals("::1")) + { + UpdatedAllowHosts += allowHost + ","; + } + } + return UpdatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER : + UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1); + } + + private void UpdateOtherComponentBasedEnableNRPECheckBox() + { + GeneralConfigureGroupBox.Enabled = EnableNRPECheckBox.Checked; + UpdateCheckDataGridViewAvailableStatus(); + } + + private void UpdateComponentBasedConfiguration() + { + EnableNRPECheckBox.Enabled = true; + EnableNRPECheckBox.Checked = _nrpeOriginalConfig.EnableNRPE; + AllowHostsTextBox.Text = AllowHostsWithoutLocalAddress(_nrpeOriginalConfig.AllowHosts); + AllowHostsTextBox.ForeColor = AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ? + Color.FromKnownColor(KnownColor.ControlDark) : AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + DebugLogCheckBox.Checked = _nrpeOriginalConfig.Debug; + SslDebugLogCheckBox.Checked = _nrpeOriginalConfig.SslLogging; + UpdateCheckDataGridViewAvailableStatus(); + } + + private void UpdateCheckDataGridViewAvailableStatus() + { + CheckDataGridView.Enabled = EnableNRPECheckBox.Checked; + CheckDataGridView.DefaultCellStyle.BackColor = EnableNRPECheckBox.Checked ? + Color.FromKnownColor(KnownColor.Window) : Color.FromKnownColor(KnownColor.Control); + if (_isHost) { - if (!REGEX_IPV4.Match(host.Trim()).Success && - !REGEX_IPV4_CIDR.Match(host.Trim()).Success && - !REGEX_DOMAIN.Match(host.Trim()).Success) + foreach (var checkGroup in _checkGroupList) { - InvalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR; - return false; + if (EnableNRPECheckBox.Checked) + { + checkGroup.WarningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + checkGroup.CriticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + } + else + { + checkGroup.WarningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + checkGroup.CriticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + } } } - CheckDataGridView.ShowCellToolTips = false; - return true; } - private string AllowHostsWithoutLocalAddress(string allowHosts) + private bool IsNRPEConfigurationChanged() { - string UpdatedAllowHosts = ""; - string[] AllowHostArray = allowHosts.Split(','); - foreach (string allowHost in AllowHostArray) + if (_nrpeCurrentConfig.EnableNRPE != _nrpeOriginalConfig.EnableNRPE || + !_nrpeCurrentConfig.AllowHosts.Equals(_nrpeOriginalConfig.AllowHosts) || + _nrpeCurrentConfig.Debug != _nrpeOriginalConfig.Debug || + _nrpeCurrentConfig.SslLogging != _nrpeOriginalConfig.SslLogging) + { + return true; + } + foreach (KeyValuePair kvp in _nrpeCurrentConfig.CheckDict) { - if (!allowHost.Trim().Equals("127.0.0.1") && - !allowHost.Trim().Equals("::1")) + NRPEHostConfiguration.Check CurrentCheck = kvp.Value; + _nrpeOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); + if (CurrentCheck != null && OriginalCheck != null + && (!CurrentCheck.WarningThreshold.Equals(OriginalCheck.WarningThreshold) + || !CurrentCheck.CriticalThreshold.Equals(OriginalCheck.CriticalThreshold))) { - UpdatedAllowHosts += allowHost + ","; + return true; } } - return UpdatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER : - UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1); + return false; } - private void UpdateOtherComponentBasedEnableNRPECheckBox() + private void UpdateCurrentNRPEConfiguration() { - if (EnableNRPECheckBox.Checked) + _nrpeCurrentConfig = new NRPEHostConfiguration { - GeneralConfigureGroupBox.Enabled = true; - CheckDataGridView.Enabled = true; - CheckDataGridView.BackgroundColor = Color.FromKnownColor(KnownColor.Window); - CheckDataGridView.DefaultCellStyle.BackColor = Color.FromKnownColor(KnownColor.Window); - } - else + EnableNRPE = EnableNRPECheckBox.Checked, + AllowHosts = AllowHostsTextBox.Text, + Debug = DebugLogCheckBox.Checked, + SslLogging = SslDebugLogCheckBox.Checked + }; + foreach (KeyValuePair item in _checkGroupDictByName) { - GeneralConfigureGroupBox.Enabled = false; - CheckDataGridView.Enabled = false; - CheckDataGridView.BackgroundColor = Color.FromKnownColor(KnownColor.Control); - CheckDataGridView.DefaultCellStyle.BackColor = Color.FromKnownColor(KnownColor.Control); + if (item.Value.WarningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText)) + && item.Value.CriticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText))) + { + _nrpeCurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(item.Key, + item.Value.WarningThresholdCell.Value.ToString(), item.Value.CriticalThresholdCell.Value.ToString())); + } } } @@ -350,8 +452,8 @@ private void AllowHostsTextBox_GotFocus(object sender, EventArgs e) if (AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER)) { AllowHostsTextBox.Text = ""; - AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlText); } + AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlText); } private void AllowHostsTextBox_LostFocus(object sender, EventArgs e) @@ -381,7 +483,7 @@ private void CheckDataGridView_EndEdit(object sender, DataGridViewCellEventArgs 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); + _checkGroupDictByLabel.TryGetValue(CheckDataGridView.CurrentRow.Cells[0].Value.ToString(), out CheckGroup checkGroup); if (checkGroup != null) { @@ -390,6 +492,7 @@ private void CheckDataGridView_EndEdit(object sender, DataGridViewCellEventArgs else if (currentCell.ColumnIndex == CriticalThresholdColumn.Index) currentCell.Value = checkGroup.CriticalThresholdDefault; } + _nrpeOriginalConfig.CheckDict.TryGetValue(checkGroup.Name, out NRPEHostConfiguration.Check check); } } } diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.resx b/XenAdmin/SettingsPanels/NRPEEditPage.resx index 434ae8216..b8734a055 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.resx +++ b/XenAdmin/SettingsPanels/NRPEEditPage.resx @@ -118,67 +118,28 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - 1 - - True - - - - NoControl - - - - 3, 88 - - - 3, 3, 3, 8 - - - 3, 0, 0, 0 - - - 95, 17 - - - 2 - - - &Enable NRPE - - - EnableNRPECheckBox - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - NRPETableLayoutPanel - - - 0 - True + Fill NoControl + - 3, 0 + 4, 0 - 3, 0, 3, 10 + 4, 0, 4, 15 - 644, 39 + 967, 39 0 @@ -197,40 +158,79 @@ This page does not offer an overview of the NRPE configuration and metric thresh NRPETableLayoutPanel - 1 + 0 - + True - + Fill - - 3, 49 + + NoControl + + + 4, 54 - - 3, 0, 3, 10 + + 4, 0, 4, 15 - - 644, 26 + + 967, 26 - + 1 - + Nagios Remote Plugin Executor (NRPE) allows you to monitor remotely resource metrics on the servers of your pool. Use this page to review and modify the NRPE configuration and metric threshold settings used for this server. - - descLabelHost + + DescLabelHost - + XenAdmin.Controls.Common.AutoHeightLabel, [XenCenter], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - + NRPETableLayoutPanel - + + 1 + + + True + + + NoControl + + + 4, 99 + + + 4, 4, 4, 12 + + + 4, 0, 0, 0 + + + 103, 21 + + + 2 + + + &Enable NRPE + + + EnableNRPECheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + 2 @@ -252,7 +252,10 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 3, 6 + 4, 7 + + + 4, 0, 4, 0 96, 13 @@ -279,10 +282,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s Left, Right - 105, 3 + 108, 4 + + + 4, 4, 4, 4 - 530, 20 + 847, 20 1 @@ -306,13 +312,16 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 3, 29 + 4, 32 + + + 4, 4, 4, 4 - 3, 0, 0, 0 + 4, 0, 0, 0 - 211, 17 + 219, 21 2 @@ -339,13 +348,16 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 3, 52 + 4, 61 + + + 4, 4, 4, 4 - 3, 0, 0, 0 + 4, 0, 0, 0 - 181, 17 + 189, 21 3 @@ -369,13 +381,16 @@ Use this page to review and modify the NRPE configuration and metric threshold s Top - 3, 16 + 4, 17 + + + 4, 4, 4, 4 3 - 638, 72 + 959, 86 0 @@ -393,22 +408,22 @@ Use this page to review and modify the NRPE configuration and metric threshold s 0 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="AllowHostsLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="AllowHostsTextBox" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="DebugLogCheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="SslDebugLogCheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="2" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,Absolute,20" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="AllowHostsLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="AllowHostsTextBox" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="DebugLogCheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="SslDebugLogCheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="2" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,Absolute,30" /></TableLayoutSettings> Fill - 3, 116 + 4, 136 - 3, 3, 3, 10 + 4, 4, 4, 15 - 3, 3, 3, 0 + 4, 4, 4, 0 - 644, 100 + 967, 150 3 @@ -428,6 +443,9 @@ Use this page to review and modify the NRPE configuration and metric threshold s 3 + + 34 + Metric @@ -456,10 +474,16 @@ Use this page to review and modify the NRPE configuration and metric threshold s Fill - 3, 229 + 4, 305 + + + 4, 4, 4, 4 + + + 62 - 644, 305 + 967, 450 4 @@ -476,6 +500,96 @@ Use this page to review and modify the NRPE configuration and metric threshold s 4 + + True + + + 2 + + + Top, Bottom, Left, Right + + + NoControl + + + 35, 0 + + + 4, 0, 4, 0 + + + 930, 31 + + + 5 + + + Retrieving NRPE configuration... + + + MiddleLeft + + + RetrieveNRPELabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + RetrieveNRPEPanel + + + 0 + + + 3, 3 + + + 25, 25 + + + 6 + + + RetrieveNRPEPicture + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + RetrieveNRPEPanel + + + 1 + + + 3, 762 + + + 1 + + + 969, 31 + + + 6 + + + RetrieveNRPEPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 5 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="RetrieveNRPELabel" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="RetrieveNRPEPicture" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="Percent,100" /></TableLayoutSettings> + Fill @@ -483,13 +597,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s 0, 0 - 3, 10, 3, 3 + 4, 15, 4, 0 - 5 + 7 - 650, 537 + 975, 806 0 @@ -507,19 +621,22 @@ Use this page to review and modify the NRPE configuration and metric threshold s 0 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="EnableNRPECheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="DescLabelPool" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="descLabelHost" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="GeneralConfigureGroupBox" Row="3" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="CheckDataGridView" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Percent,100" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="DescLabelPool" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="DescLabelHost" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="EnableNRPECheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="GeneralConfigureGroupBox" Row="3" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="CheckDataGridView" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="RetrieveNRPEPanel" Row="5" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Percent,100,AutoSize,0,Absolute,10" /></TableLayoutSettings> True - 96, 96 + 144, 144 True + + 4, 4, 4, 4 + - 650, 537 + 975, 806 CheckColumn diff --git a/XenAdmin/XenAdmin.csproj b/XenAdmin/XenAdmin.csproj index 3930e9eef..2c2420e00 100755 --- a/XenAdmin/XenAdmin.csproj +++ b/XenAdmin/XenAdmin.csproj @@ -483,9 +483,6 @@ NRPEEditPage.cs - - UserControl - UserControl diff --git a/XenModel/Actions/NRPE/CheckGroup.cs b/XenModel/Actions/NRPE/CheckGroup.cs new file mode 100644 index 000000000..3b23469d9 --- /dev/null +++ b/XenModel/Actions/NRPE/CheckGroup.cs @@ -0,0 +1,267 @@ +/* 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.Actions.NRPE +{ + 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.01M; + private readonly decimal THRESHOLD_MAXIMUM = 100M; + + private string name; + private string warningThresholdDefault; + private string criticalThresholdDefault; + private bool changed; + + 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 bool Changed { get => changed; set => changed = 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 = ""; + + if (IsEmptyForPool()) + { + return true; + } + + if (CheckEachValue(warningThresholdCell) && + CheckEachValue(criticalThresholdCell) && + CompareWarningAndCritical() && + CheckModifyAllForPool()) + { + return true; + } + return false; + } + + private bool IsEmptyForPool() + { + return warningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark)) + && criticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark)); + } + + 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; + } + } + + 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) + { + } + + 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) + { + 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 = ""; + return true; + } + } +} diff --git a/XenModel/Actions/NRPE/NRPEHostConfiguration.cs b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs index 7f1e62098..ea250c385 100644 --- a/XenModel/Actions/NRPE/NRPEHostConfiguration.cs +++ b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs @@ -30,6 +30,7 @@ using System; using System.Collections.Generic; +using XenAPI; namespace XenAdmin.Actions.NRPE { @@ -48,12 +49,12 @@ public class NRPEHostConfiguration : ICloneable public const string DEBUG_ENABLE = "1"; public const string DEBUG_DISABLE = "0"; - public const string SSL_LOGGING_ENABLE = "0xff"; + public const string SSL_LOGGING_ENABLE = "0x2f"; public const string SSL_LOGGING_DISABLE = "0x00"; public static readonly string ALLOW_HOSTS_PLACE_HOLDER = Messages.NRPE_ALLOW_HOSTS_PLACE_HOLDER; - private readonly Dictionary checkDict = new Dictionary(); + private Dictionary _checkDict = new Dictionary(); public bool EnableNRPE { get; set; } @@ -63,7 +64,17 @@ public class NRPEHostConfiguration : ICloneable public bool SslLogging { get; set; } - public Dictionary CheckDict => checkDict; + public Dictionary CheckDict => _checkDict; + + public RetrieveNRPEStatus Status { get; set; } + + public enum RetrieveNRPEStatus + { + Retrieving, + Successful, + Failed, + Unsupport + } public class Check { @@ -82,12 +93,12 @@ public Check(string name, string warningThreshold, string criticalThreshold) public void AddNRPECheck(Check checkItem) { - checkDict.Add(checkItem.Name, checkItem); + _checkDict.Add(checkItem.Name, checkItem); } public bool GetNRPECheck(string name, out Check check) { - return checkDict.TryGetValue(name, out check); + return _checkDict.TryGetValue(name, out check); } public object Clone() @@ -99,6 +110,12 @@ public object Clone() Debug = Debug, SslLogging = SslLogging }; + foreach (KeyValuePair kvp in _checkDict) + { + NRPEHostConfiguration.Check CurrentCheck = kvp.Value; + cloned.AddNRPECheck(new Check(CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold)); + } + return cloned; } } diff --git a/XenModel/Actions/NRPE/NRPERetrieveAction.cs b/XenModel/Actions/NRPE/NRPERetrieveAction.cs new file mode 100644 index 000000000..9c9b287aa --- /dev/null +++ b/XenModel/Actions/NRPE/NRPERetrieveAction.cs @@ -0,0 +1,163 @@ +/* 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.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Threading; +using XenAPI; + + +namespace XenAdmin.Actions.NRPE +{ + public class NRPERetrieveAction : AsyncAction + { + private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + private readonly NRPEHostConfiguration _nrpeCurrentConfig; + private readonly Dictionary _checkGroupDictByName; + + private readonly IXenObject _clone; + + public NRPERetrieveAction(IXenObject host, NRPEHostConfiguration nrpeHostConfiguration, Dictionary checkGroupDictByName, bool suppressHistory) + : base(host.Connection, Messages.NRPE_ACTION_RETRIEVING, Messages.NRPE_ACTION_RETRIEVING, suppressHistory) + { + _clone = host; + _nrpeCurrentConfig = nrpeHostConfiguration; + _checkGroupDictByName = checkGroupDictByName; + } + + protected override void Run() + { + _nrpeCurrentConfig.Status = NRPEHostConfiguration.RetrieveNRPEStatus.Successful; + if (_clone is Pool p) + { + List hostList = p.Connection.Cache.Hosts.ToList(); + Host checkHost = hostList[0]; + try + { + Host.call_plugin(checkHost.Connection.Session, checkHost.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, null); + } + catch (Exception e) + { + log.ErrorFormat("Execute NRPE plugin failed, failed reason: {0}.", e.Message); + _nrpeCurrentConfig.Status = e.Message.Contains("UNKNOWN_XENAPI_PLUGIN_FUNCTION") ? + NRPEHostConfiguration.RetrieveNRPEStatus.Unsupport : NRPEHostConfiguration.RetrieveNRPEStatus.Failed; + } + } + else + { + try + { + InitNRPEGeneralConfiguration(); + InitNRPEThreshold(); + } + catch (Exception e) + { + log.ErrorFormat("Execute NRPE plugin failed, failed reason: {0}.", e.Message); + _nrpeCurrentConfig.Status = e.Message.Contains("UNKNOWN_XENAPI_PLUGIN_FUNCTION") ? + NRPEHostConfiguration.RetrieveNRPEStatus.Unsupport : NRPEHostConfiguration.RetrieveNRPEStatus.Failed; + } + } + } + + private void InitNRPEGeneralConfiguration() + { + string status = Host.call_plugin(_clone.Connection.Session, _clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_STATUS, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_STATUS, status); + _nrpeCurrentConfig.EnableNRPE = status.Trim().Equals("active enabled"); + + string nrpeConfig = Host.call_plugin(_clone.Connection.Session, _clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, nrpeConfig); + + string[] nrpeConfigArray = nrpeConfig.Split('\n'); + foreach (string nrpeConfigItem in nrpeConfigArray) + { + if (nrpeConfigItem.Trim().StartsWith("allowed_hosts:")) + { + string allowHosts = nrpeConfigItem.Replace("allowed_hosts:", "").Trim(); + _nrpeCurrentConfig.AllowHosts = AllowHostsWithoutLocalAddress(allowHosts); + } + else if (nrpeConfigItem.Trim().StartsWith("debug:")) + { + string enableDebug = nrpeConfigItem.Replace("debug:", "").Trim(); + _nrpeCurrentConfig.Debug = enableDebug.Equals(NRPEHostConfiguration.DEBUG_ENABLE); + } + else if (nrpeConfigItem.Trim().StartsWith("ssl_logging:")) + { + string enableSslLogging = nrpeConfigItem.Replace("ssl_logging:", "").Trim(); + _nrpeCurrentConfig.SslLogging = enableSslLogging.Equals(NRPEHostConfiguration.SSL_LOGGING_ENABLE); + } + } + } + + private void InitNRPEThreshold() + { + string nrpeThreshold = Host.call_plugin(_clone.Connection.Session, _clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, nrpeThreshold); + + string[] nrpeThresholdArray = nrpeThreshold.Split('\n'); + foreach (string nrpeThresholdItem in nrpeThresholdArray) + { + // Return string format for each line: check_cpu warning threshold - 50 critical threshold - 80 + string[] thresholdRtnArray = nrpeThresholdItem.Split(' '); + string checkName = thresholdRtnArray[0]; + if (_checkGroupDictByName.TryGetValue(thresholdRtnArray[0], out CheckGroup thresholdCheck)) + { + string warningThreshold = thresholdRtnArray[4]; + string criticalThreshold = thresholdRtnArray[8]; + thresholdCheck.UpdateThreshold(warningThreshold, criticalThreshold); + _nrpeCurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(checkName, warningThreshold, criticalThreshold)); + } + } + } + + private string AllowHostsWithoutLocalAddress(string allowHosts) + { + string UpdatedAllowHosts = ""; + string[] AllowHostArray = allowHosts.Split(','); + foreach (string allowHost in AllowHostArray) + { + if (!allowHost.Trim().Equals("127.0.0.1") && + !allowHost.Trim().Equals("::1")) + { + UpdatedAllowHosts += allowHost + ","; + } + } + return UpdatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER : + UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1); + } + } +} diff --git a/XenModel/Actions/NRPE/NRPEUpdateAction.cs b/XenModel/Actions/NRPE/NRPEUpdateAction.cs index 05cb749db..f323b0243 100644 --- a/XenModel/Actions/NRPE/NRPEUpdateAction.cs +++ b/XenModel/Actions/NRPE/NRPEUpdateAction.cs @@ -39,22 +39,22 @@ public class NRPEUpdateAction : AsyncAction { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private readonly NRPEHostConfiguration NRPEOriginalConfig; // NRPE configuration fetched from host - private readonly NRPEHostConfiguration NRPEHostConfiguration; // NRPE configuration after user modified + private readonly NRPEHostConfiguration _nrpeOriginalConfig; // NRPE configuration fetched from host + private readonly NRPEHostConfiguration _nrpeHostConfiguration; // NRPE configuration after user modified - private readonly IXenObject Clone; + private readonly IXenObject _clone; public NRPEUpdateAction(IXenObject host, NRPEHostConfiguration nrpeHostConfiguration, NRPEHostConfiguration nrpeOriginalConfig, bool suppressHistory) - : base(host.Connection, Messages.ACTION_CHANGE_POWER_ON, Messages.NRPE_ACTION_CHANGING, suppressHistory) + : base(host.Connection, Messages.NRPE_ACTION_CHANGING, Messages.NRPE_ACTION_CHANGING, suppressHistory) { - Clone = host; - NRPEHostConfiguration = nrpeHostConfiguration; - NRPEOriginalConfig = nrpeOriginalConfig; + _clone = host; + _nrpeHostConfiguration = nrpeHostConfiguration; + _nrpeOriginalConfig = nrpeOriginalConfig; } protected override void Run() { - if (Clone is Host) + if (_clone is Host) { SetNRPEConfigureForHost(); } @@ -67,43 +67,43 @@ protected override void Run() private void SetNRPEConfigureForHost() { // Enable/Disable NRPE - if (!NRPEHostConfiguration.EnableNRPE == NRPEOriginalConfig.EnableNRPE) + if (!_nrpeHostConfiguration.EnableNRPE == _nrpeOriginalConfig.EnableNRPE) { - SetNRPEStatus(Clone, NRPEHostConfiguration.EnableNRPE); + SetNRPEStatus(_clone, _nrpeHostConfiguration.EnableNRPE); } - if (!NRPEHostConfiguration.EnableNRPE) // If disable, return + if (!_nrpeHostConfiguration.EnableNRPE) // If disable, return { return; } // NRPE General Configuration - if (!NRPEHostConfiguration.AllowHosts.Equals(NRPEOriginalConfig.AllowHosts) - || !NRPEHostConfiguration.Debug.Equals(NRPEOriginalConfig.Debug) - || !NRPEHostConfiguration.SslLogging.Equals(NRPEOriginalConfig.SslLogging)) + if (!_nrpeHostConfiguration.AllowHosts.Equals(_nrpeOriginalConfig.AllowHosts) + || !_nrpeHostConfiguration.Debug.Equals(_nrpeOriginalConfig.Debug) + || !_nrpeHostConfiguration.SslLogging.Equals(_nrpeOriginalConfig.SslLogging)) { - SetNRPEGeneralConfiguration(Clone, NRPEHostConfiguration.AllowHosts, NRPEHostConfiguration.Debug, NRPEHostConfiguration.SslLogging); + SetNRPEGeneralConfiguration(_clone, _nrpeHostConfiguration.AllowHosts, _nrpeHostConfiguration.Debug, _nrpeHostConfiguration.SslLogging); } // NRPE Check Threshold - foreach (KeyValuePair kvp in NRPEHostConfiguration.CheckDict) + foreach (KeyValuePair kvp in _nrpeHostConfiguration.CheckDict) { NRPEHostConfiguration.Check CurrentCheck = kvp.Value; - NRPEOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); + _nrpeOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); if (CurrentCheck != null && OriginalCheck != null && (!CurrentCheck.WarningThreshold.Equals(OriginalCheck.WarningThreshold) || !CurrentCheck.CriticalThreshold.Equals(OriginalCheck.CriticalThreshold))) { - SetNRPEThreshold(Clone, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold); + SetNRPEThreshold(_clone, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold); } } - RestartNRPE(Clone); + RestartNRPE(_clone); } private void SetNRPEConfigureForPool() { List hostList = null; - if (Clone is Pool p) + if (_clone is Pool p) { hostList = p.Connection.Cache.Hosts.ToList(); } @@ -111,20 +111,20 @@ private void SetNRPEConfigureForPool() hostList.ForEach(host => { // Enable/Disable NRPE - SetNRPEStatus(host, NRPEHostConfiguration.EnableNRPE); - if (!NRPEHostConfiguration.EnableNRPE) // If disable, return + SetNRPEStatus(host, _nrpeHostConfiguration.EnableNRPE); + if (!_nrpeHostConfiguration.EnableNRPE) // If disable, return { return; } // NRPE General Configuration - SetNRPEGeneralConfiguration(host, NRPEHostConfiguration.AllowHosts, NRPEHostConfiguration.Debug, NRPEHostConfiguration.SslLogging); + SetNRPEGeneralConfiguration(host, _nrpeHostConfiguration.AllowHosts, _nrpeHostConfiguration.Debug, _nrpeHostConfiguration.SslLogging); // NRPE Check Threshold - foreach (KeyValuePair kvp in NRPEHostConfiguration.CheckDict) + foreach (KeyValuePair kvp in _nrpeHostConfiguration.CheckDict) { NRPEHostConfiguration.Check CurrentCheck = kvp.Value; - NRPEOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); + _nrpeOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); if (CurrentCheck != null) { SetNRPEThreshold(host, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold); @@ -156,9 +156,9 @@ private void SetNRPEGeneralConfiguration(IXenObject host, string allowHosts, boo NRPEHostConfiguration.XAPI_NRPE_SET_CONFIG, ConfigArgDict); log.InfoFormat("Execute nrpe {0}, allowed_hosts={1}, debug={2}, ssl_logging={3}, return: {4}", NRPEHostConfiguration.XAPI_NRPE_SET_CONFIG, - NRPEHostConfiguration.AllowHosts, - NRPEHostConfiguration.Debug, - NRPEHostConfiguration.SslLogging, + _nrpeHostConfiguration.AllowHosts, + _nrpeHostConfiguration.Debug, + _nrpeHostConfiguration.SslLogging, result); } diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index e387c153d..92325ebca 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -29088,7 +29088,7 @@ public static string NRPE { } /// - /// Looks up a localized string similar to Changing NRPE configuration.... + /// Looks up a localized string similar to Changing NRPE configuration. /// public static string NRPE_ACTION_CHANGING { get { @@ -29096,6 +29096,15 @@ public static string NRPE_ACTION_CHANGING { } } + /// + /// Looks up a localized string similar to Retrieving NRPE configuration. + /// + public static string NRPE_ACTION_RETRIEVING { + get { + return ResourceManager.GetString("NRPE_ACTION_RETRIEVING", resourceCulture); + } + } + /// /// Looks up a localized string similar to NRPE service is active. /// @@ -29141,6 +29150,15 @@ public static string NRPE_ALLOW_HOSTS_PLACE_HOLDER { } } + /// + /// Looks up a localized string similar to Please remove duplicated address. + /// + public static string NRPE_ALLOW_HOSTS_SAME_ADDRESS { + get { + return ResourceManager.GetString("NRPE_ALLOW_HOSTS_SAME_ADDRESS", resourceCulture); + } + } + /// /// Looks up a localized string similar to NRPE batch configuration. /// @@ -29267,6 +29285,24 @@ public static string NRPE_INACTIVE { } } + /// + /// Looks up a localized string similar to Retrieve NRPE configuration failed, please check XenCenter logs.. + /// + public static string NRPE_RETRIEVE_FAILED { + get { + return ResourceManager.GetString("NRPE_RETRIEVE_FAILED", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Retrieving NRPE configuration.... + /// + public static string NRPE_RETRIEVING_CONFIGURATION { + get { + return ResourceManager.GetString("NRPE_RETRIEVING_CONFIGURATION", resourceCulture); + } + } + /// /// Looks up a localized string similar to Threshold value should range from {0} to {1}.. /// @@ -29321,6 +29357,15 @@ public static string NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL { } } + /// + /// Looks up a localized string similar to Unsupport NRPE, please upgrade your XenServer version.. + /// + public static string NRPE_UNSUPPORT { + get { + return ResourceManager.GetString("NRPE_UNSUPPORT", resourceCulture); + } + } + /// /// Looks up a localized string similar to Number of snapshots to keep. /// diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index b4418b67c..6e390e156 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -10096,7 +10096,10 @@ When you configure an NFS storage repository, you simply provide the host name o NRPE - Changing NRPE configuration... + Changing NRPE configuration + + + Retrieving NRPE configuration NRPE service is active @@ -10113,6 +10116,9 @@ When you configure an NFS storage repository, you simply provide the host name o Comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com + + Please remove duplicated address + NRPE batch configuration @@ -10155,6 +10161,12 @@ When you configure an NFS storage repository, you simply provide the host name o NRPE service is inactive + + Retrieve NRPE configuration failed, please check XenCenter logs. + + + Retrieving NRPE configuration... + Threshold value should range from {0} to {1}. @@ -10173,6 +10185,9 @@ When you configure an NFS storage repository, you simply provide the host name o Warning threshold should be less than critical threshold. + + Unsupport NRPE, please upgrade your XenServer version. + Number of snapshots to keep @@ -15137,7 +15152,7 @@ Any disk in your VM's DVD drive will be ejected when installing {1}. Normal - + {0} recommends that you synchronize the selected pool(s) or standalone host(s) with the specified update channel as soon as possible to retrieve the latest available updates. diff --git a/XenModel/XenModel.csproj b/XenModel/XenModel.csproj index 2850c5ca4..117ab7806 100755 --- a/XenModel/XenModel.csproj +++ b/XenModel/XenModel.csproj @@ -57,6 +57,7 @@ + @@ -88,6 +89,8 @@ + + From 02988d1fbfcc5324ceac484790dd0bbe7c74bfe5 Mon Sep 17 00:00:00 2001 From: Bengang Yuan Date: Thu, 12 Oct 2023 22:24:35 +0800 Subject: [PATCH 06/10] For pool, add a CheckBox for decide if to sync the NRPE configuration to all hosts. --- XenAdmin/Properties/AssemblyInfo.cs | 6 +- .../SettingsPanels/NRPEEditPage.Designer.cs | 90 +++---- XenAdmin/SettingsPanels/NRPEEditPage.cs | 219 ++++++++++-------- XenAdmin/SettingsPanels/NRPEEditPage.resx | 163 +++++++------ XenAdmin/XenAdmin.csproj | 4 +- 5 files changed, 265 insertions(+), 217 deletions(-) diff --git a/XenAdmin/Properties/AssemblyInfo.cs b/XenAdmin/Properties/AssemblyInfo.cs index 0b3ce0218..1e24ef8a4 100644 --- a/XenAdmin/Properties/AssemblyInfo.cs +++ b/XenAdmin/Properties/AssemblyInfo.cs @@ -35,10 +35,10 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("[XenCenter]")] -[assembly: AssemblyDescription("[XenCenter]")] +[assembly: AssemblyTitle("XenCenter")] +[assembly: AssemblyDescription("XenCenter")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyProduct("[XenCenter]")] +[assembly: AssemblyProduct("XenCenter")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs index a3fcc3103..6c41c0255 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs @@ -30,8 +30,7 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NRPEEditPage)); this.NRPETableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); - this.DescLabelPool = new XenAdmin.Controls.Common.AutoHeightLabel(); - this.DescLabelHost = new XenAdmin.Controls.Common.AutoHeightLabel(); + this.BatchConfigurationCheckBox = new System.Windows.Forms.CheckBox(); this.EnableNRPECheckBox = new System.Windows.Forms.CheckBox(); this.GeneralConfigureGroupBox = new System.Windows.Forms.GroupBox(); this.GeneralConfigTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); @@ -39,19 +38,21 @@ private void InitializeComponent() this.AllowHostsTextBox = new System.Windows.Forms.TextBox(); this.DebugLogCheckBox = new System.Windows.Forms.CheckBox(); this.SslDebugLogCheckBox = new System.Windows.Forms.CheckBox(); + this.RetrieveNRPEPanel = new System.Windows.Forms.TableLayoutPanel(); + this.RetrieveNRPELabel = new System.Windows.Forms.Label(); + this.RetrieveNRPEPicture = new System.Windows.Forms.PictureBox(); + this.DescLabelPool = new XenAdmin.Controls.Common.AutoHeightLabel(); + this.DescLabelHost = new XenAdmin.Controls.Common.AutoHeightLabel(); this.CheckDataGridView = new XenAdmin.Controls.DataGridViewEx.DataGridViewEx(); this.CheckColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.WarningThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.CriticalThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.RetrieveNRPEPanel = new System.Windows.Forms.TableLayoutPanel(); - this.RetrieveNRPELabel = new System.Windows.Forms.Label(); - this.RetrieveNRPEPicture = new System.Windows.Forms.PictureBox(); this.NRPETableLayoutPanel.SuspendLayout(); this.GeneralConfigureGroupBox.SuspendLayout(); this.GeneralConfigTableLayoutPanel.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).BeginInit(); this.RetrieveNRPEPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.RetrieveNRPEPicture)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).BeginInit(); this.SuspendLayout(); // // NRPETableLayoutPanel @@ -59,21 +60,19 @@ private void InitializeComponent() resources.ApplyResources(this.NRPETableLayoutPanel, "NRPETableLayoutPanel"); this.NRPETableLayoutPanel.Controls.Add(this.DescLabelPool, 0, 0); this.NRPETableLayoutPanel.Controls.Add(this.DescLabelHost, 0, 1); - this.NRPETableLayoutPanel.Controls.Add(this.EnableNRPECheckBox, 0, 2); - this.NRPETableLayoutPanel.Controls.Add(this.GeneralConfigureGroupBox, 0, 3); - this.NRPETableLayoutPanel.Controls.Add(this.CheckDataGridView, 0, 4); - this.NRPETableLayoutPanel.Controls.Add(this.RetrieveNRPEPanel, 0, 5); + this.NRPETableLayoutPanel.Controls.Add(this.BatchConfigurationCheckBox, 0, 2); + this.NRPETableLayoutPanel.Controls.Add(this.EnableNRPECheckBox, 0, 3); + this.NRPETableLayoutPanel.Controls.Add(this.GeneralConfigureGroupBox, 0, 4); + this.NRPETableLayoutPanel.Controls.Add(this.CheckDataGridView, 0, 5); + this.NRPETableLayoutPanel.Controls.Add(this.RetrieveNRPEPanel, 0, 6); this.NRPETableLayoutPanel.Name = "NRPETableLayoutPanel"; // - // DescLabelPool - // - resources.ApplyResources(this.DescLabelPool, "DescLabelPool"); - this.DescLabelPool.Name = "DescLabelPool"; - // - // DescLabelHost + // BatchConfigurationCheckBox // - resources.ApplyResources(this.DescLabelHost, "DescLabelHost"); - this.DescLabelHost.Name = "DescLabelHost"; + resources.ApplyResources(this.BatchConfigurationCheckBox, "BatchConfigurationCheckBox"); + this.BatchConfigurationCheckBox.Name = "BatchConfigurationCheckBox"; + this.BatchConfigurationCheckBox.UseVisualStyleBackColor = true; + this.BatchConfigurationCheckBox.CheckedChanged += new System.EventHandler(this.BatchConfigurationCheckBox_CheckedChanged); // // EnableNRPECheckBox // @@ -122,6 +121,34 @@ private void InitializeComponent() this.SslDebugLogCheckBox.Name = "SslDebugLogCheckBox"; this.SslDebugLogCheckBox.UseVisualStyleBackColor = true; // + // RetrieveNRPEPanel + // + resources.ApplyResources(this.RetrieveNRPEPanel, "RetrieveNRPEPanel"); + this.RetrieveNRPEPanel.Controls.Add(this.RetrieveNRPELabel, 1, 0); + this.RetrieveNRPEPanel.Controls.Add(this.RetrieveNRPEPicture, 0, 0); + this.RetrieveNRPEPanel.Name = "RetrieveNRPEPanel"; + // + // RetrieveNRPELabel + // + resources.ApplyResources(this.RetrieveNRPELabel, "RetrieveNRPELabel"); + this.RetrieveNRPELabel.Name = "RetrieveNRPELabel"; + // + // RetrieveNRPEPicture + // + resources.ApplyResources(this.RetrieveNRPEPicture, "RetrieveNRPEPicture"); + this.RetrieveNRPEPicture.Name = "RetrieveNRPEPicture"; + this.RetrieveNRPEPicture.TabStop = false; + // + // DescLabelPool + // + resources.ApplyResources(this.DescLabelPool, "DescLabelPool"); + this.DescLabelPool.Name = "DescLabelPool"; + // + // DescLabelHost + // + resources.ApplyResources(this.DescLabelHost, "DescLabelHost"); + this.DescLabelHost.Name = "DescLabelHost"; + // // CheckDataGridView // this.CheckDataGridView.BackgroundColor = System.Drawing.SystemColors.Window; @@ -141,41 +168,23 @@ private void InitializeComponent() // // CheckColumn // - this.CheckColumn.FillWeight = 40F; + this.CheckColumn.FillWeight = 15.57632F; resources.ApplyResources(this.CheckColumn, "CheckColumn"); this.CheckColumn.Name = "CheckColumn"; this.CheckColumn.ReadOnly = true; // // WarningThresholdColumn // - this.WarningThresholdColumn.FillWeight = 30F; + this.WarningThresholdColumn.FillWeight = 42.21184F; resources.ApplyResources(this.WarningThresholdColumn, "WarningThresholdColumn"); this.WarningThresholdColumn.Name = "WarningThresholdColumn"; // // CriticalThresholdColumn // - this.CriticalThresholdColumn.FillWeight = 30F; + this.CriticalThresholdColumn.FillWeight = 42.21184F; resources.ApplyResources(this.CriticalThresholdColumn, "CriticalThresholdColumn"); this.CriticalThresholdColumn.Name = "CriticalThresholdColumn"; // - // RetrieveNRPEPanel - // - resources.ApplyResources(this.RetrieveNRPEPanel, "RetrieveNRPEPanel"); - this.RetrieveNRPEPanel.Controls.Add(this.RetrieveNRPELabel, 1, 0); - this.RetrieveNRPEPanel.Controls.Add(this.RetrieveNRPEPicture, 0, 0); - this.RetrieveNRPEPanel.Name = "RetrieveNRPEPanel"; - // - // RetrieveNRPELabel - // - resources.ApplyResources(this.RetrieveNRPELabel, "RetrieveNRPELabel"); - this.RetrieveNRPELabel.Name = "RetrieveNRPELabel"; - // - // RetrieveNRPEPicture - // - resources.ApplyResources(this.RetrieveNRPEPicture, "RetrieveNRPEPicture"); - this.RetrieveNRPEPicture.Name = "RetrieveNRPEPicture"; - this.RetrieveNRPEPicture.TabStop = false; - // // NRPEEditPage // resources.ApplyResources(this, "$this"); @@ -188,9 +197,9 @@ private void InitializeComponent() this.GeneralConfigureGroupBox.PerformLayout(); this.GeneralConfigTableLayoutPanel.ResumeLayout(false); this.GeneralConfigTableLayoutPanel.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).EndInit(); this.RetrieveNRPEPanel.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.RetrieveNRPEPicture)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).EndInit(); this.ResumeLayout(false); } @@ -213,6 +222,7 @@ private void InitializeComponent() private System.Windows.Forms.Label RetrieveNRPELabel; private System.Windows.Forms.TableLayoutPanel RetrieveNRPEPanel; private System.Windows.Forms.PictureBox RetrieveNRPEPicture; + private System.Windows.Forms.CheckBox BatchConfigurationCheckBox; } } \ No newline at end of file diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.cs b/XenAdmin/SettingsPanels/NRPEEditPage.cs index 819366428..191ab0f6f 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -96,6 +96,7 @@ public NRPEEditPage() _checkGroupDictByLabel.Add(checkGroup.NameCell.Value.ToString(), checkGroup); } + AllowHostsTextBox.Text = NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER; AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); AllowHostsTextBox.GotFocus += AllowHostsTextBox_GotFocus; AllowHostsTextBox.LostFocus += AllowHostsTextBox_LostFocus; @@ -158,15 +159,13 @@ public bool HasChanged { get { - UpdateCurrentNRPEConfiguration(); - if (_isHost) - { - return IsNRPEConfigurationChanged(); - } - else + if (_isHost && IsNRPEConfigurationChanged() || + !_isHost && BatchConfigurationCheckBox.Checked) { + UpdateCurrentNRPEConfiguration(); return true; } + return false; } } @@ -235,6 +234,7 @@ public void SetXenObjects(IXenObject orig, IXenObject clone) DescLabelHost.Visible = _isHost; DescLabelPool.Visible = !_isHost; + BatchConfigurationCheckBox.Visible = !_isHost; UpdateRetrievingNRPETip(NRPEHostConfiguration.RetrieveNRPEStatus.Retrieving); DisableAllComponent(); @@ -252,10 +252,16 @@ private void UpdateRetrieveStatus() { if (_nrpeOriginalConfig.Status == NRPEHostConfiguration.RetrieveNRPEStatus.Successful) { - AllowHostsTextBox.ForeColor = AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ? - Color.FromKnownColor(KnownColor.ControlDark) : Color.FromKnownColor(KnownColor.ControlText); - UpdateOtherComponentBasedEnableNRPECheckBox(); - UpdateComponentBasedConfiguration(); + if (_isHost) + { + EnableNRPECheckBox.Enabled = true; + UpdateComponentValueBasedConfiguration(); + UpdateComponentStatusBasedEnableNRPECheckBox(); + } + else + { + BatchConfigurationCheckBox.Enabled = true; + } } UpdateRetrievingNRPETip(_nrpeOriginalConfig.Status); } @@ -291,96 +297,40 @@ private void UpdateRetrievingNRPETip(NRPEHostConfiguration.RetrieveNRPEStatus st private void DisableAllComponent() { - EnableNRPECheckBox.Enabled = false; - GeneralConfigureGroupBox.Enabled = false; - CheckDataGridView.Enabled = false; - } - - private bool IsAllowHostsValid() - { - _invalidParamToolTip.ToolTipTitle = Messages.NRPE_ALLOW_HOSTS_ERROR_TITLE; - _invalidParamToolTip.Tag = AllowHostsTextBox; - CheckDataGridView.ShowCellToolTips = true; - - string str = AllowHostsTextBox.Text; - if (str.Trim().Length == 0 || str.Trim().Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER)) - { - _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_EMPTY_ERROR; - return false; - } - - string[] hostArray = str.Split(','); - for ( int i = 0; i < hostArray.Length; i++ ) - { - if (!REGEX_IPV4.Match(hostArray[i].Trim()).Success && - !REGEX_IPV4_CIDR.Match(hostArray[i].Trim()).Success && - !REGEX_DOMAIN.Match(hostArray[i].Trim()).Success) - { - _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR; - return false; - } - for ( int j = 0; j < i; j++ ) - { - if (hostArray[i].Trim().Equals(hostArray[j].Trim())) - { - _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_SAME_ADDRESS; - return false; - } - } - } - foreach (string host in hostArray) - { - if (!REGEX_IPV4.Match(host.Trim()).Success && - !REGEX_IPV4_CIDR.Match(host.Trim()).Success && - !REGEX_DOMAIN.Match(host.Trim()).Success) - { - _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR; - return false; - } - } - CheckDataGridView.ShowCellToolTips = false; - return true; - } - - private string AllowHostsWithoutLocalAddress(string allowHosts) - { - string UpdatedAllowHosts = ""; - string[] AllowHostArray = allowHosts.Split(','); - foreach (string allowHost in AllowHostArray) - { - if (!allowHost.Trim().Equals("127.0.0.1") && - !allowHost.Trim().Equals("::1")) - { - UpdatedAllowHosts += allowHost + ","; - } - } - return UpdatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER : - UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1); - } - - private void UpdateOtherComponentBasedEnableNRPECheckBox() - { - GeneralConfigureGroupBox.Enabled = EnableNRPECheckBox.Checked; - UpdateCheckDataGridViewAvailableStatus(); - } - - private void UpdateComponentBasedConfiguration() - { - EnableNRPECheckBox.Enabled = true; - EnableNRPECheckBox.Checked = _nrpeOriginalConfig.EnableNRPE; - AllowHostsTextBox.Text = AllowHostsWithoutLocalAddress(_nrpeOriginalConfig.AllowHosts); - AllowHostsTextBox.ForeColor = AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ? - Color.FromKnownColor(KnownColor.ControlDark) : AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlText); - DebugLogCheckBox.Checked = _nrpeOriginalConfig.Debug; - SslDebugLogCheckBox.Checked = _nrpeOriginalConfig.SslLogging; - UpdateCheckDataGridViewAvailableStatus(); - } - - private void UpdateCheckDataGridViewAvailableStatus() - { - CheckDataGridView.Enabled = EnableNRPECheckBox.Checked; - CheckDataGridView.DefaultCellStyle.BackColor = EnableNRPECheckBox.Checked ? - Color.FromKnownColor(KnownColor.Window) : Color.FromKnownColor(KnownColor.Control); + EnableNRPECheckBox.Enabled = false; + GeneralConfigureGroupBox.Enabled = false; + CheckDataGridView.Enabled = false; + } + + private void UpdateComponentValueBasedConfiguration() + { + EnableNRPECheckBox.Checked = _nrpeOriginalConfig.EnableNRPE; + AllowHostsTextBox.Text = AllowHostsWithoutLocalAddress(_nrpeOriginalConfig.AllowHosts); + AllowHostsTextBox.ForeColor = AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ? + Color.FromKnownColor(KnownColor.ControlDark) : AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + DebugLogCheckBox.Checked = _nrpeOriginalConfig.Debug; + SslDebugLogCheckBox.Checked = _nrpeOriginalConfig.SslLogging; + } + + private void UpdateComponentStatusBasedBatchConfigurationCheckBox() + { + if (BatchConfigurationCheckBox.Checked) + { + EnableNRPECheckBox.Enabled = true; + UpdateComponentStatusBasedEnableNRPECheckBox(); + } + else + { + DisableAllComponent(); + } + } + + private void UpdateComponentStatusBasedEnableNRPECheckBox() + { + GeneralConfigureGroupBox.Enabled = EnableNRPECheckBox.Checked; + CheckDataGridView.Enabled = EnableNRPECheckBox.Checked; + CheckDataGridView.DefaultCellStyle.BackColor = EnableNRPECheckBox.Checked ? + Color.FromKnownColor(KnownColor.Window) : Color.FromKnownColor(KnownColor.Control); if (_isHost) { foreach (var checkGroup in _checkGroupList) @@ -399,6 +349,68 @@ private void UpdateCheckDataGridViewAvailableStatus() } } + private bool IsAllowHostsValid() + { + _invalidParamToolTip.ToolTipTitle = Messages.NRPE_ALLOW_HOSTS_ERROR_TITLE; + _invalidParamToolTip.Tag = AllowHostsTextBox; + CheckDataGridView.ShowCellToolTips = true; + + string str = AllowHostsTextBox.Text; + if (str.Trim().Length == 0 || str.Trim().Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER)) + { + _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_EMPTY_ERROR; + return false; + } + + string[] hostArray = str.Split(','); + for ( int i = 0; i < hostArray.Length; i++ ) + { + if (!REGEX_IPV4.Match(hostArray[i].Trim()).Success && + !REGEX_IPV4_CIDR.Match(hostArray[i].Trim()).Success && + !REGEX_DOMAIN.Match(hostArray[i].Trim()).Success) + { + _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR; + return false; + } + for ( int j = 0; j < i; j++ ) + { + if (hostArray[i].Trim().Equals(hostArray[j].Trim())) + { + _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_SAME_ADDRESS; + return false; + } + } + } + foreach (string host in hostArray) + { + if (!REGEX_IPV4.Match(host.Trim()).Success && + !REGEX_IPV4_CIDR.Match(host.Trim()).Success && + !REGEX_DOMAIN.Match(host.Trim()).Success) + { + _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR; + return false; + } + } + CheckDataGridView.ShowCellToolTips = false; + return true; + } + + private string AllowHostsWithoutLocalAddress(string allowHosts) + { + string UpdatedAllowHosts = ""; + string[] AllowHostArray = allowHosts.Split(','); + foreach (string allowHost in AllowHostArray) + { + if (!allowHost.Trim().Equals("127.0.0.1") && + !allowHost.Trim().Equals("::1")) + { + UpdatedAllowHosts += allowHost + ","; + } + } + return UpdatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER : + UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1); + } + private bool IsNRPEConfigurationChanged() { if (_nrpeCurrentConfig.EnableNRPE != _nrpeOriginalConfig.EnableNRPE || @@ -442,9 +454,14 @@ private void UpdateCurrentNRPEConfiguration() } } + private void BatchConfigurationCheckBox_CheckedChanged(object sender, EventArgs e) + { + UpdateComponentStatusBasedBatchConfigurationCheckBox(); + } + private void EnableNRPECheckBox_CheckedChanged(object sender, EventArgs e) { - UpdateOtherComponentBasedEnableNRPECheckBox(); + UpdateComponentStatusBasedEnableNRPECheckBox(); } private void AllowHostsTextBox_GotFocus(object sender, EventArgs e) diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.resx b/XenAdmin/SettingsPanels/NRPEEditPage.resx index b8734a055..bfbbd26f3 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.resx +++ b/XenAdmin/SettingsPanels/NRPEEditPage.resx @@ -133,13 +133,13 @@ - 4, 0 + 3, 0 - 4, 0, 4, 15 + 3, 0, 3, 10 - 967, 39 + 644, 39 0 @@ -152,7 +152,7 @@ This page does not offer an overview of the NRPE configuration and metric thresh DescLabelPool - XenAdmin.Controls.Common.AutoHeightLabel, [XenCenter], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.Common.AutoHeightLabel, XenCenter, Version=0.0.0.9999, Culture=neutral, PublicKeyToken=null NRPETableLayoutPanel @@ -170,13 +170,13 @@ This page does not offer an overview of the NRPE configuration and metric thresh NoControl - 4, 54 + 3, 49 - 4, 0, 4, 15 + 3, 0, 3, 10 - 967, 26 + 644, 26 1 @@ -189,7 +189,7 @@ Use this page to review and modify the NRPE configuration and metric threshold s DescLabelHost - XenAdmin.Controls.Common.AutoHeightLabel, [XenCenter], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.Common.AutoHeightLabel, XenCenter, Version=0.0.0.9999, Culture=neutral, PublicKeyToken=null NRPETableLayoutPanel @@ -197,6 +197,42 @@ Use this page to review and modify the NRPE configuration and metric threshold s 1 + + True + + + NoControl + + + 3, 88 + + + 3, 3, 3, 8 + + + 3, 0, 0, 0 + + + 171, 17 + + + 7 + + + Sync &Configuration to all hosts + + + BatchConfigurationCheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 2 + True @@ -204,16 +240,16 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 4, 99 + 3, 116 - 4, 4, 4, 12 + 3, 3, 3, 8 - 4, 0, 0, 0 + 3, 0, 0, 0 - 103, 21 + 95, 17 2 @@ -231,7 +267,7 @@ Use this page to review and modify the NRPE configuration and metric threshold s NRPETableLayoutPanel - 2 + 3 True @@ -252,10 +288,7 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 4, 7 - - - 4, 0, 4, 0 + 3, 6 96, 13 @@ -282,13 +315,10 @@ Use this page to review and modify the NRPE configuration and metric threshold s Left, Right - 108, 4 - - - 4, 4, 4, 4 + 105, 3 - 847, 20 + 530, 20 1 @@ -312,16 +342,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 4, 32 - - - 4, 4, 4, 4 + 3, 29 - 4, 0, 0, 0 + 3, 0, 0, 0 - 219, 21 + 211, 17 2 @@ -348,16 +375,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 4, 61 - - - 4, 4, 4, 4 + 3, 52 - 4, 0, 0, 0 + 3, 0, 0, 0 - 189, 21 + 181, 17 3 @@ -381,16 +405,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s Top - 4, 17 - - - 4, 4, 4, 4 + 3, 16 3 - 959, 86 + 638, 72 0 @@ -408,22 +429,22 @@ Use this page to review and modify the NRPE configuration and metric threshold s 0 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="AllowHostsLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="AllowHostsTextBox" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="DebugLogCheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="SslDebugLogCheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="2" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,Absolute,30" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="AllowHostsLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="AllowHostsTextBox" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="DebugLogCheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="SslDebugLogCheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="2" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,Absolute,20" /></TableLayoutSettings> Fill - 4, 136 + 3, 144 - 4, 4, 4, 15 + 3, 3, 3, 10 - 4, 4, 4, 0 + 3, 3, 3, 0 - 967, 150 + 644, 100 3 @@ -441,7 +462,7 @@ Use this page to review and modify the NRPE configuration and metric threshold s NRPETableLayoutPanel - 3 + 4 34 @@ -474,16 +495,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s Fill - 4, 305 - - - 4, 4, 4, 4 + 3, 257 62 - 967, 450 + 644, 248 4 @@ -492,13 +510,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s CheckDataGridView - XenAdmin.Controls.DataGridViewEx.DataGridViewEx, [XenCenter], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.DataGridViewEx.DataGridViewEx, XenCenter, Version=0.0.0.9999, Culture=neutral, PublicKeyToken=null NRPETableLayoutPanel - 4 + 5 True @@ -513,13 +531,10 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 35, 0 - - - 4, 0, 4, 0 + 24, 0 - 930, 31 + 619, 5 5 @@ -542,11 +557,17 @@ Use this page to review and modify the NRPE configuration and metric threshold s 0 + + NoControl + - 3, 3 + 2, 2 + + + 2, 2, 2, 2 - 25, 25 + 17, 1 6 @@ -564,13 +585,16 @@ Use this page to review and modify the NRPE configuration and metric threshold s 1 - 3, 762 + 2, 510 + + + 2, 2, 2, 2 1 - 969, 31 + 646, 5 6 @@ -585,7 +609,7 @@ Use this page to review and modify the NRPE configuration and metric threshold s NRPETableLayoutPanel - 5 + 6 <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="RetrieveNRPELabel" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="RetrieveNRPEPicture" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="Percent,100" /></TableLayoutSettings> @@ -597,13 +621,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s 0, 0 - 4, 15, 4, 0 + 3, 10, 3, 0 - 7 + 8 - 975, 806 + 650, 537 0 @@ -621,22 +645,19 @@ Use this page to review and modify the NRPE configuration and metric threshold s 0 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="DescLabelPool" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="DescLabelHost" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="EnableNRPECheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="GeneralConfigureGroupBox" Row="3" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="CheckDataGridView" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="RetrieveNRPEPanel" Row="5" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Percent,100,AutoSize,0,Absolute,10" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="DescLabelPool" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="DescLabelHost" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="BatchConfigurationCheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="EnableNRPECheckBox" Row="3" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="GeneralConfigureGroupBox" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="CheckDataGridView" Row="5" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="RetrieveNRPEPanel" Row="6" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Percent,100,AutoSize,0,Absolute,20" /></TableLayoutSettings> True - 144, 144 + 96, 96 True - - 4, 4, 4, 4 - - 975, 806 + 650, 537 CheckColumn diff --git a/XenAdmin/XenAdmin.csproj b/XenAdmin/XenAdmin.csproj index 2c2420e00..c60abed56 100755 --- a/XenAdmin/XenAdmin.csproj +++ b/XenAdmin/XenAdmin.csproj @@ -9,7 +9,7 @@ WinExe Properties XenAdmin - [XenCenter] + XenCenter ..\Branding\Images\AppIcon.ico v4.8 publish\ @@ -6816,4 +6816,4 @@ copy "$(ProjectDir)\ReportViewer\resource_report.rdlc" "$(TargetDir)" - \ No newline at end of file + From 6c8158506e64b8f94dca584f3e9f95daf99f3d88 Mon Sep 17 00:00:00 2001 From: Bengang Yuan Date: Mon, 16 Oct 2023 16:59:33 +0800 Subject: [PATCH 07/10] All the configurations of host in a pool are the same. Fix some review comments. --- XenAdmin/Dialogs/PropertiesDialog.cs | 2 +- XenAdmin/Properties/AssemblyInfo.cs | 6 +- .../SettingsPanels/NRPEEditPage.Designer.cs | 80 ++++----- XenAdmin/SettingsPanels/NRPEEditPage.cs | 163 ++--------------- XenAdmin/SettingsPanels/NRPEEditPage.resx | 165 ++++++++---------- .../Actions/NRPE/NRPEHostConfiguration.cs | 25 ++- XenModel/Actions/NRPE/NRPERetrieveAction.cs | 46 ++--- XenModel/Actions/NRPE/NRPEUpdateAction.cs | 42 +---- 8 files changed, 178 insertions(+), 351 deletions(-) diff --git a/XenAdmin/Dialogs/PropertiesDialog.cs b/XenAdmin/Dialogs/PropertiesDialog.cs index 8c6f9de77..1af7923bf 100755 --- a/XenAdmin/Dialogs/PropertiesDialog.cs +++ b/XenAdmin/Dialogs/PropertiesDialog.cs @@ -318,7 +318,7 @@ private void Build() dialog.ShowDialog(Program.MainWindow); } } - if ((isHost || isPool) && + if (isPoolOrStandalone && (connection.Session.IsLocalSuperuser || connection.Session.Roles.Any(r => r.name_label == Role.MR_ROLE_POOL_ADMIN))) { NRPEEditPage = new NRPEEditPage(); diff --git a/XenAdmin/Properties/AssemblyInfo.cs b/XenAdmin/Properties/AssemblyInfo.cs index 1e24ef8a4..0b3ce0218 100644 --- a/XenAdmin/Properties/AssemblyInfo.cs +++ b/XenAdmin/Properties/AssemblyInfo.cs @@ -35,10 +35,10 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("XenCenter")] -[assembly: AssemblyDescription("XenCenter")] +[assembly: AssemblyTitle("[XenCenter]")] +[assembly: AssemblyDescription("[XenCenter]")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyProduct("XenCenter")] +[assembly: AssemblyProduct("[XenCenter]")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs index 6c41c0255..a619e79ac 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs @@ -30,7 +30,8 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NRPEEditPage)); this.NRPETableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); - this.BatchConfigurationCheckBox = new System.Windows.Forms.CheckBox(); + this.DescLabelPool = new XenAdmin.Controls.Common.AutoHeightLabel(); + this.DescLabelHost = new XenAdmin.Controls.Common.AutoHeightLabel(); this.EnableNRPECheckBox = new System.Windows.Forms.CheckBox(); this.GeneralConfigureGroupBox = new System.Windows.Forms.GroupBox(); this.GeneralConfigTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); @@ -38,21 +39,19 @@ private void InitializeComponent() this.AllowHostsTextBox = new System.Windows.Forms.TextBox(); this.DebugLogCheckBox = new System.Windows.Forms.CheckBox(); this.SslDebugLogCheckBox = new System.Windows.Forms.CheckBox(); + this.CheckDataGridView = new XenAdmin.Controls.DataGridViewEx.DataGridViewEx(); this.RetrieveNRPEPanel = new System.Windows.Forms.TableLayoutPanel(); this.RetrieveNRPELabel = new System.Windows.Forms.Label(); this.RetrieveNRPEPicture = new System.Windows.Forms.PictureBox(); - this.DescLabelPool = new XenAdmin.Controls.Common.AutoHeightLabel(); - this.DescLabelHost = new XenAdmin.Controls.Common.AutoHeightLabel(); - this.CheckDataGridView = new XenAdmin.Controls.DataGridViewEx.DataGridViewEx(); this.CheckColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.WarningThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.CriticalThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.NRPETableLayoutPanel.SuspendLayout(); this.GeneralConfigureGroupBox.SuspendLayout(); this.GeneralConfigTableLayoutPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).BeginInit(); this.RetrieveNRPEPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.RetrieveNRPEPicture)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).BeginInit(); this.SuspendLayout(); // // NRPETableLayoutPanel @@ -60,19 +59,21 @@ private void InitializeComponent() resources.ApplyResources(this.NRPETableLayoutPanel, "NRPETableLayoutPanel"); this.NRPETableLayoutPanel.Controls.Add(this.DescLabelPool, 0, 0); this.NRPETableLayoutPanel.Controls.Add(this.DescLabelHost, 0, 1); - this.NRPETableLayoutPanel.Controls.Add(this.BatchConfigurationCheckBox, 0, 2); this.NRPETableLayoutPanel.Controls.Add(this.EnableNRPECheckBox, 0, 3); this.NRPETableLayoutPanel.Controls.Add(this.GeneralConfigureGroupBox, 0, 4); this.NRPETableLayoutPanel.Controls.Add(this.CheckDataGridView, 0, 5); this.NRPETableLayoutPanel.Controls.Add(this.RetrieveNRPEPanel, 0, 6); this.NRPETableLayoutPanel.Name = "NRPETableLayoutPanel"; // - // BatchConfigurationCheckBox + // DescLabelPool + // + resources.ApplyResources(this.DescLabelPool, "DescLabelPool"); + this.DescLabelPool.Name = "DescLabelPool"; // - resources.ApplyResources(this.BatchConfigurationCheckBox, "BatchConfigurationCheckBox"); - this.BatchConfigurationCheckBox.Name = "BatchConfigurationCheckBox"; - this.BatchConfigurationCheckBox.UseVisualStyleBackColor = true; - this.BatchConfigurationCheckBox.CheckedChanged += new System.EventHandler(this.BatchConfigurationCheckBox_CheckedChanged); + // DescLabelHost + // + resources.ApplyResources(this.DescLabelHost, "DescLabelHost"); + this.DescLabelHost.Name = "DescLabelHost"; // // EnableNRPECheckBox // @@ -121,6 +122,21 @@ private void InitializeComponent() this.SslDebugLogCheckBox.Name = "SslDebugLogCheckBox"; this.SslDebugLogCheckBox.UseVisualStyleBackColor = true; // + // CheckDataGridView + // + this.CheckDataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.CheckDataGridView.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None; + resources.ApplyResources(this.CheckDataGridView, "CheckDataGridView"); + this.CheckDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; + this.CheckDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.CheckColumn, + this.WarningThresholdColumn, + this.CriticalThresholdColumn}); + this.CheckDataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; + this.CheckDataGridView.Name = "CheckDataGridView"; + this.CheckDataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; + this.CheckDataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; + // // RetrieveNRPEPanel // resources.ApplyResources(this.RetrieveNRPEPanel, "RetrieveNRPEPanel"); @@ -139,49 +155,22 @@ private void InitializeComponent() this.RetrieveNRPEPicture.Name = "RetrieveNRPEPicture"; this.RetrieveNRPEPicture.TabStop = false; // - // DescLabelPool - // - resources.ApplyResources(this.DescLabelPool, "DescLabelPool"); - this.DescLabelPool.Name = "DescLabelPool"; - // - // DescLabelHost - // - resources.ApplyResources(this.DescLabelHost, "DescLabelHost"); - this.DescLabelHost.Name = "DescLabelHost"; - // - // CheckDataGridView - // - this.CheckDataGridView.BackgroundColor = System.Drawing.SystemColors.Window; - this.CheckDataGridView.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None; - resources.ApplyResources(this.CheckDataGridView, "CheckDataGridView"); - this.CheckDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; - this.CheckDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.CheckColumn, - this.WarningThresholdColumn, - this.CriticalThresholdColumn}); - this.CheckDataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; - this.CheckDataGridView.Name = "CheckDataGridView"; - this.CheckDataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; - this.CheckDataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; - this.CheckDataGridView.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.CheckDataGridView_BeginEdit); - this.CheckDataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.CheckDataGridView_EndEdit); - // // CheckColumn // - this.CheckColumn.FillWeight = 15.57632F; + this.CheckColumn.FillWeight = 40F; resources.ApplyResources(this.CheckColumn, "CheckColumn"); this.CheckColumn.Name = "CheckColumn"; this.CheckColumn.ReadOnly = true; // // WarningThresholdColumn // - this.WarningThresholdColumn.FillWeight = 42.21184F; + this.WarningThresholdColumn.FillWeight = 30F; resources.ApplyResources(this.WarningThresholdColumn, "WarningThresholdColumn"); this.WarningThresholdColumn.Name = "WarningThresholdColumn"; // // CriticalThresholdColumn // - this.CriticalThresholdColumn.FillWeight = 42.21184F; + this.CriticalThresholdColumn.FillWeight = 30F; resources.ApplyResources(this.CriticalThresholdColumn, "CriticalThresholdColumn"); this.CriticalThresholdColumn.Name = "CriticalThresholdColumn"; // @@ -197,9 +186,9 @@ private void InitializeComponent() this.GeneralConfigureGroupBox.PerformLayout(); this.GeneralConfigTableLayoutPanel.ResumeLayout(false); this.GeneralConfigTableLayoutPanel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).EndInit(); this.RetrieveNRPEPanel.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.RetrieveNRPEPicture)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).EndInit(); this.ResumeLayout(false); } @@ -216,13 +205,12 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox SslDebugLogCheckBox; private Controls.DataGridViewEx.DataGridViewEx CheckDataGridView; private Controls.Common.AutoHeightLabel DescLabelHost; - private System.Windows.Forms.DataGridViewTextBoxColumn CheckColumn; - private System.Windows.Forms.DataGridViewTextBoxColumn WarningThresholdColumn; - private System.Windows.Forms.DataGridViewTextBoxColumn CriticalThresholdColumn; private System.Windows.Forms.Label RetrieveNRPELabel; private System.Windows.Forms.TableLayoutPanel RetrieveNRPEPanel; private System.Windows.Forms.PictureBox RetrieveNRPEPicture; - private System.Windows.Forms.CheckBox BatchConfigurationCheckBox; + private System.Windows.Forms.DataGridViewTextBoxColumn CheckColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn WarningThresholdColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn CriticalThresholdColumn; } } \ No newline at end of file diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.cs b/XenAdmin/SettingsPanels/NRPEEditPage.cs index 191ab0f6f..ffbde99d9 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -37,14 +37,11 @@ using XenAdmin.Core; using XenAdmin.Actions.NRPE; using XenAPI; -using System.Linq; namespace XenAdmin.SettingsPanels { 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,})$"); @@ -108,21 +105,13 @@ public NRPEEditPage() ToolTipTitle = Messages.INVALID_PARAMETER, Tag = AllowHostsTextBox }; - DisableAllComponent(); } public string SubText { get { - if (_isHost) - { - return Messages.NRPE_EDIT_PAGE_TEXT; - } - else - { - return Messages.NRPE_BATCH_CONFIGURATION; - } + return Messages.NRPE_EDIT_PAGE_TEXT; } } @@ -159,10 +148,9 @@ public bool HasChanged { get { - if (_isHost && IsNRPEConfigurationChanged() || - !_isHost && BatchConfigurationCheckBox.Checked) + UpdateCurrentNRPEConfiguration(); + if (!_nrpeCurrentConfig.Equals(_nrpeOriginalConfig)) { - UpdateCurrentNRPEConfiguration(); return true; } return false; @@ -198,35 +186,6 @@ public AsyncAction SaveSettings() return new NRPEUpdateAction(_clone, _nrpeCurrentConfig, _nrpeOriginalConfig, true); } - public bool IsNRPEAvailable(IXenObject clone) - { - IXenObject checkHost; - if (clone is Host h) - { - checkHost = h; - } - else if (clone is Pool p) - { - List hostList = p.Connection.Cache.Hosts.ToList(); - checkHost = hostList[0]; - } - else - { - return false; - } - try - { - Host.call_plugin(checkHost.Connection.Session, checkHost.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, - NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, null); - } - catch (Exception e) - { - log.InfoFormat("Execute NRPE plugin failed, failed reason: {0}. It may not support NRPE.", e.Message); - return false; - } - return true; - } - public void SetXenObjects(IXenObject orig, IXenObject clone) { _clone = clone; @@ -234,7 +193,6 @@ public void SetXenObjects(IXenObject orig, IXenObject clone) DescLabelHost.Visible = _isHost; DescLabelPool.Visible = !_isHost; - BatchConfigurationCheckBox.Visible = !_isHost; UpdateRetrievingNRPETip(NRPEHostConfiguration.RetrieveNRPEStatus.Retrieving); DisableAllComponent(); @@ -252,16 +210,9 @@ private void UpdateRetrieveStatus() { if (_nrpeOriginalConfig.Status == NRPEHostConfiguration.RetrieveNRPEStatus.Successful) { - if (_isHost) - { - EnableNRPECheckBox.Enabled = true; - UpdateComponentValueBasedConfiguration(); - UpdateComponentStatusBasedEnableNRPECheckBox(); - } - else - { - BatchConfigurationCheckBox.Enabled = true; - } + EnableNRPECheckBox.Enabled = true; + UpdateComponentValueBasedConfiguration(); + UpdateComponentStatusBasedEnableNRPECheckBox(); } UpdateRetrievingNRPETip(_nrpeOriginalConfig.Status); } @@ -312,39 +263,24 @@ private void UpdateComponentValueBasedConfiguration() SslDebugLogCheckBox.Checked = _nrpeOriginalConfig.SslLogging; } - private void UpdateComponentStatusBasedBatchConfigurationCheckBox() - { - if (BatchConfigurationCheckBox.Checked) - { - EnableNRPECheckBox.Enabled = true; - UpdateComponentStatusBasedEnableNRPECheckBox(); - } - else - { - DisableAllComponent(); - } - } - private void UpdateComponentStatusBasedEnableNRPECheckBox() { GeneralConfigureGroupBox.Enabled = EnableNRPECheckBox.Checked; CheckDataGridView.Enabled = EnableNRPECheckBox.Checked; + CheckDataGridView.ScrollBars = ScrollBars.Both; CheckDataGridView.DefaultCellStyle.BackColor = EnableNRPECheckBox.Checked ? Color.FromKnownColor(KnownColor.Window) : Color.FromKnownColor(KnownColor.Control); - if (_isHost) + foreach (var checkGroup in _checkGroupList) { - foreach (var checkGroup in _checkGroupList) + if (EnableNRPECheckBox.Checked) { - if (EnableNRPECheckBox.Checked) - { - checkGroup.WarningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); - checkGroup.CriticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); - } - else - { - checkGroup.WarningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); - checkGroup.CriticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); - } + checkGroup.WarningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + checkGroup.CriticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + } + else + { + checkGroup.WarningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + checkGroup.CriticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); } } } @@ -411,29 +347,6 @@ private string AllowHostsWithoutLocalAddress(string allowHosts) UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1); } - private bool IsNRPEConfigurationChanged() - { - if (_nrpeCurrentConfig.EnableNRPE != _nrpeOriginalConfig.EnableNRPE || - !_nrpeCurrentConfig.AllowHosts.Equals(_nrpeOriginalConfig.AllowHosts) || - _nrpeCurrentConfig.Debug != _nrpeOriginalConfig.Debug || - _nrpeCurrentConfig.SslLogging != _nrpeOriginalConfig.SslLogging) - { - return true; - } - foreach (KeyValuePair kvp in _nrpeCurrentConfig.CheckDict) - { - NRPEHostConfiguration.Check CurrentCheck = kvp.Value; - _nrpeOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); - if (CurrentCheck != null && OriginalCheck != null - && (!CurrentCheck.WarningThreshold.Equals(OriginalCheck.WarningThreshold) - || !CurrentCheck.CriticalThreshold.Equals(OriginalCheck.CriticalThreshold))) - { - return true; - } - } - return false; - } - private void UpdateCurrentNRPEConfiguration() { _nrpeCurrentConfig = new NRPEHostConfiguration @@ -445,20 +358,11 @@ private void UpdateCurrentNRPEConfiguration() }; foreach (KeyValuePair item in _checkGroupDictByName) { - if (item.Value.WarningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText)) - && item.Value.CriticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText))) - { - _nrpeCurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(item.Key, - item.Value.WarningThresholdCell.Value.ToString(), item.Value.CriticalThresholdCell.Value.ToString())); - } + _nrpeCurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(item.Key, + item.Value.WarningThresholdCell.Value.ToString(), item.Value.CriticalThresholdCell.Value.ToString())); } } - private void BatchConfigurationCheckBox_CheckedChanged(object sender, EventArgs e) - { - UpdateComponentStatusBasedBatchConfigurationCheckBox(); - } - private void EnableNRPECheckBox_CheckedChanged(object sender, EventArgs e) { UpdateComponentStatusBasedEnableNRPECheckBox(); @@ -481,36 +385,5 @@ private void AllowHostsTextBox_LostFocus(object sender, EventArgs e) AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); } } - - private void CheckDataGridView_BeginEdit(object sender, DataGridViewCellCancelEventArgs e) - { - 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 = ""; - } - } - - private void CheckDataGridView_EndEdit(object sender, DataGridViewCellEventArgs e) - { - 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); - - if (checkGroup != null) - { - if (currentCell.ColumnIndex == WarningThresholdColumn.Index) - currentCell.Value = checkGroup.WarningThresholdDefault; - else if (currentCell.ColumnIndex == CriticalThresholdColumn.Index) - currentCell.Value = checkGroup.CriticalThresholdDefault; - } - _nrpeOriginalConfig.CheckDict.TryGetValue(checkGroup.Name, out NRPEHostConfiguration.Check check); - } - } } } diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.resx b/XenAdmin/SettingsPanels/NRPEEditPage.resx index bfbbd26f3..3250d8794 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.resx +++ b/XenAdmin/SettingsPanels/NRPEEditPage.resx @@ -133,26 +133,26 @@ - 3, 0 + 4, 0 - 3, 0, 3, 10 + 4, 0, 4, 15 - 644, 39 + 967, 40 0 Nagios Remote Plugin Executor (NRPE) allows you to monitor remotely resource metrics on the servers of your pool. -This page does not offer an overview of the NRPE configuration and metric threshold settings of the pool servers. Use it only to apply your chosen configuration and threshold settings to all servers in the pool. +Use this page to review and modify the NRPE configuration and metric threshold settings used for this pool. DescLabelPool - XenAdmin.Controls.Common.AutoHeightLabel, XenCenter, Version=0.0.0.9999, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.Common.AutoHeightLabel, XenCenter, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null NRPETableLayoutPanel @@ -170,13 +170,13 @@ This page does not offer an overview of the NRPE configuration and metric thresh NoControl - 3, 49 + 4, 55 - 3, 0, 3, 10 + 4, 0, 4, 15 - 644, 26 + 967, 40 1 @@ -189,7 +189,7 @@ Use this page to review and modify the NRPE configuration and metric threshold s DescLabelHost - XenAdmin.Controls.Common.AutoHeightLabel, XenCenter, Version=0.0.0.9999, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.Common.AutoHeightLabel, XenCenter, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null NRPETableLayoutPanel @@ -197,42 +197,6 @@ Use this page to review and modify the NRPE configuration and metric threshold s 1 - - True - - - NoControl - - - 3, 88 - - - 3, 3, 3, 8 - - - 3, 0, 0, 0 - - - 171, 17 - - - 7 - - - Sync &Configuration to all hosts - - - BatchConfigurationCheckBox - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - NRPETableLayoutPanel - - - 2 - True @@ -240,16 +204,16 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 3, 116 + 4, 114 - 3, 3, 3, 8 + 4, 4, 4, 12 - 3, 0, 0, 0 + 4, 0, 0, 0 - 95, 17 + 137, 24 2 @@ -267,7 +231,7 @@ Use this page to review and modify the NRPE configuration and metric threshold s NRPETableLayoutPanel - 3 + 2 True @@ -288,10 +252,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 3, 6 + 4, 7 + + + 4, 0, 4, 0 - 96, 13 + 142, 20 0 @@ -315,10 +282,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s Left, Right - 105, 3 + 154, 4 + + + 4, 4, 4, 4 - 530, 20 + 801, 26 1 @@ -342,13 +312,16 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 3, 29 + 4, 38 + + + 4, 4, 4, 4 - 3, 0, 0, 0 + 4, 0, 0, 0 - 211, 17 + 313, 24 2 @@ -375,13 +348,16 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 3, 52 + 4, 70 + + + 4, 4, 4, 4 - 3, 0, 0, 0 + 4, 0, 0, 0 - 181, 17 + 269, 24 3 @@ -405,13 +381,16 @@ Use this page to review and modify the NRPE configuration and metric threshold s Top - 3, 16 + 4, 23 + + + 4, 4, 4, 4 3 - 638, 72 + 959, 98 0 @@ -429,22 +408,22 @@ Use this page to review and modify the NRPE configuration and metric threshold s 0 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="AllowHostsLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="AllowHostsTextBox" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="DebugLogCheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="SslDebugLogCheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="2" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,Absolute,20" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="AllowHostsLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="AllowHostsTextBox" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="DebugLogCheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="SslDebugLogCheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="2" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,Absolute,30" /></TableLayoutSettings> Fill - 3, 144 + 4, 154 - 3, 3, 3, 10 + 4, 4, 4, 15 - 3, 3, 3, 0 + 4, 4, 4, 0 - 644, 100 + 967, 150 3 @@ -462,7 +441,7 @@ Use this page to review and modify the NRPE configuration and metric threshold s NRPETableLayoutPanel - 4 + 3 34 @@ -495,13 +474,19 @@ Use this page to review and modify the NRPE configuration and metric threshold s Fill - 3, 257 + 4, 323 + + + 4, 4, 4, 4 62 + + None + - 644, 248 + 967, 411 4 @@ -510,13 +495,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s CheckDataGridView - XenAdmin.Controls.DataGridViewEx.DataGridViewEx, XenCenter, Version=0.0.0.9999, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.DataGridViewEx.DataGridViewEx, XenCenter, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null NRPETableLayoutPanel - 5 + 4 True @@ -531,10 +516,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 24, 0 + 36, 0 + + + 4, 0, 4, 0 - 619, 5 + 928, 32 5 @@ -561,13 +549,10 @@ Use this page to review and modify the NRPE configuration and metric threshold s NoControl - 2, 2 - - - 2, 2, 2, 2 + 3, 3 - 17, 1 + 26, 26 6 @@ -585,16 +570,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s 1 - 2, 510 - - - 2, 2, 2, 2 + 3, 741 1 - 646, 5 + 968, 32 6 @@ -609,7 +591,7 @@ Use this page to review and modify the NRPE configuration and metric threshold s NRPETableLayoutPanel - 6 + 5 <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="RetrieveNRPELabel" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="RetrieveNRPEPicture" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="Percent,100" /></TableLayoutSettings> @@ -621,13 +603,13 @@ Use this page to review and modify the NRPE configuration and metric threshold s 0, 0 - 3, 10, 3, 0 + 4, 15, 4, 0 8 - 650, 537 + 975, 806 0 @@ -645,19 +627,22 @@ Use this page to review and modify the NRPE configuration and metric threshold s 0 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="DescLabelPool" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="DescLabelHost" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="BatchConfigurationCheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="EnableNRPECheckBox" Row="3" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="GeneralConfigureGroupBox" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="CheckDataGridView" Row="5" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="RetrieveNRPEPanel" Row="6" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Percent,100,AutoSize,0,Absolute,20" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="DescLabelPool" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="DescLabelHost" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="EnableNRPECheckBox" Row="3" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="GeneralConfigureGroupBox" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="CheckDataGridView" Row="5" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="RetrieveNRPEPanel" Row="6" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Percent,100,AutoSize,0,Absolute,30" /></TableLayoutSettings> True - 96, 96 + 144, 144 True + + 4, 4, 4, 4 + - 650, 537 + 975, 806 CheckColumn diff --git a/XenModel/Actions/NRPE/NRPEHostConfiguration.cs b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs index ea250c385..8b3e7cf9e 100644 --- a/XenModel/Actions/NRPE/NRPEHostConfiguration.cs +++ b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs @@ -34,7 +34,7 @@ namespace XenAdmin.Actions.NRPE { - public class NRPEHostConfiguration : ICloneable + public class NRPEHostConfiguration : ICloneable, IEquatable { public const string XAPI_NRPE_PLUGIN_NAME = "nrpe"; public const string XAPI_NRPE_STATUS = "status"; @@ -101,6 +101,29 @@ public bool GetNRPECheck(string name, out Check check) return _checkDict.TryGetValue(name, out check); } + public bool Equals(NRPEHostConfiguration other) + { + if (EnableNRPE != other.EnableNRPE || + !AllowHosts.Equals(other.AllowHosts) || + Debug != other.Debug || + SslLogging != other.SslLogging) + { + return false; + } + foreach (KeyValuePair kvp in CheckDict) + { + Check CurrentCheck = kvp.Value; + other.GetNRPECheck(kvp.Key, out Check OriginalCheck); + if (CurrentCheck != null && OriginalCheck != null + && (!CurrentCheck.WarningThreshold.Equals(OriginalCheck.WarningThreshold) + || !CurrentCheck.CriticalThreshold.Equals(OriginalCheck.CriticalThreshold))) + { + return false; + } + } + return true; + } + public object Clone() { NRPEHostConfiguration cloned = new NRPEHostConfiguration diff --git a/XenModel/Actions/NRPE/NRPERetrieveAction.cs b/XenModel/Actions/NRPE/NRPERetrieveAction.cs index 9c9b287aa..495b3bc9e 100644 --- a/XenModel/Actions/NRPE/NRPERetrieveAction.cs +++ b/XenModel/Actions/NRPE/NRPERetrieveAction.cs @@ -33,6 +33,7 @@ using System.Drawing; using System.Linq; using System.Threading; +using XenAdmin.Core; using XenAPI; @@ -58,46 +59,29 @@ public NRPERetrieveAction(IXenObject host, NRPEHostConfiguration nrpeHostConfigu protected override void Run() { _nrpeCurrentConfig.Status = NRPEHostConfiguration.RetrieveNRPEStatus.Successful; - if (_clone is Pool p) + // For pool, retrieve the configuration from the master of the pool. + IXenObject o = _clone is Pool p ? Helpers.GetCoordinator(p) : _clone; + try { - List hostList = p.Connection.Cache.Hosts.ToList(); - Host checkHost = hostList[0]; - try - { - Host.call_plugin(checkHost.Connection.Session, checkHost.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, - NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, null); - } - catch (Exception e) - { - log.ErrorFormat("Execute NRPE plugin failed, failed reason: {0}.", e.Message); - _nrpeCurrentConfig.Status = e.Message.Contains("UNKNOWN_XENAPI_PLUGIN_FUNCTION") ? - NRPEHostConfiguration.RetrieveNRPEStatus.Unsupport : NRPEHostConfiguration.RetrieveNRPEStatus.Failed; - } + InitNRPEGeneralConfiguration(o); + InitNRPEThreshold(o); } - else + catch (Exception e) { - try - { - InitNRPEGeneralConfiguration(); - InitNRPEThreshold(); - } - catch (Exception e) - { - log.ErrorFormat("Execute NRPE plugin failed, failed reason: {0}.", e.Message); - _nrpeCurrentConfig.Status = e.Message.Contains("UNKNOWN_XENAPI_PLUGIN_FUNCTION") ? - NRPEHostConfiguration.RetrieveNRPEStatus.Unsupport : NRPEHostConfiguration.RetrieveNRPEStatus.Failed; - } + log.ErrorFormat("Execute NRPE plugin failed, failed reason: {0}", e.Message); + _nrpeCurrentConfig.Status = e.Message.Contains("UNKNOWN_XENAPI_PLUGIN_FUNCTION") || e.Message.Contains("The requested plug-in could not be found") ? + NRPEHostConfiguration.RetrieveNRPEStatus.Unsupport : NRPEHostConfiguration.RetrieveNRPEStatus.Failed; } } - private void InitNRPEGeneralConfiguration() + private void InitNRPEGeneralConfiguration(IXenObject o) { - string status = Host.call_plugin(_clone.Connection.Session, _clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + string status = Host.call_plugin(o.Connection.Session, o.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, NRPEHostConfiguration.XAPI_NRPE_STATUS, null); log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_STATUS, status); _nrpeCurrentConfig.EnableNRPE = status.Trim().Equals("active enabled"); - string nrpeConfig = Host.call_plugin(_clone.Connection.Session, _clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + string nrpeConfig = Host.call_plugin(o.Connection.Session, o.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, null); log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, nrpeConfig); @@ -122,9 +106,9 @@ private void InitNRPEGeneralConfiguration() } } - private void InitNRPEThreshold() + private void InitNRPEThreshold(IXenObject o) { - string nrpeThreshold = Host.call_plugin(_clone.Connection.Session, _clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + string nrpeThreshold = Host.call_plugin(o.Connection.Session, o.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, null); log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, nrpeThreshold); diff --git a/XenModel/Actions/NRPE/NRPEUpdateAction.cs b/XenModel/Actions/NRPE/NRPEUpdateAction.cs index f323b0243..cb9060f18 100644 --- a/XenModel/Actions/NRPE/NRPEUpdateAction.cs +++ b/XenModel/Actions/NRPE/NRPEUpdateAction.cs @@ -56,7 +56,7 @@ protected override void Run() { if (_clone is Host) { - SetNRPEConfigureForHost(); + SetNRPEConfigureForHost(_clone); } else { @@ -64,12 +64,12 @@ protected override void Run() } } - private void SetNRPEConfigureForHost() + private void SetNRPEConfigureForHost(IXenObject o) { // Enable/Disable NRPE if (!_nrpeHostConfiguration.EnableNRPE == _nrpeOriginalConfig.EnableNRPE) { - SetNRPEStatus(_clone, _nrpeHostConfiguration.EnableNRPE); + SetNRPEStatus(o, _nrpeHostConfiguration.EnableNRPE); } if (!_nrpeHostConfiguration.EnableNRPE) // If disable, return { @@ -81,7 +81,7 @@ private void SetNRPEConfigureForHost() || !_nrpeHostConfiguration.Debug.Equals(_nrpeOriginalConfig.Debug) || !_nrpeHostConfiguration.SslLogging.Equals(_nrpeOriginalConfig.SslLogging)) { - SetNRPEGeneralConfiguration(_clone, _nrpeHostConfiguration.AllowHosts, _nrpeHostConfiguration.Debug, _nrpeHostConfiguration.SslLogging); + SetNRPEGeneralConfiguration(o, _nrpeHostConfiguration.AllowHosts, _nrpeHostConfiguration.Debug, _nrpeHostConfiguration.SslLogging); } // NRPE Check Threshold @@ -93,45 +93,19 @@ private void SetNRPEConfigureForHost() && (!CurrentCheck.WarningThreshold.Equals(OriginalCheck.WarningThreshold) || !CurrentCheck.CriticalThreshold.Equals(OriginalCheck.CriticalThreshold))) { - SetNRPEThreshold(_clone, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold); + SetNRPEThreshold(o, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold); } } - RestartNRPE(_clone); + RestartNRPE(o); } private void SetNRPEConfigureForPool() { - List hostList = null; - if (_clone is Pool p) - { - hostList = p.Connection.Cache.Hosts.ToList(); - } - + List hostList = ((Pool) _clone).Connection.Cache.Hosts.ToList(); hostList.ForEach(host => { - // Enable/Disable NRPE - SetNRPEStatus(host, _nrpeHostConfiguration.EnableNRPE); - if (!_nrpeHostConfiguration.EnableNRPE) // If disable, return - { - return; - } - - // NRPE General Configuration - SetNRPEGeneralConfiguration(host, _nrpeHostConfiguration.AllowHosts, _nrpeHostConfiguration.Debug, _nrpeHostConfiguration.SslLogging); - - // NRPE Check Threshold - foreach (KeyValuePair kvp in _nrpeHostConfiguration.CheckDict) - { - NRPEHostConfiguration.Check CurrentCheck = kvp.Value; - _nrpeOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); - if (CurrentCheck != null) - { - SetNRPEThreshold(host, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold); - } - } - - RestartNRPE(host); + SetNRPEConfigureForHost(host); }); } From c06defe53e0ffbdbc0ac5e95d66b80e44500feea Mon Sep 17 00:00:00 2001 From: Bengang Yuan Date: Wed, 18 Oct 2023 01:01:39 +0800 Subject: [PATCH 08/10] Check NRPE plugin before showing properties dialog. --- XenAdmin/Dialogs/PropertiesDialog.cs | 4 +-- XenAdmin/SettingsPanels/NRPEEditPage.cs | 25 ++++++------------- .../Actions/NRPE/NRPEHostConfiguration.cs | 10 +++----- XenModel/Actions/NRPE/NRPERetrieveAction.cs | 20 ++++++--------- XenModel/Actions/NRPE/NRPEUpdateAction.cs | 18 ++++++------- XenModel/Messages.Designer.cs | 9 ------- XenModel/Messages.resx | 5 +--- XenModel/Utils/Helpers.Versions.cs | 6 +++++ 8 files changed, 37 insertions(+), 60 deletions(-) diff --git a/XenAdmin/Dialogs/PropertiesDialog.cs b/XenAdmin/Dialogs/PropertiesDialog.cs index 1af7923bf..11a29d89d 100755 --- a/XenAdmin/Dialogs/PropertiesDialog.cs +++ b/XenAdmin/Dialogs/PropertiesDialog.cs @@ -318,8 +318,8 @@ private void Build() dialog.ShowDialog(Program.MainWindow); } } - if (isPoolOrStandalone && - (connection.Session.IsLocalSuperuser || connection.Session.Roles.Any(r => r.name_label == Role.MR_ROLE_POOL_ADMIN))) + if (isPoolOrStandalone && Helpers.XapiEqualOrGreater_23_27_0(connection) + && (connection.Session.IsLocalSuperuser || connection.Session.Roles.Any(r => r.name_label == Role.MR_ROLE_POOL_ADMIN))) { NRPEEditPage = new NRPEEditPage(); ShowTab(NRPEEditPage); diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.cs b/XenAdmin/SettingsPanels/NRPEEditPage.cs index ffbde99d9..9bb719e6c 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -37,11 +37,15 @@ using XenAdmin.Core; using XenAdmin.Actions.NRPE; using XenAPI; +using System.Linq; +using XenAdmin.Network; namespace XenAdmin.SettingsPanels { 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,})$"); @@ -107,13 +111,7 @@ public NRPEEditPage() }; } - public string SubText - { - get - { - return Messages.NRPE_EDIT_PAGE_TEXT; - } - } + public string SubText => Messages.NRPE_EDIT_PAGE_TEXT; public bool ValidToSave { @@ -149,11 +147,7 @@ public bool HasChanged get { UpdateCurrentNRPEConfiguration(); - if (!_nrpeCurrentConfig.Equals(_nrpeOriginalConfig)) - { - return true; - } - return false; + return !_nrpeCurrentConfig.Equals(_nrpeOriginalConfig); } } @@ -236,13 +230,8 @@ private void UpdateRetrievingNRPETip(NRPEHostConfiguration.RetrieveNRPEStatus st RetrieveNRPEPicture.Image = Images.StaticImages._000_error_h32bit_16; RetrieveNRPEPicture.Visible = true; break; - case NRPEHostConfiguration.RetrieveNRPEStatus.Unsupport: - RetrieveNRPELabel.Text = Messages.NRPE_UNSUPPORT; - RetrieveNRPEPicture.Image = Images.StaticImages._000_error_h32bit_16; - RetrieveNRPEPicture.Visible = true; - break; default: - break; + throw new ArgumentOutOfRangeException(nameof(status), status, null); } } diff --git a/XenModel/Actions/NRPE/NRPEHostConfiguration.cs b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs index 8b3e7cf9e..31154b329 100644 --- a/XenModel/Actions/NRPE/NRPEHostConfiguration.cs +++ b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs @@ -30,7 +30,6 @@ using System; using System.Collections.Generic; -using XenAPI; namespace XenAdmin.Actions.NRPE { @@ -54,7 +53,7 @@ public class NRPEHostConfiguration : ICloneable, IEquatable _checkDict = new Dictionary(); + private readonly Dictionary _checkDict = new Dictionary(); public bool EnableNRPE { get; set; } @@ -72,8 +71,7 @@ public enum RetrieveNRPEStatus { Retrieving, Successful, - Failed, - Unsupport + Failed } public class Check @@ -133,9 +131,9 @@ public object Clone() Debug = Debug, SslLogging = SslLogging }; - foreach (KeyValuePair kvp in _checkDict) + foreach (KeyValuePair kvp in _checkDict) { - NRPEHostConfiguration.Check CurrentCheck = kvp.Value; + Check CurrentCheck = kvp.Value; cloned.AddNRPECheck(new Check(CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold)); } diff --git a/XenModel/Actions/NRPE/NRPERetrieveAction.cs b/XenModel/Actions/NRPE/NRPERetrieveAction.cs index 495b3bc9e..77513db45 100644 --- a/XenModel/Actions/NRPE/NRPERetrieveAction.cs +++ b/XenModel/Actions/NRPE/NRPERetrieveAction.cs @@ -30,9 +30,6 @@ using System; using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Threading; using XenAdmin.Core; using XenAPI; @@ -69,8 +66,7 @@ protected override void Run() catch (Exception e) { log.ErrorFormat("Execute NRPE plugin failed, failed reason: {0}", e.Message); - _nrpeCurrentConfig.Status = e.Message.Contains("UNKNOWN_XENAPI_PLUGIN_FUNCTION") || e.Message.Contains("The requested plug-in could not be found") ? - NRPEHostConfiguration.RetrieveNRPEStatus.Unsupport : NRPEHostConfiguration.RetrieveNRPEStatus.Failed; + _nrpeCurrentConfig.Status = NRPEHostConfiguration.RetrieveNRPEStatus.Failed; } } @@ -128,20 +124,20 @@ private void InitNRPEThreshold(IXenObject o) } } - private string AllowHostsWithoutLocalAddress(string allowHosts) + private static string AllowHostsWithoutLocalAddress(string allowHosts) { - string UpdatedAllowHosts = ""; - string[] AllowHostArray = allowHosts.Split(','); - foreach (string allowHost in AllowHostArray) + string updatedAllowHosts = ""; + string[] allowHostArray = allowHosts.Split(','); + foreach (string allowHost in allowHostArray) { if (!allowHost.Trim().Equals("127.0.0.1") && !allowHost.Trim().Equals("::1")) { - UpdatedAllowHosts += allowHost + ","; + updatedAllowHosts += allowHost + ","; } } - return UpdatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER : - UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1); + return updatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER : + updatedAllowHosts.Substring(0, updatedAllowHosts.Length - 1); } } } diff --git a/XenModel/Actions/NRPE/NRPEUpdateAction.cs b/XenModel/Actions/NRPE/NRPEUpdateAction.cs index cb9060f18..47bdf9e87 100644 --- a/XenModel/Actions/NRPE/NRPEUpdateAction.cs +++ b/XenModel/Actions/NRPE/NRPEUpdateAction.cs @@ -87,13 +87,13 @@ private void SetNRPEConfigureForHost(IXenObject o) // NRPE Check Threshold foreach (KeyValuePair kvp in _nrpeHostConfiguration.CheckDict) { - NRPEHostConfiguration.Check CurrentCheck = kvp.Value; + NRPEHostConfiguration.Check currentCheck = kvp.Value; _nrpeOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); - if (CurrentCheck != null && OriginalCheck != null - && (!CurrentCheck.WarningThreshold.Equals(OriginalCheck.WarningThreshold) - || !CurrentCheck.CriticalThreshold.Equals(OriginalCheck.CriticalThreshold))) + if (currentCheck != null && OriginalCheck != null + && (!currentCheck.WarningThreshold.Equals(OriginalCheck.WarningThreshold) + || !currentCheck.CriticalThreshold.Equals(OriginalCheck.CriticalThreshold))) { - SetNRPEThreshold(o, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold); + SetNRPEThreshold(o, currentCheck.Name, currentCheck.WarningThreshold, currentCheck.CriticalThreshold); } } @@ -120,14 +120,14 @@ private void SetNRPEStatus(IXenObject host, bool enableNRPE) private void SetNRPEGeneralConfiguration(IXenObject host, string allowHosts, bool debug, bool sslLogging) { - Dictionary ConfigArgDict = new Dictionary + Dictionary configArgDict = new Dictionary { { "allowed_hosts", "127.0.0.1,::1," + (allowHosts.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ? "" : allowHosts) }, { "debug", debug ? NRPEHostConfiguration.DEBUG_ENABLE : NRPEHostConfiguration.DEBUG_DISABLE }, { "ssl_logging", sslLogging ? NRPEHostConfiguration.SSL_LOGGING_ENABLE : NRPEHostConfiguration.SSL_LOGGING_DISABLE} }; string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, - NRPEHostConfiguration.XAPI_NRPE_SET_CONFIG, ConfigArgDict); + NRPEHostConfiguration.XAPI_NRPE_SET_CONFIG, configArgDict); log.InfoFormat("Execute nrpe {0}, allowed_hosts={1}, debug={2}, ssl_logging={3}, return: {4}", NRPEHostConfiguration.XAPI_NRPE_SET_CONFIG, _nrpeHostConfiguration.AllowHosts, @@ -138,14 +138,14 @@ private void SetNRPEGeneralConfiguration(IXenObject host, string allowHosts, boo private void SetNRPEThreshold(IXenObject host, string checkName, string warningThreshold, string criticalThreshold) { - Dictionary ThresholdArgDict = new Dictionary + Dictionary thresholdArgDict = new Dictionary { { checkName, null }, { "w", warningThreshold }, { "c", criticalThreshold } }; string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, - NRPEHostConfiguration.XAPI_NRPE_SET_THRESHOLD, ThresholdArgDict); + NRPEHostConfiguration.XAPI_NRPE_SET_THRESHOLD, thresholdArgDict); log.InfoFormat("Execute nrpe {0}, check={1}, w={2}, c={3}, return: {4}", NRPEHostConfiguration.XAPI_NRPE_SET_THRESHOLD, checkName, diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index 92325ebca..9409d987a 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -29357,15 +29357,6 @@ public static string NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL { } } - /// - /// Looks up a localized string similar to Unsupport NRPE, please upgrade your XenServer version.. - /// - public static string NRPE_UNSUPPORT { - get { - return ResourceManager.GetString("NRPE_UNSUPPORT", resourceCulture); - } - } - /// /// Looks up a localized string similar to Number of snapshots to keep. /// diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index 6e390e156..1df986623 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -10185,9 +10185,6 @@ When you configure an NFS storage repository, you simply provide the host name o Warning threshold should be less than critical threshold. - - Unsupport NRPE, please upgrade your XenServer version. - Number of snapshots to keep @@ -15180,4 +15177,4 @@ Do you want to synchronize immediately? Only synchronize &visible - + \ No newline at end of file diff --git a/XenModel/Utils/Helpers.Versions.cs b/XenModel/Utils/Helpers.Versions.cs index eccfe9652..a1740bede 100644 --- a/XenModel/Utils/Helpers.Versions.cs +++ b/XenModel/Utils/Helpers.Versions.cs @@ -528,6 +528,12 @@ public static bool XapiEqualOrGreater_23_18_0(IXenConnection conn) return coordinator == null || ProductVersionCompare(coordinator.GetXapiVersion(), "23.18.0") >= 0; } + public static bool XapiEqualOrGreater_23_27_0(IXenConnection conn) + { + var coordinator = GetCoordinator(conn); + return coordinator == null || ProductVersionCompare(coordinator.GetXapiVersion(), "23.27.0") >= 0; + } + #endregion } } From c5a11dcf280b96b0f59bf04e0540816bf802c07b Mon Sep 17 00:00:00 2001 From: Bengang Yuan Date: Mon, 23 Oct 2023 17:05:03 +0800 Subject: [PATCH 09/10] Resolve NRPE code review comments from Tina. --- .../SettingsPanels/NRPEEditPage.CheckGroup.cs | 213 ++++++++++++++ .../SettingsPanels/NRPEEditPage.Designer.cs | 44 +-- XenAdmin/SettingsPanels/NRPEEditPage.cs | 42 ++- XenAdmin/XenAdmin.csproj | 8 +- XenModel/Actions/NRPE/CheckGroup.cs | 267 ------------------ XenModel/Actions/NRPE/NRPERetrieveAction.cs | 23 +- XenModel/Actions/NRPE/NRPEUpdateAction.cs | 29 +- XenModel/Messages.Designer.cs | 4 +- XenModel/Messages.resx | 4 +- XenModel/XenModel.csproj | 2 - 10 files changed, 293 insertions(+), 343 deletions(-) create mode 100644 XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs delete mode 100644 XenModel/Actions/NRPE/CheckGroup.cs diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs b/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs new file mode 100644 index 000000000..268a008ed --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs @@ -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(); + CriticalThresholdCell = new DataGridViewTextBoxCell(); + 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; + } + } + } +} diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs index a619e79ac..af65fa8f5 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs @@ -40,12 +40,12 @@ private void InitializeComponent() this.DebugLogCheckBox = new System.Windows.Forms.CheckBox(); this.SslDebugLogCheckBox = new System.Windows.Forms.CheckBox(); this.CheckDataGridView = new XenAdmin.Controls.DataGridViewEx.DataGridViewEx(); - this.RetrieveNRPEPanel = new System.Windows.Forms.TableLayoutPanel(); - this.RetrieveNRPELabel = new System.Windows.Forms.Label(); - this.RetrieveNRPEPicture = new System.Windows.Forms.PictureBox(); this.CheckColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.WarningThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.CriticalThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.RetrieveNRPEPanel = new System.Windows.Forms.TableLayoutPanel(); + this.RetrieveNRPELabel = new System.Windows.Forms.Label(); + this.RetrieveNRPEPicture = new System.Windows.Forms.PictureBox(); this.NRPETableLayoutPanel.SuspendLayout(); this.GeneralConfigureGroupBox.SuspendLayout(); this.GeneralConfigTableLayoutPanel.SuspendLayout(); @@ -136,24 +136,8 @@ private void InitializeComponent() this.CheckDataGridView.Name = "CheckDataGridView"; this.CheckDataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; this.CheckDataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; - // - // RetrieveNRPEPanel - // - resources.ApplyResources(this.RetrieveNRPEPanel, "RetrieveNRPEPanel"); - this.RetrieveNRPEPanel.Controls.Add(this.RetrieveNRPELabel, 1, 0); - this.RetrieveNRPEPanel.Controls.Add(this.RetrieveNRPEPicture, 0, 0); - this.RetrieveNRPEPanel.Name = "RetrieveNRPEPanel"; - // - // RetrieveNRPELabel - // - resources.ApplyResources(this.RetrieveNRPELabel, "RetrieveNRPELabel"); - this.RetrieveNRPELabel.Name = "RetrieveNRPELabel"; - // - // RetrieveNRPEPicture - // - resources.ApplyResources(this.RetrieveNRPEPicture, "RetrieveNRPEPicture"); - this.RetrieveNRPEPicture.Name = "RetrieveNRPEPicture"; - this.RetrieveNRPEPicture.TabStop = false; + this.CheckDataGridView.ShowCellErrors = true; + this.CheckDataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.CheckDataGridView_EndEdit); // // CheckColumn // @@ -174,6 +158,24 @@ private void InitializeComponent() resources.ApplyResources(this.CriticalThresholdColumn, "CriticalThresholdColumn"); this.CriticalThresholdColumn.Name = "CriticalThresholdColumn"; // + // RetrieveNRPEPanel + // + resources.ApplyResources(this.RetrieveNRPEPanel, "RetrieveNRPEPanel"); + this.RetrieveNRPEPanel.Controls.Add(this.RetrieveNRPELabel, 1, 0); + this.RetrieveNRPEPanel.Controls.Add(this.RetrieveNRPEPicture, 0, 0); + this.RetrieveNRPEPanel.Name = "RetrieveNRPEPanel"; + // + // RetrieveNRPELabel + // + resources.ApplyResources(this.RetrieveNRPELabel, "RetrieveNRPELabel"); + this.RetrieveNRPELabel.Name = "RetrieveNRPELabel"; + // + // RetrieveNRPEPicture + // + resources.ApplyResources(this.RetrieveNRPEPicture, "RetrieveNRPEPicture"); + this.RetrieveNRPEPicture.Name = "RetrieveNRPEPicture"; + this.RetrieveNRPEPicture.TabStop = false; + // // NRPEEditPage // resources.ApplyResources(this, "$this"); diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.cs b/XenAdmin/SettingsPanels/NRPEEditPage.cs index 9bb719e6c..758526fae 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -37,15 +37,11 @@ using XenAdmin.Core; using XenAdmin.Actions.NRPE; using XenAPI; -using System.Linq; -using XenAdmin.Network; namespace XenAdmin.SettingsPanels { 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,})$"); @@ -119,8 +115,6 @@ public bool ValidToSave { _invalidParamToolTipText = ""; _invalidParamToolTip.ToolTipTitle = ""; - CheckDataGridView.ShowCellToolTips = false; - CheckDataGridView.ShowCellErrors = false; if (!EnableNRPECheckBox.Checked) { @@ -129,15 +123,23 @@ public bool ValidToSave bool valid = IsAllowHostsValid(); + DataGridViewTextBoxCell focusCellWhenErrorOccurs = null; foreach (CheckGroup checkGroup in _checkGroupList) { if (!checkGroup.CheckValue()) { - CheckDataGridView.ShowCellToolTips = true; - CheckDataGridView.ShowCellErrors = true; valid = false; + if (focusCellWhenErrorOccurs == null) + { + focusCellWhenErrorOccurs = checkGroup.NameCell; + } } } + if (focusCellWhenErrorOccurs != null) + { + CheckDataGridView.CurrentCell = CheckDataGridView.Rows[0].Cells[0]; + CheckDataGridView.CurrentCell = focusCellWhenErrorOccurs; + } return valid; } } @@ -190,7 +192,7 @@ public void SetXenObjects(IXenObject orig, IXenObject clone) UpdateRetrievingNRPETip(NRPEHostConfiguration.RetrieveNRPEStatus.Retrieving); DisableAllComponent(); - NRPERetrieveAction action = new NRPERetrieveAction(_clone, _nrpeOriginalConfig, _checkGroupDictByName, true); + NRPERetrieveAction action = new NRPERetrieveAction(_clone, _nrpeOriginalConfig, true); action.Completed += ActionCompleted; action.RunAsync(); } @@ -250,6 +252,12 @@ private void UpdateComponentValueBasedConfiguration() Color.FromKnownColor(KnownColor.ControlDark) : AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlText); DebugLogCheckBox.Checked = _nrpeOriginalConfig.Debug; SslDebugLogCheckBox.Checked = _nrpeOriginalConfig.SslLogging; + + foreach (KeyValuePair check in _nrpeOriginalConfig.CheckDict) + { + _checkGroupDictByName.TryGetValue(check.Key, out CheckGroup cg); + cg?.UpdateThreshold(check.Value.WarningThreshold, check.Value.CriticalThreshold); + } } private void UpdateComponentStatusBasedEnableNRPECheckBox() @@ -272,13 +280,14 @@ private void UpdateComponentStatusBasedEnableNRPECheckBox() checkGroup.CriticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); } } + CheckDataGridView.ShowCellToolTips = EnableNRPECheckBox.Checked; + CheckDataGridView.ShowCellErrors = EnableNRPECheckBox.Checked; } private bool IsAllowHostsValid() { _invalidParamToolTip.ToolTipTitle = Messages.NRPE_ALLOW_HOSTS_ERROR_TITLE; _invalidParamToolTip.Tag = AllowHostsTextBox; - CheckDataGridView.ShowCellToolTips = true; string str = AllowHostsTextBox.Text; if (str.Trim().Length == 0 || str.Trim().Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER)) @@ -316,7 +325,6 @@ private bool IsAllowHostsValid() return false; } } - CheckDataGridView.ShowCellToolTips = false; return true; } @@ -341,14 +349,14 @@ private void UpdateCurrentNRPEConfiguration() _nrpeCurrentConfig = new NRPEHostConfiguration { EnableNRPE = EnableNRPECheckBox.Checked, - AllowHosts = AllowHostsTextBox.Text, + AllowHosts = AllowHostsTextBox.Text.Replace(" ", string.Empty), Debug = DebugLogCheckBox.Checked, SslLogging = SslDebugLogCheckBox.Checked }; foreach (KeyValuePair item in _checkGroupDictByName) { _nrpeCurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(item.Key, - item.Value.WarningThresholdCell.Value.ToString(), item.Value.CriticalThresholdCell.Value.ToString())); + item.Value.WarningThresholdCell.Value.ToString().Trim(), item.Value.CriticalThresholdCell.Value.ToString().Trim())); } } @@ -374,5 +382,13 @@ private void AllowHostsTextBox_LostFocus(object sender, EventArgs e) AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); } } + + private void CheckDataGridView_EndEdit(object sender, DataGridViewCellEventArgs e) + { + foreach (CheckGroup checkGroup in _checkGroupList) + { + checkGroup.CheckValue(); + } + } } } diff --git a/XenAdmin/XenAdmin.csproj b/XenAdmin/XenAdmin.csproj index c60abed56..d0338e5fc 100755 --- a/XenAdmin/XenAdmin.csproj +++ b/XenAdmin/XenAdmin.csproj @@ -9,7 +9,7 @@ WinExe Properties XenAdmin - XenCenter + [XenCenter] ..\Branding\Images\AppIcon.ico v4.8 publish\ @@ -483,6 +483,10 @@ NRPEEditPage.cs + + NRPEEditPage.cs + UserControl + UserControl @@ -6816,4 +6820,4 @@ copy "$(ProjectDir)\ReportViewer\resource_report.rdlc" "$(TargetDir)" - + \ No newline at end of file diff --git a/XenModel/Actions/NRPE/CheckGroup.cs b/XenModel/Actions/NRPE/CheckGroup.cs deleted file mode 100644 index 3b23469d9..000000000 --- a/XenModel/Actions/NRPE/CheckGroup.cs +++ /dev/null @@ -1,267 +0,0 @@ -/* 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.Actions.NRPE -{ - 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.01M; - private readonly decimal THRESHOLD_MAXIMUM = 100M; - - private string name; - private string warningThresholdDefault; - private string criticalThresholdDefault; - private bool changed; - - 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 bool Changed { get => changed; set => changed = 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 = ""; - - if (IsEmptyForPool()) - { - return true; - } - - if (CheckEachValue(warningThresholdCell) && - CheckEachValue(criticalThresholdCell) && - CompareWarningAndCritical() && - CheckModifyAllForPool()) - { - return true; - } - return false; - } - - private bool IsEmptyForPool() - { - return warningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark)) - && criticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark)); - } - - 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; - } - } - - 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) - { - } - - 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) - { - 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 = ""; - return true; - } - } -} diff --git a/XenModel/Actions/NRPE/NRPERetrieveAction.cs b/XenModel/Actions/NRPE/NRPERetrieveAction.cs index 77513db45..dc5ab62ed 100644 --- a/XenModel/Actions/NRPE/NRPERetrieveAction.cs +++ b/XenModel/Actions/NRPE/NRPERetrieveAction.cs @@ -29,7 +29,6 @@ */ using System; -using System.Collections.Generic; using XenAdmin.Core; using XenAPI; @@ -41,16 +40,14 @@ public class NRPERetrieveAction : AsyncAction private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private readonly NRPEHostConfiguration _nrpeCurrentConfig; - private readonly Dictionary _checkGroupDictByName; private readonly IXenObject _clone; - public NRPERetrieveAction(IXenObject host, NRPEHostConfiguration nrpeHostConfiguration, Dictionary checkGroupDictByName, bool suppressHistory) + public NRPERetrieveAction(IXenObject host, NRPEHostConfiguration nrpeHostConfiguration, bool suppressHistory) : base(host.Connection, Messages.NRPE_ACTION_RETRIEVING, Messages.NRPE_ACTION_RETRIEVING, suppressHistory) { _clone = host; _nrpeCurrentConfig = nrpeHostConfiguration; - _checkGroupDictByName = checkGroupDictByName; } protected override void Run() @@ -65,7 +62,7 @@ protected override void Run() } catch (Exception e) { - log.ErrorFormat("Execute NRPE plugin failed, failed reason: {0}", e.Message); + log.ErrorFormat("Run NRPE plugin failed, failed reason: {0}", e.Message); _nrpeCurrentConfig.Status = NRPEHostConfiguration.RetrieveNRPEStatus.Failed; } } @@ -74,12 +71,12 @@ private void InitNRPEGeneralConfiguration(IXenObject o) { string status = Host.call_plugin(o.Connection.Session, o.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, NRPEHostConfiguration.XAPI_NRPE_STATUS, null); - log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_STATUS, status); + log.InfoFormat("Run NRPE {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_STATUS, status); _nrpeCurrentConfig.EnableNRPE = status.Trim().Equals("active enabled"); string nrpeConfig = Host.call_plugin(o.Connection.Session, o.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, null); - log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, nrpeConfig); + log.InfoFormat("Run NRPE {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, nrpeConfig); string[] nrpeConfigArray = nrpeConfig.Split('\n'); foreach (string nrpeConfigItem in nrpeConfigArray) @@ -106,21 +103,15 @@ private void InitNRPEThreshold(IXenObject o) { string nrpeThreshold = Host.call_plugin(o.Connection.Session, o.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, null); - log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, nrpeThreshold); + log.InfoFormat("Run NRPE {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, nrpeThreshold); string[] nrpeThresholdArray = nrpeThreshold.Split('\n'); foreach (string nrpeThresholdItem in nrpeThresholdArray) { // Return string format for each line: check_cpu warning threshold - 50 critical threshold - 80 string[] thresholdRtnArray = nrpeThresholdItem.Split(' '); - string checkName = thresholdRtnArray[0]; - if (_checkGroupDictByName.TryGetValue(thresholdRtnArray[0], out CheckGroup thresholdCheck)) - { - string warningThreshold = thresholdRtnArray[4]; - string criticalThreshold = thresholdRtnArray[8]; - thresholdCheck.UpdateThreshold(warningThreshold, criticalThreshold); - _nrpeCurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(checkName, warningThreshold, criticalThreshold)); - } + _nrpeCurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(thresholdRtnArray[0], + thresholdRtnArray[4], thresholdRtnArray[8])); } } diff --git a/XenModel/Actions/NRPE/NRPEUpdateAction.cs b/XenModel/Actions/NRPE/NRPEUpdateAction.cs index 47bdf9e87..366d0a5b7 100644 --- a/XenModel/Actions/NRPE/NRPEUpdateAction.cs +++ b/XenModel/Actions/NRPE/NRPEUpdateAction.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using XenAPI; @@ -60,7 +61,8 @@ protected override void Run() } else { - SetNRPEConfigureForPool(); + List hostList = ((Pool) _clone).Connection.Cache.Hosts.ToList(); + hostList.ForEach(SetNRPEConfigureForHost); } } @@ -88,10 +90,10 @@ private void SetNRPEConfigureForHost(IXenObject o) foreach (KeyValuePair kvp in _nrpeHostConfiguration.CheckDict) { NRPEHostConfiguration.Check currentCheck = kvp.Value; - _nrpeOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); - if (currentCheck != null && OriginalCheck != null - && (!currentCheck.WarningThreshold.Equals(OriginalCheck.WarningThreshold) - || !currentCheck.CriticalThreshold.Equals(OriginalCheck.CriticalThreshold))) + _nrpeOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check originalCheck); + if (currentCheck != null && originalCheck != null + && (!currentCheck.WarningThreshold.Equals(originalCheck.WarningThreshold) + || !currentCheck.CriticalThreshold.Equals(originalCheck.CriticalThreshold))) { SetNRPEThreshold(o, currentCheck.Name, currentCheck.WarningThreshold, currentCheck.CriticalThreshold); } @@ -100,22 +102,13 @@ private void SetNRPEConfigureForHost(IXenObject o) RestartNRPE(o); } - private void SetNRPEConfigureForPool() - { - List hostList = ((Pool) _clone).Connection.Cache.Hosts.ToList(); - hostList.ForEach(host => - { - SetNRPEConfigureForHost(host); - }); - } - private void SetNRPEStatus(IXenObject host, bool enableNRPE) { string nrpeUpdateStatusMethod = enableNRPE ? NRPEHostConfiguration.XAPI_NRPE_ENABLE : NRPEHostConfiguration.XAPI_NRPE_DISABLE; string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, nrpeUpdateStatusMethod, null); - log.InfoFormat("Execute nrpe {0}, return: {1}", nrpeUpdateStatusMethod, result); + log.InfoFormat("Run NRPE {0}, return: {1}", nrpeUpdateStatusMethod, result); } private void SetNRPEGeneralConfiguration(IXenObject host, string allowHosts, bool debug, bool sslLogging) @@ -128,7 +121,7 @@ private void SetNRPEGeneralConfiguration(IXenObject host, string allowHosts, boo }; string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, NRPEHostConfiguration.XAPI_NRPE_SET_CONFIG, configArgDict); - log.InfoFormat("Execute nrpe {0}, allowed_hosts={1}, debug={2}, ssl_logging={3}, return: {4}", + log.InfoFormat("Run NRPE {0}, allowed_hosts={1}, debug={2}, ssl_logging={3}, return: {4}", NRPEHostConfiguration.XAPI_NRPE_SET_CONFIG, _nrpeHostConfiguration.AllowHosts, _nrpeHostConfiguration.Debug, @@ -146,7 +139,7 @@ private void SetNRPEThreshold(IXenObject host, string checkName, string warningT }; string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, NRPEHostConfiguration.XAPI_NRPE_SET_THRESHOLD, thresholdArgDict); - log.InfoFormat("Execute nrpe {0}, check={1}, w={2}, c={3}, return: {4}", + log.InfoFormat("Run NRPE {0}, check={1}, w={2}, c={3}, return: {4}", NRPEHostConfiguration.XAPI_NRPE_SET_THRESHOLD, checkName, warningThreshold, @@ -159,7 +152,7 @@ private void RestartNRPE(IXenObject host) { string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, NRPEHostConfiguration.XAPI_NRPE_RESTART, null); - log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_RESTART, result); + log.InfoFormat("Run NRPE {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_RESTART, result); } } } diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index 9409d987a..d4cbd6173 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -29151,7 +29151,7 @@ public static string NRPE_ALLOW_HOSTS_PLACE_HOLDER { } /// - /// Looks up a localized string similar to Please remove duplicated address. + /// Looks up a localized string similar to Please remove duplicate addresses. /// public static string NRPE_ALLOW_HOSTS_SAME_ADDRESS { get { @@ -29286,7 +29286,7 @@ public static string NRPE_INACTIVE { } /// - /// Looks up a localized string similar to Retrieve NRPE configuration failed, please check XenCenter logs.. + /// Looks up a localized string similar to Failed to retrieve NRPE configuration, please check XenCenter logs.. /// public static string NRPE_RETRIEVE_FAILED { get { diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index 1df986623..54838ed18 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -10117,7 +10117,7 @@ When you configure an NFS storage repository, you simply provide the host name o Comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com - Please remove duplicated address + Please remove duplicate addresses NRPE batch configuration @@ -10162,7 +10162,7 @@ When you configure an NFS storage repository, you simply provide the host name o NRPE service is inactive - Retrieve NRPE configuration failed, please check XenCenter logs. + Failed to retrieve NRPE configuration, please check XenCenter logs. Retrieving NRPE configuration... diff --git a/XenModel/XenModel.csproj b/XenModel/XenModel.csproj index 117ab7806..1ff3f37a4 100755 --- a/XenModel/XenModel.csproj +++ b/XenModel/XenModel.csproj @@ -57,7 +57,6 @@ - @@ -89,7 +88,6 @@ - From f06fb0fc49f17f8964a852769eaee4c4aea624a5 Mon Sep 17 00:00:00 2001 From: Bengang Yuan Date: Tue, 24 Oct 2023 09:50:57 +0800 Subject: [PATCH 10/10] Resolve NRPE code review comments from Tina. --- XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs b/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs index 268a008ed..a5893066f 100644 --- a/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs +++ b/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs @@ -54,8 +54,8 @@ public CheckGroup(string name, string labelName) { Name = name; NameCell = new DataGridViewTextBoxCell { Value = labelName }; - WarningThresholdCell = new DataGridViewTextBoxCell(); - CriticalThresholdCell = new DataGridViewTextBoxCell(); + WarningThresholdCell = new DataGridViewTextBoxCell { Value = "" }; + CriticalThresholdCell = new DataGridViewTextBoxCell { Value = "" }; CheckThresholdRow = new DataGridViewRow(); CheckThresholdRow.Cells.AddRange(NameCell, WarningThresholdCell, CriticalThresholdCell); CheckThresholdRow.DefaultCellStyle.Format = "N2";