mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-21 17:11:29 +01:00
Check NRPE plugin before showing properties dialog.
This commit is contained in:
parent
aac73932ce
commit
7dfe809c66
@ -318,8 +318,8 @@ namespace XenAdmin.Dialogs
|
||||
dialog.ShowDialog(Program.MainWindow);
|
||||
}
|
||||
}
|
||||
if (isPoolOrStandalone &&
|
||||
(connection.Session.IsLocalSuperuser || connection.Session.Roles.Any(r => r.name_label == Role.MR_ROLE_POOL_ADMIN)))
|
||||
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);
|
||||
|
@ -37,11 +37,15 @@ using XenAdmin.Actions;
|
||||
using XenAdmin.Core;
|
||||
using XenAdmin.Actions.NRPE;
|
||||
using XenAPI;
|
||||
using System.Linq;
|
||||
using XenAdmin.Network;
|
||||
|
||||
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,})$");
|
||||
@ -107,13 +111,7 @@ namespace XenAdmin.SettingsPanels
|
||||
};
|
||||
}
|
||||
|
||||
public string SubText
|
||||
{
|
||||
get
|
||||
{
|
||||
return Messages.NRPE_EDIT_PAGE_TEXT;
|
||||
}
|
||||
}
|
||||
public string SubText => Messages.NRPE_EDIT_PAGE_TEXT;
|
||||
|
||||
public bool ValidToSave
|
||||
{
|
||||
@ -149,11 +147,7 @@ namespace XenAdmin.SettingsPanels
|
||||
get
|
||||
{
|
||||
UpdateCurrentNRPEConfiguration();
|
||||
if (!_nrpeCurrentConfig.Equals(_nrpeOriginalConfig))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return !_nrpeCurrentConfig.Equals(_nrpeOriginalConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,13 +230,8 @@ namespace XenAdmin.SettingsPanels
|
||||
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;
|
||||
throw new ArgumentOutOfRangeException(nameof(status), status, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using XenAPI;
|
||||
|
||||
namespace XenAdmin.Actions.NRPE
|
||||
{
|
||||
@ -54,7 +53,7 @@ namespace XenAdmin.Actions.NRPE
|
||||
|
||||
public static readonly string ALLOW_HOSTS_PLACE_HOLDER = Messages.NRPE_ALLOW_HOSTS_PLACE_HOLDER;
|
||||
|
||||
private Dictionary<string, Check> _checkDict = new Dictionary<string, Check>();
|
||||
private readonly Dictionary<string, Check> _checkDict = new Dictionary<string, Check>();
|
||||
|
||||
public bool EnableNRPE { get; set; }
|
||||
|
||||
@ -72,8 +71,7 @@ namespace XenAdmin.Actions.NRPE
|
||||
{
|
||||
Retrieving,
|
||||
Successful,
|
||||
Failed,
|
||||
Unsupport
|
||||
Failed
|
||||
}
|
||||
|
||||
public class Check
|
||||
@ -133,9 +131,9 @@ namespace XenAdmin.Actions.NRPE
|
||||
Debug = Debug,
|
||||
SslLogging = SslLogging
|
||||
};
|
||||
foreach (KeyValuePair<string, NRPEHostConfiguration.Check> kvp in _checkDict)
|
||||
foreach (KeyValuePair<string, Check> kvp in _checkDict)
|
||||
{
|
||||
NRPEHostConfiguration.Check CurrentCheck = kvp.Value;
|
||||
Check CurrentCheck = kvp.Value;
|
||||
cloned.AddNRPECheck(new Check(CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold));
|
||||
}
|
||||
|
||||
|
@ -30,9 +30,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using XenAdmin.Core;
|
||||
using XenAPI;
|
||||
|
||||
@ -69,8 +66,7 @@ namespace XenAdmin.Actions.NRPE
|
||||
catch (Exception e)
|
||||
{
|
||||
log.ErrorFormat("Execute NRPE plugin failed, failed reason: {0}", e.Message);
|
||||
_nrpeCurrentConfig.Status = e.Message.Contains("UNKNOWN_XENAPI_PLUGIN_FUNCTION") || e.Message.Contains("The requested plug-in could not be found") ?
|
||||
NRPEHostConfiguration.RetrieveNRPEStatus.Unsupport : NRPEHostConfiguration.RetrieveNRPEStatus.Failed;
|
||||
_nrpeCurrentConfig.Status = NRPEHostConfiguration.RetrieveNRPEStatus.Failed;
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,20 +124,20 @@ namespace XenAdmin.Actions.NRPE
|
||||
}
|
||||
}
|
||||
|
||||
private string AllowHostsWithoutLocalAddress(string allowHosts)
|
||||
private static string AllowHostsWithoutLocalAddress(string allowHosts)
|
||||
{
|
||||
string UpdatedAllowHosts = "";
|
||||
string[] AllowHostArray = allowHosts.Split(',');
|
||||
foreach (string allowHost in AllowHostArray)
|
||||
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 + ",";
|
||||
updatedAllowHosts += allowHost + ",";
|
||||
}
|
||||
}
|
||||
return UpdatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER :
|
||||
UpdatedAllowHosts.Substring(0, UpdatedAllowHosts.Length - 1);
|
||||
return updatedAllowHosts.Length == 0 ? NRPEHostConfiguration.ALLOW_HOSTS_PLACE_HOLDER :
|
||||
updatedAllowHosts.Substring(0, updatedAllowHosts.Length - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,13 +87,13 @@ namespace XenAdmin.Actions.NRPE
|
||||
// NRPE Check Threshold
|
||||
foreach (KeyValuePair<string, NRPEHostConfiguration.Check> kvp in _nrpeHostConfiguration.CheckDict)
|
||||
{
|
||||
NRPEHostConfiguration.Check CurrentCheck = kvp.Value;
|
||||
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)))
|
||||
if (currentCheck != null && OriginalCheck != null
|
||||
&& (!currentCheck.WarningThreshold.Equals(OriginalCheck.WarningThreshold)
|
||||
|| !currentCheck.CriticalThreshold.Equals(OriginalCheck.CriticalThreshold)))
|
||||
{
|
||||
SetNRPEThreshold(o, CurrentCheck.Name, CurrentCheck.WarningThreshold, CurrentCheck.CriticalThreshold);
|
||||
SetNRPEThreshold(o, currentCheck.Name, currentCheck.WarningThreshold, currentCheck.CriticalThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,14 +120,14 @@ namespace XenAdmin.Actions.NRPE
|
||||
|
||||
private void SetNRPEGeneralConfiguration(IXenObject host, string allowHosts, bool debug, bool sslLogging)
|
||||
{
|
||||
Dictionary<string, string> ConfigArgDict = new Dictionary<string, string>
|
||||
Dictionary<string, string> configArgDict = new Dictionary<string, string>
|
||||
{
|
||||
{ "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);
|
||||
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,
|
||||
@ -138,14 +138,14 @@ namespace XenAdmin.Actions.NRPE
|
||||
|
||||
private void SetNRPEThreshold(IXenObject host, string checkName, string warningThreshold, string criticalThreshold)
|
||||
{
|
||||
Dictionary<string, string> ThresholdArgDict = new Dictionary<string, string>
|
||||
Dictionary<string, string> thresholdArgDict = new Dictionary<string, string>
|
||||
{
|
||||
{ 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);
|
||||
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,
|
||||
|
9
XenModel/Messages.Designer.cs
generated
9
XenModel/Messages.Designer.cs
generated
@ -29357,15 +29357,6 @@ namespace XenAdmin {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unsupport NRPE, please upgrade your XenServer version..
|
||||
/// </summary>
|
||||
public static string NRPE_UNSUPPORT {
|
||||
get {
|
||||
return ResourceManager.GetString("NRPE_UNSUPPORT", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Number of snapshots to keep.
|
||||
/// </summary>
|
||||
|
@ -10185,9 +10185,6 @@ When you configure an NFS storage repository, you simply provide the host name o
|
||||
<data name="NRPE_THRESHOLD_WARNING_SHOULD_LESS_THAN_CRITICAL" xml:space="preserve">
|
||||
<value>Warning threshold should be less than critical threshold.</value>
|
||||
</data>
|
||||
<data name="NRPE_UNSUPPORT" xml:space="preserve">
|
||||
<value>Unsupport NRPE, please upgrade your XenServer version.</value>
|
||||
</data>
|
||||
<data name="NUMBER_OF_SNAPSHOTS_TO_KEEP" xml:space="preserve">
|
||||
<value>Number of snapshots to keep</value>
|
||||
</data>
|
||||
@ -15180,4 +15177,4 @@ Do you want to synchronize immediately?</value>
|
||||
<data name="YUM_REPO_SYNC_YES_VISIBLE_BUTTON" xml:space="preserve">
|
||||
<value>Only synchronize &visible</value>
|
||||
</data>
|
||||
</root>
|
||||
</root>
|
@ -528,6 +528,12 @@ namespace XenAdmin.Core
|
||||
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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user