Example #1
0
 private void OncePerComputerPerUser(DtoClientPolicy policy, EntityPolicyHistory history)
 {
     Logger.Debug(policy.Name + " Is Set To Run Once Per Computer Per User.");
     if (history == null)
     {
         Logger.Debug("Policy Has Never Been Run.  Adding To Run List.");
         _policiesToRun.Add(policy);
     }
     else if (policy.ReRunExisting)
     {
         Logger.Debug("Policy Is Set ReRun On Previously Completed Computers.");
         var hashHistory = _policyHistoryServices.GetLastPolicyRunForUserFromHash(policy.Hash, _currentUser);
         if (hashHistory == null)
         {
             Logger.Debug("This Policy's Hash Was Not Found In The History.  Adding To Run List.");
             _policiesToRun.Add(policy);
         }
         else
         {
             Logger.Debug("Policy Last Ran On " + hashHistory.LastRunTime);
             Logger.Debug("This Policy Has Already Ran With Forced ReRun.  Skipping");
         }
     }
     else
     {
         Logger.Debug("Policy Has Already Ran And Has Not Been Forced Run Again.  Skipping.");
         Logger.Debug("Policy Last Ran On " + history.LastRunTime);
     }
 }
Example #2
0
 public DtoActionResult WritePolicyHistory(EntityPolicyHistory history)
 {
     Request.Method = Method.POST;
     Request.AddJsonBody(history);
     Request.Resource = string.Format("api/{0}/WritePolicyHistory/", Resource);
     return
         (new ApiRequest("http://localhost:" + DtoGobalSettings.LocalApiPort + "/").Execute <DtoActionResult>(
              Request));
 }
Example #3
0
        public DtoActionResult AddHistory(EntityPolicyHistory history)
        {
            var actionResult = new DtoActionResult();

            _uow.PolicyHistoryRepository.Insert(history);
            _uow.Save();
            actionResult.Success = true;
            actionResult.Id      = history.Id;
            return(actionResult);
        }
Example #4
0
        private void EveryXHours(DtoClientPolicy policy, EntityPolicyHistory history)
        {
            Logger.Debug(policy.Name + " Is Set To Run Every " + policy.SubFrequency + " Hours.");
            if (policy.ReRunExisting)
            {
                Logger.Debug("Policy Is Set ReRun On Previously Completed Computers.");
                var hashHistory = _policyHistoryServices.GetLastPolicyRunFromHash(policy.Hash);
                if (hashHistory == null)
                {
                    Logger.Debug("This Policy's Hash Was Not Found In The History.  Adding To Run List.");
                    _policiesToRun.Add(policy);
                    return;
                }
                else
                {
                    Logger.Debug("Policy Last Ran On " + hashHistory.LastRunTime);
                    Logger.Debug("This Policy Has Already Ran With Forced ReRun.  Skipping");
                    return;
                }
            }
            if (history == null)
            {
                Logger.Debug("Policy Has Never Been Run.  Adding To Run List.");
                _policiesToRun.Add(policy);
            }
            else
            {
                Logger.Debug("Policy Last Ran On " + history.LastRunTime);

                var limit = DateTime.UtcNow - TimeSpan.FromHours(policy.SubFrequency);

                if (history.LastRunTime.ToUniversalTime() < limit)
                {
                    Logger.Debug("It Has Been More Than " + policy.SubFrequency + " Hours Since The Last Run, Adding To Run List.");
                    _policiesToRun.Add(policy);
                }
                else
                {
                    Logger.Debug("This Policy Has Already Ran Within The Last " + policy.SubFrequency + " Hours.  Skipping");
                }
            }
        }
Example #5
0
        private void RecordResults()
        {
            Logger.Info("Submitting Policy Results");
            var serverHistoryList   = new List <DtoServerPolicyHistory>();
            var customInventoryList = new List <DtoScriptModuleOutput>();

            foreach (var policyResult in _policyResults)
            {
                var history = new EntityPolicyHistory();
                history.PolicyGUID  = policyResult.PolicyGuid;
                history.PolicyHash  = policyResult.PolicyHash;
                history.LastRunTime = DateTime.UtcNow;
                history.Username    = Environment.UserDomainName + "\\" + Environment.UserName;

                if (!policyResult.SkipServerResult)
                {
                    var serverHistory = new DtoServerPolicyHistory();
                    serverHistory.Hash = policyResult.PolicyHash;
                    if (policyResult.PolicyResult == EnumPolicy.Result.Success)
                    {
                        serverHistory.Result = EnumPolicyHistory.RunResult.Success;
                    }
                    else if (policyResult.PolicyResult == EnumPolicy.Result.Failed)
                    {
                        serverHistory.Result = EnumPolicyHistory.RunResult.Failed;
                    }
                    else if (policyResult.PolicyResult == EnumPolicy.Result.Skipped)
                    {
                        serverHistory.Result = EnumPolicyHistory.RunResult.Skipped;
                    }
                    else
                    {
                        serverHistory.Result = EnumPolicyHistory.RunResult.NotApplicable;
                    }

                    serverHistory.PolicyGuid  = policyResult.PolicyGuid;
                    serverHistory.LastRunTime = DateTime.UtcNow;
                    serverHistory.User        = Environment.UserDomainName + "\\" + Environment.UserName;
                    serverHistoryList.Add(serverHistory);
                }
                //Don't record local results if not success, only server
                if (policyResult.PolicyResult == EnumPolicy.Result.Success || policyResult.PolicyResult == EnumPolicy.Result.NotApplicable)
                {
                    if (policyResult.ScriptOutputs.Count > 0)
                    {
                        customInventoryList.AddRange(policyResult.ScriptOutputs);
                    }
                    if (_trigger == EnumPolicy.Trigger.Login)
                    {
                        new APICall().LocalApi.WritePolicyHistory(history);
                    }
                    else
                    {
                        new PolicyHistoryServices().AddHistory(history);
                    }
                }
            }

            var results = new DtoPolicyResults();

            results.CustomInventories = customInventoryList;
            results.Histories         = serverHistoryList;
            if (results.CustomInventories.Count == 0 && results.Histories.Count == 0)
            {
                Logger.Info("Completed Submitting Policy Results");
                return;
            }

            if (_trigger == EnumPolicy.Trigger.Login)
            {
                new APICall().LocalApi.SendServerResults(results);
            }
            else
            {
                new APICall().PolicyApi.AddHistory(results);
            }
            Logger.Info("Completed Submitting Policy Results");
        }
Example #6
0
 public DtoActionResult WritePolicyHistory(EntityPolicyHistory history)
 {
     return(new PolicyHistoryServices().AddHistory(history));
 }