Esempio n. 1
0
        internal static int Run(int engineRequestTimeoutMS)
        {
            // check to see if metadata binary exists
            string telemetryMetadataFile = Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.METADATA_BINARY_FILE_NAME);

            TelemetryDashboardMain.Logger.Log("Trying to get metadata binary file: " + telemetryMetadataFile, LogLevel.Debug);
            TelemetryMetadata oldMeta, newMetadata;

            if (File.Exists(telemetryMetadataFile))
            {
                TelemetryDashboardMain.Logger.Log("Found metadata file, will load contents.", LogLevel.Info);
                Stream          openFileStream = File.OpenRead(telemetryMetadataFile);
                BinaryFormatter deserializer   = new BinaryFormatter();
                oldMeta = (TelemetryMetadata)deserializer.Deserialize(openFileStream);
                openFileStream.Close();
            }
            else
            {
                oldMeta = new TelemetryMetadata();
            }

            newMetadata = new TelemetryMetadata(true);

            GetAboutServiceInfo(newMetadata);
            GetRepositoryExtensions(newMetadata);
            GetRepositoryExtensionSchemas(newMetadata);
            GetRepositoryEngineInfos(newMetadata);
            GetRepositoryUsers(newMetadata);
            GetRepositoryApps(newMetadata);
            IList <UnparsedSheet> unparsedSheets = GetRepositorySheets();

            newMetadata.ParseSheets(unparsedSheets);
            newMetadata.PopulateFromCachedMetadata(oldMeta);


            string centralNodeHost;

            if (!TelemetryDashboardMain.ArgsManager.UseLocalEngine)
            {
                centralNodeHost = GetCentralNodeHostname();
                TelemetryDashboardMain.Logger.Log("Got central node hostname for engine calls: " + centralNodeHost, LogLevel.Info);
            }
            else
            {
                centralNodeHost = CertificateConfigHelpers.Hostname;
                TelemetryDashboardMain.Logger.Log("Arg '-uselocalengine' was used. Using hostname '" + centralNodeHost + "' for all engine calls.", LogLevel.Info);
            }
            GetEngineObjects(centralNodeHost, newMetadata, engineRequestTimeoutMS);

            Stream          SaveFileStream = File.Create(telemetryMetadataFile);
            BinaryFormatter serializer     = new BinaryFormatter();

            serializer.Serialize(SaveFileStream, newMetadata);
            SaveFileStream.Close();

            MetadataWriter.DeleteMetadataFiles();
            MetadataWriter.WriteMetadataToFile(newMetadata);

            return(0);
        }
Esempio n. 2
0
        internal static void WriteMetadataToFile(TelemetryMetadata meta)
        {
            TelemetryDashboardMain.Logger.Log("Writing metadata files to disk.", LogLevel.Info);

            // check to see if folder exists
            TelemetryDashboardMain.Logger.Log("Checking to see if output dir exists.", LogLevel.Debug);
            string outputDir = Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME);

            if (!Directory.Exists(outputDir))
            {
                TelemetryDashboardMain.Logger.Log("Output dir didn't exist. Creating.", LogLevel.Debug);

                Directory.CreateDirectory(outputDir);
            }

            TelemetryDashboardMain.Logger.Log("Writing System Info file to disk.", LogLevel.Info);
            WriteSystemInfoFile(meta);

            TelemetryDashboardMain.Logger.Log("Writing Extensions file to disk.", LogLevel.Info);
            WriteExtensionsMetadataFile(meta);

            TelemetryDashboardMain.Logger.Log("Writing Extension Schemas file to disk.", LogLevel.Info);
            WriteExtensionSchemasMetadataFile(meta);

            TelemetryDashboardMain.Logger.Log("Writing Engine Infos file to disk.", LogLevel.Info);
            WriteEngineInfosMetadataFile(meta);

            TelemetryDashboardMain.Logger.Log("Writing User file to disk.", LogLevel.Info);
            WriteUsersMetadataFile(meta);

            TelemetryDashboardMain.Logger.Log("Writing all App metadata files to disk.", LogLevel.Info);
            WriteAppsMetadataFiles(meta);
        }
Esempio n. 3
0
        private static void WriteSystemInfoFile(TelemetryMetadata meta)
        {
            StringBuilder sb = new StringBuilder();

            WriteHeaders(sb, HEADERS_SYSTEMINFO);

            foreach (Extension extension in meta.Extensions)
            {
                sb.Append(meta.Version);
                sb.Append(CSV_SEPARATOR);
                sb.Append(meta.ReleaseLabel);
                sb.Append('\n');
            }

            WriteFile(sb, Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME, FileLocationManager.METADATA_SYSTEMINFO_FILE_NAME));
        }
Esempio n. 4
0
        private static void WriteEngineInfosMetadataFile(TelemetryMetadata meta)
        {
            StringBuilder sb = new StringBuilder();

            WriteHeaders(sb, HEADERS_ENGINEINFOS);

            foreach (EngineInfo engine in meta.EngineInfos)
            {
                sb.Append(engine.Hostname);
                sb.Append(CSV_SEPARATOR);
                sb.Append("WorkingSetMin");
                sb.Append(CSV_SEPARATOR);
                sb.Append(engine.WorkingSetMin);
                sb.Append('\n');

                sb.Append(engine.Hostname);
                sb.Append(CSV_SEPARATOR);
                sb.Append("WorkingSetMax");
                sb.Append(CSV_SEPARATOR);
                sb.Append(engine.WorkingSetMax);
                sb.Append('\n');

                sb.Append(engine.Hostname);
                sb.Append(CSV_SEPARATOR);
                sb.Append("PerformanceLogLevel");
                sb.Append(CSV_SEPARATOR);
                sb.Append(engine.PerformanceLogLevel);
                sb.Append('\n');

                sb.Append(engine.Hostname);
                sb.Append(CSV_SEPARATOR);
                sb.Append("QIXPerformanceLogLevel");
                sb.Append(CSV_SEPARATOR);
                sb.Append(engine.QIXPerformanceLogLevel);
                sb.Append('\n');

                sb.Append(engine.Hostname);
                sb.Append(CSV_SEPARATOR);
                sb.Append("SessionLogLevel");
                sb.Append(CSV_SEPARATOR);
                sb.Append(engine.SessionLogLevel);
                sb.Append('\n');
            }

            WriteFile(sb, Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME, FileLocationManager.METADATA_ENGINEINFOS_FILE_NAME));
        }
Esempio n. 5
0
        private static void WriteExtensionSchemasMetadataFile(TelemetryMetadata meta)
        {
            StringBuilder sb = new StringBuilder();

            WriteHeaders(sb, HEADERS_EXTENSIONSCHEMAS);

            foreach (ExtensionSchema schema in meta.ExtensionSchemas)
            {
                sb.Append(schema.ID);
                sb.Append(CSV_SEPARATOR);
                sb.Append(schema.Name);
                sb.Append(CSV_SEPARATOR);
                sb.Append(schema.Type);
                sb.Append('\n');
            }

            WriteFile(sb, Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME, FileLocationManager.METADATA_EXTENSIONSCHEMAS_FILE_NAME));
        }
Esempio n. 6
0
        private static void WriteUsersMetadataFile(TelemetryMetadata meta)
        {
            StringBuilder sb = new StringBuilder();

            WriteHeaders(sb, HEADERS_USERS);

            foreach (User user in meta.Users)
            {
                sb.Append(user.ID.ToString());
                sb.Append(CSV_SEPARATOR);
                sb.Append(user.UserID);
                sb.Append(CSV_SEPARATOR);
                sb.Append(user.UserDirectory);
                sb.Append(CSV_SEPARATOR);
                sb.Append(user.Username);
                sb.Append('\n');
            }

            WriteFile(sb, Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME, FileLocationManager.METADATA_USERS_FILE_NAME));
        }
Esempio n. 7
0
        private static void WriteExtensionsMetadataFile(TelemetryMetadata meta)
        {
            StringBuilder sb = new StringBuilder();

            WriteHeaders(sb, HEADERS_EXTENSIONS);

            foreach (Extension extension in meta.Extensions)
            {
                sb.Append(extension.ID.ToString());
                sb.Append(CSV_SEPARATOR);
                sb.Append(extension.CreatedDate.ToString("O"));
                sb.Append(CSV_SEPARATOR);
                sb.Append(extension.Name);
                sb.Append(CSV_SEPARATOR);
                sb.Append(extension.OwnerID.ToString());
                sb.Append(CSV_SEPARATOR);
                sb.Append(extension.DashboardBundle.ToString());
                sb.Append(CSV_SEPARATOR);
                sb.Append(extension.VisualizationBundle.ToString());
                sb.Append('\n');
            }

            WriteFile(sb, Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME, FileLocationManager.METADATA_EXTENSIONS_FILE_NAME));
        }
Esempio n. 8
0
        internal static void DeleteMetadataFiles()
        {
            TelemetryDashboardMain.Logger.Log("Deleting old metadata files.", LogLevel.Info);

            try
            {
                string outputDir = Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME);
                if (Directory.Exists(outputDir))
                {
                    DirectoryInfo di = new DirectoryInfo(outputDir);

                    foreach (FileInfo file in di.GetFiles())
                    {
                        TelemetryDashboardMain.Logger.Log("Deleting: " + file.FullName, LogLevel.Debug);

                        file.Delete();
                    }
                }
            }
            catch (Exception e)
            {
                TelemetryDashboardMain.Logger.Log("Error deleting file. Message: " + e.Message, LogLevel.Error);
            }
        }
Esempio n. 9
0
        private static void WriteAppsMetadataFiles(TelemetryMetadata meta)
        {
            StringBuilder appsSB           = new StringBuilder();
            StringBuilder sheetsSB         = new StringBuilder();
            StringBuilder visualizationsSB = new StringBuilder();

            WriteHeaders(appsSB, HEADERS_APPS);
            WriteHeaders(sheetsSB, HEADERS_SHEETS);
            WriteHeaders(visualizationsSB, HEADERS_VISUALIZATIONS);

            foreach (KeyValuePair <Guid, QRSApp> app in meta.Apps)
            {
                appsSB.Append(app.Key.ToString());
                appsSB.Append(CSV_SEPARATOR);
                appsSB.Append(app.Value.Name);
                appsSB.Append(CSV_SEPARATOR);
                appsSB.Append(app.Value.AppOwnerID.ToString());
                appsSB.Append(CSV_SEPARATOR);
                appsSB.Append(app.Value.Published);
                if (app.Value.Published)
                {
                    appsSB.Append(CSV_SEPARATOR);
                    appsSB.Append(app.Value.PublishedDateTime.ToString("o"));
                    appsSB.Append(CSV_SEPARATOR);
                    appsSB.Append(app.Value.StreamID.ToString());
                    appsSB.Append(CSV_SEPARATOR);
                    appsSB.Append(app.Value.StreamName);
                }
                appsSB.Append('\n');

                foreach (KeyValuePair <Guid, QRSSheet> sheet in app.Value.Sheets)
                {
                    sheetsSB.Append(app.Key.ToString());
                    sheetsSB.Append(CSV_SEPARATOR);
                    sheetsSB.Append(sheet.Value.EngineObjectID);
                    sheetsSB.Append(CSV_SEPARATOR);
                    sheetsSB.Append(sheet.Value.Name);
                    sheetsSB.Append(CSV_SEPARATOR);
                    sheetsSB.Append(sheet.Value.OwnerID);
                    sheetsSB.Append(CSV_SEPARATOR);
                    sheetsSB.Append(sheet.Value.Published);
                    sheetsSB.Append(CSV_SEPARATOR);
                    sheetsSB.Append(sheet.Value.Approved);
                    sheetsSB.Append('\n');

                    foreach (Visualization viz in sheet.Value.Visualizations)
                    {
                        visualizationsSB.Append(app.Key.ToString() + '|' + sheet.Value.EngineObjectID);
                        visualizationsSB.Append(CSV_SEPARATOR);
                        visualizationsSB.Append(viz.ObjectName);
                        visualizationsSB.Append(CSV_SEPARATOR);
                        visualizationsSB.Append(viz.ObjectType);
                        visualizationsSB.Append('\n');
                    }
                }
            }

            WriteFile(appsSB, Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME, FileLocationManager.METADATA_APPS_FILE_NAME));
            WriteFile(sheetsSB, Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME, FileLocationManager.METADATA_SHEETS_FILE_NAME));
            WriteFile(visualizationsSB, Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME, FileLocationManager.METADATA_VISUALIZATIONS_FILE_NAME));
        }
        private static void CreateDataConnections()
        {
            // Add TelemetryMetadata dataconnection
            Tuple <HttpStatusCode, string> dataConnections = TelemetryDashboardMain.QRSRequest.MakeRequest("/dataconnection?filter=name eq 'TelemetryMetadata'", HttpMethod.Get);

            if (dataConnections.Item1 != HttpStatusCode.OK)
            {
                throw new InvalidResponseException(dataConnections.Item1.ToString() + " returned when trying to get 'TelmetryMetadata' data connections. Request failed.");
            }
            JArray listOfDataconnections = JArray.Parse(dataConnections.Item2);

            if (listOfDataconnections.Count == 0)
            {
                TelemetryDashboardMain.Logger.Log("Existing Data Connection 'TelemetryMetadata' was not found.", LogLevel.Info);

                string connectionStringPath = Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME) + @"\";
                TelemetryDashboardMain.Logger.Log("Building body for 'TelemetryMetadata' data connection. Connection string path: " + connectionStringPath, LogLevel.Debug);
                connectionStringPath = connectionStringPath.Replace("\\", "\\\\");
                string body = @"
			{
				'name': 'TelemetryMetadata',
				'connectionstring': '"                 + connectionStringPath + @"',
				'type': 'folder',
				'username': ''
			}"            ;


                Tuple <HttpStatusCode, string> createdConnection = TelemetryDashboardMain.QRSRequest.MakeRequest("/dataconnection", HttpMethod.Post, HTTPContentType.json, Encoding.UTF8.GetBytes(body));
                if (createdConnection.Item1 != HttpStatusCode.Created)
                {
                    throw new InvalidResponseException(dataConnections.Item1.ToString() + " returned when trying to create 'TelemetryMetadata' data connection. Request failed.");
                }
                TelemetryDashboardMain.Logger.Log("Data Connection 'TelemetryMetadata' was created.", LogLevel.Info);
            }
            else
            {
                TelemetryDashboardMain.Logger.Log("Existing Data Connection 'TelemetryMetadata' was found.", LogLevel.Info);

                listOfDataconnections[0]["connectionstring"] = Path.Combine(FileLocationManager.GetTelemetrySharePath(), FileLocationManager.TELEMETRY_OUTPUT_FOLDER_NAME) + "\\";
                listOfDataconnections[0]["modifiedDate"]     = DateTime.UtcNow.ToString("s") + "Z";
                string appId = listOfDataconnections[0]["id"].ToString();
                Tuple <HttpStatusCode, string> updatedConnection = TelemetryDashboardMain.QRSRequest.MakeRequest("/dataconnection/" + appId, HttpMethod.Put, HTTPContentType.json, Encoding.UTF8.GetBytes(listOfDataconnections[0].ToString()));
                if (updatedConnection.Item1 != HttpStatusCode.OK)
                {
                    throw new InvalidResponseException(dataConnections.Item1.ToString() + " returned when trying to update 'TelemetryMetadata' data connection. Request failed.");
                }
                TelemetryDashboardMain.Logger.Log("Data Connection 'TelemetryMetadata' was updated.", LogLevel.Info);
            }

            // Add EngineSettings dataconnection
            Tuple <HttpStatusCode, string> engineSettingDataconnection = TelemetryDashboardMain.QRSRequest.MakeRequest("/dataconnection?filter=name eq 'EngineSettingsFolder'", HttpMethod.Get);

            if (dataConnections.Item1 != HttpStatusCode.OK)
            {
                throw new InvalidResponseException(dataConnections.Item1.ToString() + " returned when trying to get 'EngineSettingsFolder' data connection. Request failed.");
            }
            listOfDataconnections = JArray.Parse(engineSettingDataconnection.Item2);
            if (listOfDataconnections.Count == 0)
            {
                TelemetryDashboardMain.Logger.Log("Existing Data Connection 'EngineSettingsFolder' was not found.", LogLevel.Info);

                string body = @"
					{
						'name': 'EngineSettingsFolder',
						'connectionstring': 'C:\\ProgramData\\Qlik\\Sense\\Engine\\',
						'type': 'folder',
						'username': ''
					}"                    ;

                Tuple <HttpStatusCode, string> createdConnection = TelemetryDashboardMain.QRSRequest.MakeRequest("/dataconnection", HttpMethod.Post, HTTPContentType.json, Encoding.UTF8.GetBytes(body));
                if (createdConnection.Item1 != HttpStatusCode.Created)
                {
                    throw new InvalidResponseException(dataConnections.Item1.ToString() + " returned when trying to create 'EngineSettingsFolder' data connection. Request failed.");
                }
                TelemetryDashboardMain.Logger.Log("Data Connection 'EngineSettingsFolder' was updated.", LogLevel.Info);
            }
            else
            {
                TelemetryDashboardMain.Logger.Log("Existing Data Connection 'EngineSettingsFolder' already exists.", LogLevel.Info);
            }

            return;
        }
        internal static int Run(string serviceAccount, bool skipCopy = false)
        {
            TelemetryDashboardMain.Logger.Log("Running in initialize mode.", LogLevel.Info);

            string telemetrySharePath = FileLocationManager.GetTelemetrySharePath();
            string telemetryExePath   = Path.Combine(telemetrySharePath, FileLocationManager.TELEMETRY_EXE_FILE_NAME);

            TelemetryDashboardMain.Logger.Log("Current TelemetryDashboard.exe path: " + FileLocationManager.WorkingTelemetryDashboardExePath, LogLevel.Debug);
            TelemetryDashboardMain.Logger.Log("Share folder TelemetryDashboard.exe path: " + telemetryExePath, LogLevel.Debug);
            TelemetryDashboardMain.Logger.Log("Share folder TelemetryDashboard.exe root path: " + telemetrySharePath, LogLevel.Debug);


            if (!skipCopy)
            {
                string telemetryExeNonUNCPath = FileLocationManager.GetPath(telemetryExePath);
                TelemetryDashboardMain.Logger.Log("GetPath() for telemetryExePath: " + telemetryExeNonUNCPath, LogLevel.Debug);

                if (telemetryExeNonUNCPath != FileLocationManager.WorkingTelemetryDashboardExePath)
                {
                    TelemetryDashboardMain.Logger.Log("Not running executable in Telemetry Folder, will copy file.", LogLevel.Debug);

                    bool doCopy = true;
                    if (File.Exists(telemetryExePath))
                    {
                        try
                        {
                            TelemetryDashboardMain.Logger.Log("Old TelemetryDashboard.exe file found. Deleting.", LogLevel.Debug);

                            File.Delete(telemetryExePath);
                        }
                        catch (UnauthorizedAccessException)
                        {
                            TelemetryDashboardMain.Logger.Log(string.Format("Tried to delete '{0}', unauthorizaed access. This probably means you are running this executable and can ignore the error, OR you do not have access to delete this file.", telemetryExePath), LogLevel.Debug);
                            doCopy = false;
                        }
                    }
                    if (doCopy)
                    {
                        if (!Directory.Exists(telemetrySharePath))
                        {
                            Directory.CreateDirectory(telemetrySharePath);
                        }
                        TelemetryDashboardMain.Logger.Log("Copying TelemetryDashboard.exe.", LogLevel.Debug);
                        File.Copy(FileLocationManager.WorkingTelemetryDashboardExePath, telemetryExePath);

                        try
                        {
                            // Change Permissions to allow service account:
                            DirectoryInfo dInfo = new DirectoryInfo(telemetrySharePath);
                            FileInfo      fInfo = new FileInfo(telemetryExePath);

                            DirectorySecurity dSecurity = dInfo.GetAccessControl();
                            FileSecurity      fSecurity = fInfo.GetAccessControl();

                            dSecurity.AddAccessRule(new FileSystemAccessRule(serviceAccount, FileSystemRights.FullControl, AccessControlType.Allow));
                            fSecurity.AddAccessRule(new FileSystemAccessRule(serviceAccount, FileSystemRights.FullControl, AccessControlType.Allow));

                            dInfo.SetAccessControl(dSecurity);
                            fInfo.SetAccessControl(fSecurity);
                        }
                        catch (IdentityNotMappedException)
                        {
                            TelemetryDashboardMain.Logger.Log("Invalid service account '" + serviceAccount + "' was entered. Initialize failed to complete.", LogLevel.Error);
                            return(1);
                        }
                    }
                }
            }
            else
            {
                TelemetryDashboardMain.Logger.Log("Will NOT copy file to share location due to command line arguments flag set.", LogLevel.Info);
                TelemetryDashboardMain.Logger.Log("FILE LOCATION OF EXECUTABLE CURRENTLY RUNNING MUST MATCH: " + telemetryExePath, LogLevel.Info);
                TelemetryDashboardMain.Logger.Log("If this is not the case, you can copy the executable to the above location after this initialization completes.", LogLevel.Info);
            }


            TelemetryDashboardMain.Logger.Log("Ready to import app.", LogLevel.Debug);
            string appGUID = ImportApp();

            TelemetryDashboardMain.Logger.Log("Ready to create data connections.", LogLevel.Debug);
            CreateDataConnections();

            TelemetryDashboardMain.Logger.Log("Ready to create tasks.", LogLevel.Debug);
            CreateTasks(appGUID, telemetryExePath);

            return(0);
        }