[SNMP4J] Howto build a snmp-daemon?
Deon van der Merwe
dvdm at truteq.co.za
Fri Sep 23 20:30:51 CEST 2005
Hi Laura,
Here is more-or-less how I put a SNMP server together. I hope that I did
not strip it too much...
public class Handler
implements org.snmp4j.CommandResponder {
protected org.snmp4j.TransportMapping mServerSocket = null;
protected org.snmp4j.Snmp mSNMP = null;
public Handler() {
mServerSocket = new org.snmp4j.transport.DefaultUdpTransportMapping(new
org.snmp4j.smi.UdpAddress(mPort));
mSNMP = new org.snmp4j.Snmp(mServerSocket);
mSNMP.addCommandResponder(this);
mServerSocket.listen();
}
public synchronized void processPdu(
org.snmp4j.CommandResponderEvent aEvent) {
org.snmp4j.PDU vPDU = aEvent.getPDU();
if (vPDU == null) {
mLogger.warning("NULL PDU received???");
} else {
switch (vPDU.getType()) {
case org.snmp4j.PDU.GET:
vPDU.setErrorIndex(0);
vPDU.setErrorStatus(0);
vPDU.setType(org.snmp4j.PDU.RESPONSE);
for (int vIndex = 0; vIndex < vPDU.size(); ++vIndex) {
org.snmp4j.smi.VariableBinding vVB = vPDU.get(vIndex);
org.snmp4j.smi.OID vOID = vVB.getOid();
if (vOID.equals(org.snmp4j.mp.SnmpConstants.sysDescr)) {
vVB.setVariable(new
org.snmp4j.smi.OctetString(mSystemDescription));
} else if
(vOID.equals(org.snmp4j.mp.SnmpConstants.sysContact)) {
vVB.setVariable(new
org.snmp4j.smi.OctetString(mSystemContact));
} else if (vOID.equals(org.snmp4j.mp.SnmpConstants.sysName)) {
vVB.setVariable(new
org.snmp4j.smi.OctetString(mSystemName));
} else if
(vOID.equals(org.snmp4j.mp.SnmpConstants.sysLocation)) {
vVB.setVariable(new
org.snmp4j.smi.OctetString(mSystemLocation));
} else if (vOID.equals(org.snmp4j.mp.SnmpConstants.sysUpTime))
{
vVB.setVariable(new
org.snmp4j.smi.TimeTicks((long)(java.lang.System.currentTimeMillis() -
mStartTime)/10l));
} else if (vOID.equals(vMyMemoryOID)) {
vVB.setVariable(new
org.snmp4j.smi.UnsignedInteger32((long)vCurrentMemory));
} else {
}
}
org.snmp4j.mp.StatusInformation statusInformation = new
org.snmp4j.mp.StatusInformation();
org.snmp4j.mp.StateReference ref = aEvent.getStateReference();
try {
aEvent.getMessageDispatcher().returnResponsePdu(aEvent.getMessageProcessingM
odel(), aEvent.getSecurityModel(), aEvent.getSecurityName(),
aEvent.getSecurityLevel(), vPDU, aEvent.getMaxSizeResponsePDU(), ref,
statusInformation);
} catch (org.snmp4j.MessageException vException) {
mLogger.error(vException.getMessage(), vException);
}
break;
default:
mLogger.warning("Unsupported PDU type received: " +
vPDU.getType());
break;
}
}
}
}
> -----Original Message-----
> From: snmp4j-bounces at agentpp.org
> [mailto:snmp4j-bounces at agentpp.org] On Behalf Of
> laura.reising at arcor.de
> Sent: Friday, September 23, 2005 17:29
> To: snmp4j at agentpp.org
> Subject: [SNMP4J] Howto build a snmp-daemon?
>
> Hello all,
>
> first of all: I'm new to snmp, so please bear with me!
>
> I came to snmp because I would like to monitor some performance-issues
> of my JBoss while I'm doing some OpenSTA-tests
> (http://www.opensta.org).
> OpenSTA offers the possibility to fire snmp-queries while it
> is running
> it's tests.
>
> My idea is to write a snmp-daemon (and deploy it under my JBoss) that
> takes this requests, checks (for example) the JBoss-memory
> und delivers
> this value back to OpenSTA (via a snmp-response).
>
> So I got SNMP4J-Agent. I took a look at the TestAgent, hoping to adapt
> this class for my needs with some hand grips. But far wrong!
>
> I hoped to find a Servlet-similar interface with some kind of
> "doGet(SnmpRequest request, SnmpResponse response)"-Method,
> where I can
> do my work put my response-value back into some kind of
> response-object.
>
> This is confusing! I don't have any cue where to start! Do I need all
> this stuff in TestAgent for my simple problem?
>
> I the a "snmp4j for dummies"-Tutorial?
>
> Thanks a lot in advance for any answer, tip, hint and/or link!
>
> Best wishes
> Laura
>
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j
>
More information about the SNMP4J
mailing list