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); }); }