CollNginx.java
3.69 KB
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
package com.sitech.ismp.coll.middleware.nginx;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
import com.sitech.util.DES3;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Vector;
/**
* Created with IntelliJ IDEA.
* User: mooker
* Date: 14-7-4
* Time: 上午10:05
* To change this template use File | Settings | File Templates.
*/
public class CollNginx implements CollNginxMBean {
@Override
public Vector<TblATO_KPIDETAIL> getConfig(HashMap<String, String> params) {
CollNginxWithCMD coll = new CollNginxWithCMD();
return coll.getConfig(params);
}
@Override
public Vector<TblATO_KPIDETAIL> getPerfor(HashMap<String, String> params) {
CollNginxWithCMD coll = new CollNginxWithCMD();
return coll.getPerfor(params);
}
public static void main(String[] args) {
System.out.println("***************Nginx Collect Test Begin*********************");
/* String ipAddr = "172.21.0.203";
String username = "ssdbomc";
String password = "bomcssd";
String prototal = "ssh";
String deviceName = "csdppdnginx";
String statusUrl = "nginx_status";
String nginxPort = "90";*/
String ipAddr = "10.243.29.26";
String username = "cloud";
String password = "cloud1234!";
String prototal = "ssh";
String deviceName = "cobbler";
String statusUrl = "NginxStatus";
String nginxPort = "8091";
String methodStr = "2";
// String ipAddr = read("IP_ADDR(remote host ip):\n");
// String username = read("USERNAME:\n");
// String password = read("PASSWORD:\n");
// String prototal = read("PROTOTAL(ssh/telent):\n");
// String deviceName = read("DEVICENAME(nginx name):\n");
// String statusUrl = read("STATUSURL(status http request):\n");
// String methodStr = read("METHOD(0:getAll, 1:getConfig, 2:getPerfor):\n");
System.out.println("IP_ADDR=" + ipAddr + ", USERNAME=" + username
+ ", PASSWORD=" + password + ", PROTOTAL=" + prototal
+ ", DEVICENAME=" + deviceName + ", METHOD=" + methodStr);
HashMap<String, String> params = new HashMap<String, String>();
params.put("IP_ADDR", ipAddr);
params.put("USERNAME", username);
params.put("PASSWORD", DES3.encrypt(password));
params.put("PROTOCOL", prototal);
params.put("DEVICENAME", deviceName);
params.put("STATUSURL", statusUrl);
params.put("NGINXPORT", nginxPort);
// params.put("AUTHNAME", "zy");
// params.put("AUTHPASS", "zy2015");
int method = Integer.parseInt(methodStr);
Vector<TblATO_KPIDETAIL> result = new Vector<TblATO_KPIDETAIL>();
CollNginx collector = new CollNginx();
switch (method) {
case 0:
result.addAll(collector.getConfig(params));
result.addAll(collector.getPerfor(params));
break;
case 1:
result.addAll(collector.getConfig(params));
break;
case 2:
result.addAll(collector.getPerfor(params));
break;
default:
break;
}
System.out.println("***************Nginx Collect Test End*********************");
for (int i = 0; i < result.size(); i++) {
TblATO_KPIDETAIL record = (TblATO_KPIDETAIL) result.get(i);
System.out.println(record.UNIT_ID + "\t" + record.KPI_ID + "\t" + record.KPI_VALUE);
}
}
private static String read(String prompt) {
Scanner scanner = new Scanner(System.in);
System.out.print(prompt);
return scanner.nextLine();
}
}