Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP-44171: XenCenter: Add SNMP page #3254

Conversation

YizhouChen1998
Copy link

No description provided.

@DeliZhangX
Copy link

As we discussed, remember to change UI

  • Authentication Passphrase --> Authentication Password
  • Privacy Passphrase--> Privacy Password
  • Security Name --> User Name

See details from CA-384958.

@YizhouChen1998
Copy link
Author

As we discussed, remember to change UI

  • Authentication Passphrase --> Authentication Password
  • Privacy Passphrase--> Privacy Password
  • Security Name --> User Name

See details from CA-384958.

finished and committed

@kc284 kc284 added ITE PR should be reviewed within this iteration and removed ITE PR should be reviewed within this iteration labels Nov 13, 2023
privacy_protocol = _snmpConfiguration.PrivacyProtocol,
}
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some redundant codes for these three if statements. Can we combine these three if statements into one?

{
{"config", new JavaScriptSerializer().Serialize(configArgObj)}
};
var resultJson = Host.call_plugin(o.Connection.Session, o.opaque_ref, SnmpXapiConfig.XAPI_SNMP_PLUGIN_NAME,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resultJson is not used. Can remove it, or record some logs.

authentication_password = _snmpConfiguration.AuthPass,
authentication_protocol = _snmpConfiguration.AuthProtocol,
privacy_password = _snmpConfiguration.PrivacyPass,
privacy_protocol = _snmpConfiguration.PrivacyProtocol,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing comma.

using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Dynamic;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary packages.

<value>Privacy password is invalid</value>
</data>
<data name="SNMP_ALLOW_SECURITY_TITLE" xml:space="preserve">
<value>Security name is invalid</value>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security name -> User Name


public bool Equals(SnmpConfiguration other)
{
return !(IsSnmpEnabled != other.IsSnmpEnabled ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more clear to use equal than to use not equal. Can be replaced like this:

return (IsSnmpEnabled == other.IsSnmpEnabled &&
        IsLogEnabled == other.IsLogEnabled &&
...

public SnmpConfiguration() { }


public object Clone()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used, can be removed. ICloneable needs not to be implemented.

XenModel/Actions/SNMP/SnmpUpdateAction.cs Outdated Show resolved Hide resolved
var configArgObj = GetConfigArgObj();
Dictionary<string, string> configArgDict = new Dictionary<string, string>
{
{"config", new JavaScriptSerializer().Serialize(configArgObj)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of config is a JSON string. Can we use JsonSerializer to serialize the JSON object?

private GroupBox GeneralConfigureGroupBox;
private TableLayoutPanel GeneralConfigTableLayoutPanel;

private CheckBox EnableSnmpCheckBox;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The height of EnableSnmpCheckBox, DebugLogCheckBox, and SupportV3CheckBox is different. Please adjust them.

@YizhouChen1998
Copy link
Author

I have resolved and recommitted the issue you mentioned above. @BengangY

Copy link
Contributor

@kc284 kc284 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the first comments I have from reading the code (plus the layout tweaks in that patch file I sent you, you can also see it here kc284@4f4a7ff).
I may have some more comments later after I set up a machine and try out the code, but in the mean time you can work on the current stuff.

@@ -317,6 +318,11 @@ private void Build()
dialog.ShowDialog(Program.MainWindow);
}
}
if (isPoolOrStandalone)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The page should not be visible at all for servers that don't have the plugin installed. Showing the error "retrieving the SNMP configuration failed" is misleading, especially for LCM servers where SNMP is not supported. We need a version check. Helpers.NileOrGreater, for example, excludes LCM servers. However, it is not enough because it does not exclude stream servers where updates have not been installed yet. We need a plugin version check (or a xapi version check as a compromise; we did this for NRPE).

Also, to keep a uniform behaviour with NRPE, the page should not be visible for users that are not pool admins.

<value>SNMP configuration</value>
</data>
<data name="SNMP_RETRIEVE_FAILED" xml:space="preserve">
<value>Failed to retrieve SNMP configuration, please check XenCenter logs.</value>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This contains the product brand, which causes problems for forks that do rebranding. We need to use Failed to retrieve SNMP configuration, please check {0} logs. and then call it in the code as string.Format(Messages.SNMP_RETRIEVE_FAILED, BrandManager.BrandConsole) - or a simpler solution is to say Failed to retrieve SNMP configuration, please check the application logs.
The same applies to the other messages below.

<value>Failed to retrieve SNMP configuration, please check XenCenter logs.</value>
</data>
<data name="SNMP_UPDATE_ERROR1" xml:space="preserve">
<value>Common error, please check XenCenter logs for details.</value>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of error is the "common error"? It sounds a bit vague.


public bool Equals(SnmpConfiguration other)
{
return (IsSnmpEnabled == other.IsSnmpEnabled &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parentheses are not needed. Missing null check: return other != null && ...

Also, very trivial issue, but could you please leave an empty line between the various class declarations so the code is easier to read (just use VS to auto-format the file).

private readonly IXenObject _clone;

public SnmpRetrieveAction(IXenObject host, SnmpConfiguration snmpConfiguration, bool suppressHistory)
: base(host.Connection, "Retrieving SNMP configuration", "Retrieving SNMP configuration", suppressHistory)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These strings here are shown on the UI, therefore we need to internationalize them, i.e. move them to Messages.resx.

if (SupportV2cCheckBox.Checked)
{
var communityStr = CommunityTextBox.Text;
if (!RegexCommon.Match(communityStr.Trim()).Success)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be checking for null first? I.e. if (string.IsNullOrEmpty(communityStr) || !Regex...). Same in the other checks below.

}
private void EnableSNMPCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (EnableSnmpCheckBox.Checked)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if-else block can be replaced with:

DebugLogCheckBox.Enabled = EnableSnmpCheckBox.Checked;
SnmpV2cGroupBox.Enabled = EnableSnmpCheckBox.Checked && SupportV2cCheckBox.Checked;
etc.

{
get
{
_invalidParamToolTip.Dispose();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to dispose and reconstruct the tooltip every time, we can make it readonly and just hide/show it and change the text. Also, to decide on which control to show it you can use the Tag, but an alternative way would be to use HelpersGUI.ShowBalloonMessage(). Have a look in file GeneralEditPage.cs to see how that tooltip is used.

private string _invalidParamToolTipText = "";
private static readonly Regex RegexCommon = new Regex(@"^[a-zA-Z0-9-.\#@=:_]{6,32}$");
private static readonly Regex RegexEncryptTextBox = new Regex(@"^([a-zA-Z0-9-.\#@=:_]{8,32}|[*]{8})$");
private static bool _encryptTextBoxFlag = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting to false when declaring the field is not needed because it is the default value anyway. Also, why is it static?

{
public partial class SnmpEditPage : UserControl, IEditPage
{
public string SubText => Messages.SNMP_EDIT_PAGE_TEXT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very trivial thing, but since you'll be making changes in this file anyway let's tidy up a bit:

  • Sort usings alphabetically.
  • Move the constructor after the private fields, and SubText and Image properties after the constructor.
  • Move SaveSettings closer to the other IEditPage implementation methods.
  • Leave a line between all methods so the code can breath a bit (lack of lines is normally a C++ style).

@kc284 kc284 added the needs updating A reviewer has requested changes label Nov 15, 2023
@kc284 kc284 added updated Changes completed, please review and removed needs updating A reviewer has requested changes labels Nov 22, 2023
Copy link
Contributor

@kc284 kc284 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the above comment I have made some more changes here kc284@68a9b41 (I also sent you this patch privately), please try it out and let me know what you think.

@@ -317,6 +318,12 @@ private void Build()
dialog.ShowDialog(Program.MainWindow);
}
}
if (isPoolOrStandalone && Helpers.XapiEqualOrGreater_23_18_0(connection)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

23.18.0 is a very early version. In any case, @DeliZhangX mentioned they will be adding a feature flag, so we can now check that one instead of the xapi version (I would also add the Helpers.NileOrGreater check as an extra safety valve for older servers). See XenModel/XenAPI-Extensions/Host.cs for methods checking the feature flags.

@YizhouChen1998 YizhouChen1998 changed the title CP-44171: XenCenter: Add SNMP page CP-44171: XenCenter: Add SNMP page(Not ready for review) Nov 30, 2023
@danilo-delbusso danilo-delbusso added the do not review yet PR is still being drafted, do not review. label Nov 30, 2023
@danilo-delbusso danilo-delbusso changed the title CP-44171: XenCenter: Add SNMP page(Not ready for review) CP-44171: XenCenter: Add SNMP page Nov 30, 2023
@danilo-delbusso danilo-delbusso marked this pull request as draft November 30, 2023 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not review yet PR is still being drafted, do not review. updated Changes completed, please review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants