/
AlertApi.java
256 lines (235 loc) · 9.47 KB
/
AlertApi.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
*
* NOTE: This copyright does *not* cover user programs that use HQ
* program services by normal system calls through the application
* program interfaces provided as part of the Hyperic Plug-in Development
* Kit or the Hyperic Client Development Kit - this is merely considered
* normal use of the program, and does *not* fall under the heading of
* "derived work".
*
* Copyright (C) [2008, 2009], Hyperic, Inc.
* This file is part of HQ.
*
* HQ 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.
*
*/
package org.hyperic.hq.hqapi1;
import org.hyperic.hq.hqapi1.types.Resource;
import org.hyperic.hq.hqapi1.types.StatusResponse;
import org.hyperic.hq.hqapi1.types.AlertsResponse;
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
/**
* The Hyperic HQ Alert API.
* <br><br>
* This class provides access to the alerts within the HQ system. Each of the
* methods in this class return {@link org.hyperic.hq.hqapi1.types.Response}
* objects that wrap the result of the method with a
* {@link org.hyperic.hq.hqapi1.types.ResponseStatus} and a
* {@link org.hyperic.hq.hqapi1.types.ServiceError} that indicates the error
* if the response status is {@link org.hyperic.hq.hqapi1.types.ResponseStatus#FAILURE}.
*/
public class AlertApi extends BaseApi {
AlertApi(HQConnection conn) {
super(conn);
}
/**
* Find Alerts in the system.
*
* @param begin The beginning of the time window in epoch-millis.
* @param end The end of the time window in epoch-millis.
* @param count The maximum number of Alert instances to return.
* @param severity The minimum severity to query. 1 = LOW, 2 = MEDIUM, 3 = HIGH
* @param inEscalation If true, only return Alerts which are in Escalation
* @param notFixed If true, only return Alerts which are not fixed.
*
* @return On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
* a list of Alerts are returned via
* {@link org.hyperic.hq.hqapi1.types.AlertsResponse#getAlert()}.
*
* @throws IOException If a network error occurs while making the request.
*/
public AlertsResponse findAlerts(long begin, long end, int count,
int severity, Boolean inEscalation,
Boolean notFixed)
throws IOException
{
Map<String,String[]> params = new HashMap<String,String[]>();
params.put("begin", new String[] { Long.toString(begin)});
params.put("end", new String[] { Long.toString(end)});
params.put("count", new String[] { Integer.toString(count)});
params.put("severity", new String[] { Integer.toString(severity)});
if (inEscalation != null) {
params.put("inEscalation", new String[] { Boolean.toString(inEscalation)});
}
if (notFixed != null) {
params.put("notFixed", new String[] { Boolean.toString(notFixed)});
}
return doGet("alert/find.hqu", params, AlertsResponse.class);
}
/**
* Find Alerts for the given Resource.
*
* @param r The Resource to query for alerts.
* @param begin The beginning of the time window in epoch-millis.
* @param end The end of the time window in epoch-millis.
* @param count The maximum number of Alert instances to return.
* @param severity The minimum severity to query. 1 = LOW, 2 = MEDIUM, 3 = HIGH
* @param inEscalation If true, only return Alerts which are in Escalation
* @param notFixed If true, only return Alerts which are not fixed.
*
* @return On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
* a list of Alerts are returned via
* {@link org.hyperic.hq.hqapi1.types.AlertsResponse#getAlert()}.
*
* @throws IOException If a network error occurs while making the request.
*/
public AlertsResponse findAlerts(Resource r, long begin, long end,
int count, int severity,
Boolean inEscalation,
Boolean notFixed)
throws IOException
{
Map<String,String[]> params = new HashMap<String,String[]>();
params.put("resourceId", new String[] { Integer.toString(r.getId())});
params.put("begin", new String[] { Long.toString(begin)});
params.put("end", new String[] { Long.toString(end)});
params.put("count", new String[] { Integer.toString(count)});
params.put("severity", new String[] {Integer.toString(severity)});
if (inEscalation != null) {
params.put("inEscalation", new String[] { Boolean.toString(inEscalation)});
}
if (notFixed != null) {
params.put("notFixed", new String[] { Boolean.toString(notFixed)});
}
return doGet("alert/findByResource.hqu", params, AlertsResponse.class);
}
/**
* Fix an Alert
*
* @param alertId The id of the Alert to fix.
*
* @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
* if the Alert was successfully fixed.
*
* @throws IOException If a network error occurs while making the request.
*/
public StatusResponse fixAlert(Integer alertId)
throws IOException
{
return fixAlerts(new Integer[] { alertId });
}
/**
* Fix multiple Alerts
*
* @param alertIds An array of Alert id's to fix.
*
* @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
* if the Alert was successfully fixed.
*
* @throws IOException If a network error occurs while making the request.
*/
public StatusResponse fixAlerts(Integer[] alertIds)
throws IOException
{
Map<String,String[]> params = new HashMap<String,String[]>();
String[] ids = new String[alertIds.length];
for (int i = 0; i < alertIds.length; i++) {
ids[i] = Integer.toString(alertIds[i]);
}
params.put("id", ids);
return doGet("alert/fix.hqu", params, StatusResponse.class);
}
/**
* Acknowledge an Alert
*
* @param alertId The id of the Alert to acknowledge.
* @param reason The reason for acknowledgement.
* @param pause If not null, pause the Escalation for the specified number
* of milliseconds.
*
* @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
* if the Alert was successfully acknowledged.
*
* @throws IOException If a network error occurs while making the request.
*/
public StatusResponse ackAlert(Integer alertId, String reason, Long pause)
throws IOException
{
return ackAlerts(new Integer[] { alertId }, reason, pause);
}
/**
* Acknowledge multiple Alerts
*
* @param alertIds An array of Alert id's to acknowledge.
* @param reason The reason for acknowledgement.
* @param pause If not null, pause the Escalation for the specified number
* of milliseconds.
*
* @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
* if the Alert was successfully acknowledged.
*
* @throws IOException If a network error occurs while making the request.
*/
public StatusResponse ackAlerts(Integer[] alertIds, String reason, Long pause)
throws IOException
{
Map<String,String[]> params = new HashMap<String,String[]>();
String[] ids = new String[alertIds.length];
for (int i = 0; i < alertIds.length; i++) {
ids[i] = Integer.toString(alertIds[i]);
}
params.put("id", ids);
params.put("reason", new String[] { reason });
params.put("pause", new String[] { Long.toString(pause)});
return doGet("alert/ack.hqu", params, StatusResponse.class);
}
/**
* Delete an Alert
*
* @param alertId An array of Alert id's to delete.
*
* @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
* if the Alert was successfully deleted.
*
* @throws IOException If a network error occurs while making the request.
*/
public StatusResponse delete(Integer alertId)
throws IOException
{
return delete(new Integer[] { alertId});
}
/**
* Delete multiple Alerts
*
* @param alertIds An array of Alert id's to delete.
*
* @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
* if the Alert was successfully deleted.
*
* @throws IOException If a network error occurs while making the request.
*/
public StatusResponse delete(Integer[] alertIds)
throws IOException
{
Map<String,String[]> params = new HashMap<String,String[]>();
String[] ids = new String[alertIds.length];
for (int i = 0; i < alertIds.length; i++) {
ids[i] = Integer.toString(alertIds[i]);
}
params.put("id", ids);
return doGet("alert/delete.hqu", params, StatusResponse.class);
}
}