public static bool ValidateSettings(Settings settings, ChaosLogger logger)
        {
            var settingsValid = true;

            if (string.IsNullOrEmpty(settings.ServiceUrl) && !string.IsNullOrEmpty(settings.Ec2Endpoint))
            {
                settings.ServiceUrl = ServiceUrlFromEndPointName(settings.Ec2Endpoint);
                if (string.IsNullOrEmpty(settings.ServiceUrl))
                {
                    logger.Log("ERROR: Cannot find service url for endpoint '" + settings.Ec2Endpoint + "'");
                    settingsValid = false;
                }
            }

            if (string.IsNullOrEmpty(settings.ServiceUrl))
            {
                logger.Log("ERROR: No service URL found");
                settingsValid = false;
            }

            if (string.IsNullOrEmpty(settings.Tagkey))
            {
                logger.Log("ERROR: Tag key needed");
                settingsValid = false;
            }

            if (string.IsNullOrEmpty(settings.TagValue))
            {
                logger.Log("ERROR: Tag value needed");
                settingsValid = false;
            }

            return(settingsValid);
        }
示例#2
0
        public void WhenMonkeyListProviderGivesMultipleMonkeysAndUnleashMultipleTimes_UseThoseMonkeysAtleastOnce()
        {
            Settings    settings = new Settings();
            ChaosLogger logger   = new ChaosLogger("");

            var mockMonkey1 = new Mock <ParentMonkey>(settings, logger);
            var mockMonkey2 = new Mock <ParentMonkey>(settings, logger);
            var mockMonkey3 = new Mock <ParentMonkey>(settings, logger);

            var mockMonkeyListBuilder = new Mock <MonkeyListBuilder>();

            mockMonkeyListBuilder.Setup(builder => builder.GetMonkeys(settings, logger))
            .Returns(new List <ParentMonkey>()
            {
                mockMonkey1.Object,
                mockMonkey2.Object,
                mockMonkey3.Object
            });

            MonkeyKeeper keeper = new MonkeyKeeper(
                settings,
                logger,
                mockMonkeyListBuilder.Object);

            keeper.UnleashRandomMonkey();
            keeper.UnleashRandomMonkey();
            keeper.UnleashRandomMonkey();
            keeper.UnleashRandomMonkey();
            keeper.UnleashRandomMonkey();

            mockMonkey1.Verify(monkey => monkey.Unleash(), Times.AtLeastOnce);
            mockMonkey2.Verify(monkey => monkey.Unleash(), Times.AtLeastOnce);
            mockMonkey3.Verify(monkey => monkey.Unleash(), Times.AtLeastOnce);
        }
 public override IList <ParentMonkey> GetMonkeys(Settings settings, ChaosLogger logger)
 {
     logger.Log("Hard coded MonkyeListProvider returning EC2Monkey");
     return(new List <ParentMonkey>()
     {
         new EC2Monkey(settings, logger)
     });
 }
示例#4
0
        public static void UnleashChaos(Settings settings, ChaosLogger logger)
        {
            var ec2Factory = new Ec2Factory(settings.AwsAccessKey, settings.AwsSecretKey, settings.ServiceUrl, logger);
            var random     = new Random();

            if (settings.Repeat == 0)
            {
                settings.Repeat = 1;
            }

            if (settings.Repeat > 1)
            {
                logger.Log(string.Format("Repeating {0} times", settings.Repeat));
            }

            for (var t = 0; t < settings.Repeat; t++)
            {
                logger.Log(string.Format("Looking for instances in {0} with tag {1}={2}", settings.ServiceUrl, settings.Tagkey, settings.TagValue));

                List <Reservation> instances;
                try
                {
                    instances = ec2Factory.ListInstancesByTag(settings.Tagkey, settings.TagValue);
                }
                catch (Exception ex)
                {
                    logger.Log("ERROR: " + ex.Message);
                    return;
                }

                if (instances.Count == 0)
                {
                    logger.Log("No instances found");
                }
                else
                {
                    logger.Log(string.Format("Found {0} candidate instance(s) for chaos!", instances.Count));
                    var victimIndex = random.Next(0, instances.Count);
                    var instanceId  = instances[victimIndex].RunningInstance[0].InstanceId;
                    logger.Log(string.Format("Randomly chosen instance {0} ({1}) as the chaos victim.", instanceId, instances[victimIndex].RunningInstance[0].PublicDnsName));
                    logger.Log(string.Format("Terminating {0}...", instanceId));

                    ec2Factory.TerminateInstance(instanceId);
                    logger.Log(string.Format("{0} terminated", instanceId));
                }

                if (settings.Delay <= 0)
                {
                    continue;
                }

                logger.Log(string.Format("Waiting {0} ms", settings.Delay));
                System.Threading.Thread.Sleep(settings.Delay);
            }
        }
示例#5
0
 private static bool IsDisclaimerAcceptedViaDialog(ChaosLogger logger)
 {
     Console.WriteLine("WARNING!!! ChaosMonkey is going to break stuff. Press 'D' to indemnify the ChaosMonkey or its authors/contributors to your actions");
     var key = Console.ReadKey();
     Console.WriteLine();
     if (key.KeyChar != 'D')
     {
         return true;
     }
     return false;
 }
示例#6
0
        private static bool IsDisclaimerAcceptedViaDialog(ChaosLogger logger)
        {
            Console.WriteLine("WARNING!!! ChaosMonkey is going to break stuff. Press 'D' to indemnify the ChaosMonkey or its authors/contributors to your actions");
            var key = Console.ReadKey();

            Console.WriteLine();
            if (key.KeyChar != 'D')
            {
                return(true);
            }
            return(false);
        }
示例#7
0
        public static void UnleashChaos(Settings settings, ChaosLogger logger)
        {
            var ec2Factory = new Ec2Factory(settings.AwsAccessKey, settings.AwsSecretKey, settings.ServiceUrl, logger);
            var random = new Random();
            if (settings.Repeat == 0)
            {
                settings.Repeat = 1;
            }

            if (settings.Repeat > 1)
            {
                logger.Log(string.Format("Repeating {0} times", settings.Repeat));
            }

            for (var t = 0; t < settings.Repeat; t++)
            {
                logger.Log(string.Format("Looking for instances in {0} with tag {1}={2}", settings.ServiceUrl, settings.Tagkey, settings.TagValue));

                List<Reservation> instances;
                try
                {
                    instances = ec2Factory.ListInstancesByTag(settings.Tagkey, settings.TagValue);
                }
                catch (Exception ex)
                {
                    logger.Log("ERROR: " + ex.Message);
                    return;
                }

                if (instances.Count == 0)
                {
                    logger.Log("No instances found");
                }
                else
                {
                    logger.Log(string.Format("Found {0} candidate instance(s) for chaos!", instances.Count));
                    var victimIndex = random.Next(0, instances.Count);
                    var instanceId = instances[victimIndex].RunningInstance[0].InstanceId;
                    logger.Log(string.Format("Randomly chosen instance {0} ({1}) as the chaos victim.", instanceId, instances[victimIndex].RunningInstance[0].PublicDnsName));
                    logger.Log(string.Format("Terminating {0}...", instanceId));

                    ec2Factory.TerminateInstance(instanceId);
                    logger.Log(string.Format("{0} terminated", instanceId));
                }

                if (settings.Delay <= 0) continue;

                logger.Log(string.Format("Waiting {0} ms", settings.Delay));
                System.Threading.Thread.Sleep(settings.Delay);
            }
        }
示例#8
0
 public static void SaveSettings(string filename, Settings settings, ChaosLogger logger)
 {
     var serializer = new XmlSerializer(typeof(Settings));
     try
     {
         TextWriter writer = new StreamWriter(filename);
         serializer.Serialize(writer, settings);
         writer.Close();
     }
     catch (Exception ex)
     {
         logger.Log("ERROR: " + ex.Message);
         throw new Exception("Cannot save settings");
     }
 }
示例#9
0
 private static void LoadSettings(string loadSettingsFile, ChaosLogger logger)
 {
     if (!string.IsNullOrEmpty(loadSettingsFile))
     {
         try
         {
             Tasks.LoadSettings(loadSettingsFile, logger);
         }
         catch (Exception ex)
         {
             logger.Log("ERROR: " + ex.Message);
             return;
         }
     }
 }
示例#10
0
 private static void LoadSettings(string loadSettingsFile, ChaosLogger logger)
 {
     if (!string.IsNullOrEmpty(loadSettingsFile))
     {
         try
         {
             Tasks.LoadSettings(loadSettingsFile, logger);
         }
         catch (Exception ex)
         {
             logger.Log("ERROR: " + ex.Message);
             return;
         }
     }
 }
示例#11
0
        public static void SaveSettings(string filename, Settings settings, ChaosLogger logger)
        {
            var serializer = new XmlSerializer(typeof(Settings));

            try
            {
                TextWriter writer = new StreamWriter(filename);
                serializer.Serialize(writer, settings);
                writer.Close();
            }
            catch (Exception ex)
            {
                logger.Log("ERROR: " + ex.Message);
                throw new Exception("Cannot save settings");
            }
        }
示例#12
0
 public static Settings LoadSettings(string filename, ChaosLogger logger)
 {
     var serializer = new XmlSerializer(typeof(Settings));
     try
     {
         logger.Log(string.Format("Loading settings from file {0}", filename));
         var fileStream = new FileStream(filename, FileMode.Open);
         var settings = (Settings)serializer.Deserialize(fileStream);
         return settings;
     }
     catch (Exception ex)
     {
         logger.Log("ERROR: " + ex.Message);
         throw new Exception("Cannot load settings");
     }
 }
示例#13
0
        public static Settings LoadSettings(string filename, ChaosLogger logger)
        {
            var serializer = new XmlSerializer(typeof(Settings));

            try
            {
                logger.Log(string.Format("Loading settings from file {0}", filename));
                var fileStream = new FileStream(filename, FileMode.Open);
                var settings   = (Settings)serializer.Deserialize(fileStream);
                return(settings);
            }
            catch (Exception ex)
            {
                logger.Log("ERROR: " + ex.Message);
                throw new Exception("Cannot load settings");
            }
        }
示例#14
0
        static void Main(string[] args)
        {
            CommandLineParser   parser = new CommandLineParser(args);
            CommandLineSettings commandLineSettings = parser.GetCommandLineSettings();
            var logger = new ChaosLogger(commandLineSettings.Settings.LogFileName);

            try
            {
                LoadSettings(commandLineSettings.LoadSettingsFile, logger);

                if (IsDisclaimerAccepted(commandLineSettings.AcceptDisclaimer, logger))
                {
                }
                else
                {
                    logger.Log("Disclaimer not accepted, exiting");
                    return;
                }
                if (commandLineSettings.ApplicationMode.Equals("Pluggable"))
                {
                }
                else
                {
                    if (!CommandLineValidator.ValidateSettings(commandLineSettings.Settings, logger))
                    {
                        logger.Log("Invalid settings. use '-?' for help on parameters. Exiting.");
                        return;
                    }
                }


                Tasks.UnleashChaos(commandLineSettings.Settings, logger);
                SaveSettingsFile(commandLineSettings.SaveSettingsFile, commandLineSettings.Settings, logger);
            }
            finally
            {
                logger.Close();
                if (commandLineSettings.ShowHelp)
                {
                    parser.WriteOptionDescriptions(Console.Out);
                }
            }
        }
示例#15
0
        static void Main(string[] args)
        {
            CommandLineParser parser = new CommandLineParser(args);
            CommandLineSettings commandLineSettings= parser.GetCommandLineSettings();
            var logger = new ChaosLogger(commandLineSettings.Settings.LogFileName);
            try
            {
                LoadSettings(commandLineSettings.LoadSettingsFile, logger);

                if (IsDisclaimerAccepted(commandLineSettings.AcceptDisclaimer, logger))
                {

                }
                else
                {
                    logger.Log("Disclaimer not accepted, exiting");
                    return;
                }
                if (commandLineSettings.ApplicationMode.Equals("Pluggable"))
                {
                }
                else
                {
                    if (!CommandLineValidator.ValidateSettings(commandLineSettings.Settings, logger))
                    {
                        logger.Log("Invalid settings. use '-?' for help on parameters. Exiting.");
                        return;
                    }
                }

                Tasks.UnleashChaos(commandLineSettings.Settings, logger);
                SaveSettingsFile(commandLineSettings.SaveSettingsFile, commandLineSettings.Settings, logger);
            }
            finally
            {
                logger.Close();
                if (commandLineSettings.ShowHelp)
                {
                 parser.WriteOptionDescriptions(Console.Out);
                }
            }
        }
示例#16
0
 private static bool IsDisclaimerAccepted(bool acceptDisclaimer, ChaosLogger logger)
 {
     if (!acceptDisclaimer)
     {
         if (IsDisclaimerAcceptedViaDialog(logger))
         {
             logger.Log("Disclaimer accepted.");
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         logger.Log("Disclaimer accepted via startup parameters.");
         return(true);
     }
 }
示例#17
0
 private static bool IsDisclaimerAccepted(bool acceptDisclaimer, ChaosLogger logger)
 {
     if (!acceptDisclaimer)
     {
         if (IsDisclaimerAcceptedViaDialog(logger))
         {
             logger.Log("Disclaimer accepted.");
             return true;
         }
         else
         {
             return false;
         }
     }
     else
     {
         logger.Log("Disclaimer accepted via startup parameters.");
         return true;
     }
 }
示例#18
0
        public void WhenMonkeyListProviderGivenSingleMonkey_UseThatMonkey()
        {
            Settings    settings   = new Settings();
            ChaosLogger logger     = new ChaosLogger("");
            var         mock       = new Mock <MonkeyListBuilder>();
            var         mockMonkey = new Mock <ParentMonkey>(settings, logger);

            mock.Setup(builder => builder.GetMonkeys(settings, logger))
            .Returns(new List <ParentMonkey>()
            {
                mockMonkey.Object
            });
            MonkeyKeeper keeper = new MonkeyKeeper(
                settings,
                logger,
                mock.Object);

            keeper.UnleashRandomMonkey();
            mockMonkey.Verify(monkey => monkey.Unleash(), Times.Exactly(1));
        }
示例#19
0
        public static void UnleashChaos(Settings settings, ChaosLogger logger)
        {
            if (settings.Repeat == 0)
            {
                settings.Repeat = 1;
            }

            if (settings.Repeat > 1)
            {
                logger.Log(string.Format("Repeating {0} times", settings.Repeat));
            }
            MonkeyKeeper keeper = new MonkeyKeeper(settings, logger, new HardCodedMonkeyListBuilder());
            for (var times = 0; times < settings.Repeat; times++)
            {
                keeper.UnleashRandomMonkey();
                if (settings.Delay <= 0) return;
                logger.Log(string.Format("Waiting {0} ms", settings.Delay));
                System.Threading.Thread.Sleep(settings.Delay);
            }
        }
示例#20
0
        public void WhenMonkeyListProviderGivesEmptyList_ThrowException()
        {
            Settings    settings   = new Settings();
            ChaosLogger logger     = new ChaosLogger("");
            var         mock       = new Mock <MonkeyListBuilder>();
            var         mockMonkey = new Mock <ParentMonkey>();

            //mockMonkey.Verify(monkey => monkey.Unleash(),Times.Once);
            mock.Setup(builder => builder.GetMonkeys(settings, logger)).Returns(
                new List <ParentMonkey>()
            {
            }
                );
            MonkeyKeeper keeper = new MonkeyKeeper(
                settings,
                logger,
                mock.Object);

            keeper.UnleashRandomMonkey();
        }
示例#21
0
        public static void UnleashChaos(Settings settings, ChaosLogger logger)
        {
            if (settings.Repeat == 0)
            {
                settings.Repeat = 1;
            }

            if (settings.Repeat > 1)
            {
                logger.Log(string.Format("Repeating {0} times", settings.Repeat));
            }
            MonkeyKeeper keeper = new MonkeyKeeper(settings, logger, new HardCodedMonkeyListBuilder());

            for (var times = 0; times < settings.Repeat; times++)
            {
                keeper.UnleashRandomMonkey();
                if (settings.Delay <= 0)
                {
                    return;
                }
                logger.Log(string.Format("Waiting {0} ms", settings.Delay));
                System.Threading.Thread.Sleep(settings.Delay);
            }
        }
示例#22
0
 private static void SaveSettingsFile(string saveSettingsFile, Settings settings, ChaosLogger logger)
 {
     if (!string.IsNullOrEmpty(saveSettingsFile))
     {
         logger.Log(string.Format("Saving settings to {0}", saveSettingsFile));
         try
         {
             Tasks.SaveSettings(saveSettingsFile, settings, logger);
         }
         catch (Exception ex)
         {
             logger.Log("ERROR: " + ex.Message);
         }
     }
 }
示例#23
0
 public EC2Monkey(Settings settings, ChaosLogger logger) : base(settings, logger)
 {
 }
示例#24
0
 private static void SaveSettingsFile(string saveSettingsFile, Settings settings, ChaosLogger logger)
 {
     if (!string.IsNullOrEmpty(saveSettingsFile))
     {
         logger.Log(string.Format("Saving settings to {0}", saveSettingsFile));
         try
         {
             Tasks.SaveSettings(saveSettingsFile, settings, logger);
         }
         catch (Exception ex)
         {
             logger.Log("ERROR: " + ex.Message);
         }
     }
 }
示例#25
0
        static void Main(string[] args)
        {
            var settings = new Settings();
            var showHelp = false;
            var saveSettingsFile = string.Empty;
            var acceptDisclaimer = false;
            var loadSettingsFile = string.Empty;

            var options = new OptionSet()
                                    {
                                        {
                                            "a=|awsaccesskey=",
                                            "Access key of AWS IAM user that can list and terminate instances",
                                            x => settings.AwsAccessKey = x
                                            },
                                        {
                                            "d=|delay=",
                                            "Delay (milliseconds) before chaos is unleashed again (if repeat option set)",
                                            (int x) => settings.Delay = x
                                            },
                                        {
                                            "D|acceptdisclaimer",
                                            "Chaos Monkey is designed to break stuff, setting this option means that you acknowledge this",
                                            x => acceptDisclaimer = x != null
                                            },
                                        {
                                            "e=|endpoint=",
                                            "AWS endpoint name (US-East, US-West, EU, Asia-Pacific-Singapore, Asia-Pacific-Japan)",
                                            x => settings.Ec2Endpoint = x
                                            },
                                        {
                                            "h|?|help",
                                            "Show help (this screen)",
                                            x => showHelp = x != null
                                            },
                                        {
                                            "i=|loadsettings=", "Load settings xml file", x => loadSettingsFile = x
                                            },
                                        {
                                            "l=|log=", "Save log to file", x => settings.LogFileName = x
                                            },
                                        {
                                            "o=|savesettings=", "Save settings to xml file", x => saveSettingsFile = x
                                            },
                                        {
                                            "r=|repeat=",
                                            "Number of times chaos is unleashed (default 1)",
                                            (int x) => settings.Repeat = x
                                            },
                                        {
                                            "s=|awssecretkey=",
                                            "Access key of AWS IAM user that can list and terminate instances",
                                            x => settings.AwsSecretKey = x
                                            },
                                        {
                                            "S=|serviceurl=",
                                            "URL of EC2 service endpoint (use e|endpoint to use defaults)",
                                            x => settings.ServiceUrl = x
                                            },
                                        {
                                            "t=|tagkey=", "Key of Tag that will be search for in instances e.g. if EC2 tag is chaos=1, ChaosMonkey TagKey=chaos",
                                            x => settings.Tagkey = x
                                            },
                                        {
                                            "v=|tagvalue=", "Value of Tag that will be search for in instances e.g. if EC2 tag is chaos=1, ChaosMonkey TagValue=1",
                                            x => settings.TagValue = x
                                            }
                                    };

            options.Parse(args);

            var logger = new ChaosLogger(settings.LogFileName);
            try
            {
                if (!string.IsNullOrEmpty(loadSettingsFile))
                {
                    try
                    {
                        Tasks.LoadSettings(loadSettingsFile, logger);
                    }
                    catch (Exception ex)
                    {
                        logger.Log("ERROR: " + ex.Message);
                        return;
                    }
                }

                if (!acceptDisclaimer)
                {
                    Console.WriteLine("WARNING!!! ChaosMonkey is going to break stuff. Press 'D' to indemnify the ChaosMonkey or its authors/contributors to your actions");
                    var key = Console.ReadKey();
                    Console.WriteLine();
                    if (key.KeyChar != 'D')
                    {
                        logger.Log("Disclaimer not accepted, exiting");
                        return;
                    }

                    logger.Log("Disclaimer accepted.");
                }
                else
                {
                    logger.Log("Disclaimer accepted via startup parameters.");
                }

                if (!Tasks.ValidateSettings(settings, logger))
                {
                    logger.Log("Invalid settings. use '-?' for help on parameters. Exiting.");
                    return;
                }

                Tasks.UnleashChaos(settings, logger);

                if (!string.IsNullOrEmpty(saveSettingsFile))
                {
                    logger.Log(string.Format("Saving settings to {0}", saveSettingsFile));
                    try
                    {
                        Tasks.SaveSettings(saveSettingsFile, settings, logger);
                    }
                    catch (Exception ex)
                    {
                        logger.Log("ERROR: " + ex.Message);
                    }
                }
            }
            finally
            {
                logger.Close();
                if (showHelp)
                {
                    options.WriteOptionDescriptions(Console.Out);
                }
            }
        }
示例#26
0
        public static bool ValidateSettings(Settings settings, ChaosLogger logger)
        {
            var settingsValid = true;
            if (string.IsNullOrEmpty(settings.ServiceUrl) && !string.IsNullOrEmpty(settings.Ec2Endpoint))
            {
                settings.ServiceUrl = ServiceUrlFromEndPointName(settings.Ec2Endpoint);
                if (string.IsNullOrEmpty(settings.ServiceUrl))
                {
                    logger.Log("ERROR: Cannot find service url for endpoint '" + settings.Ec2Endpoint + "'");
                    settingsValid = false;
                }
            }

            if (string.IsNullOrEmpty(settings.ServiceUrl))
            {
                logger.Log("ERROR: No service URL found");
                settingsValid = false;
            }

            if (string.IsNullOrEmpty(settings.Tagkey))
            {
                logger.Log("ERROR: Tag key needed");
                settingsValid = false;
            }

            if (string.IsNullOrEmpty(settings.TagValue))
            {
                logger.Log("ERROR: Tag value needed");
                settingsValid = false;
            }

            return settingsValid;
        }
示例#27
0
 public ParentMonkey(Settings settings, ChaosLogger logger)
 {
     _logger   = logger;
     _settings = settings;
 }
示例#28
0
        static void Main(string[] args)
        {
            var settings         = new Settings();
            var showHelp         = false;
            var saveSettingsFile = string.Empty;
            var acceptDisclaimer = false;
            var loadSettingsFile = string.Empty;

            var options = new OptionSet()
            {
                {
                    "a=|awsaccesskey=",
                    "Access key of AWS IAM user that can list and terminate instances",
                    x => settings.AwsAccessKey = x
                },
                {
                    "d=|delay=",
                    "Delay (milliseconds) before chaos is unleashed again (if repeat option set)",
                    (int x) => settings.Delay = x
                },
                {
                    "D|acceptdisclaimer",
                    "Chaos Monkey is designed to break stuff, setting this option means that you acknowledge this",
                    x => acceptDisclaimer = x != null
                },
                {
                    "e=|endpoint=",
                    "AWS endpoint name (US-East, US-West, EU, Asia-Pacific-Singapore, Asia-Pacific-Japan)",
                    x => settings.Ec2Endpoint = x
                },
                {
                    "h|?|help",
                    "Show help (this screen)",
                    x => showHelp = x != null
                },
                {
                    "i=|loadsettings=", "Load settings xml file", x => loadSettingsFile = x
                },
                {
                    "l=|log=", "Save log to file", x => settings.LogFileName = x
                },
                {
                    "o=|savesettings=", "Save settings to xml file", x => saveSettingsFile = x
                },
                {
                    "r=|repeat=",
                    "Number of times chaos is unleashed (default 1)",
                    (int x) => settings.Repeat = x
                },
                {
                    "s=|awssecretkey=",
                    "Access key of AWS IAM user that can list and terminate instances",
                    x => settings.AwsSecretKey = x
                },
                {
                    "S=|serviceurl=",
                    "URL of EC2 service endpoint (use e|endpoint to use defaults)",
                    x => settings.ServiceUrl = x
                },
                {
                    "t=|tagkey=", "Key of Tag that will be search for in instances e.g. if EC2 tag is chaos=1, ChaosMonkey TagKey=chaos",
                    x => settings.Tagkey = x
                },
                {
                    "v=|tagvalue=", "Value of Tag that will be search for in instances e.g. if EC2 tag is chaos=1, ChaosMonkey TagValue=1",
                    x => settings.TagValue = x
                }
            };

            options.Parse(args);

            var logger = new ChaosLogger(settings.LogFileName);

            try
            {
                if (!string.IsNullOrEmpty(loadSettingsFile))
                {
                    try
                    {
                        Tasks.LoadSettings(loadSettingsFile, logger);
                    }
                    catch (Exception ex)
                    {
                        logger.Log("ERROR: " + ex.Message);
                        return;
                    }
                }

                if (!acceptDisclaimer)
                {
                    Console.WriteLine("WARNING!!! ChaosMonkey is going to break stuff. Press 'D' to indemnify the ChaosMonkey or its authors/contributors to your actions");
                    var key = Console.ReadKey();
                    Console.WriteLine();
                    if (key.KeyChar != 'D')
                    {
                        logger.Log("Disclaimer not accepted, exiting");
                        return;
                    }

                    logger.Log("Disclaimer accepted.");
                }
                else
                {
                    logger.Log("Disclaimer accepted via startup parameters.");
                }

                if (!Tasks.ValidateSettings(settings, logger))
                {
                    logger.Log("Invalid settings. use '-?' for help on parameters. Exiting.");
                    return;
                }

                Tasks.UnleashChaos(settings, logger);

                if (!string.IsNullOrEmpty(saveSettingsFile))
                {
                    logger.Log(string.Format("Saving settings to {0}", saveSettingsFile));
                    try
                    {
                        Tasks.SaveSettings(saveSettingsFile, settings, logger);
                    }
                    catch (Exception ex)
                    {
                        logger.Log("ERROR: " + ex.Message);
                    }
                }
            }
            finally
            {
                logger.Close();
                if (showHelp)
                {
                    options.WriteOptionDescriptions(Console.Out);
                }
            }
        }
示例#29
0
 public MonkeyKeeper(Settings setting, ChaosLogger logger, MonkeyListBuilder listBuilder)
 {
     _settings = setting;
     _logger   = logger;
     _builder  = listBuilder;
 }
示例#30
0
 public IISServerMonkey(Settings settings, ChaosLogger logger) : base(settings, logger)
 {
 }
示例#31
0
 /// <summary>
 /// Gives the list of Monkeys
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="logger"></param>
 /// <returns></returns>
 public abstract IList <ParentMonkey> GetMonkeys(Settings settings, ChaosLogger logger);