Permalink
Browse files

Defer alerts module initialization until after import.

  • Loading branch information...
Logan Hanks
Logan Hanks committed Jan 5, 2012
1 parent e911a23 commit 44be4042f42bd8a2d19e0272f6f434515d788ee0
Showing with 21 additions and 8 deletions.
  1. +18 −8 alerts.py
  2. +1 −0 cassandra.py
  3. +1 −0 haproxy.py
  4. +1 −0 site_up.py
View
@@ -6,12 +6,22 @@
__all__ = ["harold", "config"]
-# load the configuration
-config = ConfigParser.RawConfigParser()
-config.read(['production.ini'])
-HAROLD_HOST = config.get('harold', 'host')
-HAROLD_PORT = config.getint('harold', 'port')
-HAROLD_SECRET = config.get('harold', 'secret')
+harold = None
+config = None
-# create the harold object
-harold = wessex.Harold(host=HAROLD_HOST, port=HAROLD_PORT, secret=HAROLD_SECRET)
+def load_config(path='production.ini'):
+ config = ConfigParser.RawConfigParser()
+ config.read([path])
+ return config
+
+def get_harold(config):
+ harold_host = config.get('harold', 'host')
+ harold_port = config.getint('harold', 'port')
+ harold_secret = config.get('harold', 'secret')
+ return wessex.Harold(
+ host=harold_host, port=harold_port, secret=harold_secret)
+
+def init(config_path='production.ini'):
+ global config, harold
+ config = load_config(path=config_path)
+ harold = get_harold(config)
View
@@ -68,6 +68,7 @@ def start_monitor(self):
time.sleep(INTERVAL)
if __name__ == "__main__":
+ alerts.init()
server = sys.argv[1]
monitor = CassandraMonitor(server)
monitor.start_monitor()
View
@@ -60,6 +60,7 @@ def main():
# threshold = 200
# interval = 30
# url.* = url
+ alerts.init()
haproxy_urls = [value for key, value in
alerts.config.items(CONFIG_SECTION)
if key.startswith("url")]
View
@@ -37,5 +37,6 @@ def monitor_site(url):
if __name__ == "__main__":
+ alerts.init()
url = sys.argv[1]
monitor_site(url)

0 comments on commit 44be404

Please sign in to comment.