This repository was archived by the owner on Feb 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHypericCheck.java
More file actions
155 lines (131 loc) · 5.49 KB
/
HypericCheck.java
File metadata and controls
155 lines (131 loc) · 5.49 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* HypericCheck Written by Greg Walters
* Copyright (C) 2011, Contegix, LLC, www.contegix.com
*
* This is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
* About Contegix:
* Contegix provides high-level managed hosting solutions for enterprise
* applications and infrastructure. The company delivers proactive,
* passionate support that is unparalleled in the industry. All Contegix
* solutions encompass supporting dedicated hardware and operating system
* management, deploying and configuring software, and offering complete
* licensing management. Contegix\u2019s award-winning service is delivered
* by a staff of Tier-3 engineers from its global headquarters in St. Louis,
* MO. Current clients and partners include Six Apart, ReadWriteWeb, VMware
* and Atlassian. For additional information, visit www.contegix.com or call
* 1(877) 426-6834.
*/
import org.hyperic.hq.hqapi1.*;
import org.hyperic.hq.hqapi1.types.*;
import org.hyperic.hq.product.util.PluginDumper;
import org.hyperic.hq.product.ServiceTypeInfo;
import org.hyperic.hq.product.ServerTypeInfo;
import org.hyperic.util.config.ConfigResponse;
import java.io.*;
import java.util.*;
import java.util.Properties;
import java.util.ArrayList;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import org.apache.log4j.BasicConfigurator;
class HypericCheck {
public static void main(String args[]) {
ParseOptions options = new ParseOptions(args);
boolean debug = options.getDebug();
boolean has_services = options.hasServices();
boolean has_resources = options.hasResources();
String properties_file = options.getDefaultFile();
Properties sprops = System.getProperties();
Logger logger = Logger.getLogger("org.apache");
Logger logger2 = Logger.getLogger("org.hyperic.hq.product");
BasicConfigurator.configure();
if (options.getDebug()) {
Logger.getRootLogger().setLevel(Level.DEBUG);
logger2.setLevel(Level.DEBUG);
sprops.setProperty("log","DEBUG");
} else {
Logger.getRootLogger().setLevel(Level.ERROR);
logger2.setLevel(Level.ERROR);
}
GetConfig config = new GetConfig(properties_file);
sprops.setProperty("metric-collect", config.getDefaultMetrics());
sprops.setProperty("pdkDir", config.getpdkDir());
sprops.setProperty("pluginDir", config.getpluginDir());
System.setProperties(sprops);
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("dd MMM yyyy hh:mm:ss zzz");
System.out.println("#\tHypericChecker v1.0");
System.out.println("#\tStarted on " + sdf.format(cal.getTime()) + "\n");
HQApi api = new HQApi(config.getHost(), config.getPort(), config.getSecure(), config.getUser(), config.getPassword());
ResourceApi r_api = api.getResourceApi();
if (has_services) {
ArrayList<Object> services = options.getServices();
for (int i = 0; i < services.size(); i++) {
doCheck(services.get(i), r_api, sprops, true);
}
}
if (has_resources) {
ArrayList<Object> resources = options.getResources();
for (int i = 0; i < resources.size(); i++) {
doCheck(resources.get(i), r_api, sprops, false);
}
}
}
private static void doCheck(Object oid, ResourceApi r_api, Properties sprops, boolean aeid) {
int id = Integer.parseInt(oid.toString());
try {
ResourceResponse r_response = new ResourceResponse();
if (aeid) {
r_response = r_api.getResource("3:" + Integer.toString(id), true, false);
} else {
r_response = r_api.getResource(id, true, false);
}
if (!r_response.getStatus().equals(ResponseStatus.SUCCESS)) {
System.err.println("Error :" + r_response.getError().getReasonText());
System.exit(1);
}
Resource resource = r_response.getResource();
List<ResourceConfig> config = new ArrayList<ResourceConfig>();
config = resource.getResourceConfig();
ResourcePrototype type = resource.getResourcePrototype();
ConfigResponse configr = new ConfigResponse();
System.out.println("#\tResource config:");
System.out.println("**************************************");
for (int i = 0; i < config.size(); i++) {
ResourceConfig rconfig = config.get(i);
String key = rconfig.getKey();
String value = rconfig.getValue();
if ( !key.contains("service.log_") ) {
System.out.println("#\t" + key + " : " + value );
}
configr.setValue(key, value);
}
System.out.println("**************************************\n");
ServerTypeInfo serverti = new ServerTypeInfo();
ServiceTypeInfo serviceti = new ServiceTypeInfo();
PluginDumper pd = new PluginDumper(sprops.getProperty("pdkDir"), sprops.getProperty("pluginDir"));
serviceti.setServerTypeInfo(serverti);
serviceti.setName(type.getName().replace("Remote Server ", ""));
pd.init();
pd.fetchMetrics(serviceti, false, configr);
System.out.println();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}