Google+

SNMP Simulator Project Logo
SNMP Simulator introduction
Producing SNMP snapshots
Simulating SNMP Agents
Transport-based variation
Sharing snapshots
MIB-based simiulation
Simulation based on captured traffic
Simulation with variation modules
Recording with variation modules
Managing data files
Large scale simulation
Tips and tricks
Download & Install
License
Changelog
Github repo
Adding features
Simulation Service
Contact
Get SNMP Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads

Recording with value variation modules

Features described in this chapter are only applicable to Simulator versions 0.2.1 and later.

Some valuable simulation information may also be collected in the process of recording snapshots off live SNMP Agent. Examples include changes in the set of OIDs in time, changes in numeric values, request processing times and so on. To facilitate capturing such information, some of the stock variation modules support snapshots recording mode.

To invoke a variation module while snapshotting a SNMP Agent with snmprec.py tool, pass its name via the --variation-module command-line parameter. Additional variation module parameters could also be passed through the --variation-module-options switch.

In the following sections we will outline the use of recording facilities in stock variation modules. Here's the current list of recording variation modules supplied with Simulator:

  • numeric - produces a non-decreasing sequence of integers over time
  • delay - delays SNMP response by specified number of miliseconds.
  • multiplex - records a series of snapshots at specified time interval.
  • sql - reads/writes var-binds from/to a SQL database
  • redis - reads/writes var-binds from/to a no-SQL database

What follows is a brief description of the recording variation modules included into the distribution.

Numeric module

The numeric module can be used for capturing initial values of Managed Objects and calculating a coefficient to a linear function in attempt to approximate live values changes in time. In case value change law is not linear, custom approximation function should be used instead.

The numeric module supports the following comma-separated key:value options whilst running in recording mode:

  • taglist - a dash-separated list of .snmprec tags indicating SNMP value types to apply numeric module to. Valid tags are:
    • 2 - Integer
    • 65 - Counter32
    • 66 - Gauge32
    • 67 - TimeTicks
    • 70 - Counter64
    Default is empty list.
  • iterations - number of times snmprec.py will walk the specified [portion] of Agent's MIB tree. There's no point in values beyond 2 for purposes of modelling approximation function. Default is 1.
  • period - Agent walk period in seconds. Default is 10 seconds.
  • addon - a single snmprec record scope key=value parameter for the multiplex module to be used whilst running in variation mode. Multiple addon parameters can be used. Default is empty.

Example use of numeric module for recording follows:

$ snmprec.py --agent-udpv4-endpoint=demo.snmplabs.com
  --start-oid=1.3.6.1.2.1.2 --stop-oid=1.3.6.1.2.1.3
  --variation-module=numeric
  --variation-module-options=taglist:65,iterations:2,period:15
Scanning "/usr/local/share/snmpsim/variation" directory for variation
modules...numeric module loaded
SNMP version 2c
Community name: public
Querying UDP/IPv4 agent at demo.snmplabs.com:161
Initializing variation module:
    numeric...OK
numeric: waiting 0.77 sec(s), 111 OIDs dumped, 1 iterations remaining...
...
1.3.6.1.2.1.2.2.1.6.4|4x|008d120f4fa4
1.3.6.1.2.1.2.2.1.7.1|2|1
1.3.6.1.2.1.2.2.1.9.2|67|0
1.3.6.1.2.1.2.2.1.10.1|65:numeric|rate=3374,initial=641734,increasing=1
1.3.6.1.2.1.2.2.1.10.2|65:numeric|rate=0,initial=0,increasing=1
1.3.6.1.2.1.2.2.1.10.4|65:numeric|rate=1159,initial=32954879,increasing=1
1.3.6.1.2.1.2.2.1.11.1|65:numeric|rate=86,initial=12238,increasing=1
1.3.6.1.2.1.2.2.1.21.1|66|0
...
Shutting down variation modules:
    numeric...OK
OIDs dumped: 224, elapsed: 15.53 sec, rate: 20.00 OIDs/sec

In the above example we have run two iterations against a subset of Managed Objects at an Agent requesting numeric module to configure itself into generated .snmprec data for Counter32-typed objects (ID 65).

Produced snmprec could be used for simulation as-is or edited by hand to change variation module behaviour on on a per-OID basis.

Delay module

The delay module can be used for capturing request processing time when snapshotting an Agent.

Example use of delay module for recording follows:

$ snmprec.py --agent-udpv4-endpoint=demo.snmplabs.com
  --start-oid=1.3.6.1.2.1.2 --stop-oid=1.3.6.1.2.1.3
  --variation-module=delay
Scanning "/usr/local/share/snmpsim/variation" directory for variation
modules...delay module loaded
SNMP version 2c
Community name: public
Querying UDP/IPv4 agent at demo.snmplabs.com:161
Initializing variation module:
    delay...OK
1.3.6.1.2.1.2.1.0|2:delay|value=5,wait=8
1.3.6.1.2.1.2.2.1.1.1|2:delay|value=1,wait=32
1.3.6.1.2.1.2.2.1.6.4|4x:delay|hexvalue=008d120f4fa4,wait=20
...
Shutting down variation modules:
    delay...OK
OIDs dumped: 224, elapsed: 15.53 sec, rate: 20.00 OIDs/sec

Produced snmprec could be used for Simulation as-is or edited by hand to change delay variation.

Multiplex module

The multiplex module can record a series of snapshots at specified period of time. Recorded .snmprec snapshots could then be used for simulation by multiplex module.

The multiplex module supports the following comma-separated key:value options whilst running in recording mode:

  • dir - directory for produced .snmprec files.
  • iterations - number of times snmprec.py will walk the specified [portion] of Agent's MIB tree. Default is 1.
  • period - Agent walk period in seconds. Default is 10 seconds.
  • addon - a single snmprec record scope key=value parameter for the multiplex module to be used whilst running in variation mode. Multiple addon parameters can be used. Default is empty.

Example use of numeric module for recording follows:

$ snmprec.py --agent-udpv4-endpoint=demo.snmplabs.com
  --start-oid=1.3.6.1.2.1.2 --stop-oid=1.3.6.1.2.1.3
  --output-file=data/multiplex.snmprec
  --variation-module=multiplex
  --variation-module-options=dir:data/multiplex,iterations:5,period:15
Scanning "/usr/local/share/snmpsim/variation" directory for variation modules...multiplex module loaded
SNMP version 2c
Community name: public
Querying UDP/IPv4 agent at demo.snmplabs.com:161
Initializing variation module:
    multiplex...OK
multiplex: writing into data/multiplex/00000.snmprec file...
multiplex: waiting 14.78 sec(s), 45 OIDs dumped, 5 iterations remaining...
...
multiplex: writing into data/multiplex/00005.snmprec file...
Shutting down variation modules:
    multiplex...OK
OIDs dumped: 276, elapsed: 75.76 sec, rate: 3.64 OIDs/sec

Besides individual snmprec snapshots the "main" .snmprec file will also be written:

$ cat data/multiplex.snmprec
1.3.6.1.2.1.2|:multiplex|period=15.00,dir=data/multiplex
$

where the multiplex module is configured for specific OID subtree (actually, specified in --start-oid).

Although multiplex-generated .snmprec files can also be addressed directly by Simulator, it's more conventional to access them through "main" .snmprec file and multiplex module.

SQL module

The sql module can record a snapshot of Agent's set of Managed Objects and store it in a SQL database. Recorded snapshots could then be used for simulation by sql module running in variation mode.

Module configuration parameters are described in the simulation chapter.

Module invocation requires passing database type (sqlite3, psycopg2, MySQL and any other compliant to Python DB-API and importable as a Python module) and connect string which is database dependant:

Here's an example use of sql module with Python built-in SQLite database for snapshot recording purposes:

$ snmprec.py --agent-udpv4-endpoint=demo.snmplabs.com
  --start-oid=1.3.6.1.2.1.2 --stop-oid=1.3.6.1.2.1.3
  --output-file=data/sql.snmprec
  --variation-module=sql
  --variation-module-options=dbtype:sqlite3,database:/tmp/snmpsim.db,dbtable:snmprec
Scanning "/usr/local/share/snmpsim/variation" directory for variation modules... sql module loaded
SNMP version 2c
Community name: public
Querying UDP/IPv4 agent at demo.snmplabs.com:161
Initializing variation module:
    sql...OK
Shutting down variation modules:
    sql...OK
OIDs dumped: 45, elapsed: 0.21 sec, rate: 213.00 OIDs/sec

By this point you'd get the data/sql.snmprec file where sql module is configured for OID subtree (taked from --start-oid parameter):

$ cat data/sql.snmprec
1.3.6.1.2.1.2.2|:sql|snmprec
$

and SQLite database /tmp/snmpsim.db having SQL table "snmprec" with the following contents:

$ sqlite3 /tmp/snmpsim.db
SQLite version 3.7.5
sqlite> .schema snmprec
CREATE TABLE snmprec (oid text, tag text, value text, maxaccess text);
sqlite> select * from snmprec limit 1;
         1.         3.         6.         1.         2.         1.         
2.         2.         1.         1.         1|2|1|read-write

Notice the format of the OIDs there -- each sub-oid is left-padded with up to 8 spaces (must be 10 chars in total) to make OIDs ordering work properly with SQL sorting facilities.

The following snmprec.py invocation would make it storing snapshots into a MySQL database using native MySQL's Connector/Python driver (since snmpsim 0.2.4):

$ snmprec.py --agent-udpv4-endpoint=demo.snmplabs.com
  --output-file=data/sql.snmprec
  --variation-module=sql
  --variation-module-options=dbtype:mysql.connector,host:127.0.0.1,
port:3306,user:snmpsim,password:snmpsim,database:snmpsim

The above parameters assume that you have the MySQL Connector/Python driver installed on a snapshot recording machine and a MySQL server running at 127.0.0.1 with MySQL user/password snmpsim/snmpsim having sufficient permissions for creating new tables.

Another variation of MySQL server installation setup on a UNIX system employs UNIX domain socket for client-server communication. In that case the following command-line for snmprec might work:

$ snmprec.py --agent-udpv4-endpoint=demo.snmplabs.com
  --output-file=data/sql.snmprec
  --variation-module=sql
  --variation-module-options=dbtype:mysql.connector,unix_socket:
/var/run/mysql/mysql.sock,user:snmpsim,password:snmpsim,database:snmpsim

Alternatively, MySQL for Python package could be used for Simulator to MySQL connection:

$ snmprec.py --agent-udpv4-endpoint=demo.snmplabs.com
  --output-file=data/sql.snmprec
  --variation-module=sql
  --variation-module-options=dbtype:MySQLdb,host:127.0.0.1,port:3306,
user:snmpsim,passwd:snmpsim,db:snmpsim

And here's another example of using PostgreSQL as a database backend for sql variation module. In this example we are using Psycopg adapter (since snmpsim 0.2.5rc0):

$ snmprec.py --agent-udpv4-endpoint=demo.snmplabs.com
  --output-file=data/sql.snmprec
  --variation-module=sql
  --variation-module-options=dbtype:psycopg2,database:snmpsim,user:snmpsim,
password:snmpsim,dbtable:snmprec

Parameters in the example above assume that you have the psycopg2 module installed into Python on a snapshot recording machine and a PostgreSQL server running locally (accessed through default UNIX domain socket). PostgreSQL user/password are snmpsim/snmpsim and this user has sufficient permissions to create new database tables (snmprec table will be created).

When sql variation module is invoked by Simulator, it can read, create and modify individual rows in the SQL database we just created (this is described in relevant section of this document).

You could also modify the contents of such SQL tables, create SQL triggers to react to certain changes elsewhere.

Redis module

(available since snmpsim 0.2.5rc0)

The redis module can record one or more snapshots of Agent's set of Managed Objects and store it in a Redis key-value store. Recorded snapshots could then be replayed by redis module running in variation mode.

Redis database schema and module configuration parameters are described in the simulation chapter.

Module invocation in recording mode accepts the following parameters:

  • host - Redis hostname or IP address.
  • port - Redis TCP port the server is listening on.
  • unix_socket - UNIX domain socket Redis server is listening on.
  • db - Redis database number.
  • password - Redis database admission password.
  • key-spaces-id - key spaces ID to use for recording a single or a series of snapshots
  • iterations - number of snapshots to record (default - 1).
  • period - how many seconds to ways between starting next snapshotting (default - 60 seconds).
  • evalsha - Redis server side Lua script to use for storing oid-value pairs in Redis. If this option is not given, bare Redis SET commands will be used instead.

Here's an example use of redis module for recording five snapshots of a demo SNMP Agent:

$ snmprec.py --agent-udpv4-endpoint=demo.snmplabs.com
  --start-oid=1.3.6.1.2.1.2 --stop-oid=1.3.6.1.2.1.3
  --output-file=data/redis.snmprec
  --variation-module=redis
  --variation-module-options=host:127.0.0.1,port:6379,db:0,key-spaces-id:1111,
iterations:5,period:30
Scanning "variation" directory for variation modules...
Variation module "redis" loaded
SNMP version 2c, Community name: public
Querying UDP/IPv4 agent at 195.218.195.228:161
Initializing variation module...
redis: using key-spaces-id 1111
Variation module "redis" initialization OK
Sending initial GETNEXT request....
redis: done with key-space 0000001116
redis: 4 iterations remaining
85 OIDs dumped, waiting 30.00 sec(s)...
redis: done with key-space 0000001115
redis: 3 iterations remaining
171 OIDs dumped, waiting 30.00 sec(s)...
redis: done with key-space 0000001114
redis: 2 iterations remaining
257 OIDs dumped, waiting 30.00 sec(s)...
redis: done with key-space 0000001113
redis: 1 iterations remaining
343 OIDs dumped, waiting 30.00 sec(s)...
redis: done with key-space 0000001112
redis: 0 iterations remaining
Shutting down variation module redis...
Variation module redis shutdown OK
OIDs dumped: 603, elapsed: 329.22 sec, rate: 0.00 OIDs/sec

By this point you'd get the data/redis.snmprec file where redis module is configured for OID subtree (taked from --start-oid parameter):

$ cat data/redis.snmprec
1.3.6|:redis|period=30.00,key-spaces-id=1111
$

When redis variation module is invoked by Simulator, it can read, create and modify individual OID-value pairs in Redis database we just created. See redis variation module chapter for more information.


Need help? Open an issue at GitHub or ask question at Stack Overflow or try browsing snmpsim-users mailing list.