Skip to main content
This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal

Notes/Domino 6 and 7 Forum

Notes/Domino 6 and 7 Forum


  

PreviousPrevious NextNext


~Vanessa Elfanaskiettu 9.Aug.03 07:53 AM a Web browser
Applications Development All Releases Windows XP


'SNMP: Button

Use "snmp-s"
Sub Click(Source As Button)
Call snmp
End Sub
'snmp-s script:

Option Public
Option Declare
Uselsx "*javacon"
Use "snmp-j"

Sub snmp
Dim ws As New NotesUIWorkspace
Dim mySession As JavaSession
Dim myClass As JavaClass
Dim myObject As JavaObject
Dim adc As NotesDocumentCollection
Dim rc As Variant
Dim Ar(1) As String

Ar(0) = "172.0.0.1"
Ar(1) = ".1.3.6.1.2.1.1.3.0"
Set mySession = New JavaSession()
Set myClass = mySession.GetClass("snmpget")
Set myObject = myClass.CreateObject
rc = myObject.main(Ar)
rc = Messagebox(rc, 4+32, "Weiter ?")
If Not rc = 6 Then Exit Sub

Set mySession = New JavaSession()
Set myClass = mySession.GetClass("snmpgetnext")
Set myObject = myClass.CreateObject
rc = myObject.main(Ar)
rc = Messagebox(rc, 4+32, "Weiter ?")
If Not rc = 6 Then Exit Sub


Ar(1) = ".1.3"
Set mySession = New JavaSession()
Set myClass = mySession.GetClass("snmpwalk")
Set myObject = myClass.CreateObject
rc = myObject.main(Ar)
Messagebox(rc)
End Sub


/*
* Copyright (c) 2002 iReasoning Networks. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by iReasoning Networks as part
* of an iReasoning Software product for use ONLY by licensed users of the
product,
* includes CONFIDENTIAL and PROPRIETARY information of iReasoning Networks.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD IREASONING SOFTWARE, ITS
* RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY
* CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR
* DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES
* ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR
* DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR
* DERIVED FROM THIS SOURCE CODE FILE.
*/



import java.io.*;
import java.util.*;
import com.ireasoning.protocol.*;
import com.ireasoning.protocol.snmp.*;
import com.ireasoning.util.ParseArguments;

/**
* This class is the base class of snmp command line programs. It provides
* usefull functionalities such as parsing command line arguments, prints out
* PDU data, etc.
* <br>
* Note: MIB-II is preloaded.
*/
public abstract class snmp
{
String Ausgabe = "x";

protected ParseArguments _parseArgs;

protected int _port;
protected int _version;
protected String _host;
protected String _authProtocol;
protected String _authPassword;
protected String _privPassword;
protected String _community;
protected String _user;
protected String[] _oids ;
protected boolean _isSnmpV3;
protected boolean _numericalOID = false;
protected String[] _mibFiles;
protected String _mibString;
/**
* Prints usage lines without explanation lines
*/
protected void usage(String programName, boolean allowMulitpleOIDs)
{
if(allowMulitpleOIDs)
{
System.out.println( "Usage: java " + programName +
" [options...] <hostname> {<OID> ...]\n");
System.out.println( "<OID>\tobject identifiers, .1.3 by default. Or
MIB node name if MIB loaded");
}
else
{
System.out.println( "Usage: java " + programName +
" [options...] <hostname> {<OID>]\n");
System.out.println( "<OID>\tobject identifier, .1.3 by default.");
}
}

/**
* Prints SnmpPdu content to standard out
*/
protected void print(SnmpPdu pdu)
{
print(pdu, System.out);
}

/**
* Prints SnmpPdu content to PrintStream p
*/
protected void print(SnmpPdu pdu, PrintStream p)
{
if(pdu.getErrorStatus() > 0)
{//Error occurs or end of mib view reached.
System.out.println( "PDU error status = " +
pdu.getErrorStatusString());
return;
}
print(pdu.getVarBinds(), p);
}

/**
* Prints variable binding array to standard out
*/
protected void print(SnmpVarBind[] varbinds)
{
print(varbinds, System.out);
}

/**
* Prints variable binding array to PrintStream p
*/
protected void print(SnmpVarBind[] varbinds, PrintStream p)
{
for (int i = 0; i < varbinds.length ; i++)
{
print(varbinds[i], p);
}
}

/**
* Prints variable binding to standard out
*/
protected void print(SnmpVarBind var)
{
print(var, System.out);
}

/**
* Prints variable binding to PrintStream p
*/
protected void print(SnmpVarBind var, PrintStream p)
{

if(var == null)
{
return;
}

SnmpDataType n = var.getName();
SnmpDataType v = var.getValue();

if(n == null)
{
p.println( "SnmpVarBind 's name is null" );
}
String oid = n.toString();
String value = v.toString();

// **** Optional, if MIB OID name translation is desired.
if(MibUtil.isMibFileLoaded())
{
//Use MibUtil.translate to translate oid and its value to string
//format
NameValue nv = MibUtil.translate(oid, value, true);
if(nv != null)
{
if(!_numericalOID)
{
oid = nv.getName();
}
value = nv.getValue();
}
}

if( v.getType() == SnmpDataType.TIMETICKS )
{ // if it's time ticks, translate it to friendly readable format
value = ((SnmpTimeTicks) v).getTimeString();
}
else if( v.getType() == SnmpDataType.END_OF_MIB_VIEW )
{
p.println( "End of MIB reached.");
return;
}
else if( v.getType() == SnmpDataType.NO_SUCH_OBJECT )
{
p.println( "No such object.");
return;
}
else if( v.getType() == SnmpDataType.NO_SUCH_INSTANCE )
{
p.println( "No such Instance.");
return;
}
p.println( oid + "\r\nValue (" + v.getTypeString() +
"): "+ value + "\r\n");
Ausgabe = Ausgabe + oid + " Value (" + v.getTypeString() + "): "+
value + "\r\n";
}

/**
* Creates a new instance of ParseArguments
*/
protected ParseArguments newParseArgumentsInstance(String[] args)
{
return new ParseArguments(args, "?ho", "uvaAXcpm");
}

/**
* Parses command options, allowing multiple OIDs and no command line
* options
* @see #parseOptions(String[] args, String programName, boolean
allowMulitpleOIDs, boolean allowNoOption)
*/
protected void parseOptions(String[] args, String program)
{
parseOptions(args, program, true, false);
}
protected void parseOptions(String[] args,
String programName,
boolean allowMulitpleOIDs,
boolean allowNoOption)
{
_parseArgs = newParseArgumentsInstance(args);
_numericalOID = false;
_version = 0;
_isSnmpV3 = false;
_mibString = null;
_community = "public";
_port = 161;
parseArgs();
}
/**
* Parses non-option arguments
*/
protected void parseArgs()
{
String [] as = _parseArgs.getArguments();
if(as.length > 0)
{
_host = as[0];
}

if(as.length > 1)
{
_oids = new String[as.length - 1];
for (int i = 1; i < as.length ; i++)
{
_oids[i - 1] = as[i];
}
}
else
{
_oids = new String[]{".1.3"};
}
}

/**
* Prints values of all options
*/
protected void printOptions()
{
System.out.println( "Options:");
System.out.println( "_____________________________________");
System.out.println( "host =\t\t\t" + _host);
System.out.println( "port =\t\t\t" + _port);
System.out.println( "isSnmpV3 =\t\t" + _isSnmpV3);
System.out.println( "authProtocol =\t\t" + _authProtocol);
System.out.println( "authPassword =\t\t" + _authPassword);
System.out.println( "privPassword =\t\t" + _privPassword);
System.out.println( "community =\t\t" + _community);
System.out.println( "user =\t\t\t" + _user);
System.out.println( "mib files =\t\t" + _mibString);
// printMoreOptions();
System.out.println( "_____________________________________");
}


//
// ------------ utility methods
//

/**
* Translates to SnmpDataType object. Used in snmptrap and snmpset classes
* @param type one of i, u, t, a, o, s
* i: INTEGER, u: unsigned INTEGER, t: TIMETICKS,
* a: IPADDRESS, o: OBJID, s: STRING
* @param value value
*/
public static SnmpDataType translate(String type, String value)
{
if(type.equals("i"))
{
return new SnmpInt(Integer.parseInt(value));
}
else if(type.equals("u"))
{
return new SnmpUInt(Long.parseLong(value));
}
else if(type.equals("t"))
{
return new SnmpTimeTicks(Long.parseLong(value));
}
else if(type.equals("a"))
{
return new SnmpIpAddress(value);
}
else if(type.equals("o"))
{
return new SnmpOID(value);
}
else if(type.equals("o"))
{
return new SnmpOID(value);
}
else if(type.equals("s"))
{
return new SnmpOctetString(value);
}
else
{
throw new RuntimeException("Unknown data type");
}
}
}
// end of class snmp
import com.ireasoning.util.ParseArguments;
import com.ireasoning.protocol.snmp.*;
import com.ireasoning.protocol.TimeoutException;
import java.io.IOException;

import java.io.*;
import java.util.*;
import com.ireasoning.protocol.*;

/**
* This class demonstrates two different implementations of SNMP GET operation.
* <br>
* 1. Use SnmpSession.snmpGetRequest. This is a more convinient way. <br>
* 2. Use primitive SnmpSession.send <br>
* <pre>
* Example:
* java snmpget localhost .1.3.6.1.2.1.1.3.0
* java snmpget localhost sysUpTime
* java snmpget ucd-snmp.ucdavis.edu -v 3 -u MD5DESUser -A "The UCD Demo
Password" -X "The UCD Demo Password" sysContact
*
* </pre>
*/
public class snmpget extends snmp
{
static int _getMethod = 1;

public String main(String[] args)
{
snmpget s = new snmpget();
s.parseOptions(args, "snmpget");
s.printOptions();
Ausgabe = s.get();
return Ausgabe;
}

/**
* uses SnmpSession.snmpGetRequest
*/
private String get()
{
try
{
Ausgabe = "1";
SnmpSession session = new SnmpSession(_host, _port, _community,
_community, _version);
session.setTimeout(5000); // sets timeout to be 5 seconds
session.setRetries(0); // no retry after timeout
if(_isSnmpV3)
{
session.setV3Params(_user, _authProtocol, _authPassword,
_privPassword);
}

SnmpPdu retPdu = session.snmpGetRequest(_oids);

print(retPdu);
session.close();
}
catch(TimeoutException timeout)
{
System.out.println( "time out");
}
catch(IOException e)
{
System.out.println(e);
e.printStackTrace();
}
return(Ausgabe);
}

// ----------------------------------------------------------------------
// Parsing command line options
// ----------------------------------------------------------------------

protected void moreOptions()
{
System.out.println( "-w {1|2} which get method to use, default is 1");
}

/**
* Prints out the example usage
*/
protected void printExample(String programName)
{
System.out.println( "java " + programName + " localhost
.1.3.6.1.2.1.1.3.0");
System.out.println( "java " + programName + " localhost sysUpTime");
System.out.println( "java " + programName +
" ucd-snmp.ucdavis.edu -v 3 -u MD5DESUser -A \"The UCD Demo
Password\" -X \"The UCD Demo Password\" sysContact" );
}

protected void parseOptions(String[] args, String program)
{
super.parseOptions(args, program);
_getMethod = Integer.parseInt(_parseArgs.getOptionValue('w', "1"));
}

protected void printMoreOptions()
{
System.out.println( "get-method =\t\t" + _getMethod);
}

/**
* Creates a new instance of ParseArguments
*/
protected ParseArguments newParseArgumentsInstance(String[] args)
{
return new ParseArguments(args, "?ho", "uvaAXcpmnrw");
}

}// end of class snmpget

import com.ireasoning.protocol.TimeoutException;
import com.ireasoning.protocol.snmp.*;
import com.ireasoning.util.ParseArguments;
import java.io.IOException;

/**
* This class demonstrates two different implementations of snmp get_next
operation.
* <br>
* 1. Use SnmpSession.snmpGetNextRequest. This is a more convinient way. <br>
* 2. Use primitive SnmpSession.send <br>
* <pre>
* Example:
* java snmpgetnext localhost .1.3.6.1.2.1.1.3.0
* java snmpgetnext localhost sysUpTime
* java snmpgetnext ucd-snmp.ucdavis.edu -v 3 -u MD5DESUser -A "The UCD Demo
Password" -X "The UCD Demo Password" .1.3.2
*
* </pre>
*/
public class snmpgetnext extends snmp
{
/**
* Which getnext method to use
*/
static int _getNextMethod = 1;

public String main(String[] args)
{
snmpgetnext s = new snmpgetnext();
s.parseOptions(args, "snmpgetnext");
s.printOptions();
Ausgabe = s.getnext();
return Ausgabe;
}

/**
* use SnmpSession.snmpGetNextRequest
*/
private String getnext()
{
try
{
SnmpSession session = new SnmpSession(_host, _port, _community,
_community, _version);
if(_isSnmpV3)
{
session.setV3Params(_user, _authProtocol, _authPassword,
_privPassword);
}

SnmpPdu retPdu = session.snmpGetNextRequest(_oids);

print(retPdu);
session.close();
}
catch(TimeoutException timeout)
{
System.out.println( "time out");
}
catch(IOException e)
{
System.out.println(e);
e.printStackTrace();
}
return(Ausgabe);
}

// ----------------------------------------------------------------------
// Parsing command line options
// ----------------------------------------------------------------------

protected void moreOptions()
{
System.out.println( "-w {1|2} which getnext method to use, default is
1");
}

protected void parseOptions(String[] args, String program)
{
super.parseOptions(args, program);
_getNextMethod = Integer.parseInt(_parseArgs.getOptionValue('w', "1"));
}

protected void printMoreOptions()
{
System.out.println( "getnext-method =\t" + _getNextMethod);
}

/**
* Prints out the example usage
*/
protected void printExample(String programName)
{
System.out.println( "java " + programName + " localhost
.1.3.6.1.2.1.1.3.0");
System.out.println( "java " + programName + " localhost sysUpTime");
System.out.println( "java " + programName +
" ucd-snmp.ucdavis.edu -v 3 -u MD5DESUser -A \"The UCD Demo
Password\" -X \"The UCD Demo Password\" .1.3.2" );
}

/**
* Creates a new instance of ParseArguments
*/
protected ParseArguments newParseArgumentsInstance(String[] args)
{
return new ParseArguments(args, "?ho", "uvaAXcpmnrw");
}

}// end of class snmpgetnext


import com.ireasoning.protocol.Listener;
import com.ireasoning.protocol.Msg;
import com.ireasoning.protocol.TimeoutException;
import com.ireasoning.protocol.snmp.*;
import com.ireasoning.util.ParseArguments;
import java.io.IOException;

/**
* This class demonstrates three different implementations of snmp walk.
* <br>
* walk1() demonstrates use of SnmpSession.snmpWalk to implement snmp (simplest
* way) <br>
* walk2() demonstrates use of SnmpSession.snmpGetNextRequest to implement snmp
* walk<br>
* walk3() demonstrates use of primitive SnmpSession.send to implement
* snmp walk<br>
* <pre>
* Example:
* java snmpwalk localhost .1.3
* java snmpwalk localhost
* java snmpwalk localhost -v 3 -u newUser -A abc12345 -X abc12345 .1.3
*
* </pre>
*/
public class snmpwalk extends snmp implements Listener
{
static int _walkMethod = 1;

public String main(String[] args)
{
snmpwalk s = new snmpwalk();
s.parseOptions(args, "snmpwalk", false, false);
s.printOptions();
Ausgabe = s.walk();
return(Ausgabe);
// starting to walk...

// if(_walkMethod == 1)
// {// use SnmpSession.snmpWalk
// s.walk1();
// }
// else if(_walkMethod == 2)
// {// use SnmpSession.snmpGetNextRequest
// s.walk2();
// }
// else if(_walkMethod == 3)
// {// use SnmpSession.send
// s.walk3();
// }
}

/**
* This method demonstrates use of SnmpSession.snmpWalk to implement snmp
* walk. It's the simplest way to do snmp walk.
* @see #handleMsg
*/
private String walk()
{
try
{
SnmpSession session = new SnmpSession(_host, _port, _community,
_community, _version);
if(_isSnmpV3)
{
session.setV3Params(_user, _authProtocol, _authPassword,
_privPassword);
}
session.snmpWalk(_oids[0], this);
}
catch(TimeoutException timeout)
{
System.out.println( "time out");
}
catch(IOException ie)
{
System.out.println(ie);
ie.printStackTrace();
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
return(Ausgabe);
}

/**
* Callback method. walk1() will indirectly invoke this method.
*/
public void handleMsg(Object session, Msg msg)
{
SnmpPdu pdu = (SnmpPdu) msg;
if(!pdu.hasMore())
{
System.out.println( "<End of MIB View Reached>");
((SnmpSession)session).close();
return;
}

print(pdu);
}

/**
* This method demonstrates use of SnmpSession.snmpGetNextRequest to
implement snmp
* walk
*/
private void walk2()
{
try
{
SnmpTarget target = new SnmpTarget(_host, _port, _community,
_community, _version);
SnmpSession session = new SnmpSession(target);
if(_isSnmpV3)
{
session.setV3Params(_user, _authProtocol, _authPassword,
_privPassword);
}

SnmpPdu retPdu = session.snmpGetNextRequest(_oids[0]);
if(!retPdu.hasMore())
{
System.out.println("End of mib view reached");
return;
}

print(retPdu);

while (true)
{
retPdu =
session.snmpGetNextRequest(retPdu.getFirstVarBind().getName());
if(!retPdu.hasMore())
{
System.out.println("End of mib view reached");
break;
}
print(retPdu);
}
session.close();
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
}

/**
* This method demonstrates use of primitive SnmpSession.send to implement
* snmp walk
*/
private void walk3()
{
try
{
SnmpTarget target = new SnmpTarget(_host, _port, _community,
_community);
SnmpSession session = new SnmpSession(target);
if(_isSnmpV3)
{
session.setV3Params(_user, _authProtocol, _authPassword,
_privPassword);
}

SnmpVarBind[] vblist = { new SnmpVarBind(_oids[0]) };
SnmpPdu pdu = new SnmpPdu(SnmpConst.GET_NEXT, vblist);
SnmpPdu retPdu = null;
retPdu = session.send(pdu);
if(!retPdu.hasMore())
{
System.out.println("End of mib view reached");
return;
}

print(retPdu);

while (true)
{
pdu.setOID(retPdu.getFirstVarBind().getName());
retPdu = session.send(pdu);
if(!retPdu.hasMore())
{
System.out.println("End of mib view reached");
break;
}
print(retPdu);
}
session.close();
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
}

// ----------------------------------------------------------------------
// Parsing command line options
// ----------------------------------------------------------------------

protected void moreOptions()
{
System.out.println( "-w {1|2|3} which walk method to use, default is
1");
}

protected void parseOptions(String[] args,
String programName,
boolean allowMulitpleOIDs,
boolean allowNoOption)
{
super.parseOptions(args, programName, allowMulitpleOIDs, allowNoOption);
_walkMethod = Integer.parseInt(_parseArgs.getOptionValue('w', "1"));
}

protected void printMoreOptions()
{
System.out.println( "walk-method =\t\t" + _walkMethod);
}

/**
* Creates a new instance of ParseArguments
*/
protected ParseArguments newParseArgumentsInstance(String[] args)
{
return new ParseArguments(args, "?ho", "uvaAXcpmnrw");
}

}// end of class snmpwalk








  Document options
Print this pagePrint this page

 Search this forum

  Forum views and search
Date (threaded)
Date (flat)
With excerpt
Category
Platform
Release
Advanced search

 RSS feedsRSS
All forum posts RSS
All main topics RSS