CP-13592: Add reg to store upload url and time interval

Signed-off-by: Cheng Zhang <cheng.zhang@citrix.com>
This commit is contained in:
Cheng Zhang 2015-08-07 12:01:02 +08:00
parent 9ccd52752b
commit 1fc91d2381
7 changed files with 178 additions and 80 deletions

View File

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18444
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@ -36,32 +36,6 @@ namespace XenServerHealthCheck.Properties {
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
[global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
public string UPLOAD_URL {
get {
return ((string)(this["UPLOAD_URL"]));
}
set {
this["UPLOAD_URL"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
[global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
public int UploadTimeIntervalInMinutes {
get {
return ((int)(this["UploadTimeIntervalInMinutes"]));
}
set {
this["UploadTimeIntervalInMinutes"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("40000")]

View File

@ -1,37 +1,31 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="XenServerHealthCheck" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="UUID" Roaming="true" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="UPLOAD_URL" Roaming="true" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="UploadTimeIntervalInMinutes" Roaming="true" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="HttpTimeout" Roaming="true" Type="System.Int32" Scope="User">
<Value Profile="(Default)">40000</Value>
</Setting>
<Setting Name="ServerList" Roaming="true" Type="System.String[]" Scope="User">
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="XenServerHealthCheck.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="UUID" Roaming="true" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="HttpTimeout" Roaming="true" Type="System.Int32" Scope="User">
<Value Profile="(Default)">40000</Value>
</Setting>
<Setting Name="ServerList" Roaming="true" Type="System.String[]" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /&gt;</Value>
</Setting>
<Setting Name="ProxySetting" Roaming="true" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="ProxyAddress" Roaming="true" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="BypassProxyForLocal" Roaming="true" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="ProxyPort" Roaming="true" Type="System.Int32" Scope="User">
<Value Profile="(Default)">80</Value>
</Setting>
<Setting Name="ConnectionTimeout" Roaming="true" Type="System.Int32" Scope="User">
<Value Profile="(Default)">20000</Value>
</Setting>
</Settings>
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /&gt;</Value>
</Setting>
<Setting Name="ProxySetting" Roaming="true" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="ProxyAddress" Roaming="true" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="BypassProxyForLocal" Roaming="true" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="ProxyPort" Roaming="true" Type="System.Int32" Scope="User">
<Value Profile="(Default)">80</Value>
</Setting>
<Setting Name="ConnectionTimeout" Roaming="true" Type="System.Int32" Scope="User">
<Value Profile="(Default)">20000</Value>
</Setting>
</Settings>
</SettingsFile>

121
XenServerHealthCheck/Registry.cs Executable file
View File

@ -0,0 +1,121 @@
/* 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;
using Microsoft.Win32;
namespace XenServerHealthCheck
{
public class Registry
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// Reads a key from XENCENTER_LOCAL_KEYS\k.
/// </summary>
private static string ReadKey(string k, string def)
{
try
{
RegistryKey masterKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(HEALTH_CHECK_LOCAL_KEYS);
if (masterKey == null)
return def;
try
{
var v = masterKey.GetValue(k);
return (v != null) ? v.ToString() : def;
}
finally
{
masterKey.Close();
}
}
catch (Exception e)
{
log.DebugFormat(@"Failed to read {0}\{1} from registry; assuming NULL.", HEALTH_CHECK_LOCAL_KEYS, k);
log.Debug(e, e);
return def;
}
}
/// <summary>
/// Read a true/false key from XENCENTER_LOCAL_KEYS\k.
/// </summary>
/// <returns>False if the value is "false" (case insensitive), true if the key is present but not
/// "false", def otherwise.</returns>
private static Int32 ReadLong(string k, Int32 def)
{
try
{
RegistryKey masterKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(HEALTH_CHECK_LOCAL_KEYS);
if (masterKey == null)
return def;
try
{
object v = masterKey.GetValue(k);
if (v == null)
return def;
else
return Convert.ToInt32(v);
}
finally
{
masterKey.Close();
}
}
catch (Exception e)
{
log.DebugFormat(@"Failed to read {0}\{1} from registry; assuming {1} is {2}.", HEALTH_CHECK_LOCAL_KEYS, k, def);
log.Debug(e, e);
return def;
}
}
public static string HealthCheckUploadDomainName
{
get { return ReadKey(HEALTH_CHECK_UPLOAD_DOMAIN_NAME, "https://rttf-staging.citrix.com/feeds/api/"); }
}
public static Int32 HealthCheckTimeInterval
{
get { return ReadLong(HEALTH_CHECK_TIME_INTERVAL, 30); }
}
private const string HEALTH_CHECK_LOCAL_KEYS = @"SOFTWARE\Citrix\XenHealthCheck";
private const string HEALTH_CHECK_UPLOAD_DOMAIN_NAME = "HealthCheckUploadDomainName";
private const string HEALTH_CHECK_TIME_INTERVAL = "HealthCheckTimeIntervalInMinutes";
}
public enum SSLCertificateTypes { None, Changed, All }
}

View File

@ -63,6 +63,7 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="Registry.cs" />
<Compile Include="XenServerHealthCheckConfigProvider.cs" />
<Compile Include="XenServerHealthCheckBugTool.cs" />
<Compile Include="XenServerHealthCheckBundleUpload.cs" />

View File

@ -244,8 +244,9 @@ namespace XenServerHealthCheck
}
// Upload the zip file to CIS uploading server.
XenServerHealthCheckUpload upload = new XenServerHealthCheckUpload(uploadToken, VERBOSITY_LEVEL,
Properties.Settings.Default.UPLOAD_URL);
string upload_url = Registry.HealthCheckUploadDomainName;
log.InfoFormat("Upload report to {0}", upload_url);
XenServerHealthCheckUpload upload = new XenServerHealthCheckUpload(uploadToken, VERBOSITY_LEVEL, upload_url);
string upload_uuid = "";
try

View File

@ -76,12 +76,9 @@ namespace XenServerHealthCheck
initConfig();
CredentialReceiver.instance.Init();
ServerListHelper.instance.Init();
System.Timers.Timer timer = new System.Timers.Timer();
if (Properties.Settings.Default.UploadTimeIntervalInMinutes != 0)
timer.Interval = Properties.Settings.Default.UploadTimeIntervalInMinutes * 60000;
else
timer.Interval = 30 * 60000; // 30 minitues
timer.Interval = Registry.HealthCheckTimeInterval * 60000;
log.InfoFormat("XenServer Health Check Service will be scheduled every {0} seconds", timer.Interval);
timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);
timer.Start();
}

View File

@ -3,7 +3,7 @@
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="XenServerHealthCheck.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
<section name="XenServerHealthCheck.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings/>
@ -44,24 +44,34 @@
</roleManager>
</system.web>
<userSettings>
<XenServerHealthCheck.Settings>
<XenServerHealthCheck.Properties.Settings>
<setting name="UUID" serializeAs="String">
<value/>
</setting>
<setting name="UPLOAD_URL" serializeAs="String">
<value/>
</setting>
<setting name="UploadTimeIntervalInMinutes" serializeAs="String">
<value>0</value>
<value />
</setting>
<setting name="HttpTimeout" serializeAs="String">
<value>40000</value>
</setting>
<setting name="ServerList" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</value>
</setting>
</XenServerHealthCheck.Settings>
<setting name="ProxySetting" serializeAs="String">
<value>0</value>
</setting>
<setting name="ProxyAddress" serializeAs="String">
<value />
</setting>
<setting name="BypassProxyForLocal" serializeAs="String">
<value>False</value>
</setting>
<setting name="ProxyPort" serializeAs="String">
<value>80</value>
</setting>
<setting name="ConnectionTimeout" serializeAs="String">
<value>20000</value>
</setting>
</XenServerHealthCheck.Properties.Settings>
</userSettings>
</configuration>