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

Fixes snmp sender #298

Merged
merged 8 commits into from
Oct 9, 2023
Merged

Fixes snmp sender #298

merged 8 commits into from
Oct 9, 2023

Conversation

kamilernerd
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@KristianLyng KristianLyng left a comment

Choose a reason for hiding this comment

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

I'd like to have the hardcoded OID/PDU thing resolved and preferably also the x.err.

Fixing reflection->regular type switching is nice-to-have, not required.

sender/snmp.go Show resolved Hide resolved
sender/snmp.go Outdated

pduName := fmt.Sprintf("%s", x.Oidmap[j])

switch reflect.TypeOf(i).Kind() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't realize this the last time I approved this, but this really doesn't require reflection.

You can write (copied from marshal.go as an example):

        switch value := v.(type) {
        case float64:
                d.Duration = time.Duration(value)
                return nil
        case string:
                var err error
                d.Duration, err = time.ParseDuration(value)
                if err != nil {
                        return err
                }
                return nil
        default:
                return errors.New("invalid duration")
        }

Reflection is considerably slower, which probably isn't noticeable in an SNMP trap sender, but should, in general, be avoided in busy loops.

sender/snmp.go Outdated

if err != nil {
x.err = err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure you want to do this? This will DISABLE the entire sender on the first mal-formed or failing snmp trap. The pattern of using x.err is mainly meant to remember that initialization (x.init()) failed after sync.Once has run.

Copy link
Collaborator

@KristianLyng KristianLyng left a comment

Choose a reason for hiding this comment

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

The SNMPTrapOID thing needs to be properly resolved since it will dictate configuration we will have to support.

sender/snmp.go Outdated
Value: ".1.3.6.1.4.1.12748.2023.0.888",
Name: ".1.3.6.1.6.3.1.1.4.1.0",
Type: gosnmp.ObjectIdentifier,
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is still hard coded.

I did a little research. Turns out .1.3.6.1.6.3.1.1.4.1 is literally "snmpTrapOID" oid, and always part of a trap, however, the value needs to not be hard-coded, even if it can be overridden now. The value you provide is Telenor-specific, and the .2023 makes it very implementation-specific.

I suggest changing the configurable PduTypes to say "SnmpTrapOID" and being of type string, and then using that as value.

E.g.:

	pdutypes = []gosnmp.SnmpPDU{
			{
				Value: x.SnmpTrapOID,
				Name:  ".1.3.6.1.6.3.1.1.4.1.0",
				Type:  gosnmp.ObjectIdentifier,
			},

That does mean this wont work without configuration, but it shouldn't. The value here should always be configured, it's very much site-local and not something where we can assume a sensible global default exists.

See:

https://oidref.com/1.3.6.1.6.3.1.1.4.1
https://oidref.com/1.3.6.1.4.1.12748

A bonus would be to add to Verify() that it makes sure that the value is:

  1. Actually provided.
  2. Matches [0-9.]+

@KristianLyng KristianLyng merged commit 4b86732 into primary Oct 9, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants