Search in sources :

Example 1 with AS400Connection

use of com.ibm.nagios.util.AS400Connection in project nagios-for-i by IBM.

the class ConnectToSystem method run.

@SuppressWarnings("unchecked")
public void run() {
    StringBuffer response = new StringBuffer();
    int retval = Constants.UNKNOWN;
    HashMap<String, String> args = new HashMap<String, String>();
    try {
        InputStream is = socket.getInputStream();
        ObjectInputStream ois = new ObjectInputStream(is);
        args = (HashMap<String, String>) ois.readObject();
        String systemName = args.get("-H");
        String metric = args.get("-M");
        if (systemName == null) {
            if (metric.equalsIgnoreCase("DaemonServer")) {
                // check daemon server status
                CheckIBMiStatus check = new CheckIBMiStatus(null, args);
                retval = check.run(response);
            } else if (metric.equalsIgnoreCase("RefreshProfile")) {
                // reload HostConfigInfo
                HostConfigInfo.load();
            }
        } else if (metric.equalsIgnoreCase("HMC")) {
            CheckIBMiStatus check = new CheckIBMiStatus(null, args);
            retval = check.run(response);
        } else {
            // check IBM i status
            // load user profile and password from Nagios.host.java.config.ser
            String user = HostConfigInfo.getUserID(systemName);
            String pass = HostConfigInfo.getPassword(systemName);
            if (user == null || pass == null) {
                response.append("Host user profile not set");
                return;
            }
            String password = Base64Coder.decodeString(pass);
            args.put("-U", user);
            args.put("-P", password);
            AS400Connection as400Conn = new AS400Connection();
            AS400 as400 = as400Conn.getAS400Object(systemName, user, password, response, args.get("-SSL"));
            if (as400 == null) {
                response.append("\nConnectToSystem - run(): as400 is null");
            } else {
                as400.setGuiAvailable(false);
                // Server.metricPool.execute(new CheckIBMiStatus(as400, socket, args));
                CheckIBMiStatus check = new CheckIBMiStatus(as400, args);
                retval = check.run(response);
            }
        }
    } 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 {
            PrintResponse(retval, response);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        response = null;
    }
}
Also used : AS400Connection(com.ibm.nagios.util.AS400Connection) HashMap(java.util.HashMap) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) AS400(com.ibm.as400.access.AS400) IOException(java.io.IOException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

AS400 (com.ibm.as400.access.AS400)1 AS400Connection (com.ibm.nagios.util.AS400Connection)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 HashMap (java.util.HashMap)1