mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-02 17:19:37 +00:00
Included system information on each bundle restart
This commit is contained in:
1 parent
f76296d84b
commit
ea81c28501
1 file changed
+13
-4
+13
-4
@@ -17,9 +17,12 @@ import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleEvent;
|
||||
import org.osgi.framework.BundleException;
|
||||
|
||||
import com.sap.sailing.monitoring.sysinfo.SystemInformation;
|
||||
import com.sap.sailing.monitoring.sysinfo.SystemInformationImpl;
|
||||
|
||||
/**
|
||||
* This monitor tries to restart registered services
|
||||
* on failure. It also sends out email to fixed recipients.
|
||||
* on failure. It also sends out email to fixed recipients including system information.
|
||||
*
|
||||
* @author Simon Pamies (info@pamies.de)
|
||||
* @since Nov 26, 2012
|
||||
@@ -39,6 +42,8 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
|
||||
@Override
|
||||
public void handleFailure(Endpoint endpoint) {
|
||||
SystemInformation info = SystemInformationImpl.getInstance();
|
||||
|
||||
Bundle bundle = getBundleByName(endpoint.getBundleName());
|
||||
if (bundle == null) {
|
||||
log.severe("Couldn't find bundle "+endpoint.getBundleName()+". Cannot restart. Please check monitoring.properties file");
|
||||
@@ -50,6 +55,7 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
log.throwing(getClass().getName(), "handleFailure", e);
|
||||
}
|
||||
} else {
|
||||
final String info_before_restart = info.toString();
|
||||
if (bundle.getState() == BundleEvent.STARTED || bundle.getState() == BundleEvent.STOPPED) {
|
||||
try {
|
||||
bundle.stop();
|
||||
@@ -69,9 +75,12 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
log.info("Sending mail to " + this.properties.getProperty("mail.to") + " saying that bundle "
|
||||
+ endpoint.getBundleName() + " was restarted");
|
||||
try {
|
||||
sendMail(endpoint, subject, "The Bundle " + endpoint.getBundleName() + " has been restarted - check on "
|
||||
String content = "The Bundle " + endpoint.getBundleName() + " has been restarted - check on "
|
||||
+ endpoint + " didn't respond!\n"
|
||||
+ "This Mail won't be sent again if service continues to fail.");
|
||||
+ "This Mail won't be sent again if service continues to fail.";
|
||||
content += "\nSystem Information BEFORE restart:\n" + info_before_restart;
|
||||
content += "\n\nSystem information AFTER restart:\n" + info.toString();
|
||||
sendMail(endpoint, subject, content);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
log.throwing(getClass().getName(), "handleFailure", ex);
|
||||
@@ -85,7 +94,7 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
Session session = Session.getDefaultInstance(this.properties, new SMTPAuthenticator());
|
||||
MimeMessage msg = new MimeMessage(session);
|
||||
msg.setFrom(new InternetAddress("root@sapsailing.com"));
|
||||
msg.setSubject(subject);
|
||||
msg.setSubject(subject);
|
||||
msg.setContent(content, "text/plain");
|
||||
for (String mailAddress : this.properties.getProperty("mail.to").split(",")) {
|
||||
msg.addRecipient(RecipientType.TO, new InternetAddress(mailAddress.trim()));
|
||||
|
||||
Reference in new issue
Block a user