Apple's XServe RAID Plugin

XServe Raid is a device plugin specific for Apple. It is used to monitor XServe Raid device which is a high performance storage device with innovative Apple-engineered architecture.

Overview:

Usage:
To use this plugin, Follow the plugin deployment steps provided by Hyperic. After opening the URL in the browser and after logging in follow these steps:

SNMP TRAP RECEIVER

package org.hyperic.hq.plugin.xserve;
import java.io.IOException;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hyperic.hq.product.LogTrackPlugin;
import org.hyperic.snmp.SNMPClient;

import org.snmp4j.CommandResponder;
import org.snmp4j.CommandResponderEvent;
import org.snmp4j.MessageDispatcherImpl;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
import org.snmp4j.mp.MPv1;
import org.snmp4j.mp.MPv2c;
import org.snmp4j.mp.MPv3;
import org.snmp4j.security.SecurityModels;
import org.snmp4j.security.SecurityProtocols;
import org.snmp4j.security.USM;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.TcpAddress;
import org.snmp4j.smi.UdpAddress;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultTcpTransportMapping;
import org.snmp4j.transport.DefaultUdpTransportMapping;
import org.snmp4j.util.MultiThreadedMessageDispatcher;
import org.snmp4j.util.ThreadPool;

public class SNMPTrapReceiver
    implements CommandResponder {

    private static SNMPTrapReceiver instance = null;
    private static final Log log = LogFactory.getLog(SNMPTrapReceiver.class.getName());
   
    private MultiThreadedMessageDispatcher _dispatcher;
    private Snmp _snmp;
    private Address _listenAddress;
    private ThreadPool _threadPool;
    private Map _plugins = new HashMap();

    private int _received = 0;

    public static SNMPTrapReceiver getInstance(Properties props)
        throws IOException {
        
        if (instance == null) {
            instance = new SNMPTrapReceiver();
            instance.init(props);
        }

        return instance;
    }

    public static void start(Properties props)
        throws IOException {

        getInstance(props);
    }

    public static void shutdown() throws IOException {
        if (instance != null) {
            log.debug("Shutdown instance");
            instance._threadPool.cancel();
            instance._snmp.close();
            instance = null;
        }
    }

    private static String getPluginKey(String address, String community) {
        return address + "-" + community;        
    }

    private static String getConfig(LogTrackPlugin plugin,
                                   String key, String def) {

        String value = plugin.getConfig(key);
        if (value == null) {
            //commandline-testing
            return plugin.getManager().getProperty(key, def);
        }
        else {
            return value;
        }
    }

    private static String getPluginKey(LogTrackPlugin plugin) {
        String address =
            getConfig(plugin,
                      SNMPClient.PROP_IP,
                      SNMPClient.DEFAULT_IP);

        String community = 
            getConfig(plugin,
                      SNMPClient.PROP_COMMUNITY,
                      SNMPClient.DEFAULT_COMMUNITY);

        return getPluginKey(address, community);
    }

    private LogTrackPlugin getPlugin(String address, String community) {
        String key = getPluginKey(address, community);
        return (LogTrackPlugin)_plugins.get(key);
    }

    public void add(LogTrackPlugin plugin)
        throws IOException {

        String key = getPluginKey(plugin);
        log.debug("Add " + plugin.getName() + " for " + key);
        _plugins.put(key, plugin);
    }

    public static void remove(LogTrackPlugin plugin) {
        if (instance == null) {
            return;
        }
        String key = getPluginKey(plugin);
        log.debug("Remove " + plugin.getName() + " for " + key);
        instance._plugins.remove(key);
    }

    private SNMPTrapReceiver () {}

    private void init(Properties props)
        throws IOException {

        String address =
            props.getProperty("snmpTrapReceiver.listenAddress",
                              "udp:0.0.0.0/162");

        log.debug("Listen address=" + address);

        String numThreads =
            props.getProperty("snmpTrapReceiver.numThreads", "1");

        _threadPool =
            ThreadPool.create("SNMPTrapReceiver",
                              Integer.parseInt(numThreads));

        _dispatcher =
            new MultiThreadedMessageDispatcher(_threadPool,
                                               new MessageDispatcherImpl());

        _listenAddress = GenericAddress.parse(address);

        TransportMapping transport;
        if (_listenAddress instanceof UdpAddress) {
            transport =
                new DefaultUdpTransportMapping((UdpAddress)_listenAddress);
        }
        else {
            transport =
                new DefaultTcpTransportMapping((TcpAddress)_listenAddress);
        }

        _snmp = new Snmp(_dispatcher, transport);
        _snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
        _snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
        _snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());

        USM usm =
            new USM(SecurityProtocols.getInstance(),
                    new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);

        _snmp.addCommandResponder(this);
        _snmp.listen();
    }

    public int getTrapsReceived() {
        return _received;
    }

    private String getMessage(CommandResponderEvent event) {
        StringBuffer msg = new StringBuffer();

        Vector vars = event.getPDU().getVariableBindings();
        int size = vars.size();
        for (int i=0; i<size; i++) {
            VariableBinding var = (VariableBinding)vars.get(i);
            msg.append(var.getVariable().toString().trim());
            if (i < size-1) {
                msg.append(", ");
            }
        }        

        return msg.toString();
    }

    public void processPdu(CommandResponderEvent event) {
        _received++;

        Address peer = event.getPeerAddress();
        InetAddress peerAddress;
        if (peer instanceof UdpAddress) {
            peerAddress = ((UdpAddress)peer).getInetAddress();
        }
        else if (peer instanceof TcpAddress) {
            peerAddress = ((TcpAddress)peer).getInetAddress();
        }
        else {
            log.debug("Unsupported transport: " +
                      peer.getClass().getName());
            return;
        }

        String address =
            peerAddress.getHostAddress();

        String community =
            new OctetString(event.getSecurityName()).toString();

        LogTrackPlugin plugin = getPlugin(address, community);

        if (plugin == null) {
            if (log.isDebugEnabled()) {
                log.debug("No plugin for " + address +
                          ", msg=" + getMessage(event));
            }
        }
        else {
            String msg = getMessage(event);
            if (log.isDebugEnabled()) {
                log.debug("Msg=" + msg);
            }
            plugin.reportEvent(System.currentTimeMillis(),
                               LogTrackPlugin.LOGLEVEL_ERROR,
                               address,
                               msg);
        }
    }

    public static void main(String[] args) throws Exception {
        SNMPTrapReceiver.start(System.getProperties());

        System.out.println("Ready");
        System.in.read();
        System.out.print("Shutting down...");
        SNMPTrapReceiver.shutdown();
        System.out.println("done");
    }
}

SNMP TRAP Receiver Plugin

package org.hyperic.hq.plugin.xserve;
import java.io.IOException;

import org.hyperic.hq.product.LogTrackPlugin;
import org.hyperic.hq.product.PluginException;
import org.hyperic.util.config.ConfigResponse;

public class SNMPTrapReceiverPlugin extends LogTrackPlugin {

    private SNMPTrapReceiver getReceiver()
        throws IOException {

        return SNMPTrapReceiver.getInstance(getManager().getProperties());
    }

    public void configure(ConfigResponse config) throws PluginException {
        super.configure(config);

        try {
            getReceiver().add(this);
        } catch (IOException e) {
            throw new PluginException(e.getMessage(), e);
        }
    }

    public void shutdown() throws PluginException {
        super.shutdown();

        SNMPTrapReceiver.remove(this);
    }
}

XServe Device Detector

package org.hyperic.hq.plugin.xserve;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.logging.Log;

import org.hyperic.hq.product.MeasurementPlugin;
import org.hyperic.hq.product.PlatformServiceDetector;
import org.hyperic.hq.product.PluginException;
import org.hyperic.hq.product.ProductPlugin;
import org.hyperic.hq.product.ProductPluginManager;
import org.hyperic.hq.product.SNMPDetector;
import org.hyperic.hq.product.ServerResource;
import org.hyperic.hq.product.ServiceResource;

import org.hyperic.snmp.SNMPClient;
import org.hyperic.snmp.SNMPException;
import org.hyperic.snmp.SNMPSession;
import org.hyperic.snmp.SNMPValue;

import org.hyperic.util.collection.IntHashMap;
import org.hyperic.util.config.ConfigResponse;

public class XserveDeviceDetector extends PlatformServiceDetector {

    private static final String SVC_NAME   = "Interface";
    private static final String PROP_IF    = SVC_NAME.toLowerCase();
    static final String PROP_IF_IX = PROP_IF + ".index";
    static final String IF_DESCR   = "ifDescr";
    static final String IF_NAME    = "ifName";
    private static final String MAC_COLUMN = "ifPhysAddress";
    private static final String IP_IF_IX   = "ipAdEntIfIndex";
    private static final String IP_NETMASK = "ipAdEntNetMask";

    private static final String PROP_IP      = "ipaddress";
    private static final String PROP_NETMASK = "netmask";
    private static final String[] FILTER_PROPS = {
        PROP_IP, PROP_NETMASK
    };

    private SNMPSession session;

    private Object get(String name, List column, int ix) {
        int size = column.size();
        if (ix >= size) {
            getLog().warn(name + " column index [" + ix + "] " +
                          "out-of-bounds [" + size + "]");
            return null;
        }
        return column.get(ix);
    }

    public List discoverServices(ConfigResponse serverConfig)
        throws PluginException {

        Log log = getLog();
        log.info("Enter into the Xserve Device Detector discover Services");
        List services = new ArrayList();

        openSession(serverConfig);

        if (log.isDebugEnabled()) {
            log.debug("Using snmp config=" + serverConfig);
        }

        services.addAll(discoverInterfaces(serverConfig));

        List extServices =
            SNMPDetector.discoverServices(this,
                                          serverConfig,
                                          this.session);
        services.addAll(extServices);

        closeSession();

        return services;
    }

    protected boolean hasInterfaceService() {
        String type = getServiceTypeName(SVC_NAME);
        ProductPluginManager manager =
            (ProductPluginManager)getManager().getParent();
        MeasurementPlugin plugin =
            manager.getMeasurementPlugin(type);
        if (plugin == null) {
            //Interface service is not defined 
            return false;  
        }
        else {
            //Check that ifMtu cprop exists, if so assume standard IF-MIB interface
            return plugin.getCustomPropertiesSchema().getOption("ifMtu") != null;
        }
    }

    protected List discoverInterfaces(ConfigResponse serverConfig)
        throws PluginException {

        Log log = getLog();
        List services = new ArrayList();

        String type = getServiceTypeName(SVC_NAME);

        if (!hasInterfaceService()) {
            log.debug("Skipping discovery of " + type);
            return services;
        }

        String[] keys =
            getCustomPropertiesSchema(type).getOptionNames();
        HashMap cpropColumns = new HashMap();
        for (int i=0; i<keys.length; i++) {
            String key = keys[i];
            if (Arrays.binarySearch(FILTER_PROPS, key) != -1) {
                continue;
            }
            try {
                cpropColumns.put(key, getColumn(key));
            } catch (PluginException e) {
                log.warn("Error getting '" + key + "': " +
                         e.getMessage());
            }
        }

        String columnName = serverConfig.getValue(PROP_IF_IX);
        if (columnName == null) {
            columnName = IF_DESCR;
        }
        List interfaces = getColumn(columnName);
        log.debug("Found " + interfaces.size() + " interfaces using " +
                  columnName);

        String descrColumn =
            columnName.equals(IF_DESCR) ? IF_NAME : IF_DESCR;
        List descriptions;
        
        try {
            descriptions = getColumn(descrColumn);
        } catch (PluginException e) {
            descriptions = null;
            String msg =
                "Error getting descriptions from " +
                descrColumn + ": " + e;
            log.warn(msg);
        }

        boolean hasDescriptions = 
            (descriptions != null) && (descriptions.size() == interfaces.size());

        List ip_if_ix = getColumn(IP_IF_IX);
        IntHashMap ips = new IntHashMap();
        IntHashMap netmasks = new IntHashMap();
        final String IF_IX_OID = SNMPClient.getOID(IP_IF_IX) + ".";
        final String NETMASK_OID = SNMPClient.getOID(IP_NETMASK) + ".";
        String ip, netmask;

        for (int i=0; i<ip_if_ix.size(); i++) {
            SNMPValue value = (SNMPValue)ip_if_ix.get(i);
            String oid = value.getOID();

            int ix = Integer.parseInt(value.toString()) - 1;
            if (oid.startsWith(IF_IX_OID)) {
                ip = oid.substring(IF_IX_OID.length());
                ips.put(ix, ip);
                try {
                    netmask =
                        this.session.getSingleValue(NETMASK_OID + ip).toString();
                    netmasks.put(ix, netmask);
                } catch (SNMPException e) {
                    log.debug("Failed to get netmask for " + ip);
                }
            }
        }

        for (int i=0; i<interfaces.size(); i++) {
            ConfigResponse config = new ConfigResponse();
            ConfigResponse cprops = new ConfigResponse();
            String name = interfaces.get(i).toString();
            String mac = null;

            ServiceResource service = createServiceResource(SVC_NAME);

            config.setValue(PROP_IF, name);
            config.setValue(PROP_IF_IX, columnName);
            service.setProductConfig(config);
            //required to auto-enable metric
            service.setMeasurementConfig();

            for (int j=0; j<keys.length; j++) {
                String key = keys[j];
                List data = (List)cpropColumns.get(key);
                if (data == null) {
                    continue;
                }
                String val;
                Object obj = get(key, data, i);
                if (obj == null) {
                    continue;
                }
                if (key.equals(MAC_COLUMN)) {
                    mac = val = ((SNMPValue)obj).toPhysAddressString();
                }
                else {
                    val = obj.toString();
                }
                cprops.setValue(key, val);
            }

            ip = (String)ips.get(i);
            netmask = (String)netmasks.get(i);
            if (ip == null) {
                ip = "0.0.0.0";
            }
            if (netmask == null) {
                netmask = "0.0.0.0";
            }
            cprops.setValue(PROP_IP, ip);
            cprops.setValue(PROP_NETMASK, netmask);

            service.setCustomProperties(cprops);

            //might be more than 1 interface w/ the same name
            //so append the mac address to make it unique
            name = name.trim() + " " + SVC_NAME;
            if ((mac != null) && !mac.equals("0:0:0:0:0:0")) {
                name += " (" + mac + ")";
            }
            service.setServiceName(name);
            if (hasDescriptions) {
                Object obj = get(IF_DESCR, descriptions, i);
                if (obj != null) {
                    service.setDescription(obj.toString());
                }
            }
            services.add(service);
        }

        return services;
    }

    static SNMPSession getSession(ConfigResponse config)
        throws PluginException {

        try {
            return new SNMPClient().getSession(config);
        } catch(SNMPException e) {
            throw new PluginException("Error getting SNMP session: " +
                                      e.getMessage(), e);
        }
    }
    
    //XXX these could be in a base class of some sort
    protected void openSession(ConfigResponse config) throws PluginException {
        this.session = getSession(config);
    }
    
    protected void closeSession() {
        this.session = null;
    }
    
    protected List getColumn(String name) throws PluginException {
        try {
            return this.session.getColumn(name);
        } catch(SNMPException e) {
            throw new PluginException("Error getting SNMP column: " +
                                      name+ ":" + e, e);
        }
    }
    
    //use platform.name instead of the generic type name
    protected String getServerName(ConfigResponse config) {
        String fqdn = config.getValue(ProductPlugin.PROP_PLATFORM_FQDN);
        String name = config.getValue(ProductPlugin.PROP_PLATFORM_NAME);        
        return fqdn + " " + name;
    }

    public List getServerResources(ConfigResponse config) {
        Log log = getLog();
        if (log.isDebugEnabled()) {
            log.debug("Testing snmp config=" + config);
        }
        if (config.getValue(SNMPClient.PROP_IP) == null) {
            log.debug("snmp config incomplete, defering server creation");
            return null;
        }
        try {
            getSession(config).getSingleValue("sysName");
        } catch (Exception e) {
            //wait till we have valid snmp config at the platform level
            log.debug("snmp config invalid, defering server creation");
            return null;
        }
        log.debug("snmp config valid, creating server");
        return super.getServerResources(config);
    }
    
    protected ServerResource getServer(ConfigResponse config) {
        ServerResource server = super.getServer(config);

        server.setName(getServerName(config));

        return server;
    }
}

XServe Device Platform Detector

package org.hyperic.hq.plugin.xserve;
import java.util.Properties;
import java.util.StringTokenizer;

import org.apache.commons.logging.Log;

import org.hyperic.hq.product.PlatformDetector;
import org.hyperic.hq.product.PlatformResource;
import org.hyperic.hq.product.PluginException;
import org.hyperic.hq.product.PluginManager;
import org.hyperic.hq.product.ProductPlugin;
import org.hyperic.snmp.SNMPClient;
import org.hyperic.snmp.SNMPException;
import org.hyperic.snmp.SNMPSession;
import org.hyperic.util.config.ConfigResponse;

public class XserveDevicePlatformDetector extends PlatformDetector {

    private static final String PROP_VERSION = "Version";

    private Properties props;
    private boolean autoDefaults;

    public void init(PluginManager manager) throws PluginException {
        super.init(manager);
        this.props = manager.getProperties();
        this.autoDefaults =
            "true".equals(this.props.getProperty("snmp.autoDefaults"));
        if (!this.autoDefaults) {
            //command-line -DsnmpCommunity=public
            this.autoDefaults =
                this.props.getProperty(SNMPClient.PROP_COMMUNITY) != null;
        }
    }

    private SNMPSession getSession(ConfigResponse config) {
        try {
            return XserveDeviceDetector.getSession(config);
        } catch (PluginException e) {
            getLog().error(e.getMessage(), e);
            return null;
        }
    }

    private String getString(SNMPSession session, String oid) {
        try {
            Object obj = session.getSingleValue(oid); 
            if (obj == null) {
                return null;
            }
            String value = obj.toString();
         
            return value;
        } catch (SNMPException e) {
            getLog().warn("Error getting '" + oid+ "': " +
                          e.getMessage());
            return null;
        }
    }

    //allow defaults to be configure in agent.properties like so:
    //snmpCommunity.192.168.1.102=MyCommunity
    //snmpVersion.192.168.1.102=v1
    //snmpPort.192.168.1.102=1611
    private String getIpProp(String key, String ip, String defVal) {
        String propDefault = this.props.getProperty(key, defVal);
        return this.props.getProperty(key + "." + ip, propDefault);
    }
    
    public PlatformResource getPlatformResource(ConfigResponse config)
        throws PluginException {

        String platformIp = config.getValue(ProductPlugin.PROP_PLATFORM_IP);
        //for command-line -DsnmpIp=x.x.x.x usage
        platformIp =
            getIpProp(SNMPClient.PROP_IP, platformIp, platformIp);

        String defaultVersion =
            getIpProp(SNMPClient.PROP_VERSION,
                      platformIp,
                      SNMPClient.VALID_VERSIONS[1]); //v2c
        String fallbackVersion = SNMPClient.VALID_VERSIONS[0]; //v1

        PlatformResource platform =
            super.getPlatformResource(config);

        Log log = getLog();
        ConfigResponse metricConfig;
        boolean hasConfig =
            config.getValue(SNMPClient.PROP_IP) != null;

        if (hasConfig) {
            //we've already been here
            metricConfig = config;
            if (log.isDebugEnabled()) {
                log.debug("Using approved snmp config=" + metricConfig);
            }
        }
        else if (this.autoDefaults) {
            //platform was just created, attempt to auto-configure
            metricConfig = new ConfigResponse();
            metricConfig.setValue(SNMPClient.PROP_IP, platformIp);
            metricConfig.setValue(SNMPClient.PROP_VERSION, defaultVersion);
            metricConfig.setValue(SNMPClient.PROP_COMMUNITY,
                                  getIpProp(SNMPClient.PROP_COMMUNITY,
                                            platformIp,
                                            SNMPClient.DEFAULT_COMMUNITY));
            metricConfig.setValue(SNMPClient.PROP_PORT,
                                  getIpProp(SNMPClient.PROP_PORT,
                                            platformIp,
                                            SNMPClient.DEFAULT_PORT_STRING));
            metricConfig.setValue(XserveDeviceDetector.PROP_IF_IX,
                                  getIpProp(XserveDeviceDetector.PROP_IF_IX,
                                            platformIp,
                                            XserveDeviceDetector.IF_DESCR));
            if (log.isDebugEnabled()) {
                log.debug("Using default snmp config=" + metricConfig);
            }
        }
        else {
            if (log.isDebugEnabled()) {
                log.debug("Need user input for snmp config=" + config);
            }
            return platform;
        }

        ConfigResponse cprops = new ConfigResponse();

        SNMPSession session;

        if ((session = getSession(metricConfig)) == null) {
            return platform;
        }

        try {
            session.getSingleValue("sysName");
        } catch (SNMPException e) {
            getLog().debug("Unable to connect using " +
                           defaultVersion + ", trying version " +
                           fallbackVersion);
            metricConfig.setValue(SNMPClient.PROP_VERSION,
                                  fallbackVersion);
            if ((session = getSession(metricConfig)) == null) {
                return platform;
            }
        }

        String[] keys =
            getCustomPropertiesSchema().getOptionNames();

        for (int i=0; i<keys.length; i++) {
            String key = keys[i];
            if (Character.isUpperCase(key.charAt(0))) {
                continue; //not a mib name
            }
            String val = getString(session, key);
            if (val == null) {
                log.debug("'" + key + "'==null");
                continue;
            }
            cprops.setValue(key, val);
        }

        if (!hasConfig) {
            //should only happen when the platform is created
            config.merge(metricConfig, false);
            platform.setProductConfig(config);
            platform.setMeasurementConfig(new ConfigResponse());
            log.debug("Setting measurement config="+metricConfig);
        }
        
        String description = getString(session, "sysDescr");
        if (description != null) {
            platform.setDescription(description);

            boolean hasVersionCprop =
                getCustomPropertiesSchema().getOption(PROP_VERSION) != null;

            if (hasVersionCprop) {
                 StringTokenizer tok = new StringTokenizer(description, " ,");

                while (tok.hasMoreTokens()) {
                    String s = tok.nextToken();
                    if (s.equalsIgnoreCase(PROP_VERSION) &&
                        tok.hasMoreTokens())
                    {
                        String version = tok.nextToken();
                        cprops.setValue(PROP_VERSION, version);
                        break;
                    }
                }
            }
        }

        platform.setCustomProperties(cprops);

        return platform;
    }
}

XServe Device Product Plugin

package org.hyperic.hq.plugin.xserve;
import java.io.IOException;

import org.hyperic.hq.product.PluginException;
import org.hyperic.hq.product.ProductPlugin;

public class XserveDeviceProductPlugin extends ProductPlugin {

    public void shutdown() throws PluginException {
        super.shutdown();

        try {
            SNMPTrapReceiver.shutdown();
        } catch (IOException e) {
            getLog().error(e.getMessage(), e);
        }
    }
}

XServe Host Detector

package org.hyperic.hq.plugin.xserve;

import java.util.List;

import org.hyperic.hq.product.PluginException;
import org.hyperic.hq.product.ServiceResource;
import org.hyperic.util.config.ConfigResponse;

public class XserveHostDetector extends XserveDeviceDetector {
    
    private static final String STORAGE_NAME   = "Storage";
    private static final String PROP_STORAGE   = STORAGE_NAME.toLowerCase();
    private static final String STORAGE_COLUMN = "hrStorageDescr";
    
    public List discoverServices(ConfigResponse serverConfig)
            throws PluginException {

        List services = super.discoverServices(serverConfig);
        openSession(serverConfig);

        List storageDesc = getColumn(STORAGE_COLUMN);

        for (int i=0; i<storageDesc.size(); i++) {
            ConfigResponse config = new ConfigResponse();
            String name = storageDesc.get(i).toString();

            ServiceResource service = createServiceResource(STORAGE_NAME);

            config.setValue(PROP_STORAGE, name);
            service.setProductConfig(config);
            //required to auto-enable metric
            service.setMeasurementConfig();
            
            service.setServiceName(name.trim() + " " + STORAGE_NAME);

            services.add(service);
        }

        closeSession();
        
        return services;
    }
}

XserveInterfaceMeasurementPlugin

package org.hyperic.hq.plugin.xserve;

import java.util.HashMap;

import org.hyperic.hq.product.Metric;
import org.hyperic.hq.product.MetricNotFoundException;
import org.hyperic.hq.product.MetricUnreachableException;
import org.hyperic.hq.product.MetricValue;
import org.hyperic.hq.product.PluginException;
import org.hyperic.hq.product.SNMPMeasurementPlugin;
import org.hyperic.snmp.SNMPClient;
import org.hyperic.util.StringUtil;

/**
 * Conditionally use Counter64 versions of IF-MIB metrics.
 * These metrics are not supported when using snmp v1.
 * Not all devices support the 64 bit versions regardless.
 */
public class XserveInterfaceMeasurementPlugin
    extends SNMPMeasurementPlugin {

    static HashMap counter64 = new HashMap();
    static HashMap unsupported = new HashMap();

    static {
        counter64.put("ifInOctets", "ifHCInOctets");
        counter64.put("ifOutOctets", "ifHCOutOctets");

        counter64.put("ifInUcastPkts", "ifHCInUcastPkts");
        counter64.put("ifOutUcastPkts", "ifHCOutUcastPkts");

        counter64.put("ifInNUcastPkts", "ifInMulticastPkts");
        counter64.put("ifOutNUcastPkts", "ifOutMulticastPkts");
    }

    private boolean supportsCounter64(String version) {
        return (version != null) && !version.equals("v1");
    }

    private boolean supportsCounter64(Metric metric) {
        if (unsupported.get(metric.getObjectPropString()) == Boolean.TRUE) {
            return false;
        }
        return supportsCounter64(metric.getObjectProperty(SNMPClient.PROP_VERSION));
    }

    public MetricValue getValue(Metric metric)
        throws MetricUnreachableException,
               MetricNotFoundException,
               PluginException {
        if (supportsCounter64(metric)) {
            String attr = metric.getAttributeName();
            String counter = (String)counter64.get(attr);

            if (counter != null) {
                boolean isDebug = getLog().isDebugEnabled();

                if (isDebug) {
                    getLog().debug("Trying 64 bit counter: " +
                                   attr + "->" + counter);
                }

                //would be nice to avoid this every time.
                String template =
                    StringUtil.replace(metric.toString(), attr, counter);

                Metric metric64 = Metric.parse(template);

                try {
                    return super.getValue(metric64);
                } catch (MetricNotFoundException e) {
                    //not supported, fallthru
                    unsupported.put(metric.getObjectPropString(),
                                    Boolean.TRUE); //dont try again
                    if (isDebug) {
                        getLog().debug("Device does not support Counter64: " +
                                       metric.getObjectPropString());
                    }
                }
            }
        }
        return super.getValue(metric);
    }
}

XML Files

HQ Plugin

<?xml version="1.0"?>

<!DOCTYPE plugin [

  <!ENTITY xserve-platform SYSTEM "/etc/xserve-platform.xml">

  <!ENTITY xserve-services SYSTEM "/etc/xserve-services.xml">

]>

<plugin name="Xserve RAID"

        class="org.hyperic.hq.plugin.xserve.XserveDeviceProductPlugin">

  <filter name="if.config"

          value="snmpIndexName=%interface.index%,snmpIndexValue=%interface%"/>

  <filter name="storage.config"

          value="snmpIndexName=hrStorageDescr,snmpIndexValue=%storage%"/>

  <metrics name="xserve-platform">

    <metric name="Uptime"

            template="${snmp.template}:sysUpTime"

            category="AVAILABILITY"

            units="jiffys"

            collectionType="static"/>

    <metric name="Availability"

            template="${snmp.template},Avail=true:ifNumber"

            indicator="true"/>

    <metric name="IP In Receives"

            template="${snmp.template}:ipInReceives"

            category="THROUGHPUT"

             indicator="true"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP In Header Errors"

            template="${snmp.template}:ipInHdrErrors"

            category="THROUGHPUT"

             indicator="true"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP In Address Errors"

            template="${snmp.template}:ipInAddrErrors"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP Forwards"

            template="${snmp.template}:ipForwDatagrams"

            category="THROUGHPUT"

            indicator="true"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP In Unknown Protocol"

            template="${snmp.template}:ipInUnknownProtos"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP In Discards"

            template="${snmp.template}:ipInDiscards"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP In Delivers"

            template="${snmp.template}:ipInDelivers"

            category="THROUGHPUT"

            indicator="true"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP Out Requests"

            template="${snmp.template}:ipOutRequests"

            category="THROUGHPUT"

            indicator="true"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP Out Discards"

            template="${snmp.template}:ipOutDiscards"

            category="THROUGHPUT"

            indicator="true"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP Out No Routes"

            template="${snmp.template}:ipOutNoRoutes"

            category="THROUGHPUT"

            indicator="true"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP Reassembles Required"

            template="${snmp.template}:ipReasmReqds"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP Reassembles OK"

            template="${snmp.template}:ipReasmOKs"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP Reassembles Failed"

            template="${snmp.template}:ipReasmFails"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP Fragmented OK"

            template="${snmp.template}:ipFragOKs"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP Fragmented Failures"

            template="${snmp.template}:ipFragFails"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="IP Fragmented Creates"

            template="${snmp.template}:ipFragCreates"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

  </metrics>

  <!-- note 'if-' prefix on several templates is to bypass the
    snmp: proxy and use XserveInterfaceMeasurementPlugin to conditionally handle 64 bit counters -->

  <metrics name="xserve-interface">

  <metric name="Availability"

            template="${snmp.template},Avail=true:ifOperStatus:${if.config}"

            indicator="true"/>

       <metric name="Bytes Sent"

            template="if-${snmp.template}:ifOutOctets:${if.config}"

            category="THROUGHPUT"

            units="B"

            indicator="true"

            collectionType="trendsup"/>

    <metric name="Bits Sent"

            template="if-${snmp.template}:ifOutOctets:${if.config}"

            category="THROUGHPUT"

            indicator="true"

            units="bytesToBits"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="Last Change"

            template="${snmp.template}:ifLastChange:${if.config}"

            category="AVAILABILITY"

            units="jiffys"

            collectionType="static"/>

    <metric name="Bytes Received"

            template="if-${snmp.template}:ifInOctets:${if.config}"

            category="THROUGHPUT"

            units="B"

            indicator="true"

            collectionType="trendsup"/>

    <metric name="Bits Received"

            template="if-${snmp.template}:ifInOctets:${if.config}"

            category="THROUGHPUT"

            indicator="true"

            units="bytesToBits"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="Inbound Packets"

            template="if-${snmp.template}:ifInUcastPkts:${if.config}"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="Outbound Packets"

            template="if-${snmp.template}:ifOutUcastPkts:${if.config}"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="Outbound Multicast Packets"

            template="if-${snmp.template}:ifOutNUcastPkts:${if.config}"

            category="THROUGHPUT"

            indicator="true"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="Outbound Packet Discards"

            template="if-${snmp.template}:ifOutDiscards:${if.config}"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="Outbound Errors"

            template="${snmp.template}:ifOutErrors:${if.config}"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="Outbound Packets Queues"

            template="${snmp.template}:ifOutQLen:${if.config}"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

            <metric name="Inbound Multicast Packets"

            template="if-${snmp.template}:ifInNUcastPkts:${if.config}"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="Inbound Packet Discards"

            template="${snmp.template}:ifInDiscards:${if.config}"

            category="THROUGHPUT"

            indicator="true"

            rate="1s"

            collectionType="trendsup"/>

    <metric name="Inbound Errors"

            template="${snmp.template}:ifInErrors:${if.config}"

            category="THROUGHPUT"

            rate="1s"

            collectionType="trendsup"/>

  </metrics>

  <config name="interface.index">

    <option name="interface.index"

            description="Interface index"

            type="enum">

      <include name="ifDescr"/>

      <include name="ifName"/>

      <include name="ifAlias"/>

      <include name="ifIndex"/>

    </option>

  </config>

  <platform name="Xserve RAID Device">

    &xserve-platform;

    <server>

      <plugin type="autoinventory" class="org.hyperic.hq.plugin.xserve.XserveDeviceDetector"/>

    &xserve-services;

    </server>

  </platform>

  <platform name="Xserve Host">

    &xserve-platform;

    <server>

      <plugin type="autoinventory" class="org.hyperic.hq.plugin.xserve.XserveHostDetector"/>

      &xserve-services;

   </server>

  </platform>

  </plugin>

XServe Platform

<plugin type="autoinventory" class="org.hyperic.hq.plugin.xserve.XserveDevicePlatformDetector"/>

    <!-- type must be measurement to override SNMPMeasurementPlugin -->
    <config include="snmp,interface.index" type="measurement"/>

    <properties>
      <property name="sysDescr"
                description="System Description"/>
      <property name="sysName"
                description="System Name & Version"/>
      <property name="sysContact"
                description="Contact Name"/>
      <property name="sysLocation"
                description="Location"/>
       <property name="sysUpTime"
                description="System Updated Time"/>
      <property name="sysServices"
                description="Number of System Services"/>
     </properties>

    <plugin type="measurement"
            class="org.hyperic.hq.product.SNMPMeasurementPlugin"/>

    <plugin type="log_track"
            class="org.hyperic.hq.plugin.xserve.SNMPTrapReceiverPlugin"/>
    <metrics include="xserve-platform"/>

XServe Services

<service name="Interface">
        <config include="interface.index">
          <option name="interface"
                  description="Interface Name (Ex:cpm0,lo0,mirror0 for ifDescr)"/>
        </config>
<!-- 
       snmpwalk is an SNMP application that  uses  SNMP  GETNEXT  requests  to
       query a network entity for a tree of information.
       Ex : snmpwalk -Os -c private -v 1 192.168.1.240
       By using the above command to retrieve the Xserve RAID metric Information
 -->
        <properties>
          <property name="ifDescr"
                    type="string"
                    description="Interface Description"/>
          <property name="ifIndex"
                    type="int"
                    description="Interface Index"/>
          <property name="ifName"
                    type="string"
                    description="Interface Name"/>
          <property name="ifPhysAddress"
                    type="macaddress"
                    description="Physical Address"/>
          <property name="ifMtu"
                    type="int"
                    description="Maximum Transmission Unit"/>
          <property name="ifSpeed"
                    type="int"
                    description="Bandwidth"/>
          <property name="ipaddress"
                    type="ipaddress"
                    description="IP Address"/>
          <property name="netmask"
                    type="ipaddress"
                    description="Netmask"/>
        </properties>

        <metrics include="xserve-interface"/>

        <plugin type="measurement"
                class="org.hyperic.hq.plugin.xserve.XserveInterfaceMeasurementPlugin"/>

      </service>

Browse Space

- Pages
- News
- Labels
- Attachments
- Bookmarks
- Mail
- Advanced
- Activity

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

or Sign Up  

Other Features

Add Content


SourceForge.net Logo