package yami;

import java.util.List;

import yami.configuration.ConfigurationManager;
import yami.configuration.HttpCollector;
import yami.configuration.Node;
import yami.mail.SendMailTLS;
import yami.model.Constants;
import yami.model.Result;

public class SendMailStrategy
{
	
	public void mailCollectorResult(List<String> mailingList, HttpCollector c, Node n, Result results)
	{
		String successString = results.success() ? "OK" : "FAIL";
		String subject = "yami monitor '" + c.name + "' on " + n.nick() + " is now " + successString;
		String content = "Collector current status: " + Constants.CLIENT_LINK.replace(Constants.CLIENT_PORT, ConfigurationManager.getInstance().getCurrentGlobalConfiguration().getClientPort() + "").replace(Constants.NODE_NAME, n.name).replace(Constants.PEER_NAME, n.peer.dnsName()).replace(Constants.COLLECTOR_NAME, c.name) + "\n\n";
		content += "Dashboard: " + Constants.getServerDashboard() + "\n\n";
		content += "Collector Output:\n";
		content += results.output + "\n";
		ConfigurationManager cm = ConfigurationManager.getInstance();
		if (null == cm.getCurrentGlobalConfiguration() || null == cm.getCurrentGlobalConfiguration().email_configuration)
		{
		    Send.mail(subject, content, mailingList);
		}
		else
		{
		    SendMailTLS.mail(subject, content, mailingList, cm.getCurrentGlobalConfiguration().email_configuration);
		}
	}
}

@@ -169,53 +169,203 @@
 ami.
-mail.SendMailTLS;%0Aimport yami.model.Constants
+configuration.VersionCollector;%0Aimport yami.mail.CollectorOnNodeState;%0Aimport yami.mail.SendMailTLS;%0Aimport yami.model.Constants;%0Aimport yami.model.DataStore;%0Aimport yami.model.DataStoreRetriever
 ;%0Aim
@@ -586,16 +586,50 @@
 %22FAIL%22;%0A
+%09%09String version = getVersion(n);%0A
 %09%09String
@@ -687,16 +687,26 @@
 nick() +
+ version +
  %22 is no
@@ -1561,10 +1561,268 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09%0A%09private String getVersion(Node node) %0A%09%7B%0A%09%09DataStore ds = DataStoreRetriever.getD();%0A%09%09CollectorOnNodeState result = ds.getResult(node, new VersionCollector());%0A%09%09if (null == result)%0A%09%09%7B%0A%09%09%09return %22%22;%0A%09%09%7D%0A%09%09return %22version %22 + result.getLast().output;%0A%09%7D%0A
 %7D%0A

add version to mail