SNMP4J代理和网络SNMP“;“客户”;
我还在学习SNMP,所以请温柔一点 我用snmp4j做了一个代理,它似乎在工作,我有一个标量,它应该记录自代理启动以来经过了多少时间 我只需要做代理,然后我想用netsnmp查看标量的值 问题是,当我启动代理时,我将my scalar SystemUpTime设置为0,然后每次有人尝试使用net snmp检查SystemUpTime时,我都会尝试更新SystemUpTime,该值不会更改 每次有人试图访问时,如何让代理更新SystemUpTime? 我有一个方法MOScalar getSystemUpTime,因为它在返回它之前更新SystemUpTime,我认为它可以完成这项工作,但它不起作用 你们有什么建议 编辑(我的代理代码,我去掉了一些必要的方法来缩短这件事)SNMP4J代理和网络SNMP“;“客户”;,snmp,net-snmp,snmp4j,Snmp,Net Snmp,Snmp4j,我还在学习SNMP,所以请温柔一点 我用snmp4j做了一个代理,它似乎在工作,我有一个标量,它应该记录自代理启动以来经过了多少时间 我只需要做代理,然后我想用netsnmp查看标量的值 问题是,当我启动代理时,我将my scalar SystemUpTime设置为0,然后每次有人尝试使用net snmp检查SystemUpTime时,我都会尝试更新SystemUpTime,该值不会更改 每次有人试图访问时,如何让代理更新SystemUpTime? 我有一个方法MOScalar getSyste
没有代码片段没有回答。您好,我想听听做这件事的一些想法/方法,我没有发布我的代码,因为我想得到关于我需要做什么的反馈。任何想法都很好。不管怎样,编辑了我的问题,我发布了我的一些代码,尽管他可能很愚蠢
public class Agent extends BaseAgent {
// not needed but very 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 does not exist and are not used but has to be specified
// Read snmp4j docs for more info
super(new File("conf.agent"), new File("bootCounter.agent"),
new CommandProcessor(
new OctetString(MPv3.createLocalEngineID())));
this.address = address;
}
/**
* Clients can register the MO they 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 some initialization methods needed to
* start the agent
* @throws IOException
*/
public void start() throws IOException {
init();
// This method reads some old config from a file and causes
// unexpected behavior.
// loadConfig(ImportModes.REPLACE_CREATE);
addShutdownHook();
getServer().addContext(new OctetString("public"));
finishInit();
run();
sendColdStartNotification();
}
protected void unregisterManagedObjects() {
// here we should unregister those objects previously registered...
}
/**
* The table of community strings configured in the SNMP
* engine's Local Configuration Datastore (LCD).
*
* We only 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;
}
}