Example #1
0
def main():
    # Parse the arguments
    parser = argparse.ArgumentParser(
        prog='surveil-pack-upload',
        add_help=False,
    )
    parser.add_argument('--surveil_api_url',
                        default='http://localhost:5311/v2',
                        type=str)
    parser.add_argument('--surveil_auth_url',
                        default='http://localhost:5311/v2/auth',
                        type=str)
    parser.add_argument('--surveil_api_version', default='2_0', type=str)
    parser.add_argument('pack',
                        metavar='[Pack]',
                        type=str,
                        nargs=1,
                        help='Pack directory')

    (options, args) = parser.parse_known_args(sys.argv[1:])

    cli_surveil = sc.Client(options.surveil_api_url,
                            auth_url=options.surveil_auth_url,
                            version=options.surveil_api_version)

    upload_pack(options.pack[0], cli_surveil)
Example #2
0
def main():
    # Create a basic config in mongodb
    mongo = config.app_hooks[0].mongo_connection

    # Drop the current shinken config
    mongo.drop_database('shinken')

    mongo_shinken = mongo.shinken
    mongo_hosts = mongo_shinken.hosts
    mongo_services = mongo_shinken.services

    # 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/linux-glance/",
    ])

    subprocess.call([
        "surveil-pack-upload",
        "--mongo-url=mongo",
        "--mongo-port=27017",
        "/packs/generic-host/",
    ])

    mongo_hosts.insert({
        "use": "generic-host",
        "contact_groups": "admins",
        "host_name": "ws-arbiter",
        "address": "localhost"
    })

    mongo_services.insert({
        "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"
    })

    # Reload the surveil config
    cli_surveil = sc.Client('http://localhost:8080/v1')
    cli_surveil.reload_config()
Example #3
0
 def reload_config_threads():
     c = client.Client(daemon_config["SURVEIL_API_URL"],
                       auth_url=daemon_config["SURVEIL_AUTH_URL"],
                       version=daemon_config["SURVEIL_VERSION"])
     while True:
         time.sleep(30)
         if compt_thread:
             c.config.reload_config()
             del (compt_thread[:])
Example #4
0
def main(args=None):

    cfg = parse_args(args)

    # Make the inventory of the OpenStack install
    keystone = kc.Client(
        username=cfg.os_username,
        tenant_name=cfg.os_tenant_name,
        password=cfg.os_password,
        auth_url=cfg.os_auth_url,
    )

    endpoints = keystone.service_catalog.get_endpoints()

    cli_surveil = sc.Client(cfg.api_url, version='1_0')

    for ep in endpoints.get('identity', []):

        cli_surveil.hosts.create(
            host_name='OS_keystone_host_%s' % ep['id'],
            use='linux-keystone',
            address=urlparse.urlparse(ep['publicURL']).hostname,
            custom_fields={
                '_OS_AUTH_URL': ep['publicURL'],
                '_OS_USERNAME': cfg.os_username,
                '_OS_PASSWORD': cfg.os_password,
                '_OS_TENANT_NAME': cfg.os_tenant_name,
                '_KS_SERVICES': 'identity',
            }
        )

    for ep in endpoints.get('image', []):
        cli_surveil.hosts.create(
            host_name='OS_glance_host_%s' % ep['id'],
            use='linux-glance',
            address=urlparse.urlparse(ep['publicURL']).hostname,
            custom_fields={
                '_OS_AUTH_URL': ep['publicURL'],
                '_OS_USERNAME': cfg.os_username,
                '_OS_PASSWORD': cfg.os_password,
                '_OS_TENANT_NAME': cfg.os_tenant_name,
                '_OS_GLANCE_URL': ep['publicURL'] + '/v1',
            }
        )

    # Reload the surveil config
    cli_surveil.reload_config()
Example #5
0
    def setUpClass(self):
        surveil_dir = os.path.realpath(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         "../../../../"))

        compose_file = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'integration.yml')

        project_config = compose_config.from_dictionary(
            compose_config.load_yaml(compose_file),
            working_dir=surveil_dir,
            filename=compose_file)

        self.project = compose_project.Project.from_dicts(
            "surveilintegrationtest", project_config,
            docker_client.docker_client())

        self.project.kill()
        self.project.remove_stopped()
        self.project.build()
        self.project.up()

        self.surveil_client = sclient.Client(
            'http://localhost:8999/v2',
            auth_url='http://localhost:8999/v2/auth',
            version='2_0')

        #  Wait until Surveil is available
        now = time.time()
        while True:
            print("Waiting for surveil... %s" % int(time.time() - now))
            if time.time() < (now + 380):
                try:
                    #  If 'ws-arbiter' is found, Surveil is ready!
                    configured_hosts = self.surveil_client.status.hosts.list()
                    host_found = False
                    for host in configured_hosts:
                        if host['host_name'].decode() == 'ws-arbiter':
                            host_found = True
                            break
                    if host_found:
                        break
                except Exception:
                    pass
                time.sleep(10)
            else:
                raise Exception("Surveil could not start")
Example #6
0
    def process_event(body):
        sclient = client.Client(daemon_config["SURVEIL_API_URL"],
                                auth_url=daemon_config["SURVEIL_AUTH_URL"],
                                version=daemon_config["SURVEIL_VERSION"])

        #  Load the event
        event = json.loads(body)

        #  Process the event
        try:
            if event['event_type'] == 'compute.instance.create.start':
                process_instance_create_start(event, sclient)
            elif event['event_type'] == 'compute.instance.create.end':
                process_instance_create_end(event, sclient)
            elif event['event_type'] == 'compute.instance.delete.end':
                process_instance_delete_end(sclient, event)
        except Exception as e:
            print("Could not process event %s" % e, file=sys.stderr)
Example #7
0
def main():
    parser = optparse.OptionParser()
    parser.add_option('-d',
                      '--demo',
                      default=False,
                      dest='demo',
                      help="Create fake hosts in Alignak",
                      action="store_true")
    parser.add_option('-i',
                      '--influxdb',
                      default=False,
                      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')
    opts, _ = parser.parse_args(sys.argv)

    # Create a basic config in mongodb
    mongo = pymongo.MongoClient(config.surveil_api_config['mongodb_uri'])

    if opts.mongodb is True:
        # Drop the current shinken config
        print("Dropping existing Alignak MongoDB database...")
        mongo.drop_database('shinken')

    if opts.influxdb is True:
        print("Pre-creating InfluxDB database...")
        # Create the InfluxDB database
        influx_client = influxdb.InfluxDBClient.from_DSN(
            config.surveil_api_config['influxdb_uri'])

        databases = influx_client.get_list_database()
        if not any(db['name'] == influx_client._database for db in databases):
            influx_client.create_database(influx_client._database)

    if opts.packs:
        print("Uploading packs...")
        # Load the shinken packs
        subprocess.call([
            "surveil-pack-upload",
            "--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
            "/usr/share/monitoring/packs/sfl/openstack-keystone-http/",
        ])

        subprocess.call([
            "surveil-pack-upload",
            "--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
            "/usr/share/monitoring/packs/sfl/openstack-glance-http/",
        ])

        subprocess.call([
            "surveil-pack-upload",
            "--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
            "/usr/share/monitoring/packs/sfl/generic-host/",
        ])

        subprocess.call([
            "surveil-pack-upload",
            "--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
            "/usr/share/monitoring/packs/sfl/linux-system-nrpe/",
        ])

        subprocess.call([
            "surveil-pack-upload",
            "--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
            "/usr/share/monitoring/packs/sfl/openstack-nova-http/",
        ])

        subprocess.call([
            "surveil-pack-upload",
            "--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
            "/usr/share/monitoring/packs/sfl/openstack-cinder-http/",
        ])

        subprocess.call([
            "surveil-pack-upload",
            "--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
            "/usr/share/monitoring/packs/sfl/openstack-host/",
        ])

    cli_surveil = sc.Client('http://localhost:8080/v2',
                            auth_url='http://localhost:8080/v2/auth',
                            version='2_0')

    # if --demo is specified, you get more hosts.
    if opts.demo is True:
        print("Creating demo configuration...")
        # 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='openstack-keystone-http',
                                        address='127.0.0.1',
                                        custom_fields={
                                            "_OS_AUTH_URL": "bla",
                                            "_OS_USERNAME": "******",
                                            "_OS_PASSWORD": "******",
                                            "_OS_TENANT": "blu",
                                            "_KS_SERVICES": "bly",
                                            "parents": "localhost"
                                        })

        # openstack-host template
        cli_surveil.config.hosts.create(host_name='openstackceilometer-host',
                                        use='openstack-host',
                                        address='127.0.0.1',
                                        custom_fields={
                                            "_OS_AUTH_URL": "bla",
                                            "_OS_USERNAME": "******",
                                            "_OS_PASSWORD": "******",
                                            "_OS_TENANT_NAME": "blu",
                                            "_KS_SERVICES": "bly",
                                            "parents": "localhost"
                                        })

        # DOWN HOST (cant resolve)
        cli_surveil.config.hosts.create(host_name='srv-apache-01',
                                        use='linux-system-nrpe',
                                        address='srv-apache-01',
                                        custom_fields={
                                            "_TRAFFICLIMIT": "100000",
                                        })

        # DOWN, and parent down (Network outage)
        cli_surveil.config.hosts.create(
            host_name='myparentisdown',
            address='dfgsdgsdgf',
            parents='srv-apache-01',
        )

        # UP host, no template
        cli_surveil.config.hosts.create(host_name='google.com',
                                        address='google.com')

        # NRPE host, UP
        cli_surveil.config.hosts.create(host_name='srv-monitoring-01',
                                        use='linux-system-nrpe',
                                        address='127.0.0.1',
                                        custom_fields={
                                            "_TRAFFICLIMIT": "500000",
                                        })

        # Has parent, UP
        cli_surveil.config.hosts.create(host_name='sw-iwebcore-01',
                                        parents='srv-monitoring-01',
                                        use='generic-host',
                                        address='127.0.0.1',
                                        custom_fields={
                                            "_TRAFFICLIMIT": "200000",
                                        })

        # Has chain of 2 parents, UP
        cli_surveil.config.hosts.create(host_name='srv-ldap-01',
                                        parents='sw-iwebcore-01',
                                        use='generic-host',
                                        address='127.0.0.1',
                                        custom_fields={
                                            "_TRAFFICLIMIT": "5000000",
                                        })

        # UP host with down service
        cli_surveil.config.hosts.create(use="generic-host",
                                        contact_groups="admins",
                                        host_name="myserviceisdown",
                                        address="localhost")
        cli_surveil.config.services.create(
            check_command="check_tcp!4553",
            check_interval="5",
            check_period="24x7",
            contact_groups="admins",
            contacts="admin",
            host_name="myserviceisdown",
            max_check_attempts="5",
            notification_interval="30",
            notification_period="24x7",
            retry_interval="3",
            service_description="iamadownservice")

    # Reload the shinken config
    cli_surveil.config.reload_config()
Example #8
0
def main():
    parser = optparse.OptionParser()
    parser.add_option('-d',
                      '--demo',
                      default=False,
                      dest='demo',
                      help="Create fake hosts in Alignak",
                      action="store_true")
    parser.add_option('-i',
                      '--influxdb',
                      default=False,
                      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')
    parser.add_option('--pecan_config',
                      '-P',
                      default='/etc/surveil/config.py',
                      dest='pecan_config',
                      help='Pecan config file (config.py)')
    parser.add_option('--config_file',
                      '-c',
                      default='/etc/surveil/surveil.cfg',
                      dest='config_file',
                      help='Pecan config file (surveil.cfg)')

    opts, _ = parser.parse_args(sys.argv)

    surveil_api_url = 'http://*****:*****@gmail.com",
            pager="12",
            can_submit_commands=1,
            is_admin=0,
            retain_status_information=1,
            retain_nonstatus_information=365,
            min_business_impact=24)

        cli_surveil.config.contactgroups.create(
            contactgroup_name="BDFL",
            members=["demoContact"],
            alias="group Alias",
            contactgroup_members=["Linus", "Richard"])

        cli_surveil.config.hostgroups.create(
            hostgroup_name="OpenStack01",
            members=['sw-iwebcore-01', 'srv-monitoring-01'],
            alias="group Alias",
            hostgroup_members=["AWS01", "Azure01"],
            notes="notes",
            notes_url="http://....notes.com",
            action_url="mail")

        cli_surveil.config.macromodulations.create(
            macromodulation_name="Demo macroModulation",
            modulation_period="24x7",
            macro={
                "Linus": "Linux",
                "Richard": "Gnu"
            })

        cli_surveil.config.notificationways.create(
            notificationway_name="Demo motificationway",
            host_notification_period="24x7",
            service_notification_period="12x7",
            host_notification_options=["mail", "sms"],
            service_notification_options=["mail"],
            host_notification_commands=["sms admin"],
            service_notification_commands=["send mail to admin"],
            min_business_impact="24")

        cli_surveil.config.realms.create(
            realm_name="Mordor",
            realm_members=["Frodon", "Gandalf", "Sauron"],
            default=42)

        cli_surveil.config.servicegroups.create(
            servicegroup_name="check Openstack",
            members=["check-ws-arbiter"],
            alias="group Alias",
            servicegroup_members=["check Keystone", "check Nova"],
            notes="notes",
            notes_url="http://....notes.com",
            action_url="mail")

        cli_surveil.config.timeperiods.create(
            timeperiod_name="Demo TimePeriod",
            exclude=["24x7", "11x12"],
            periods={
                "day": "demo",
                "night": "demoNight"
            },
            alias="aliasGroup")
    # Reload the shinken config
    cli_surveil.config.reload_config()