Skip to content

Commit

Permalink
Check NRPE plugin before showing properties dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
BengangY committed Oct 17, 2023
1 parent 6c81585 commit dbf168c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
18 changes: 17 additions & 1 deletion XenAdmin/Dialogs/PropertiesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,23 @@ private void Build()
(connection.Session.IsLocalSuperuser || connection.Session.Roles.Any(r => r.name_label == Role.MR_ROLE_POOL_ADMIN)))
{
NRPEEditPage = new NRPEEditPage();
ShowTab(NRPEEditPage);
bool nrpeAvailable = false;
using (var dialog = new ActionProgressDialog(
new DelegatedAsyncAction(connection, Messages.NRPE_PLUGIN_CHECKING,
Messages.NRPE_PLUGIN_CHECKING, Messages.NRPE_PLUGIN_CHECKED,
delegate (Session session)
{
nrpeAvailable = NRPEEditPage.IsNRPEAvailable(_xenObjectCopy);
}),
ProgressBarStyle.Continuous))
{
dialog.ShowCancel = true;
dialog.ShowDialog(Program.MainWindow);
}
if (nrpeAvailable)
{
ShowTab(NRPEEditPage);
}
}
}
finally
Expand Down
18 changes: 18 additions & 0 deletions XenAdmin/SettingsPanels/NRPEEditPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ 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,})$");
Expand Down Expand Up @@ -363,6 +365,22 @@ private void UpdateCurrentNRPEConfiguration()
}
}

public bool IsNRPEAvailable(IXenObject clone)
{
IXenObject o = clone is Pool p ? Helpers.GetCoordinator(p) : clone;
try
{
Host.call_plugin(o.Connection.Session, o.opaque_ref, NRPEHostConfiguration.XAPI_NRPE_PLUGIN_NAME,
NRPEHostConfiguration.XAPI_NRPE_STATUS, null);
return true;
}
catch (Exception e)
{
log.ErrorFormat("NRPE plugin checking failed, failed reason: {0}", e.Message);
return false;
}
}

private void EnableNRPECheckBox_CheckedChanged(object sender, EventArgs e)
{
UpdateComponentStatusBasedEnableNRPECheckBox();
Expand Down
18 changes: 18 additions & 0 deletions XenModel/Messages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions XenModel/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -10161,6 +10161,12 @@ When you configure an NFS storage repository, you simply provide the host name o
<data name="NRPE_INACTIVE" xml:space="preserve">
<value>NRPE service is inactive</value>
</data>
<data name="NRPE_PLUGIN_CHECKED" xml:space="preserve">
<value>Checking NRPE plugin status finished.</value>
</data>
<data name="NRPE_PLUGIN_CHECKING" xml:space="preserve">
<value>Checking NRPE plugin status.</value>
</data>
<data name="NRPE_RETRIEVE_FAILED" xml:space="preserve">
<value>Retrieve NRPE configuration failed, please check XenCenter logs.</value>
</data>
Expand Down

0 comments on commit dbf168c

Please sign in to comment.