Search in sources :

Example 1 with Action

use of com.ibm.nagios.service.Action in project nagios-for-i by IBM.

the class CheckIBMiStatus method main.

public static void main(String[] args) {
    int retValue = Constants.UNKNOWN;
    try {
        ParseArgs(args);
        socket = new Socket(Constants.SERVER, Constants.PORT);
        socket.setReuseAddress(true);
        socket.setSoLinger(true, 0);
        ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
        oos.writeObject(argsMap);
        socket.shutdownOutput();
        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String result = null;
        if ((result = br.readLine()) != null) {
            String message;
            while ((message = br.readLine()) != null) {
                System.out.println(message);
            }
            retValue = Integer.parseInt(result);
        }
    } catch (IOException e) {
        try {
            String metric = argsMap.get("-M");
            String system = argsMap.get("-H");
            Action action = ActionFactory.get(metric);
            StringBuffer response = new StringBuffer();
            if (!HostConfigInfo.load()) {
                System.err.println("load file Nagios.host.java.config.ser error");
                System.exit(retValue);
            }
            if ("HMC".equalsIgnoreCase(metric)) {
                retValue = action.execute(null, argsMap, response);
            } else {
                String user = HostConfigInfo.getUserID(system);
                String pass = HostConfigInfo.getPassword(system);
                if (user == null || pass == null) {
                    System.err.println("Host user profile not set");
                    System.exit(retValue);
                }
                String password = Base64Coder.decodeString(pass);
                argsMap.put("-U", user);
                argsMap.put("-P", password);
                AS400 as400 = null;
                String ssl = argsMap.get("-SSL");
                if (ssl != null && ssl.equalsIgnoreCase("Y")) {
                    as400 = new SecureAS400(system, user, password);
                } else {
                    as400 = new AS400(system, user, password);
                }
                as400.setGuiAvailable(false);
                as400.validateSignon();
                retValue = action.execute(as400, argsMap, response);
            }
            System.out.println(response);
        } catch (Exception e1) {
            retValue = Constants.UNKNOWN;
            e1.printStackTrace();
        }
    } finally {
        try {
            if (socket != null) {
                socket.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    System.exit(retValue);
}
Also used : Action(com.ibm.nagios.service.Action) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) IOException(java.io.IOException) SecureAS400(com.ibm.as400.access.SecureAS400) BufferedReader(java.io.BufferedReader) AS400(com.ibm.as400.access.AS400) SecureAS400(com.ibm.as400.access.SecureAS400) Socket(java.net.Socket)

Example 2 with Action

use of com.ibm.nagios.service.Action in project nagios-for-i by IBM.

the class RequestHandler method CollectStatus.

private int CollectStatus(AS400 as400, Map<String, String> args, StringBuffer response) throws Exception {
    // UNKNOW = 3
    int retVal = 3;
    String metric = args.get("-M");
    if (metric == null) {
        response.append("The argument -m is not set");
        return Constants.UNKNOWN;
    }
    String systemName = args.get("-H");
    String user = args.get("-U");
    Action action = ActionFactory.get(metric);
    retVal = action.execute(as400, args, response);
    if (as400 != null) {
        // TODO maybe need a better way to generate the key
        AS400Connection.ReturnConnectionToPool(systemName + user, as400);
    }
    return retVal;
}
Also used : Action(com.ibm.nagios.service.Action)

Example 3 with Action

use of com.ibm.nagios.service.Action in project nagios-for-i by IBM.

the class ActionFactory method get.

public static synchronized Action get(String action) throws Exception {
    String classDir = "com.ibm.nagios.service.impl";
    String className = classDir + "." + action;
    Action actionInstance = null;
    try {
        actionInstance = (Action) Class.forName(className).getConstructor(null).newInstance();
    } catch (ClassNotFoundException e) {
        className = "com.ibm.nagios.hmc.service.Impl" + "." + action;
        actionInstance = (Action) Class.forName(className).getConstructor(null).newInstance();
    }
    return actionInstance;
}
Also used : Action(com.ibm.nagios.service.Action)

Example 4 with Action

use of com.ibm.nagios.service.Action in project nagios-for-i by IBM.

the class HMC method execute.

public int execute(AS400 as400, Map<String, String> args, StringBuffer response) {
    int returnValue = Constants.UNKNOWN;
    try {
        String func = args.get("-F");
        if (func == null) {
            response.append("The argument -F [function name] is not set");
            return returnValue;
        }
        String system = args.get("-H");
        String user = HostConfigInfo.getHMCUserID(system);
        if (user == null) {
            response.append("HMC user profile not set");
            return returnValue;
        }
        String password = Base64Coder.decodeString(HostConfigInfo.getHMCPassword(system));
        args.put("-U", user);
        args.put("-P", password);
        Action action = ActionFactory.get(func);
        returnValue = action.execute(null, args, response);
        return returnValue;
    } catch (Exception e) {
        // TODO Pre-defined class not found. Load the plugin from CustomHMC.xml
        response.append(Constants.retrieveDataException + " -  " + e.toString());
        CommonUtil.printStack(e.getStackTrace(), response);
        e.printStackTrace();
    }
    return returnValue;
}
Also used : Action(com.ibm.nagios.service.Action)

Aggregations

Action (com.ibm.nagios.service.Action)4 AS400 (com.ibm.as400.access.AS400)1 SecureAS400 (com.ibm.as400.access.SecureAS400)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Socket (java.net.Socket)1