Exemple #1
0
        public async Task ProcessCommands(KustoFunctionsState functionsState)
        {
            IKustoFunction[]   functions = { ListDatabases.Create(), ListTables.Create(), AddUser.Create() };
            KustoFunctionsEnum kustoEnum = KustoFunctionsEnum.None;

            if (functionsState._options.ListDatabases)
            {
                kustoEnum |= KustoFunctionsEnum.ListDatabases;
            }
            if (functionsState._options.ListTables)
            {
                kustoEnum |= KustoFunctionsEnum.ListTables;
            }
            if (functionsState._options.AddUser)
            {
                kustoEnum |= KustoFunctionsEnum.AddUser;
            }
            // TODO: Need to ensure that there is error handling within the contained classes for things like database and table names - should be a validate method on the interface
            foreach (var function in functions)
            {
                if ((function.KustoCommandType & kustoEnum) == function.KustoCommandType)
                {
                    await function.Execute(functionsState);
                }
            }
        }
Exemple #2
0
        public async Task Execute(KustoFunctionsState functionsState)
        {
            try
            {
                var client = await functionsState.GetManagementClient();

                var databases =
                    await client.Databases.ListByClusterAsync(resourceGroupName : functionsState._options.ResourceGroup,
                                                              clusterName : $"{functionsState._options.KustoClusterName}");

                var headerThickness = new LineThickness(LineWidth.Single, LineWidth.Single);

                var doc = new Document(
                    new Grid
                {
                    Color    = Gray,
                    Columns  = { GridLength.Auto, GridLength.Char(20), GridLength.Char(20) },
                    Children =
                    {
                        new Cell("Name")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("Row Count")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("Cache Size (GB)")
                        {
                            Stroke = headerThickness
                        },
                        databases.Select(item =>
                        {
                            var databasesQuery = functionsState.GetDataAdminReader(item.Name.Split('/')[1], ".show database datastats").Result;
                            var dataStats      = new KustoDatastats(databasesQuery);
                            return(new[]
                            {
                                new Cell(dataStats.DatabaseName)
                                {
                                    Color = Yellow
                                },
                                new Cell(dataStats.HotRowCount),
                                new Cell(dataStats.HotCompressedSize.ToString("##,##0.00000000", CultureInfo.InvariantCulture))
                                {
                                    Align = Align.Right
                                },
                            });
                        })
                    }
                }
                    );

                ConsoleRenderer.RenderDocument(doc);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemple #3
0
        public async Task Execute(KustoFunctionsState functionsState)
        {
            try
            {
                List <KustoTableDetail> tableDetails = new List <KustoTableDetail>();
                var databasesQuery = await functionsState.GetDataAdminReader(functionsState._options.DatabaseName, ".show tables details");

                var allTables = databasesQuery.FromDataReader(functionsState._options.DatabaseName);

                foreach (DataRow row in allTables.Tables[0].Rows)
                {
                    tableDetails.Add(new KustoTableDetail(row));
                }

                var headerThickness = new LineThickness(LineWidth.Single, LineWidth.Single);

                var doc = new Document(
                    new Grid
                {
                    Color    = Gray,
                    Columns  = { GridLength.Auto, GridLength.Char(20), GridLength.Char(20), GridLength.Auto },
                    Children =
                    {
                        new Cell("Name")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("Row Count")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("Cache Size (GB)")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("Users/Groups")
                        {
                            Stroke = headerThickness
                        },
                        tableDetails.Select(item =>
                        {
                            var kustoAuthorised = JsonConvert.DeserializeObject <List <KustoAuthorisedPrincipals> >(item.AuthorizedPrincipals);
                            var kaWithType      = kustoAuthorised.Select(item => item.DisplayName + $" [{item.Type}]");
                            string principals   = String.Join('\n', kaWithType);
                            double extentSize   = item.TotalExtentSize / 1000000000;
                            return(new[]
                            {
                                new Cell(item.TableName)
                                {
                                    Color = Yellow
                                },
                                new Cell(item.TotalRowCount),
                                new Cell(extentSize.ToString("##,##0.00000000", CultureInfo.InvariantCulture))
                                {
                                    Align = Align.Right
                                },
                                new Cell(principals)
                                {
                                    Color = Yellow
                                },
                            });
                        })
                    }
                }
                    );

                ConsoleRenderer.RenderDocument(doc);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemple #4
0
        public async Task Execute(KustoFunctionsState functionsState)
        {
            try
            {
                var databasesQuery = await functionsState.GetDataAdminReader(functionsState._options.DatabaseName,
                                                                             $".add table {functionsState._options.TableName} admins('aaduser={functionsState._options.UserName}')", true);

                var allTables = databasesQuery.FromDataReader(functionsState._options.DatabaseName);

                var principals = (from DataRow row in allTables.Tables[0].Rows select new KustoPrincipal(row)).ToList();

                var headerThickness = new LineThickness(LineWidth.Single, LineWidth.Single);

                var doc = new Document(
                    new Grid
                {
                    Color    = Gray,
                    Columns  = { GridLength.Auto, GridLength.Char(20), GridLength.Char(20), GridLength.Auto },
                    Children =
                    {
                        new Cell("Role")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("Principal Type")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("Display Name")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("PrincipalFQN")
                        {
                            Stroke = headerThickness
                        },
                        principals.Select(item =>
                        {
                            return(new[]
                            {
                                new Cell(item.Role)
                                {
                                    Color = Yellow
                                },
                                new Cell(item.PrincipalType),
                                new Cell(item.PrincipalDisplayName),
                                new Cell(item.PrincipalFQN)
                                {
                                    Color = Yellow
                                },
                            });
                        })
                    }
                }
                    );

                ConsoleRenderer.RenderDocument(doc);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }