Giter Club home page Giter Club logo

snmpman's Introduction

SNMPMAN

Java CI with Maven javadoc Maven Central Docker Image Size (latest by date) License

The SNMPMAN is a command-line application that simulates SNMP-capable devices and was developed to be usable during unit testing. It may be used to test traffic monitoring applications that execute SNMP queries. Due to the lack of flexibility in already existing alternatives, it was developed by the IONOS SE to improve flexibility. Therefore the SNMPMAN is highly extendable and will be enhanced over time.

Multiple SNMP agents may be started at once and will run in parallel. The agents running in parallel will return the data queried and save it to a textual walk result file. This file will be created by querying a real device. It is also possible to query several device types at once. The query configuration may contain policies on how to dynamically change the query responses. E.g. the response of an ifInOctets may be incremented with each query to simulate traffic. Several variable modifiers are already in existence for different data types.

Usage

SNMPMAN can either be used as

  • Java library
  • Standalone command line program
  • Docker image

Java library usage

You can include the SNMPMAN as a Maven dependency from Maven Central.

<dependency>
    <groupId>com.oneandone</groupId>
    <artifactId>snmpman</artifactId>
    <version>2.2.0</version>
</dependency>

In order to start and stop the simulation use this code snippet as an example:

/* 
 * creates a new instance of the SNMPMAN with the specified configuration file 
 * and executes all agents 
 */
Snmpman snmpman = Snmpman.start(new File("configuration.yaml"));
/* ... do something with the agents */

/* stop the SNMPMAN and all started agents */
snmpman.stop();

Standalone commandline usage

For standalone commandline usage, you need to pass a YAML file as a configuration.

The commandline options are:

 -c (--configuration) FILE  : the path to the configuration YAML
 -h (--help)                : print the help message (Vorgabe: false)

A YAML configuration specifying one SNMP agent, binding to IP 127.0.0.1, UDP port 10000 and SNMP community 'public' is given here:

- name: "example1"
  device: "/opt/snmpman/etc/devices/ios.yaml"
  walk: "/opt/snmpman/etc/walk/example1.walk"
  ip: "127.0.0.1"
  port: 10000
  community: public

The walk can be a SNMP walk extracted with the 'snmpwalk' command line program with the options -On.

Docker usage

There's an experimental docker image available that can be used to simulate SNMP agents.

Available configuration options:

  • SNMPMAN_CONFIG: The location of the default configuration can be changed using the env var SNMPMAN_CONFIG, it defaults to a sample config at /snmpman/etc/configuration.yaml if you're not specifying thie config file. Instead of providing a full-blown config, you can also let the docker entrypoint create a config for you with the following env vars.
  • SNMPMAN_PORT: The UDP port to bind to, from the perspective of the docker container. Only gets written if SNMPMAN_CONFIG is not set.
  • SNMPMAN_COMMUNITY: The SNMP community to use for authentication. Only gets written if SNMPMAN_CONFIG is not set.
  • SNMPMAN_WALK: The location of the SNMP walk to provide via SNMP in the docker container filesystem (can be bind-mounted as a volume into the container). Only gets written if SNMPMAN_CONFIG is not set.

Sample call mounting a walk inside the container and binding the container towards the standard SNMP port 161:

docker run -v ABSOLUTE/PATH/TO/walk.txt:/snmpman/etc/walk/example1.walk -p 161:10000/udp stephanfuhrmannionos/snmpman

Installation and building

Prerequisites

  • Java JDK 9+
  • Apache Maven 3.5.2

Building a fat Jar

In order to build the SNMPMAN you can use Apache Maven to build a far JAR:

mvn clean package

After that you find your JAR in snmpman-cli/target/snmpman-cli-$VERSION-SNAPSHOT-jar-with-dependencies.jar.

Execution

To execute an instance of the SNMPMAN you have to start the execution script and specify a value for the -c or --configuration option that lists the path to the configuration YAML file that will be loaded during execution.

Configuration

The SNMPMAN configuration can be found in two main YAML files ...

  • The agent configuration lists all agents which will be started
  • The device type configuration defines the modifiers that will be applied to a range of OIDs

You can find some YAML example configuration files within the test resources of this project in this directory.

The third component of the configuration are the walk files for the agents as specified in the agent configuration.

This is a basic overview and more information will be provided on the project's Wiki pages.

Contribution

This section gives some pointers about contributions to the snmpman project. The project is being developed by the community. Maintainers merge pull-requests, fix critical bugs, etc.

If you fixed or added something useful to the project, you can send a pull-request. It will be reviewed and accepted, or commented on for rework by maintainers. Pull-requests are declined if a maintainer closes the request.

snmpman's People

Contributors

bitionaire avatar dependabot[bot] avatar netdevfighter avatar sfuhrm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snmpman's Issues

Variables are not Modified

The result of the snmp walk of randomized values is only randomized once at application startup. In any other case it remains constant.
But it should change on every snmp walk.
I discovered that this issue first appeared after the class MOGroup was deleted in commit 78675aa

Fix JDK10 build & Lombok

[INFO] Changes detected - recompiling the module!
[INFO] Compiling 25 source files to /home/travis/build/1and1/snmpman/snmpman/target/classes
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by lombok.javac.apt.LombokProcessor to field com.sun.tools.javac.processing.JavacProcessingEnvironment.discoveredProcs
WARNING: Please consider reporting this to the maintainers of lombok.javac.apt.LombokProcessor
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Update from legacy Jackson 2.5.1

The update breaks the code because property loading in Jackson stopped working.

Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.oneandone.snmpman.configuration.modifier.Modifier`, problem: property "minimum" is not a number
 at [Source: (File); line: 10, column: 3] (through reference chain: com.oneandone.snmpman.configuration.Device["modifiers"]->java.lang.Object[][0])
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
	at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:1601)
	at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.wrapAsJsonMappingException(StdValueInstantiator.java:484)
	at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.rewrapCtorProblem(StdValueInstantiator.java:503)
	at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:285)
	at com.fasterxml.jackson.databind.deser.ValueInstantiator.createFromObjectWith(ValueInstantiator.java:229)
	at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:195)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:422)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1287)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
	at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:195)
	at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:21)
	at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:530)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:528)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:417)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1287)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2902)
	at com.oneandone.snmpman.configuration.AgentConfiguration$DeviceFactory.getDevice(AgentConfiguration.java:61)
	... 26 more
Caused by: java.lang.ClassCastException: property "minimum" is not a number
	at com.oneandone.snmpman.configuration.type.ModifierProperties.getNumber(ModifierProperties.java:60)
	at com.oneandone.snmpman.configuration.type.ModifierProperties.getInteger(ModifierProperties.java:19)
	at com.oneandone.snmpman.configuration.modifier.Integer32Modifier.init(Integer32Modifier.java:27)
	at com.oneandone.snmpman.configuration.modifier.Modifier.<init>(Modifier.java:45)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.fasterxml.jackson.databind.introspect.AnnotatedConstructor.call(AnnotatedConstructor.java:124)
	at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:283)
	... 43 more

Add Debian and RedHat packaging

Debian and RedHat packaging plugins will be added to the pom.xml so that those packages can be constructed automatically by a specified maven profile.

Create some base configuration files that will be installed by default.

e.g.
mvn clean package -P debian
mvn clean package -P redhat

Improve error handling

Under some circumstances, it's not useful to just log a problem, but better to throw an Error.
After some errors it won't make sense to go on.

Example: No UTF-8 Charset ... this is very unlikely.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.