Search in sources :

Example 1 with Disk

use of com.ibm.nagios.model.Disk in project nagios-for-i by IBM.

the class DiskConfig method execute.

public int execute(AS400 as400, Map<String, String> args, StringBuffer response) {
    int returnValue = Constants.UNKNOWN;
    String system = args.get("-H");
    String userID = HostConfigInfo.getSSTUserID(system);
    String pass = HostConfigInfo.getSSTPassword(system);
    if (userID == null || pass == null) {
        response.append("SST user profile not set");
        return returnValue;
    }
    int userLen = userID.length();
    String password = Base64Coder.decodeString(pass);
    int passLen = password.length();
    final int ccsid = as400.getCcsid();
    QYHCHCOP pgmCall = null;
    AS400Text userText = new AS400Text(userLen, ccsid, as400);
    AS400Text passText = new AS400Text(passLen, ccsid, as400);
    try {
        pgmCall = new QYHCHCOP();
        pgmCall.setParameter(pgmCall.USER_ID, userText.toBytes(userID));
        pgmCall.setParameter(pgmCall.USER_ID_LEN, BinaryConverter.intToByteArray(userLen));
        pgmCall.setParameter(pgmCall.PASSWORD, passText.toBytes(password));
        pgmCall.setParameter(pgmCall.PASSWOD_LEN, BinaryConverter.intToByteArray(passLen));
        String receiver = pgmCall.run(as400, response);
        if (receiver == null) {
            return returnValue;
        }
        ArrayList<Disk> disks = DiskXMLReader.getDiskConfigInfo(receiver.trim());
        int ASPNum;
        int unitNum;
        String resourceName = null;
        int status;
        int warningStatus = 0;
        returnValue = Constants.OK;
        for (int i = 0; i < disks.size(); i++) {
            Disk disk = disks.get(i);
            ASPNum = disk.getASPNum();
            unitNum = disk.getDiskNum();
            resourceName = disk.getResourceName();
            status = disk.getStatus();
            if (status != Hardware_OK && returnValue != Constants.WARN) {
                returnValue = Constants.WARN;
                warningStatus = status;
            }
            response.append("Unit " + ASPNum + "-" + unitNum + ": " + resourceName + " Status: " + STATUS[status] + "\n");
        }
        if (returnValue == Constants.OK) {
            response.insert(0, "Disk Status: OK\n");
        } else if (returnValue == Constants.WARN) {
            response.insert(0, "Disk Status: " + STATUS[warningStatus] + "\n");
        }
    } catch (Exception e) {
        response.setLength(0);
        response.append(Constants.retrieveDataException + " - " + e.toString());
        CommonUtil.printStack(e.getStackTrace(), response);
        e.printStackTrace();
    } finally {
        userText = null;
        passText = null;
        pgmCall = null;
    }
    return returnValue;
}
Also used : AS400Text(com.ibm.as400.access.AS400Text) QYHCHCOP(com.ibm.nagios.util.QYHCHCOP) Disk(com.ibm.nagios.model.Disk)

Example 2 with Disk

use of com.ibm.nagios.model.Disk in project nagios-for-i by IBM.

the class DiskUsageStatus method setASPDiskData.

public void setASPDiskData() throws Exception {
    QYASPOL pc = new QYASPOL();
    Disks.clear();
    if (callQYASPOL(pc)) {
        if (!firstTime) {
            for (int i = 0; i < pc.getRcdsReturned(); i++) {
                Disk disk = new Disk();
                disk.setASPNum(pc.getASPNumber(i));
                disk.setDiskNum(pc.getDiskNumber(i));
                disk.setDiskBusy(pc.getPercBusy(i, sCountBase.get(i), nbCountBase.get(i)));
                disk.setDiskUsed(pc.getPercentUsed(i));
                disk.setDiskReads(pc.getReadRequests(i, rReqBase.get(i)));
                disk.setDiskWrites(pc.getWriteRequests(i, wReqBase.get(i)));
                disk.setDiskTotalIO(pc.getTotalIO(i, rReqBase.get(i), wReqBase.get(i)));
                disk.setDiskCapacity(pc.getDiskCapacity(i));
                disk.setDiskAvailable(pc.getDiskAvailable(i));
                disk.setDiskType(pc.getDiskType(i));
                Disks.add(disk);
            }
        } else {
            sCountBase = pc.getSCountBase();
            nbCountBase = pc.getNBCountBase();
            rReqBase = pc.getReadReqBase();
            wReqBase = pc.getWriteReqBase();
            totalTime = System.currentTimeMillis();
        }
        firstTime = false;
    }
}
Also used : Disk(com.ibm.nagios.model.Disk)

Example 3 with Disk

use of com.ibm.nagios.model.Disk in project nagios-for-i by IBM.

the class DiskXMLReader method parseXML.

private static void parseXML(String inputXML) {
    try {
        DocumentBuilderFactory dbFact = DocumentBuilderFactory.newInstance();
        DocumentBuilder domParser = dbFact.newDocumentBuilder();
        InputSource isrc = new InputSource(new StringReader(inputXML));
        Document document = domParser.parse(isrc);
        NodeList disks = document.getElementsByTagName("Disk");
        for (int i = 0; i < disks.getLength(); i++) {
            Node diskNode = disks.item(i);
            if (diskNode != null && diskNode.getNodeType() == Node.ELEMENT_NODE) {
                if (diskNode.getAttributes().getNamedItem("ASP") != null) {
                    String ASPNum = diskNode.getAttributes().getNamedItem("ASP").getNodeValue();
                    String unitNum = diskNode.getAttributes().getNamedItem("Number").getNodeValue();
                    String resourceName = diskNode.getAttributes().getNamedItem("Name").getNodeValue();
                    String status = diskNode.getAttributes().getNamedItem("Status").getNodeValue();
                    Disk disk = new Disk();
                    disk.setASPNum(Integer.parseInt(ASPNum));
                    disk.setDiskNum(Integer.parseInt(unitNum));
                    disk.setResourceName(resourceName);
                    disk.setStatus(Integer.parseInt(status));
                    diskList.add(disk);
                }
            }
        }
    } catch (Exception e) {
        System.err.println("Error in parsing disk xml: " + e.toString());
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) Disk(com.ibm.nagios.model.Disk)

Aggregations

Disk (com.ibm.nagios.model.Disk)3 AS400Text (com.ibm.as400.access.AS400Text)1 QYHCHCOP (com.ibm.nagios.util.QYHCHCOP)1 StringReader (java.io.StringReader)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 InputSource (org.xml.sax.InputSource)1