2012-10-22 Miguel de Dios <miguel.dedios@artica.es>
* src/pandroid_event_viewer/pandorafms/API.java: added more log for to make more easy. * src/pandroid_event_viewer/pandorafms/Core.java: the constant TIMEOUT now is 10 seconds instead old 5 seconds that sometimes fails. * src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java: added functions "getEvents_v50" and "getEvents_old" for to get events list for serveral api pandora versions. * src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java: fixed source code style. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8947 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
b589732730
commit
9920066b50
|
@ -1,3 +1,19 @@
|
|||
2012-10-22 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* src/pandroid_event_viewer/pandorafms/API.java: added more log
|
||||
for to make more easy.
|
||||
|
||||
* src/pandroid_event_viewer/pandorafms/Core.java: the constant
|
||||
TIMEOUT now is 10 seconds instead old 5 seconds that sometimes
|
||||
fails.
|
||||
|
||||
* src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java:
|
||||
added functions "getEvents_v50" and "getEvents_old" for to get
|
||||
events list for serveral api pandora versions.
|
||||
|
||||
* src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java:
|
||||
fixed source code style.
|
||||
|
||||
2012-09-13 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* res/layout/main.xml: removed the typo bug.
|
||||
|
|
|
@ -94,6 +94,7 @@ public class API {
|
|||
parameters.add(new BasicNameValuePair("op2", "test"));
|
||||
String return_api;
|
||||
return_api = Core.httpGet(context, parameters);
|
||||
|
||||
if (return_api.contains("OK")) {
|
||||
String[] lines = return_api.split(",");
|
||||
if (lines.length == 3) {
|
||||
|
@ -144,6 +145,7 @@ public class API {
|
|||
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"));
|
||||
|
@ -283,6 +285,24 @@ public class API {
|
|||
if (more_criticity) {
|
||||
totalStr = "more_criticity";
|
||||
}
|
||||
|
||||
Log.i(TAG + " serializeEventsParamsToAPI",
|
||||
" separator: ;" +
|
||||
" Criticity: " + Integer.toString(filterSeverity) +
|
||||
" Agent: " + filterAgentName +
|
||||
" Module: " +
|
||||
" Alter template: " +
|
||||
" User: " +
|
||||
" Min interval: " + Long.toString(filterTimestamp) +
|
||||
" Max interval: " +
|
||||
" Status: " + String.valueOf(filterStatus) +
|
||||
" Description: " +
|
||||
" Pagination: " + Integer.toString(20) +
|
||||
" Count/Show: " + totalStr +
|
||||
" Group ID: " + Integer.toString(idGroup) +
|
||||
" Tag: " + filterTag
|
||||
);
|
||||
|
||||
return Core.serializeParams2Api(new String[] {
|
||||
";", // Separator for the csv
|
||||
Integer.toString(filterSeverity), // criticity or severity
|
||||
|
|
|
@ -77,7 +77,7 @@ import android.widget.Toast;
|
|||
*/
|
||||
public class Core {
|
||||
private static String TAG = "Core";
|
||||
private static int CONNECTION_TIMEOUT = 5000;
|
||||
private static int CONNECTION_TIMEOUT = 10000;
|
||||
private static Map<String, Bitmap> imgCache = new HashMap<String, Bitmap>();
|
||||
// Don't use this variable, just call getSocketFactory
|
||||
private static SSLSocketFactory sslSocketFactory;
|
||||
|
|
|
@ -259,117 +259,199 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
"Configuration changes commited (timestamp)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get events from pandora console.
|
||||
* Get events from pandora console. For only Pandora 5.0 version
|
||||
*
|
||||
* @throws IOException
|
||||
* If there is any connection problem.
|
||||
*
|
||||
*/
|
||||
private void getEvents() throws IOException {
|
||||
// Get total count.
|
||||
String return_api = API.getEvents(getApplicationContext(),
|
||||
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) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.count_events == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the list of events.
|
||||
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 '(.*)'");
|
||||
Matcher matcher;
|
||||
String filename;
|
||||
|
||||
boolean endReplace = false;
|
||||
int i22 = 0;
|
||||
while (!endReplace) {
|
||||
Log.i(TAG + " getEvents - loop", i22 + "");
|
||||
i22++;
|
||||
matcher = pattern.matcher(return_api);
|
||||
|
||||
if (matcher.find()) {
|
||||
filename = matcher.group(1);
|
||||
return_api = return_api
|
||||
.replaceFirst(
|
||||
"Unable to process XML data file[^\n]*\n[^\n]*line 187 thread .*\n",
|
||||
"Bad XML: " + filename);
|
||||
} else {
|
||||
endReplace = true;
|
||||
}
|
||||
}
|
||||
|
||||
Log.i(TAG + " getEvents - return_api", return_api);
|
||||
|
||||
String[] lines = return_api.split("\n");
|
||||
newEvents = true;
|
||||
if (return_api.length() == 0) {
|
||||
Log.d("WORKS?", "NEWEVENTS = FALSE");
|
||||
newEvents = false;
|
||||
return;
|
||||
}
|
||||
|
||||
private void getEvents_v50(String[] lines) {
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String[] items = lines[i].split(";");
|
||||
|
||||
EventListItem event = new EventListItem();
|
||||
try {
|
||||
//Get id event
|
||||
if (items[0].length() == 0) {
|
||||
event.id_event = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
event.id_event = Integer.parseInt(items[0]);
|
||||
}
|
||||
|
||||
//Get id agent
|
||||
if (items[1].length() == 0) {
|
||||
event.id_agent = 0;
|
||||
}
|
||||
else {
|
||||
event.id_agent = Integer.parseInt(items[1]);
|
||||
}
|
||||
|
||||
//Get id user
|
||||
event.id_user = items[2];
|
||||
|
||||
//Get id group
|
||||
if (items[3].length() == 0) {
|
||||
event.id_group = 0;
|
||||
}
|
||||
else {
|
||||
event.id_group = Integer.parseInt(items[3]);
|
||||
}
|
||||
|
||||
//Get status
|
||||
if (items[4].length() == 0) {
|
||||
event.status = 0;
|
||||
}
|
||||
else {
|
||||
event.status = Integer.parseInt(items[4]);
|
||||
}
|
||||
|
||||
//Get timestamp (format Y-M-d H:m:s)
|
||||
event.timestamp = items[5];
|
||||
|
||||
//Get event as text
|
||||
event.event = items[6];
|
||||
|
||||
//Get unix timestamp
|
||||
if (items[7].length() == 0) {
|
||||
event.utimestamp = 0;
|
||||
}
|
||||
else {
|
||||
event.utimestamp = Integer.parseInt(items[7]);
|
||||
}
|
||||
|
||||
//Get event type
|
||||
event.event_type = items[8];
|
||||
|
||||
//Get id module
|
||||
if (items[9].length() == 0) {
|
||||
event.id_agentmodule = 0;
|
||||
}
|
||||
else {
|
||||
event.id_agentmodule = Integer.parseInt(items[9]);
|
||||
}
|
||||
|
||||
//Get id alert
|
||||
if (items[10].length() == 0) {
|
||||
event.id_alert_am = 0;
|
||||
}
|
||||
else {
|
||||
event.id_alert_am = Integer.parseInt(items[10]);
|
||||
}
|
||||
|
||||
//Get criticity
|
||||
if (items[11].length() == 0) {
|
||||
event.criticity = 0;
|
||||
}
|
||||
else {
|
||||
event.criticity = Integer.parseInt(items[11]);
|
||||
}
|
||||
|
||||
//Get user comment
|
||||
event.user_comment = items[12];
|
||||
|
||||
//Get tags
|
||||
event.tags = items[13];
|
||||
|
||||
/* This fields are not used in the Pandroid event
|
||||
|
||||
event.source = item[14];
|
||||
event.id_extra = item[15];
|
||||
event.critical_instructions = item[16];
|
||||
event.warning_instructions = item[17];
|
||||
event.unknown_instructions = item[18];
|
||||
event.owner_user = item[19];
|
||||
event.ack_utimestamp = item[20];
|
||||
event.custom_data = item[21]
|
||||
|
||||
*/
|
||||
|
||||
//Get agent name
|
||||
event.agent_name = items[22];
|
||||
event.group_name = items[23];
|
||||
event.group_icon = items[24];
|
||||
event.description_event = items[25];
|
||||
event.description_image = items[26];
|
||||
event.criticity_name = items[27];
|
||||
event.criticity_image = items[28];
|
||||
|
||||
event.opened = false;
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
event.event = getApplication().getString(
|
||||
R.string.unknown_event_str);
|
||||
launchProblemParsingNotification();
|
||||
}
|
||||
this.eventList.add(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get events from pandora console. For old versions of Pandora (v4 <)
|
||||
*
|
||||
* @throws IOException
|
||||
* If there is any connection problem.
|
||||
*
|
||||
*/
|
||||
private void getEvents_old(String[] lines) {
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String[] items = lines[i].split(";");
|
||||
|
||||
EventListItem event = new EventListItem();
|
||||
try {
|
||||
|
||||
if (items[0].length() == 0) {
|
||||
event.id_event = 0;
|
||||
}
|
||||
else {
|
||||
event.id_event = Integer.parseInt(items[0]);
|
||||
}
|
||||
if (items[1].length() == 0) {
|
||||
event.id_agent = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
event.id_agent = Integer.parseInt(items[1]);
|
||||
}
|
||||
event.id_user = items[2];
|
||||
if (items[3].length() == 0) {
|
||||
event.id_group = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
event.id_group = Integer.parseInt(items[3]);
|
||||
}
|
||||
if (items[4].length() == 0) {
|
||||
event.status = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
event.status = Integer.parseInt(items[4]);
|
||||
}
|
||||
event.timestamp = items[5];
|
||||
event.event = items[6];
|
||||
if (items[7].length() == 0) {
|
||||
event.utimestamp = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
event.utimestamp = Integer.parseInt(items[7]);
|
||||
}
|
||||
event.event_type = items[8];
|
||||
if (items[9].length() == 0) {
|
||||
event.id_agentmodule = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
event.id_agentmodule = Integer.parseInt(items[9]);
|
||||
}
|
||||
if (items[10].length() == 0) {
|
||||
event.id_alert_am = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
event.id_alert_am = Integer.parseInt(items[10]);
|
||||
}
|
||||
if (items[11].length() == 0) {
|
||||
event.criticity = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
event.criticity = Integer.parseInt(items[11]);
|
||||
}
|
||||
event.user_comment = items[12];
|
||||
|
@ -383,7 +465,8 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
event.criticity_image = items[20];
|
||||
|
||||
event.opened = false;
|
||||
} catch (NumberFormatException nfe) {
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
event.event = getApplication().getString(
|
||||
R.string.unknown_event_str);
|
||||
launchProblemParsingNotification();
|
||||
|
@ -391,6 +474,84 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
this.eventList.add(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get events from pandora console.
|
||||
*
|
||||
* @throws IOException
|
||||
* If there is any connection problem.
|
||||
*
|
||||
*/
|
||||
private void getEvents() throws IOException {
|
||||
// Get total count.
|
||||
String return_api = API.getEvents(getApplicationContext(),
|
||||
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) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.count_events == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the list of events.
|
||||
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 '(.*)'");
|
||||
Matcher matcher;
|
||||
String filename;
|
||||
|
||||
boolean endReplace = false;
|
||||
int i22 = 0;
|
||||
while (!endReplace) {
|
||||
Log.i(TAG + " getEvents - loop", i22 + "");
|
||||
i22++;
|
||||
matcher = pattern.matcher(return_api);
|
||||
|
||||
if (matcher.find()) {
|
||||
filename = matcher.group(1);
|
||||
return_api = return_api
|
||||
.replaceFirst(
|
||||
"Unable to process XML data file[^\n]*\n[^\n]*line 187 thread .*\n",
|
||||
"Bad XML: " + filename);
|
||||
}
|
||||
else {
|
||||
endReplace = true;
|
||||
}
|
||||
}
|
||||
|
||||
Log.i(TAG + " getEvents - return_api", return_api);
|
||||
|
||||
String[] lines = return_api.split("\n");
|
||||
newEvents = true;
|
||||
if (return_api.length() == 0) {
|
||||
Log.d("WORKS?", "NEWEVENTS = FALSE");
|
||||
newEvents = false;
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences preferences = getSharedPreferences(
|
||||
getString(R.string.const_string_preferences),
|
||||
Activity.MODE_PRIVATE);
|
||||
String api_version = preferences.getString("api_version", "");
|
||||
|
||||
if (api_version.equals("v5.0")) {
|
||||
this.getEvents_v50(lines);
|
||||
}
|
||||
else {
|
||||
this.getEvents_old(lines);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the async task of getting events.
|
||||
|
|
|
@ -60,7 +60,8 @@ public class PandroidEventviewerService extends IntentService {
|
|||
protected void onHandleIntent(Intent intent) {
|
||||
try {
|
||||
checkNewEvents(getApplicationContext());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e) {
|
||||
Log.e(TAG, "OnHandleIntent: " + e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -104,12 +105,13 @@ public class PandroidEventviewerService extends IntentService {
|
|||
"");
|
||||
String filterTag = preferences.getString("filterTag", "");
|
||||
String return_api = API.getEvents(this, filterAgentName, idGroup,
|
||||
filterSeverity, filterStatus, filterEventSearch, filterTag,
|
||||
new_events_filterTimestamp, 20, 0, true, false);
|
||||
filterSeverity, filterStatus, filterEventSearch, filterTag,
|
||||
new_events_filterTimestamp, 20, 0, true, false);
|
||||
return_api = return_api.replace("\n", "");
|
||||
try {
|
||||
this.count_events = Long.valueOf(return_api);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
@ -118,12 +120,13 @@ public class PandroidEventviewerService extends IntentService {
|
|||
if (this.count_events != 0) {
|
||||
Log.i(TAG, "There are new events");
|
||||
return_api = API.getEvents(this, filterAgentName, idGroup,
|
||||
filterSeverity, filterStatus, filterEventSearch, filterTag,
|
||||
new_events_filterTimestamp, 20, 0, false, true);
|
||||
filterSeverity, filterStatus, filterEventSearch, filterTag,
|
||||
new_events_filterTimestamp, 20, 0, false, true);
|
||||
return_api = return_api.replace("\n", "");
|
||||
try {
|
||||
this.more_criticity = Integer.valueOf(return_api).intValue();
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
@ -136,7 +139,8 @@ public class PandroidEventviewerService extends IntentService {
|
|||
editor.commit();
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this.more_criticity = -1;
|
||||
}
|
||||
Log.d(TAG, "Check finished at "
|
||||
|
|
Loading…
Reference in New Issue