2012-07-14 Santiago Munín <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java: Now uses the new getEvents() method in API class. * src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java: Little changes. * src/pandroid_event_viewer/pandorafms/API.java: Now the getEvents() method accepts all parameters of get_events petition in Pandora API. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6770 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
f704670749
commit
eb7b272ed3
|
@ -1,3 +1,8 @@
|
|||
2012-07-14 Santiago Munín <burning1@gmail.com>
|
||||
* src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java: Now uses the new getEvents() method in API class.
|
||||
* src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java: Little changes.
|
||||
* src/pandroid_event_viewer/pandorafms/API.java: Now the getEvents() method accepts all parameters of get_events petition in Pandora API.
|
||||
|
||||
2012-07-13 Santiago Munín <burning1@gmail.com>
|
||||
* ChangeLog: Fixed a line.
|
||||
* src/pandroid_event_viewer/pandorafms/Main.java: Fixed a bug. Default profile can't be deleted.
|
||||
|
|
|
@ -105,22 +105,52 @@ public class API {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get events from pandora console.
|
||||
* Performs a get_events API call.
|
||||
*
|
||||
* @param newEvents
|
||||
* @param context
|
||||
* Application context.
|
||||
* @param filterAgentName
|
||||
* Agent name.
|
||||
* @param idGroup
|
||||
* Group id.
|
||||
* @param filterSeverity
|
||||
* Severity.
|
||||
* @param filterStatus
|
||||
* Status.
|
||||
* @param filterEventSearch
|
||||
* Text in event title.
|
||||
* @param filterTag
|
||||
* Tag.
|
||||
* @param filterTimestamp
|
||||
* Events after this time.
|
||||
* @param itemsPerPage
|
||||
* Number of items retrieved per list in each call.
|
||||
* @param offset
|
||||
* List offset.
|
||||
* @param total
|
||||
* Retrieve number of events instead of events info.
|
||||
* @param more_criticity
|
||||
* Retrieve maximum criticity instead of events info.
|
||||
* @return API call result.
|
||||
* @throws IOException
|
||||
* If there is a problem with the connection.
|
||||
* if there was any problem.
|
||||
*/
|
||||
public static String getEvents(Context context, String other)
|
||||
throws IOException {
|
||||
// Get total count.
|
||||
public static String getEvents(Context context, String filterAgentName,
|
||||
int idGroup, int filterSeverity, int filterStatus,
|
||||
String filterEventSearch, String filterTag, long filterTimestamp,
|
||||
long itemsPerPage, long offset, boolean total,
|
||||
boolean more_criticity) throws IOException {
|
||||
ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other", other));
|
||||
parameters.add(new BasicNameValuePair("other",
|
||||
serializeEventsParamsToAPI(filterAgentName, idGroup,
|
||||
filterSeverity, filterStatus, filterEventSearch,
|
||||
filterTag, filterTimestamp, itemsPerPage, offset,
|
||||
total, more_criticity)));
|
||||
return Core.httpGet(context, parameters);
|
||||
}
|
||||
|
||||
|
@ -207,4 +237,60 @@ public class API {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize parameters to api.
|
||||
*
|
||||
* @param filterAgentName
|
||||
* Agent name.
|
||||
* @param idGroup
|
||||
* Group id.
|
||||
* @param filterSeverity
|
||||
* Severity.
|
||||
* @param filterStatus
|
||||
* Status.
|
||||
* @param filterEventSearch
|
||||
* Text in event title.
|
||||
* @param filterTag
|
||||
* Tag.
|
||||
* @param filterTimestamp
|
||||
* Events after this time.
|
||||
* @param itemsPerPage
|
||||
* Number of items retrieved per list in each call.
|
||||
* @param offset
|
||||
* List offset.
|
||||
* @param total
|
||||
* Retrieve number of events instead of events info.
|
||||
* @param more_criticity
|
||||
* Retrieve maximum criticity instead of events info.
|
||||
* @return Serialized parameters.
|
||||
*/
|
||||
private static String serializeEventsParamsToAPI(String filterAgentName,
|
||||
int idGroup, int filterSeverity, int filterStatus,
|
||||
String filterEventSearch, String filterTag, long filterTimestamp,
|
||||
long itemsPerPage, long offset, boolean total,
|
||||
boolean more_criticity) {
|
||||
|
||||
String totalStr = (total) ? "total" : "-1";
|
||||
if (more_criticity) {
|
||||
totalStr = "more_criticity";
|
||||
}
|
||||
return Core.serializeParams2Api(new String[] { ";", // Separator for the
|
||||
// csv
|
||||
Integer.toString(filterSeverity), // criticity or severity
|
||||
filterAgentName, // The agent name
|
||||
"", // Name of module
|
||||
"", // Name of alert template
|
||||
"", // Id user
|
||||
Long.toString(filterTimestamp), // The minimum 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
|
||||
filterTag }); // Tag
|
||||
}
|
||||
}
|
|
@ -263,33 +263,6 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes all parameters.
|
||||
*
|
||||
* @param total
|
||||
* True if only want the count
|
||||
* @return All parameters in a string.
|
||||
*/
|
||||
private String serializeParams2Api(boolean total) {
|
||||
String totalStr = (total) ? "total" : "-1";
|
||||
|
||||
return Core.serializeParams2Api(new String[] { ";", // Separator
|
||||
Integer.toString(this.severity), // Severity
|
||||
this.agentNameStr, // Agent name
|
||||
"", // Module
|
||||
"", // 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
|
||||
this.eventTag });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get events from pandora console.
|
||||
*
|
||||
|
@ -300,8 +273,10 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
private void getEvents() throws IOException {
|
||||
// Get total count.
|
||||
String return_api = API.getEvents(getApplicationContext(),
|
||||
serializeParams2Api(true));
|
||||
agentNameStr, id_group, severity, status, eventSearch,
|
||||
eventTag, timestamp, pagination, offset, true, false);
|
||||
return_api = return_api.replace("\n", "");
|
||||
|
||||
try {
|
||||
this.count_events = Long.valueOf(return_api);
|
||||
} catch (NumberFormatException e) {
|
||||
|
@ -314,8 +289,9 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
}
|
||||
|
||||
// Get the list of events.
|
||||
return_api = API.getEvents(getApplicationContext(),
|
||||
serializeParams2Api(false));
|
||||
return_api = API.getEvents(getApplicationContext(), agentNameStr,
|
||||
id_group, severity, status, eventSearch, eventTag, timestamp,
|
||||
pagination, offset, false, false);
|
||||
Log.d(TAG, "List of events: " + return_api);
|
||||
Pattern pattern = Pattern
|
||||
.compile("Unable to process XML data file '(.*)'");
|
||||
|
|
|
@ -48,10 +48,6 @@ public class PandroidEventviewerService extends IntentService {
|
|||
|
||||
private static String TAG = "PandroidEventviewerService";
|
||||
private static final int NOTIFICATION_PANDROID_EVENT_VIEWER = 666;
|
||||
public String url;
|
||||
public String user;
|
||||
public String password;
|
||||
|
||||
public long count_events;
|
||||
public int more_criticity;
|
||||
|
||||
|
@ -69,6 +65,7 @@ public class PandroidEventviewerService extends IntentService {
|
|||
try {
|
||||
checkNewEvents(getApplicationContext());
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "OnHandleIntent: " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,77 +80,73 @@ public class PandroidEventviewerService extends IntentService {
|
|||
public void checkNewEvents(Context context) throws IOException {
|
||||
Log.d(TAG, "Checking events at "
|
||||
+ Calendar.getInstance().getTime().toGMTString());
|
||||
if (this.url == null) {
|
||||
SharedPreferences preferences = context.getSharedPreferences(
|
||||
context.getString(R.string.const_string_preferences),
|
||||
Activity.MODE_PRIVATE);
|
||||
Calendar c = Calendar.getInstance();
|
||||
long now = (c.getTimeInMillis() / 1000);
|
||||
long old_previous_filterTimestamp = preferences.getLong(
|
||||
"previous_filterTimestamp", now);
|
||||
SharedPreferences preferences = context.getSharedPreferences(
|
||||
context.getString(R.string.const_string_preferences),
|
||||
Activity.MODE_PRIVATE);
|
||||
Calendar c = Calendar.getInstance();
|
||||
long now = (c.getTimeInMillis() / 1000);
|
||||
long old_previous_filterTimestamp = preferences.getLong(
|
||||
"previous_filterTimestamp", now);
|
||||
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
String parametersAPI = serializeParams2Api(context, true, false,
|
||||
false);
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
String parametersAPI = serializeParams2Api(context, true, false, false);
|
||||
|
||||
// Get total count.
|
||||
// Get total count.
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other", parametersAPI));
|
||||
String return_api;
|
||||
return_api = Core.httpGet(getApplicationContext(), parameters);
|
||||
|
||||
Log.i(TAG + " checkNewEvents", return_api);
|
||||
return_api = return_api.replace("\n", "");
|
||||
try {
|
||||
this.count_events = Long.valueOf(return_api);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
// Check the more critical level
|
||||
if (this.count_events != 0) {
|
||||
Log.i(TAG, "There are new events");
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other", parametersAPI));
|
||||
String return_api;
|
||||
parameters.add(new BasicNameValuePair("other", serializeParams2Api(
|
||||
context, false, true, true)));
|
||||
return_api = Core.httpGet(getApplicationContext(), parameters);
|
||||
|
||||
Log.i(TAG + " checkNewEvents", return_api);
|
||||
return_api = return_api.replace("\n", "");
|
||||
try {
|
||||
this.count_events = Long.valueOf(return_api);
|
||||
this.more_criticity = Integer.valueOf(return_api).intValue();
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
// Check the more critical level
|
||||
if (this.count_events != 0) {
|
||||
Log.i(TAG, "There are new events");
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other",
|
||||
serializeParams2Api(context, false, true, true)));
|
||||
return_api = Core.httpGet(getApplicationContext(), parameters);
|
||||
return_api = return_api.replace("\n", "");
|
||||
try {
|
||||
this.more_criticity = Integer.valueOf(return_api)
|
||||
.intValue();
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
return;
|
||||
}
|
||||
long lastCountEvents = preferences.getLong("last_count_events", 0);
|
||||
// Does not repeat the same notification
|
||||
if (lastCountEvents != count_events) {
|
||||
notificationEvent(context);
|
||||
Editor editor = preferences.edit();
|
||||
editor.putLong("last_count_events", count_events);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
} else {
|
||||
this.more_criticity = -1;
|
||||
|
||||
// Restore timestamp
|
||||
SharedPreferences.Editor editorPreferences = preferences.edit();
|
||||
editorPreferences.putLong("previous_filterTimestamp",
|
||||
old_previous_filterTimestamp);
|
||||
editorPreferences.commit();
|
||||
long lastCountEvents = preferences.getLong("last_count_events", 0);
|
||||
// Does not repeat the same notification
|
||||
if (lastCountEvents != count_events) {
|
||||
notificationEvent(context);
|
||||
Editor editor = preferences.edit();
|
||||
editor.putLong("last_count_events", count_events);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
} else {
|
||||
this.more_criticity = -1;
|
||||
|
||||
// Restore timestamp
|
||||
SharedPreferences.Editor editorPreferences = preferences.edit();
|
||||
editorPreferences.putLong("previous_filterTimestamp",
|
||||
old_previous_filterTimestamp);
|
||||
editorPreferences.commit();
|
||||
}
|
||||
Log.d(TAG, "Check finished at "
|
||||
+ Calendar.getInstance().getTime().toGMTString());
|
||||
|
|
Loading…
Reference in New Issue