Developers guide

112
F.1.5. SNMPMasterswitch.java
/**
* $Id: SNMPMasterswitch.java,v 1.6 2002/10/22 08:23:11 oliverm Exp $
* Author: Oliver Mather
*
*/
package apt.masterswitch.snmp;
import org.opennms.protocols.snmp.*;
import java.util.*;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.SocketException;
import java.io.FileNotFoundException;
import pt.ipb.agentapi.mibs.MibModule;
import pt.ipb.agentapi.mibs.MibException;
import pt.ipb.agentapi.OID;
import apt.masterswitch.AbstractMasterswitch;
import apt.masterswitch.Masterswitch;
import apt.masterswitch.MasterswitchException;
/**
* Description:
* <p>
* An implementation of {@link apt.masterswitch.Masterswitch} using the SNMP
* interface to the APC Masterswitch.
* <p>
* SNMP Transport is handled using the <a href="http://www.opennms.org">opennms joesnmp stack</a>
* <p>
* Control of the device is achived by sending SNMP Messages as Datagram Packets to the
* <i>Management Interface Board</i> built into the Masterswitch Device
* <p>
* Changes to status information on the masterswitch are detected by listening
* to events from a {@link apt.masterswitch.snmp.SnmpTrapDaemon}
*
*
* @author $Author: oliverm $ <a href="mailto:oliverm@student.unsw.edu.au">Oliver Mather</a>
* @version $Revision: 1.6 $
* @see apt.masterswitch.snmp.SnmpTrapListener
*/
public class SNMPMasterswitch extends AbstractMasterswitch implements SnmpHandler, SnmpTrapListener {
// These are the values needed to populate the snmp packets
private static final int SNMP_OUTLET_ON = 1;
private static final int SNMP_OUTLET_OFF = 2;
private static final int SNMP_OUTLET_REBOOT = 3;
private static final int SNMP_OUTLET_UNKNOWN = 4; // this value cannot be set. If it is read, the
apt.masterswitch.masterswitch must be power cycled.
private static final int SNMP_OUTLET_ON_WITH_DELAY = 5;
private static final int SNMP_OUTLET_OFF_WITH_DELAY = 6;
private static final int SNMP_OUTLET_REBOOT_WITH_DELAY = 7;
private static final String MASTERSWITCH_IP = "150.203.153.9";
private static final String SNMP_COMM_READ = "public";
private static final String SNMP_COMM_WRITE = "private";
private static final String MIB_FILENAME = "./config/snmp/POWERNET.MIB";
private static SNMPMasterswitch singletonInstance;
//sPDUOutletControlTable
private static final String sPDUOutletPending = "sPDUOutletPending";
private static final String sPDUOutletCtl = "sPDUOutletCtl";