SNMP4J Agent and Net-SNMP "client" -
i'm still learning snmp, gentle please.
i did agent snmp4j , seems working, have scalar should register how time has passed since agent started.
i have agent, see value of scalar net-snmp.
the problem is, when start agent set scalar systemuptime 0, try update systemuptime everytime tries check net-snmp value doesnt change.
how can agent update systemuptime everytime tries access it? have method moscalar getsystemuptime since updates systemuptime before returning , thought job, not working.
what u guys sugest?
edit ( agent code, ive taken off of mandatory methods short thing bit )
public class agent extends baseagent { // not needed useful of course static { logfactory.setlogfactory(new log4jlogfactory()); } static long starttime=0; private string address; static oid oid= new oid(".1.3.6.1.4.1.1.1.0"); public static moscalar sysuptime; private static mofactory mofactory = defaultmofactory.getinstance(); public agent(string address) throws ioexception { // these files not exist , not used has specified // read snmp4j docs more info super(new file("conf.agent"), new file("bootcounter.agent"), new commandprocessor( new octetstring(mpv3.createlocalengineid()))); this.address = address; } /** * clients can register mo need */ public void registermanagedobject(managedobject mo) { try { server.register(mo, null); system.out.println("mib filled!"); } catch (duplicateregistrationexception ex) { throw new runtimeexception(ex); } } /** * start method invokes initialization methods needed * start agent * @throws ioexception */ public void start() throws ioexception { init(); // method reads old config file , causes // unexpected behavior. // loadconfig(importmodes.replace_create); addshutdownhook(); getserver().addcontext(new octetstring("public")); finishinit(); run(); sendcoldstartnotification(); } protected void unregistermanagedobjects() { // here should unregister objects registered... } /** * table of community strings configured in snmp * engine's local configuration datastore (lcd). * * configure one, "public". */ protected void addcommunities(snmpcommunitymib communitymib) { variable[] com2sec = new variable[] { new octetstring("public"), // community name new octetstring("cpublic"), // security name getagent().getcontextengineid(), // local engine id new octetstring("public"), // default context name new octetstring(), // transport tag new integer32(storagetype.nonvolatile), // storage type new integer32(rowstatus.active) // row status }; } public static void main(string[] args) throws ioexception, interruptedexception { agent agent = new agent("127.0.0.1/6666"); sysuptime=mofactory.createscalar(oid, mofactory.createaccess(moaccessimpl.accessible_for_read_only), new timeticks(0)); starttime=system.currenttimemillis(); agent.registermanagedobject(sysuptime); agent.start(); while(true) { system.out.println("agent running..."); thread.sleep(5000); } } public moscalar getsystemid() { variable var = new integer32((int) (system.currenttimemillis() - starttime)); sysuptime.setvalue(var); return sysuptime; } }
Comments
Post a Comment