public ApplicationLogsModule(GlobalConfig globals, ILogStore logStore, IAppConfigurationManager config)
        {
            if (globals.IsAuthenticationEnabled())
            {
                this.RequiresAuthentication();
            }

            Get["/logs/{apppath}/{server?}", true] = async(x, ct) => {
                var app = await config.FindAppAsync(Application.GetPathFromBase64Key((String)x.apppath));

                var model = this.Bind <ApplicationLogFilterModel>();

                model.dfrom   = model.dfrom.HasValue ? model.dfrom.Value : DateTime.Now.Subtract(TimeSpan.FromHours(10));
                model.dto     = model.dto.HasValue ? model.dto.Value : DateTime.Now;
                model.apppath = app.Path;
                model.appname = app.Name;
                model.lfrom   = model.lfrom.HasValue ? model.lfrom.Value : (short)LogRecord.ELogLevel.Info;
                model.lto     = model.lto.HasValue ? model.lto.Value : (short)LogRecord.ELogLevel.Critical;
                model.server  = x.server;

                ViewBag.Logs = await FilterLogsAsync(logStore, model, model.off);

                return(View["ApplicationLogs.cshtml", model]);
            };
        }
Beispiel #2
0
        public MusketeerModule(IAppConfigurationManager appconf, ILogStore logStore,
                               IValidator <Application> appvalidator, IValidator <ApplicationServerConfig> appconfvalidator)
        {
            Post["conf/appsrvconfig", true] = async(x, ct) => {
                var configs  = this.Bind <ApplicationServerConfig[]>();
                var apppaths = new List <String>();
                foreach (var conf in configs)
                {
                    var validationResult = appconfvalidator.Validate(conf);
                    if (!validationResult.IsValid)
                    {
                        logger.TraceEvent(TraceEventType.Error, 0, "Validation failed for config {@0}, errors: {1}", conf, validationResult.Errors);
                        continue;
                    }
                    var app = await appconf.FindAppAsync(conf.AppPath);

                    if (app == null)
                    {
                        app = new Application {
                            IsExcluded = true,
                            Path       = conf.AppPath
                        };
                        await appconf.AddOrUpdateAppAsync(app);
                    }
                    else if (app != null && !app.IsExcluded)
                    {
                        apppaths.Add(conf.AppPath);
                    }
                    await appconf.AddOrUpdateAppServerConfigAsync(conf);
                }
                return(Response.AsJson(apppaths));
            };
        }
        public async Task <Application> FindAppAsync(string path)
        {
            var cacheKey = CachePrefixForApplications + path;

            if (IsCachingEnabled && cache.Contains(cacheKey))
            {
                return((Application)cache[cacheKey]);
            }
            var app = await wrappedInstance.FindAppAsync(path);

            if (IsCachingEnabled && app != null)
            {
                cache.Add(cacheKey, app, new CacheItemPolicy {
                    AbsoluteExpiration = DateTimeOffset.UtcNow.Add(TimeToKeepApplicationInCache)
                });
            }
            return(app);
        }
        public ApplicationConfModule(GlobalConfig globals, IAppConfigurationManager appconf, ILogStore logStore,
                                     IValidator <Application> appvalidator, IValidator <ApplicationServerConfig> appconfvalidator)
        {
            if (globals.IsAuthenticationEnabled())
            {
                this.RequiresAuthentication();
            }

            Post["conf/appname", true] = async(x, ct) => {
                return(await UpdateAppPropertiesAsync(appconf, appvalidator, this.Bind <Application>(), "Name"));
            };
            Post["conf/appmaintenance", true] = async(x, ct) => {
                return(await UpdateAppPropertiesAsync(appconf, appvalidator, this.Bind <Application>(), "DaysToKeepLogs"));
            };
            Post["conf/appexclusion", true] = async(x, ct) => {
                return(await UpdateAppPropertiesAsync(appconf, appvalidator, this.Bind <Application>(), "IsExcluded"));
            };
            Post["conf/apphidden", true] = async(x, ct) => {
                // we will mark it as excluded also
                var app = this.Bind <Application>();
                app.IsExcluded = true;
                return(await UpdateAppPropertiesAsync(appconf, appvalidator, app, new[] { "IsHidden", "IsExcluded" }));
            };
            Get["conf/appsrvconfig/{apppath?}", true] = async(x, ct) => {
                IEnumerable <Application> apps;
                if (x.apppath != null)
                {
                    apps = new[] { await appconf.FindAppAsync(Application.GetPathFromBase64Key((String)x.apppath)) };
                }
                else
                {
                    // get all non-hidden applications
                    apps = (await appconf.GetAppsAsync()).Where(app => !app.IsHidden);
                }
                // and send back their configuration
                return(await appconf.GetAppConfigsAsync(apps.Select(app => app.Path).ToArray()));
            };
            Get["conf/appsrvconfigs", true] = async(x, ct) => {
                var activeAppPaths = (await appconf.GetAppsAsync()).Where(
                    app => !app.IsHidden && !app.IsExcluded).Select(app => app.Path).ToArray();
                return(Response.AsJson(await appconf.GetAppConfigsAsync(activeAppPaths)));
            };
        }
Beispiel #5
0
        public CollectModule(IAppConfigurationManager config, IValidator <LogRecord> logRecordValidator, ILogStore logStore)
        {
            Post["/collect", true] = async(x, ct) => {
                var logrec = this.Bind <LogRecord>(new BindingConfig {
                    BodyOnly = true
                });
                var validationResult = logRecordValidator.Validate(logrec);
                if (!validationResult.IsValid)
                {
                    return("VALIDATION ERROR");
                }
                logrec.ApplicationPath = logrec.ApplicationPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                var app = await config.FindAppAsync(logrec.ApplicationPath);

                if (app == null)
                {
                    app = new Application {
                        IsExcluded = true,
                        Path       = logrec.ApplicationPath
                    };
                    await config.AddOrUpdateAppAsync(app);
                }
                if (!app.IsExcluded)
                {
                    await logStore.AddLogRecordAsync(logrec);

                    await logStore.UpdateApplicationStatusAsync(
                        CreateApplicationStatus(logrec));
                }
                return("OK");
            };
            Post["/collectall", true] = async(x, ct) => {
                var logrecs = this.Bind <LogRecord[]>(new BindingConfig {
                    BodyOnly = true
                });

                var logsToSave = new List <LogRecord>(logrecs.Length);
                foreach (var logrec in logrecs)
                {
                    var validationResult = logRecordValidator.Validate(logrec);
                    if (validationResult.IsValid)
                    {
                        logrec.ApplicationPath = logrec.ApplicationPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                        // add new application to the configuration as excluded (it could be later renamed or unexcluded)
                        var app = await config.FindAppAsync(logrec.ApplicationPath);

                        if (app == null)
                        {
                            app = new Application {
                                IsExcluded = true,
                                Path       = logrec.ApplicationPath
                            };
                            await config.AddOrUpdateAppAsync(app);
                        }
                        if (!app.IsExcluded)
                        {
                            logsToSave.Add(logrec);
                        }
                        else
                        {
                            logger.TraceEvent(TraceEventType.Verbose, 0, "Log record for the application '{0}' was not stored as the application is excluded.");
                        }
                    }
                    else
                    {
                        if (logger.Switch.ShouldTrace(TraceEventType.Warning))
                        {
                            logger.TraceEvent(TraceEventType.Warning, 0, "Validation error(s) occured when saving a logrecord: {0}, errors: {1}",
                                              logrec, validationResult.Errors);
                        }
                    }
                }

                if (logsToSave.Count > 0)
                {
                    await logStore.AddLogRecordsAsync(logsToSave);

                    await logStore.UpdateApplicationStatusesAsync(CreateApplicationStatusesList(logsToSave));
                }

                return("OK");
            };
        }