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..a5893066f --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs @@ -0,0 +1,213 @@ +/* Copyright (c) Cloud Software Group, Inc. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +using System.Drawing; +using System.Windows.Forms; + +namespace XenAdmin.SettingsPanels +{ + public partial class NRPEEditPage + { + public class CheckGroup + { + private const decimal THRESHOLD_MINIMUM = 0.01M; + private const decimal THRESHOLD_MAXIMUM = 100M; + + public string Name { get; } + + public DataGridViewRow CheckThresholdRow { get; } + + public DataGridViewTextBoxCell NameCell { get; } + + public DataGridViewTextBoxCell WarningThresholdCell { get; } + + public DataGridViewTextBoxCell CriticalThresholdCell { get; } + + public CheckGroup(string name, string labelName) + { + Name = name; + NameCell = new DataGridViewTextBoxCell { Value = labelName }; + WarningThresholdCell = new DataGridViewTextBoxCell { 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..af65fa8f5 --- /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; + 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.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..758526fae --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -0,0 +1,394 @@ +/* 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; + } + } + } + foreach (string host in hostArray) + { + if (!REGEX_IPV4.Match(host.Trim()).Success && + !REGEX_IPV4_CIDR.Match(host.Trim()).Success && + !REGEX_DOMAIN.Match(host.Trim()).Success) + { + _invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR; + return false; + } + } + 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..3250d8794 --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.resx @@ -0,0 +1,671 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + 4, 0 + + + 4, 0, 4, 15 + + + 967, 40 + + + 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 + + + 4, 55 + + + 4, 0, 4, 15 + + + 967, 40 + + + 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 + + + 4, 114 + + + 4, 4, 4, 12 + + + 4, 0, 0, 0 + + + 137, 24 + + + 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 + + + 4, 7 + + + 4, 0, 4, 0 + + + 142, 20 + + + 0 + + + &Monitoring servers: + + + AllowHostsLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 0 + + + Left, Right + + + 154, 4 + + + 4, 4, 4, 4 + + + 801, 26 + + + 1 + + + AllowHostsTextBox + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 1 + + + True + + + NoControl + + + 4, 38 + + + 4, 4, 4, 4 + + + 4, 0, 0, 0 + + + 313, 24 + + + 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 + + + 4, 70 + + + 4, 4, 4, 4 + + + 4, 0, 0, 0 + + + 269, 24 + + + 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 + + + 4, 23 + + + 4, 4, 4, 4 + + + 3 + + + 959, 98 + + + 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,30" /></TableLayoutSettings> + + + Fill + + + 4, 154 + + + 4, 4, 4, 15 + + + 4, 4, 4, 0 + + + 967, 150 + + + 3 + + + General Configuration + + + GeneralConfigureGroupBox + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 3 + + + 34 + + + Metric + + + 100 + + + True + + + Warning Threshold + + + 100 + + + True + + + Critical Threshold + + + 100 + + + Fill + + + 4, 323 + + + 4, 4, 4, 4 + + + 62 + + + None + + + 967, 411 + + + 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 + + + 36, 0 + + + 4, 0, 4, 0 + + + 928, 32 + + + 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 + + + 3, 3 + + + 26, 26 + + + 6 + + + RetrieveNRPEPicture + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + RetrieveNRPEPanel + + + 1 + + + 3, 741 + + + 1 + + + 968, 32 + + + 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 + + + 4, 15, 4, 0 + + + 8 + + + 975, 806 + + + 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,30" /></TableLayoutSettings> + + + True + + + 144, 144 + + + True + + + 4, 4, 4, 4 + + + 975, 806 + + + CheckColumn + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + WarningThresholdColumn + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + CriticalThresholdColumn + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPEEditPage + + + System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/XenAdmin/XenAdmin.csproj b/XenAdmin/XenAdmin.csproj index 6f449aa5c..d0338e5fc 100755 --- a/XenAdmin/XenAdmin.csproj +++ b/XenAdmin/XenAdmin.csproj @@ -477,6 +477,16 @@ NetworkOptionsEditPage.cs + + UserControl + + + NRPEEditPage.cs + + + NRPEEditPage.cs + UserControl + UserControl @@ -2104,6 +2114,10 @@ Designer HostPowerONEditPage.cs + + NRPEEditPage.cs + Designer + Designer PerfmonAlertOptionsPage.cs diff --git a/XenModel/Actions/NRPE/NRPEHostConfiguration.cs b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs new file mode 100644 index 000000000..31154b329 --- /dev/null +++ b/XenModel/Actions/NRPE/NRPEHostConfiguration.cs @@ -0,0 +1,143 @@ +/* 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 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..366d0a5b7 --- /dev/null +++ b/XenModel/Actions/NRPE/NRPEUpdateAction.cs @@ -0,0 +1,158 @@ +/* Copyright (c) Cloud Software Group, Inc. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +using System.Collections.Generic; +using System.Linq; +using System.Threading; +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) + { + 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/Messages.Designer.cs b/XenModel/Messages.Designer.cs index 2d47ae38c..d4cbd6173 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -29078,6 +29078,285 @@ 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 Memory Usage (%). + /// + public static string NRPE_CHECK_VGPU { + get { + return ResourceManager.GetString("NRPE_CHECK_VGPU", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host vGPU Usage (%). + /// + public static string NRPE_CHECK_VGPU_MEMORY { + get { + return ResourceManager.GetString("NRPE_CHECK_VGPU_MEMORY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to NRPE Configuration. + /// + public static string NRPE_EDIT_PAGE_TEXT { + get { + return ResourceManager.GetString("NRPE_EDIT_PAGE_TEXT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to NRPE service is inactive. + /// + public static string NRPE_INACTIVE { + get { + return ResourceManager.GetString("NRPE_INACTIVE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 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 2e4f0691d..54838ed18 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -10092,6 +10092,99 @@ 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 Memory Usage (%) + + + Host vGPU Usage (%) + + + NRPE Configuration + + + NRPE service is inactive + + + 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 @@ -15056,7 +15149,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. @@ -15084,4 +15177,4 @@ Do you want to synchronize immediately? Only synchronize &visible - + \ No newline at end of file diff --git a/XenModel/Utils/Helpers.Versions.cs b/XenModel/Utils/Helpers.Versions.cs index eccfe9652..a1740bede 100644 --- a/XenModel/Utils/Helpers.Versions.cs +++ b/XenModel/Utils/Helpers.Versions.cs @@ -528,6 +528,12 @@ public static bool XapiEqualOrGreater_23_18_0(IXenConnection conn) return coordinator == null || ProductVersionCompare(coordinator.GetXapiVersion(), "23.18.0") >= 0; } + public static bool XapiEqualOrGreater_23_27_0(IXenConnection conn) + { + var coordinator = GetCoordinator(conn); + return coordinator == null || ProductVersionCompare(coordinator.GetXapiVersion(), "23.27.0") >= 0; + } + #endregion } } diff --git a/XenModel/XenModel.csproj b/XenModel/XenModel.csproj index 13349a2b8..1ff3f37a4 100755 --- a/XenModel/XenModel.csproj +++ b/XenModel/XenModel.csproj @@ -88,6 +88,8 @@ + + @@ -198,6 +200,7 @@ +