Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feedback can now collects all logs #248

Merged
merged 1 commit into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions DesktopEdge/MainMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using NLog.Targets;

using ZitiDesktopEdge.Server;
using System.Threading.Tasks;
using ZitiDesktopEdge.DataStructures;

namespace ZitiDesktopEdge
{
Expand Down Expand Up @@ -223,7 +225,8 @@ private void ShowPrivacy(object sender, MouseButtonEventArgs e) {
private void ShowTerms(object sender, MouseButtonEventArgs e) {
Process.Start(new ProcessStartInfo("https://netfoundry.io/terms") { UseShellExecute = true });
}
private void ShowFeedback(object sender, MouseButtonEventArgs e) {

async private void ShowFeedback(object sender, MouseButtonEventArgs e) {
DataClient client = (DataClient)Application.Current.Properties["ServiceClient"];
var mailMessage = new MailMessage();
mailMessage.From = new MailAddress("[email protected]");
Expand All @@ -232,18 +235,11 @@ private void ShowFeedback(object sender, MouseButtonEventArgs e) {
mailMessage.Body = "";

string timestamp = DateTime.Now.ToFileTime().ToString();
string serviceLogTempFile = Path.Combine(Path.GetTempPath(), timestamp+"-Ziti-Service.log");
using (StreamWriter sw = new StreamWriter(serviceLogTempFile)) {
sw.WriteLine(client.GetLogs());
}

string uiLogTempFile = Path.Combine(Path.GetTempPath(), timestamp+"-Ziti-Application.log");
using (StreamWriter sw = new StreamWriter(uiLogTempFile)) {
sw.WriteLine(UILog.GetLogs());
}

mailMessage.Attachments.Add(new Attachment(serviceLogTempFile));
mailMessage.Attachments.Add(new Attachment(uiLogTempFile));
var monitorClient = (MonitorClient)Application.Current.Properties["MonitorClient"];
ServiceStatusEvent resp = await monitorClient.CaptureLogsAsync();
string pathToLogs = resp.Message;
logger.Info("Log files found at : {0}", resp.Message);
mailMessage.Attachments.Add(new Attachment(pathToLogs));

string emlFile = Path.Combine(Path.GetTempPath(), timestamp+"-ziti.eml");

Expand All @@ -260,12 +256,14 @@ private void ShowFeedback(object sender, MouseButtonEventArgs e) {
closeMethod.Invoke(mailWriter, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { }, null);
}

Process.Start(emlFile);



//string body = HttpUtility.UrlEncode("\n\nService Logs\n\n" + client.GetLogs());// + "\n\nApplication Logs\n\n" + UILog.GetLogs());
//Process.Start(new ProcessStartInfo("mailto:[email protected]?subject=Ziti%20Support&body="+body) { UseShellExecute = true });
var p = Process.Start(emlFile);
Task.Run(async () => {
logger.Info("Waiting to send email...");
p.WaitForExit();
logger.Info("Email sent or cancelled... removing file: {0}", emlFile);
File.Delete(emlFile);
logger.Info("file removed: {0}", emlFile);
});
}
private void ShowSupport(object sender, MouseButtonEventArgs e) {
Process.Start(new ProcessStartInfo("https://openziti.discourse.group/") { UseShellExecute = true });
Expand Down
19 changes: 15 additions & 4 deletions DesktopEdge/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,13 @@ async private void MainWindow_Loaded(object sender, RoutedEventArgs e) {
serviceClient.OnMetricsEvent += ServiceClient_OnMetricsEvent;
serviceClient.OnServiceEvent += ServiceClient_OnServiceEvent;
serviceClient.OnTunnelStatusEvent += ServiceClient_OnTunnelStatusEvent;
Application.Current.Properties.Add("ServiceClient", serviceClient);

monitorClient = new MonitorClient();
monitorClient.OnClientConnected += MonitorClient_OnClientConnected;
monitorClient.OnServiceStatusEvent += MonitorClient_OnServiceStatusEvent;
Application.Current.Properties.Add("MonitorClient", monitorClient);

Application.Current.Properties.Add("ServiceClient", serviceClient);
Application.Current.Properties.Add("Identities", new List<ZitiIdentity>());
MainMenu.OnAttachmentChange += AttachmentChanged;
MainMenu.OnLogLevelChanged += LogLevelChanged;
Expand Down Expand Up @@ -567,11 +568,9 @@ private void LoadIdentities(Boolean repaint) {
}

private void Id_OnStatusChanged(bool attached) {
bool isActive = false;
for (int i = 0; i < IdList.Children.Count; i++) {
IdentityItem item = IdList.Children[i] as IdentityItem;
if (item.ToggleSwitch.Enabled) {
isActive = true;
break;
}
}
Expand Down Expand Up @@ -817,5 +816,17 @@ public LogLevelEnum NextLevel() {
private void IdList_LayoutUpdated(object sender, EventArgs e) {
Placement();
}
}

async private void CollectLogFileClick(object sender, RoutedEventArgs e) {
await CollectLogFiles();
}
async private Task CollectLogFiles() {
ServiceStatusEvent resp = await monitorClient.CaptureLogsAsync();
logger.Info("response: {0}", resp.Message);
}

private void Button_Click(object sender, RoutedEventArgs e) {

}
}
}
2 changes: 1 addition & 1 deletion DesktopEdge/ZitiDesktopEdge.log.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<targets>
<target name="logconsole" xsi:type="Console" />
<target name="LogFile" xsi:type="File"
layout="[${date:format=yyyy-MM-ddTHH:mm:ss.fff}Z] ${level:uppercase=true:padding=5}\t${logger}\t${message}\t${exception:format=tostring}"
layout="[${date:format=yyyy-MM-ddTHH:mm:ss.fff}Z] ${level:uppercase=true:padding=5}&#009;${logger}&#009;${message}&#009;${exception:format=tostring}"
fileName="logs\UI\ZitiDesktopEdge.log"
archiveEvery="Day"
archiveNumbering="Date"
Expand Down
28 changes: 22 additions & 6 deletions ZitiDesktopEdge.Client/Server/IPCServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class IPCServer {
private string ipcPipeName;
private string eventPipeName;

public delegate string CaptureLogsDelegate();
public CaptureLogsDelegate CaptureLogs { get; set; }

public IPCServer() {
this.ipcPipeName = IPCServer.PipeName;
this.eventPipeName = IPCServer.EventPipeName;
Expand Down Expand Up @@ -156,12 +159,12 @@ async public Task handleEventClientAsync(NamedPipeServerStream ss) {
}
}

async public Task processMessageAsync(string msg, StreamWriter writer) {
Logger.Debug("message received: {0}", msg);
async public Task processMessageAsync(string json, StreamWriter writer) {
Logger.Debug("message received: {0}", json);
var r = new SvcResponse();
var rr = new ServiceStatusEvent();
try {
ActionEvent ae = serializer.Deserialize<ActionEvent>(new JsonTextReader(new StringReader(msg)));
ActionEvent ae = serializer.Deserialize<ActionEvent>(new JsonTextReader(new StringReader(json)));
Logger.Info("Op: {0}", ae.Op);
switch (ae.Op.ToLower()) {
case "stop":
Expand Down Expand Up @@ -195,15 +198,28 @@ async public Task processMessageAsync(string msg, StreamWriter writer) {
rr.Status = ServiceActions.ServiceStatus();
r = rr;
break;
case "capturelogs":
try {
string results = CaptureLogs();
r.Message = results;
} catch(Exception ex) {
string err = string.Format("UNKNOWN ERROR : {0}", ex.Message);
Logger.Error(ex, err);
r.Code = -5;
r.Message = "FAILURE";
r.Error = err;
}
break;
default:
msg = string.Format("UNKNOWN ACTION received: {0}", ae.Op);
Logger.Error(msg);
r.Message = "FAILURE";
r.Code = -3;
r.Error = msg;
r.Error = string.Format("UNKNOWN ACTION received: {0}", ae.Op);
Logger.Error(r.Message);
break;
}
} catch (Exception e) {
Logger.Error(e, "Unexpected erorr in processMessage!");
r.Message = "FAILURE";
r.Code = -2;
r.Error = e.Message + ":" + e?.InnerException?.Message;
}
Expand Down
6 changes: 6 additions & 0 deletions ZitiDesktopEdge.Client/ServiceClient/MonitorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,11 @@ async public Task<ServiceStatusEvent> Status() {
await sendAsync(action);
return await readAsync<ServiceStatusEvent>(ipcReader, "Status");
}
async public Task<ServiceStatusEvent> CaptureLogsAsync() {
ActionEvent action = new ActionEvent() { Action = "Normal", Op = "captureLogs" };
//string result = await SendServiceFunctionAsync(action);
await sendAsync(action);
return await readAsync<ServiceStatusEvent>(ipcReader, "CaptureLogsAsync");
}
}
}
28 changes: 24 additions & 4 deletions ZitiUpdateService/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public partial class UpdateService : ServiceBase {
private bool inUpdateCheck = false;

private string _versionType = "latest";
private string exeLocation = null;

private DataClient svc = new DataClient();
private bool running = false;
Expand All @@ -36,22 +37,42 @@ public partial class UpdateService : ServiceBase {
Version assemblyVersion = null;

ServiceController controller;
ZitiDesktopEdge.Server.IPCServer svr = new ZitiDesktopEdge.Server.IPCServer();
IPCServer svr = new IPCServer();
Task ipcServer = null;
Task eventServer = null;
IUpdateCheck check = null;

public UpdateService() {
InitializeComponent();
exeLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

Logger.Info("Initializing");
svc.OnClientConnected += Svc_OnClientConnected;
svc.OnTunnelStatusEvent += Svc_OnTunnelStatusEvent;
svc.OnClientDisconnected += Svc_OnClientDisconnected;
svc.OnShutdownEvent += Svc_OnShutdownEvent;

svr.CaptureLogs = GetLogs;
}

private string GetLogs() {
Logger.Info("Request to collect logs received");
var ps = System.Management.Automation.PowerShell.Create();
string script = Path.Combine(exeLocation, "collect-logs.ps1");
ps.Commands.AddScript(script);
var results = ps.Invoke();
Logger.Info("Collected logs.");
for(int i=0; i<results.Count; i++) {
string r = results[i].ToString();
Logger.Info(r);
if (r.Contains("Log location")) {
return r.Trim().Substring("Log location: ".Length);
}
}
return "success but log location not found.";
}

public void Debug() {
public void Debug() {
OnStart(null);// new string[] { "FilesystemCheck" });
}

Expand All @@ -63,8 +84,7 @@ protected override void OnStart(string[] args) {
Logger.Info(e.ToString());
}

var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var logs = Path.Combine(root, "logs");
var logs = Path.Combine(exeLocation, "logs");
addLogsFolder(logs);
addLogsFolder(Path.Combine(logs, "UI"));
addLogsFolder(Path.Combine(logs, "ZitiMonitorService"));
Expand Down
2 changes: 1 addition & 1 deletion ZitiUpdateService/ziti-monitor-log.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<targets>
<target name="logconsole" xsi:type="Console" />
<target name="LogFile" xsi:type="File"
layout="[${date:format=yyyy-MM-ddTHH:mm:ss.fff}Z] ${level:uppercase=true:padding=5}\t${logger}\t${message}\t${exception:format=tostring}"
layout="[${date:format=yyyy-MM-ddTHH:mm:ss.fff}Z] ${level:uppercase=true:padding=5}&#009;${logger}&#009;${message}&#009;${exception:format=tostring}"
fileName="logs\ZitiMonitorService\ZitiUpdateService.log"
archiveEvery="Day"
archiveNumbering="Date"
Expand Down