Exemple #1
0
    def dbs(self, **params):
        logging.debug(params)
        messages = []
        data = []
        preset_configs = []
        metrics_list = []
        influx_active_dbnames = []
        preset_configs_json = {}

        if params:
            try:
                if params.get('save'):
                    pgwatch2.update_monitored_db(params)
                    messages.append('Updated!')
                elif params.get('new'):
                    messages.append(pgwatch2.insert_monitored_db(params))
                elif params.get('delete'):
                    pgwatch2.delete_monitored_db(params)
                    messages.append('Entry with ID {} ("{}") deleted!'.format(
                        params['md_id'], params['md_unique_name']))
                elif params.get('influx_delete_single'):
                    if not params['influx_single_unique_name']:
                        raise Exception('No "Unique Name" provided!')
                    pgwatch2_influx.delete_influx_data_single(params['influx_single_unique_name'])
                    messages.append('InfluxDB data for "{}" deleted!'.format(params['influx_single_unique_name']))
                elif params.get('influx_delete_all'):
                    active_dbs = pgwatch2.get_active_db_uniques()
                    deleted_dbnames = pgwatch2_influx.delete_influx_data_all(active_dbs)
                    messages.append('InfluxDB data deleted for: {}'.format(','.join(deleted_dbnames)))
            except Exception as e:
                messages.append('ERROR: ' + str(e))

        try:
            influx_active_dbnames = pgwatch2_influx.get_active_dbnames()
        except requests.exceptions.ConnectionError:
            messages.append('ERROR: Could not connect to InfluxDB')
        except Exception as e:
            messages.append('ERROR: ' + str(e))

        try:
            data = pgwatch2.get_all_monitored_dbs()
            preset_configs = pgwatch2.get_preset_configs()
            preset_configs_json = json.dumps(
                {c['pc_name']: c['pc_config'] for c in preset_configs})
            metrics_list = pgwatch2.get_active_metrics_with_versions()
        except psycopg2.OperationalError:
            messages.append('ERROR: Could not connect to Postgres')
        except Exception as e:
            messages.append('ERROR: ' + str(e))

        tmpl = env.get_template('dbs.html')
        return tmpl.render(messages=messages, data=data, preset_configs=preset_configs, preset_configs_json=preset_configs_json,
                           metrics_list=metrics_list, influx_active_dbnames=influx_active_dbnames,
                           no_anonymous_access=cmd_args.no_anonymous_access, session=cherrypy.session,
                           no_component_logs=cmd_args.no_component_logs)
Exemple #2
0
    def dbs(self, **params):
        logging.debug(params)
        message = ''
        if params:
            try:
                if params.get('save'):
                    pgwatch2.update_monitored_db(params)
                    message = 'Updated!'
                elif params.get('new'):
                    msg = pgwatch2.insert_monitored_db(params)
                    message = msg
                elif params.get('delete'):
                    pgwatch2.delete_monitored_db(params)
                    message = 'Entry with ID {} ("{}") deleted!'.format(
                        params['md_id'], params['md_unique_name'])
                elif params.get('influx_delete_single'):
                    if not params['influx_single_unique_name']:
                        raise Exception('No "Unique Name" provided!')
                    pgwatch2_influx.delete_influx_data_single(
                        params['influx_single_unique_name'])
                    message = 'InfluxDB data for "{}" deleted!'.format(
                        params['influx_single_unique_name'])
                elif params.get('influx_delete_all'):
                    active_dbs = pgwatch2.get_active_db_uniques()
                    print('active_dbs', active_dbs)
                    deleted_dbnames = pgwatch2_influx.delete_influx_data_all(
                        active_dbs)
                    message = 'InfluxDB data deleted for: {}'.format(
                        ','.join(deleted_dbnames))
            except Exception as e:
                message = 'ERROR: ' + str(e)

        data = pgwatch2.get_all_monitored_dbs()
        preset_configs = pgwatch2.get_preset_configs()
        preset_configs_json = json.dumps(
            {c['pc_name']: c['pc_config']
             for c in preset_configs})
        metrics_list = pgwatch2.get_active_metrics_with_versions()
        influx_active_dbnames = pgwatch2_influx.get_active_dbnames()

        tmpl = env.get_template('dbs.html')
        return tmpl.render(message=message,
                           data=data,
                           preset_configs=preset_configs,
                           preset_configs_json=preset_configs_json,
                           metrics_list=metrics_list,
                           influx_active_dbnames=influx_active_dbnames)
Exemple #3
0
    def dbs(self, **params):
        logging.debug(params)
        messages = []
        data = []
        preset_configs = []
        metrics_list = []
        active_dbnames = []
        preset_configs_json = {}

        if params:
            try:
                if params.get('save'):
                    messages += pgwatch2.update_monitored_db(params, cmd_args)
                elif params.get('new'):
                    messages += pgwatch2.insert_monitored_db(params, cmd_args)
                elif params.get('delete'):
                    pgwatch2.delete_monitored_db(params)
                    messages.append('Entry with ID {} ("{}") deleted!'.format(
                        params['md_id'], params['md_unique_name']))
                elif params.get('delete_single'):
                    if not params['single_unique_name']:
                        raise Exception('No "Unique Name" provided!')
                    if cmd_args.datastore == 'influx':
                        pgwatch2_influx.delete_influx_data_single(
                            params['single_unique_name'])
                    else:
                        pgwatch2.delete_postgres_metrics_data_single(
                            params['single_unique_name'])
                    messages.append('Data for "{}" deleted!'.format(
                        params['single_unique_name']))
                elif params.get('delete_all'):
                    active_dbs = pgwatch2.get_active_db_uniques()
                    if cmd_args.datastore == 'influx':
                        deleted_dbnames = pgwatch2_influx.delete_influx_data_all(
                            active_dbs)
                    else:
                        deleted_dbnames = pgwatch2.delete_postgres_metrics_for_all_inactive_hosts(
                            active_dbs)
                    messages.append('Data deleted for: {}'.format(
                        ','.join(deleted_dbnames)))
            except Exception as e:
                logging.exception('Changing DBs failed')
                messages.append('ERROR: ' + str(e))

        try:
            active_dbnames = pgwatch2_influx.get_active_dbnames(
            ) if cmd_args.datastore == 'influx' else pgwatch2.get_all_dbnames(
            )
        except (requests.exceptions.ConnectionError,
                influxdb.exceptions.InfluxDBClientError):
            logging.exception('Influx ERROR')
            messages.append('ERROR: Could not connect to InfluxDB')
        except Exception as e:
            logging.exception('ERROR')
            messages.append('ERROR: ' + str(e))

        try:
            data = pgwatch2.get_all_monitored_dbs()
            preset_configs = pgwatch2.get_preset_configs()
            preset_configs_json = json.dumps(
                {c['pc_name']: c['pc_config']
                 for c in preset_configs})
            metrics_list = pgwatch2.get_active_metrics_with_versions()
        except psycopg2.OperationalError:
            messages.append('ERROR: Could not connect to Postgres')
        except Exception as e:
            messages.append('ERROR: ' + str(e))

        tmpl = env.get_template('dbs.html')
        return tmpl.render(messages=messages,
                           data=data,
                           preset_configs=preset_configs,
                           preset_configs_json=preset_configs_json,
                           metrics_list=metrics_list,
                           active_dbnames=active_dbnames,
                           no_anonymous_access=cmd_args.no_anonymous_access,
                           session=cherrypy.session,
                           no_component_logs=cmd_args.no_component_logs,
                           aes_gcm_enabled=cmd_args.aes_gcm_keyphrase,
                           datastore=cmd_args.datastore)
Exemple #4
0
    def dbs(self, **params):
        logging.debug(params)
        messages = []
        data = []
        preset_configs = []
        metrics_list = []
        active_dbnames = []
        preset_configs_json = {}

        if params:
            try:
                if params.get('save'):
                    messages += pgwatch2.update_monitored_db(params, cmd_args)
                elif params.get('new'):
                    messages += pgwatch2.insert_monitored_db(params, cmd_args)
                elif params.get('delete'):
                    pgwatch2.delete_monitored_db(params)
                    messages.append('Entry with ID {} ("{}") deleted!'.format(
                        params['md_id'], params['md_unique_name']))
                elif params.get('delete_single'):
                    if not params['single_unique_name']:
                        raise Exception('No "Unique Name" provided!')
                    if cmd_args.datastore == 'influx':
                        pgwatch2_influx.delete_influx_data_single(
                            params['single_unique_name'])
                    else:
                        pgwatch2.delete_postgres_metrics_data_single(
                            params['single_unique_name'])
                    messages.append('Data for "{}" deleted!'.format(
                        params['single_unique_name']))
                elif params.get('delete_all'):
                    active_dbs = pgwatch2.get_active_db_uniques()
                    if cmd_args.datastore == 'influx':
                        deleted_dbnames = pgwatch2_influx.delete_influx_data_all(
                            active_dbs)
                    else:
                        deleted_dbnames = pgwatch2.delete_postgres_metrics_for_all_inactive_hosts(
                            active_dbs)
                    messages.append('Data deleted for: {}'.format(
                        ','.join(deleted_dbnames)))
                elif params.get('disable_all'):
                    affected = pgwatch2.disable_all_dbs()
                    messages.append(
                        '{} DBs disabled. It will take some minutes for this to become effective'
                        .format(affected))
                elif params.get('enable_all'):
                    affected = pgwatch2.enable_all_dbs()
                    messages.append('{} DBs enabled'.format(affected))
                elif params.get('set_bulk_config'):
                    affected = pgwatch2.set_bulk_config(params)
                    messages.append(
                        "'{}' preset set as config for {} DBs. It will take some minutes for this to become effective"
                        .format(params.get('bulk_preset_config_name'),
                                affected))
                elif params.get('set_bulk_timeout'):
                    affected = pgwatch2.set_bulk_timeout(params)
                    messages.append("Timeout set for {} DBs".format(affected))
                elif params.get('set_bulk_password'):
                    err, affected = pgwatch2.set_bulk_password(
                        params, cmd_args)
                    if err:
                        messages.append(err)
                    else:
                        messages.append(
                            "Password updated for {} DBs".format(affected))
            except Exception as e:
                logging.exception('Changing DBs failed')
                messages.append('ERROR: ' + str(e))

        try:
            active_dbnames = pgwatch2_influx.get_active_dbnames(
            ) if cmd_args.datastore == 'influx' else pgwatch2.get_all_dbnames(
            )
        except Exception as e:
            logging.exception(e)
            messages.append(str(e))
        except Exception as e:
            logging.exception('ERROR getting DB listing from metrics DB')
            messages.append('ERROR getting DB listing from metrics DB: ' +
                            str(e))

        try:
            data = pgwatch2.get_all_monitored_dbs()
            preset_configs = pgwatch2.get_preset_configs()
            preset_configs_json = json.dumps(
                {c['pc_name']: c['pc_config']
                 for c in preset_configs})
            metrics_list = pgwatch2.get_active_metrics_with_versions()
        except psycopg2.OperationalError:
            messages.append('ERROR: Could not connect to Postgres')
        except Exception as e:
            messages.append('ERROR: ' + str(e))

        tmpl = env.get_template('dbs.html')
        return tmpl.render(messages=messages,
                           data=data,
                           preset_configs=preset_configs,
                           preset_configs_json=preset_configs_json,
                           metrics_list=metrics_list,
                           active_dbnames=active_dbnames,
                           no_anonymous_access=cmd_args.no_anonymous_access,
                           session=cherrypy.session,
                           no_component_logs=cmd_args.no_component_logs,
                           aes_gcm_enabled=cmd_args.aes_gcm_keyphrase,
                           datastore=cmd_args.datastore)