diff --git a/XenAdmin/Dialogs/GraphDetailsDialog.Designer.cs b/XenAdmin/Dialogs/GraphDetailsDialog.Designer.cs index b48ca2e97..1d7b7c17c 100644 --- a/XenAdmin/Dialogs/GraphDetailsDialog.Designer.cs +++ b/XenAdmin/Dialogs/GraphDetailsDialog.Designer.cs @@ -96,9 +96,8 @@ private void InitializeComponent() // this.dataGridView.AllowUserToAddRows = false; this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.AllowUserToResizeColumns = false; this.dataGridView.AllowUserToResizeRows = false; - this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Window; this.dataGridView.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.dataGridView.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None; @@ -237,6 +236,7 @@ private void InitializeComponent() // // ColumnDisplayOnGraph // + this.ColumnDisplayOnGraph.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle1.NullValue = false; dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Window; @@ -250,14 +250,12 @@ private void InitializeComponent() // // ColumnName // - this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; resources.ApplyResources(this.ColumnName, "ColumnName"); this.ColumnName.Name = "ColumnName"; this.ColumnName.ReadOnly = true; // // Description // - this.Description.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; resources.ApplyResources(this.Description, "Description"); this.Description.Name = "Description"; this.Description.ReadOnly = true; @@ -271,6 +269,7 @@ private void InitializeComponent() // // ColumnEnabled // + this.ColumnEnabled.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells; resources.ApplyResources(this.ColumnEnabled, "ColumnEnabled"); this.ColumnEnabled.Name = "ColumnEnabled"; this.ColumnEnabled.ReadOnly = true; diff --git a/XenAdmin/Dialogs/PropertiesDialog.cs b/XenAdmin/Dialogs/PropertiesDialog.cs index 94f72f9f4..11a29d89d 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,12 @@ private void Build() dialog.ShowDialog(Program.MainWindow); } } + 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); + } } finally { diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs b/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs new file mode 100644 index 000000000..8f9f3f24d --- /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, ToolTipText = string.Format(Messages.NRPE_METRIC_TOOLTIP, name) }; + WarningThresholdCell = new DataGridViewTextBoxCell { Value = "" }; + CriticalThresholdCell = new DataGridViewTextBoxCell { Value = "" }; + CheckThresholdRow = new DataGridViewRow(); + CheckThresholdRow.Cells.AddRange(NameCell, WarningThresholdCell, CriticalThresholdCell); + CheckThresholdRow.DefaultCellStyle.Format = "N2"; + CheckThresholdRow.DefaultCellStyle.NullValue = 0; + WarningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + CriticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + } + + public void UpdateThreshold(string warningThreshold, string criticalThreshold) + { + WarningThresholdCell.Value = warningThreshold; + CriticalThresholdCell.Value = criticalThreshold; + WarningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + CriticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + } + + public virtual bool CheckValue() + { + WarningThresholdCell.ErrorText = ""; + CriticalThresholdCell.ErrorText = ""; + + return CheckEachValue(WarningThresholdCell) && + CheckEachValue(CriticalThresholdCell) && + CompareWarningAndCritical(); + } + + protected virtual bool CheckEachValue(DataGridViewTextBoxCell cell) + { + string thresholdStr = cell.Value.ToString().Trim(); + if (thresholdStr.Equals("")) + { + cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY); + return false; + } + + if (!decimal.TryParse(thresholdStr, out decimal threshold)) + { + cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_BE_NUMBER); + return false; + } + + if (threshold < THRESHOLD_MINIMUM || threshold > THRESHOLD_MAXIMUM) + { + cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_RANGE_ERROR, THRESHOLD_MINIMUM, + THRESHOLD_MAXIMUM); + return false; + } + + cell.ErrorText = ""; + return true; + } + + protected virtual bool CompareWarningAndCritical() + { + decimal.TryParse(WarningThresholdCell.Value.ToString().Trim(), out decimal warningDecimal); + decimal.TryParse(CriticalThresholdCell.Value.ToString().Trim(), out decimal criticalDecimal); + if (warningDecimal < criticalDecimal) + { + WarningThresholdCell.ErrorText = ""; + return true; + } + else + { + WarningThresholdCell.ErrorText = + string.Format(Messages.NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL); + return false; + } + } + } + + public class FreeCheckGroup : CheckGroup + { + public FreeCheckGroup(string name, string labelName) + : base(name, labelName) + { + } + + protected override bool CompareWarningAndCritical() + { + decimal.TryParse(WarningThresholdCell.Value.ToString().Trim(), out decimal warningDecimal); + decimal.TryParse(CriticalThresholdCell.Value.ToString().Trim(), out decimal criticalDecimal); + if (warningDecimal > criticalDecimal) + { + WarningThresholdCell.ErrorText = ""; + return true; + } + else + { + WarningThresholdCell.ErrorText = + string.Format(Messages.NRPE_THRESHOLD_WARNING_SHOULD_BIGGER_THAN_CRITICAL); + return false; + } + } + + } + + public class HostLoadCheckGroup : CheckGroup + { + public HostLoadCheckGroup(string name, string labelName) + : base(name, labelName) + { + } + } + + public class Dom0LoadCheckGroup : CheckGroup + { + public Dom0LoadCheckGroup(string name, string labelName) + : base(name, labelName) + { + } + + protected override bool CompareWarningAndCritical() + { + string[] warningArray = WarningThresholdCell.Value.ToString().Split(','); + string[] criticalArray = CriticalThresholdCell.Value.ToString().Split(','); + for (int i = 0; i < 3; i++) + { + decimal.TryParse(warningArray[i].Trim(), out decimal warningDecimal); + decimal.TryParse(criticalArray[i].Trim(), out decimal criticalDecimal); + if (warningDecimal > criticalDecimal) + { + WarningThresholdCell.ErrorText = + string.Format(Messages.NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL); + return false; + } + } + + WarningThresholdCell.ErrorText = ""; + return true; + } + + protected override bool CheckEachValue(DataGridViewTextBoxCell cell) + { + cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_BE_3_NUMBERS); + string[] loadArray = cell.Value.ToString().Split(','); + if (loadArray.Length != 3) + { + return false; + } + + foreach (string load in loadArray) + { + bool isDecimal = decimal.TryParse(load, out _); + if (!isDecimal) + { + return false; + } + } + + cell.ErrorText = ""; + return true; + } + } + } +} diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs new file mode 100644 index 000000000..2fee41b34 --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs @@ -0,0 +1,218 @@ +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)); + this.NRPETableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + 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(); + 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 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(); + this.SuspendLayout(); + // + // NRPETableLayoutPanel + // + 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, 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 + // + resources.ApplyResources(this.DescLabelHost, "DescLabelHost"); + this.DescLabelHost.Name = "DescLabelHost"; + // + // EnableNRPECheckBox + // + resources.ApplyResources(this.EnableNRPECheckBox, "EnableNRPECheckBox"); + this.EnableNRPECheckBox.Name = "EnableNRPECheckBox"; + this.EnableNRPECheckBox.UseVisualStyleBackColor = true; + this.EnableNRPECheckBox.CheckedChanged += new System.EventHandler(this.EnableNRPECheckBox_CheckedChanged); + // + // 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.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"; + // + // 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.BackgroundColor = System.Drawing.SystemColors.Window; + 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.Name = "CheckDataGridView"; + this.CheckDataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; + this.CheckDataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; + this.CheckDataGridView.ShowCellErrors = true; + this.CheckDataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.CheckDataGridView_EndEdit); + // + // CheckColumn + // + this.CheckColumn.FillWeight = 40F; + resources.ApplyResources(this.CheckColumn, "CheckColumn"); + this.CheckColumn.Name = "CheckColumn"; + this.CheckColumn.ReadOnly = true; + // + // WarningThresholdColumn + // + this.WarningThresholdColumn.FillWeight = 30F; + resources.ApplyResources(this.WarningThresholdColumn, "WarningThresholdColumn"); + this.WarningThresholdColumn.Name = "WarningThresholdColumn"; + // + // CriticalThresholdColumn + // + this.CriticalThresholdColumn.FillWeight = 30F; + 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"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.Controls.Add(this.NRPETableLayoutPanel); + this.Name = "NRPEEditPage"; + this.NRPETableLayoutPanel.ResumeLayout(false); + this.NRPETableLayoutPanel.PerformLayout(); + this.GeneralConfigureGroupBox.ResumeLayout(false); + 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(); + this.ResumeLayout(false); + + } + + #endregion + 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.Label RetrieveNRPELabel; + private System.Windows.Forms.TableLayoutPanel RetrieveNRPEPanel; + private System.Windows.Forms.PictureBox RetrieveNRPEPicture; + 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 new file mode 100644 index 000000000..6dd28e0ca --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -0,0 +1,384 @@ +/* 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.Text.RegularExpressions; +using System.Windows.Forms; +using XenAdmin.Actions; +using XenAdmin.Core; +using XenAdmin.Actions.NRPE; +using XenAPI; + +namespace XenAdmin.SettingsPanels +{ + public partial class NRPEEditPage : UserControl, IEditPage + { + 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 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 NRPEHostConfiguration _nrpeOriginalConfig; + private NRPEHostConfiguration _nrpeCurrentConfig; + + public Image Image => Images.StaticImages._000_Module_h32bit_16; + + public NRPEEditPage() + { + InitializeComponent(); + Text = Messages.NRPE; + + _nrpeOriginalConfig = new NRPEHostConfiguration + { + EnableNRPE = false, + AllowHosts = NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER, + Debug = false, + SslLogging = false + }; + + _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); + } + + AllowHostsTextBox.Text = NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER; + AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + AllowHostsTextBox.GotFocus += AllowHostsTextBox_GotFocus; + AllowHostsTextBox.LostFocus += AllowHostsTextBox_LostFocus; + + _invalidParamToolTip = new ToolTip + { + IsBalloon = true, + ToolTipIcon = ToolTipIcon.Warning, + ToolTipTitle = Messages.INVALID_PARAMETER, + Tag = AllowHostsTextBox + }; + } + + public string SubText => Messages.NRPE_EDIT_PAGE_TEXT; + + public bool ValidToSave + { + get + { + _invalidParamToolTipText = ""; + _invalidParamToolTip.ToolTipTitle = ""; + + if (!EnableNRPECheckBox.Checked) + { + return true; + } + + bool valid = IsAllowHostsValid(); + + DataGridViewTextBoxCell focusCellWhenErrorOccurs = null; + foreach (CheckGroup checkGroup in _checkGroupList) + { + if (!checkGroup.CheckValue()) + { + valid = false; + if (focusCellWhenErrorOccurs == null) + { + focusCellWhenErrorOccurs = checkGroup.NameCell; + } + } + } + if (focusCellWhenErrorOccurs != null) + { + CheckDataGridView.CurrentCell = CheckDataGridView.Rows[0].Cells[0]; + CheckDataGridView.CurrentCell = focusCellWhenErrorOccurs; + } + return valid; + } + } + + public bool HasChanged + { + get + { + UpdateCurrentNRPEConfiguration(); + return !_nrpeCurrentConfig.Equals(_nrpeOriginalConfig); + } + } + + 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) + { + _invalidParamToolTip.Hide(ctrl); + } + } + + public AsyncAction SaveSettings() + { + return new NRPEUpdateAction(_clone, _nrpeCurrentConfig, _nrpeOriginalConfig, true); + } + + public void SetXenObjects(IXenObject orig, IXenObject clone) + { + _clone = clone; + _isHost = _clone is Host; + + DescLabelHost.Visible = _isHost; + DescLabelPool.Visible = !_isHost; + UpdateRetrievingNRPETip(NRPEHostConfiguration.RetrieveNRPEStatus.Retrieving); + DisableAllComponent(); + + NRPERetrieveAction action = new NRPERetrieveAction(_clone, _nrpeOriginalConfig, true); + action.Completed += ActionCompleted; + action.RunAsync(); + } + + private void ActionCompleted(ActionBase sender) + { + Program.Invoke(this.Parent, UpdateRetrieveStatus); + } + + private void UpdateRetrieveStatus() + { + if (_nrpeOriginalConfig.Status == NRPEHostConfiguration.RetrieveNRPEStatus.Successful) + { + EnableNRPECheckBox.Enabled = true; + UpdateComponentValueBasedConfiguration(); + UpdateComponentStatusBasedEnableNRPECheckBox(); + } + UpdateRetrievingNRPETip(_nrpeOriginalConfig.Status); + } + + private void UpdateRetrievingNRPETip(NRPEHostConfiguration.RetrieveNRPEStatus status) + { + switch (status) + { + 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; + default: + throw new ArgumentOutOfRangeException(nameof(status), status, null); + } + } + + private void DisableAllComponent() + { + 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; + + foreach (KeyValuePair check in _nrpeOriginalConfig.CheckDict) + { + _checkGroupDictByName.TryGetValue(check.Key, out CheckGroup cg); + cg?.UpdateThreshold(check.Value.WarningThreshold, check.Value.CriticalThreshold); + } + } + + 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); + foreach (var checkGroup in _checkGroupList) + { + 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 = EnableNRPECheckBox.Checked; + CheckDataGridView.ShowCellErrors = EnableNRPECheckBox.Checked; + } + + private bool IsAllowHostsValid() + { + _invalidParamToolTip.ToolTipTitle = Messages.NRPE_ALLOW_HOSTS_ERROR_TITLE; + _invalidParamToolTip.Tag = AllowHostsTextBox; + + 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; + } + } + } + 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 UpdateCurrentNRPEConfiguration() + { + _nrpeCurrentConfig = new NRPEHostConfiguration + { + EnableNRPE = EnableNRPECheckBox.Checked, + 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().Trim(), item.Value.CriticalThresholdCell.Value.ToString().Trim())); + } + } + + private void EnableNRPECheckBox_CheckedChanged(object sender, EventArgs e) + { + UpdateComponentStatusBasedEnableNRPECheckBox(); + } + + 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_EndEdit(object sender, DataGridViewCellEventArgs e) + { + foreach (CheckGroup checkGroup in _checkGroupList) + { + checkGroup.CheckValue(); + } + } + } +} diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.resx b/XenAdmin/SettingsPanels/NRPEEditPage.resx new file mode 100644 index 000000000..a8f49ac6f --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.resx @@ -0,0 +1,650 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + 1 + + + True + + + + Fill + + + NoControl + + + + 3, 0 + + + 3, 0, 3, 10 + + + 644, 26 + + + 0 + + + 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 pool. + + + DescLabelPool + + + XenAdmin.Controls.Common.AutoHeightLabel, [XenCenter], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + + NRPETableLayoutPanel + + + 0 + + + True + + + Fill + + + NoControl + + + 3, 36 + + + 3, 0, 3, 10 + + + 644, 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 + + + XenAdmin.Controls.Common.AutoHeightLabel, [XenCenter], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + + NRPETableLayoutPanel + + + 1 + + + True + + + NoControl + + + 3, 75 + + + 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 + + + 2 + + + True + + + GrowAndShrink + + + 2 + + + Left + + + True + + + NoControl + + + 3, 6 + + + 96, 13 + + + 0 + + + &Monitoring servers: + + + AllowHostsLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 0 + + + Left, Right + + + 105, 3 + + + 530, 20 + + + 1 + + + AllowHostsTextBox + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 1 + + + True + + + NoControl + + + 3, 29 + + + 3, 0, 0, 0 + + + 211, 17 + + + 2 + + + Record &debugging messages to syslog + + + DebugLogCheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 2 + + + True + + + NoControl + + + 3, 52 + + + 3, 0, 0, 0 + + + 181, 17 + + + 3 + + + Record &SSL messages to syslog + + + SslDebugLogCheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 3 + + + Top + + + 3, 16 + + + 3 + + + 638, 72 + + + 0 + + + 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="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, 103 + + + 3, 3, 3, 10 + + + 3, 3, 3, 0 + + + 644, 100 + + + 3 + + + General Configuration + + + GeneralConfigureGroupBox + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 3 + + + Metric + + + 100 + + + True + + + Warning Threshold + + + 100 + + + True + + + Critical Threshold + + + 100 + + + Fill + + + 3, 216 + + + 62 + + + None + + + 644, 273 + + + 4 + + + CheckDataGridView + + + XenAdmin.Controls.DataGridViewEx.DataGridViewEx, [XenCenter], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + + NRPETableLayoutPanel + + + 4 + + + True + + + 2 + + + Top, Bottom, Left, Right + + + NoControl + + + 24, 0 + + + 619, 21 + + + 5 + + + Retrieving NRPE configuration... + + + MiddleLeft + + + RetrieveNRPELabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + RetrieveNRPEPanel + + + 0 + + + NoControl + + + 2, 2 + + + 2, 2, 2, 2 + + + 17, 17 + + + 6 + + + RetrieveNRPEPicture + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + RetrieveNRPEPanel + + + 1 + + + 2, 494 + + + 2, 2, 2, 2 + + + 1 + + + 646, 21 + + + 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 + + + 0, 0 + + + 3, 10, 3, 0 + + + 8 + + + 650, 537 + + + 0 + + + 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="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,20" /></TableLayoutSettings> + + + True + + + 96, 96 + + + True + + + 650, 537 + + + 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 ce61eca48..e17cbd15f 100755 --- a/XenAdmin/XenAdmin.csproj +++ b/XenAdmin/XenAdmin.csproj @@ -480,6 +480,16 @@ NetworkOptionsEditPage.cs + + UserControl + + + NRPEEditPage.cs + + + NRPEEditPage.cs + UserControl + UserControl @@ -2107,6 +2117,10 @@ Designer HostPowerONEditPage.cs + + NRPEEditPage.cs + Designer + Designer PerfmonAlertOptionsPage.cs diff --git a/XenModel/Actions/NRPE/NRPEHostConfiguration.cs b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs new file mode 100644 index 000000000..c9668a98a --- /dev/null +++ b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs @@ -0,0 +1,144 @@ +/* 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.Actions.NRPE +{ + public class NRPEHostConfiguration : ICloneable, IEquatable + { + 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 XAPI_NRPE_CONTROL = "control"; + + public const string DEBUG_ENABLE = "1"; + public const string DEBUG_DISABLE = "0"; + + 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(); + + 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 RetrieveNRPEStatus Status { get; set; } + + public enum RetrieveNRPEStatus + { + Retrieving, + Successful, + Failed + } + + public class Check + { + public string Name { get; } + public string WarningThreshold { get; } + public string CriticalThreshold{ get; } + + public Check(string name, string warningThreshold, string criticalThreshold) + { + Name = name; + WarningThreshold = warningThreshold; + CriticalThreshold = criticalThreshold; + } + + } + + 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 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 + { + EnableNRPE = EnableNRPE, + AllowHosts = AllowHosts, + Debug = Debug, + SslLogging = SslLogging + }; + foreach (KeyValuePair kvp in _checkDict) + { + 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..dc5ab62ed --- /dev/null +++ b/XenModel/Actions/NRPE/NRPERetrieveAction.cs @@ -0,0 +1,134 @@ +/* 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 XenAdmin.Core; +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 IXenObject _clone; + + public NRPERetrieveAction(IXenObject host, NRPEHostConfiguration nrpeHostConfiguration, bool suppressHistory) + : base(host.Connection, Messages.NRPE_ACTION_RETRIEVING, Messages.NRPE_ACTION_RETRIEVING, suppressHistory) + { + _clone = host; + _nrpeCurrentConfig = nrpeHostConfiguration; + } + + protected override void Run() + { + _nrpeCurrentConfig.Status = NRPEHostConfiguration.RetrieveNRPEStatus.Successful; + // For pool, retrieve the configuration from the master of the pool. + IXenObject o = _clone is Pool p ? Helpers.GetCoordinator(p) : _clone; + try + { + InitNRPEGeneralConfiguration(o); + InitNRPEThreshold(o); + } + catch (Exception e) + { + log.ErrorFormat("Run NRPE plugin failed, failed reason: {0}", e.Message); + _nrpeCurrentConfig.Status = NRPEHostConfiguration.RetrieveNRPEStatus.Failed; + } + } + + 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("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("Run 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(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("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(' '); + _nrpeCurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(thresholdRtnArray[0], + thresholdRtnArray[4], thresholdRtnArray[8])); + } + } + + private static 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 new file mode 100644 index 000000000..82733ef3b --- /dev/null +++ b/XenModel/Actions/NRPE/NRPEUpdateAction.cs @@ -0,0 +1,180 @@ +/* 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.Linq; +using XenAPI; + + +namespace XenAdmin.Actions.NRPE +{ + 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.NRPE_ACTION_CHANGING, Messages.NRPE_ACTION_CHANGING, suppressHistory) + { + _clone = host; + _nrpeHostConfiguration = nrpeHostConfiguration; + _nrpeOriginalConfig = nrpeOriginalConfig; + } + + protected override void Run() + { + if (_clone is Host) + { + SetNRPEConfigureForHost(_clone); + } + else + { + List hostList = ((Pool) _clone).Connection.Cache.Hosts.ToList(); + hostList.ForEach(SetNRPEConfigureForHost); + } + } + + private void SetNRPEConfigureForHost(IXenObject o) + { + // Enable/Disable NRPE + if (!_nrpeHostConfiguration.EnableNRPE == _nrpeOriginalConfig.EnableNRPE) + { + SetNRPEStatus(o, _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(o, _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(o, currentCheck.Name, currentCheck.WarningThreshold, currentCheck.CriticalThreshold); + } + } + + RestartNRPE(o); + } + + private void SetNRPEStatus(IXenObject host, bool enableNRPE) + { + // Workaround for CA-384579 (caused by CA-384572): + // If the certificate used by NRPE was generated in Yangtze it has no permissions. + // We prevent command (start, restart, etc) failures by calling control, which modifies certificate permissions. + // After CA-384572 is resolved we will remove this workaround code. + if (enableNRPE) + { + Dictionary enableDict = new Dictionary + { + { "enable", "true" } + }; + try + { + string controlResult = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_CONTROL, enableDict); + log.InfoFormat("Run NRPE {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_CONTROL, controlResult); + } + catch (Exception e) + { + log.ErrorFormat("Run NRPE {0} failed, error: {1}", NRPEHostConfiguration.XAPI_NRPE_CONTROL, e.Message); + } + } + + 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("Run 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("Run 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("Run 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("Run NRPE {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_RESTART, result); + } + } +} diff --git a/XenModel/FriendlyNames.Designer.cs b/XenModel/FriendlyNames.Designer.cs index d1c0652b1..c6a0c86c8 100644 --- a/XenModel/FriendlyNames.Designer.cs +++ b/XenModel/FriendlyNames.Designer.cs @@ -5282,6 +5282,15 @@ public static string Message_name_wlb_vm_relocation { } } + /// + /// Looks up a localized string similar to Host CPU Load. + /// + public static string OPERATIONAL_METRICS_HOSTLOAD { + get { + return ResourceManager.GetString("OPERATIONAL_METRICS_HOSTLOAD", resourceCulture); + } + } + /// /// Looks up a localized string similar to There was an error in preparing the host for upgrade.. /// diff --git a/XenModel/FriendlyNames.resx b/XenModel/FriendlyNames.resx index 59865a153..91c4dede7 100644 --- a/XenModel/FriendlyNames.resx +++ b/XenModel/FriendlyNames.resx @@ -1859,6 +1859,9 @@ WLB VM Relocation + + Host CPU Load + There was an error in preparing the host for upgrade. diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index bf9759448..d580f79aa 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -29123,6 +29123,294 @@ 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. + /// + public static string NRPE_ACTION_CHANGING { + get { + return ResourceManager.GetString("NRPE_ACTION_CHANGING", resourceCulture); + } + } + + /// + /// 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. + /// + public static string NRPE_ACTIVE { + get { + return ResourceManager.GetString("NRPE_ACTIVE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Monitoring servers 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 Monitoring servers 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 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 { + 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 Please remove duplicate addresses. + /// + 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. + /// + 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 Usage (%). + /// + public static string NRPE_CHECK_VGPU { + get { + return ResourceManager.GetString("NRPE_CHECK_VGPU", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host vGPU Memory 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 NRPE check name: {0}. + /// + public static string NRPE_METRIC_TOOLTIP { + get { + return ResourceManager.GetString("NRPE_METRIC_TOOLTIP", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Failed to retrieve NRPE configuration, 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}.. + /// + 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 consist of 3 comma separated numbers.. + /// + 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 a 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 greater 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 c0ca9f592..865d0ea2c 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -10107,6 +10107,102 @@ When you configure an NFS storage repository, you simply provide the host name o Now + + NRPE + + + Changing NRPE configuration + + + Retrieving NRPE configuration + + + NRPE service is active + + + Monitoring servers should not be empty. + + + Monitoring servers format is not correct + + + 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 + + + Please remove duplicate addresses + + + 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 Usage (%) + + + Host vGPU Memory Usage (%) + + + NRPE Configuration + + + NRPE service is inactive + + + NRPE check name: {0} + + + Failed to retrieve NRPE configuration, please check XenCenter logs. + + + Retrieving NRPE configuration... + + + Threshold value should range from {0} to {1}. + + + Threshold value should consist of 3 comma separated numbers. + + + Threshold value should be a number. + + + Threshold value should not be empty. + + + Warning threshold should be greater than critical threshold. + + + Warning threshold should be less than critical threshold. + Number of snapshots to keep @@ -15077,7 +15173,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. @@ -15105,4 +15201,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 } } diff --git a/XenModel/Utils/Helpers.cs b/XenModel/Utils/Helpers.cs index 2c1e46b73..4853dbc69 100755 --- a/XenModel/Utils/Helpers.cs +++ b/XenModel/Utils/Helpers.cs @@ -671,6 +671,7 @@ public static string ToStringI18N(this DataSourceCategory category) static Regex XapiMemoryRegex = new Regex("^xapi_(allocation|free_memory|live_memory|memory_usage)_kib$"); static Regex StatefileLatencyRegex = new Regex("^statefile/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/latency$"); static Regex LoadAvgRegex = new Regex("loadavg"); + static Regex HostLoadRegex = new Regex("hostload"); static Regex SrRegex = new Regex("^sr_[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}_cache_(size|hits|misses)"); static Regex SrIORegex = new Regex("^(io_throughput|iops)_(read|write|total)_([a-f0-9]{8})$"); static Regex SrOtherRegex = new Regex("^(latency|avgqu_sz|inflight|iowait)_([a-f0-9]{8})$"); @@ -706,6 +707,9 @@ public static DataSourceCategory GetDataSourceCategory(string name) if (LoadAvgRegex.IsMatch(name)) return DataSourceCategory.LoadAverage; + if (HostLoadRegex.IsMatch(name)) + return DataSourceCategory.LoadAverage; + if (name.StartsWith("pvsaccelerator")) return DataSourceCategory.Pvs; @@ -899,6 +903,9 @@ private static string GetFriendlyDataSourceName_(string name, IXenObject iXenObj if (LoadAvgRegex.IsMatch(name)) return FriendlyNameManager.GetFriendlyName("Label-performance.loadavg"); + if (HostLoadRegex.IsMatch(name)) + return FriendlyNames.OPERATIONAL_METRICS_HOSTLOAD; + return FriendlyNameManager.GetFriendlyName(string.Format("Label-performance.{0}", name)); } diff --git a/XenModel/XenModel.csproj b/XenModel/XenModel.csproj index b0b30a5ca..2285f0acf 100755 --- a/XenModel/XenModel.csproj +++ b/XenModel/XenModel.csproj @@ -88,6 +88,8 @@ + + @@ -198,6 +200,7 @@ +