Skip to content

Commit

Permalink
sajat megoldas, hogy menjen a kulonbozo parancsok
Browse files Browse the repository at this point in the history
  • Loading branch information
Elbandi committed Mar 20, 2011
1 parent 8da2546 commit 1057346
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 127 deletions.
14 changes: 14 additions & 0 deletions res/layout/host.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:layout_width="fill_parent" android:layout_margin="5px" android:layout_height="wrap_content" android:id="@+id/hostTvHost"></TextView>
<TextView android:layout_width="fill_parent" android:layout_margin="5px" android:layout_height="wrap_content" android:id="@+id/hostTvInfo"></TextView>
<Button android:layout_width="fill_parent" android:id="@+id/hostBtnDisableCheck" android:layout_height="wrap_content" android:text="Disable Host Checks"></Button>
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/hostBtnDisableNotify" android:text="Disable Host Notifications"></Button>
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/hostBtnEnableServiceCheck" android:text="Enable All Service Checks"></Button>
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/hostBtnDisableServiceCheck" android:text="Disable All Service Checks"></Button>
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/hostBtnEnableServiceNotify" android:text="Enable All Service Notifications"></Button>
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/hostBtnDisableServiceNotify" android:text="Disable All Service Notifications"></Button>
</LinearLayout>
13 changes: 13 additions & 0 deletions res/layout/service.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_margin="5px" android:id="@+id/serviceTvHost"></TextView>
<TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_margin="5px" android:id="@+id/serviceTvService"></TextView>
<TextView android:layout_margin="5px" android:layout_height="wrap_content" android:id="@+id/serviceTvInfo" android:layout_width="fill_parent"></TextView>
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Acknowledge Problem" android:id="@+id/serviceBtnAckProblem"></Button>
<Button android:id="@+id/serviceBtnDisableCheck" android:text="Disable Checks" android:layout_height="wrap_content" android:layout_width="fill_parent"></Button>
<Button android:id="@+id/serviceBtnSchedCheck" android:text="Schedule Immediate Check" android:layout_height="wrap_content" android:layout_width="fill_parent"></Button>
<Button android:id="@+id/serviceBtnDisableNotify" android:text="Disable Notifications" android:layout_height="wrap_content" android:layout_width="fill_parent"></Button>
</LinearLayout>
302 changes: 245 additions & 57 deletions src/de/schoar/nagroid/dialog/ProblemDialog.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package de.schoar.nagroid.dialog;

import android.app.Dialog;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import de.schoar.nagroid.ConfigurationAccess;
import de.schoar.nagroid.DM;
import de.schoar.nagroid.R;
import de.schoar.nagroid.nagios.NagiosExtState;
import de.schoar.nagroid.nagios.NagiosHost;
import de.schoar.nagroid.nagios.NagiosService;
import de.schoar.nagroid.nagios.NagiosSite;
import de.schoar.nagroid.nagios.NagiosState;
import de.schoar.nagroid.nagios.parser.NagiosParsingFailedException;
import de.schoar.nagroid.nagios.parser.NagiosV2Parser;

public class ProblemDialog extends AlertDialog {
public class ProblemDialog extends Dialog {

public ProblemDialog(Context context, AdapterView<?> view, int position) {
super(context);
Expand All @@ -30,73 +39,252 @@ private void init(AdapterView<?> view, int position) {
final NagiosService serviceProblem = (NagiosService) problem;
NagiosExtState serviceExtState = serviceProblem.getExtState();

String msg = "Host: " + serviceProblem.getHost().getName() +
"\nService: " + serviceProblem.getName() +
"\nState: " + serviceProblem.getState();
setContentView(R.layout.service);

TextView tv = (TextView) findViewById(R.id.serviceTvHost);
tv.setText("Host: " + serviceProblem.getHost().getName());

tv = (TextView) findViewById(R.id.serviceTvService);
tv.setText("Service: " + serviceProblem.getName());

tv = (TextView) findViewById(R.id.serviceTvInfo);
if (serviceExtState != null) {
msg += "\nDuration: " + serviceProblem.getExtState().getDuration() +
"\nInfo: " + serviceProblem.getExtState().getInfo();
}

setMessage(msg);
tv.setText("Info: " + serviceExtState.getInfo());
tv.setVisibility(View.VISIBLE);
} else
tv.setVisibility(View.INVISIBLE);

if (serviceProblem.getState() != NagiosState.SERVICE_OK) {
setButton3("Ack", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
new AcknowledgeDialog(lstSite.getContext(), serviceProblem).show();
}
});
setButton2("Snooze", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
new SnoozeDialog(lstSite.getContext(), serviceProblem).show();
}
});
}
setButton("View", new OnClickListener() {
Button btn = (Button) findViewById(R.id.serviceBtnAckProblem);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Context context = lstSite.getContext();
Uri uri = Uri.parse(DM.I.getConfiguration().getNagiosUrl()
+ "/extinfo.cgi?type=2&host="+serviceProblem.getHost().getName()+"&service="+serviceProblem.getName());
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
public void onClick(View view) {
new AcknowledgeDialog(lstSite.getContext(), serviceProblem).show();
}
});
}
else if (problem.getClass() == NagiosHost.class) {
});
btn = (Button) findViewById(R.id.serviceBtnDisableCheck);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowAlert(lstSite.getContext(), "Disable Check", "Really?", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DisableCheck(serviceProblem, NagiosV2Parser.DisableChecks);
DM.I.getPollHandler().poll();
}
});
}
});
btn = (Button) findViewById(R.id.serviceBtnDisableNotify);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowAlert(lstSite.getContext(), "Disable Notify", "Really?", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DisableNotify(serviceProblem, NagiosV2Parser.DisableNotifications);
DM.I.getPollHandler().poll();
}
});
}
});
btn = (Button) findViewById(R.id.serviceBtnSchedCheck);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ScheduleCheck(serviceProblem);
DM.I.getPollHandler().poll();
}
});
} else if (problem.getClass() == NagiosHost.class) {
final NagiosHost hostProblem = (NagiosHost) problem;
setContentView(R.layout.host);

setMessage("Host: " + hostProblem.getName() +
"\nState: " + hostProblem.getState() +
"\nService Problems: " + hostProblem.getServices().size());
TextView tv = (TextView) findViewById(R.id.hostTvHost);
tv.setText("Host: " + hostProblem.getName());

if (hostProblem.getState() != NagiosState.HOST_UP) {
setButton3("Ack", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
new AcknowledgeDialog(lstSite.getContext(), hostProblem).show();
}
});
setButton2("Actions", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
new SnoozeDialog(lstSite.getContext(), hostProblem).show();
}
});
}
setButton("View", new OnClickListener() {
tv = (TextView) findViewById(R.id.hostTvInfo);
tv.setText("Service Problems: " + hostProblem.getServices().size());

Button btn = (Button) findViewById(R.id.hostBtnDisableServiceCheck);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ChangeServiceCheck(hostProblem, NagiosV2Parser.DisableAllServiceChecks, "Disable All Check");
}
});
btn = (Button) findViewById(R.id.hostBtnEnableServiceCheck);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Context context = lstSite.getContext();
Uri uri = Uri.parse(DM.I.getConfiguration().getNagiosUrl()
+ "/status.cgi?host="+hostProblem.getName());
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
public void onClick(View view) {
ChangeServiceCheck(hostProblem, NagiosV2Parser.EnableAllServiceChecks, "Enable All Check");
}
});
});
btn = (Button) findViewById(R.id.hostBtnDisableServiceNotify);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ChangeServiceNotify(hostProblem, NagiosV2Parser.DisableAllServiceChecks, "Disable All Notify");
}
});
btn = (Button) findViewById(R.id.hostBtnEnableServiceNotify);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ChangeServiceNotify(hostProblem, NagiosV2Parser.EnableAllServiceChecks, "Enable All Notify");
}
});
btn = (Button) findViewById(R.id.hostBtnDisableCheck);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowAlert(lstSite.getContext(), "Disable Check", "Really?", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DisableCheck(hostProblem, NagiosV2Parser.DisableHostChecks);
DM.I.getPollHandler().poll();
}
});
}
});
btn = (Button) findViewById(R.id.hostBtnDisableNotify);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowAlert(lstSite.getContext(), "Disable Notify", "Really?", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DisableNotify(hostProblem, NagiosV2Parser.DisableHostNotifications);
DM.I.getPollHandler().poll();
}
});
}
});

}

setCancelable(true);
}

private void ShowAlert(Context context, String title, String message, DialogInterface.OnClickListener cl) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.setPositiveButton("Yes" /* android.R.string.yes */, cl);
builder.setNegativeButton("no" /* android.R.string.no */, null);
builder.show();
}

private void ShowResDialog(String title, String cmdRes) {
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
builder.setTitle(title);
builder.setMessage(cmdRes);
builder.setCancelable(true);
builder.setPositiveButton("OK", null);
builder.show();
}

private void DisableCheck(Object o, int type) {

This comment has been minimized.

Copy link
@Elbandi

Elbandi Mar 20, 2011

Author Owner

eh, why hasnt java macro feature? :(

// Not working :(
// ProgressDialog busyDialog = ProgressDialog.show(this.getContext(),
// "", "Sending Acknowledge...", true);

ConfigurationAccess ca = DM.I.getConfiguration();
NagiosSite site = ca.getNagiosSite();
try {
String cmdRes = new NagiosV2Parser(site).SendCmd(o, type, null);

// busyDialog.dismiss();
ShowResDialog("Disable Check", cmdRes);
} catch (NagiosParsingFailedException e) {
// Log.d("NagiosAcknowledge", "Nagios Acknowledge failed!", e);
DM.I.getNagroidLog().addLogWithTime("DisableCheck: Failed: " + e.getMessage());
return;
}

DM.I.getNagroidLog().addLogWithTime("DisableCheck: Ok");
}

private void DisableNotify(Object o, int type) {
// Not working :(
// ProgressDialog busyDialog = ProgressDialog.show(this.getContext(),
// "", "Sending Acknowledge...", true);

ConfigurationAccess ca = DM.I.getConfiguration();
NagiosSite site = ca.getNagiosSite();
try {
String cmdRes = new NagiosV2Parser(site).SendCmd(o, type, null);
// busyDialog.dismiss();
ShowResDialog("Disable Notify", cmdRes);
} catch (NagiosParsingFailedException e) {
// Log.d("NagiosAcknowledge", "Nagios Acknowledge failed!", e);
DM.I.getNagroidLog().addLogWithTime("DisableNotify: Failed: " + e.getMessage());
return;
}

DM.I.getNagroidLog().addLogWithTime("DisableNotify: Ok");
}

private void ScheduleCheck(Object o) {
// Not working :(
// ProgressDialog busyDialog = ProgressDialog.show(this.getContext(),
// "", "Sending Acknowledge...", true);

ConfigurationAccess ca = DM.I.getConfiguration();
NagiosSite site = ca.getNagiosSite();
try {
String cmdRes = new NagiosV2Parser(site).ScheduleImmediateCheck(o);

// busyDialog.dismiss();

ShowResDialog("Schedule Check", cmdRes);
} catch (NagiosParsingFailedException e) {
// Log.d("NagiosAcknowledge", "Nagios Acknowledge failed!", e);
DM.I.getNagroidLog().addLogWithTime("ScheduleCheck: Failed: " + e.getMessage());
return;
}

DM.I.getNagroidLog().addLogWithTime("ScheduleCheck: Ok");
}

private void ChangeServiceCheck(Object o, int type, String title) {
// Not working :(
// ProgressDialog busyDialog = ProgressDialog.show(this.getContext(),
// "", "Sending Acknowledge...", true);

ConfigurationAccess ca = DM.I.getConfiguration();
NagiosSite site = ca.getNagiosSite();
try {
String cmdRes = new NagiosV2Parser(site).SendCmd(o, type, null);

// busyDialog.dismiss();
ShowResDialog(title, cmdRes);
} catch (NagiosParsingFailedException e) {
// Log.d("NagiosAcknowledge", "Nagios Acknowledge failed!", e);
DM.I.getNagroidLog().addLogWithTime("ChangeServiceCheck: Failed: " + e.getMessage());
return;
}

DM.I.getNagroidLog().addLogWithTime(title + ": Ok");
}

private void ChangeServiceNotify(Object o, int type, String title) {
// Not working :(
// ProgressDialog busyDialog = ProgressDialog.show(this.getContext(),
// "", "Sending Acknowledge...", true);

ConfigurationAccess ca = DM.I.getConfiguration();
NagiosSite site = ca.getNagiosSite();
try {
String cmdRes = new NagiosV2Parser(site).SendCmd(o, type, null);
// busyDialog.dismiss();
ShowResDialog(title, cmdRes);
} catch (NagiosParsingFailedException e) {
// Log.d("NagiosAcknowledge", "Nagios Acknowledge failed!", e);
DM.I.getNagroidLog().addLogWithTime("ChangeServiceNotify: Failed: " + e.getMessage());
return;
}

DM.I.getNagroidLog().addLogWithTime(title + ": Ok");
}
}
Loading

0 comments on commit 1057346

Please sign in to comment.