def save(self): label = self.cleaned_data.get('label') key = generate_api_key() data = {'label': label, "key": key, "account_id": settings.ACCOUNT_ID} api_key_model.add(data=data) return True
def create_test(self): self._cleanup() key = generate_api_key() api_key_model.add({'key': key}) params = {'key': key} result = api_key_model.get_one(params=params) assert result['key'] == key self._cleanup()
def get_or_create_metric(self, data=None): result = None process_id = data.get('process_id', '') plugin_id = data.get('plugin_id') metric_id = data.get('metric_id') healthcheck_id = data.get('healthcheck_id') dashboard_id = data.get('dashboard_id') metric_type = data.get('metric_type') # Global metrics all have this data['unique_id'] = generate_api_key() data['metric_type'] = 'system' if process_id == '' else 'process' data['metric_type'] = 'plugin' if plugin_id else data['metric_type'] data['metric_type'] = 'healthcheck' if healthcheck_id else data[ 'metric_type'] # Check for global metrics here if metric_type in ['system_global', 'process_global', 'plugin_global']: data['metric_type'] = metric_type data = self.remove_keys(data, ['server_id', 'process_id', 'plugin_id']) data = self.keys_to_mongoid(data=data, keys=[ 'server_id', 'process_id', 'dashboard_id', 'plugin_id', 'metric_id', 'gauge_id', 'healthcheck_id' ]) if dashboard_id: result = super(DashboardMetricsModel, self).get_or_create(data) self.collection.ensure_index([('account_id', self.desc)], background=True) self.collection.ensure_index([('server_id', self.desc)], background=True) self.collection.ensure_index([('process_id', self.desc)], background=True) self.collection.ensure_index([('plugin_id', self.desc)], background=True) self.collection.ensure_index([('healthcheck_id', self.desc)], background=True) return result
def get_or_create_metric(self, data=None): result = None process_id = data.get('process_id', '') plugin_id = data.get('plugin_id') metric_id = data.get('metric_id') healthcheck_id = data.get('healthcheck_id') dashboard_id = data.get('dashboard_id') metric_type = data.get('metric_type') # Global metrics all have this data['unique_id'] = generate_api_key() data['metric_type'] = 'system' if process_id == '' else 'process' data['metric_type'] = 'plugin' if plugin_id else data['metric_type'] data['metric_type'] = 'healthcheck' if healthcheck_id else data['metric_type'] # Check for global metrics here if metric_type in ['system_global', 'process_global', 'plugin_global']: data['metric_type'] = metric_type data = self.remove_keys(data, ['server_id', 'process_id', 'plugin_id']) data = self.keys_to_mongoid(data=data, keys=['server_id', 'process_id', 'dashboard_id', 'plugin_id', 'metric_id', 'gauge_id', 'healthcheck_id']) if dashboard_id: result = super(DashboardMetricsModel, self).get_or_create(data) self.collection.ensure_index([('account_id', self.desc)], background=True) self.collection.ensure_index([('server_id', self.desc)], background=True) self.collection.ensure_index([('process_id', self.desc)], background=True) self.collection.ensure_index([('plugin_id', self.desc)], background=True) self.collection.ensure_index([('healthcheck_id', self.desc)], background=True) return result
def add_initial_data(self): key = generate_api_key() data = {'label': "first-key", "key": key} self.add(data)