chaosmonkey.engine package

Submodules

chaosmonkey.engine.app module

ChaosMonkey Engine

chaosmonkey.engine.app.configure_engine(database_uri, attacks_folder, planners_folder, cme_timezone)[source]

Create a Flask App and all the configuration needed to run the CMEEngine

  • Init and configure the SQLAlchemy store (create db and tables if don’t exists)
  • Init ModuleStores (attacks and planners)
  • Configure the timezone and jobstore for the scheduler
  • Configure the CMEManager
TODO:
The scheduler start is not made until the first request is made. This is due to the way the SQLAlchemy store is created, because it needs the app.context to work properly
Parameters:
  • database_uri – SQLAlchemy SQLALCHEMY_DATABASE_URI
  • attacks_folder – folder to load the attacks modules
  • planners_folder – folder to load the planners modules
  • cme_timezone – timezone to set in the scheduler
chaosmonkey.engine.app.make_sure_path_exists(path)[source]

Make sure a path exists and create it if don’t

Parameters:path – string path to check
chaosmonkey.engine.app.shutdown_engine()[source]

Shutdown the scheduler

chaosmonkey.engine.app.start_scheduler()[source]

chaosmonkey.engine.cme_manager module

CME Manager

Control layer for CME Engine

class chaosmonkey.engine.cme_manager.CMEManager[source]

Bases: object

CMEManager is the manager responsible of communicating the API with the backend.

It manages:

  • scheduler: BackgroundScheduler from appscheduler lib. The scheduler run executors
  • sql_store: SQLAlchemy store. The persistence layer
  • planners_store: ModuleStore that load and manages available planners.
  • attacks_store: ModuleStore that load and manage available attacks.

Methods to interact with Executors and Plans always returns the db.Models (chaosmonkey.dal.*_model)

Methods that interact with Attacks always returns Attacks objects (chaosmonkey.attacks.attack)

Methods that interact with Planners always returns Planners objects (chaosmonkey.planners.planner)

add_executor(date, name, attack_config, plan_id)[source]

Adds a new executor to the scheduler

Parameters:
  • date – Datetime to execute the job
  • name – Executor name
  • attack_config – Attack config. Dict to be passed to the executor on execution time
  • plan_id – Referenced plan id
Returns:

chaosmonkey.dal.executor.Executor

add_plan(name)[source]

Creates a new plan in the sqlStore

Parameters:name – Plan name
Returns:chaosmonkey.dal.plan.Plan
attacks_store

Attacks store property

configure(scheduler, sql_store, planners_store, attacks_store)[source]

Configure the manager

Parameters:
  • scheduler – apscheduler.schedulers.background.BackgroundScheduler
  • sql_store – SQLAlchemy
  • planners_store – chaosmonkey.modules.ModuleStore
  • attacks_store – chaosmonkey.modules.ModuleStore
Returns:

delete_plan(plan_id)[source]

Delete a plan (and all his associated executors) from the sqlStore

Parameters:plan_id – String plan Id
Returns:
execute_plan(name, planner_config, attack_config)[source]

Execute a plan with a planner and executor config to create executors based on the configs

It also validates the planner and executor config against the modules

Parameters:
  • name – Plan name
  • planner_config – Dict with planner config
  • attack_config – Dict with attack config
get_attack_list()[source]

Return a list with all attacks loaded in the self._attacks_store

Returns:chaosmonkey.attacks.attack.Attack list
get_executor(executor_id)[source]

Return an Executor object with the given id :return: chaosmonkey.dal.executor.Executor

get_executors(executed=False)[source]

Return a list of Executor objects created in DB :return: chaosmonkey.dal.executor.Executor list

get_executors_for_plan(plan_id)[source]

Return a list of Executors for a given plan id :return: chaosmonkey.dal.executor.Executor

get_plan(plan_id)[source]

Returns a plans

Returns:chaosmonkey.dal.plan.Plan
get_planner_list()[source]

Return a list with all planners loaded in the self._planners_store

Returns:chaosmonkey.planners.planner.Planner list
get_plans(show_all=None)[source]

Returns a list with al plans in the sqlStore

Returns:List of chaosmonkey.dal.plan.Plan
planners_store

Planners store property

remove_executor(executor_id)[source]

Removes an executor by his ID :param executor_id: :return:

scheduler

Scheduler property

sql_store

SQLstore property

update_executor_trigger(executor_id, trigger)[source]

Update an executor trigger to change is due date

Parameters:
  • executor_id – executor id
  • trigger – apscheduler.triggers.BaseTrigger instance
Returns:

chaosmonkey.dal.executor.Executor

chaosmonkey.engine.scheduler module

apscheduler.schedulers.background.BackgroundScheduler() used by the CME.

The scheduler is responsible of storing executors and execute them in the given datatime.

Module contents

This package contains the pieces to run the Engine

  • Engine configuration (FlaskApp, Store, Modules...)
  • CMEManager, used to communicate the Engine with the API and the Store
  • Scheduler to schedule executors for later use