Search in sources :

Example 1 with UserInfo

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

the class HostConfig method ListAll.

@SuppressWarnings("rawtypes")
private static void ListAll() {
    try {
        load();
        Iterator iter = hosts.entrySet().iterator();
        System.out.println("Host profiles:");
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            String host = (String) entry.getKey();
            UserInfo userInfo = (UserInfo) entry.getValue();
            System.out.println(host + "  " + userInfo.getUser());
        }
        iter = sst.entrySet().iterator();
        System.out.println("\nSST profiles:");
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            String host = (String) entry.getKey();
            UserInfo userInfo = (UserInfo) entry.getValue();
            System.out.println(host + "  " + userInfo.getUser());
        }
        iter = hmc.entrySet().iterator();
        System.out.println("\nHMC profiles:");
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            String host = (String) entry.getKey();
            UserInfo userInfo = (UserInfo) entry.getValue();
            System.out.println(host + "  " + userInfo.getUser());
        }
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}
Also used : Iterator(java.util.Iterator) UserInfo(com.ibm.nagios.config.util.UserInfo) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException)

Example 2 with UserInfo

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

the class HostConfigInfo method load.

public static boolean load() {
    try {
        HostConfig.load();
        hosts = HostConfig.getHosts();
        sst = HostConfig.getSST();
        hmc = HostConfig.getHMC();
        // bulk load: load profile information from profile.csv
        File customUserProfile = new File(CUST_PROFILE);
        if (customUserProfile.isFile() && customUserProfile.exists()) {
            InputStreamReader read = new InputStreamReader(new FileInputStream(customUserProfile), "UTF-8");
            BufferedReader bufferedReader = new BufferedReader(read);
            String line = null;
            String system = null;
            String user = null;
            String pwd = null;
            String type = null;
            while ((line = bufferedReader.readLine()) != null) {
                line = line.trim();
                if (line.startsWith("#") == true) {
                    continue;
                }
                String[] elem = line.split("[,;]");
                if (elem.length != 4) {
                    System.err.println("HostConfig-load(): bad format of profile.csv");
                    bufferedReader.close();
                    // DO NOT let the loading failure stop the server initialization
                    return true;
                }
                system = elem[0];
                user = elem[1];
                pwd = elem[2];
                type = elem[3];
                if (type.equalsIgnoreCase("host")) {
                    hosts.put(system, new UserInfo(user, Base64Coder.encodeString(pwd)));
                } else if (type.equalsIgnoreCase("sst")) {
                    sst.put(system, new UserInfo(user, Base64Coder.encodeString(pwd)));
                } else if (type.equalsIgnoreCase("hmc")) {
                    hmc.put(system, new UserInfo(user, Base64Coder.encodeString(pwd)));
                }
            }
            HostConfig.save();
            bufferedReader.close();
        }
        return true;
    } catch (Exception e) {
        System.err.println("HostConfig-load(): " + e.toString());
    }
    return false;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UserInfo(com.ibm.nagios.config.util.UserInfo) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with UserInfo

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

the class HostConfig method Insert.

private static boolean Insert(String hostAddr, String userID, String password, String type) {
    try {
        if (type.equalsIgnoreCase("host")) {
            AS400 as400 = new AS400(hostAddr, userID, password);
            SocketProperties socketProps = new SocketProperties();
            // set timeout to 15 seconds
            socketProps.setLoginTimeout(15000);
            as400.setSocketProperties(socketProps);
            as400.setGuiAvailable(false);
            try {
                as400.validateSignon();
            } catch (Exception e) {
                System.out.println(e.toString());
                return false;
            }
        }
        if (load()) {
            if (type.equalsIgnoreCase("host")) {
                hosts.put(hostAddr, new UserInfo(userID, Base64Coder.encodeString(password)));
            } else if (type.equalsIgnoreCase("sst")) {
                sst.put(hostAddr, new UserInfo(userID, Base64Coder.encodeString(password)));
            } else if (type.equalsIgnoreCase("hmc")) {
                hmc.put(hostAddr, new UserInfo(userID, Base64Coder.encodeString(password)));
            }
            if (save()) {
                refreshProfile();
                return true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.toString());
        for (StackTraceElement ele : e.getStackTrace()) {
            System.out.println(ele);
        }
    }
    return false;
}
Also used : AS400(com.ibm.as400.access.AS400) UserInfo(com.ibm.nagios.config.util.UserInfo) SocketProperties(com.ibm.as400.access.SocketProperties) IOException(java.io.IOException)

Example 4 with UserInfo

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

the class HostConfig method load.

@SuppressWarnings("unchecked")
public static boolean load() throws IOException, ClassNotFoundException {
    File file = new File(NEW_DIRECTORY + FILENAME);
    if (!file.exists()) {
        File dir = new File(NEW_DIRECTORY);
        if (!dir.exists() && !dir.isDirectory()) {
            System.out.println("The directory " + NEW_DIRECTORY + "doesn't exist");
            return false;
        }
        file.createNewFile();
        // if the old ser file exists, copy the content to new ser file
        File oldFile = new File(OLD_DIRECTORY + FILENAME);
        if (oldFile.exists()) {
            InputStream bis = new BufferedInputStream(new FileInputStream(oldFile));
            GZIPInputStream gzis = new GZIPInputStream(bis);
            ObjectInputStream ois = new ObjectInputStream(gzis);
            cache = (HashMap<String, HashMap<String, UserInfo>>) ois.readObject();
            hosts = cache.get("host");
            sst = cache.get("sst");
            hmc = cache.get("hmc");
            ois.close();
        }
        save();
        // set authority to 666
        file.setReadable(true, false);
        file.setWritable(true, false);
        file.setExecutable(false, false);
    }
    InputStream bis = new BufferedInputStream(new FileInputStream(file));
    GZIPInputStream gzis = new GZIPInputStream(bis);
    ObjectInputStream ois = new ObjectInputStream(gzis);
    cache = (HashMap<String, HashMap<String, UserInfo>>) ois.readObject();
    hosts = cache.get("host");
    sst = cache.get("sst");
    hmc = cache.get("hmc");
    if (hosts == null) {
        hosts = new HashMap<String, UserInfo>();
    }
    if (sst == null) {
        sst = new HashMap<String, UserInfo>();
    }
    if (hmc == null) {
        hmc = new HashMap<String, UserInfo>();
    }
    ois.close();
    return true;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) HashMap(java.util.HashMap) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) UserInfo(com.ibm.nagios.config.util.UserInfo) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

UserInfo (com.ibm.nagios.config.util.UserInfo)4 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 AS400 (com.ibm.as400.access.AS400)1 SocketProperties (com.ibm.as400.access.SocketProperties)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ObjectInputStream (java.io.ObjectInputStream)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 GZIPInputStream (java.util.zip.GZIPInputStream)1