Esempio n. 1
0
 private static List <Func <object> > CatCommands(ElasticClient elastic)
 {
     return(new List <Func <object> >
     {
         () => elastic.CatAliases(new CatAliasesRequest()),
         () => elastic.CatAllocation(new CatAllocationRequest()),
         () => elastic.CatCount(new CatCountRequest()),
         () => elastic.CatFielddata(new CatFielddataRequest()),
         () => elastic.CatHealth(new CatHealthRequest()),
         () => elastic.CatHelp(new CatHelpRequest()),
         () => elastic.CatIndices(new CatIndicesRequest()),
         () => elastic.CatMaster(new CatMasterRequest()),
         () => elastic.CatNodeAttributes(new CatNodeAttributesRequest()),
         () => elastic.CatNodes(new CatNodesRequest()),
         () => elastic.CatPendingTasks(new CatPendingTasksRequest()),
         () => elastic.CatPlugins(new CatPluginsRequest()),
         () => elastic.CatRecovery(new CatRecoveryRequest()),
         () => elastic.CatRepositories(new CatRepositoriesRequest()),
         () => elastic.CatSegments(new CatSegmentsRequest()),
         () => elastic.CatShards(new CatShardsRequest()),
         // CatSnapshots is failing with a JSON deserialization error.
         // It might be a bug in the client or an incompatibility between client
         // and server versions.
         // () => elastic.CatSnapshots(new CatSnapshotsRequest()),
         () => elastic.CatTasks(new CatTasksRequest()),
         () => elastic.CatTemplates(new CatTemplatesRequest()),
         () => elastic.CatThreadPool(new CatThreadPoolRequest()),
     });
 }
Esempio n. 2
0
 private static List <Func <object> > CatCommands(ElasticClient elastic)
 {
     return(new List <Func <object> >
     {
         () => elastic.CatAliases(new CatAliasesRequest()),
         () => elastic.CatAllocation(new CatAllocationRequest()),
         () => elastic.CatCount(new CatCountRequest()),
         () => elastic.CatFielddata(new CatFielddataRequest()),
         () => elastic.CatHealth(new CatHealthRequest()),
         () => elastic.CatHelp(new CatHelpRequest()),
         () => elastic.CatIndices(new CatIndicesRequest()),
         () => elastic.CatMaster(new CatMasterRequest()),
         () => elastic.CatNodeAttributes(new CatNodeAttributesRequest()),
         () => elastic.CatNodes(new CatNodesRequest()),
         () => elastic.CatPendingTasks(new CatPendingTasksRequest()),
         () => elastic.CatPlugins(new CatPluginsRequest()),
         () => elastic.CatRecovery(new CatRecoveryRequest()),
         () => elastic.CatRepositories(new CatRepositoriesRequest()),
         () => elastic.CatSegments(new CatSegmentsRequest()),
         () => elastic.CatShards(new CatShardsRequest()),
         () => elastic.CatSnapshots(new CatSnapshotsRequest()),
         () => elastic.CatTasks(new CatTasksRequest()),
         () => elastic.CatTemplates(new CatTemplatesRequest()),
         () => elastic.CatThreadPool(new CatThreadPoolRequest()),
     });
 }
Esempio n. 3
0
        public Dictionary <string, string> GetAllAliases(string prefix)
        {
            var allAliases = _client.CatAliases();

            var myAliases = allAliases.Records.Where(x => x.Index.StartsWith(prefix)).ToDictionary(x => x.Alias, y => y.Index);

            return(myAliases);
        }
        public ElasticsearchResponse GetElasticHealth(IEnumerable <Uri> uris, IEnumerable <string> requiredAliases, string environment)
        {
            try
            {
                using (var connectionSettings = new ConnectionSettings(new StaticConnectionPool(uris)))
                {
                    var elasticClient = new ElasticClient(connectionSettings);
                    var catAliases    = elasticClient
                                        .CatAliases()
                                        .Records
                                        .Where(m => m.Alias.StartsWith(environment)).ToList();

                    var rawAliases = catAliases.Select(al => al.Alias.Replace(environment, string.Empty));

                    var aliases = new List <ElasticsearchAlias>();

                    foreach (var catAlias in catAliases)
                    {
                        var index = elasticClient.CatIndices(m => m.Index(catAlias.Index));

                        aliases.Add(new ElasticsearchAlias
                        {
                            AliasName     = catAlias.Alias,
                            IndexName     = catAlias.Index,
                            Status        = index.Records.FirstOrDefault()?.Status,
                            DocumentCount = index.Records.FirstOrDefault()?.DocsCount,
                            Health        = index.Records.FirstOrDefault()?.Health
                        });
                    }
                    return(new ElasticsearchResponse
                    {
                        RequiredAliasesExist = requiredAliases.All(al => rawAliases.Contains(al)),
                        ElasticsearchAliases = aliases
                    });
                }
            }
            catch (Exception exception)
            {
                _logger.Warn(exception, "Not able to get aliases");

                return(new ElasticsearchResponse {
                    ElasticsearchAliases = new List <ElasticsearchAlias>(), Exception = exception
                });
            }
        }
        public ICatResponse <CatAliasesRecord> AliasList()
        {
            var request = new CatAliasesRequest();

            return(client.CatAliases(request));
        }