def handle(self, **options): from django.contrib.auth.models import User from django.template.defaultfilters import slugify from sentry.models import Project, Team, ProjectKey from sentry.utils.models import update if options.get('owner'): owner = User.objects.get(username__iexact=options.get('owner')) else: owner = None if owner: print "Assigning ownerless projects to %s" % owner.username # Assign unowned projects for project in Project.objects.filter(owner__isnull=True): update(project, owner=owner) print "* Changed owner of %s" % project # Create teams for any projects that are missing them print "Creating missing teams on projects" for project in Project.objects.filter(team__isnull=True, owner__isnull=False): team = Team( name=project.name, owner=project.owner, ) base_slug = slugify(team.name) slug = base_slug n = 0 while True: if Team.objects.filter(slug=slug).exists(): n += 1 slug = base_slug + '-' + str(n) continue team.slug = slug break team.save() update(project, team=team) print "* Created team %s for %s" % (team, project) # Create missing project keys print "Creating missing project keys" for team in Team.objects.all(): for member in team.member_set.select_related('user'): for project in team.project_set.all(): try: created = ProjectKey.objects.get_or_create( project=project, user=member.user, )[1] except ProjectKey.MultipleObjectsReturned: pass else: if created: print "* Created key for %s on %s" % (member.user.username, project)
def handle(self, **options): from django.db.models import Q from sentry.constants import RESERVED_ORGANIZATION_SLUGS from sentry.models import Organization, Project, Team, ProjectKey from sentry.db.models import update from sentry.db.models.utils import slugify_instance from sentry.utils.query import RangeQuerySetWrapperWithProgressBar print("Correcting data on organizations") queryset = Organization.objects.filter( slug__isnull=True, ) for org in RangeQuerySetWrapperWithProgressBar(queryset): slugify_instance(org, org.name, RESERVED_ORGANIZATION_SLUGS) org.save() # Create teams for any projects that are missing them print("Correcting data on projects") queryset = Project.objects.filter( Q(team__isnull=True) | Q(organization__isnull=True), ).select_related('owner') for project in RangeQuerySetWrapperWithProgressBar(queryset): if not project.team: organization = Organization( name=project.name, owner=project.owner, ) slugify_instance(organization, organization.name, RESERVED_ORGANIZATION_SLUGS) organization.save() team = Team( name=project.name, owner=project.owner, oprganization=organization, ) slugify_instance(team, team.name, RESERVED_ORGANIZATION_SLUGS) team.save() update(project, organization=team.organization, team=team) # Create missing project keys print("Creating missing project keys") queryset = Team.objects.all() for team in RangeQuerySetWrapperWithProgressBar(queryset): for member in team.member_set.select_related('user'): for project in team.project_set.all(): try: created = ProjectKey.objects.get_or_create( project=project, user=member.user, )[1] except ProjectKey.MultipleObjectsReturned: pass
def create_team_and_keys_for_project(instance, created, **kwargs): if not created or kwargs.get('raw'): return if not instance.owner: return if not instance.team: team = Team(owner=instance.owner, name=instance.name) slugify_instance(team, instance.slug) team.save() update(instance, team=team) if not ProjectKey.objects.filter(project=instance, user__isnull=True).exists(): ProjectKey.objects.create( project=instance, )
def test_send_invite_email(self): team = Team(name='test', slug='test', id=1) member = PendingTeamMember(id=1, team=team, email='*****@*****.**') with self.Settings(SENTRY_URL_PREFIX='http://example.com'): member.send_invite_email() self.assertEquals(len(mail.outbox), 1) msg = mail.outbox[0] self.assertEquals(msg.to, ['*****@*****.**'])
def assigned(request): org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) project = Project( id=1, slug='example', name='Example', team=team, organization=org, ) group = Group( id=1, project=project, message='This is an example event.', ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data('python'), ) assigned = Activity( group=event.group, project=event.project, type=Activity.ASSIGNED, user=request.user, data={ 'text': 'This is an example note!', 'assignee': '*****@*****.**' }, ) return MailPreview( html_template='sentry/emails/activity/assigned.html', text_template='sentry/emails/activity/assigned.txt', context={ 'data': assigned.data, 'author': assigned.user, 'date': assigned.datetime, 'group': group, 'link': group.get_absolute_url(), }, ).render()
def get(self, request): org = Organization( id=1, slug='organization', name='My Company', ) team = Team( id=1, slug='team', name='My Team', organization=org, ) project = Project( id=1, organization=org, team=team, slug='project', name='My Project', ) release = Release( project=project, version=sha1(uuid4().hex).hexdigest(), ) release_link = absolute_uri( reverse('sentry-release-details', kwargs={ 'organization_slug': org.slug, 'project_id': project.slug, 'version': release.version, })) project_link = absolute_uri( reverse('sentry-stream', kwargs={ 'organization_slug': org.slug, 'project_id': project.slug, })) preview = MailPreview( html_template='sentry/emails/activity/release.html', text_template='sentry/emails/activity/release.txt', context={ 'release': release, 'project': project, 'release_link': release_link, 'project_link': project_link, }, ) return render_to_response('sentry/debug/mail/preview.html', { 'preview': preview, })
def loaddata(): with open('initial_data.json') as data_file: structure = json.load(data_file) organization = Organization.objects.get(pk=1) for record in structure: try: team = Team.objects.get(name=record['team'], organization=organization) except ObjectDoesNotExist: team = Team() team.name = record['team'] team.organization = organization team.save() try: project = Project.objects.get(name=record['project'], team=team, organization=organization) except ObjectDoesNotExist: project = Project() project.team = team project.name = record['project'] project.organization = organization project.save() key = ProjectKey.objects.filter(project=project)[0] if 'key' in record: parts = record['key'].split(':') key.public_key = parts[0] if len(parts) > 1: key.secret_key = parts[1] key.save() print 'PROJECT_NAME = "%s"' % (project.name, ) print 'SENTRY_DSN = "%s"' % (key.get_dsn(), ) print ''
def new_event(request): team = Team( id=1, slug='example', name='Example', ) project = Project( id=1, slug='example', name='Example', team=team, ) group = Group( id=1, project=project, message='This is an example event.', level=logging.ERROR, ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data('python'), ) rule = Rule(label="An example rule") interface_list = [] for interface in event.interfaces.itervalues(): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) preview = MailPreview( html_template='sentry/emails/error.html', text_template='sentry/emails/error.html', context={ 'rule': rule, 'group': group, 'event': event, 'link': 'http://example.com/link', 'interfaces': interface_list, 'tags': event.get_tags(), }, ) return render_to_response('sentry/debug/mail/preview.html', { 'preview': preview, })
def access_approved(request): org = Organization(id=1, slug="example", name="Example") team = Team(id=1, slug="example", name="Example", organization=org) return MailPreview( html_template="sentry/emails/access-approved.html", text_template="sentry/emails/access-approved.txt", context={ "email": "*****@*****.**", "name": "George Bush", "organization": org, "team": team, }, ).render(request)
def new_note(request): team = Team( id=1, slug='example', name='Example', ) project = Project( id=1, slug='example', name='Example', team=team, ) group = Group( id=1, project=project, message='This is an example event.', ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data('python'), ) note = Activity( group=event.group, event=event, project=event.project, type=Activity.NOTE, user=request.user, data={'text': 'This is an example note!'}, ) preview = MailPreview( html_template='sentry/emails/new_note.html', text_template='sentry/emails/new_note.txt', context={ 'text': note.data['text'], 'author': note.user, 'date': note.datetime, 'group': group, 'link': group.get_absolute_url(), }, ) return render_to_response('sentry/debug/mail/preview.html', { 'preview': preview, })
def sentry_create_team(organization, name): model = sentry_find_team(organization, name) existing = model is not None if not existing: model = Team() model.name = name model.organization = organization model.save() return model, existing
def get(self, request): org = Organization( id=1, slug='organization', name='My Company', ) team = Team( id=1, slug='team', name='My Team', organization=org, ) project = Project( id=1, organization=org, team=team, slug='project', name='My Project', ) release = Release( project=project, version=sha1(uuid4().hex).hexdigest(), ) release_link = absolute_uri('/{}/{}/releases/{}/'.format( org.slug, project.slug, release.version, )) project_link = absolute_uri( reverse('sentry-stream', kwargs={ 'organization_slug': org.slug, 'project_id': project.slug, })) return MailPreview( html_template='sentry/emails/activity/release.html', text_template='sentry/emails/activity/release.txt', context={ 'release': release, 'project': project, 'release_link': release_link, 'project_link': project_link, }, ).render(request)
def request_access(request): org = Organization(id=1, slug="sentry", name="Sentry org") team = Team(id=1, slug="example", name="Example", organization=org) return MailPreview( html_template="sentry/emails/request-team-access.html", text_template="sentry/emails/request-team-access.txt", context={ "email": "*****@*****.**", "name": "George Bush", "organization": org, "team": team, "url": absolute_uri( reverse("sentry-organization-teams", kwargs={"organization_slug": org.slug}) ), }, ).render(request)
def get(self, request): org = Organization( id=1, slug='organization', name='My Company', ) team = Team( id=1, slug='team', name='My Team', organization=org, ) project = Project( id=1, organization=org, team=team, slug='project', name='My Project', ) group = next( make_group_generator( get_random(request), project, ), ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data('python'), datetime=datetime(2016, 6, 13, 3, 8, 24, tzinfo=timezone.utc), ) activity = Activity( group=event.group, project=event.project, **self.get_activity(request, event) ) return render_to_response('sentry/debug/mail/preview.html', { 'preview': ActivityMailPreview(activity), 'format': request.GET.get('format'), })
def request_access_for_another_member(request): org = Organization(id=1, slug="sentry", name="Sentry org") team = Team(id=1, slug="example", name="Example", organization=org) return MailPreview( html_template="sentry/emails/request-team-access.html", text_template="sentry/emails/request-team-access.txt", context={ "email": "*****@*****.**", "name": "Username", "organization": org, "team": team, "url": absolute_uri( reverse("sentry-organization-teams", kwargs={"organization_slug": org.slug}) ), "requester": request.user.get_display_name(), }, ).render(request)
def get(self, request): org = Organization( id=1, slug='organization', name='My Company', ) team = Team( id=1, slug='team', name='My Team', organization=org, ) project = Project( id=1, organization=org, team=team, slug='project', name='My Project', ) group = Group( id=1, project=project, ) return MailPreview( html_template='sentry/emails/activity/new-user-feedback.html', text_template='sentry/emails/activity/new-user-feedback.txt', context={ 'group': group, 'report': { 'name': 'Homer Simpson', 'email': '*****@*****.**', 'comments': 'I hit a bug.\n\nI went to https://example.com, hit the any key, and then it stopped working. DOH!', }, }, ).render(request)
def access_approved(request): org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) return MailPreview( html_template='sentry/emails/access-approved.html', text_template='sentry/emails/access-approved.txt', context={ 'email': '*****@*****.**', 'name': 'George Bush', 'organization': org, 'team': team, }, ).render(request)
def request_access(request): org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) preview = MailPreview( html_template='sentry/emails/request-team-access.html', text_template='sentry/emails/request-team-access.txt', context={ 'email': '*****@*****.**', 'name': 'George Bush', 'organization': org, 'team': team, 'url': absolute_uri( reverse('sentry-organization-members', kwargs={ 'organization_slug': org.slug, }) + '?ref=access-requests'), }, ) return render_to_response('sentry/debug/mail/preview.html', { 'preview': preview, })
name = 'AgoraVoting' name2 = 'AuthApi' if Organization.objects.filter(name=name).count() == 0: organization = Organization() organization.name = name organization.save() om = OrganizationMember() om.organization = organization om.role = 'owner' om.user = user om.save() team = Team() team.name = name team.organization = organization team.save() project = Project() project.team = team project.name = name2 project.organization = organization project.save() else: organization = Organization.objects.filter(name=name).all()[0] team = Team.objects.filter(name=name, organization=organization).all()[0] project =Project.objects.filter(team=team, name=name2, organization=organization).all()[0] key = ProjectKey.objects.filter(project=project)[0]
options.set('beacon.anonymous', True) from django.conf import settings from sentry.models import (Team, Project, ProjectKey, User, Organization, OrganizationMember, OrganizationMemberTeam) organization = Organization.objects.first() if not organization: organization = Organization() organization.name = 'Sentry' organization.save() team = Team.objects.first() if not team: team = Team() team.name = 'Sentry' team.organization = organization team.save() django_project = Project.objects.filter(name='Django').first() if not django_project: django_project = Project() django_project.team = team django_project.name = 'Django' django_project.organization = organization django_project.save() django_project.add_team(team) django_project.save()
def report(request): from sentry.tasks import reports random = get_random(request) duration = 60 * 60 * 24 * 7 timestamp = random.randint( to_timestamp(datetime(2016, 6, 1, 0, 0, 0, tzinfo=timezone.utc)), to_timestamp(datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc)), ) organization = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=organization, ) project = Project( id=1, organization=organization, team=team, slug='project', name='My Project', ) start, stop = reports._to_interval(timestamp, duration) group_instances = {} def fetch_group_instances(id_list): results = {} for id in id_list: instance = group_instances.get(id) if instance is not None: results[id] = instance return results def make_group_id_generator(): group_generator = make_group_generator(random, project) while True: group = next(group_generator) if random.random() < 0.95: group_instances[group.id] = group yield group.id group_id_sequence = make_group_id_generator() def make_release_generator(): id_sequence = itertools.count(1) while True: dt = to_datetime( random.randint( timestamp - (30 * 24 * 60 * 60), timestamp, ), ) yield Release( id=next(id_sequence), project=project, version=''.join([ random.choice('0123456789abcdef') for _ in range(40) ]), date_added=dt, date_started=dt, ) release_instances = {} def make_release_id_generator(): release_generator = make_release_generator() while True: release = next(release_generator) release_instances[release.id] = release yield release.id release_id_generator = make_release_id_generator() def build_issue_list(): summaries = [] for i in range(3): summaries.append( int(random.weibullvariate(10, 1) * random.paretovariate(0.5)) ) return summaries, [( next(group_id_sequence), ( int(random.paretovariate(0.3)), int(random.paretovariate(0.3)), ), ) for _ in xrange(0, random.randint(1, 5))] def build_release_list(): return reports.trim_release_list([ ( next(release_id_generator), max(1, int(random.weibullvariate(20, 0.15))), ) for _ in range(random.randint(0, 10)) ]) def build_report(): daily_maximum = random.randint(1000, 10000) rollup = 60 * 60 * 24 series = [( timestamp + (i * rollup), (random.randint(0, daily_maximum), random.randint(0, daily_maximum)) ) for i in xrange(0, 7)] aggregates = [ random.randint(0, daily_maximum * 7) if random.random() < 0.9 else None for _ in xrange(0, 4) ] return series, aggregates, build_issue_list(), build_release_list() report = reduce( reports.merge_reports, [build_report() for _ in xrange(0, random.randint(1, 3))] ) if random.random() < 0.85: personal = { 'resolved': random.randint(0, 100), 'users': int(random.paretovariate(0.2)), } else: personal = { 'resolved': 0, 'users': 0, } return MailPreview( html_template='sentry/emails/reports/body.html', text_template='sentry/emails/reports/body.txt', context={ 'duration': reports.durations[duration], 'interval': { 'start': reports.date_format(start), 'stop': reports.date_format(stop), }, 'report': reports.to_context( report, fetch_group_instances, ), 'organization': organization, 'personal': personal, 'user': request.user, }, ).render(request)
def get(self, request): org = Organization( id=1, slug='organization', name='My Company', ) team = Team( id=1, slug='team', name='My Team', organization=org, ) projects = [ Project( id=1, organization=org, team=team, slug='project', name='My Project', ), Project( id=2, organization=org, team=team, slug='another-project', name='Another Project', ), Project( id=3, organization=org, team=team, slug='yet-another-project', name='Yet Another Project', ), ] release = Release( organization_id=org.id, version='6c998f755f304593a4713abd123eaf8833a2de5e', date_added=datetime.datetime(2016, 10, 12, 15, 39, tzinfo=pytz.utc) ) deploy = Deploy( release=release, organization_id=org.id, environment_id=1, date_finished=datetime.datetime(2016, 10, 12, 15, 39, tzinfo=pytz.utc), ) release_links = [ absolute_uri('/{}/{}/releases/{}/'.format( org.slug, p.slug, release.version, )) for p in projects ] repos = [ { 'name': 'getsentry/getsentry', 'commits': [ ( Commit( key='48b86fcd677da3dba5679d7a738240ce6fb74b20', date_added=datetime.datetime(2016, 10, 11, 15, 39, tzinfo=pytz.utc), ), None ), ( Commit( key='a53a2756bb8d111b43196210b34df90b87ed336b', message='Fix billing', author=CommitAuthor( name='David Cramer', email='*****@*****.**', ), date_added=datetime.datetime(2016, 10, 11, 16, 45, tzinfo=pytz.utc), ), User(email='*****@*****.**', name='David Cramer') ), ], }, { 'name': 'getsentry/sentry', 'commits': [ ( Commit( key='3c8eb3b4af6ee2a29c68daa188fc730c8e4b39fd', date_added=datetime.datetime(2016, 10, 10, 15, 39, tzinfo=pytz.utc), ), None ), ( Commit( key='373562702009df1692da6eb80a933139f29e094b', message='Fix padding', author=CommitAuthor( name='Chris Jennings', email='*****@*****.**', ), date_added=datetime.datetime(2016, 10, 10, 16, 39, tzinfo=pytz.utc), ), None ), ( Commit( key='631cd9096bd9811a046a472bb0aa8b573e86e1f1', message='Update README.rst', author=CommitAuthor( name='David Cramer', email='*****@*****.**', ), date_added=datetime.datetime(2016, 10, 11, 10, 39, tzinfo=pytz.utc), ), User(email='*****@*****.**', name='David Cramer') ), ], } ] return MailPreview( html_template='sentry/emails/activity/release.html', text_template='sentry/emails/activity/release.txt', context={ 'release': release, 'projects': zip(projects, release_links, [6, 1, 0]), 'repos': repos, 'reason': GroupSubscriptionReason.descriptions[GroupSubscriptionReason.committed], 'project_count': len(projects), 'commit_count': 4, 'author_count': 1, 'file_count': 5, 'environment': 'production', 'deploy': deploy, 'setup_repo_link': absolute_uri('/organizations/{}/repos/'.format( org.slug, )), }, ).render(request)
DEFAULT_PROJECT = 'Default' organizations = Organization.objects.filter(name=DEFAULT_ORGANIZATION) if organizations.count(): organization = organizations.first() else: organization = Organization() organization.name = DEFAULT_ORGANIZATION organization.save() teams = Team.objects.filter(name=DEFAULT_TEAM) if teams.count(): team = teams.first() else: team = Team() team.name = DEFAULT_TEAM team.organization = organization team.save() projects = Project.objects.filter(name=DEFAULT_PROJECT) if projects.count(): project = projects.first() else: project = Project() project.team = team project.name = 'Default' project.organization = organization project.save() user = User()
configure() # Then import the models from sentry.models import ( Team, Project, User, Organization, OrganizationMember, OrganizationMemberTeam ) # Create an organization, team, and user if there are *no* users # in the install (bootstrap 1 time only) if not User.objects.all(): organization = Organization() organization.name = os.environ.get('TEAM_NAME', 'Aptible') organization.save() team = Team() team.name = os.environ.get('TEAM_NAME', 'Aptible') team.organization = organization team.save() project = Project() project.team = team project.name = 'Default' project.organization = organization project.save() user = User() user.username = os.environ.get('ADMIN_USERNAME', 'aptible') user.email = 'admin@localhost' user.is_superuser = True user.set_password(os.environ['ADMIN_PASSWORD'])
from sentry.models import Team, Project, ProjectKey, User, Organization user = User() user.username = '******' user.email = '{{sentry.bootstrap.email}}' user.is_superuser = True user.set_password('{{sentry.bootstrap.password}}') user.save() organization = Organization() organization.name = '{{sentry.bootstrap.organization}}' organization.owner = user organization.save() team = Team() team.organization = organization team.name = '{{sentry.bootstrap.team}}' team.owner = user team.save() project = Project() project.organization = organization project.team = team project.owner = user project.name = '{{sentry.bootstrap.project}}' project.save() #let's replace the key key = ProjectKey.objects.filter(project=project)[0] key.public_key = '{{sentry.bootstrap.public_key}}'
def main(): parser = build_parser() options, _args = parser.parse_args() os.environ['SENTRY_CONF'] = options.sentry_path from sentry.utils.runner import configure configure() from django.conf import settings # Add in the sentry object models from sentry.models import Organization, Project, ProjectKey, Team, User admin_email = settings.SENTRY_OPTIONS['system.admin-email'] if not options.project: parser.error("Project name required") if not options.platform: parser.error("Platform is required") try: o = Organization.objects.get(name=options.org) except Organization.DoesNotExist: print "Organization not found: %s" % options.org sys.exit(1) try: u = User.objects.get(email=admin_email) except User.DoesNotExist: print "Admin user not found: %s" % admin_email sys.exit(1) # try to load the requested team try: t = Team.objects.get(name=options.team, organization_id=o.id) except Team.DoesNotExist: # this team does not yet exist. Create it. t = Team() t.name = options.team t.organization_id = o.id t.owner_id = u.id t.save() # reload the object t = Team.objects.get(name=options.team, organization_id=o.id) try: p = Project.objects.get(name=options.project, team_id=t.id) except: # the project doesn't exist. Create it! p = Project() # ensure all project names are in lowercase p.name = options.project.lower() p.team_id = t.id p.organization_id = o.id p.platform = options.platform try: p.save() except: print "Project save failed for %s" % (options.project) sys.exit(1) # create a static file containing this application's DSN k = ProjectKey.objects.get(project_id=p.id).get_dsn() prefix = quote(o.name.lower() + "-" + t.name.lower() + "-") dsn_path = "%s/dsn/%s%s" % (options.sentry_path, prefix, p.name) dsn = open(dsn_path, 'w') dsn.write(k) dsn.close() if options.verbose: print "Project %s created in team %s." % (options.project, t.name)
def get(self, request): org = Organization( id=1, slug='organization', name='My Company', ) team = Team( id=1, slug='team', name='My Team', organization=org, ) project = Project( id=1, organization=org, team=team, slug='project', name='My Project', ) release = Release(project=project, organization_id=project.organization_id, version='6c998f755f304593a4713abd123eaf8833a2de5e', date_added=datetime(2016, 10, 12, 15, 39, tzinfo=pytz.utc)) release_link = absolute_uri('/{}/{}/releases/{}/'.format( org.slug, project.slug, release.version, )) project_link = absolute_uri('/{}/{}/'.format( org.slug, project.slug, )) commit_list = [ Commit(key='48b86fcd677da3dba5679d7a738240ce6fb74b20'), Commit(key='a53a2756bb8d111b43196210b34df90b87ed336b', message='Update README.rst', author=CommitAuthor( name='David Cramer', email='*****@*****.**', )), ] return MailPreview( html_template='sentry/emails/activity/release.html', text_template='sentry/emails/activity/release.txt', context={ 'release': release, 'project': project, 'release_link': release_link, 'project_link': project_link, 'commit_list': commit_list, 'reason': GroupSubscriptionReason.descriptions[ GroupSubscriptionReason.committed], }, ).render(request)
def digest(request): seed = request.GET.get('seed', str(time.time())) logger.debug('Using random seed value: %s') random = Random(seed) now = datetime.utcnow().replace(tzinfo=pytz.utc) # TODO: Refactor all of these into something more manageable. org = Organization( id=1, slug='example', name='Example Organization', ) team = Team( id=1, slug='example', name='Example Team', organization=org, ) project = Project( id=1, slug='example', name='Example Project', team=team, organization=org, ) rules = {i: Rule( id=i, project=project, label="Rule #%s" % (i,), ) for i in xrange(1, random.randint(2, 4))} state = { 'project': project, 'groups': {}, 'rules': rules, 'event_counts': {}, 'user_counts': {}, } records = [] group_sequence = itertools.count(1) event_sequence = itertools.count(1) for i in xrange(random.randint(1, 30)): group_id = next(group_sequence) culprit = '{module} in {function}'.format( module='.'.join( ''.join(random.sample(WORDS, random.randint(1, int(random.paretovariate(2.2))))) for word in xrange(1, 4) ), function=random.choice(WORDS) ) group = state['groups'][group_id] = Group( id=group_id, project=project, message=words(int(random.weibullvariate(8, 4)), common=False), culprit=culprit, level=random.choice(LOG_LEVELS.keys()), ) offset = timedelta(seconds=0) for i in xrange(random.randint(1, 10)): offset += timedelta(seconds=random.random() * 120) event = Event( id=next(event_sequence), event_id=uuid.uuid4().hex, project=project, group=group, message=group.message, data=load_data('python'), datetime=now - offset, ) records.append( Record( event.event_id, Notification( event, random.sample(state['rules'], random.randint(1, len(state['rules']))), ), to_timestamp(event.datetime), ) ) state['event_counts'][group_id] = random.randint(10, 1e4) state['user_counts'][group_id] = random.randint(10, 1e4) digest = build_digest(project, records, state) start, end, counts = get_digest_metadata(digest) return MailPreview( html_template='sentry/emails/digests/body.html', text_template='sentry/emails/digests/body.txt', context={ 'project': project, 'counts': counts, 'digest': digest, 'start': start, 'end': end, }, ).render()
def report(request): from sentry.tasks import reports random = get_random(request) duration = 60 * 60 * 24 * 7 timestamp = to_timestamp( reports.floor_to_utc_day( to_datetime( random.randint( to_timestamp( datetime(2015, 6, 1, 0, 0, 0, tzinfo=timezone.utc)), to_timestamp( datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc)), )))) start, stop = interval = reports._to_interval(timestamp, duration) organization = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=organization, ) projects = [] for i in xrange(0, random.randint(1, 8)): name = ' '.join(random.sample(loremipsum.words, random.randint(1, 4))) projects.append( Project( id=i, organization=organization, team=team, slug=slugify(name), name=name, date_added=start - timedelta(days=random.randint(0, 120)), )) def make_release_generator(): id_sequence = itertools.count(1) while True: dt = to_datetime( random.randint( timestamp - (30 * 24 * 60 * 60), timestamp, ), ) p = random.choice(projects) yield Release( id=next(id_sequence), project=p, organization_id=p.organization_id, version=''.join( [random.choice('0123456789abcdef') for _ in range(40)]), date_added=dt, ) def build_issue_summaries(): summaries = [] for i in range(3): summaries.append( int(random.weibullvariate(10, 1) * random.paretovariate(0.5))) return summaries def build_usage_summary(): return ( int(random.weibullvariate(3, 1) * random.paretovariate(0.2)), int(random.weibullvariate(5, 1) * random.paretovariate(0.2)), ) def build_calendar_data(project): start, stop = reports.get_calendar_query_range(interval, 3) rollup = 60 * 60 * 24 series = [] weekend = frozenset((5, 6)) value = int(random.weibullvariate(5000, 3)) for timestamp in tsdb.get_optimal_rollup_series(start, stop, rollup)[1]: damping = random.uniform( 0.2, 0.6) if to_datetime(timestamp).weekday in weekend else 1 jitter = random.paretovariate(1.2) series.append((timestamp, int(value * damping * jitter))) value = value * random.uniform(0.25, 2) return reports.clean_calendar_data(project, series, start, stop, rollup, stop) def build_report(project): daily_maximum = random.randint(1000, 10000) rollup = 60 * 60 * 24 series = [(timestamp + (i * rollup), (random.randint(0, daily_maximum), random.randint(0, daily_maximum))) for i in xrange(0, 7)] aggregates = [ random.randint(0, daily_maximum * 7) if random.random() < 0.9 else None for _ in xrange(0, 4) ] return reports.Report( series, aggregates, build_issue_summaries(), build_usage_summary(), build_calendar_data(project), ) if random.random() < 0.85: personal = { 'resolved': random.randint(0, 100), 'users': int(random.paretovariate(0.2)), } else: personal = { 'resolved': 0, 'users': 0, } return MailPreview( html_template='sentry/emails/reports/body.html', text_template='sentry/emails/reports/body.txt', context={ 'duration': reports.durations[duration], 'interval': { 'start': reports.date_format(start), 'stop': reports.date_format(stop), }, 'report': reports.to_context( organization, interval, {project: build_report(project) for project in projects}), 'organization': organization, 'personal': personal, 'user': request.user, }, ).render(request)
from sentry.models import Team, Project, ProjectKey, User, Organization user = User() user.username = '******' user.email = 'admin@localhost' user.is_superuser = True user.set_password('admin') user.save() organization = Organization() organization.name = 'MyOrg' organization.owner = user organization.save() team = Team() team.name = 'Sentry' team.organization = organization team.owner = user team.save() project = Project() project.team = team project.name = 'Default' project.organization = organization project.save() f = open('dsn', 'wb') key = ProjectKey.objects.filter(project=project)[0] f.write(key.get_dsn()) f.close()
def get(self, request): from sentry.plugins.sentry_mail.activity.new_processing_issues import summarize_issues org = Organization( id=1, slug='organization', name='My Company', ) team = Team( id=1, slug='team', name='My Team', organization=org, ) project = Project( id=1, organization=org, team=team, slug='project', name='My Project', ) return MailPreview( html_template='sentry/emails/activity/new_processing_issues.html', text_template='sentry/emails/activity/new_processing_issues.txt', context={ 'project': project, 'reason': GroupSubscriptionReason.descriptions[GroupSubscriptionReason.processing_issue], 'issues': summarize_issues( [ { 'data': { 'image_arch': 'arm64', 'image_path': '/var/containers/Bundle/Application/FB14D416-DE4E-4224-9789-6B88E9C42601/CrashProbeiOS.app/CrashProbeiOS', 'image_uuid': 'a2df1794-e0c7-371c-baa4-93eac340a78a' }, 'object': 'dsym:a2df1794-e0c7-371c-baa4-93eac340a78a', 'scope': 'native', 'type': 'native_missing_dsym' }, { 'data': { 'image_arch': 'arm64', 'image_path': '/var/containers/Bundle/Application/FB14D416-DE4E-4224-9789-6B88E9C42601/CrashProbeiOS.app/libCrashProbeiOS', 'image_uuid': '12dc1b4c-a01b-463f-ae88-5cf0c31ae680' }, 'object': 'dsym:12dc1b4c-a01b-463f-ae88-5cf0c31ae680', 'scope': 'native', 'type': 'native_bad_dsym' }, ] ), 'reprocessing_active': self.reprocessing_active, 'info_url': absolute_uri('/{}/{}/settings/processing-issues/'.format( org.slug, project.slug, )), }, ).render(request)
# Bootstrap the Sentry environment from sentry.utils.runner import configure configure("/home/sentry/sentry.conf.py") # Do something crazy from sentry.models import Team, Project, ProjectKey, User, Organization user = User.objects.get(pk=1) organization = Organization() organization.name = 'AgoraVoting' organization.owner = user organization.save() team = Team() team.name = 'AgoraVoting' team.organization = organization team.save() project = Project() project.team = team project.name = 'AuthApi' project.organization = organization project.save() key = ProjectKey.objects.filter(project=project)[0] dsn = key.get_dsn() # writting the sentry configuration to deploy.conf authapi_conf = ''' # sentry
def parse_team_value(projects, value, user): return Team.objects.filter( slug__iexact=value[1:], projectteam__project__in=projects).first() or Team(id=0)
def new_event(request): platform = request.GET.get('platform', 'python') org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) project = Project( id=1, slug='example', name='Example', team=team, organization=org, ) random = get_random(request) group = next( make_group_generator(random, project), ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data(platform), datetime=to_datetime( random.randint( to_timestamp(group.first_seen), to_timestamp(group.last_seen), ), ), ) rule = Rule(label="An example rule") interface_list = [] for interface in six.itervalues(event.interfaces): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) return MailPreview( html_template='sentry/emails/error.html', text_template='sentry/emails/error.txt', context={ 'rule': rule, 'group': group, 'event': event, 'link': 'http://example.com/link', 'interfaces': interface_list, 'tags': event.get_tags(), 'project_label': project.name, 'tags': [ ('logger', 'javascript'), ('environment', 'prod'), ('level', 'error'), ('device', 'Other') ] }, ).render(request)
# Bootstrap the Sentry environment from sentry.utils.runner import configure # YOU MUST COPY THE SETTINGS FILE TO /root/.sentry/sentry.conf.py configure() # Do something crazy from sentry.models import Team, Project, ProjectKey, User user = User.objects.get(username="******") team = Team() team.name = 'Sentry' team.owner = user team.save() project = Project() project.team = team project.owner = user project.name = 'Default' project.save() key = ProjectKey.objects.filter(project=project)[0] print '%s' % (key.get_dsn(),)
def digest(request): random = get_random(request) # TODO: Refactor all of these into something more manageable. org = Organization( id=1, slug='example', name='Example Organization', ) team = Team( id=1, slug='example', name='Example Team', organization=org, ) project = Project( id=1, slug='example', name='Example Project', team=team, organization=org, ) rules = {i: Rule( id=i, project=project, label="Rule #%s" % (i,), ) for i in range(1, random.randint(2, 4))} state = { 'project': project, 'groups': {}, 'rules': rules, 'event_counts': {}, 'user_counts': {}, } records = [] event_sequence = itertools.count(1) group_generator = make_group_generator(random, project) for i in range(random.randint(1, 30)): group = next(group_generator) state['groups'][group.id] = group offset = timedelta(seconds=0) for i in range(random.randint(1, 10)): offset += timedelta(seconds=random.random() * 120) event = Event( id=next(event_sequence), event_id=uuid.uuid4().hex, project=project, group=group, message=group.message, data=load_data('python'), datetime=to_datetime( random.randint( to_timestamp(group.first_seen), to_timestamp(group.last_seen), ), ) ) records.append( Record( event.event_id, Notification( event, random.sample(state['rules'], random.randint(1, len(state['rules']))), ), to_timestamp(event.datetime), ) ) state['event_counts'][group.id] = random.randint(10, 1e4) state['user_counts'][group.id] = random.randint(10, 1e4) digest = build_digest(project, records, state) start, end, counts = get_digest_metadata(digest) return MailPreview( html_template='sentry/emails/digests/body.html', text_template='sentry/emails/digests/body.txt', context={ 'project': project, 'counts': counts, 'digest': digest, 'start': start, 'end': end, }, ).render(request)
configure() # Make an assumption that if 'admin' -User exists Sentry has been initialized if not User.objects.filter(username='******').exists(): user = User() user.username = '******' user.email = '*****@*****.**' user.is_superuser = True user.set_password('admin') user.save() organization = Organization.objects.filter(slug='sentry')[0] team = Team() team.name = 'COD' team.organization = organization team.save() project = Project() project.team = team project.add_team(team) project.name = 'Cern Open Data Portal' project.organization = organization project.save() ProjectKey.objects.get(project=project).delete() public_key = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' secret_key = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
def new_event(request): platform = request.GET.get('platform', 'python') org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) project = Project( id=1, slug='example', name='Example', team=team, organization=org, ) group = Group( id=1, project=project, message='This is an example event.', level=logging.ERROR, ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data(platform), ) rule = Rule(label="An example rule") interface_list = [] for interface in event.interfaces.itervalues(): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) return MailPreview( html_template='sentry/emails/error.html', text_template='sentry/emails/error.html', context={ 'rule': rule, 'group': group, 'event': event, 'link': 'http://example.com/link', 'interfaces': interface_list, 'tags': event.get_tags(), 'project_label': project.name, 'tags': [('logger', 'javascript'), ('environment', 'prod'), ('level', 'error'), ('device', 'Other')] }, ).render()