// Home | Go Back //
package agent.master;
import java.io.*;
import java.util.*;
import com.ireasoning.util.*;
import com.ireasoning.protocol.snmp.*;
import com.ireasoning.protocol.Listener;
import com.ireasoning.protocol.Msg;
import javax.management.*;
public class Agent extends SnmpAgentX implements Listener
{
public Agent(String configFileName) throws Exception
{
super(configFileName, false);
}
public static void main(String[] args)
{
try
{
String os = System.getProperty("os.name").toUpperCase();
if(os.indexOf("WINDOWS") < 0)
{
System.out.println( "The purpose of this demo is to demononstrate how to create a simple agent. To make it as simple as possible, it makes use of windows' \"ipconfig\" command to figure out interfaces instead of making native calls, so it can only run correctly on Windows, although snmpagent.jar itself is platform independent. ");
return;
}
String configFile = "SnmpAgent.xml";
Agent agent = new Agent(configFile); agent.startMasterAgent(); agent.sendV1ColdStartTrap();
agent.addSubagentEventListener(agent);
}
catch(Exception e)
{
Logger.error(e);
System.exit(1);
}
}
public void handleMsg(Object msgSender, Msg msg)
{
if(msg instanceof SubagentEvent)
{
SubagentEvent event = (SubagentEvent) msg;
System.out.println( event );
}
else if(msg instanceof AgentEvent)
{
AgentEvent event = (AgentEvent) msg;
System.out.println( event);
}
}
protected void setOIDTree()
{
_root = OIDTree.getTree();
}
protected void registerMBeans() throws SnmpException
{
AgentMib.registerMBeans(_mbeanServer, _root);
}
}