Example #1
0
        /// <summary>
        /// Updates the mapping state of a monitored system, if the mapping duration of this monitored system is out of date
        /// </summary>
        /// <param name="monitoredSystemMac">ID of the monitored system to update</param>
        public void UpdateMappingState(int monitoredSystemID)
        {
            try
            {
                using (var dataContext = DataContextFactory.CreateReadOnlyDataContext())
                {
                    var monitoredSystem = PrecompiledQueries.GetMonitoredSystemByID(dataContext, monitoredSystemID);

                    if (monitoredSystem.MacAddress != null)
                    {
                        UpdateMappingState(monitoredSystem.MacAddress);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Instance.WriteEntry("ValueManager_UpdateMappingState: Can't update the mapping of workstation " + monitoredSystemID + ". " + e.StackTrace, LogType.Exception);
            }
        }
Example #2
0
        /// <summary>
        /// Retuns all observer of an monitored system
        /// </summary>
        /// <param name="userID">ID of the users email adress</param>
        /// <returns>List of MAC adress </returns>
        public List <WorkstationInfo> GetObserver(int userID)
        {
            List <WorkstationInfo> result = new List <WorkstationInfo>();

            try
            {
                using (var dataContext = DataContextFactory.CreateReadOnlyDataContext())
                {
                    var msIDs = (from q in dataContext.EmailObserver
                                 where q.EmailID == userID
                                 select q.MonitoredSystem.ID).ToList();

                    foreach (var ms in msIDs)
                    {
                        //update mapping state
                        ValueManager.Instance.UpdateMonitoredSystemMappingState(ms);

                        var monitoredSystem = PrecompiledQueries.GetMonitoredSystemByID(dataContext, ms);

                        //create result
                        var workstationinfo = new WorkstationInfo()
                        {
                            Name        = monitoredSystem.Name,
                            ID          = monitoredSystem.ID,
                            FQDN        = monitoredSystem.FQDN,
                            OuID        = monitoredSystem.OrganizationalUnitID,
                            IsAvailable = monitoredSystem.IsAvailable,
                            CurrentOS   = ((MISD.Core.Platform)monitoredSystem.OperatingSystem).ToString(),
                            MacAddress  = monitoredSystem.MacAddress,
                            State       = monitoredSystem.Status.HasValue ? (MappingState)monitoredSystem.Status : MappingState.OK
                        };
                        result.Add(workstationinfo);
                    }
                }

                return(result);
            }
            catch (Exception e)
            {
                Logger.Instance.WriteEntry("Mailer_GetObserver: Can't create result: " + e.StackTrace, LogType.Exception);
                return(null);
            }
        }
Example #3
0
        public List <WorkstationInfo> GetWorkstationInfo(List <Tuple <int, TimeSpan> > workstationsWithReset)
        {
            List <WorkstationInfo> returns = new List <WorkstationInfo>();

            using (var dataContext = DataContextFactory.CreateDataContext())
            {
                dataContext.Log = Console.Out;
                try
                {
                    foreach (Tuple <int, TimeSpan> current in workstationsWithReset)
                    {
                        //update mapping state
                        UpdateMappingState(current.Item1);

                        var monitoredSystem = PrecompiledQueries.GetMonitoredSystemByID(dataContext, current.Item1);

                        WorkstationInfo workstationInfo;

                        if (monitoredSystem.LastUpdate != null)
                        {
                            //create result
                            workstationInfo = new WorkstationInfo()
                            {
                                Name        = monitoredSystem.Name,
                                ID          = monitoredSystem.ID,
                                FQDN        = monitoredSystem.FQDN,
                                OuID        = monitoredSystem.OrganizationalUnitID,
                                IsAvailable = monitoredSystem.IsAvailable,
                                CurrentOS   = ((MISD.Core.Platform)monitoredSystem.OperatingSystem).ToString(),
                                MacAddress  = monitoredSystem.MacAddress,
                                State       = monitoredSystem.Status.HasValue ? (MappingState)monitoredSystem.Status : MappingState.OK,
                                LastUpdate  = new DateTime((long)monitoredSystem.LastUpdate)
                            };
                        }
                        else
                        {
                            //create result
                            workstationInfo = new WorkstationInfo()
                            {
                                Name        = monitoredSystem.Name,
                                ID          = monitoredSystem.ID,
                                FQDN        = monitoredSystem.FQDN,
                                OuID        = monitoredSystem.OrganizationalUnitID,
                                IsAvailable = monitoredSystem.IsAvailable,
                                CurrentOS   = ((MISD.Core.Platform)monitoredSystem.OperatingSystem).ToString(),
                                MacAddress  = monitoredSystem.MacAddress,
                                State       = monitoredSystem.Status.HasValue ? (MappingState)monitoredSystem.Status : MappingState.OK,
                                LastUpdate  = null
                            };
                        }

                        returns.Add(workstationInfo);
                    }
                    return(returns);
                }
                catch (Exception e)
                {
                    //logging exception
                    var messageEx = new StringBuilder();
                    messageEx.Append("Can't create List of WorkstationInfos" + ". " + e.ToString());
                    MISD.Core.Logger.Instance.WriteEntry(messageEx.ToString(), LogType.Exception);

                    return(null);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Registers a new node in the database.
        /// </summary>
        /// <param name="node">The node to be registered.</param>
        /// <param name="OUName">The name of the OU for the node.</param>
        private void RegisterNode(WorkstationInfo node, string OUName)
        {
            using (var dataContext = DataContextFactory.CreateDataContext())
            {
                Database.MonitoredSystem monitoredSystem = null;
                try
                {
                    try
                    {
                        monitoredSystem = PrecompiledQueries.GetMonitoredSystemByID(dataContext, PrecompiledQueries.GetMonitoredSystemIDByMAC(dataContext, node.MacAddress));
                    }
                    catch (Exception)
                    {
                        monitoredSystem = null;
                    }

                    // monitored system is not yet known in the db
                    if (monitoredSystem == null)
                    {
                        monitoredSystem = new MonitoredSystem();
                        monitoredSystem.OrganizationalUnitID = this.OUID;
                        monitoredSystem.Name            = node.Name;
                        monitoredSystem.FQDN            = node.FQDN;
                        monitoredSystem.IsAvailable     = node.IsAvailable;
                        monitoredSystem.IsIgnored       = false;
                        monitoredSystem.OperatingSystem = (byte)PlatformHelper.ParsePlatform(node.CurrentOS);
                        monitoredSystem.MacAddress      = node.MacAddress;

                        dataContext.MonitoredSystem.InsertOnSubmit(monitoredSystem);
                        dataContext.SubmitChanges();

                        //logging info
                        var messageOK = new StringBuilder();
                        messageOK.Append("ClusterManager_RegisterNode: ");
                        messageOK.Append("Cluster node " + monitoredSystem.Name + " ");
                        messageOK.Append("(" + monitoredSystem.OperatingSystem.ToString() + ") ");
                        messageOK.Append("is now added to the system.");
                        MISD.Core.Logger.Instance.WriteEntry(messageOK.ToString(), LogType.Info);
                    }
                    else
                    {
                        if (node.IsAvailable)
                        {
                            monitoredSystem.IsAvailable          = node.IsAvailable;
                            monitoredSystem.Name                 = node.Name;
                            monitoredSystem.FQDN                 = node.FQDN;
                            monitoredSystem.OperatingSystem      = (byte)PlatformHelper.ParsePlatform(node.CurrentOS);
                            monitoredSystem.OrganizationalUnitID = this.OUID;
                        }
                        else
                        {
                            // no changes necessary as the node might be booted under a different cluster
                        }
                        dataContext.SubmitChanges();
                    }
                    node.ID = monitoredSystem.ID;
                }
                catch (Exception e)
                {
                    //logging exception
                    string workstationLogName;
                    string osLogName;
                    if (monitoredSystem != null)
                    {
                        workstationLogName = monitoredSystem.Name;
                        osLogName          = monitoredSystem.OperatingSystem.ToString();
                    }
                    else
                    {
                        workstationLogName = "[unkown]";
                        osLogName          = "system unkown";
                    }

                    var messageEx2 = new StringBuilder();
                    messageEx2.Append("ClusterManager_RegisterNode: ");
                    messageEx2.Append("Cluster node" + workstationLogName + " ");
                    messageEx2.Append("(" + osLogName + ") ");
                    messageEx2.Append("sign in has failed. " + e.ToString());
                    MISD.Core.Logger.Instance.WriteEntry(messageEx2.ToString(), LogType.Exception);
                }
            }
        }