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:
~Vanessa Elfanaskiettu 9.Aug.03 07:53 AM a Web browser Applications DevelopmentAll ReleasesWindows 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.
*/
/**
* 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";
/**
* 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");
}
/**
* 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;
/**
* 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);
}
/**
* Creates a new instance of ParseArguments
*/
protected ParseArguments newParseArgumentsInstance(String[] args)
{
return new ParseArguments(args, "?ho", "uvaAXcpmnrw");
}
/**
* 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;
}
/**
* Creates a new instance of ParseArguments
*/
protected ParseArguments newParseArgumentsInstance(String[] args)
{
return new ParseArguments(args, "?ho", "uvaAXcpmnrw");
}
/**
* Creates a new instance of ParseArguments
*/
protected ParseArguments newParseArgumentsInstance(String[] args)
{
return new ParseArguments(args, "?ho", "uvaAXcpmnrw");
}