Beispiel #1
0
        ///<Summary>
        ///Fetches Alerts based on the parameters passed.
        ///If no parameters are specified returns all the Alerts.
        /// </Summary>
        ///<param name="name">
        ///The name of the Alert
        ///</param>
        ///<param name="severity">
        ///The Severity of the Alert
        ///</param>
        ///<param name="category">
        ///The Category of the Alert
        ///</param>
        ///<param name="number">
        ///The number of alerts to be fetched
        ///</param>
        public static List <Alert> GetAlert(string name = "", string severity = "", string category = "", int?number = null)
        {
            LogUtility.LogInfoFunction("Entered GetAlert.");
            //For Loading the powershell scripts ( Main.ps1 ) in memory.
            LogUtility.LogInfoFunction("Calling BemcliHelper function LoadPowerShellScript(); ");
            PowerShell powershell = BemcliHelper.LoadPowerShellScript();

            //Calling the powershell function GetAlerts(Name,Severity,Category,Number) which is present in BEMCLIScripts\Alerts.psm1
            LogUtility.LogInfoFunction("Invoking PowerShell Command GetAlerts(Name,Severity,Category,Number) ");
            powershell.AddCommand("GetAlerts");
            powershell.AddParameter("Name", name);
            powershell.AddParameter("Severity", severity);
            powershell.AddParameter("Category", category);
            powershell.AddParameter("Number", number);
            powershell.AddCommand("Out-String");
            var results = powershell.Invoke <string>();

            //check if the results string is empty
            if (String.IsNullOrWhiteSpace(results[0]))
            {
                //If the string is empty, there were no records found. Threfore return null.
                LogUtility.LogInfoFunctionFinished();
                return(null);
            }
            //If records are found pass it to ConvertFromJson.
            string mediaServerName = MediaServerController.GetMediaSever();
            var    alertObjects    = ConvertFromJson(results[0]);

            foreach (Alert alert in alertObjects)
            {
                alert.MediaServerName = mediaServerName;
            }
            LogUtility.LogInfoFunctionFinished();
            return(alertObjects);
        }
Beispiel #2
0
        ///<Summary>
        ///Fetches Alerts based on the FromTime and ToTime and the number of Alerts to be fetched.
        ///</Summary>
        public static List <Alert> GetAlertByDate(DateTime fromDate, DateTime toDate, int?number = null)
        {
            LogUtility.LogInfoFunction("Entered GetAlertByDate.");
            //For Loading the powershell scripts ( Main.ps1 )in memory.
            LogUtility.LogInfoFunction("Call to BemcliHelper.LoadPowerShellScript();");
            PowerShell powershell = BemcliHelper.LoadPowerShellScript();

            LogUtility.LogInfoFunction("Invoking PowerShell Command GetAlertsByDate");
            powershell.AddCommand("GetAlertsByDate");
            powershell.AddParameter("FromTime", fromDate);
            powershell.AddParameter("ToTime", toDate);
            powershell.AddParameter("Number", number);
            powershell.AddCommand("Out-String");
            var results = powershell.Invoke <string>();

            //check if the results string is empty
            if (String.IsNullOrWhiteSpace(results[0]))
            {
                LogUtility.LogInfoFunctionFinished();
                //If the string is empty, there were no records found. Threfore return null.
                return(null);
            }
            string mediaServerName = MediaServerController.GetMediaSever();
            //If records are found pass it to ConvertFromJson.
            var alertObjects = ConvertFromJson(results[0]);

            //To det the Media server name.
            foreach (Alert alert in alertObjects)
            {
                alert.MediaServerName = mediaServerName;
            }
            LogUtility.LogInfoFunctionFinished();
            return(alertObjects);
        }
Beispiel #3
0
        /// <summary>
        /// Checks if the File system type and DocumentDB type is enabled
        /// and calls the respective handler methods.
        /// </summary>
        public static void Init()
        {
            try
            {
                LogUtility.CheckLogFileEnabled();

                //Get the file Systems that are enabled.
                IEnumerable <BEArcus.Agent.FileSystemType> fileSystems = Configuration.Instance.DataStores.FileSystem.
                                                                         Where(f => f.Enabled);
                LogUtility.LogInfoFunction("Storing data to enbled File Systems");
                IStorageService fileservice = new FileDataController();
                foreach (FileSystemType fileSystem in fileSystems)
                {
                    UserSettingsHelper.CreateFileSystemSettings(fileSystem.Name);
                    AlertController.SaveAlertData(fileservice, fileSystem.Name);
                    JobController.SaveJobData(fileservice, fileSystem.Name);
                    JobHistoryController.SaveJobHistoryData(fileservice, fileSystem.Name);
                    MediaServerController.SaveMediaServerData(fileservice, fileSystem.Name);
                }

                //Get the DocumentDB data store that are enabled.
                IEnumerable <BEArcus.Agent.DocumentDBType> documentDBStreams = Configuration.Instance.DataStores.DocumentDB.
                                                                               Where(d => d.Enabled);
                LogUtility.LogInfoFunction("Storing data to enbled DocumentDB accounts.");
                //IStorageService documentDBService = new DocumentDBDataController();
                foreach (DocumentDBType documentDB in documentDBStreams)
                {
                    UserSettingsHelper.CreateDocumentDBSettings(documentDB.Name);

                    //Decrypt the Authorization Key to check if it was encryped earlier
                    string decrypedAuthorizationKey = SecurityController.Decrypt(documentDB.AuthorizationKey);

                    //Decrypt method returns null if the Authorization key was not Encrypted earlier
                    if (string.IsNullOrEmpty(decrypedAuthorizationKey))
                    {
                        //Encrypt Authorization Key
                        string encryptedAuthorizationKey = SecurityController.Encrypt(documentDB.AuthorizationKey);
                        //Encrypt EndpointUrl
                        string encryptedEndpointUrl = SecurityController.Encrypt(documentDB.EndPointUrl);
                        //Save changes to Configuration.xml
                        SecurityController.UpdateConfiguration(encryptedEndpointUrl, encryptedAuthorizationKey);
                    }
                    IStorageService documentDBService = new DocumentDBDataController();
                    AlertController.SaveAlertData(documentDBService, documentDB.Name);
                    JobController.SaveJobData(documentDBService, documentDB.Name);
                    JobHistoryController.SaveJobHistoryData(documentDBService, documentDB.Name);
                    MediaServerController.SaveMediaServerData(documentDBService, documentDB.Name);
                    PurgeDataController.PurgeAlerts(documentDB.Name);
                    PurgeDataController.PurgeJobHistories(documentDB.Name);
                }
                LogUtility.LogInfoFunctionFinished();
            }
            catch (Exception e)
            {
                Exception baseException = e.GetBaseException();
                LogUtility.LogInfoFunction("Error:" + e.Message + "Message:" + baseException.Message);
                Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Delete the existing Media server records from MediaServerCollection.
        /// </summary>
        /// <param name="documentDBName"></param>
        /// <returns></returns>
        public async Task DeleteMediaServer(string documentDBName)
        {
            LogUtility.LogInfoFunction("Entered DeleteMediaServer.");

            List <string> list = GetEndpointUrlAndAuthorizationKey(documentDBName);

            EndpointUrl      = list[0];
            AuthorizationKey = list[1];

            using (client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey))
            {
                try
                {
                    Database db = client.CreateDatabaseQuery().
                                  Where(o => o.Id == databaseId).AsEnumerable().FirstOrDefault();
                    var coll = client.CreateDocumentCollectionQuery(db.CollectionsLink).Where(c => c.Id == mediaServerCollectionId).ToList().First();

                    var collectionLink = UriFactory.CreateDocumentCollectionUri(databaseId, mediaServerCollectionId);

                    var docs = client.CreateDocumentQuery(
                        collectionLink,
                        new SqlQuerySpec()
                    {
                        QueryText  = "SELECT * FROM MediaServerCollection c WHERE c.Name = @MediaServerName",
                        Parameters = new SqlParameterCollection()
                        {
                            new SqlParameter("@MediaServerName", MediaServerController.GetMediaSever())
                        }
                    });

                    LogUtility.LogInfoFunction("Deleting Existing Media Server.");
                    foreach (Document doc in docs)
                    {
                        await client.DeleteDocumentAsync(doc.SelfLink);
                    }
                    LogUtility.LogInfoFunctionFinished();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    LogUtility.LogExceptionFunction(e);
                }
            }
            LogUtility.LogInfoFunctionFinished();
        }
Beispiel #5
0
        ///<Summary>
        ///Fetches JobHistories based on the parameters passed.
        ///If no parameters are specified returns all the Job Histories.
        /// </Summary>
        ///<param name="name">
        ///The name of the JobHistory
        ///</param>
        ///<param name="jobStatus">
        ///Status of the job
        ///</param>
        ///<param name="jobType">
        ///Type of the Job
        ///</param>
        ///<param name="number">
        ///The number of Job Histories to be fetched
        ///</param>
        public static List <JobHistory> GetJobHistory(string name = "", string jobStatus = "", string jobType = "", int?number = null)
        {
            LogUtility.LogInfoFunction("Entered GetJobHistory.");
            //For Loading the powershell scripts ( Main.ps1 ) in memory.
            LogUtility.LogInfoFunction("Calling BemcliHelper function LoadPowerShellScript(); ");
            PowerShell powershell = BemcliHelper.LoadPowerShellScript();

            //Calling the powershell function GetJobHistory(Name,JobStatus,JobType,Number) which is present in BEMCLIScripts\JobHistory.psm1
            LogUtility.LogInfoFunction("Invoking PowerShell Command GetJobHistory");
            powershell.AddCommand("GetJobHistory");
            powershell.AddParameter("Name", name);
            powershell.AddParameter("JobStatus", jobStatus);
            powershell.AddParameter("JobType", jobType);
            powershell.AddParameter("Number", number);
            powershell.AddCommand("Out-String");
            var results = powershell.Invoke <string>();

            //check if the results string is empty
            if (String.IsNullOrWhiteSpace(results[0]))
            {
                //If the string is empty, there were no records found. Threfore return null.
                LogUtility.LogInfoFunction("Job History List is empty");
                LogUtility.LogInfoFunctionFinished();
                return(null);
            }

            //If records are found pass it to ConvertFromJson.
            string mediaServerName   = MediaServerController.GetMediaSever();
            var    jobHistoryObjects = ConvertFromJson(results[0]);

            foreach (JobHistory jobHistory in jobHistoryObjects)
            {
                jobHistory.MediaServerName = mediaServerName;
            }
            LogUtility.LogInfoFunctionFinished();
            return(jobHistoryObjects);
        }