soulwing / tnm4j

A simplified SNMP API for Java, based on Jürgen Schönwälder's Tnm extension for Tcl.
GNU General Public License v3.0
41 stars 18 forks source link

SnmpV3 #3

Closed komcrad closed 5 years ago

komcrad commented 7 years ago

Do you have any examples on using this for snmpv3? A simple snmpv3 get perhaps? I thought it would be similar to using snmpv2c but I'm getting an Unsupported security model Exception.

ceharris commented 7 years ago

I thought I had an example around for it, but I don't see it. I'll try to address that soon.

Here's something that should be pretty close. I don't have an SNMPv3 capable agent handy at the moment to try it myself.

  public static void main(String[] args) throws Exception {
    SimpleSnmpV3Target target = new SimpleSnmpV3Target();
    target.setAddress(System.getProperty("tnm4j.agent.address", "10.0.0.1"));
    target.setSecurityName(System.getProperty("tnm4j.agent.username", "manager"));
    target.setAuthType(SnmpV3Target.AuthType.SHA);
    target.setPrivType(SnmpV3Target.PrivType.AES128);
    target.setAuthPassphrase(System.getProperty("tnm4j.agent.auth.password", "authpasswd"));
    target.setPrivPassphrase(System.getProperty("tnm4j.agent.priv.password", "privpasswd"));
    SnmpContext context = SnmpFactory.getInstance().newContext(target);
    try {
      VarbindCollection result = context.get("1.3.6.1.2.1.1.3.0").get();
      System.out.println(result.get(0));
    }
    finally {
      context.close();
    }

  }

I'm v

komcrad commented 7 years ago

I have tried to use your rough draft and different iterations. I keep getting this; Caused by: org.snmp4j.MessageException: Message processing model 3 returned error: Unsupported security model at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:506) at org.snmp4j.Snmp.sendMessage(Snmp.java:1004) at org.snmp4j.Snmp.send(Snmp.java:974) at org.soulwing.snmp.provider.snmp4j.SessionWrapper$AbstractRequest.send(SessionWrapper.java:200) at org.soulwing.snmp.provider.snmp4j.SessionWrapper$SynchronousRequest.get(SessionWrapper.java:250) at org.soulwing.snmp.provider.snmp4j.SessionWrapper.send(SessionWrapper.java:100) at org.soulwing.snmp.provider.snmp4j.SessionWrapper.send(SessionWrapper.java:88) at org.soulwing.snmp.provider.snmp4j.SessionWrapper.get(SessionWrapper.java:118) at org.soulwing.snmp.provider.snmp4j.GetOperation.doInvoke(GetOperation.java:48) at org.soulwing.snmp.provider.snmp4j.AbstractOperation.invoke(AbstractOperation.java:97) at org.soulwing.snmp.provider.snmp4j.Snmp4jContext.get(Snmp4jContext.java:215) Does it give you any ideas?

komcrad commented 7 years ago

I seemed to of gotten around the issue by modifying provider.snmp4j.UserTargetStrategy. To get an idea of what I think the issue is, changes can be seen here: https://github.com/komcrad/tnm4j/commit/720560b49394ad236d7d17941d0b85f69f0f49a9

ceharris commented 7 years ago

Looks reasonable. Make sure your changes use the same style (indents, etc) as the source you're changing, and submit a pull request. I'll merge it.

ceharris commented 7 years ago

Looks like the transport model configuration was discarded when UserTargetStrategy was created and separated from another class, a long time back.

komcrad commented 7 years ago

Will maven central be updated with this patch?

ceharris commented 7 years ago

Yes, but I need to update dependencies in the pom before I cut a new release, and didn't have time for that this morning.

ceharris commented 7 years ago

I'll update this issue when I do...

komcrad commented 7 years ago

Perfect! Thanks for your help.

komcrad commented 7 years ago

Could you deploy a .7 and then update dependencies in a .8 patch?

ceharris commented 7 years ago

Sorry for the delay in getting back to this. Had a death in our family. It wasn't unexpected, but more sudden than expected.

So I did a 1.0.7 release today. Should hit Maven Central in the next few hours.

ceharris commented 7 years ago

I'm going to open a separate issue for updating dependencies.

komcrad commented 7 years ago

My condolences.

I ended up deploying a fork. There's another patch I made that seems possibly toxic but it solved an issue I was having. I'll make a separate issue for that this week hopefully with a pull request.