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());
}
}
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;
}
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;
}
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;
}
Aggregations