Search in sources :

Example 36 with AS400

use of com.ibm.as400.access.AS400 in project openicf by Evolveum.

the class OS400Connector method init.

/**
 * Callback method to receive the {@link Configuration}.
 *
 * @see Connector#init(org.identityconnectors.framework.spi.Configuration)
 */
public void init(Configuration configuration1) {
    this.configuration = (OS400Configuration) configuration1;
    if (as400 == null) {
        try {
            final StringBuilder clear = new StringBuilder();
            GuardedString.Accessor accessor = new GuardedString.Accessor() {

                public void access(char[] clearChars) {
                    clear.append(clearChars);
                }
            };
            configuration.getPassword().access(accessor);
            if (configuration.isSsl()) {
                as400 = new SecureAS400(configuration.getHost(), configuration.getRemoteUser(), clear.toString());
            } else {
                as400 = new AS400(configuration.getHost(), configuration.getRemoteUser(), clear.toString());
            }
            clear.setLength(0);
            if (as400 == null) {
                throw new ConnectorException("Connection Exception");
            }
            if (!as400.validateSignon()) {
                throw new ConnectorSecurityException("Login Error");
            }
            try {
                as400.setGuiAvailable(false);
                fetchPasswordLevel();
            } catch (Exception e) {
            }
        } catch (AS400SecurityException e) {
            throw new ConnectorSecurityException(e);
        } catch (IOException e) {
            throw new ConnectorIOException(e);
        }
    }
}
Also used : ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) SecureAS400(com.ibm.as400.access.SecureAS400) AS400SecurityException(com.ibm.as400.access.AS400SecurityException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) SecureAS400(com.ibm.as400.access.SecureAS400) AS400(com.ibm.as400.access.AS400) GuardedString(org.identityconnectors.common.security.GuardedString) ConnectorSecurityException(org.identityconnectors.framework.common.exceptions.ConnectorSecurityException) ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) IOException(java.io.IOException) ConnectorSecurityException(org.identityconnectors.framework.common.exceptions.ConnectorSecurityException) IntrospectionException(java.beans.IntrospectionException) ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) RequestNotSupportedException(com.ibm.as400.access.RequestNotSupportedException) IOException(java.io.IOException) AS400SecurityException(com.ibm.as400.access.AS400SecurityException)

Example 37 with AS400

use of com.ibm.as400.access.AS400 in project nagios-for-i by IBM.

the class QWCRSSTS method run.

public final byte[] run(AS400 system, StringBuffer response) throws Exception {
    final ProgramCall pgm = new ProgramCall(system, programName_, parameters_);
    init(system);
    if (!pgm.run()) {
        AS400Message[] msgList = pgm.getMessageList();
        response.append(Constants.retrieveDataError + " - ");
        for (int i = 0; i < msgList.length; i++) {
            response.append(msgList[i].getID() + ": " + msgList[i].getText() + "\n");
        }
        return null;
    }
    byte[] receiver = parameters_[0].getOutputData().clone();
    errorCode_ = null;
    parameters_ = null;
    return receiver;
}
Also used : AS400Message(com.ibm.as400.access.AS400Message) ProgramCall(com.ibm.as400.access.ProgramCall)

Example 38 with AS400

use of com.ibm.as400.access.AS400 in project nagios-for-i by IBM.

the class QYASPOL method collectData.

/*
     * Performs the program call using the qyaspol API to gather the disk information. Adds gathered data to the
     * appropriate list The number of records returned is 1 for each disk within the system
     */
private final boolean collectData(AS400 system, boolean firstTime, int receiverLength) throws Exception {
    AS400Text text8 = null;
    AS400Text text4 = null;
    byte[] filterInfo = null;
    byte[] sortInfo = null;
    byte[] data = null;
    byte[] listInfo = null;
    try {
        final ProgramCall pgm = new ProgramCall(system, programName_, parameters_);
        final int ccsid = system.getCcsid();
        text8 = new AS400Text(8, ccsid, system);
        text4 = new AS400Text(4, ccsid, system);
        filterInfo = new byte[16];
        BinaryConverter.intToByteArray(16, filterInfo, 0);
        BinaryConverter.intToByteArray(1, filterInfo, 4);
        BinaryConverter.intToByteArray(4, filterInfo, 8);
        BinaryConverter.intToByteArray(-1, filterInfo, 12);
        sortInfo = new byte[16];
        BinaryConverter.intToByteArray(16, filterInfo, 0);
        BinaryConverter.intToByteArray(1, filterInfo, 4);
        BinaryConverter.intToByteArray(4, filterInfo, 8);
        BinaryConverter.intToByteArray(-1, filterInfo, 12);
        parameters_[0].setOutputDataLength(receiverLength);
        parameters_[1].setInputData(BinaryConverter.intToByteArray(receiverLength));
        parameters_[5].setInputData(filterInfo);
        parameters_[6].setInputData(text8.toBytes(formatName_));
        parameters_[8].setInputData(sortInfo);
        if (!pgm.run()) {
            throw new AS400Exception(pgm.getMessageList());
        }
        data = parameters_[0].getOutputData();
        listInfo = parameters_[2].getOutputData();
        rcdsReturned_ = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(listInfo, 4)), 0);
        int totalRcds = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(listInfo, 0)), 0);
        int firstRecord = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(listInfo, 36)), 0);
        rqsHandle_ = new byte[4];
        System.arraycopy(listInfo, 8, rqsHandle_, 0, 4);
        if (debug) {
            System.out.println("QYASPOL300.collectData: Total Records:" + totalRcds);
            System.out.println("QYASPOL300.collectData: Records Returned:" + rcdsReturned_);
            System.out.println("QYASPOL300.collectData: First Record:" + firstRecord);
            if ((firstRecord + rcdsReturned_ - 1) != totalRcds) {
                System.out.println("QYASPOL300.collectData: Not all records were returned");
            }
        }
        sCountNew.clear();
        nbCountNew.clear();
        rRequestsNew.clear();
        wRequestsNew.clear();
        aspNumber.clear();
        diskNumber.clear();
        diskType.clear();
        diskCapacity.clear();
        percUsed.clear();
        diskAvailable.clear();
        aspProType.clear();
        unitStatus.clear();
        if (!firstTime) {
            for (int i = 0; i < rcdsReturned_; i++) {
                // The receiver struct has a length of 96
                int offset = i * rcdLength_;
                // Sample Count -- 80
                int sInt = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (80 + offset))), 0);
                // Not Busy Count -- 84
                int nbInt = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (84 + offset))), 0);
                // ASP Number -- 0
                int aspNum = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (0 + offset))), 0);
                // Disk Number -- 32
                int dNum = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (32 + offset))), 0);
                // Read Requests -- 64
                int rReq = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (64 + offset))), 0);
                // Write Requests -- 68
                int wReq = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (68 + offset))), 0);
                // Disk Type -- 4
                String dType = ((String) text4.toObject(data, (4 + offset))).trim();
                // Disk Capacity -- 36
                int dSize = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (36 + offset))), 0);
                // Storage Available -- 40
                int storAvail = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (40 + offset))), 0);
                // Storage Reserved For System -- 44
                int storReser = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (44 + offset))), 0);
                // Baseline is established so now just update value
                sCountNew.add(sInt);
                nbCountNew.add(nbInt);
                rRequestsNew.add(rReq);
                wRequestsNew.add(wReq);
                // No baseline needed so just gather data normally
                aspNumSet.add(aspNum);
                aspNumber.add(aspNum);
                diskNumber.add(dNum);
                diskType.add(dType);
                diskCapacity.add(dSize);
                diskAvailable.add(storAvail);
                percUsed.add(calcPercentUsed(dSize, storAvail, storReser));
            }
        } else {
            for (int i = 0; i < rcdsReturned_; i++) {
                // The receiver struct has a length of 96
                int offset = i * 96;
                // Sample Count -- 80
                int sInt = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (80 + offset))), 0);
                // Not Busy Count -- 84
                int nbInt = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (84 + offset))), 0);
                // Read Requests -- 64
                int rReq = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (64 + offset))), 0);
                // Write Requests -- 68
                int wReq = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(data, (68 + offset))), 0);
                sCountBase.add(sInt);
                nbCountBase.add(nbInt);
                rRequestsBase.add(rReq);
                wRequestsBase.add(wReq);
            }
        }
        ProgramParameter[] parameters = new ProgramParameter[] { new ProgramParameter(rqsHandle_), new ProgramParameter(BinaryConverter.intToByteArray(0)) };
        ProgramCall pc = new ProgramCall(system, "/QSYS.LIB/QGY.LIB/QGYCLST.PGM", parameters);
        if (!pc.run()) {
            throw new AS400Exception(pc.getMessageList());
        }
        return true;
    } catch (Exception e) {
        System.err.println("QYASPOL300.collectData: " + e.getMessage());
        e.printStackTrace();
        throw new Exception("QYASPOL300.collectData: " + e.getMessage());
    } finally {
        text8 = null;
        text4 = null;
        filterInfo = null;
        sortInfo = null;
        data = null;
        listInfo = null;
        rqsHandle_ = null;
        errorCode_ = null;
        parameters_ = null;
    }
}
Also used : ProgramParameter(com.ibm.as400.access.ProgramParameter) AS400Exception(com.ibm.as400.access.AS400Exception) AS400Text(com.ibm.as400.access.AS400Text) AS400Exception(com.ibm.as400.access.AS400Exception) ProgramCall(com.ibm.as400.access.ProgramCall)

Example 39 with AS400

use of com.ibm.as400.access.AS400 in project nagios-for-i by IBM.

the class QYASPOL method getPCLength.

private final int getPCLength(AS400 system) throws Exception {
    AS400Text text8 = null;
    AS400Text text4 = null;
    byte[] filterInfo = null;
    byte[] sortInfo = null;
    try {
        final ProgramCall pgm = new ProgramCall(system, programName_, parameters_);
        final int ccsid = system.getCcsid();
        text8 = new AS400Text(8, ccsid, system);
        text4 = new AS400Text(4, ccsid, system);
        filterInfo = new byte[16];
        BinaryConverter.intToByteArray(16, filterInfo, 0);
        BinaryConverter.intToByteArray(1, filterInfo, 4);
        BinaryConverter.intToByteArray(4, filterInfo, 8);
        BinaryConverter.intToByteArray(-1, filterInfo, 12);
        sortInfo = new byte[16];
        BinaryConverter.intToByteArray(16, filterInfo, 0);
        BinaryConverter.intToByteArray(1, filterInfo, 4);
        BinaryConverter.intToByteArray(4, filterInfo, 8);
        BinaryConverter.intToByteArray(-1, filterInfo, 12);
        parameters_[0].setOutputDataLength(0);
        parameters_[1].setInputData(BinaryConverter.intToByteArray(0));
        parameters_[5].setInputData(filterInfo);
        parameters_[6].setInputData(text8.toBytes(formatName_));
        parameters_[8].setInputData(sortInfo);
        if (!pgm.run()) {
            throw new AS400Exception(pgm.getMessageList());
        }
        final byte[] listInfo = parameters_[2].getOutputData();
        rcdsReturned_ = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(listInfo, 4)), 0);
        rqsHandle_ = new byte[4];
        System.arraycopy(listInfo, 8, rqsHandle_, 0, 4);
        int totalRcds = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(listInfo, 0)), 0);
        rcdLength_ = BinaryConverter.byteArrayToInt(text4.toBytes(text4.toObject(listInfo, 12)), 0);
        int receiverLength = totalRcds * rcdLength_;
        ProgramParameter[] parameters = new ProgramParameter[] { new ProgramParameter(rqsHandle_), new ProgramParameter(BinaryConverter.intToByteArray(0)) };
        ProgramCall pc = new ProgramCall(system, "/QSYS.LIB/QGY.LIB/QGYCLST.PGM", parameters);
        if (!pc.run()) {
            throw new AS400Exception(pc.getMessageList());
        }
        return receiverLength;
    } catch (Exception e) {
        System.err.println("QYASPOL300.collectData: " + e.toString());
        e.printStackTrace();
        throw new Exception("QYASPOL300.getPCLength: " + e.toString());
    } finally {
        text8 = null;
        text4 = null;
        filterInfo = null;
        sortInfo = null;
    }
}
Also used : ProgramParameter(com.ibm.as400.access.ProgramParameter) AS400Exception(com.ibm.as400.access.AS400Exception) AS400Text(com.ibm.as400.access.AS400Text) AS400Exception(com.ibm.as400.access.AS400Exception) ProgramCall(com.ibm.as400.access.ProgramCall)

Example 40 with AS400

use of com.ibm.as400.access.AS400 in project nagios-for-i by IBM.

the class QYHCHCOP method init.

private final void init(AS400 system) throws Exception {
    AS400Text reqText = null;
    try {
        final int ccsid = system.getCcsid();
        int requestLen = requestInfo.length();
        reqText = new AS400Text(requestLen, ccsid, system);
        parameters_[REQUEST].setInputData(reqText.toBytes(requestInfo));
        parameters_[REQUEST_LEN].setInputData(BinaryConverter.intToByteArray(requestInfo.length()));
        parameters_[REQUEST_TYPE].setInputData(BinaryConverter.intToByteArray(2));
        parameters_[RECEIVER].setOutputDataLength(OUTPUT_LENGTH);
        parameters_[RECEIVER_LEN].setInputData(BinaryConverter.intToByteArray(OUTPUT_LENGTH));
        parameters_[RETURN_DATA].setOutputDataLength(4);
        parameters_[CCSID].setInputData(BinaryConverter.intToByteArray(0));
    } catch (PropertyVetoException pve) {
        System.err.println("QYHCHCOP.init: Error setting parameters: " + pve.toString());
    } finally {
        reqText = null;
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) AS400Text(com.ibm.as400.access.AS400Text)

Aggregations

IFSFile (com.ibm.as400.access.IFSFile)16 AS400Text (com.ibm.as400.access.AS400Text)14 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)14 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)14 AS400Message (com.ibm.as400.access.AS400Message)12 AS400 (com.ibm.as400.access.AS400)11 CommandCall (com.ibm.as400.access.CommandCall)9 IOException (java.io.IOException)8 AS400FileRecordDescription (com.ibm.as400.access.AS400FileRecordDescription)5 Record (com.ibm.as400.access.Record)5 RecordFormat (com.ibm.as400.access.RecordFormat)5 SequentialFile (com.ibm.as400.access.SequentialFile)5 BadLocationException (javax.swing.text.BadLocationException)5 ProgramCall (com.ibm.as400.access.ProgramCall)4 Point (java.awt.Point)4 Path (java.nio.file.Path)4 AS400SecurityException (com.ibm.as400.access.AS400SecurityException)3 RequestNotSupportedException (com.ibm.as400.access.RequestNotSupportedException)3 IntrospectionException (java.beans.IntrospectionException)3 ConnectorException (org.identityconnectors.framework.common.exceptions.ConnectorException)3