Beispiel #1
0
        public MessageProcessor(IMonikServiceSettings settings, IRepository repository, 
            ICacheLog cacheLog, ICacheKeepAlive cacheKeepAlive, ICacheMetric cacheMetric,
            IMonik monik)
        {
            _settings = settings;
            _repository = repository;
            _cacheLog = cacheLog;
            _cacheKeepAlive = cacheKeepAlive;
            _cacheMetric = cacheMetric;
            _monik = monik;

            _cleaner = Scheduler.CreatePerHour(_monik, CleanerTask, "cleaner");
            _statist = Scheduler.CreatePerHour(_monik, StatistTask, "statist");
        }
Beispiel #2
0
        public SecureNancyModule(ICacheMetric cacheMetric, ICacheSourceInstance sourceInstanceCache, IMonik monik)
        {
            this.RequiresAuthentication();

            Delete("/instances/{id:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Delete /instances/{args.id} by {Context.CurrentUser.Identity.Name}");
                    sourceInstanceCache.RemoveInstance(args.id);
                    return(HttpStatusCode.OK);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method DELETE /instances/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Delete("/metrics/{id:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Delete /metrics/{args.id} by {Context.CurrentUser.Identity.Name}");
                    cacheMetric.RemoveMetric(args.id);
                    return(HttpStatusCode.OK);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method DELETE /metrics/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Delete("/sources/{id:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Delete /sources/{args.id} by {Context.CurrentUser.Identity.Name}");
                    sourceInstanceCache.RemoveSource((short)args.id);
                    return(HttpStatusCode.OK);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method DELETE /sources/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Post("/groups", args =>
            {
                try
                {
                    var group = this.Bind <Group_>();
                    monik.ApplicationInfo($"Post /groups {group.Name} by {Context.CurrentUser.Identity.Name}");
                    var result = sourceInstanceCache.CreateGroup(group);
                    return(Response.AsJson(result, HttpStatusCode.Created)
                           .WithHeader("Location", $"/groups/{result.ID}"));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method POST /groups : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });
            Delete("/groups/{id:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Delete /groups/{args.id} by {Context.CurrentUser.Identity.Name}");
                    var result = sourceInstanceCache.RemoveGroup((short)args.id);
                    return(result ? HttpStatusCode.OK : HttpStatusCode.NotFound);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method DELETE /groups/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });
            Put("/groups/{groupId:int}/instances/{instanceId:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Put /groups/{args.groupId}/instances/{args.instanceId} by {Context.CurrentUser.Identity.Name}");
                    sourceInstanceCache.AddInstanceToGroup(args.instanceId, (short)args.groupId);
                    return(HttpStatusCode.OK);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method PUT /groups/id/instances/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });
            Delete("/groups/{groupId:int}/instances/{instanceId:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Delete /groups/{args.groupId}/instances/{args.instanceId} by {Context.CurrentUser.Identity.Name}");
                    var result = sourceInstanceCache.RemoveInstanceFromGroup(args.instanceId, (short)args.groupId);
                    return(result ? HttpStatusCode.OK : HttpStatusCode.NotFound);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method DELETE /groups/id/instances/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });
        }
Beispiel #3
0
        public MainNancyModule(IRepository repo, ICacheLog cacheLog, ICacheKeepAlive cacheKeepAlive,
                               ICacheMetric cacheMetric, ICacheSourceInstance sourceInstanceCache, IMonik monik)
        {
            _repo                = repo;
            _cacheLog            = cacheLog;
            _cacheKeepAlive      = cacheKeepAlive;
            _cacheMetric         = cacheMetric;
            _sourceInstanceCache = sourceInstanceCache;
            _monik               = monik;

            Get("/sources", args =>
            {
                try
                {
                    List <Source> result = sourceInstanceCache.GetAllSources();
                    return(Response.AsJson <Source[]>(result.ToArray()));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /sources : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/instances", args =>
            {
                try
                {
                    List <Instance> result = sourceInstanceCache.GetAllInstances();
                    return(Response.AsJson <Instance[]>(result.ToArray()));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /instances : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/groups", args =>
            {
                try
                {
                    List <Group> result = sourceInstanceCache.GetAllGroups();
                    return(Response.AsJson <Group[]>(result.ToArray()));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /groups : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Post("/logs5", args =>
            {
                try
                {
                    var filter = this.Bind <LogRequest>();

                    List <Log_> result = cacheLog.GetLogs5(filter);
                    return(Response.AsJson <Log_[]>(result.ToArray()));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /logs5 : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Post("/keepalive2", args =>
            {
                var filter = this.Bind <KeepAliveRequest>();

                try
                {
                    List <KeepAlive_> result = cacheKeepAlive.GetKeepAlive2(filter);
                    return(Response.AsJson <KeepAlive_[]>(result.ToArray()));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /keepalive : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/keepalive-status", args =>
            {
                var filter = new KeepAliveRequest();
                return(GetKeepAliveStatuses(filter));
            });

            Post("/keepalive-status", args =>
            {
                var filter = this.Bind <KeepAliveRequest>();
                return(GetKeepAliveStatuses(filter));
            });

            Get("/metrics", args =>
            {
                try
                {
                    var result = cacheMetric.GetMetricsDescriptions();
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/metrics/currents", args =>
            {
                try
                {
                    var result = cacheMetric.GetAllCurrentMeasures();
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics/currents : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Post("/metrics/currents", args =>
            {
                try
                {
                    var filter = this.Bind <MetricRequest>();

                    var result = cacheMetric.GetCurrentMeasures(filter);
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method POST /metrics/currents : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/metrics/{id:int}/current", args =>
            {
                try
                {
                    int metricId = args.id;

                    var result = cacheMetric.GetCurrentMeasure(metricId);
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics/id/current : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/metrics/windows", args =>
            {
                try
                {
                    var result = cacheMetric.GetAllWindowsMeasures();
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics/windows : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Post("/metrics/windows", args =>
            {
                try
                {
                    var filter = this.Bind <MetricRequest>();

                    var result = cacheMetric.GetWindowMeasures(filter);
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method POST /metrics/windows : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/metrics/{id:int}/window", args =>
            {
                try
                {
                    int metricId = args.id;

                    var result = cacheMetric.GetWindowMeasure(metricId);
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics/id/window : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/metrics/{id:int}/history", args =>
            {
                try
                {
                    int metricId = args.id;
                    var p        = this.Bind <MetricHistoryRequestParameters>();
                    var result   = cacheMetric.GetMetricHistory(metricId, p.Amount, p.Skip);
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics/id/history : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });
        }