use of com.ibm.nagios.util.JDBCConnection in project nagios-for-i by IBM.
the class Message method execute.
public int execute(AS400 as400, Map<String, String> args, StringBuffer response) {
int version = 0;
int release = 0;
try {
version = as400.getVersion();
release = as400.getRelease();
} catch (Exception eVR) {
response.append(Constants.retrieveDataException + " - " + eVR.getMessage());
return Constants.UNKNOWN;
}
int messageNum = 0;
int severity = 0;
String type = null;
String msgText = null;
String msgID = null;
String user = null;
Date date = null;
Time time = null;
Statement stmt = null;
ResultSet rs = null;
String msgQueLib = args.get("-LIB");
msgQueLib = msgQueLib == null ? "QSYS" : msgQueLib.trim().toUpperCase();
String msgQueName = args.get("-NAME");
msgQueName = msgQueName == null ? "QSYSOPR" : msgQueName.trim().toUpperCase();
String msgType = args.get("-TY");
msgType = msgType == null ? "INQUIRY, ESCAPE, REPLY" : msgType.trim().toUpperCase();
String[] types = msgType.split(",");
String requireType = "";
for (int i = 0; i < types.length; i++) {
requireType = requireType + "'" + types[i].trim() + "'";
if (i != types.length - 1)
requireType += ",";
}
Integer returnValue = Constants.UNKNOWN;
String warningCap = args.get("-W");
String criticalCap = args.get("-C");
int intWarningCap = (warningCap == null) ? 100 : Integer.parseInt(warningCap);
int intCriticalCap = (criticalCap == null) ? 100 : Integer.parseInt(criticalCap);
if (version > 7 || (version == 7 && release > 1)) {
// system version is priority to v7r1, run the plugin by SQL service
Connection connection = null;
try {
JDBCConnection JDBCConn = new JDBCConnection();
connection = JDBCConn.getJDBCConnection(as400.getSystemName(), args.get("-U"), args.get("-P"), args.get("-SSL"));
if (connection == null) {
response.append(Constants.retrieveDataError + " - " + "Cannot get the JDBC connection");
return returnValue;
}
stmt = connection.createStatement();
rs = stmt.executeQuery("SELECT MESSAGE_ID, FROM_USER, MESSAGE_TYPE, MESSAGE_TEXT, SEVERITY, MESSAGE_TIMESTAMP FROM QSYS2.MESSAGE_QUEUE_INFO WHERE MESSAGE_QUEUE_LIBRARY = '" + msgQueLib.trim() + "' AND MESSAGE_QUEUE_NAME = '" + msgQueName.trim() + "' AND MESSAGE_TYPE IN (" + requireType + ")");
if (rs == null) {
response.append(Constants.retrieveDataError + " - " + "Cannot retrieve data from server");
return returnValue;
}
while (rs.next()) {
msgID = rs.getString("MESSAGE_ID");
user = rs.getString("FROM_USER");
type = rs.getString("MESSAGE_TYPE");
msgText = rs.getString("MESSAGE_TEXT");
date = rs.getDate("MESSAGE_TIMESTAMP");
time = rs.getTime("MESSAGE_TIMESTAMP");
severity = rs.getInt("SEVERITY");
response.append("ID: " + msgID + " Text: " + msgText + "\n");
response.append("User: " + user + " Type: " + type + " Severity: " + severity + " Date Sent: " + date + " Time Sent: " + time + "\n");
messageNum++;
}
returnValue = CommonUtil.getStatus(messageNum, intWarningCap, intCriticalCap, returnValue);
response.insert(0, "Message Num in type " + requireType + ": " + messageNum + "\n");
} catch (Exception e) {
response.setLength(0);
response.append(Constants.retrieveDataException + " - " + e.toString());
CommonUtil.printStack(e.getStackTrace(), response);
CommonUtil.logError(args.get("-H"), this.getClass().getName(), e.getMessage());
e.printStackTrace();
} finally {
date = null;
time = null;
types = null;
try {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (connection != null)
connection.close();
} catch (SQLException e) {
response.append(Constants.retrieveDataException + " - " + e.toString());
}
}
} else {
// system version is v7r1 or below, run the plugin by API
ProgramCallDocument pcml = null;
boolean rc = false;
String strTime = null;
String strDate = null;
String m_parameter;
try {
pcml = new ProgramCallDocument(as400, "com.ibm.nagios.util.qgyolmsg");
int[] fieldIndex = new int[1];
// Set selection criteria value
m_parameter = "qgyolmsg.msgSelInfo.selectionCriteria";
fieldIndex[0] = 0;
pcml.setValue(m_parameter, fieldIndex, "*ALL ");
// Set message queue information for the list
m_parameter = "qgyolmsg.userOrQueueInfo.userOrQueueIndicator";
pcml.setValue(m_parameter, "1");
m_parameter = "qgyolmsg.userOrQueueInfo.userOrQueueName";
msgQueName += BLANK10.substring(msgQueName.length());
msgQueLib += BLANK10.substring(msgQueLib.length());
pcml.setValue(m_parameter, msgQueName + msgQueLib);
// Set starting message key
m_parameter = "qgyolmsg.msgSelInfo.messageKeys";
fieldIndex[0] = 0;
pcml.setValue(m_parameter, fieldIndex, 0);
fieldIndex[0] = 1;
pcml.setValue(m_parameter, fieldIndex, 65535);
// Set fields to return
int[] keyIndex;
int keyValue;
keyIndex = new int[1];
m_parameter = "qgyolmsg.msgSelInfo.fldsToReturn";
keyIndex[0] = 0;
// Message
keyValue = 301;
pcml.setIntValue(m_parameter, keyIndex, keyValue);
keyIndex[0] = 1;
// User profile
keyValue = 607;
pcml.setIntValue(m_parameter, keyIndex, keyValue);
keyIndex[0] = 2;
// Reply status
keyValue = 1001;
pcml.setIntValue(m_parameter, keyIndex, keyValue);
rc = pcml.callProgram("qgyolmsg");
if (rc == false) {
// Print out all of the AS/400 messages
AS400Message[] messageList = pcml.getMessageList("qgyolmsg");
for (int i = 0; i < messageList.length; i++) {
response.append(Constants.retrieveDataException + " - " + messageList[i].getID() + " " + messageList[i].getText());
}
return Constants.UNKNOWN;
}
// Get number messages returned
m_parameter = "qgyolmsg.listInfo.rcdsReturned";
int nbrEntries = pcml.getIntValue(m_parameter);
int[] index = new int[1];
fieldIndex = new int[2];
for (int i = 0; i < nbrEntries; i++) {
index[0] = i;
// Retrieve message ID
msgID = pcml.getStringValue("qgyolmsg.lstm0100.msgEntry.msgID", index).trim();
// Retrieve message type
type = pcml.getStringValue("qgyolmsg.lstm0100.msgEntry.msgType", index).trim();
// Retrieve sent time
strTime = pcml.getStringValue("qgyolmsg.lstm0100.msgEntry.timeSent", index);
// Retrieve sent date
strDate = pcml.getStringValue("qgyolmsg.lstm0100.msgEntry.dateSent", index).substring(1);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmss");
Date dateTime = dateFormat.parse(strDate + strTime);
// Retrieve filed number
int nbrKeyFields = pcml.getIntValue("qgyolmsg.lstm0100.msgEntry.nbrOfFields", index);
for (int j = 0; j < nbrKeyFields; j++) {
fieldIndex[0] = i;
fieldIndex[1] = j;
// Retrieve key field data
byte[] keyData = (byte[]) pcml.getValue("qgyolmsg.lstm0100.msgEntry.fieldInfo.keyData", fieldIndex);
// Retrieve field key
int dataKey = pcml.getIntValue("qgyolmsg.lstm0100.msgEntry.fieldInfo.keyField", fieldIndex);
// Retrieve data length
int dataLength = pcml.getIntValue("qgyolmsg.lstm0100.msgEntry.fieldInfo.lengthOfData", fieldIndex);
switch(dataKey) {
case 301:
// Set the message: Char(*)
if (dataLength > 0) {
AS400Text text = new AS400Text(dataLength, as400.getCcsid(), as400);
msgText = (String) text.toObject(keyData, 0);
text = null;
}
break;
case 607:
// Set the user profile: Char(*)
if (dataLength > 0) {
AS400Text text = new AS400Text(dataLength, as400.getCcsid(), as400);
user = (String) text.toObject(keyData, 0);
text = null;
}
break;
}
}
type = MESSAGE_TYPE[Integer.parseInt(type)];
if (msgType.contains(type)) {
response.append("ID: " + msgID + " Text: " + msgText + "\n");
response.append("User: " + user + " Type: " + type + " Severity: " + severity + " Time Sent: " + dateTime + "\n");
messageNum++;
}
}
returnValue = CommonUtil.getStatus(messageNum, intWarningCap, intCriticalCap, returnValue);
response.insert(0, "Message Num in type " + requireType + ": " + messageNum + "\n");
m_parameter = "qgyolmsg.listInfo.rqsHandle";
Object handle = pcml.getValue(m_parameter);
m_parameter = "qgyclst.closeHand";
pcml.setValue(m_parameter, handle);
m_parameter = "qgyclst";
pcml.callProgram("qgyclst");
} catch (Exception e) {
response.setLength(0);
response.append(Constants.retrieveDataException + " - " + e.toString());
e.printStackTrace();
}
}
return returnValue;
}
use of com.ibm.nagios.util.JDBCConnection in project nagios-for-i by IBM.
the class TempStorageJobs method execute.
public int execute(AS400 as400, Map<String, String> args, StringBuffer response) {
try {
int version = as400.getVersion();
int release = as400.getRelease();
if (version < 7 || (version >= 7 && release == 1)) {
response.append(Constants.retrieveDataError + " - " + "The service is not supported on this release");
return Constants.UNKNOWN;
}
} catch (Exception eVR) {
response.append(Constants.retrieveDataException + " - " + eVR.getMessage());
return Constants.UNKNOWN;
}
String jobCount = args.get("-N");
int jobNum = 0;
jobCount = jobCount == null ? "10" : jobCount;
String jobName = null;
String currentUser = null;
String CPUPercent = null;
String storageConsumed = null;
String maxStorage = null;
String jobStatus = null;
String subsystem = null;
String functionType = null;
String function = null;
Statement stmt = null;
ResultSet rs = null;
int returnValue = Constants.UNKNOWN;
Connection connection = null;
try {
JDBCConnection JDBCConn = new JDBCConnection();
connection = JDBCConn.getJDBCConnection(as400.getSystemName(), args.get("-U"), args.get("-P"), args.get("-SSL"));
if (connection == null) {
response.append(Constants.retrieveDataError + " - " + "Cannot get the JDBC connection");
return returnValue;
}
stmt = connection.createStatement();
rs = stmt.executeQuery("SELECT SUBSTR(JOB_NAME,8,POSSTR(SUBSTR(JOB_NAME,8),'/')-1) AS JOB_USER, SUBSTR(SUBSTR(JOB_NAME,8),POSSTR(SUBSTR(JOB_NAME,8),'/')+1) AS JOB_NAME, SUBSYSTEM, ELAPSED_CPU_PERCENTAGE, FUNCTION_TYPE, FUNCTION, JOB_STATUS, TEMPORARY_STORAGE FROM TABLE (QSYS2.ACTIVE_JOB_INFO('NO', '', '', '')) X " + "ORDER BY TEMPORARY_STORAGE DESC FETCH FIRST " + jobCount + " ROWS ONLY");
if (rs == null) {
response.append(Constants.retrieveDataError + " - " + "Cannot retrieve data from server");
return returnValue;
}
while (rs.next()) {
jobName = String.format("%-10s", rs.getString("JOB_NAME"));
currentUser = String.format("%-10s", rs.getString("JOB_USER"));
CPUPercent = rs.getString("ELAPSED_CPU_PERCENTAGE");
storageConsumed = String.format("%-4s", rs.getString("TEMPORARY_STORAGE"));
if (maxStorage == null) {
maxStorage = storageConsumed;
}
jobStatus = String.format("%-4s", rs.getString("JOB_STATUS"));
subsystem = rs.getString("SUBSYSTEM");
subsystem = String.format("%-10s", subsystem != null ? subsystem : "- ");
functionType = rs.getString("FUNCTION_TYPE");
function = rs.getString("FUNCTION");
if (functionType == null && function == null) {
function = "- ";
} else {
function = functionType + "-" + function;
}
response.append("Job: " + jobName + " Storage: " + storageConsumed + "M CPU: " + CPUPercent + " User: " + currentUser + " Status: " + jobStatus + " Subsystem: " + subsystem + " Function: " + function + "\n");
jobNum++;
}
response.insert(0, jobNum + " jobs retrieved from endpoint. Max storage=" + maxStorage + "M\n");
returnValue = Constants.OK;
} catch (Exception e) {
response.setLength(0);
response.append(Constants.retrieveDataException + " - " + e.toString());
CommonUtil.printStack(e.getStackTrace(), response);
CommonUtil.logError(args.get("-H"), this.getClass().getName(), e.getMessage());
e.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (connection != null)
connection.close();
} catch (SQLException e) {
response.append(Constants.retrieveDataException + " - " + e.toString());
}
}
return returnValue;
}
use of com.ibm.nagios.util.JDBCConnection in project nagios-for-i by IBM.
the class ActiveJobs method execute.
public int execute(AS400 as400, Map<String, String> args, StringBuffer response) {
int actJobNum = 0;
Statement stmt = null;
ResultSet rs = null;
int returnValue = Constants.UNKNOWN;
String warningCap = args.get("-W");
String criticalCap = args.get("-C");
int intWarningCap = (warningCap == null) ? 100 : Integer.parseInt(warningCap);
int intCriticalCap = (criticalCap == null) ? 100 : Integer.parseInt(criticalCap);
Connection connection = null;
try {
JDBCConnection JDBCConn = new JDBCConnection();
connection = JDBCConn.getJDBCConnection(as400.getSystemName(), args.get("-U"), args.get("-P"), args.get("-SSL"));
if (connection == null) {
response.append(Constants.retrieveDataError + " - " + "Cannot get the JDBC connection");
return returnValue;
}
stmt = connection.createStatement();
rs = stmt.executeQuery("SELECT ACTIVE_JOBS_IN_SYSTEM FROM QSYS2.SYSTEM_STATUS_INFO");
if (rs == null) {
response.append(Constants.retrieveDataError + " - " + "Cannot retrieve data from server");
return returnValue;
}
while (rs.next()) {
actJobNum = rs.getInt("ACTIVE_JOBS_IN_SYSTEM");
}
returnValue = CommonUtil.getStatus(actJobNum, intWarningCap, intCriticalCap, returnValue);
response.insert(0, "Num of Active Jobs: " + actJobNum + " | 'Num of Active Jobs' = " + actJobNum + ";" + warningCap + ";" + criticalCap);
} catch (Exception e) {
response.append(Constants.retrieveDataException + " - " + e.toString());
CommonUtil.printStack(e.getStackTrace(), response);
CommonUtil.logError(args.get("-H"), this.getClass().getName(), e.getMessage());
e.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (connection != null)
connection.close();
} catch (SQLException e) {
response.append(Constants.retrieveDataException + " - " + e.toString());
e.printStackTrace();
}
}
return returnValue;
}
use of com.ibm.nagios.util.JDBCConnection in project nagios-for-i by IBM.
the class CPU method execute.
public int execute(AS400 as400, Map<String, String> args, StringBuffer response) {
double AverageCPU = 0.;
Statement stmt = null;
ResultSet rs = null;
String warningCap = args.get("-W");
String criticalCap = args.get("-C");
double doubleWarningCap = (warningCap == null) ? 100 : Double.parseDouble(warningCap);
double doubleCriticalCap = (criticalCap == null) ? 100 : Double.parseDouble(criticalCap);
int returnValue = Constants.UNKNOWN;
Connection connection = null;
try {
JDBCConnection JDBCConn = new JDBCConnection();
connection = JDBCConn.getJDBCConnection(as400.getSystemName(), args.get("-U"), args.get("-P"), args.get("-SSL"));
if (connection == null) {
response.append(Constants.retrieveDataError + " - " + "Cannot get the JDBC connection");
return returnValue;
}
stmt = connection.createStatement();
rs = stmt.executeQuery("SELECT AVERAGE_CPU_UTILIZATION FROM QSYS2.SYSTEM_STATUS_INFO");
if (rs == null) {
response.append(Constants.retrieveDataError + " - " + "Cannot retrieve data from server");
return returnValue;
}
if (rs.next()) {
AverageCPU = rs.getDouble("AVERAGE_CPU_UTILIZATION");
returnValue = CommonUtil.getStatus(AverageCPU, doubleWarningCap, doubleCriticalCap, returnValue);
response.append("CPU Utilization = " + AverageCPU + "%" + " | 'CPU Utilization' = " + AverageCPU + "%;" + doubleWarningCap + ";" + doubleCriticalCap);
return returnValue;
}
} catch (Exception e) {
response.append(Constants.retrieveDataException + " - " + e.toString());
CommonUtil.printStack(e.getStackTrace(), response);
CommonUtil.logError(args.get("-H"), this.getClass().getName(), e.getMessage());
e.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (connection != null)
connection.close();
} catch (SQLException e) {
response.append(Constants.retrieveDataException + " - " + e.toString());
e.printStackTrace();
}
}
return returnValue;
}
Aggregations