2017-07-04 14:18:59 +02:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
2017-06-16 12:54:49 +02:00
|
|
|
|
using System.Collections.Generic;
|
2017-06-26 23:06:45 +02:00
|
|
|
|
using System.Diagnostics;
|
2017-06-16 12:54:49 +02:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Web.Script.Serialization;
|
2017-06-28 08:24:21 +02:00
|
|
|
|
using XenAdmin.Model;
|
2017-06-16 12:54:49 +02:00
|
|
|
|
using XenAdmin.Plugins;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
2017-06-26 23:06:45 +02:00
|
|
|
|
namespace XenAdmin.Core
|
2017-06-16 12:54:49 +02:00
|
|
|
|
{
|
2017-06-26 23:06:45 +02:00
|
|
|
|
public static class Metadata
|
2017-06-16 12:54:49 +02:00
|
|
|
|
{
|
2017-06-26 23:06:45 +02:00
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
2017-06-16 12:54:49 +02:00
|
|
|
|
|
2017-06-26 23:06:45 +02:00
|
|
|
|
internal struct XenCenterMetadata
|
|
|
|
|
{
|
|
|
|
|
public SystemInfo System;
|
|
|
|
|
public XenCenterSettings Settings;
|
|
|
|
|
public XenCenterInfrastructure Infrastructure;
|
|
|
|
|
public List<Plugin> Plugins;
|
|
|
|
|
public string SourceOfData;
|
2017-06-28 08:24:21 +02:00
|
|
|
|
public string Created;
|
|
|
|
|
public string Reported;
|
2017-06-26 23:06:45 +02:00
|
|
|
|
}
|
2017-06-16 12:54:49 +02:00
|
|
|
|
|
2017-06-26 23:06:45 +02:00
|
|
|
|
internal struct SystemInfo
|
|
|
|
|
{
|
|
|
|
|
public string Version;
|
|
|
|
|
public string DotNetVersion;
|
|
|
|
|
public string Culture;
|
|
|
|
|
public string OsVersion;
|
|
|
|
|
public string OsCulture;
|
|
|
|
|
public string IpAddress;
|
|
|
|
|
public string Uuid;
|
|
|
|
|
public string Uptime;
|
|
|
|
|
}
|
2017-06-16 12:54:49 +02:00
|
|
|
|
|
2017-06-26 23:06:45 +02:00
|
|
|
|
internal struct CFU
|
|
|
|
|
{
|
|
|
|
|
public bool AllowXenCenterUpdates;
|
|
|
|
|
public bool AllowPatchesUpdates;
|
|
|
|
|
public bool AllowXenServerUpdates;
|
|
|
|
|
}
|
2017-06-16 12:54:49 +02:00
|
|
|
|
|
2017-06-26 23:06:45 +02:00
|
|
|
|
internal struct Proxy
|
|
|
|
|
{
|
|
|
|
|
public bool UseProxy;
|
|
|
|
|
public bool UseIEProxy;
|
|
|
|
|
public bool BypassProxyForServers;
|
|
|
|
|
public bool ProxyAuthentication;
|
|
|
|
|
public string ProxyAuthenticationMethod;
|
|
|
|
|
}
|
2017-06-16 12:54:49 +02:00
|
|
|
|
|
2017-06-26 23:06:45 +02:00
|
|
|
|
internal struct SaveAndRestore
|
|
|
|
|
{
|
|
|
|
|
public bool SaveSessionCredentials;
|
|
|
|
|
public bool RequireMasterPassword;
|
|
|
|
|
}
|
2017-06-16 12:54:49 +02:00
|
|
|
|
|
2017-06-26 23:06:45 +02:00
|
|
|
|
internal struct XenCenterSettings
|
|
|
|
|
{
|
|
|
|
|
public CFU CFU;
|
|
|
|
|
public Proxy Proxy;
|
|
|
|
|
public SaveAndRestore SaveAndRestore;
|
|
|
|
|
public string HelpLastUsed;
|
|
|
|
|
}
|
2017-06-16 12:54:49 +02:00
|
|
|
|
|
2017-06-26 23:06:45 +02:00
|
|
|
|
internal struct XenCenterInfrastructure
|
|
|
|
|
{
|
|
|
|
|
public int TotalConnections;
|
|
|
|
|
public int Connected;
|
|
|
|
|
}
|
2017-06-16 12:54:49 +02:00
|
|
|
|
|
2017-06-26 23:06:45 +02:00
|
|
|
|
internal struct Plugin
|
|
|
|
|
{
|
|
|
|
|
public string Name;
|
|
|
|
|
public string Organization;
|
|
|
|
|
public bool Enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Generate(PluginManager pluginManager, bool isForXenCenter)
|
2017-06-16 12:54:49 +02:00
|
|
|
|
{
|
|
|
|
|
var metadata = new XenCenterMetadata
|
|
|
|
|
{
|
|
|
|
|
System = new SystemInfo
|
|
|
|
|
{
|
|
|
|
|
Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
|
|
|
|
|
DotNetVersion = Environment.Version.ToString(4),
|
|
|
|
|
Culture = Thread.CurrentThread.CurrentUICulture.EnglishName,
|
|
|
|
|
OsVersion = Environment.OSVersion.ToString(),
|
2017-07-05 12:19:07 +02:00
|
|
|
|
OsCulture = CultureInfo.CurrentUICulture.EnglishName,
|
2017-06-26 23:06:45 +02:00
|
|
|
|
IpAddress = GetLocalIPAddress(),
|
|
|
|
|
Uuid = Updates.GetUniqueIdHash(),
|
2017-06-27 11:58:42 +02:00
|
|
|
|
Uptime = isForXenCenter ? (DateTime.Now - Process.GetCurrentProcess().StartTime).ToString() : string.Empty
|
2017-06-16 12:54:49 +02:00
|
|
|
|
},
|
|
|
|
|
Settings = new XenCenterSettings
|
|
|
|
|
{
|
|
|
|
|
CFU = new CFU
|
|
|
|
|
{
|
|
|
|
|
AllowXenCenterUpdates = Properties.Settings.Default.AllowXenCenterUpdates,
|
|
|
|
|
AllowPatchesUpdates = Properties.Settings.Default.AllowPatchesUpdates,
|
|
|
|
|
AllowXenServerUpdates = Properties.Settings.Default.AllowXenServerUpdates
|
|
|
|
|
},
|
|
|
|
|
Proxy = new Proxy
|
|
|
|
|
{
|
|
|
|
|
UseProxy = (HTTPHelper.ProxyStyle) Properties.Settings.Default.ProxySetting == HTTPHelper.ProxyStyle.SpecifiedProxy,
|
|
|
|
|
UseIEProxy = (HTTPHelper.ProxyStyle) Properties.Settings.Default.ProxySetting == HTTPHelper.ProxyStyle.SystemProxy,
|
|
|
|
|
BypassProxyForServers = Properties.Settings.Default.BypassProxyForServers,
|
|
|
|
|
ProxyAuthentication = Properties.Settings.Default.ProvideProxyAuthentication,
|
|
|
|
|
ProxyAuthenticationMethod = ((HTTP.ProxyAuthenticationMethod)Properties.Settings.Default.ProxyAuthenticationMethod).ToString()
|
|
|
|
|
},
|
|
|
|
|
SaveAndRestore = new SaveAndRestore
|
|
|
|
|
{
|
|
|
|
|
SaveSessionCredentials = Properties.Settings.Default.SaveSession,
|
|
|
|
|
RequireMasterPassword = Properties.Settings.Default.RequirePass
|
|
|
|
|
},
|
|
|
|
|
HelpLastUsed = Properties.Settings.Default.HelpLastUsed
|
|
|
|
|
},
|
|
|
|
|
Infrastructure = new XenCenterInfrastructure
|
|
|
|
|
{
|
|
|
|
|
TotalConnections = ConnectionsManager.XenConnectionsCopy.Count,
|
|
|
|
|
Connected = ConnectionsManager.XenConnectionsCopy.Count(c => c.IsConnected)
|
|
|
|
|
},
|
|
|
|
|
Plugins = new List<Plugin>(),
|
2017-06-28 08:24:21 +02:00
|
|
|
|
SourceOfData = isForXenCenter ? Messages.XENCENTER : Messages.HEALTH_CHECK,
|
|
|
|
|
Created = DateTime.UtcNow.ToString("u"),
|
|
|
|
|
Reported = isForXenCenter ? DateTime.UtcNow.ToString("u") : HealthCheckSettings.REPORT_TIME_PLACEHOLDER
|
2017-06-16 12:54:49 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (pluginManager != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var plugin in pluginManager.Plugins)
|
|
|
|
|
{
|
|
|
|
|
metadata.Plugins.Add(new Plugin
|
|
|
|
|
{
|
|
|
|
|
Name = plugin.Name,
|
|
|
|
|
Organization = plugin.Organization,
|
|
|
|
|
Enabled = plugin.Enabled
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var obj = new Dictionary<string, object> {{Messages.XENCENTER, metadata}};
|
|
|
|
|
return new JavaScriptSerializer().Serialize(obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetLocalIPAddress()
|
|
|
|
|
{
|
2017-06-26 23:06:45 +02:00
|
|
|
|
IPAddress ipAddress = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var host = Dns.GetHostEntry(Dns.GetHostName());
|
2017-06-27 11:58:42 +02:00
|
|
|
|
ipAddress = host.AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
|
2017-06-26 23:06:45 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.ErrorFormat("Exception while getting the local IP address: {0}", e.Message);
|
|
|
|
|
}
|
2017-06-27 11:58:42 +02:00
|
|
|
|
return ipAddress != null ? ipAddress.ToString() : String.Empty;
|
2017-06-16 12:54:49 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|