static void Main(string[] args)
        {
            DateTime lastRunTime = DateTime.Now;

            if (File.Exists("LastRun.txt"))
            {
                lastRunTime = Convert.ToDateTime(File.ReadAllText("LastRun.txt"));
            }

            //Output all console logs to log file
            FileStream filestream   = new FileStream("log.txt", FileMode.Create);
            var        streamwriter = new StreamWriter(filestream);

            streamwriter.AutoFlush = true;
            Console.SetOut(streamwriter);
            Console.SetError(streamwriter);

            Console.WriteLine("Starting Connector Health Utility... \n");
            Console.WriteLine("Application Version: " + Version);
            Console.WriteLine("Current System Time: " + DateTime.Now + Environment.NewLine);

            Console.WriteLine("Checking last run time and backing up files if needed...");

            if (lastRunTime < DateTime.Today)
            {
                var    files  = Directory.GetFiles(@".\Output\", "*.csv");
                string prefix = lastRunTime.Month.ToString() + "_" + lastRunTime.Day.ToString() + "_" + lastRunTime.Year.ToString() + "_";
                foreach (var file in files)
                {
                    string newFileName = Path.Combine(Path.GetDirectoryName(file) + "\\Archived\\", (prefix + Path.GetFileName(file)));
                    File.Move(file, newFileName);
                }
            }

            Console.WriteLine("Connecting to Centrify API...");

            //Authenticate to Centrify with no MFA service account
            RestClient authenticatedRestClient = InteractiveLogin.Authenticate(ConfigurationManager.AppSettings["CentrifyEndpointUrl"], ConfigurationManager.AppSettings["AdminUserName"], ConfigurationManager.AppSettings["AdminPassword"]);
            ApiClient  apiClient = new ApiClient(authenticatedRestClient);

            Console.WriteLine("Getting list of Centrify Cloud Connectors");

            //Get list of Cloud Connectors for tenant
            Newtonsoft.Json.Linq.JObject connectorList = apiClient.Query("select MachineName, ID from proxy");

            //Check health of each connector in tenant and write health status to CSV
            foreach (var connector in connectorList["Results"])
            {
                Dictionary <string, dynamic> dicConnector = connector["Row"].ToObject <Dictionary <string, dynamic> >();
                Console.WriteLine("Checking health of cloud connector. Name: {0}, ID: {1}", dicConnector["MachineName"], dicConnector["ID"]);

                Newtonsoft.Json.Linq.JArray results = apiClient.CheckProxyHealth(dicConnector["ID"]);

                Dictionary <string, dynamic> dicConnResults = results[0].ToObject <Dictionary <string, dynamic> >();

                ProcessQueryResults(dicConnector["MachineName"].ToString(), dicConnResults);
            }

            //Log last run time at every successful run.
            try
            {
                System.IO.File.WriteAllText(@".\LastRun.txt", DateTime.Now.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine("There Was An Error When Writing LastRun.txt");
                Console.WriteLine(ex.InnerException);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            DateTime lastRunTime = DateTime.Now;

            if (File.Exists("LastRun.txt"))
            {
                lastRunTime = Convert.ToDateTime(File.ReadAllText("LastRun.txt"));
            }

            //Output all console logs to log file
            FileStream filestream   = new FileStream("log.txt", FileMode.Create);
            var        streamwriter = new StreamWriter(filestream);

            streamwriter.AutoFlush = true;
            Console.SetOut(streamwriter);
            Console.SetError(streamwriter);

            Console.WriteLine("Starting SIEM Utility... \n");
            Console.WriteLine("Application Version: " + Version);
            Console.WriteLine("Current System Time: " + DateTime.Now + Environment.NewLine);

            Console.WriteLine("Checking last run time and backing up files if needed...");

            if (lastRunTime < DateTime.Today)
            {
                var    files  = Directory.GetFiles(@".\Output\", "*.csv");
                string prefix = lastRunTime.Month.ToString() + "_" + lastRunTime.Day.ToString() + "_" + lastRunTime.Year.ToString() + "_";
                foreach (var file in files)
                {
                    string newFileName = Path.Combine(Path.GetDirectoryName(file), (prefix + Path.GetFileName(file)));
                    File.Move(file, newFileName);
                }
            }

            Console.WriteLine("Connecting to Centrify API...");

            //Authenticate to Centrify with no MFA service account
            RestClient authenticatedRestClient = InteractiveLogin.Authenticate(ConfigurationManager.AppSettings["CentrifyEndpointUrl"], ConfigurationManager.AppSettings["AdminUserName"], ConfigurationManager.AppSettings["AdminPassword"]);
            ApiClient  apiClient = new ApiClient(authenticatedRestClient);

            Console.WriteLine("Getting list of queries...");

            //Read queries from query file
            JavaScriptSerializer         m_jsSerializer = new JavaScriptSerializer();
            StreamReader                 jsonReader     = new StreamReader("Queries.json");
            Dictionary <string, dynamic> queries_Dict   = m_jsSerializer.Deserialize <Dictionary <string, dynamic> >(jsonReader.ReadToEnd());

            //Exicute queries in Queries file and export the results to ; delimeted CSV
            foreach (var query in queries_Dict["queries"])
            {
                Console.WriteLine("Exicuting Query {0}... \n", query["caption"]);
                ProcessQueryResults(query["caption"], apiClient.Query(query["query"]));
            }

            //Log last run time at every successful run.
            try
            {
                System.IO.File.WriteAllText(@".\LastRun.txt", DateTime.Now.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine("There Was An Error When Writing LastRun.txt");
                Console.WriteLine(ex.InnerException);
            }
        }