Uploaded lost changes.

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8969 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-10-28 14:49:21 +00:00
parent e0cc349341
commit 2c0b6a35da
7 changed files with 146 additions and 64 deletions

View File

@ -155,8 +155,22 @@
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="2dp"
android:text="@string/timeout_connections_label_str"
android:textColor="#ffffff" />
<EditText
android:id="@+id/timeout_connections"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:ems="3"
android:inputType="number"
android:singleLine="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"

View File

@ -75,4 +75,5 @@
<string name="pandroid_info_long_txt"><p>Esta aplicación se usa para ver de forma autónoma y cómoda, el estado de los eventos resportados por un servidor de monitorización Pandora FMS. Desde esta aplicación podrá ver en tiempo real los eventos, e incluso validar o filtrarlos.</p><p>La configuración por defecto apunta al servidor de demo de Pandora FMS en firefly.artica.es. Cambie la configuración para que apunte a su propio servidor de Pandora FMS.</p></string>
<string name="connection_problems">Conexión fallida</string>
<string name="empty">- Vacia -</string>
<string name="timeout_connections_label_str">Tiempo de espera de las conexiones (en segundos)</string>
</resources>

View File

@ -76,4 +76,5 @@
<string name="validate_event_label_str">承諾済イベント</string>
<string name="pandroid_event_viewer_description_str">Pandora FMS リアルタイムイベントビューワ</string>
<string name="empty">- 空 -</string>
<string name="timeout_connections_label_str">Timeout connections (in seconds)</string>
</resources>

View File

@ -82,7 +82,7 @@
<string name="validate_event_label_str">Event validated</string>
<string name="pandroid_event_viewer_description_str">Realtime event viewer for Pandora FMS.</string>
<string name="pandroid_info_txt"><b>Welcome to Pandora FMS Event viewer for Android</b></string>
<string name="pandroid_info_long_txt"><p>This app is used for to see confortable and standaralone the events status from the monitoring server of Pandora FMS. From this app you can see in realtime the events and validate or filter.</p><p>The configuration as default connecting with public demo of Pandora FMS in firefly.artica.es. Please change the configuration for to use your Pandora FMS server.</p></string>
<string name="pandroid_info_long_txt"><p>This app is used for to see comfortable and standaralone the events status from the monitoring server of Pandora FMS. From this app you can see in realtime the events and validate or filter.</p><p>The configuration as default connecting with public demo of Pandora FMS in firefly.artica.es. Please change the configuration for to use your Pandora FMS server.</p></string>
<string name="check_connection">Connection status</string>
<string name="connection">Connection</string>
<string name="notification">Notification</string>
@ -122,5 +122,6 @@
<string name="enable_background_service">Check in background</string>
<string name="default_profile_can_not_remove">Default profile can not be removed</string>
<string name="connection_problems">Connection failed</string>
<string name="timeout_connections_label_str">Timeout connections (in seconds)</string>
</resources>

View File

@ -77,7 +77,6 @@ import android.widget.Toast;
*/
public class Core {
private static String TAG = "Core";
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;
@ -350,6 +349,7 @@ public class Core {
String user = preferences.getString("user", "");
String password = preferences.getString("password", "");
String apiPassword = preferences.getString("api_password", "");
int timeout_connections = preferences.getInt("timeout_connections", 10) * 1000;
if (url.length() == 0 || user.length() == 0) {
return "";
}
@ -363,13 +363,14 @@ public class Core {
Log.i(TAG, "sent: " + url);
if (url.toLowerCase().contains("https")) {
// Secure connection
return Core.httpsGet(url, parameters);
return Core.httpsGet(context, url, parameters);
}
else {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params,
CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, CONNECTION_TIMEOUT);
timeout_connections);
HttpConnectionParams.setSoTimeout(params, timeout_connections);
DefaultHttpClient httpClient = new DefaultHttpClient(params);
UrlEncodedFormEntity entity;
HttpPost httpPost;
@ -395,7 +396,7 @@ public class Core {
* Image's url.
* @return A bitmap of that image.
*/
public static Bitmap downloadImage(String fileUrl) {
public static Bitmap downloadImage(Context context, String fileUrl) {
if (imgCache.containsKey(fileUrl)) {
Log.i(TAG, "Fetched from cache: " + fileUrl);
return imgCache.get(fileUrl);
@ -403,6 +404,11 @@ public class Core {
Log.i(TAG, "Downloading image: " + fileUrl);
URL myFileUrl = null;
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
int timeout_connections = preferences.getInt("timeout_connections", 10) * 1000;
try {
myFileUrl = new URL(fileUrl);
if (fileUrl.toLowerCase().contains("https")) {
@ -422,7 +428,7 @@ public class Core {
HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection();
conn.setDoInput(true);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setConnectTimeout(timeout_connections);
conn.connect();
InputStream is = conn.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is);
@ -457,8 +463,8 @@ public class Core {
* @param url
* Image's url.
*/
public static void setTextViewLeftImage(TextView view, String url) {
Drawable d = new BitmapDrawable(Core.downloadImage(url));
public static void setTextViewLeftImage(Context context, TextView view, String url) {
Drawable d = new BitmapDrawable(Core.downloadImage(context, url));
setTextViewLeftImage(view, d, 16);
}
@ -489,12 +495,17 @@ public class Core {
* @throws IOException
* If the given url is not accessible.
*/
public static boolean isValidCertificate(URL url) {
public static boolean isValidCertificate(Context context, URL url) {
HttpsURLConnection con;
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
int timeout_connections = preferences.getInt("timeout_connections", 10) * 1000;
try {
con = (HttpsURLConnection) url.openConnection();
con.setConnectTimeout(CONNECTION_TIMEOUT);
con.setConnectTimeout(timeout_connections);
con.connect();
con.disconnect();
@ -511,7 +522,12 @@ public class Core {
* @param url
* @return boolean
*/
public static boolean isOnline(URL url) {
public static boolean isOnline(Context context, URL url) {
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
int timeout_connections = preferences.getInt("timeout_connections", 10) * 1000;
try {
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setHostnameVerifier(new HostnameVerifier() {
@ -519,7 +535,7 @@ public class Core {
return true;
}
});
con.setConnectTimeout(CONNECTION_TIMEOUT);
con.setConnectTimeout(timeout_connections);
con.setSSLSocketFactory(getSocketFactory());
con.setDoOutput(true);
con.getInputStream();
@ -543,9 +559,14 @@ public class Core {
* If there is any problem with connection.
*
*/
private static String httpsGet(String url, List<NameValuePair> parameters)
private static String httpsGet(Context context, String url, List<NameValuePair> parameters)
throws IOException {
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
int timeout_connections = preferences.getInt("timeout_connections", 10) * 1000;
String result = "";
HttpsURLConnection con;
try {
@ -557,7 +578,7 @@ public class Core {
});
con.setSSLSocketFactory(getSocketFactory());
con.setDoOutput(true);
con.setConnectTimeout(CONNECTION_TIMEOUT);
con.setConnectTimeout(timeout_connections);
String postData = "";
boolean first = true;
for (NameValuePair nameValuePair : parameters) {

View File

@ -53,6 +53,7 @@ import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.Toast;
/**
@ -68,30 +69,34 @@ public class Main extends Activity {
private static String DEFAULT_PROFILE_NAME = "Default";
private static String DEFAULT_PROFILE = "0|3||||0|6";
private static String VERSION_4_0_2_LABEL = "v4.0.2";
private PandroidEventviewerActivity object;
private HashMap<Integer, String> pandoraGroups;
private PandroidEventviewerActivity object = null;
public Map<Integer, String> pandoraGroups;
public List<String> pandoraGroups_list;
private Spinner comboSeverity;
private List<String> profiles;
private Context context = this;
private boolean selectLastProfile = false;
// If this version, there will be changes
private boolean version402 = false;
public int id_group = -1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
this.object = (PandroidEventviewerActivity) i
.getSerializableExtra("object");
.getSerializableExtra("object");
this.pandoraGroups = new HashMap<Integer, String>();
final SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
if (preferences.getString("api_version", "")
.equals(VERSION_4_0_2_LABEL)) {
.equals(VERSION_4_0_2_LABEL)) {
version402 = true;
}
@ -111,7 +116,8 @@ public class Main extends Activity {
buttonSetAsFilterWatcher.setEnabled(false);
buttonSearch.setEnabled(false);
buttonDeleteProfile.setEnabled(false);
} else if (object.user.equals("demo") || object.password.equals("demo")) {
}
else if (object.user.equals("demo") || object.password.equals("demo")) {
Toast toast = Toast.makeText(this.getApplicationContext(),
this.getString(R.string.preferences_set_demo_pandora_str),
Toast.LENGTH_LONG);
@ -234,7 +240,8 @@ public class Main extends Activity {
// Show advanced options?
if (preferences.getBoolean("show_advanced", false)) {
advancedOptions.setVisibility(View.VISIBLE);
} else {
}
else {
advancedOptions.setVisibility(View.GONE);
setAdvancedOptionsDefaults();
clearAdvancedOptions();
@ -250,7 +257,8 @@ public class Main extends Activity {
if (isChecked) {
advancedOptions.setVisibility(View.VISIBLE);
preferencesEditor.putBoolean("show_advanced", true);
} else {
}
else {
advancedOptions.setVisibility(View.GONE);
preferencesEditor.putBoolean("show_advanced", false);
setAdvancedOptionsDefaults();
@ -269,15 +277,19 @@ public class Main extends Activity {
public void onResume() {
super.onResume();
Log.i(TAG, "Getting groups and tags");
new GetGroupsAsyncTask().execute();
GetGroupsAsyncTask task_group = new GetGroupsAsyncTask();
task_group.execute();
if (version402) {
((EditText) findViewById(R.id.tag_text))
.setVisibility(View.VISIBLE);
((ProgressBar) findViewById(R.id.loading_tag))
.setVisibility(View.GONE);
((Spinner) findViewById(R.id.tag)).setVisibility(View.GONE);
} else {
}
else {
new GetTagsAsyncTask().execute();
}
}
@ -289,14 +301,14 @@ public class Main extends Activity {
*
*/
private class GetGroupsAsyncTask extends AsyncTask<Void, Void, Boolean> {
private List<String> list;
@Override
protected Boolean doInBackground(Void... params) {
list = new ArrayList<String>();
pandoraGroups = new HashMap<Integer, String>();
try {
list.addAll(API.getGroups(getApplicationContext()).values());
} catch (IOException e) {
pandoraGroups = API.getGroups(getApplicationContext());
}
catch (IOException e) {
return false;
}
return true;
@ -308,12 +320,18 @@ public class Main extends Activity {
loadingGroup.setVisibility(ProgressBar.GONE);
if (result) {
Spinner combo = (Spinner) findViewById(R.id.group_combo);
pandoraGroups_list = new ArrayList<String>();
pandoraGroups_list.addAll(pandoraGroups.values());
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
getApplicationContext(),
android.R.layout.simple_spinner_item, list);
android.R.layout.simple_spinner_item, pandoraGroups_list);
combo.setAdapter(spinnerArrayAdapter);
combo.setSelection(0);
int index_combo = pandoraGroups_list.indexOf(pandoraGroups.get(object.id_group));
combo.setSelection(index_combo);
Button buttonSaveAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher);
Button buttonSearch = (Button) findViewById(R.id.button_send);
@ -324,7 +342,8 @@ public class Main extends Activity {
buttonSearch.setEnabled(true);
buttonDeleteProfile.setEnabled(true);
buttonSaveProfile.setEnabled(true);
} else {
}
else {
// Only this task will show the toast in order to prevent a
// message repeated.
Core.showConnectionProblemToast(getApplicationContext(), false);
@ -346,7 +365,8 @@ public class Main extends Activity {
try {
list = API.getTags(getApplicationContext());
return true;
} catch (IOException e) {
}
catch (IOException e) {
return false;
}
}
@ -360,7 +380,16 @@ public class Main extends Activity {
getApplicationContext(),
android.R.layout.simple_spinner_item, list);
combo.setAdapter(spinnerArrayAdapter);
SpinnerAdapter adapter = (SpinnerAdapter)combo.getAdapter();
combo.setSelection(0);
for (int position = 0; position < adapter.getCount(); position++) {
String event_text = adapter.getItem(position).toString();
if (event_text.equals(object.eventTag)) {
combo.setSelection(position);
}
}
}
ProgressBar loadingGroup = (ProgressBar) findViewById(R.id.loading_tag);
loadingGroup.setVisibility(ProgressBar.GONE);
@ -378,13 +407,13 @@ public class Main extends Activity {
public boolean onOptionsItemSelected(MenuItem item) {
Intent i;
switch (item.getItemId()) {
case R.id.options_button_menu_options:
startActivity(new Intent(this, Options.class));
break;
case R.id.about_button_menu_options:
i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.options_button_menu_options:
startActivity(new Intent(this, Options.class));
break;
case R.id.about_button_menu_options:
i = new Intent(this, About.class);
startActivity(i);
break;
}
return true;
}
@ -403,28 +432,31 @@ public class Main extends Activity {
timeKey = combo.getSelectedItemPosition();
this.object.timestamp = Core.convertMaxTimeOldEventValuesToTimestamp(0,
timeKey);
timeKey);
EditText text = (EditText) findViewById(R.id.agent_name);
this.object.agentNameStr = text.getText().toString();
this.object.id_group = 0;
combo = (Spinner) findViewById(R.id.group_combo);
if (combo.getSelectedItem() != null) {
String selectedGroup = combo.getSelectedItem().toString();
Iterator<Entry<Integer, String>> it = pandoraGroups.entrySet()
.iterator();
while (it.hasNext()) {
Map.Entry<Integer, String> e = (Map.Entry<Integer, String>) it
.next();
.next();
if (e.getValue().equals(selectedGroup)) {
this.object.id_group = e.getKey();
}
}
}
this.id_group = this.object.id_group;
combo = (Spinner) findViewById(R.id.severity_combo);
this.object.severity = combo.getSelectedItemPosition() - 1;
@ -437,7 +469,8 @@ public class Main extends Activity {
if (version402) {
text = (EditText) findViewById(R.id.tag_text);
this.object.eventTag = text.getText().toString();
} else {
}
else {
combo = (Spinner) findViewById(R.id.tag);
if (combo.getSelectedItem() != null) {
this.object.eventTag = combo.getSelectedItem().toString();
@ -492,7 +525,8 @@ public class Main extends Activity {
if (version402) {
text = (EditText) findViewById(R.id.tag_text);
filterTag = text.getText().toString();
} else {
}
else {
combo = (Spinner) findViewById(R.id.tag);
filterTag = combo.getSelectedItem().toString();
}
@ -519,7 +553,8 @@ public class Main extends Activity {
this.getString(R.string.filter_update_succesful_str),
Toast.LENGTH_SHORT);
toast.show();
} else {
}
else {
Toast toast = Toast.makeText(getApplicationContext(),
this.getString(R.string.filter_update_fail_str),
Toast.LENGTH_SHORT);
@ -575,7 +610,8 @@ public class Main extends Activity {
String tag = "";
if (version402) {
tag = ((EditText) findViewById(R.id.tag_text)).getText().toString();
} else {
}
else {
tag = String.valueOf(((Spinner) findViewById(R.id.tag))
.getSelectedItemPosition());
}
@ -641,7 +677,8 @@ public class Main extends Activity {
String profileData = "";
if (profileName.equals(DEFAULT_PROFILE_NAME)) {
profileData = DEFAULT_PROFILE;
} else {
}
else {
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
@ -658,11 +695,13 @@ public class Main extends Activity {
if (version402) {
((EditText) findViewById(R.id.tag_text))
.setText(options[2]);
} else {
}
else {
spinner = (Spinner) findViewById(R.id.tag);
try {
spinner.setSelection(Integer.valueOf(options[2]));
} catch (NumberFormatException nf) {
}
catch (NumberFormatException nf) {
spinner.setSelection(0);
}
}
@ -674,10 +713,12 @@ public class Main extends Activity {
spinner.setSelection(Integer.valueOf(options[5]));
spinner = (Spinner) findViewById(R.id.max_time_old_event_combo);
spinner.setSelection(Integer.valueOf(options[6]));
} catch (NumberFormatException ne) {
}
catch (NumberFormatException ne) {
Log.e(TAG, "NumberFormatException parsing profile");
return;
} catch (IndexOutOfBoundsException ie) {
}
catch (IndexOutOfBoundsException ie) {
Log.e(TAG,
"IndexOutOfBoundsException (maybe groups or tags are not correctly loaded)");
return;

View File

@ -78,13 +78,16 @@ public class Options extends Activity {
// Connection
EditText text = (EditText) findViewById(R.id.url);
text.setText(preferences.getString("url",
"http://firefly.artica.es/pandora_demo"));
"http://192.168.70.133/pandora_console"));
text = (EditText) findViewById(R.id.user);
text.setText(preferences.getString("user", "demo"));
text.setText(preferences.getString("user", "admin"));
text = (EditText) findViewById(R.id.password);
text.setText(preferences.getString("password", "demo"));
text.setText(preferences.getString("password", "pandora"));
text = (EditText) findViewById(R.id.api_password);
text.setText(preferences.getString("api_password", "doreik0"));
text.setText(preferences.getString("api_password", ""));
text = (EditText) findViewById(R.id.timeout_connections);
text.setText(Integer.toString(preferences.getInt("timeout_connections", 10)));
Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
@ -344,14 +347,14 @@ public class Options extends Activity {
@Override
protected Boolean doInBackground(URL... arg0) {
url = arg0[0];
online = Core.isOnline(url);
online = Core.isOnline(context, url);
SharedPreferences preferences = getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putBoolean("online", online);
editorPreferences.commit();
return Core.isValidCertificate(arg0[0]);
return Core.isValidCertificate(context, arg0[0]);
}