SNMP4J Wrapper

A small and convenient wrapper around SNMP4J.

License

License

Categories

Categories

Net
GroupId

GroupId

com.softos.net
ArtifactId

ArtifactId

snmp4j-wrapper
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

SNMP4J Wrapper
A small and convenient wrapper around SNMP4J.
Project URL

Project URL

https://github.com/bnese/snmp4j-wrapper
Project Organization

Project Organization

Børge Nese
Source Code Management

Source Code Management

https://github.com/bnese/snmp4j-wrapper

Download snmp4j-wrapper

How to add to project

<!-- https://jarcasting.com/artifacts/com.softos.net/snmp4j-wrapper/ -->
<dependency>
    <groupId>com.softos.net</groupId>
    <artifactId>snmp4j-wrapper</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.softos.net/snmp4j-wrapper/
implementation 'com.softos.net:snmp4j-wrapper:1.0.1'
// https://jarcasting.com/artifacts/com.softos.net/snmp4j-wrapper/
implementation ("com.softos.net:snmp4j-wrapper:1.0.1")
'com.softos.net:snmp4j-wrapper:jar:1.0.1'
<dependency org="com.softos.net" name="snmp4j-wrapper" rev="1.0.1">
  <artifact name="snmp4j-wrapper" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.softos.net', module='snmp4j-wrapper', version='1.0.1')
)
libraryDependencies += "com.softos.net" % "snmp4j-wrapper" % "1.0.1"
[com.softos.net/snmp4j-wrapper "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.snmp4j : snmp4j jar 2.5.11

test (2)

Group / Artifact Type Version
org.snmp4j : snmp4j-agent jar 2.6.2
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

License

SNMP4J Wrapper

Introduction

A small and convenient wrapper around SNMP4J. Require Java 8 or higher.

Maven

<dependency>
        <groupId>com.softos.net</groupId>
        <artifactId>snmp4j-wrapper</artifactId>
        <version>1.0.1</version>
</dependency>

Example

package com.softos.net.snmp;

import org.snmp4j.Snmp;
import org.snmp4j.Target;
import org.snmp4j.smi.OID;

import java.io.IOException;
import java.text.ParseException;

import static com.softos.net.snmp.SnmpTargetBuilder.Version.V2c;

public class Example {
    public static void main(String[] args) throws IOException, ParseException {
        Target target = SnmpTargetBuilder.builder()
                .withHost("192.168.8.1")
                .withCommunity("public")
                .withVersion(V2c)
                .build();

        final Snmp snmp = SnmpBuilder.getDefaultSnmp();

        final Snmp4jWrapper wrapper = new Snmp4jWrapper(target, snmp);

        final OID[] ifIndexedColumns = {
                new OID("1.3.6.1.2.1.2.2.1.1"),
                new OID("1.3.6.1.2.1.2.2.1.2"),
                new OID("1.3.6.1.2.1.31.1.1.1.1"),
                new OID("1.3.6.1.2.1.31.1.1.1.18"),
                new OID("1.3.6.1.2.1.2.2.1.5")};

        final OID[] ipaddressIndexedColumns = {
                new OID("1.3.6.1.2.1.4.20.1.1"),
                new OID("1.3.6.1.2.1.4.20.1.2"),
                new OID("1.3.6.1.2.1.4.20.1.3"),
                new OID("1.3.6.1.2.1.4.20.1.4"),
                new OID("1.3.6.1.2.1.4.20.1.5")
        };

        System.out.println("ifIndexedColumns - no lower bound index, stop at index 2 (inclusive)");
        wrapper.getTable(ifIndexedColumns, null, new OID("2"))
                .forEach((oid, variableBindings) -> System.out.println(oid + ": " + variableBindings));
        System.out.println();

        System.out.println("ifIndexedColumns - start at index 1 (exclusive), stop at index 3 (inclusive)");
        wrapper.getTable(ifIndexedColumns, new OID("1"), new OID("3"))
                .forEach((oid, variableBindings) -> System.out.println(oid + ": " + variableBindings));
        System.out.println();

        System.out.println("ipaddressIndexedColumns - start at index 192.168.1.0 (exclusive), no upper bound");
        wrapper.getTable(ipaddressIndexedColumns, new OID("192.168.1.0"), null)
                .forEach((oid, variableBindings) -> System.out.println(oid + ": " + variableBindings));
        System.out.println();

        System.out.println("ipaddressIndexedColumns - No bounds");
        wrapper.getTable(ipaddressIndexedColumns)
                .forEach((oid, variableBindings) -> System.out.println(oid + ": " + variableBindings));
        System.out.println();

        System.out.println("sysUpTime:");
        wrapper.getNext(new OID("1.3.6.1.2.1.1.3"))
                .forEach(System.out::println);
        System.out.println();

    }
}

Example output

ifIndexedColumns - no lower bound index, stop at index 2 (inclusive)
1: [1.3.6.1.2.1.2.2.1.1.1 = 1, 1.3.6.1.2.1.2.2.1.2.1 = GigabitEthernet8, 1.3.6.1.2.1.31.1.1.1.1.1 = Gi8, 1.3.6.1.2.1.31.1.1.1.18.1 = WAN, 1.3.6.1.2.1.2.2.1.5.1 = 1000000000]
2: [1.3.6.1.2.1.2.2.1.1.2 = 2, 1.3.6.1.2.1.2.2.1.2.2 = GigabitEthernet9, 1.3.6.1.2.1.31.1.1.1.1.2 = Gi9, 1.3.6.1.2.1.31.1.1.1.18.2 = , 1.3.6.1.2.1.2.2.1.5.2 = 1000000000]

ifIndexedColumns - start at index 1 (exclusive), stop at index 3 (inclusive)
2: [1.3.6.1.2.1.2.2.1.1.2 = 2, 1.3.6.1.2.1.2.2.1.2.2 = GigabitEthernet9, 1.3.6.1.2.1.31.1.1.1.1.2 = Gi9, 1.3.6.1.2.1.31.1.1.1.18.2 = , 1.3.6.1.2.1.2.2.1.5.2 = 1000000000]
3: [1.3.6.1.2.1.2.2.1.1.3 = 3, 1.3.6.1.2.1.2.2.1.2.3 = GigabitEthernet0, 1.3.6.1.2.1.31.1.1.1.1.3 = Gi0, 1.3.6.1.2.1.31.1.1.1.18.3 = VPN-Server, 1.3.6.1.2.1.2.2.1.5.3 = 100000000]

ipaddressIndexedColumns - start at index 192.168.1.0 (exclusive), no upper bound
192.168.9.9: [1.3.6.1.2.1.4.20.1.1.192.168.9.9 = 192.168.9.9, 1.3.6.1.2.1.4.20.1.2.192.168.9.9 = 20, 1.3.6.1.2.1.4.20.1.3.192.168.9.9 = 255.255.255.252, 1.3.6.1.2.1.4.20.1.4.192.168.9.9 = 1, 1.3.6.1.2.1.4.20.1.5.192.168.9.9 = 18024]
192.168.40.1: [1.3.6.1.2.1.4.20.1.1.192.168.40.1 = 192.168.40.1, 1.3.6.1.2.1.4.20.1.2.192.168.40.1 = 21, 1.3.6.1.2.1.4.20.1.3.192.168.40.1 = 255.255.255.0, 1.3.6.1.2.1.4.20.1.4.192.168.40.1 = 1, 1.3.6.1.2.1.4.20.1.5.192.168.40.1 = 18024]
192.168.8.1: [1.3.6.1.2.1.4.20.1.1.192.168.8.1 = 192.168.8.1, 1.3.6.1.2.1.4.20.1.2.192.168.8.1 = 13, 1.3.6.1.2.1.4.20.1.3.192.168.8.1 = 255.255.255.0, 1.3.6.1.2.1.4.20.1.4.192.168.8.1 = 1, 1.3.6.1.2.1.4.20.1.5.192.168.8.1 = 18024]

ipaddressIndexedColumns - No bounds
192.168.9.9: [1.3.6.1.2.1.4.20.1.1.192.168.9.9 = 192.168.9.9, 1.3.6.1.2.1.4.20.1.2.192.168.9.9 = 20, 1.3.6.1.2.1.4.20.1.3.192.168.9.9 = 255.255.255.252, 1.3.6.1.2.1.4.20.1.4.192.168.9.9 = 1, 1.3.6.1.2.1.4.20.1.5.192.168.9.9 = 18024]
192.168.40.1: [1.3.6.1.2.1.4.20.1.1.192.168.40.1 = 192.168.40.1, 1.3.6.1.2.1.4.20.1.2.192.168.40.1 = 21, 1.3.6.1.2.1.4.20.1.3.192.168.40.1 = 255.255.255.0, 1.3.6.1.2.1.4.20.1.4.192.168.40.1 = 1, 1.3.6.1.2.1.4.20.1.5.192.168.40.1 = 18024]
92.x.y.z: [1.3.6.1.2.1.4.20.1.1.92.x.y.z = 92.x.y.z, 1.3.6.1.2.1.4.20.1.2.92.x.y.z = 16, 1.3.6.1.2.1.4.20.1.3.92.x.y.z = 255.255.248.0, 1.3.6.1.2.1.4.20.1.4.92.x.y.z = 1, 1.3.6.1.2.1.4.20.1.5.92.x.y.z = 18024]
192.168.8.1: [1.3.6.1.2.1.4.20.1.1.192.168.8.1 = 192.168.8.1, 1.3.6.1.2.1.4.20.1.2.192.168.8.1 = 13, 1.3.6.1.2.1.4.20.1.3.192.168.8.1 = 255.255.255.0, 1.3.6.1.2.1.4.20.1.4.192.168.8.1 = 1, 1.3.6.1.2.1.4.20.1.5.192.168.8.1 = 18024]

sysUpTime:
1.3.6.1.2.1.1.3.0 = 17 days, 4:17:40.52

License

Licensed under Apache License Version 2.0, see LICENSE. See THIRD-PARTY-LICENSE.txt for dependency licenses.

Versions

Version
1.0.1
1.0.0