2012-05-23 Santiago Munín <burning1@gmail.com>
* Core.java: Added a generic function which will serialize given params in order to send an API request. * PandroidEventviewerActivity.java, PandroidEventviewerService: Refactorized the serialization of parameters (now, they call Core.java function). git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6338 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
78657a6d18
commit
02ebde436f
|
@ -1,3 +1,8 @@
|
||||||
|
2012-05-23 Santiago Munín <burning1@gmail.com>
|
||||||
|
|
||||||
|
* Core.java: Added a generic function which will serialize given params in order to send an API request.
|
||||||
|
* PandroidEventviewerActivity.java, PandroidEventviewerService: Refactorized the serialization of parameters (now, they call Core.java function).
|
||||||
|
|
||||||
2012-05-22 Santiago Munín <burning1@gmail.com>
|
2012-05-22 Santiago Munín <burning1@gmail.com>
|
||||||
|
|
||||||
* PandroidEventviewerService.java, PandroidEventviewerActivity.java: Added group filter.
|
* PandroidEventviewerService.java, PandroidEventviewerActivity.java: Added group filter.
|
||||||
|
|
|
@ -168,9 +168,9 @@ public class Core {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts chosen time from spinner to seconds (either are seconds or not)
|
* Converts max event age chosen from spinner to seconds (either are seconds or not)
|
||||||
*
|
*
|
||||||
* @return
|
* @return Time in milliseconds.
|
||||||
*/
|
*/
|
||||||
private static int convertRefreshTimeKeyToTime(Context ctx) {
|
private static int convertRefreshTimeKeyToTime(Context ctx) {
|
||||||
int returnvar = 60 * 10;
|
int returnvar = 60 * 10;
|
||||||
|
@ -243,4 +243,19 @@ public class Core {
|
||||||
|
|
||||||
return returnvar * 1000;
|
return returnvar * 1000;
|
||||||
}
|
}
|
||||||
}
|
/**
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String serializeParams2Api(String[] params) {
|
||||||
|
String return_var = params[0];
|
||||||
|
|
||||||
|
for (int i = 1; i < params.length; i++) {
|
||||||
|
return_var+= "|" + params[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i(TAG + " serializeParams2Api", return_var);
|
||||||
|
return return_var;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -247,49 +247,32 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes all params.
|
* Serializes all parameters.
|
||||||
* @param total True if only want the count
|
*
|
||||||
* @return All params in a string.
|
* @param total
|
||||||
|
* True if only want the count
|
||||||
|
* @return All parameters in a string.
|
||||||
*/
|
*/
|
||||||
private String serializeParams2Api(boolean total) {
|
private String serializeParams2Api(boolean total) {
|
||||||
String return_var = "";
|
String totalStr = (total) ? "total" : "-1";
|
||||||
|
if (!total) {
|
||||||
return_var += ';'; // Separator for the csv
|
totalStr = "-1";
|
||||||
return_var += "|";
|
|
||||||
return_var += Integer.toString(this.severity); // Criticity or severity
|
|
||||||
return_var += "|";
|
|
||||||
return_var += this.agentNameStr; // The agent name
|
|
||||||
return_var += "|";
|
|
||||||
return_var += ""; // Name of module
|
|
||||||
return_var += "|";
|
|
||||||
return_var += ""; // Name of alert template
|
|
||||||
return_var += "|";
|
|
||||||
return_var += ""; // Id user
|
|
||||||
return_var += "|";
|
|
||||||
return_var += Long.toString(this.timestamp); // The minimun timestamp
|
|
||||||
return_var += "|";
|
|
||||||
return_var += ""; // The maximum timestamp
|
|
||||||
return_var += "|";
|
|
||||||
return_var += this.status; // The status
|
|
||||||
return_var += "|";
|
|
||||||
return_var += this.eventSearch; // The free search in the text event
|
|
||||||
// description.
|
|
||||||
return_var += "|";
|
|
||||||
return_var += Integer.toString(this.pagination); // The pagination of
|
|
||||||
// list events
|
|
||||||
return_var += "|";
|
|
||||||
return_var += Long.toString(this.offset); // The offset of list events
|
|
||||||
return_var += "|";
|
|
||||||
if (total) {
|
|
||||||
return_var+="total";
|
|
||||||
} else {
|
|
||||||
return_var+="-1";
|
|
||||||
}
|
}
|
||||||
return_var += "|";
|
return Core.serializeParams2Api(new String[] { ";", // Separator
|
||||||
return_var += Integer.toString(this.id_group);
|
Integer.toString(this.severity), // Severity
|
||||||
Log.i(TAG + " serializeParams2Api", return_var);
|
this.agentNameStr, // Agent name
|
||||||
|
"", // Module
|
||||||
return return_var;
|
"", // Alert template
|
||||||
|
"", // Id user
|
||||||
|
Long.toString(this.timestamp), // Minimum timestamp,
|
||||||
|
"", // Maximum timestamp
|
||||||
|
String.valueOf(this.status), // Status
|
||||||
|
this.eventSearch, // Search in event description
|
||||||
|
String.valueOf(this.pagination), // Pagination
|
||||||
|
String.valueOf(this.offset), // Event list offset
|
||||||
|
totalStr, // Count or show
|
||||||
|
String.valueOf(this.id_group) // Group id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -98,8 +98,8 @@ public class PandroidEventviewerService extends IntentService {
|
||||||
&& (url.length() == 0)) {
|
&& (url.length() == 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
DefaultHttpClient httpClient = new DefaultHttpClient();
|
||||||
UrlEncodedFormEntity entity;
|
UrlEncodedFormEntity entity;
|
||||||
HttpPost httpPost;
|
HttpPost httpPost;
|
||||||
|
@ -110,7 +110,8 @@ public class PandroidEventviewerService extends IntentService {
|
||||||
|
|
||||||
httpPost = new HttpPost(this.url + "/include/api.php");
|
httpPost = new HttpPost(this.url + "/include/api.php");
|
||||||
|
|
||||||
String parametersAPI = serializeParams2Api(context, false);
|
String parametersAPI = serializeParams2Api(context, true, false, false);
|
||||||
|
Log.d(TAG, "Parameters checking new events: " + parametersAPI);
|
||||||
|
|
||||||
// Get total count.
|
// Get total count.
|
||||||
parameters = new ArrayList<NameValuePair>();
|
parameters = new ArrayList<NameValuePair>();
|
||||||
|
@ -121,8 +122,7 @@ public class PandroidEventviewerService extends IntentService {
|
||||||
parameters.add(new BasicNameValuePair("other_mode",
|
parameters.add(new BasicNameValuePair("other_mode",
|
||||||
"url_encode_separator_|"));
|
"url_encode_separator_|"));
|
||||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||||
parameters.add(new BasicNameValuePair("other", parametersAPI
|
parameters.add(new BasicNameValuePair("other", parametersAPI));
|
||||||
+ "|total"));
|
|
||||||
entity = new UrlEncodedFormEntity(parameters);
|
entity = new UrlEncodedFormEntity(parameters);
|
||||||
httpPost.setEntity(entity);
|
httpPost.setEntity(entity);
|
||||||
response = httpClient.execute(httpPost);
|
response = httpClient.execute(httpPost);
|
||||||
|
@ -136,6 +136,7 @@ public class PandroidEventviewerService extends IntentService {
|
||||||
|
|
||||||
// Check the event more critical
|
// Check the event more critical
|
||||||
if (this.count_events != 0) {
|
if (this.count_events != 0) {
|
||||||
|
Log.i(TAG, "There are new events");
|
||||||
parameters = new ArrayList<NameValuePair>();
|
parameters = new ArrayList<NameValuePair>();
|
||||||
parameters.add(new BasicNameValuePair("user", this.user));
|
parameters.add(new BasicNameValuePair("user", this.user));
|
||||||
parameters
|
parameters
|
||||||
|
@ -147,7 +148,7 @@ public class PandroidEventviewerService extends IntentService {
|
||||||
parameters
|
parameters
|
||||||
.add(new BasicNameValuePair("return_type", "csv"));
|
.add(new BasicNameValuePair("return_type", "csv"));
|
||||||
parameters.add(new BasicNameValuePair("other",
|
parameters.add(new BasicNameValuePair("other",
|
||||||
parametersAPI + "|more_criticity"));
|
serializeParams2Api(context, false, true, true)));
|
||||||
entity = new UrlEncodedFormEntity(parameters);
|
entity = new UrlEncodedFormEntity(parameters);
|
||||||
httpPost.setEntity(entity);
|
httpPost.setEntity(entity);
|
||||||
response = httpClient.execute(httpPost);
|
response = httpClient.execute(httpPost);
|
||||||
|
@ -156,7 +157,6 @@ public class PandroidEventviewerService extends IntentService {
|
||||||
.getContent());
|
.getContent());
|
||||||
return_api = return_api.replace("\n", "");
|
return_api = return_api.replace("\n", "");
|
||||||
this.more_criticity = new Integer(return_api).intValue();
|
this.more_criticity = new Integer(return_api).intValue();
|
||||||
|
|
||||||
notificationEvent(context);
|
notificationEvent(context);
|
||||||
} else {
|
} else {
|
||||||
this.more_criticity = -1;
|
this.more_criticity = -1;
|
||||||
|
@ -182,9 +182,15 @@ public class PandroidEventviewerService extends IntentService {
|
||||||
* Builds an api call from all filter parameters
|
* Builds an api call from all filter parameters
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @return Api call.
|
* @param total
|
||||||
|
* Activate if you want don't want to get details, but a count.
|
||||||
|
* @param more_criticity
|
||||||
|
* Activate if you want to get the more critical level of events.
|
||||||
|
* <b>NOTE:</b> Only one can be activated at once.
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public String serializeParams2Api(Context context, boolean total) {
|
public String serializeParams2Api(Context context, boolean total,
|
||||||
|
boolean more_criticity, boolean updateTime) {
|
||||||
SharedPreferences preferences = context.getSharedPreferences(
|
SharedPreferences preferences = context.getSharedPreferences(
|
||||||
context.getString(R.string.const_string_preferences),
|
context.getString(R.string.const_string_preferences),
|
||||||
Activity.MODE_PRIVATE);
|
Activity.MODE_PRIVATE);
|
||||||
|
@ -192,6 +198,7 @@ public class PandroidEventviewerService extends IntentService {
|
||||||
String filterAgentName = preferences.getString("filterAgentName", "");
|
String filterAgentName = preferences.getString("filterAgentName", "");
|
||||||
|
|
||||||
int idGroup = preferences.getInt("filterIDGroup", 0);
|
int idGroup = preferences.getInt("filterIDGroup", 0);
|
||||||
|
Log.d(TAG, "idGroup: " + idGroup);
|
||||||
int filterSeverity = preferences.getInt("filterSeverity", -1);
|
int filterSeverity = preferences.getInt("filterSeverity", -1);
|
||||||
int filterStatus = preferences.getInt("filterStatus", 3);
|
int filterStatus = preferences.getInt("filterStatus", 3);
|
||||||
String filterEventSearch = preferences.getString("filterEventSearch",
|
String filterEventSearch = preferences.getString("filterEventSearch",
|
||||||
|
@ -200,11 +207,13 @@ public class PandroidEventviewerService extends IntentService {
|
||||||
Calendar c = Calendar.getInstance();
|
Calendar c = Calendar.getInstance();
|
||||||
long now = (c.getTimeInMillis() / 1000);
|
long now = (c.getTimeInMillis() / 1000);
|
||||||
long filterTimestamp = preferences.getLong("filterTimestamp", now);
|
long filterTimestamp = preferences.getLong("filterTimestamp", now);
|
||||||
|
if (updateTime) {
|
||||||
SharedPreferences.Editor editorPreferences = preferences.edit();
|
SharedPreferences.Editor editorPreferences = preferences.edit();
|
||||||
// Save for the next execution
|
// Save for the next execution
|
||||||
editorPreferences.putLong("filterTimestamp", now);
|
editorPreferences.putLong("filterTimestamp", now);
|
||||||
// Save the previous for the list.
|
// Save the previous for the list.
|
||||||
editorPreferences.putLong("previous_filterTimestamp", filterTimestamp);
|
editorPreferences.putLong("previous_filterTimestamp",
|
||||||
|
filterTimestamp);
|
||||||
if (editorPreferences.commit()) {
|
if (editorPreferences.commit()) {
|
||||||
Log.i(TAG + " (filter options)",
|
Log.i(TAG + " (filter options)",
|
||||||
"Configuration changes commited (timestamp)");
|
"Configuration changes commited (timestamp)");
|
||||||
|
@ -212,51 +221,28 @@ public class PandroidEventviewerService extends IntentService {
|
||||||
Log.e(TAG + " (filter options)",
|
Log.e(TAG + " (filter options)",
|
||||||
"Configuration changes not commited");
|
"Configuration changes not commited");
|
||||||
}
|
}
|
||||||
|
|
||||||
String return_var = "";
|
|
||||||
|
|
||||||
return_var += ';'; // Separator for the csv
|
|
||||||
return_var += "|";
|
|
||||||
return_var += Integer.toString(filterSeverity); // Criticity or severity
|
|
||||||
return_var += "|";
|
|
||||||
return_var += filterAgentName; // The agent name
|
|
||||||
return_var += "|";
|
|
||||||
return_var += ""; // Name of module
|
|
||||||
return_var += "|";
|
|
||||||
return_var += ""; // Name of alert template
|
|
||||||
return_var += "|";
|
|
||||||
return_var += ""; // Id user
|
|
||||||
return_var += "|";
|
|
||||||
return_var += Long.toString(filterTimestamp); // The minimun timestamp
|
|
||||||
return_var += "|";
|
|
||||||
return_var += ""; // The maximum timestamp
|
|
||||||
return_var += "|";
|
|
||||||
return_var += filterStatus; // The status
|
|
||||||
return_var += "|";
|
|
||||||
return_var += filterEventSearch; // The free search in the text event
|
|
||||||
// description.
|
|
||||||
return_var += "|";
|
|
||||||
return_var += Integer.toString(100); // The pagination of list events
|
|
||||||
return_var += "|";
|
|
||||||
return_var += Long.toString(0); // The offset of list events
|
|
||||||
return_var += "|";
|
|
||||||
if (total) {
|
|
||||||
return_var += "total";
|
|
||||||
} else {
|
|
||||||
return_var += "-1";
|
|
||||||
}
|
}
|
||||||
return_var += "|";
|
String totalStr = (total) ? "total" : "-1";
|
||||||
return_var += Integer.toString(idGroup);
|
if (more_criticity) {
|
||||||
|
totalStr = "more_criticity";
|
||||||
Log.i(TAG + " serializeParams2Api", return_var);
|
}
|
||||||
|
return Core.serializeParams2Api(new String[] { ";", // Separator for the
|
||||||
return return_var;
|
// csv
|
||||||
//;|-1|||||1337666333||3||20|0|total|-1
|
Integer.toString(filterSeverity), // Criticity or severity
|
||||||
//;|-1|||||1337695530||3||0 |0| |12
|
filterAgentName, // The agent name
|
||||||
//;|-1|||||1337695739||3||0 |0|-1 |2
|
"", // Name of module
|
||||||
//;|-1|||||1337666333||3||20|0|-1 |2
|
"", // Name of alert template
|
||||||
//;|-1|||||1337695739||3||0 |0|-1 |12
|
"", // Id user
|
||||||
//;|-1|||||1337666333||3||20|0|-1|-1
|
Long.toString(filterTimestamp), // The minimun timestamp
|
||||||
|
"", // The maximum timestamp
|
||||||
|
String.valueOf(filterStatus), // The status
|
||||||
|
filterEventSearch, // The free search in the text event
|
||||||
|
// description.
|
||||||
|
Integer.toString(20), // The pagination of list events
|
||||||
|
Long.toString(0), // The offset of list events
|
||||||
|
totalStr, // Count or show
|
||||||
|
Integer.toString(idGroup), // Group ID
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue