use of com.ibm.as400.access.AS400Exception 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;
}
}
use of com.ibm.as400.access.AS400Exception 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;
}
}
Aggregations