mirror of
https://github.com/openziti/desktop-edge-win.git
synced 2026-10-13 00:02:50 +00:00
Merge pull request #248 from openziti/issue-201-collect-logs-using-ui
feedback can now collects all logs
This commit is contained in:
@@ -18,6 +18,8 @@ using NLog.Config;
|
||||
using NLog.Targets;
|
||||
|
||||
using ZitiDesktopEdge.Server;
|
||||
using System.Threading.Tasks;
|
||||
using ZitiDesktopEdge.DataStructures;
|
||||
|
||||
namespace ZitiDesktopEdge
|
||||
{
|
||||
@@ -223,7 +225,8 @@ namespace ZitiDesktopEdge
|
||||
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("ziti-support@netfoundry.io");
|
||||
@@ -232,18 +235,11 @@ namespace ZitiDesktopEdge
|
||||
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");
|
||||
|
||||
@@ -260,12 +256,14 @@ namespace ZitiDesktopEdge
|
||||
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:ziti-support@netfoundry.io?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 });
|
||||
|
||||
@@ -187,12 +187,13 @@ namespace ZitiDesktopEdge {
|
||||
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;
|
||||
@@ -567,11 +568,9 @@ namespace ZitiDesktopEdge {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -817,5 +816,17 @@ namespace ZitiDesktopEdge {
|
||||
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) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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}	${logger}	${message}	${exception:format=tostring}"
|
||||
fileName="logs\UI\ZitiDesktopEdge.log"
|
||||
archiveEvery="Day"
|
||||
archiveNumbering="Date"
|
||||
|
||||
@@ -22,6 +22,9 @@ namespace ZitiDesktopEdge.Server {
|
||||
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;
|
||||
@@ -156,12 +159,12 @@ namespace ZitiDesktopEdge.Server {
|
||||
}
|
||||
}
|
||||
|
||||
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":
|
||||
@@ -195,15 +198,28 @@ namespace ZitiDesktopEdge.Server {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -91,5 +91,11 @@ namespace ZitiDesktopEdge.ServiceClient {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ namespace ZitiUpdateService {
|
||||
private bool inUpdateCheck = false;
|
||||
|
||||
private string _versionType = "latest";
|
||||
private string exeLocation = null;
|
||||
|
||||
private DataClient svc = new DataClient();
|
||||
private bool running = false;
|
||||
@@ -36,22 +37,42 @@ namespace ZitiUpdateService {
|
||||
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;
|
||||
}
|
||||
|
||||
public void Debug() {
|
||||
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() {
|
||||
OnStart(null);// new string[] { "FilesystemCheck" });
|
||||
}
|
||||
|
||||
@@ -63,8 +84,7 @@ namespace ZitiUpdateService {
|
||||
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"));
|
||||
|
||||
@@ -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}	${logger}	${message}	${exception:format=tostring}"
|
||||
fileName="logs\ZitiMonitorService\ZitiUpdateService.log"
|
||||
archiveEvery="Day"
|
||||
archiveNumbering="Date"
|
||||
|
||||
Reference in New Issue
Block a user