Merge "surveil-init: Added help text and more options"

This commit is contained in:
Jenkins 2015-06-22 16:30:32 +00:00 committed by Gerrit Code Review
commit 8a09fc1a37
4 changed files with 22 additions and 14 deletions

View File

@ -51,5 +51,5 @@ ENV SURVEIL_OS_TENANT_NAME=admin
CMD cd /opt/surveil && \ CMD cd /opt/surveil && \
./setup.sh && \ ./setup.sh && \
((sleep 40 && surveil-init) &) && \ ((sleep 40 && surveil-init --influxdb --packs --mongodb) &) && \
surveil-api surveil-api

View File

@ -40,9 +40,9 @@ Launch all surveil services with the following command: ::
systemctl start surveil-full.target systemctl start surveil-full.target
The surveil-init command will create a database in InfluxDB and initialize the MongoDB database: :: The surveil-init command will flush existing MongoDB Alignak config, create an InfluxDB database and upload configuration templates to Alignak: ::
surveil-init --influxdb surveil-init --mongodb --influxdb --packs
The surveil-webui-init command will pre-create data sources in Grafana: :: The surveil-webui-init command will pre-create data sources in Grafana: ::

View File

@ -10,7 +10,7 @@ surveil:
PBR_VERSION: "DEV" PBR_VERSION: "DEV"
volumes: volumes:
- ./surveil:/opt/surveil/surveil - ./surveil:/opt/surveil/surveil
command: bash -c "cd /opt/surveil && ./setup.sh && /opt/surveil/env/bin/python setup.py develop && ((sleep 40 && surveil-init --demo) &) && sleep 20 && surveil-api --reload" command: bash -c "cd /opt/surveil && ./setup.sh && /opt/surveil/env/bin/python setup.py develop && ((sleep 40 && surveil-init --influxdb --packs --mongodb --demo) &) && sleep 20 && surveil-api --reload"
# privileged: true # Fedora users might want to uncomment this if they face permission issues # privileged: true # Fedora users might want to uncomment this if they face permission issues
alignak: alignak:

View File

@ -30,21 +30,35 @@ def main():
parser.add_option('-d', '--demo', parser.add_option('-d', '--demo',
default=False, default=False,
dest='demo', dest='demo',
help="Create fake hosts in Alignak",
action="store_true") action="store_true")
parser.add_option('-i', '--influxdb', parser.add_option('-i', '--influxdb',
default=False, default=False,
dest='influxdb', dest='influxdb',
help="Pre-create the InfluxDB database",
action='store_true')
parser.add_option('-m', '--mongodb',
default=False,
dest='mongodb',
help="Drop the existing Alignak MongoDB database",
action='store_true')
parser.add_option('-p', '--packs',
default=False,
dest='packs',
help="Upload/Update configuration packs to MongoDB",
action='store_true') action='store_true')
opts, _ = parser.parse_args(sys.argv) opts, _ = parser.parse_args(sys.argv)
# Create a basic config in mongodb # Create a basic config in mongodb
mongo = pymongo.MongoClient(config.surveil_api_config['mongodb_uri']) mongo = pymongo.MongoClient(config.surveil_api_config['mongodb_uri'])
if opts.demo is True: if opts.mongodb is True:
# Drop the current shinken config # Drop the current shinken config
print("Dropping existing Alignak MongoDB database...")
mongo.drop_database('shinken') mongo.drop_database('shinken')
if opts.influxdb is True: if opts.influxdb is True:
print("Pre-creating InfluxDB database...")
# Create the InfluxDB database # Create the InfluxDB database
influx_client = influxdb.InfluxDBClient.from_DSN( influx_client = influxdb.InfluxDBClient.from_DSN(
config.surveil_api_config['influxdb_uri'] config.surveil_api_config['influxdb_uri']
@ -54,11 +68,8 @@ def main():
if not any(db['name'] == influx_client._database for db in databases): if not any(db['name'] == influx_client._database for db in databases):
influx_client.create_database(influx_client._database) influx_client.create_database(influx_client._database)
if mongo.surveil.init.count() == 0: if opts.packs:
# Mark packs as uploaded print ("Uploading packs...")
print("Uploading packs...")
mongo.surveil.init.insert({"source": "surveil-init script"})
# Load the shinken packs # Load the shinken packs
subprocess.call( subprocess.call(
[ [
@ -108,16 +119,13 @@ def main():
] ]
) )
else:
print("Skipping pack upload...")
cli_surveil = sc.Client('http://localhost:8080/v2', cli_surveil = sc.Client('http://localhost:8080/v2',
auth_url='http://localhost:8080/v2/auth', auth_url='http://localhost:8080/v2/auth',
version='2_0') version='2_0')
# if --demo is specified, you get more hosts. # if --demo is specified, you get more hosts.
if opts.demo is True: if opts.demo is True:
print("Creating demo configuration...")
# shinken's ws-arbiter # shinken's ws-arbiter
cli_surveil.config.hosts.create( cli_surveil.config.hosts.create(
use="generic-host", use="generic-host",