From 905f4af92c726c899894b080507e580e19fe5ec0 Mon Sep 17 00:00:00 2001 From: aviau Date: Thu, 7 May 2015 16:38:42 -0400 Subject: [PATCH] surveil-init now works in prod Change-Id: I996360941222af0827ff2cb62ef7daf033336a3f --- Dockerfile | 1 + surveil/cmd/init.py | 135 ++++++++++++++++++++++++-------------------- 2 files changed, 74 insertions(+), 62 deletions(-) diff --git a/Dockerfile b/Dockerfile index 381b090..dd3116b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,4 +43,5 @@ ENV SURVEIL_KEYSTONE_ADMIN_TENANT_NAME=admin CMD cd /opt/surveil && \ ./setup.sh && \ + ((sleep 40 && surveil-init) &) && \ surveil-api diff --git a/surveil/cmd/init.py b/surveil/cmd/init.py index 65af17a..81c0ddf 100644 --- a/surveil/cmd/init.py +++ b/surveil/cmd/init.py @@ -35,78 +35,88 @@ def main(): # Create a basic config in mongodb mongo = pymongo.MongoClient(config.surveil_api_config['mongodb_uri']) - # Drop the current shinken config - mongo.drop_database('shinken') + if opts.demo is True: + # Drop the current shinken config + mongo.drop_database('shinken') - # Load the shinken packs - subprocess.call( - [ - "surveil-pack-upload", - "--mongo-url=mongo", - "--mongo-port=27017", - "/packs/linux-keystone/", - ] - ) + if mongo.surveil.init.count() == 0: + # Mark packs as uploaded + print("Uploading packs...") + mongo.surveil.init.insert({"source": "surveil-init script"}) - subprocess.call( - [ - "surveil-pack-upload", - "--mongo-url=mongo", - "--mongo-port=27017", - "/packs/linux-glance/", - ] - ) + # Load the shinken packs + subprocess.call( + [ + "surveil-pack-upload", + "--mongo-url=mongo", + "--mongo-port=27017", + "/packs/linux-keystone/", + ] + ) - subprocess.call( - [ - "surveil-pack-upload", - "--mongo-url=mongo", - "--mongo-port=27017", - "/packs/generic-host/", - ] - ) + subprocess.call( + [ + "surveil-pack-upload", + "--mongo-url=mongo", + "--mongo-port=27017", + "/packs/linux-glance/", + ] + ) + + subprocess.call( + [ + "surveil-pack-upload", + "--mongo-url=mongo", + "--mongo-port=27017", + "/packs/generic-host/", + ] + ) + else: + print("Skipping pack upload...") - # Reload the surveil config cli_surveil = sc.Client('http://localhost:8080/v2', auth_url='http://localhost:8080/v2/auth', version='2_0') - cli_surveil.config.hosts.create( - use="generic-host", - contact_groups="admins", - host_name="ws-arbiter", - address="localhost" - ) - cli_surveil.config.services.create( - check_command="check_tcp!7760", - check_interval="5", - check_period="24x7", - contact_groups="admins", - contacts="admin", - host_name="ws-arbiter", - max_check_attempts="5", - notification_interval="30", - notification_period="24x7", - retry_interval="3", - service_description="check-ws-arbiter" - ) - - cli_surveil.config.hosts.create( - host_name='test_keystone', - use='linux-keystone', - address='127.0.0.1', - custom_fields={ - "_OS_AUTH_URL": "bla", - "_OS_USERNAME": "bli", - "_OS_PASSWORD": "blo", - "_OS_TENANT": "blu", - "_KS_SERVICES": "bly", - "parents": "localhost" - } - ) - # if --demo is specified, you get more hosts. if opts.demo is True: + + # shinken's ws-arbiter + cli_surveil.config.hosts.create( + use="generic-host", + contact_groups="admins", + host_name="ws-arbiter", + address="localhost" + ) + cli_surveil.config.services.create( + check_command="check_tcp!7760", + check_interval="5", + check_period="24x7", + contact_groups="admins", + contacts="admin", + host_name="ws-arbiter", + max_check_attempts="5", + notification_interval="30", + notification_period="24x7", + retry_interval="3", + service_description="check-ws-arbiter" + ) + + # Linux-keystone template + cli_surveil.config.hosts.create( + host_name='test_keystone', + use='linux-keystone', + address='127.0.0.1', + custom_fields={ + "_OS_AUTH_URL": "bla", + "_OS_USERNAME": "bli", + "_OS_PASSWORD": "blo", + "_OS_TENANT": "blu", + "_KS_SERVICES": "bly", + "parents": "localhost" + } + ) + # DOWN HOST (cant resolve) cli_surveil.config.hosts.create( host_name='srv-apache-01', @@ -183,4 +193,5 @@ def main(): service_description="iamadownservice" ) + # Reload the shinken config cli_surveil.config.reload_config()