Beispiel #1
0
        public bool SendSmartReport()
        {
            if (ServiceSetting.GetSettingValue(SettingStrings.SmtpEnabled) != "1")
            {
                return(true);
            }

            var uow       = new UnitOfWork();
            var computers = uow.ComputerRepository.Get(x => x.ProvisionStatus == EnumProvisionStatus.Status.Provisioned);

            if (computers.Count == 0)
            {
                return(true);
            }

            var sb          = new StringBuilder();
            var errorsFound = false;

            sb.Append("The Following Hard Drives Have A Failed S.M.A.R.T. Status:\r\n\r\n");
            foreach (var computer in computers)
            {
                var localComputer = computer;
                var hdds          = uow.HardDriveInventoryRepository.Get(x => x.ComputerId == localComputer.Id);
                foreach (var hdd in hdds)
                {
                    if (!hdd.Status.ToLower().Equals("ok"))
                    {
                        errorsFound = true;
                        sb.Append(computer.Name + "\t" + hdd.Model + "\t" + hdd.SerialNumber + "\t" + hdd.Status + Environment.NewLine);
                    }
                }
            }

            if (!errorsFound)
            {
                return(true);
            }

            var emailList = new List <string>();
            var users     = uow.UserRepository.Get();

            foreach (var user in users)
            {
                if (user.Membership.Equals("Administrator"))
                {
                    if (!string.IsNullOrEmpty(user.Email))
                    {
                        emailList.Add(user.Email);
                    }
                }
                else
                {
                    var rights = new ServiceUser().GetUserRights(user.Id).Select(right => right.Right).ToList();
                    if (rights.Any(right => right == AuthorizationStrings.EmailSmart))
                    {
                        if (!string.IsNullOrEmpty(user.Email))
                        {
                            emailList.Add(user.Email);
                        }
                    }
                }
            }

            foreach (var email in emailList)
            {
                var mail = new MailServices
                {
                    Subject = "S.M.A.R.T Failure Report",
                    Body    = sb.ToString(),
                    MailTo  = email
                };

                mail.Send();
            }

            return(true);
        }
Beispiel #2
0
        public bool SendResetRequestReport()
        {
            if (ServiceSetting.GetSettingValue(SettingStrings.SmtpEnabled) != "1")
            {
                return(true);
            }

            var resetRequests = _uow.ResetRequestRepository.Get();

            if (resetRequests.Count == 0)
            {
                return(true);
            }
            var sb = new StringBuilder();

            sb.Append("The Following Computers Are Pending Reset Approval:\r\n\r\n");
            foreach (var resetRequest in resetRequests)
            {
                sb.Append(resetRequest.ComputerName + "\t" + resetRequest.RequestTime + "\t" + resetRequest.IpAddress +
                          Environment.NewLine);
            }

            var emailList = new List <string>();
            var users     = _uow.UserRepository.Get();

            foreach (var user in users)
            {
                if (user.Membership.Equals("Administrator"))
                {
                    if (!string.IsNullOrEmpty(user.Email))
                    {
                        emailList.Add(user.Email);
                    }
                }
                else
                {
                    var rights = new ServiceUser().GetUserRights(user.Id).Select(right => right.Right).ToList();
                    if (rights.Any(right => right == AuthorizationStrings.EmailReset))
                    {
                        if (!string.IsNullOrEmpty(user.Email))
                        {
                            emailList.Add(user.Email);
                        }
                    }
                }
            }

            foreach (var email in emailList)
            {
                var mail = new MailServices
                {
                    Subject = "Reset Request Report",
                    Body    = sb.ToString(),
                    MailTo  = email
                };

                mail.Send();
            }

            return(true);
        }
Beispiel #3
0
        public bool SendLowDiskSpaceReport()
        {
            if (ServiceSetting.GetSettingValue(SettingStrings.SmtpEnabled) != "1")
            {
                return(true);
            }

            var uow = new UnitOfWork();

            var sb          = new StringBuilder();
            var errorsFound = false;
            var comServers  = new Workflows.ComServerFreeSpace().RunAllServers();

            sb.Append("The Following Com Servers Have Low Disk Space:\r\n\r\n");
            foreach (var comServer in comServers)
            {
                if (comServer.freePercent < 20)
                {
                    errorsFound = true;
                    sb.Append(comServer.name + "\t" + comServer.freePercent + "% Free");
                }
            }

            if (!errorsFound)
            {
                return(true);
            }

            var emailList = new List <string>();
            var users     = uow.UserRepository.Get();

            foreach (var user in users)
            {
                if (user.Membership.Equals("Administrator"))
                {
                    if (!string.IsNullOrEmpty(user.Email))
                    {
                        emailList.Add(user.Email);
                    }
                }
                else
                {
                    var rights = new ServiceUser().GetUserRights(user.Id).Select(right => right.Right).ToList();
                    if (rights.Any(right => right == AuthorizationStrings.EmailLowDiskSpace))
                    {
                        if (!string.IsNullOrEmpty(user.Email))
                        {
                            emailList.Add(user.Email);
                        }
                    }
                }
            }

            foreach (var email in emailList)
            {
                var mail = new MailServices
                {
                    Subject = "Com Server Low Disk Space",
                    Body    = sb.ToString(),
                    MailTo  = email
                };

                mail.Send();
            }

            return(true);
        }