Example #1
0
 public async Task TestGenericHeaderless ()
 {
     var settings = InfluxerConfigSection.Load (Path.Combine (TestFilesPath, "HeaderlessText.conf"));
     settings.InputFileName = Path.Combine (TestFilesPath, "HeaderlessText.txt");
     var client = await GetClientAsync (settings);
     var file = new GenericFile ();
     var result = await file.ProcessGenericFile (settings.InputFileName, client);
     //Debug.WriteLine (result.ToString ());
     Assert.IsTrue (result.ExitCode == ExitCode.ProcessedWithErrors && result.PointsFound == 1001 && result.PointsFailed == 29, "Processing a generic text file failed");
 }
Example #2
0
 public async Task TestGenericSimple ()
 {
     var settings = InfluxerConfigSection.LoadDefault ();
     settings.FileFormat = FileFormats.Generic;
     settings.InputFileName = Path.Combine (TestFilesPath, "Simple.csv");
     settings.InfluxDB.RetentionPolicy = "autogen";
     settings.GenericFile.TimeFormat = "yyyy-MM-dd m:ss";
     var client = await GetClientAsync (settings);
     var file = new GenericFile ();
     var result = await file.ProcessGenericFile (settings.InputFileName, client);
     //Debug.WriteLine (result.ToString ());
     Assert.IsTrue (result.ExitCode == ExitCode.ProcessedWithErrors && result.PointsFound == 4897 && result.PointsFailed == 1, "Processing a generic CSV file failed");
 }
Example #3
0
        private static int Main(string[] args)
        {
            try
            {
                if (!CommandLineProcessor.ProcessArguments(args))
                {
                    return((int)ExitCode.Success);
                }
                settings = CommandLineProcessor.Settings;
            }
            catch (ArgumentException e)
            {
                Logger.LogLine(LogLevel.Error, e.Message);
                return((int)ExitCode.InvalidArgument);
            }
            catch (FileLoadException e)
            {
                Logger.LogLine(LogLevel.Error, e.Message);
                Logger.LogLine(LogLevel.Info, "Problem loading config file, regenerate it with /config option");
                return((int)ExitCode.InvalidFilename);
            }
            catch (Exception e)
            {
                Logger.LogLine(LogLevel.Error, "Error processing arguments {0}: {1}", e.GetType().Name, e.Message);
                return((int)ExitCode.InvalidArgument);
            }

            #region Validate inputs

            if (String.IsNullOrWhiteSpace(settings.InputFileName))
            {
                Logger.LogLine(LogLevel.Error, "Input File Name is not specified!! Can't continue");
                return((int)ExitCode.InvalidArgument);
            }

            try
            {
                settings.InputFileName = Path.GetFullPath(settings.InputFileName);
            }
            catch (Exception e)
            {
                Logger.LogLine(LogLevel.Error, "Error with input file:{0},{1}", e.GetType().Name, e.Message);
                Logger.LogLine(LogLevel.Info, "Problem with inputfile name, check path");
                return((int)ExitCode.InvalidFilename);
            }

            if (String.IsNullOrWhiteSpace(settings.InfluxDB.InfluxUri))
            {
                Logger.LogLine(LogLevel.Error, "Influx DB Uri is not configured!!");
                return((int)ExitCode.InvalidArgument);
            }

            if (String.IsNullOrWhiteSpace(settings.InfluxDB.DatabaseName))
            {
                Logger.LogLine(LogLevel.Error, "Influx DB name is not configured!!");
                return((int)ExitCode.InvalidArgument);
            }

            #endregion Validate inputs

            ProcessStatus result = new ProcessStatus()
            {
                ExitCode = ExitCode.UnknownError
            };
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                var client = new InfluxDBClient(settings.InfluxDB.InfluxUri, settings.InfluxDB.UserName, settings.InfluxDB.Password);

                if (!VerifyDatabaseAsync(client, settings.InfluxDB.DatabaseName).Result)
                {
                    Logger.LogLine(LogLevel.Info, "Unable to create DB {0}", settings.InfluxDB.DatabaseName);
                    return((int)ExitCode.UnableToProcess);
                }
                switch (settings.FileFormat)
                {
                case FileFormats.Perfmon:
                    result = new PerfmonFile().ProcessPerfMonLog(settings.InputFileName, client).Result;
                    break;

                case FileFormats.Generic:
                    if (String.IsNullOrWhiteSpace(settings.InfluxDB.Measurement))
                    {
                        throw new ArgumentException("Generic format needs TableName input");
                    }
                    result = new GenericFile().ProcessGenericFile(settings.InputFileName, client).Result;
                    break;
                }

                stopwatch.Stop();
                Logger.LogLine(LogLevel.Info, "\n Finished!! Processed {0} points (Success: {1}, Failed:{2}) in {3}", result.PointsFound, result.PointsProcessed, result.PointsFailed, stopwatch.Elapsed.ToString());
            }
            catch (AggregateException e)
            {
                Logger.LogLine(LogLevel.Error, "Error!! {0}:{1} - {2}", e.InnerException.GetType().Name, e.InnerException.Message, e.InnerException.StackTrace);
            }
            catch (Exception e)
            {
                Logger.LogLine(LogLevel.Error, "Error!! {0}:{1} - {2}", e.GetType().Name, e.Message, e.StackTrace);
            }
            return((int)result.ExitCode);
        }
Example #4
0
        static int Main (string[] args)
        {
            try
            {
                if (!CommandLineProcessor.ProcessArguments (args))
                    return (int) ExitCode.Success;
                settings = CommandLineProcessor.Settings;
            }
            catch (ArgumentException e)
            {
                Logger.LogLine (LogLevel.Error, e.Message);
                return (int) ExitCode.InvalidArgument;
            }
            catch (FileLoadException e)
            {
                Logger.LogLine (LogLevel.Error, e.Message);
                Logger.LogLine (LogLevel.Info, "Problem loading config file, regenerate it with /config option");
                return (int) ExitCode.InvalidFilename;
            }
            catch (Exception e)
            {
                Logger.LogLine (LogLevel.Error, "Error processing arguments {0}: {1}", e.GetType ().Name, e.Message);
                return (int) ExitCode.InvalidArgument;
            }

            #region Validate inputs
            
            if (String.IsNullOrWhiteSpace (settings.InputFileName))
            {
                Logger.LogLine (LogLevel.Error, "Input File Name is not specified!! Can't continue");
                return (int) ExitCode.InvalidArgument;
            }

            try
            {
                settings.InputFileName = Path.GetFullPath (settings.InputFileName);
            }
            catch (Exception e)
            {
                Logger.LogLine (LogLevel.Error, "Error with input file:{0},{1}", e.GetType ().Name, e.Message);
                Logger.LogLine (LogLevel.Info, "Problem with inputfile name, check path");
                return (int) ExitCode.InvalidFilename;
            }

            if (String.IsNullOrWhiteSpace (settings.InfluxDB.InfluxUri))
            {
                Logger.LogLine (LogLevel.Error, "Influx DB Uri is not configured!!");
                return (int) ExitCode.InvalidArgument;
            }

            if (String.IsNullOrWhiteSpace (settings.InfluxDB.DatabaseName))
            {
                Logger.LogLine (LogLevel.Error, "Influx DB name is not configured!!");
                return (int) ExitCode.InvalidArgument;
            }

            #endregion

            ProcessStatus result = new ProcessStatus () { ExitCode = ExitCode.UnknownError };
            try
            {
                Stopwatch stopwatch = new Stopwatch ();
                stopwatch.Start ();

                var client = new InfluxDBClient (settings.InfluxDB.InfluxUri, settings.InfluxDB.UserName, settings.InfluxDB.Password);

                if (!VerifyDatabaseAsync (client, settings.InfluxDB.DatabaseName).Result)
                {
                    Logger.LogLine (LogLevel.Info, "Unable to create DB {0}", settings.InfluxDB.DatabaseName);
                    return (int) ExitCode.UnableToProcess;
                }
                switch (settings.FileFormat)
                {
                    case FileFormats.Perfmon:
                        result = new PerfmonFile ().ProcessPerfMonLog (settings.InputFileName, client).Result;
                        break;
                    case FileFormats.Generic:
                        if (String.IsNullOrWhiteSpace (settings.InfluxDB.Measurement))
                            throw new ArgumentException ("Generic format needs TableName input");
                        result = new GenericFile ().ProcessGenericFile (settings.InputFileName, client).Result;
                        break;
                }

                stopwatch.Stop ();
                Logger.LogLine (LogLevel.Info, "\n Finished!! Processed {0} points (Success: {1}, Failed:{2}) in {3}", result.PointsFound, result.PointsProcessed, result.PointsFailed, stopwatch.Elapsed.ToString ());

            }

            catch (AggregateException e)
            {
                Logger.LogLine (LogLevel.Error, "Error!! {0}:{1} - {2}", e.InnerException.GetType ().Name, e.InnerException.Message, e.InnerException.StackTrace);
            }

            catch (Exception e)
            {
                Logger.LogLine (LogLevel.Error, "Error!! {0}:{1} - {2}", e.GetType ().Name, e.Message, e.StackTrace);
            }
            return (int) result.ExitCode;
        }