Exemple #1
0
        void KnownSettingsAreReadCorrectly()
        {
            var folder       = @"C:\ProgramData\Elastic\Kibana\";
            var loggingDest  = $@"{folder}\logs";
            var serverHost   = "localhost";
            var serverPort   = 5601;
            var basePath     = "/";
            var serverName   = "my-hostname";
            var defaultRoute = "/app/kibana";
            var esUrl        = "http://*****:*****@"C:\servercert";
            var serverKey    = @"C:\serverkey";
            var esCert       = @"C:\escert";
            var esKey        = @"C:\eskey";
            var esCa         = @"C:\esca";

            var yaml     = $@"elasticsearch.ssl.ca: {esCa}
elasticsearch.ssl.cert: {esCert}
elasticsearch.ssl.key: {esKey}
elasticsearch.url: {esUrl}
kibana.index: {kibanaIndex}
logging.dest: {loggingDest}
server.basePath: {basePath}
server.defaultRoute: {defaultRoute}
server.host: {serverHost}
server.name: {serverName}
server.port: {serverPort}
server.ssl.cert: {serverCert}
server.ssl.key: {serverKey}
status.allowAnonymous: true
";
            var fs       = FakeYaml(yaml);
            var optsFile = new KibanaYamlConfiguration(_path, fs);
            var settings = optsFile.Settings;

            settings.ServerPort.Should().Be(serverPort);
            settings.ServerHost.Should().Be(serverHost);
            settings.ServerBasePath.Should().Be(basePath);
            settings.ServerDefaultRoute.Should().Be(defaultRoute);
            settings.ElasticsearchUrl.Should().Be(esUrl);
            settings.KibanaIndex.Should().Be(kibanaIndex);
            settings.ServerCert.Should().Be(serverCert);
            settings.ServerKey.Should().Be(serverKey);
            settings.ElasticsearchCert.Should().Be(esCert);
            settings.ElasticsearchKey.Should().Be(esKey);
            settings.ElasticsearchCA.Should().Be(esCa);
            settings.LoggingDestination.Should().Be(loggingDest);
            settings.AllowAnonymousAccess.Should().Be(true);
            optsFile.Save();

            var fileContentsAfterSave = fs.File.ReadAllText(_path);

            fileContentsAfterSave.Replace("\r", "").Should().Be(yaml.Replace("\r", ""));
        }
        public KibanaProcess(IEnumerable <string> args) : base(null, null, null)
        {
            this.HomeDirectory = (this.HomeDirectory
                                  ?? Environment.GetEnvironmentVariable(KibanaEnvironmentVariables.KIBANA_HOME_ENV_VAR, EnvironmentVariableTarget.Machine)
                                  ?? Directory.GetParent(".").FullName).TrimEnd('\\');

            this.ConfigDirectory = (this.ConfigDirectory
                                    ?? Environment.GetEnvironmentVariable(KibanaEnvironmentVariables.KIBANA_CONFIG_ENV_VAR, EnvironmentVariableTarget.Machine)
                                    ?? Path.Combine(this.HomeDirectory, "config")).TrimEnd('\\');

            this.JsPath     = Path.Combine(this.HomeDirectory, @"src\cli");
            this.ConfigFile = Path.Combine(this.ConfigDirectory, "kibana.yml");
            this.ProcessExe = Path.Combine(this.HomeDirectory, @"node\node.exe");

            var yamlConfig = KibanaYamlConfiguration.FromFolder(this.ConfigDirectory);

            this.LogFile = yamlConfig.Settings.LoggingDestination;
            var parsedArguments = this.ParseArguments(args);

            this.Arguments = this.CreateObservableProcessArguments(parsedArguments);
        }
        protected override bool ExecuteTask()
        {
            this.Session.SendActionStart(TotalTicks, ActionName, "Configuring Kibana", "Configuring Kibana: [1]");
            var locations  = this.InstallationModel.LocationsModel;
            var config     = this.InstallationModel.ConfigurationModel;
            var connecting = this.InstallationModel.ConnectingModel;

            this.Session.SendProgress(1000, "reading kibana.yml from " + locations.ConfigDirectory);
            var yaml = KibanaYamlConfiguration.FromFolder(locations.ConfigDirectory, this.FileSystem);

            this.Session.SendProgress(1000, "updating kibana.yml");
            var settings = yaml.Settings;

            settings.LoggingDestination = locations.LogsFile;
            settings.ServerHost         = config.HostName;
            settings.ServerPort         = config.HttpPort;
            settings.ServerBasePath     = config.BasePath;
            settings.ServerName         = config.ServerName;
            settings.ServerKey          = config.ServerKey;
            settings.ServerCert         = config.ServerCertificate;
            settings.ServerDefaultRoute = config.DefaultRoute;
            settings.ElasticsearchUrl   = connecting.Url;
            settings.KibanaIndex        = connecting.IndexName;
            settings.ElasticsearchKey   = connecting.ElasticsearchKey;
            settings.ElasticsearchCert  = connecting.ElasticsearchCert;
            settings.ElasticsearchCA    = connecting.ElasticsearchCA;
            yaml.Save();

            // log file needs to exist for plugin installation
            if (locations.LogsFile != "stdout" && !this.FileSystem.File.Exists(locations.LogsFile))
            {
                var fileInfo = this.FileSystem.FileInfo.FromFileName(locations.LogsFile);
                fileInfo.Directory.Create();
                using (this.FileSystem.File.Create(locations.LogsFile)) { }
            }

            this.Session.SendProgress(1000, "kibana.yml updated");
            return(true);
        }
Exemple #4
0
        protected override bool ExecuteTask()
        {
            if (this.InstallationModel.NoticeModel.AlreadyInstalled && !this.Session.Uninstalling)
            {
                return(true);
            }

            var configDirectory = this.InstallationModel.LocationsModel.ConfigDirectory;

            if (!this.FileSystem.Directory.Exists(configDirectory))
            {
                return(true);
            }

            this.Session.SendActionStart(1000, ActionName, "Removing data, logs, and config directory",
                                         "Removing directories: [1]");

            var yamlConfiguration = KibanaYamlConfiguration.FromFolder(configDirectory);

            var logsDirectory = yamlConfiguration?.Settings?.LoggingDestination ?? string.Empty;

            if (this.FileSystem.Directory.Exists(logsDirectory))
            {
                this.DeleteDirectory(logsDirectory);
            }

            if (this.FileSystem.Directory.Exists(configDirectory))
            {
                this.DeleteDirectory(configDirectory);
            }

            this.Session.SendProgress(1000, "Data, logs, and config directories removed");

            var installDirectory = this.InstallationModel.LocationsModel.InstallDir;

            if (!this.FileSystem.Directory.Exists(installDirectory))
            {
                return(true);
            }

            var directories = this.FileSystem.Directory.GetDirectories(installDirectory).ToList();

            this.Session.SendActionStart((directories.Count * 1000) + 1000, ActionName, "Removing Kibana installation directory",
                                         "Removing directories: [1]");
            foreach (var directory in directories)
            {
                this.Session.Log($"Attemping to delete {directory}");
                this.FileSystem.Directory.Delete(directory, true);
                this.Session.SendProgress(1000, $"{directory} removed");
            }

            if (Empty(installDirectory))
            {
                this.FileSystem.Directory.Delete(installDirectory, true);
            }

            if (Empty(LocationsModel.DefaultCompanyDirectory))
            {
                this.FileSystem.Directory.Delete(LocationsModel.DefaultCompanyDirectory, true);
            }

            this.Session.SendProgress(1000, "Elasticsearch installation directory removed");
            return(true);
        }