[WHS] Corriger le bug de la vue console

Publié le 09 décembre 2009 par Jeremy.jeanson

Comme un certain nombre, j’ai testé chez mois Windows Home Server Power Pack 3 et Media Center. Microsoft nous avais promis une “vue console” du WHS à partir du Media Center… pour le plus grand nombre cela fonctionne…

Oui mais pas pour tout le monde. Un certain nombre de WHS en PP2 on mal,supporté le passage en PP3 et doivent comme moi attendre un correctif dont la date de sorite est encore inconnue.

Mais quel est l’élément qui ne fonctionne pas? En plongeant dans la bête on découvre que le WHS génère normalement un fichier healt.xml qui est mis à disposition via sont site intranet (http://server:55000/health/healh.xml). Quand ce la ne fonctionne pas on peut trouver un beau warning dans les journaux d’évènements du server dont la source est l’executable CqvSvc.exe. Celui-ci a une description d’erreur très explicite :

Exception occurred:  System.Management.ManagementException

Message:  Invalid class

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

J’adore :(

Histoire de palier à cela j’ai commencer à réaliser un petit HttpHandler destiné à remplacer le fichier XML. Je le fourni ici au cas ou certain comme moi ne pourraient pas supporter d’avoir à attendre après le correctif officiel.

Il y a encore quelque éléments que je n’ai pas introduit, mais avec le peu de temps que j’avais, je me suis limité à ce qu'i m’était utile.

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using System.Web.Services;
using Microsoft.HomeServer.SDK.Interop.v1;
using Microsoft.HomeServer.Controls.QSM;

namespace WhsHealth
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Health : IHttpHandler
    {

        public bool IsReusable
        {
            // Return false in case your Managed Handler cannot be reused for another request.
            // Usually this would be false in case you have some state information preserved per request.
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Clear();
            // Ceci  est un docuemnt XML
            context.Response.ContentType = "text/xml";

            WHSInfoClass server = new WHSInfoClass();

            // Lecture des espaces partagé
            Int64 sizeSharedFolders=0;
            Int64 sizeDuplication=0;
            QSMMgr.GetSharedFoldersSize(out sizeSharedFolders, out sizeDuplication);
            
            // Ecriture du docuement
            context.Response.Write(
                new XDocument(
                new XElement("HomeServerHealth",
                // Date de mise à jour
                    new XAttribute("LastUpdated", DateTime.Now.ToString("yyy-MM-dd hh:mm:ss")),

                    // Storage
                    new XElement("Storage",
                        new XElement("StorageInfo",
                            new XAttribute("StorageType", "SharedFolders"),
                            new XAttribute("Description", "Shared folders"),
                            new XAttribute("Used", sizeSharedFolders)),
                        new XElement("StorageInfo",
                            new XAttribute("StorageType", "Duplication"),
                            new XAttribute("Description", "Duplication"),
                            new XAttribute("Used", sizeDuplication)),
                        new XElement("StorageInfo",
                            new XAttribute("StorageType", "PCBackup"),
                            new XAttribute("Description", "PC backup"),
                            new XAttribute("Used", QSMMgr.GetBackupSize())),
                        new XElement("StorageInfo",
                            new XAttribute("StorageType", "System"),
                            new XAttribute("Description", "System"),
                            new XAttribute("Used", QSMMgr.GetOperatingSystemSize())),
                        new XElement("StorageInfo",
                            new XAttribute("StorageType", "FreeSpace"),
                            new XAttribute("Description", "Free space"),
                            new XAttribute("Used", QSMMgr.GetStorageFreeSpace()))
                            ),
                //<Storage>
                //  <StorageInfo StorageType="SharedFolders" Description="Shared folders" Used="854481114046" />
                //  <StorageInfo StorageType="Duplication" Description="Duplication" Used="854481114046" />
                //  <StorageInfo StorageType="PCBackup" Description="PC backup" Used="412828605952" />
                //  <StorageInfo StorageType="System" Description="System" Used="23782103684" />
                //  <StorageInfo StorageType="FreeSpace" Description="Free space" Used="695043186688" />
                //</Storage>
                      new XElement("Shares",
                      server.GetShareInfo2().Cast<IShareInfo2>()
                      .Select(c =>
                          new XElement("ShareInfo",
                              new XAttribute("Id", c.GUID),
                              new XAttribute("Name", c.Name),
                              new XAttribute("Path", c.Path),
                              new XAttribute("Description", c.Description),
                              new XAttribute("IsDuplicated", c.IsDuplicated),
                              new XAttribute("MediaConnectEnabled", c.MediaConnectEnabled),
                              new XAttribute("Status", String.Empty),
                              new XAttribute("StatusText", String.Empty),
                              new XAttribute("StatusDescription", String.Empty)))
                      .ToArray()),
                //<Shares>
                //  <ShareInfo Id="e6ecff3f-5c97-42ff-a0eb-8e7aca33e5ad" Name="P80" Path="D:\shares\P80" Description="P80 versions and documents" IsDuplicated="1" MediaConnectEnabled="0" Status="WHS_DISK_HEALTHY" StatusText="Storage Status" StatusDescription="Share with name P80 is QSM_OS_HEALTHY" />
                //    </Shares>
                  new XElement("Backup",
                      server.GetClientComputerInfo().Cast<IComputerInfo>()
                      .Select(c =>
                          new XElement("ComputerInfo",
                              new XAttribute("Id", Guid.NewGuid().ToString()),
                              new XAttribute("ComputerName", c.ComputerName),
                              new XAttribute("Description", c.Description),
                              new XAttribute("Manufacturer", String.Empty),
                              new XAttribute("Model", String.Empty),
                              new XAttribute("OS", GetOsVersion(c)),
                              new XAttribute("IsOnline", c.IsOnline),
                              new XAttribute("IPAddress", c.IPAddress),
                              new XAttribute("NumericStatus", 0),
                              new XAttribute("DaysSinceBackup", String.Empty),
                              new XAttribute("Status", String.Empty)))
                       .ToArray()),
                //<Backup>
                //  <ComputerInfo Id="{2279A424-D407-4DDA-B114-277D99462149}" ComputerName="LIVINGROOM" Description="Laptop" Manufacturer="Hewlett-Packard" Model="HP Pavilion tx1000 Notebook PC    " OS=" Windows Vista™ Home Premium " IsOnline="0" IPAddress="192.168.0.14" NumericStatus="0" DaysSinceBackup="0" Status="" />
                //  <ComputerInfo Id="{5EE4F466-C30A-493E-9D48-C4950B246A12}" ComputerName="SNOWDINS" Description="Server" Manufacturer="Gigabyte Technology Co., Ltd." Model="EP45-UD3P" OS=" Windows 7 Ultimate " IsOnline="1" IPAddress="192.168.0.9" NumericStatus="2" DaysSinceBackup="1" Status="" />
                //  <ComputerInfo Id="{9267A1F9-CF66-45AD-A4B4-CA156C11C9AB}" ComputerName="LAPTOP-OLD" Description="" Manufacturer="Hewlett-Packard " Model="Pavilion zv5200 (PL997UA#ABA) " OS=" Windows 7 Ultimate " IsOnline="0" IPAddress="192.168.0.5" NumericStatus="0" DaysSinceBackup="0" Status="" />
                //</Backup>
                  new XElement("Disks",
                      server.GetDiskInfo().Cast<IDiskInfo>()
                      .Select(c =>
                          new XElement("DiskInfo",
                              //DiskId
                              new XAttribute("DiskId", Guid.NewGuid().ToString()),
                              //SystemName="04da3e33-0000-0000-0000-000000000000"
                              new XAttribute("SystemName", c.SystemName),
                              //DevicePath="\\?\PhysicalDrive5" 
                              new XAttribute("DevicePath", c.DevicePath),
                              //Size="750156374016" 
                              new XAttribute("Size", c.Size),
                              //Description="WDC WD7500AACS-00D6B1" 
                              new XAttribute("Description", String.Empty),
                              //Role="2" 
                              new XAttribute("Role", 1),
                              //Status="WHS_DISK_HEALTHY"
                              new XAttribute("Status", c.Status.ToString()),
                              //StatusText="Storage Status"
                              new XAttribute("StatusText", c.Status.ToString()),
                              //StatusDescription="Disk with name Unknown disk WDC WD7500AACS-00D6B1 is QSM_OS_HEALTHY"
                              new XAttribute("StatusDescription", c.Status.ToString())
                              ))
                      .ToArray()
                      ),
                //<Disks>
                //  <DiskInfo DiskId="efd09aee-0000-0000-0000-000000000000" SystemName="04da3e33-0000-0000-0000-000000000000" DevicePath="\\?\PhysicalDrive5" Size="750156374016" Description="WDC WD7500AACS-00D6B1" Role="2" Status="WHS_DISK_HEALTHY" StatusText="Storage Status" StatusDescription="Disk with name Unknown disk WDC WD7500AACS-00D6B1 is QSM_OS_HEALTHY" />
                //  <DiskInfo DiskId="4a716230-0000-0000-0000-000000000000" SystemName="4a716230-0000-0000-0000-000000000000" DevicePath="\\?\PhysicalDrive0" Size="180045766656" Description="WDC WD1800JB-00DUA0" Role="1" Status="WHS_DISK_HEALTHY" StatusText="Storage Status" StatusDescription="Disk with name System disk is QSM_OS_HEALTHY" />
                //  <DiskInfo DiskId="28e328e3-0000-0000-0000-000000000000" SystemName="01cc8e4b-0000-0000-0000-000000000000" DevicePath="\\?\PhysicalDrive2" Size="250059350016" Description="ST3250623A" Role="2" Status="WHS_DISK_HEALTHY" StatusText="Storage Status" StatusDescription="Disk with name Data disk is QSM_OS_HEALTHY" />
                //</Disks>
                  new XElement("Notifications"),
                //<Notifications>
                //  <Notification UniqueID="WHS.Backup.CurrentOperation" Severity="WHS_INFO" IsSuppressed="0" TextHeader="Backup service is idle." TextDescription="" />
                //  <Notification UniqueID="WHS.DynamicDns.Test" Severity="WHS_INFO" IsSuppressed="0" TextHeader="Updating Windows Live Custom Domains failed" TextDescription="Windows Home Server was unable to update Windows Live Custom Domains with your current IP address. Your Web site may not be available on the Internet." />
                //  <Notification UniqueID="qsm.0ed4ab94-cc75-4397-95a2-a52528de19f3.Object" Severity="WHS_INFO" IsSuppressed="0" TextHeader="Storage Status" TextDescription="Disk with name Primary Size Object is QSM_OS_INITIALIZED" />
                //     <Notification UniqueID="PortForwarding" Severity="WHS_INFO" IsSuppressed="0" TextHeader="Updating port forwarding for your router failed" TextDescription="Windows Home Server was unable to update port forwarding for your router.  Your Web site may not be available on the Internet." />
                //  <Notification UniqueID="WHS.Backup.Machine.{2279A424-D407-4DDA-B114-277D99462149}" Severity="WHS_INFO" IsSuppressed="0" TextHeader="LIVINGROOM: Not configured for backup." TextDescription="" />
                //  <Notification UniqueID="WHS.Backup.Machine.{269250A6-2DBD-44D9-B20F-437C81B74622}" Severity="WHS_INFO" IsSuppressed="0" TextHeader="KRIS-A88524CDD7: Last backup succeeded." TextDescription="" />
                //  <Notification UniqueID="WHS.Backup.Machine.{5EE4F466-C30A-493E-9D48-C4950B246A12}" Severity="WHS_INFO" IsSuppressed="0" TextHeader="SNOWDINS: Last backup succeeded." TextDescription="" />
                //  <Notification UniqueID="WHS.Backup.Machine.{9267A1F9-CF66-45AD-A4B4-CA156C11C9AB}" Severity="WHS_INFO" IsSuppressed="0" TextHeader="LAPTOP-OLD: Not configured for backup." TextDescription="" />
                //  <Notification UniqueID="WHS.Backup.Startup" Severity="WHS_INFO" IsSuppressed="0" TextHeader="Backup service is started." TextDescription="" />
                //</Notifications>
                  new XElement("MediaCounts",
                    new XElement("MediaCount", 
                        new XAttribute("Id","Music"),
                        new XAttribute("Count","0"),
                        new XAttribute("Available","0")),
                    new XElement("MediaCount", 
                        new XAttribute("Id","Photos"),
                        new XAttribute("Count","0"),
                        new XAttribute("Available","0")),
                    new XElement("MediaCount", 
                        new XAttribute("Id","Videos"),
                        new XAttribute("Count","0"),
                        new XAttribute("Available","0"))),
                //<MediaCounts>
                //  <MediaCount Id="Music" Count="2" Available="7995" />
                //  <MediaCount Id="Photos" Count="2" Available="319271" />
                //  <MediaCount Id="Videos" Count="1" Available="928" />
                //</MediaCounts>
                  new XElement("Hardware",
                      new XElement("SystemInformation",
                          new XAttribute("Manufacturer", ""),
                          new XAttribute("Model", ""),
                          new XAttribute("Serial", ""),
                          new XAttribute("Version", ""),
                          new XAttribute("Uptime", "")))
                          //Manufacturer="NVIDIA" Model="AWRDACPI" Serial=" " Version="6.0.2423.0" Uptime="21"))
                //<Hardware>
                //  <SystemInformation Manufacturer="NVIDIA" Model="AWRDACPI" Serial=" " Version="6.0.2423.0" Uptime="21" />
                //</Hardware>
                    )).ToString());
            context.Response.Flush();
            context.Response.Close();
        }

        private static String GetOsVersion(IComputerInfo info)
        {
            if (info.OSMajorNumber == 5
                & info.OSMinorNumber == 0)
            {
                return "Windows 2000";
            }
            else if (info.OSMajorNumber == 5
                & info.OSMinorNumber == 1)
            {
                return "Windows XP";
            }
            else if (info.OSMajorNumber == 6
                & info.OSMinorNumber == 0)
            {
                return "Windows Vista";
            }
            else if (info.OSMajorNumber == 6
                & info.OSMinorNumber == 1)
            {
                return "Windows 7";
            }
            else
            {
                return String.Format("Windows {0}.{1}", info.OSMajorNumber, info.OSMinorNumber);
            }
        }
    }
}