2023-09-14 08:49:46 +02:00
|
|
|
|
/* 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;
|
2023-09-27 20:05:27 +02:00
|
|
|
|
using System.Collections.Generic;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
using System.Drawing;
|
2023-09-27 20:05:27 +02:00
|
|
|
|
using System.Text.RegularExpressions;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Core;
|
2023-09-27 20:05:27 +02:00
|
|
|
|
using XenAdmin.Actions.NRPE;
|
|
|
|
|
using XenAPI;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
|
|
|
|
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,})$");
|
|
|
|
|
|
2023-09-28 14:22:46 +02:00
|
|
|
|
private bool _isHost;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
private IXenObject _clone;
|
|
|
|
|
private readonly ToolTip _invalidParamToolTip;
|
|
|
|
|
private string _invalidParamToolTipText = "";
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
private readonly List<CheckGroup> _checkGroupList = new List<CheckGroup>();
|
|
|
|
|
private readonly Dictionary<string, CheckGroup> _checkGroupDictByName = new Dictionary<string, CheckGroup>();
|
|
|
|
|
private readonly Dictionary<string, CheckGroup> _checkGroupDictByLabel = new Dictionary<string, CheckGroup>();
|
2023-09-28 14:22:46 +02:00
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
private NRPEHostConfiguration _nrpeOriginalConfig;
|
|
|
|
|
private NRPEHostConfiguration _nrpeCurrentConfig;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
2023-09-27 14:01:46 +02:00
|
|
|
|
public Image Image => Images.StaticImages._000_Module_h32bit_16;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
2023-09-28 14:22:46 +02:00
|
|
|
|
public NRPEEditPage()
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-09-28 14:22:46 +02:00
|
|
|
|
Text = Messages.NRPE;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
_nrpeOriginalConfig = new NRPEHostConfiguration
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
|
|
|
|
EnableNRPE = false,
|
|
|
|
|
AllowHosts = NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER,
|
|
|
|
|
Debug = false,
|
|
|
|
|
SslLogging = false
|
|
|
|
|
};
|
2023-10-08 10:03:18 +02:00
|
|
|
|
|
|
|
|
|
_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)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
|
|
|
|
CheckDataGridView.Rows.Add(checkGroup.CheckThresholdRow);
|
2023-10-08 10:03:18 +02:00
|
|
|
|
_checkGroupDictByName.Add(checkGroup.Name, checkGroup);
|
|
|
|
|
_checkGroupDictByLabel.Add(checkGroup.NameCell.Value.ToString(), checkGroup);
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-12 16:24:35 +02:00
|
|
|
|
AllowHostsTextBox.Text = NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlDark);
|
|
|
|
|
AllowHostsTextBox.GotFocus += AllowHostsTextBox_GotFocus;
|
|
|
|
|
AllowHostsTextBox.LostFocus += AllowHostsTextBox_LostFocus;
|
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
_invalidParamToolTip = new ToolTip
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
|
|
|
|
IsBalloon = true,
|
|
|
|
|
ToolTipIcon = ToolTipIcon.Warning,
|
|
|
|
|
ToolTipTitle = Messages.INVALID_PARAMETER,
|
|
|
|
|
Tag = AllowHostsTextBox
|
|
|
|
|
};
|
2023-10-08 10:03:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string SubText
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2023-10-16 10:59:33 +02:00
|
|
|
|
return Messages.NRPE_EDIT_PAGE_TEXT;
|
2023-10-08 10:03:18 +02:00
|
|
|
|
}
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ValidToSave
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
_invalidParamToolTipText = "";
|
|
|
|
|
_invalidParamToolTip.ToolTipTitle = "";
|
2023-09-14 08:49:46 +02:00
|
|
|
|
CheckDataGridView.ShowCellToolTips = false;
|
2023-10-08 10:03:18 +02:00
|
|
|
|
CheckDataGridView.ShowCellErrors = false;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
|
|
|
|
if (!EnableNRPECheckBox.Checked)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 14:22:46 +02:00
|
|
|
|
bool valid = IsAllowHostsValid();
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
foreach (CheckGroup checkGroup in _checkGroupList)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
|
|
|
|
if (!checkGroup.CheckValue())
|
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
CheckDataGridView.ShowCellToolTips = true;
|
|
|
|
|
CheckDataGridView.ShowCellErrors = true;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
valid = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return valid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasChanged
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2023-10-16 10:59:33 +02:00
|
|
|
|
UpdateCurrentNRPEConfiguration();
|
|
|
|
|
if (!_nrpeCurrentConfig.Equals(_nrpeOriginalConfig))
|
2023-10-08 10:03:18 +02:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-10-12 16:24:35 +02:00
|
|
|
|
return false;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowLocalValidationMessages()
|
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
if (_invalidParamToolTip.Tag is Control ctrl)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
_invalidParamToolTip.Hide(ctrl);
|
|
|
|
|
if (!_invalidParamToolTipText.Equals(""))
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
HelpersGUI.ShowBalloonMessage(ctrl, _invalidParamToolTip, _invalidParamToolTipText);
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HideLocalValidationMessages()
|
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
if (_invalidParamToolTip.Tag is Control ctrl)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
_invalidParamToolTip.Hide(ctrl);
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
public AsyncAction SaveSettings()
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
return new NRPEUpdateAction(_clone, _nrpeCurrentConfig, _nrpeOriginalConfig, true);
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
public void SetXenObjects(IXenObject orig, IXenObject clone)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
_clone = clone;
|
|
|
|
|
_isHost = _clone is Host;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
DescLabelHost.Visible = _isHost;
|
|
|
|
|
DescLabelPool.Visible = !_isHost;
|
|
|
|
|
UpdateRetrievingNRPETip(NRPEHostConfiguration.RetrieveNRPEStatus.Retrieving);
|
|
|
|
|
DisableAllComponent();
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
NRPERetrieveAction action = new NRPERetrieveAction(_clone, _nrpeOriginalConfig, _checkGroupDictByName, true);
|
|
|
|
|
action.Completed += ActionCompleted;
|
|
|
|
|
action.RunAsync();
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
private void ActionCompleted(ActionBase sender)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
Program.Invoke(this.Parent, UpdateRetrieveStatus);
|
|
|
|
|
}
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
private void UpdateRetrieveStatus()
|
|
|
|
|
{
|
|
|
|
|
if (_nrpeOriginalConfig.Status == NRPEHostConfiguration.RetrieveNRPEStatus.Successful)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-16 10:59:33 +02:00
|
|
|
|
EnableNRPECheckBox.Enabled = true;
|
|
|
|
|
UpdateComponentValueBasedConfiguration();
|
|
|
|
|
UpdateComponentStatusBasedEnableNRPECheckBox();
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
2023-10-08 10:03:18 +02:00
|
|
|
|
UpdateRetrievingNRPETip(_nrpeOriginalConfig.Status);
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
private void UpdateRetrievingNRPETip(NRPEHostConfiguration.RetrieveNRPEStatus status)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
switch (status)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
case NRPEHostConfiguration.RetrieveNRPEStatus.Retrieving:
|
|
|
|
|
RetrieveNRPELabel.Text = Messages.NRPE_RETRIEVING_CONFIGURATION;
|
|
|
|
|
RetrieveNRPEPicture.Image = Images.StaticImages.ajax_loader;
|
|
|
|
|
RetrieveNRPEPicture.Visible = true;
|
|
|
|
|
break;
|
|
|
|
|
case NRPEHostConfiguration.RetrieveNRPEStatus.Successful:
|
|
|
|
|
RetrieveNRPELabel.Text = "";
|
|
|
|
|
RetrieveNRPEPicture.Image = Images.StaticImages._000_Tick_h32bit_16;
|
|
|
|
|
RetrieveNRPEPicture.Visible = false;
|
|
|
|
|
break;
|
|
|
|
|
case NRPEHostConfiguration.RetrieveNRPEStatus.Failed:
|
|
|
|
|
RetrieveNRPELabel.Text = Messages.NRPE_RETRIEVE_FAILED;
|
|
|
|
|
RetrieveNRPEPicture.Image = Images.StaticImages._000_error_h32bit_16;
|
|
|
|
|
RetrieveNRPEPicture.Visible = true;
|
|
|
|
|
break;
|
|
|
|
|
case NRPEHostConfiguration.RetrieveNRPEStatus.Unsupport:
|
|
|
|
|
RetrieveNRPELabel.Text = Messages.NRPE_UNSUPPORT;
|
|
|
|
|
RetrieveNRPEPicture.Image = Images.StaticImages._000_error_h32bit_16;
|
|
|
|
|
RetrieveNRPEPicture.Visible = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
2023-10-08 10:03:18 +02:00
|
|
|
|
}
|
2023-09-14 08:49:46 +02:00
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
private void DisableAllComponent()
|
|
|
|
|
{
|
2023-10-12 16:24:35 +02:00
|
|
|
|
EnableNRPECheckBox.Enabled = false;
|
|
|
|
|
GeneralConfigureGroupBox.Enabled = false;
|
|
|
|
|
CheckDataGridView.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateComponentValueBasedConfiguration()
|
|
|
|
|
{
|
|
|
|
|
EnableNRPECheckBox.Checked = _nrpeOriginalConfig.EnableNRPE;
|
|
|
|
|
AllowHostsTextBox.Text = AllowHostsWithoutLocalAddress(_nrpeOriginalConfig.AllowHosts);
|
|
|
|
|
AllowHostsTextBox.ForeColor = AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER) ?
|
|
|
|
|
Color.FromKnownColor(KnownColor.ControlDark) : AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlText);
|
|
|
|
|
DebugLogCheckBox.Checked = _nrpeOriginalConfig.Debug;
|
|
|
|
|
SslDebugLogCheckBox.Checked = _nrpeOriginalConfig.SslLogging;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateComponentStatusBasedEnableNRPECheckBox()
|
|
|
|
|
{
|
|
|
|
|
GeneralConfigureGroupBox.Enabled = EnableNRPECheckBox.Checked;
|
|
|
|
|
CheckDataGridView.Enabled = EnableNRPECheckBox.Checked;
|
2023-10-16 10:59:33 +02:00
|
|
|
|
CheckDataGridView.ScrollBars = ScrollBars.Both;
|
2023-10-12 16:24:35 +02:00
|
|
|
|
CheckDataGridView.DefaultCellStyle.BackColor = EnableNRPECheckBox.Checked ?
|
|
|
|
|
Color.FromKnownColor(KnownColor.Window) : Color.FromKnownColor(KnownColor.Control);
|
2023-10-16 10:59:33 +02:00
|
|
|
|
foreach (var checkGroup in _checkGroupList)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-16 10:59:33 +02:00
|
|
|
|
if (EnableNRPECheckBox.Checked)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-16 10:59:33 +02:00
|
|
|
|
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);
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-12 16:24:35 +02:00
|
|
|
|
private bool IsAllowHostsValid()
|
|
|
|
|
{
|
|
|
|
|
_invalidParamToolTip.ToolTipTitle = Messages.NRPE_ALLOW_HOSTS_ERROR_TITLE;
|
|
|
|
|
_invalidParamToolTip.Tag = AllowHostsTextBox;
|
|
|
|
|
CheckDataGridView.ShowCellToolTips = true;
|
|
|
|
|
|
|
|
|
|
string str = AllowHostsTextBox.Text;
|
|
|
|
|
if (str.Trim().Length == 0 || str.Trim().Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER))
|
|
|
|
|
{
|
|
|
|
|
_invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_EMPTY_ERROR;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string[] hostArray = str.Split(',');
|
|
|
|
|
for ( int i = 0; i < hostArray.Length; i++ )
|
|
|
|
|
{
|
|
|
|
|
if (!REGEX_IPV4.Match(hostArray[i].Trim()).Success &&
|
|
|
|
|
!REGEX_IPV4_CIDR.Match(hostArray[i].Trim()).Success &&
|
|
|
|
|
!REGEX_DOMAIN.Match(hostArray[i].Trim()).Success)
|
|
|
|
|
{
|
|
|
|
|
_invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
for ( int j = 0; j < i; j++ )
|
|
|
|
|
{
|
|
|
|
|
if (hostArray[i].Trim().Equals(hostArray[j].Trim()))
|
|
|
|
|
{
|
|
|
|
|
_invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_SAME_ADDRESS;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach (string host in hostArray)
|
|
|
|
|
{
|
|
|
|
|
if (!REGEX_IPV4.Match(host.Trim()).Success &&
|
|
|
|
|
!REGEX_IPV4_CIDR.Match(host.Trim()).Success &&
|
|
|
|
|
!REGEX_DOMAIN.Match(host.Trim()).Success)
|
|
|
|
|
{
|
|
|
|
|
_invalidParamToolTipText = Messages.NRPE_ALLOW_HOSTS_FORMAT_ERROR;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CheckDataGridView.ShowCellToolTips = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string AllowHostsWithoutLocalAddress(string allowHosts)
|
|
|
|
|
{
|
|
|
|
|
string UpdatedAllowHosts = "";
|
|
|
|
|
string[] AllowHostArray = allowHosts.Split(',');
|
|
|
|
|
foreach (string allowHost in AllowHostArray)
|
|
|
|
|
{
|
|
|
|
|
if (!allowHost.Trim().Equals("127.0.0.1") &&
|
|
|
|
|
!allowHost.Trim().Equals("::1"))
|
|
|
|
|
{
|
|
|
|
|
UpdatedAllowHosts += allowHost + ",";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return UpdatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER :
|
|
|
|
|
UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 10:03:18 +02:00
|
|
|
|
private void UpdateCurrentNRPEConfiguration()
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
_nrpeCurrentConfig = new NRPEHostConfiguration
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-08 10:03:18 +02:00
|
|
|
|
EnableNRPE = EnableNRPECheckBox.Checked,
|
|
|
|
|
AllowHosts = AllowHostsTextBox.Text,
|
|
|
|
|
Debug = DebugLogCheckBox.Checked,
|
|
|
|
|
SslLogging = SslDebugLogCheckBox.Checked
|
|
|
|
|
};
|
|
|
|
|
foreach (KeyValuePair<string, CheckGroup> item in _checkGroupDictByName)
|
2023-09-14 08:49:46 +02:00
|
|
|
|
{
|
2023-10-16 10:59:33 +02:00
|
|
|
|
_nrpeCurrentConfig.AddNRPECheck(new NRPEHostConfiguration.Check(item.Key,
|
|
|
|
|
item.Value.WarningThresholdCell.Value.ToString(), item.Value.CriticalThresholdCell.Value.ToString()));
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EnableNRPECheckBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-10-12 16:24:35 +02:00
|
|
|
|
UpdateComponentStatusBasedEnableNRPECheckBox();
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AllowHostsTextBox_GotFocus(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (AllowHostsTextBox.Text.Equals(NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER))
|
|
|
|
|
{
|
|
|
|
|
AllowHostsTextBox.Text = "";
|
|
|
|
|
}
|
2023-10-08 10:03:18 +02:00
|
|
|
|
AllowHostsTextBox.ForeColor = Color.FromKnownColor(KnownColor.ControlText);
|
2023-09-14 08:49:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|