示例#1
0
        /// <summary>
        /// GetAll call
        /// </summary>
        /// <returns></returns>
        public IEnumerable <MonitorCommand> GetAllMonitorCommands()
        {
            _logger.Info("-----------------------------------------");
            _logger.Info("Method GetAllMonitorCommands()...");
            // Check to make sure if the org-id and the user-id matches
            // correctly. Also, match the guid to create an register agent
            // if not present
            var headers = Request.Headers;

            _logger.Info("Request Headers...");
            _logger.Info(headers);
            var serverGuid = headers.GetValues("server_guid").First();

            if (!Util.IsServerGuidValid(serverGuid))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }
            try
            {
                var agent = new Agent()
                {
                    Guid             = headers.GetValues("agent_guid").First(),
                    OrgId            = 1, // currently hardcoding but will be read from the header
                    MachineName      = headers.GetValues("machine_name").First(),
                    RegistrationDate = DateTime.UtcNow,
                    LastQueried      = DateTime.UtcNow,
                    ClientIpAddress  = GetClientIpAddress(Request) ?? string.Empty,
                    ProductVersion   = headers.GetValues("product_version").First()
                };
                agent.ClientCity    = Util.GetIpInfo(agent.ClientIpAddress, false);
                agent.ClientCountry = Util.GetIpInfo(agent.ClientIpAddress, true);
                _logger.Info($"Client Ip address:--{agent.ClientIpAddress}--");
                _logger.Debug($"MonitorCommandsController : UpsertAgent()");
                monitorDb.UpsertAgent(agent);
                var monitorCommands = monitorDb.GetMonitorCommands();
                _logger.Info("Monitor Commands...");
                _logger.Info(ObjectDumper.Dump(monitorCommands));
                return(monitorCommands);
            }
            catch (Exception e)
            {
                _logger.Info($"GetMonitorCommands Exception:{e.Message}");
                return(null);
            }
        }