-
Notifications
You must be signed in to change notification settings - Fork 20
/
HostConfigInfo.java
executable file
·120 lines (109 loc) · 4.25 KB
/
HostConfigInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.ibm.nagios.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import com.ibm.nagios.config.HostConfig;
import com.ibm.nagios.config.util.Base64Coder;
import com.ibm.nagios.config.util.UserInfo;
/*
* load the info of file Nagios.host.java.config.ser
*/
public class HostConfigInfo {
private final static String CUST_PROFILE = "/usr/local/nagios/var/profile.csv";
private static HashMap<String, UserInfo> hosts = null;
private static HashMap<String, UserInfo> sst = null;
private static HashMap<String, UserInfo> hmc = null;
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();
return true;//DO NOT let the loading failure stop the server initialization
}
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;
}
public static String getUserID(String system) {
UserInfo userInfo = hosts.get(system);
if (userInfo != null)
return userInfo.getUser();
else
return null;
}
public static String getPassword(String system) {
UserInfo userInfo = hosts.get(system);
if (userInfo != null)
return userInfo.getPassword();
else
return null;
}
public static String getSSTUserID(String system) {
UserInfo userInfo = sst.get(system);
if (userInfo != null)
return userInfo.getUser();
else
return null;
}
public static String getSSTPassword(String system) {
UserInfo userInfo = sst.get(system);
if (userInfo != null)
return userInfo.getPassword();
else
return null;
}
public static String getHMCUserID(String system) {
UserInfo userInfo = hmc.get(system);
if (userInfo != null)
return userInfo.getUser();
else
return null;
}
public static String getHMCPassword(String system) {
UserInfo userInfo = hmc.get(system);
if (userInfo != null)
return userInfo.getPassword();
else
return null;
}
}