From 53fdfa0768bb6a87da4e4fb545435631f3afe14c Mon Sep 17 00:00:00 2001 From: Bengang Yuan Date: Thu, 14 Sep 2023 14:49:46 +0800 Subject: [PATCH] CP-44372: Integrate NRPE UI with backend interface --- XenAdmin/Dialogs/PropertiesDialog.cs | 6 + XenAdmin/Images.cs | 1 + XenAdmin/Images/000_NRPE_h32bit_16.png | Bin 0 -> 15586 bytes XenAdmin/Properties/Resources.Designer.cs | 10 + XenAdmin/Properties/Resources.resx | 3 + .../SettingsPanels/NRPEEditPage.CheckGroup.cs | 260 ++++++++ .../SettingsPanels/NRPEEditPage.Designer.cs | 229 +++++++ XenAdmin/SettingsPanels/NRPEEditPage.cs | 397 +++++++++++ XenAdmin/SettingsPanels/NRPEEditPage.resx | 615 ++++++++++++++++++ XenAdmin/XenAdmin.csproj | 15 + XenModel/Actions/Host/NRPEUpdateAction.cs | 191 ++++++ XenModel/Messages.Designer.cs | 234 +++++++ XenModel/Messages.resx | 80 ++- XenModel/NRPE/NRPEHostConfiguration.cs | 109 ++++ XenModel/XenModel.csproj | 2 + 15 files changed, 2151 insertions(+), 1 deletion(-) create mode 100644 XenAdmin/Images/000_NRPE_h32bit_16.png create mode 100644 XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs create mode 100644 XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs create mode 100644 XenAdmin/SettingsPanels/NRPEEditPage.cs create mode 100644 XenAdmin/SettingsPanels/NRPEEditPage.resx create mode 100644 XenModel/Actions/Host/NRPEUpdateAction.cs create mode 100644 XenModel/NRPE/NRPEHostConfiguration.cs diff --git a/XenAdmin/Dialogs/PropertiesDialog.cs b/XenAdmin/Dialogs/PropertiesDialog.cs index 94f72f9f4..a6dda37d7 100755 --- a/XenAdmin/Dialogs/PropertiesDialog.cs +++ b/XenAdmin/Dialogs/PropertiesDialog.cs @@ -82,6 +82,7 @@ public partial class PropertiesDialog : VerticallyTabbedDialog private ClusteringEditPage ClusteringEditPage; private SrReadCachingEditPage SrReadCachingEditPage; private PoolAdvancedEditPage _poolAdvancedEditPage; + private NRPEEditPage NRPEEditPage; #endregion private readonly IXenObject _xenObjectBefore, _xenObjectCopy; @@ -317,6 +318,11 @@ private void Build() dialog.ShowDialog(Program.MainWindow); } } + if (isHost || isPool) + { + NRPEEditPage = new NRPEEditPage(isHost); + ShowTab(NRPEEditPage); + } } finally { diff --git a/XenAdmin/Images.cs b/XenAdmin/Images.cs index 8d74e5df1..ea8e5dc0c 100644 --- a/XenAdmin/Images.cs +++ b/XenAdmin/Images.cs @@ -701,6 +701,7 @@ public static class StaticImages public static Bitmap _000_NewStorage_h32bit_32 = Properties.Resources._000_NewStorage_h32bit_32; public static Bitmap _000_NewVirtualAppliance_h32bit_16 = Properties.Resources._000_NewVirtualAppliance_h32bit_16; public static Bitmap _000_NewVirtualAppliance_h32bit_32 = Properties.Resources._000_NewVirtualAppliance_h32bit_32; + public static Bitmap _000_NRPE_h32bit_16 = Properties.Resources._000_NRPE_h32bit_16; public static Bitmap _000_Optimize_h32bit_16 = Properties.Resources._000_Optimize_h32bit_16; public static Bitmap _000_Patch_h32bit_16 = Properties.Resources._000_Patch_h32bit_16; public static Bitmap _000_Patch_h32bit_32 = Properties.Resources._000_Patch_h32bit_32; diff --git a/XenAdmin/Images/000_NRPE_h32bit_16.png b/XenAdmin/Images/000_NRPE_h32bit_16.png new file mode 100644 index 0000000000000000000000000000000000000000..ca16fb9163da4ba30599318f6096cf7293292065 GIT binary patch literal 15586 zcmeI3e{>Yp6~`wbNRkQyjT$A?J!^s?I6E`DJNskUT}`qHiLe-xRYEom z&V=1WPAdUgMd)cQ2p$D&#THL{IHCeteimZ+5koPxv_dT<{1S|X7J*s~^v!OvyLs8X zlhfMMe`e3woxSh-?!7agcki3|XP&K^J8OLQ-Pst1jjyb5SA*k3^_zJM_`T=KO%@z< zTt&49!`cfl?CB*K_Qg$byntb?B!*qA$1r9shTSPW|HOOcU~X2hV!n)F6FSvz+Ugk- zreK)8PxRI*wVpW)C;1I5FEt2;h(8EsW0>QCNRZ_g2#T&jXc7ZX{iPjy^g5Au>gUlO z(i1Edn#GFtkWkY;*UPmp;OxBq0avyo!hisNL1A?fzb_y&5vM*HmjVCPVM4EqPEi&( z^~GvJU9G1|S1N@B9c{4S97&mVR=a_sEmphrew`861Zg9TBu?5H+Qg7X-M~lh$_D=& zA-<8Rc9##N1C~?YtSCW-Aj09WA#5^8p(cW|+wBBtB#cHJ%)sTgfWk)bfP8N($Y30| zAafxxsEATPr^aO)q*leL*Q<%*pMmT02jhtX@&G$Pk%+KCf-;aqDkq+c`vhARfWCI)Nb@x*hdJYT;*WolU|TL=&gAWi8hd)tBn zQ7y<)Ylsud7J^H;H`UcEVq;=)hD1`85zk$Sh$FbEO3W=<3b7S(fNNz+LjtQvA+IF) zT(K&v8bqioEsa){u5g|h;H9uU-9f-EiSZX_XBud$y@99f zIBzjixY=a3;r2#Wzi0ik0X3omgXeB!hO+DcM3 zyMUX(5vM4D##vf0V$;5GkiIRd1OZ0F^1p6NAOPZrz3lEZ6X$x($usm)u z^ETW_nvJ+ku-S0RMspNJ+DtayGMFMom|>|ZL>W|TTT&H+T8{2)HA2hK(Luo{Mt7(n z8o3$D$5(gTp%r^Jf;X?C)R1Fsd1Z`@#(0m|O!vz6Bn;I@OA4t`3K|s)^h6~LHQZ-x<5VWb`Li2%C z4HpCiZECpCd>~cB1pz^u8ZI;+NY!vbK+vX!3(W^oHCzx7w5j1j^MOJ9#Fd?Rg;NNC_cp`e1s?BDrf+oh*YTCcp&?YP-|-=#gp_4zjr z9AB4PGp~H_wH0$tRBuSs!YrSER4+x-0YbtOq++%)!^8FTiR zyz-Z49yz&!t;_qY<)@RrpJtN}8LEohb@lDNIlFh~9{Bjv`?kD&>>r1Ea(BM8Yv~_v zBhp{q*gmn+kk%p^-Ai(^$Bp|X`R%{w{BywKt!-gNH#4}!f%ztb@7&8bC4=%xCL=CArDPrW^STNc&4wer9{ z*UlVk`IXhbEtH+t`thrm3T$_;FV6Ir%yF&1zPRSC4Szp7YyX!U8jpPO(Th}C<YW{*j5+Q7 z+3F`(oP7N9r}&I>SDd%3Iz6r{uXyt01#kTNgB?rghLiISpZ=_5=^D9p&-wSSF0a}( z`#KRhb8+YREBnHaS+_mI?A^S4-}bW;diwrmc{QW|MEl+>Ny`}Ubnh}jj{oAK8AgYWh$W4oqM8Ncup9sZ$b(e`&c+z*}2 zsXMlKYIa@vjHS0`bw77??eV-#tMb#wF50y9#~bfTJ8) zx>=dt_q)8E9Xqx@_gZ@2M_(RvMQ$&i(esmn{_Z?mfA>3!m`>utQ+vxhUNUV}-z=^y Lo9o_OQs41!$_q&_ literal 0 HcmV?d00001 diff --git a/XenAdmin/Properties/Resources.Designer.cs b/XenAdmin/Properties/Resources.Designer.cs index d0f382452..27f802c70 100755 --- a/XenAdmin/Properties/Resources.Designer.cs +++ b/XenAdmin/Properties/Resources.Designer.cs @@ -780,6 +780,16 @@ internal static System.Drawing.Bitmap _000_NewVirtualAppliance_h32bit_32 { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap _000_NRPE_h32bit_16 { + get { + object obj = ResourceManager.GetObject("_000_NRPE_h32bit_16", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/XenAdmin/Properties/Resources.resx b/XenAdmin/Properties/Resources.resx index 58f0396a1..d42c7ce36 100755 --- a/XenAdmin/Properties/Resources.resx +++ b/XenAdmin/Properties/Resources.resx @@ -1159,4 +1159,7 @@ ..\Images\rpm_package.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Images\000_NRPE_h32bit_16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs b/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs new file mode 100644 index 000000000..4133c3120 --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.CheckGroup.cs @@ -0,0 +1,260 @@ +/* Copyright (c) Cloud Software Group, Inc. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +using System.Drawing; +using System.Windows.Forms; + +namespace XenAdmin.SettingsPanels +{ + public partial class NRPEEditPage + { + + public class CheckGroup + { + private static readonly string DEFAULT_CHECK_WARNING_THRESHOLD = "80"; + private static readonly string DEFAULT_CHECK_CRITICAL_THRESHOLD = "90"; + + private readonly decimal THRESHOLD_MINIMUM = 0.1M; + private readonly decimal THRESHOLD_MAXIMUM = 100M; + + private string name; + private string warningThresholdDefault; + private string criticalThresholdDefault; + + protected DataGridViewRow checkThresholdRow; + protected DataGridViewTextBoxCell nameCell; + protected DataGridViewTextBoxCell warningThresholdCell; + protected DataGridViewTextBoxCell criticalThresholdCell; + + public string Name { get => name; set => name = value; } + public string WarningThresholdDefault { get => warningThresholdDefault; set => warningThresholdDefault = value; } + public string CriticalThresholdDefault { get => criticalThresholdDefault; set => criticalThresholdDefault = value; } + public DataGridViewRow CheckThresholdRow { get => checkThresholdRow; set => checkThresholdRow = value; } + public DataGridViewTextBoxCell NameCell { get => nameCell; set => nameCell = value; } + public DataGridViewTextBoxCell WarningThresholdCell { get => warningThresholdCell; set => warningThresholdCell = value; } + public DataGridViewTextBoxCell CriticalThresholdCell { get => criticalThresholdCell; set => criticalThresholdCell = value; } + + public CheckGroup(string name, string labelName, string warningThresholdDefaultValue, string criticalThresholdDefaultValue) + { + InitCheckGroup(name, labelName, warningThresholdDefaultValue, criticalThresholdDefaultValue); + } + + public CheckGroup(string name, string labelName) + { + InitCheckGroup(name, labelName, DEFAULT_CHECK_WARNING_THRESHOLD, DEFAULT_CHECK_CRITICAL_THRESHOLD); + } + + private void InitCheckGroup(string name, string labelName, string warningThresholdDefaultValue, string criticalThresholdDefaultValue) + { + Name = name; + nameCell = new DataGridViewTextBoxCell { Value = labelName }; + warningThresholdDefault = warningThresholdDefaultValue; + criticalThresholdDefault = criticalThresholdDefaultValue; + warningThresholdCell = new DataGridViewTextBoxCell { Value = warningThresholdDefaultValue }; + criticalThresholdCell = new DataGridViewTextBoxCell { Value = criticalThresholdDefaultValue }; + checkThresholdRow = new DataGridViewRow(); + checkThresholdRow.Cells.AddRange(nameCell, warningThresholdCell, criticalThresholdCell); + checkThresholdRow.DefaultCellStyle.Format = "N2"; + checkThresholdRow.DefaultCellStyle.NullValue = 0; + warningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + criticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + } + + public void UpdateThreshold(string warningThreshold, string criticalThreshold) + { + warningThresholdCell.Value = warningThreshold; + criticalThresholdCell.Value = criticalThreshold; + warningThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + criticalThresholdCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + } + + public virtual bool CheckValue() + { + warningThresholdCell.ErrorText = ""; + criticalThresholdCell.ErrorText = ""; + checkThresholdRow.DataGridView.ShowCellToolTips = false; + + if (IsEmptyForPool()) + { + return true; + } + + if (CheckEachValue(warningThresholdCell) && + CheckEachValue(criticalThresholdCell) && + CompareWarningAndCritical() && + CheckModifyAllForPool()) + { + return true; + } + + checkThresholdRow.DataGridView.ShowCellToolTips = true; + return false; + } + + private bool IsEmptyForPool() + { + return warningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark)) + && criticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark)); + } + + private bool CheckEachValue(DataGridViewTextBoxCell cell) + { + string thresholdStr = cell.Value.ToString().Trim(); + if (thresholdStr.Equals("")) + { + cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY); + return false; + } + if (!decimal.TryParse(thresholdStr, out decimal threshold)) + { + cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_BE_NUMBER); + return false; + } + if (threshold < THRESHOLD_MINIMUM || threshold > THRESHOLD_MAXIMUM) + { + cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_RANGE_ERROR, THRESHOLD_MINIMUM, THRESHOLD_MAXIMUM); + return false; + } + cell.ErrorText = ""; + return true; + } + + protected virtual bool CompareWarningAndCritical() + { + decimal.TryParse(warningThresholdCell.Value.ToString().Trim(), out decimal warningDecimal); + decimal.TryParse(criticalThresholdCell.Value.ToString().Trim(), out decimal criticalDecimal); + if (warningDecimal < criticalDecimal) + { + warningThresholdCell.ErrorText = ""; + return true; + } + else + { + warningThresholdCell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL); + return false; + } + } + + private bool CheckModifyAllForPool() + { + if (warningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText)) + && criticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark))) + { + criticalThresholdCell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY); + return false; + } + else if (warningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark)) + && criticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText))) + { + warningThresholdCell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY); + return false; + } + return true; + } + } + + public class FreeCheckGroup : CheckGroup + { + private static readonly string DEFAULT_CHECK_WARNING_THRESHOLD = "20"; + private static readonly string DEFAULT_CHECK_CRITICAL_THRESHOLD = "10"; + + public FreeCheckGroup(string name, string labelName) + : base(name, labelName, DEFAULT_CHECK_WARNING_THRESHOLD, DEFAULT_CHECK_CRITICAL_THRESHOLD) + { + } + + protected override bool CompareWarningAndCritical() + { + decimal.TryParse(warningThresholdCell.Value.ToString().Trim(), out decimal warningDecimal); + decimal.TryParse(criticalThresholdCell.Value.ToString().Trim(), out decimal criticalDecimal); + if (warningDecimal > criticalDecimal) + { + warningThresholdCell.ErrorText = ""; + return true; + } + else + { + warningThresholdCell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_WARNING_SHOULD_BIGGER_THAN_CRITICAL); + return false; + } + } + + } + + public class HostLoadCheckGroup : CheckGroup + { + private static readonly string DEFAULT_CHECK_WARNING_THRESHOLD = "3"; + private static readonly string DEFAULT_CHECK_CRITICAL_THRESHOLD = "4"; + + public HostLoadCheckGroup(string name, string labelName) + : base(name, labelName, DEFAULT_CHECK_WARNING_THRESHOLD, DEFAULT_CHECK_CRITICAL_THRESHOLD) + { + } + } + + public class Dom0LoadCheckGroup : CheckGroup + { + private static readonly string DEFAULT_CHECK_WARNING_THRESHOLD = "2.7,2.6,2.5"; + private static readonly string DEFAULT_CHECK_CRITICAL_THRESHOLD = "3.2,3.1,3"; + + public Dom0LoadCheckGroup(string name, string labelName) + : base(name, labelName, DEFAULT_CHECK_WARNING_THRESHOLD, DEFAULT_CHECK_CRITICAL_THRESHOLD) + { + } + + public override bool CheckValue() + { + return (CheckEachValue(warningThresholdCell) && CheckEachValue(criticalThresholdCell)); + } + + private bool CheckEachValue(DataGridViewTextBoxCell cell) + { + checkThresholdRow.DataGridView.ShowCellToolTips = true; + cell.ErrorText = string.Format(Messages.NRPE_THRESHOLD_SHOULD_BE_3_NUMBERS); + string[] loadArray = cell.Value.ToString().Split(','); + if (loadArray.Length != 3) + { + return false; + } + foreach (string load in loadArray) + { + bool isDecimal = decimal.TryParse(load, out _); + if (!isDecimal) + { + return false; + } + } + cell.ErrorText = ""; + checkThresholdRow.DataGridView.ShowCellToolTips = false; + return true; + } + } + } +} diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs new file mode 100644 index 000000000..d5bcfdf00 --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.Designer.cs @@ -0,0 +1,229 @@ +using System.Windows.Forms; +using DataGridView = System.Windows.Forms.DataGridView; + +namespace XenAdmin.SettingsPanels +{ + partial class NRPEEditPage + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NRPEEditPage)); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + this.NRPETableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.PoolTipsTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.PoolTipsPicture = new System.Windows.Forms.PictureBox(); + this.PoolTipsLabel = new System.Windows.Forms.Label(); + this.DescLabel = new System.Windows.Forms.Label(); + this.GeneralConfigureGroupBox = new System.Windows.Forms.GroupBox(); + this.GeneralConfigTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.EnableNRPECheckBox = new System.Windows.Forms.CheckBox(); + this.AllowHostsLabel = new System.Windows.Forms.Label(); + this.AllowHostsTextBox = new System.Windows.Forms.TextBox(); + this.DebugLogCheckBox = new System.Windows.Forms.CheckBox(); + this.SslDebugLogCheckBox = new System.Windows.Forms.CheckBox(); + this.CheckDataGridView = new System.Windows.Forms.DataGridView(); + this.CheckColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.WarningThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.CriticalThresholdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.NRPETableLayoutPanel.SuspendLayout(); + this.PoolTipsTableLayoutPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.PoolTipsPicture)).BeginInit(); + this.GeneralConfigureGroupBox.SuspendLayout(); + this.GeneralConfigTableLayoutPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).BeginInit(); + this.SuspendLayout(); + // + // NRPETableLayoutPanel + // + resources.ApplyResources(this.NRPETableLayoutPanel, "NRPETableLayoutPanel"); + this.NRPETableLayoutPanel.Controls.Add(this.PoolTipsTableLayoutPanel, 0, 4); + this.NRPETableLayoutPanel.Controls.Add(this.DescLabel, 0, 0); + this.NRPETableLayoutPanel.Controls.Add(this.GeneralConfigureGroupBox, 0, 1); + this.NRPETableLayoutPanel.Controls.Add(this.CheckDataGridView, 0, 2); + this.NRPETableLayoutPanel.Name = "NRPETableLayoutPanel"; + // + // PoolTipsTableLayoutPanel + // + resources.ApplyResources(this.PoolTipsTableLayoutPanel, "PoolTipsTableLayoutPanel"); + this.PoolTipsTableLayoutPanel.Controls.Add(this.PoolTipsPicture, 0, 0); + this.PoolTipsTableLayoutPanel.Controls.Add(this.PoolTipsLabel, 1, 0); + this.PoolTipsTableLayoutPanel.Name = "PoolTipsTableLayoutPanel"; + // + // PoolTipsPicture + // + resources.ApplyResources(this.PoolTipsPicture, "PoolTipsPicture"); + this.PoolTipsPicture.Image = global::XenAdmin.Properties.Resources._000_Info3_h32bit_16; + this.PoolTipsPicture.Name = "PoolTipsPicture"; + this.PoolTipsPicture.TabStop = false; + // + // PoolTipsLabel + // + resources.ApplyResources(this.PoolTipsLabel, "PoolTipsLabel"); + this.PoolTipsLabel.Name = "PoolTipsLabel"; + // + // DescLabel + // + resources.ApplyResources(this.DescLabel, "DescLabel"); + this.DescLabel.Name = "DescLabel"; + // + // GeneralConfigureGroupBox + // + resources.ApplyResources(this.GeneralConfigureGroupBox, "GeneralConfigureGroupBox"); + this.GeneralConfigureGroupBox.Controls.Add(this.GeneralConfigTableLayoutPanel); + this.GeneralConfigureGroupBox.Name = "GeneralConfigureGroupBox"; + this.GeneralConfigureGroupBox.TabStop = false; + // + // GeneralConfigTableLayoutPanel + // + resources.ApplyResources(this.GeneralConfigTableLayoutPanel, "GeneralConfigTableLayoutPanel"); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.EnableNRPECheckBox, 0, 1); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.AllowHostsLabel, 0, 2); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.AllowHostsTextBox, 1, 2); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.DebugLogCheckBox, 0, 3); + this.GeneralConfigTableLayoutPanel.Controls.Add(this.SslDebugLogCheckBox, 0, 4); + this.GeneralConfigTableLayoutPanel.Name = "GeneralConfigTableLayoutPanel"; + // + // EnableNRPECheckBox + // + resources.ApplyResources(this.EnableNRPECheckBox, "EnableNRPECheckBox"); + this.GeneralConfigTableLayoutPanel.SetColumnSpan(this.EnableNRPECheckBox, 2); + this.EnableNRPECheckBox.Name = "EnableNRPECheckBox"; + this.EnableNRPECheckBox.UseVisualStyleBackColor = true; + this.EnableNRPECheckBox.CheckedChanged += new System.EventHandler(this.EnableNRPECheckBox_CheckedChanged); + // + // AllowHostsLabel + // + resources.ApplyResources(this.AllowHostsLabel, "AllowHostsLabel"); + this.AllowHostsLabel.Name = "AllowHostsLabel"; + // + // AllowHostsTextBox + // + resources.ApplyResources(this.AllowHostsTextBox, "AllowHostsTextBox"); + this.AllowHostsTextBox.Name = "AllowHostsTextBox"; + // + // DebugLogCheckBox + // + resources.ApplyResources(this.DebugLogCheckBox, "DebugLogCheckBox"); + this.GeneralConfigTableLayoutPanel.SetColumnSpan(this.DebugLogCheckBox, 2); + this.DebugLogCheckBox.Name = "DebugLogCheckBox"; + this.DebugLogCheckBox.UseVisualStyleBackColor = true; + // + // SslDebugLogCheckBox + // + resources.ApplyResources(this.SslDebugLogCheckBox, "SslDebugLogCheckBox"); + this.GeneralConfigTableLayoutPanel.SetColumnSpan(this.SslDebugLogCheckBox, 2); + this.SslDebugLogCheckBox.Name = "SslDebugLogCheckBox"; + this.SslDebugLogCheckBox.UseVisualStyleBackColor = true; + // + // CheckDataGridView + // + this.CheckDataGridView.AllowUserToAddRows = false; + this.CheckDataGridView.AllowUserToDeleteRows = false; + this.CheckDataGridView.AllowUserToResizeRows = false; + resources.ApplyResources(this.CheckDataGridView, "CheckDataGridView"); + this.CheckDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.CheckDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; + this.CheckDataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.CheckDataGridView.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.CheckDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.CheckColumn, + this.WarningThresholdColumn, + this.CriticalThresholdColumn}); + this.CheckDataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; + this.CheckDataGridView.EnableHeadersVisualStyles = false; + this.CheckDataGridView.MultiSelect = false; + this.CheckDataGridView.Name = "CheckDataGridView"; + this.CheckDataGridView.RowHeadersVisible = false; + this.CheckDataGridView.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.CheckDataGridView_BeginEdit); + this.CheckDataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.CheckDataGridView_EndEdit); + // + // CheckColumn + // + this.CheckColumn.FillWeight = 103.4483F; + resources.ApplyResources(this.CheckColumn, "CheckColumn"); + this.CheckColumn.Name = "CheckColumn"; + this.CheckColumn.ReadOnly = true; + // + // WarningThresholdColumn + // + dataGridViewCellStyle1.Format = "N2"; + dataGridViewCellStyle1.NullValue = null; + this.WarningThresholdColumn.DefaultCellStyle = dataGridViewCellStyle1; + this.WarningThresholdColumn.FillWeight = 98.27586F; + resources.ApplyResources(this.WarningThresholdColumn, "WarningThresholdColumn"); + this.WarningThresholdColumn.Name = "WarningThresholdColumn"; + // + // CriticalThresholdColumn + // + this.CriticalThresholdColumn.FillWeight = 98.27586F; + resources.ApplyResources(this.CriticalThresholdColumn, "CriticalThresholdColumn"); + this.CriticalThresholdColumn.Name = "CriticalThresholdColumn"; + // + // NRPEEditPage + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.Controls.Add(this.NRPETableLayoutPanel); + this.Name = "NRPEEditPage"; + this.NRPETableLayoutPanel.ResumeLayout(false); + this.NRPETableLayoutPanel.PerformLayout(); + this.PoolTipsTableLayoutPanel.ResumeLayout(false); + this.PoolTipsTableLayoutPanel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.PoolTipsPicture)).EndInit(); + this.GeneralConfigureGroupBox.ResumeLayout(false); + this.GeneralConfigTableLayoutPanel.ResumeLayout(false); + this.GeneralConfigTableLayoutPanel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.CheckDataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private TableLayoutPanel NRPETableLayoutPanel; + + private Label DescLabel; + + private GroupBox GeneralConfigureGroupBox; + private TableLayoutPanel GeneralConfigTableLayoutPanel; + + private CheckBox EnableNRPECheckBox; + private Label AllowHostsLabel; + private TextBox AllowHostsTextBox; + private CheckBox DebugLogCheckBox; + private CheckBox SslDebugLogCheckBox; + + private DataGridView CheckDataGridView; + private DataGridViewTextBoxColumn CheckColumn; + private DataGridViewTextBoxColumn WarningThresholdColumn; + private DataGridViewTextBoxColumn CriticalThresholdColumn; + + private TableLayoutPanel PoolTipsTableLayoutPanel; + private PictureBox PoolTipsPicture; + private Label PoolTipsLabel; + } +} \ No newline at end of file diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.cs b/XenAdmin/SettingsPanels/NRPEEditPage.cs new file mode 100644 index 000000000..65192e52d --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.cs @@ -0,0 +1,397 @@ +/* Copyright (c) Cloud Software Group, Inc. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +using System; +using System.Drawing; +using System.Windows.Forms; +using XenAPI; +using XenAdmin.Actions; +using System.Collections.Generic; +using XenAdmin.Core; +using System.Text.RegularExpressions; + +namespace XenAdmin.SettingsPanels +{ + public partial class NRPEEditPage : UserControl, IEditPage + { + private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + + private static readonly Regex REGEX_IPV4 = new Regex("^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)"); + private static readonly Regex REGEX_IPV4_CIDR = new Regex("^([0-9]{1,3}\\.){3}[0-9]{1,3}(\\/([0-9]|[1-2][0-9]|3[0-2]))?$"); + private static readonly Regex REGEX_DOMAIN = new Regex("^(((?!-))(xn--|_)?[a-z0-9-]{0,61}[a-z0-9]{1,1}\\.)*(xn--)?([a-z0-9][a-z0-9\\-]{0,60}|[a-z0-9-]{1,30}\\.[a-z]{2,})$"); + + private readonly bool IsHost = true; + + private IXenObject Clone; + private readonly ToolTip InvalidParamToolTip; + private string InvalidParamToolTipText = ""; + + private readonly List CheckGroupList = new List(); + private readonly Dictionary CheckGroupDictByName = new Dictionary(); + private readonly Dictionary CheckGroupDictByLabel = new Dictionary(); + + private NRPEHostConfiguration NRPEOriginalConfig; + private NRPEHostConfiguration NRPECurrentConfig; + public string SubText + { + get + { + if (IsHost) + { + return EnableNRPECheckBox.Checked ? Messages.NRPE_ACTIVE : Messages.NRPE_INACTIVE; + } + else + { + return Messages.NRPE_BATCH_CONFIGURATION; + } + } + } + + public Image Image => Images.StaticImages._000_NRPE_h32bit_16; + + public NRPEEditPage(bool isHost) + { + IsHost = isHost; + InitializeComponent(); + Text = "NRPE"; + + NRPECurrentConfig = new NRPEHostConfiguration + { + EnableNRPE = false, + AllowHosts = NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER, + Debug = false, + SslLogging = false + }; + NRPEOriginalConfig = (NRPEHostConfiguration) NRPECurrentConfig.Clone(); + + EnableNRPECheckBox.DataBindings.Add("Checked", NRPECurrentConfig, "enableNRPE"); + AllowHostsTextBox.DataBindings.Add("Text", NRPECurrentConfig, "allowHosts"); + DebugLogCheckBox.DataBindings.Add("Checked", NRPECurrentConfig, "debug"); + SslDebugLogCheckBox.DataBindings.Add("Checked", NRPECurrentConfig, "sslLogging"); + + CheckGroupList.Add(new HostLoadCheckGroup("check_host_load", Messages.NRPE_CHECK_HOST_LOAD)); + CheckGroupList.Add(new CheckGroup("check_host_cpu", Messages.NRPE_CHECK_HOST_CPU)); + CheckGroupList.Add(new CheckGroup("check_host_memory", Messages.NRPE_CHECK_HOST_MEMORY)); + CheckGroupList.Add(new CheckGroup("check_vgpu", Messages.NRPE_CHECK_VGPU)); + CheckGroupList.Add(new CheckGroup("check_vgpu_memory", Messages.NRPE_CHECK_VGPU_MEMORY)); + CheckGroupList.Add(new Dom0LoadCheckGroup("check_load", Messages.NRPE_CHECK_LOAD)); + CheckGroupList.Add(new CheckGroup("check_cpu", Messages.NRPE_CHECK_CPU)); + CheckGroupList.Add(new CheckGroup("check_memory", Messages.NRPE_CHECK_MEMORY)); + CheckGroupList.Add(new FreeCheckGroup("check_swap", Messages.NRPE_CHECK_SWAP)); + CheckGroupList.Add(new FreeCheckGroup("check_disk_root", Messages.NRPE_CHECK_DISK_ROOT)); + CheckGroupList.Add(new FreeCheckGroup("check_disk_log", Messages.NRPE_CHECK_DISK_LOG)); + + foreach (CheckGroup checkGroup in CheckGroupList) + { + CheckDataGridView.Rows.Add(checkGroup.CheckThresholdRow); + CheckGroupDictByName.Add(checkGroup.Name, checkGroup); + CheckGroupDictByLabel.Add(checkGroup.NameCell.Value.ToString(), checkGroup); + } + + UpdateOtherComponentBasedEnableNRPECheckBox(false); + + AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + AllowHostsTextBox.GotFocus += AllowHostsTextBox_GotFocus; + AllowHostsTextBox.LostFocus += AllowHostsTextBox_LostFocus; + + if (isHost) + { + PoolTipsPicture.Hide(); + PoolTipsLabel.Hide(); + } + InvalidParamToolTip = new ToolTip + { + IsBalloon = true, + ToolTipIcon = ToolTipIcon.Warning, + ToolTipTitle = Messages.INVALID_PARAMETER, + Tag = AllowHostsTextBox + }; + } + + public bool ValidToSave + { + get + { + InvalidParamToolTipText = ""; + InvalidParamToolTip.ToolTipTitle = ""; + CheckDataGridView.ShowCellToolTips = false; + + if (!EnableNRPECheckBox.Checked) + { + return true; + } + + bool valid = true; + if (!IsAllowHostsValid()) + { + valid = false; + } + + foreach (CheckGroup checkGroup in CheckGroupList) + { + if (!checkGroup.CheckValue()) + { + valid = false; + } + } + return valid; + } + } + + public bool HasChanged + { + get + { + return true; + } + } + + public void Cleanup() + { + } + + public void ShowLocalValidationMessages() + { + if (InvalidParamToolTip.Tag is Control ctrl) + { + InvalidParamToolTip.Hide(ctrl); + if (!InvalidParamToolTipText.Equals("")) + { + HelpersGUI.ShowBalloonMessage(ctrl, InvalidParamToolTip, InvalidParamToolTipText); + } + } + } + + public void HideLocalValidationMessages() + { + if (InvalidParamToolTip.Tag is Control ctrl && ctrl != null) + { + InvalidParamToolTip.Hide(ctrl); + } + } + + public void SetXenObjects(IXenObject orig, IXenObject clone) + { + Clone = clone; + if (IsHost) + { + InitNRPEGeneralConfiguration(); + InitNRPEThreshold(); + } + } + + public AsyncAction SaveSettings() + { + foreach (KeyValuePair item in CheckGroupDictByName) + { + if (item.Value.WarningThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText)) + && item.Value.CriticalThresholdCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlText))) + { + NRPECurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(item.Key, + item.Value.WarningThresholdCell.Value.ToString(), item.Value.CriticalThresholdCell.Value.ToString())); + } + } + return new NRPEUpdateAction(Clone, NRPECurrentConfig, NRPEOriginalConfig, false); + } + + private void InitNRPEGeneralConfiguration() + { + string status = Host.call_plugin(Clone.Connection.Session, Clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_STATUS, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_STATUS, status); + NRPECurrentConfig.EnableNRPE = status.Trim().Equals("active enabled"); + + string nrpeConfig = Host.call_plugin(Clone.Connection.Session, Clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_CONFIG, nrpeConfig); + + string[] nrpeConfigArray = nrpeConfig.Split('\n'); + foreach (string nrpeConfigItem in nrpeConfigArray) + { + if (nrpeConfigItem.Trim().StartsWith("allowed_hosts:")) + { + string allowHosts = nrpeConfigItem.Replace("allowed_hosts:", "").Trim(); + NRPECurrentConfig.AllowHosts = AllowHostsWithoutLocalAddress(allowHosts); + AllowHostsTextBox.ForeColor = AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ? + Color.FromKnownColor(KnownColor.ControlDark) : Color.FromKnownColor(KnownColor.ControlText); + } + else if (nrpeConfigItem.Trim().StartsWith("debug:")) + { + string enableDebug = nrpeConfigItem.Replace("debug:", "").Trim(); + NRPECurrentConfig.Debug = enableDebug.Equals(NRPEHostConfiguration.DEBUG_ENABLE); + } + else if (nrpeConfigItem.Trim().StartsWith("ssl_logging:")) + { + string enableSslLogging = nrpeConfigItem.Replace("ssl_logging:", "").Trim(); + NRPECurrentConfig.SslLogging = enableSslLogging.Equals(NRPEHostConfiguration.SSL_LOGGING_ENABLE); + } + } + NRPEOriginalConfig = (NRPEHostConfiguration) NRPECurrentConfig.Clone(); + + UpdateOtherComponentBasedEnableNRPECheckBox(EnableNRPECheckBox.Checked); + } + + private void InitNRPEThreshold() + { + string nrpeThreshold = Host.call_plugin(Clone.Connection.Session, Clone.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_GET_THRESHOLD, nrpeThreshold); + + string[] nrpeThresholdArray = nrpeThreshold.Split('\n'); + foreach (string nrpeThresholdItem in nrpeThresholdArray) + { + // Return string format for each line: check_cpu warning threshold - 50 critical threshold - 80 + string[] thresholdRtnArray = nrpeThresholdItem.Split(' '); + string checkName = thresholdRtnArray[0]; + if (CheckGroupDictByName.TryGetValue(thresholdRtnArray[0], out CheckGroup thresholdCheck)) + { + string warningThreshold = thresholdRtnArray[4]; + string criticalThreshold = thresholdRtnArray[8]; + thresholdCheck.UpdateThreshold(warningThreshold, criticalThreshold); + NRPEOriginalConfig.AddNRPECheck(new NRPEHostConfiguration.Check(checkName, warningThreshold, criticalThreshold)); + } + } + } + + private bool IsAllowHostsValid() + { + InvalidParamToolTip.ToolTipTitle = Messages.NRPE_ALLOW_HOSTS_ERROR_TITLE; + InvalidParamToolTip.Tag = AllowHostsTextBox; + CheckDataGridView.ShowCellToolTips = true; + + string str = AllowHostsTextBox.Text; + if (str.Trim().Length == 0 || str.Trim().Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER)) + { + InvalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_EMPTY_ERROR; + return false; + } + + string[] hostArray = str.Split(','); + foreach (string host in hostArray) + { + if (!REGEX_IPV4.Match(host.Trim()).Success && + !REGEX_IPV4_CIDR.Match(host.Trim()).Success && + !REGEX_DOMAIN.Match(host.Trim()).Success) + { + InvalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR; + return false; + } + } + CheckDataGridView.ShowCellToolTips = false; + return true; + } + + private string AllowHostsWithoutLocalAddress(string allowHosts) + { + string UpdatedAllowHosts = ""; + string[] AllowHostArray = allowHosts.Split(','); + foreach (string allowHost in AllowHostArray) + { + if (!allowHost.Trim().Equals("127.0.0.1") && + !allowHost.Trim().Equals("::1")) + { + UpdatedAllowHosts += allowHost + ","; + } + } + return UpdatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER : + UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1); + } + + private void UpdateOtherComponentBasedEnableNRPECheckBox(bool check) + { + if (check) + { + AllowHostsTextBox.Enabled = true; + AllowHostsLabel.Enabled = true; + DebugLogCheckBox.Enabled = true; + SslDebugLogCheckBox.Enabled = true; + CheckDataGridView.Enabled = true; + CheckDataGridView.BackgroundColor = Color.FromKnownColor(KnownColor.Window); + CheckDataGridView.DefaultCellStyle.BackColor = Color.FromKnownColor(KnownColor.Window); + } + else + { + AllowHostsTextBox.Enabled = false; + AllowHostsLabel.Enabled = false; + DebugLogCheckBox.Enabled = false; + SslDebugLogCheckBox.Enabled = false; + CheckDataGridView.Enabled = false; + CheckDataGridView.BackgroundColor = Color.FromKnownColor(KnownColor.Control); + CheckDataGridView.DefaultCellStyle.BackColor = Color.FromKnownColor(KnownColor.Control); + } + } + + private void EnableNRPECheckBox_CheckedChanged(object sender, EventArgs e) + { + UpdateOtherComponentBasedEnableNRPECheckBox(EnableNRPECheckBox.Checked); + } + + private void AllowHostsTextBox_GotFocus(object sender, EventArgs e) + { + if (AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER)) + { + AllowHostsTextBox.Text = ""; + AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + } + } + + private void AllowHostsTextBox_LostFocus(object sender, EventArgs e) + { + if (string.IsNullOrWhiteSpace(AllowHostsTextBox.Text)) + { + AllowHostsTextBox.Text = NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER; + AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + } + } + + private void CheckDataGridView_BeginEdit(object sender, DataGridViewCellCancelEventArgs e) + { + DataGridViewCell currentCell = CheckDataGridView.CurrentRow.Cells[e.ColumnIndex]; + if (!IsHost && currentCell.Style.ForeColor.Equals(Color.FromKnownColor(KnownColor.ControlDark))) + { + currentCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlText); + currentCell.Value = ""; + } + } + + private void CheckDataGridView_EndEdit(object sender, DataGridViewCellEventArgs e) + { + DataGridViewCell currentCell = CheckDataGridView.CurrentRow.Cells[e.ColumnIndex]; + if (!IsHost && currentCell.Value.ToString().Trim().Equals("")) + { + currentCell.Style.ForeColor = Color.FromKnownColor(KnownColor.ControlDark); + CheckGroupDictByLabel.TryGetValue(CheckDataGridView.CurrentRow.Cells[0].Value.ToString(), out CheckGroup checkGroup); + currentCell.Value = currentCell.ColumnIndex == 1 ? + checkGroup.WarningThresholdDefault : (object)checkGroup.CriticalThresholdDefault; + } + } + } +} diff --git a/XenAdmin/SettingsPanels/NRPEEditPage.resx b/XenAdmin/SettingsPanels/NRPEEditPage.resx new file mode 100644 index 000000000..1359a1cf6 --- /dev/null +++ b/XenAdmin/SettingsPanels/NRPEEditPage.resx @@ -0,0 +1,615 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Top, Left, Right + + + + True + + + 1 + + + Top, Left, Right + + + True + + + 2 + + + Left + + + + + + NoControl + + + + + + + 0, 7 + + + 0, 0, 0, 0 + + + 18, 17 + + + 17 + + + PoolTipsPicture + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + PoolTipsTableLayoutPanel + + + 0 + + + Top, Bottom, Left, Right + + + True + + + NoControl + + + 23, 3 + + + 3, 3, 3, 3 + + + 600, 0 + + + 600, 26 + + + 16 + + + For the pool properties, there will not be showing the real configuration values in every host. When clicking OK, NRPE configuration and check threshold will be sent to all the hosts in this pool. + + + MiddleLeft + + + PoolTipsLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + PoolTipsTableLayoutPanel + + + 1 + + + 3, 407 + + + 1 + + + 641, 32 + + + 5 + + + PoolTipsTableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="PoolTipsPicture" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="PoolTipsLabel" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="Absolute,20,AutoSize,0" /><Rows Styles="Percent,100" /></TableLayoutSettings> + + + Top, Bottom, Left, Right + + + True + + + NoControl + + + 3, 0 + + + 641, 26 + + + 5 + + + NRPE (Nagios Remote Plugin Excutor) allow you to execute Nagios plugins on a remote host. You can modify NRPE general configuration and NRPE Check threshold in this page. + + + DescLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 1 + + + Top, Bottom, Left, Right + + + Top, Bottom, Left, Right + + + 2 + + + Top, Left, Right + + + True + + + NoControl + + + 3, 3 + + + 636, 17 + + + 0 + + + Enable NRPE + + + EnableNRPECheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 0 + + + NoControl + + + 3, 23 + + + 100, 24 + + + 1 + + + Allow Hosts: + + + MiddleLeft + + + AllowHostsLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 1 + + + Left, Right + + + 120, 25 + + + 3, 0, 20, 0 + + + 502, 20 + + + 2 + + + AllowHostsTextBox + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 2 + + + Top, Left, Right + + + True + + + NoControl + + + 3, 50 + + + 636, 17 + + + 3 + + + Record debugging message to syslog + + + DebugLogCheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 3 + + + Top, Left, Right + + + True + + + NoControl + + + 3, 73 + + + 636, 17 + + + 4 + + + Record SSL message to syslog + + + SslDebugLogCheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigTableLayoutPanel + + + 4 + + + 10, 12 + + + 3, 3, 3, 0 + + + 6 + + + 642, 93 + + + 13 + + + GeneralConfigTableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + GeneralConfigureGroupBox + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="EnableNRPECheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="AllowHostsLabel" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="AllowHostsTextBox" Row="2" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="DebugLogCheckBox" Row="3" RowSpan="1" Column="0" ColumnSpan="2" /><Control Name="SslDebugLogCheckBox" Row="4" RowSpan="1" Column="0" ColumnSpan="2" /></Controls><Columns Styles="Percent,18.36735,Percent,81.63265" /><Rows Styles="Absolute,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0" /></TableLayoutSettings> + + + 3, 29 + + + 3, 0, 3, 0 + + + 641, 118 + + + 7 + + + General Configuration + + + GeneralConfigureGroupBox + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 2 + + + Top, Left, Right + + + Check + + + 220 + + + True + + + Warning Threshold + + + 140 + + + True + + + Critical Threshold + + + 140 + + + 3, 153 + + + 641, 248 + + + 15 + + + CheckDataGridView + + + System.Windows.Forms.DataGridView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPETableLayoutPanel + + + 3 + + + 0, 0 + + + 3, 10, 3, 3 + + + 5 + + + 647, 442 + + + 4 + + + NRPETableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="PoolTipsTableLayoutPanel" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="DescLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="GeneralConfigureGroupBox" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="CheckDataGridView" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0" /></TableLayoutSettings> + + + True + + + 96, 96 + + + True + + + 650, 621 + + + CheckColumn + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + WarningThresholdColumn + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + CriticalThresholdColumn + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NRPEEditPage + + + System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/XenAdmin/XenAdmin.csproj b/XenAdmin/XenAdmin.csproj index 6f449aa5c..44ee636f7 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 @@ -4428,6 +4442,7 @@ + diff --git a/XenModel/Actions/Host/NRPEUpdateAction.cs b/XenModel/Actions/Host/NRPEUpdateAction.cs new file mode 100644 index 000000000..38eefe94b --- /dev/null +++ b/XenModel/Actions/Host/NRPEUpdateAction.cs @@ -0,0 +1,191 @@ +/* Copyright (c) Cloud Software Group, Inc. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +using System.Collections.Generic; +using System.Linq; +using XenAPI; + + +namespace XenAdmin.Actions +{ + public class NRPEUpdateAction : AsyncAction + { + private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + private readonly NRPEHostConfiguration NRPEOriginalConfig; // NRPE configuration fetched from host + private readonly NRPEHostConfiguration NRPEHostConfiguration; // NRPE configuration after user modified + + private readonly IXenObject Clone; + + public NRPEUpdateAction(IXenObject host, NRPEHostConfiguration nrpeHostConfiguration, NRPEHostConfiguration nrpeOriginalConfig, bool suppressHistory) + : base(host.Connection, Messages.ACTION_CHANGE_POWER_ON, Messages.NRPE_ACTION_CHANGING, suppressHistory) + { + Clone = host; + NRPEHostConfiguration = nrpeHostConfiguration; + NRPEOriginalConfig = nrpeOriginalConfig; + } + + protected override void Run() + { + if (Clone is Host) + { + SetNRPEConfigureForHost(); + } + else + { + SetNRPEConfigureForPool(); + } + } + + private void SetNRPEConfigureForHost() + { + // Enable/Disable NRPE + if (!NRPEHostConfiguration.EnableNRPE == NRPEOriginalConfig.EnableNRPE) + { + SetNRPEStatus(Clone, NRPEHostConfiguration.EnableNRPE); + } + if (!NRPEHostConfiguration.EnableNRPE) // If disable, return + { + return; + } + + // NRPE General Configuration + if (!NRPEHostConfiguration.AllowHosts.Equals(NRPEOriginalConfig.AllowHosts) + || !NRPEHostConfiguration.Debug.Equals(NRPEOriginalConfig.Debug) + || !NRPEHostConfiguration.SslLogging.Equals(NRPEOriginalConfig.SslLogging)) + { + SetNRPEGeneralConfiguration(Clone, NRPEHostConfiguration.AllowHosts, NRPEHostConfiguration.Debug, NRPEHostConfiguration.SslLogging); + } + + // NRPE Check Threshold + foreach (KeyValuePair kvp in NRPEHostConfiguration.CheckDict) + { + NRPEHostConfiguration.Check CurrentCheck = kvp.Value; + NRPEOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); + if (CurrentCheck != null && OriginalCheck != null + && (!CurrentCheck.WarningThreshold.Equals(OriginalCheck.WarningThreshold) + || !CurrentCheck.CriticalThreshold.Equals(OriginalCheck.CriticalThreshold))) + { + SetNRPEThreshold(Clone, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold); + } + } + + RestartNRPE(Clone); + } + + private void SetNRPEConfigureForPool() + { + List hostList = null; + if (Clone is Pool p) + { + hostList = p.Connection.Cache.Hosts.ToList(); + } + + hostList.ForEach(host => + { + // Enable/Disable NRPE + SetNRPEStatus(host, NRPEHostConfiguration.EnableNRPE); + if (!NRPEHostConfiguration.EnableNRPE) // If disable, return + { + return; + } + + // NRPE General Configuration + SetNRPEGeneralConfiguration(host, NRPEHostConfiguration.AllowHosts, NRPEHostConfiguration.Debug, NRPEHostConfiguration.SslLogging); + + // NRPE Check Threshold + foreach (KeyValuePair kvp in NRPEHostConfiguration.CheckDict) + { + NRPEHostConfiguration.Check CurrentCheck = kvp.Value; + NRPEOriginalConfig.GetNRPECheck(kvp.Key, out NRPEHostConfiguration.Check OriginalCheck); + if (CurrentCheck != null) + { + SetNRPEThreshold(host, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold); + } + } + + RestartNRPE(host); + }); + } + + private void SetNRPEStatus(IXenObject host, bool enableNRPE) + { + string nrpeUpdateStatusMethod = enableNRPE ? + NRPEHostConfiguration.XAPI_NRPE_ENABLE : NRPEHostConfiguration.XAPI_NRPE_DISABLE; + string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + nrpeUpdateStatusMethod, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", nrpeUpdateStatusMethod, result); + } + + private void SetNRPEGeneralConfiguration(IXenObject host, string allowHosts, bool debug, bool sslLogging) + { + Dictionary ConfigArgDict = new Dictionary + { + { "allowed_hosts", "127.0.0.1,::1," + (allowHosts.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ? "" : allowHosts) }, + { "debug", debug ? NRPEHostConfiguration.DEBUG_ENABLE : NRPEHostConfiguration.DEBUG_DISABLE }, + { "ssl_logging", sslLogging ? NRPEHostConfiguration.SSL_LOGGING_ENABLE : NRPEHostConfiguration.SSL_LOGGING_DISABLE} + }; + string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_SET_CONFIG, ConfigArgDict); + log.InfoFormat("Execute nrpe {0}, allowed_hosts={1}, debug={2}, ssl_logging={3}, return: {4}", + NRPEHostConfiguration.XAPI_NRPE_SET_CONFIG, + NRPEHostConfiguration.AllowHosts, + NRPEHostConfiguration.Debug, + NRPEHostConfiguration.SslLogging, + result); + } + + private void SetNRPEThreshold(IXenObject host, string checkName, string warningThreshold, string criticalThreshold) + { + Dictionary ThresholdArgDict = new Dictionary + { + { checkName, null }, + { "w", warningThreshold }, + { "c", criticalThreshold } + }; + string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_SET_THRESHOLD, ThresholdArgDict); + log.InfoFormat("Execute nrpe {0}, check={1}, w={2}, c={3}, return: {4}", + NRPEHostConfiguration.XAPI_NRPE_SET_THRESHOLD, + checkName, + warningThreshold, + criticalThreshold, + result); + } + + // After modified NRPE configuration, we need to restart NRPE to take effect + private void RestartNRPE(IXenObject host) + { + string result = Host.call_plugin(host.Connection.Session, host.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME, + NRPEHostConfiguration.XAPI_NRPE_RESTART, null); + log.InfoFormat("Execute nrpe {0}, return: {1}", NRPEHostConfiguration.XAPI_NRPE_RESTART, result); + } + } +} diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index 2d47ae38c..4640a32ae 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -29078,6 +29078,240 @@ public static string NOW { } } + /// + /// Looks up a localized string similar to Changing NRPE configuration.... + /// + public static string NRPE_ACTION_CHANGING { + get { + return ResourceManager.GetString("NRPE_ACTION_CHANGING", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to NRPE service is active. + /// + public static string NRPE_ACTIVE { + get { + return ResourceManager.GetString("NRPE_ACTIVE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Allow hosts should not be empty.. + /// + public static string NRPE_ALLOW_HOSTS_EMPTY_ERROR { + get { + return ResourceManager.GetString("NRPE_ALLOW_HOSTS_EMPTY_ERROR", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Allow hosts format is not correct. + /// + public static string NRPE_ALLOW_HOSTS_ERROR_TITLE { + get { + return ResourceManager.GetString("NRPE_ALLOW_HOSTS_ERROR_TITLE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Allow hosts should be comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com. + /// + public static string NRPE_ALLOW_HOSTS_FORMAT_ERROR { + get { + return ResourceManager.GetString("NRPE_ALLOW_HOSTS_FORMAT_ERROR", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com. + /// + public static string NRPE_ALLOW_HOSTS_PLACE_HOLDER { + get { + return ResourceManager.GetString("NRPE_ALLOW_HOSTS_PLACE_HOLDER", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to NRPE batch configuration. + /// + public static string NRPE_BATCH_CONFIGURATION { + get { + return ResourceManager.GetString("NRPE_BATCH_CONFIGURATION", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 CPU Usage (%). + /// + public static string NRPE_CHECK_CPU { + get { + return ResourceManager.GetString("NRPE_CHECK_CPU", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 Log Partition Free Space (%). + /// + public static string NRPE_CHECK_DISK_LOG { + get { + return ResourceManager.GetString("NRPE_CHECK_DISK_LOG", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 Root Partition Free Space (%). + /// + public static string NRPE_CHECK_DISK_ROOT { + get { + return ResourceManager.GetString("NRPE_CHECK_DISK_ROOT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host CPU Usage (%). + /// + public static string NRPE_CHECK_HOST_CPU { + get { + return ResourceManager.GetString("NRPE_CHECK_HOST_CPU", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host CPU Load. + /// + public static string NRPE_CHECK_HOST_LOAD { + get { + return ResourceManager.GetString("NRPE_CHECK_HOST_LOAD", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host Memory Usage (%). + /// + public static string NRPE_CHECK_HOST_MEMORY { + get { + return ResourceManager.GetString("NRPE_CHECK_HOST_MEMORY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 CPU Load. + /// + public static string NRPE_CHECK_LOAD { + get { + return ResourceManager.GetString("NRPE_CHECK_LOAD", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 Memory Usage (%). + /// + public static string NRPE_CHECK_MEMORY { + get { + return ResourceManager.GetString("NRPE_CHECK_MEMORY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dom0 Free Swap (%). + /// + public static string NRPE_CHECK_SWAP { + get { + return ResourceManager.GetString("NRPE_CHECK_SWAP", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host vGPU Memory Usage (%). + /// + public static string NRPE_CHECK_VGPU { + get { + return ResourceManager.GetString("NRPE_CHECK_VGPU", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Host vGPU Usage (%). + /// + public static string NRPE_CHECK_VGPU_MEMORY { + get { + return ResourceManager.GetString("NRPE_CHECK_VGPU_MEMORY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to NRPE Configuration. + /// + public static string NRPE_EDIT_PAGE_TEXT { + get { + return ResourceManager.GetString("NRPE_EDIT_PAGE_TEXT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to NRPE service is inactive. + /// + public static string NRPE_INACTIVE { + get { + return ResourceManager.GetString("NRPE_INACTIVE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Threshold value should range from {0} to {1}.. + /// + public static string NRPE_THRESHOLD_RANGE_ERROR { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_RANGE_ERROR", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Threshold value should be 3 numbers separated with comma.. + /// + public static string NRPE_THRESHOLD_SHOULD_BE_3_NUMBERS { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_SHOULD_BE_3_NUMBERS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Threshold value should be number.. + /// + public static string NRPE_THRESHOLD_SHOULD_BE_NUMBER { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_SHOULD_BE_NUMBER", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Threshold value should not be empty.. + /// + public static string NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_SHOULD_NOT_BE_EMPTY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Warning threshold should be bigger than critical threshold.. + /// + public static string NRPE_THRESHOLD_WARNING_SHOULD_BIGGER_THAN_CRITICAL { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_WARNING_SHOULD_BIGGER_THAN_CRITICAL", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Warning threshold should be less than critical threshold.. + /// + public static string NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL { + get { + return ResourceManager.GetString("NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL", resourceCulture); + } + } + /// /// Looks up a localized string similar to Number of snapshots to keep. /// diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index 2e4f0691d..6277783e5 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -10092,6 +10092,84 @@ When you configure an NFS storage repository, you simply provide the host name o Now + + Changing NRPE configuration... + + + NRPE service is active + + + Allow hosts should not be empty. + + + Allow hosts format is not correct + + + Allow hosts should be comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com + + + Comma separated IP address or domain list, e.g. 192.168.1.1, test.domain.com + + + NRPE batch configuration + + + Dom0 CPU Usage (%) + + + Dom0 Log Partition Free Space (%) + + + Dom0 Root Partition Free Space (%) + + + Host CPU Usage (%) + + + Host CPU Load + + + Host Memory Usage (%) + + + Dom0 CPU Load + + + Dom0 Memory Usage (%) + + + Dom0 Free Swap (%) + + + Host vGPU Memory Usage (%) + + + Host vGPU Usage (%) + + + NRPE Configuration + + + NRPE service is inactive + + + Threshold value should range from {0} to {1}. + + + Threshold value should be 3 numbers separated with comma. + + + Threshold value should be number. + + + Threshold value should not be empty. + + + Warning threshold should be bigger than critical threshold. + + + Warning threshold should be less than critical threshold. + Number of snapshots to keep @@ -15056,7 +15134,7 @@ Any disk in your VM's DVD drive will be ejected when installing {1}. Normal - + {0} recommends that you synchronize the selected pool(s) or standalone host(s) with the specified update channel as soon as possible to retrieve the latest available updates. diff --git a/XenModel/NRPE/NRPEHostConfiguration.cs b/XenModel/NRPE/NRPEHostConfiguration.cs new file mode 100644 index 000000000..597556aac --- /dev/null +++ b/XenModel/NRPE/NRPEHostConfiguration.cs @@ -0,0 +1,109 @@ +/* Copyright (c) Cloud Software Group, Inc. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; + +namespace XenAdmin +{ + public class NRPEHostConfiguration : ICloneable + { + public static readonly string XAPI_NRPE_PLUGIN_NAME = "nrpe"; + public static readonly string XAPI_NRPE_STATUS = "status"; + public static readonly string XAPI_NRPE_GET_CONFIG = "get-config"; + public static readonly string XAPI_NRPE_GET_THRESHOLD = "get-threshold"; + public static readonly string XAPI_NRPE_ENABLE = "enable"; + public static readonly string XAPI_NRPE_DISABLE = "disable"; + public static readonly string XAPI_NRPE_SET_CONFIG = "set-config"; + public static readonly string XAPI_NRPE_SET_THRESHOLD = "set-threshold"; + public static readonly string XAPI_NRPE_RESTART = "restart"; + + public static readonly string DEBUG_ENABLE = "1"; + public static readonly string DEBUG_DISABLE = "0"; + + public static readonly string SSL_LOGGING_ENABLE = "0xff"; + public static readonly string SSL_LOGGING_DISABLE = "0x00"; + + public static readonly string ALLOW_HOSTS_PLACE_HOLDER = Messages.NRPE_ALLOW_HOSTS_PLACE_HOLDER; + + private bool enableNRPE; + private string allowHosts; + private bool debug; + private bool sslLogging; + private readonly Dictionary checkDict = new Dictionary(); + + public bool EnableNRPE { get => enableNRPE; set => enableNRPE = value; } + public string AllowHosts { get => allowHosts; set => allowHosts = value; } + public bool Debug { get => debug; set => debug = value; } + public bool SslLogging { get => sslLogging; set => sslLogging = value; } + public Dictionary CheckDict { get => checkDict; } + + public class Check + { + public string Name; + public string WarningThreshold; + public string CriticalThreshold; + + public Check(string name, string warningThreshold, string criticalThreshold) + { + this.Name = name; + this.WarningThreshold = warningThreshold; + this.CriticalThreshold = criticalThreshold; + } + + } + + public NRPEHostConfiguration() + { + } + + public void AddNRPECheck(Check checkItem) + { + checkDict.Add(checkItem.Name, checkItem); + } + + public bool GetNRPECheck(string name, out Check check) + { + return checkDict.TryGetValue(name, out check); + } + + public object Clone() + { + NRPEHostConfiguration cloned = new NRPEHostConfiguration + { + enableNRPE = enableNRPE, + allowHosts = allowHosts, + debug = debug, + sslLogging = sslLogging + }; + return cloned; + } + } +} diff --git a/XenModel/XenModel.csproj b/XenModel/XenModel.csproj index 13349a2b8..949403fbd 100755 --- a/XenModel/XenModel.csproj +++ b/XenModel/XenModel.csproj @@ -88,6 +88,7 @@ + @@ -198,6 +199,7 @@ +