Exemplo n.º 1
0
        internal List <EntityViewBase> FindDatastores()
        {
            List <EntityViewBase> FoundEntities = new List <EntityViewBase> {
            };

            foreach (HostSystem host in GetHostCached().Values)
            {
                // only get information about mounted logical volumes
                foreach (ManagementObject r in (new ManagementObjectSearcher(host.Scopes["CIMV2"], new ObjectQuery("SELECT * FROM Win32_Volume WHERE drivetype='3' AND NOT name LIKE '%?%'"))).Get())
                {
                    Datastore ds   = null;
                    string    dsid = r.GetPropertyValue("DeviceId").ToString();
                    ds = GetDatastoreDiskCached(dsid);

                    bool dsalreadyfound = false;
                    foreach (Datastore entity in FoundEntities)
                    {
                        if (entity.ID == ds.ID)
                        {
                            dsalreadyfound = true; break;
                        }
                    }

                    ds.Name = r.GetPropertyValue("Name").ToString();
                    long blocksize = 0, capacity = 0, freespace = 0;
                    Int64.TryParse(r.GetPropertyValue("BlockSize").ToString(), out blocksize);
                    Int64.TryParse(r.GetPropertyValue("Capacity").ToString(), out capacity);
                    Int64.TryParse(r.GetPropertyValue("FreeSpace").ToString(), out freespace);
                    ds.BlockSize  = blocksize;
                    ds.Capacity   = capacity;
                    ds.FreeSpace  = freespace;
                    ds.FileSystem = r.GetPropertyValue("FileSystem").ToString();
                    List <string> owners = new List <string> {
                    };
                    if (ds.IsClustered)
                    {
                        foreach (HostSystem h in GetHostCached().Values)
                        {
                            owners.Add(h.Name);
                        }
                    }
                    else
                    {
                        owners.Add(host.Name);
                    }
                    ds.Cluster = _ClusterName;
                    ds.Host    = CFunctions.StringJoin(";", owners);

                    if (!dsalreadyfound)
                    {
                        FoundEntities.Add(ds);
                    }
                }
            }
            return(FoundEntities);
        }
        public void ExportDiscoveredConfig(CDiscoveredConfig oc, CService server = null, bool rolluptotals = false)
        {
            if (oc.Attributes != null && oc.Name.Length > 0)
            {
                if (server != null && rolluptotals)
                {
                    // create grouping objects
                    AddGroupingInfo(server, oc);

                    // rollup totals by group and repair object parent properties
                    oc = UpdateGroupingInfo(server, oc);
                }
                CDatabaseEntry entry = new CDatabaseEntry();
                entry.Id         = oc.Id.ToString();
                entry.Reference  = oc.Attributes.Get(CAttributeType.Reference);
                entry.Created    = oc.Attributes.Get(CAttributeType.Created);
                entry.Accessed   = oc.Attributes.Get(CAttributeType.Accessed);
                entry.Name       = CFunctions.EscapeJson(oc.Name);
                entry.Type       = oc.Type.ToString();
                entry.Parent     = CFunctions.StringJoin(";", oc.Owner);
                entry.Attributes = oc.Serialize(CDiscoveredConfig.SerializeAsShortJson);
                if (!ExportedEntries.Contains(entry.Id))
                {
                    _DBConn.AddEntry(entry);
                    ExportedEntries.Add(entry.Id);
                }
                else
                {
                    _DBConn.UpdateEntry(entry);
                }
            }
            if (oc.ChildObjects != null)
            {
                foreach (CDiscoveredConfig obj in oc.ChildObjects)
                {
                    ExportDiscoveredConfig(obj, server, rolluptotals);
                }
            }
        }
 public string _AddGroupingInfo(CService server, string name, int type, string parent, string id = "")
 {
     if (!DiscoveredGroups.ContainsKey(name))
     {
         if (id != null && id == parent)
         {
             parent = "";
         }                                                // object = parent: so parent may as well be empty
         DiscoveredGroups.Add(name, new CDiscoveredConfig()
         {
             Name = name, Type = type, Owner = new List <string> {
                 parent
             }
         });
         if (id != null && id != "")
         {
             DiscoveredGroups[name].Id = id;
         }                                                               // if id is specified specifically set this for the group
         if (DiscoveredGroups[name].Attributes == null)
         {
             DiscoveredGroups[name].Attributes = new CDiscoveredAttributes();
         }
         if (DiscoveredGroups[name].Metrics == null)
         {
             DiscoveredGroups[name].Metrics = new CDiscoveredMetrics();
         }
         if (type == CDiscoveredTypes.Site)
         {
             CSite obj = DiscoveredSites.Find(x => x.Name.Equals(name));
             if (obj != null)
             {
                 DiscoveredGroups[name].Attributes.Set(CAttributeType.Details, obj.Description.ToStringNz());
                 DiscoveredGroups[name].Attributes.Set(CAttributeType.Path, obj.Path.ToStringNz());
                 DiscoveredGroups[name].Attributes.Set(CAttributeType.Location, obj.Location.ToStringNz());
                 DiscoveredGroups[name].Attributes.Set(CAttributeType.Subnets, CFunctions.StringJoin(";", obj.Subnets));
             }
         }
         else if ((type == CDiscoveredTypes.VICluster))
         {
             if (DiscoveredGroups.ContainsKey(server.Name))
             {
                 DiscoveredGroups[server.Name].Metrics.Increment(CMetricType.ClCount, 1);
             }
         }
         else if ((type == CDiscoveredTypes.HVCluster))
         {
             DiscoveredGroups[name].Metrics.Increment(CMetricType.ClCount, 1);
         }
         else if ((type == CDiscoveredTypes.VIDatacenter) || (type == CDiscoveredTypes.HVDatacenter))
         {
             if (DiscoveredGroups.ContainsKey(server.Name))
             {
                 DiscoveredGroups[server.Name].Metrics.Increment(CMetricType.DcCount, 1);
             }
         }
         return(DiscoveredGroups[name].Id);
     }
     return(null);
 }