Beispiel #1
0
    def mark_failed(self, last_checkin=None):
        from sentry.coreapi import ClientApiHelper
        from sentry.event_manager import EventManager
        from sentry.models import Project
        from sentry.signals import monitor_failed

        if last_checkin is None:
            next_checkin_base = timezone.now()
            last_checkin = self.last_checkin or timezone.now()
        else:
            next_checkin_base = last_checkin

        affected = (type(self).objects.filter(
            Q(last_checkin__lte=last_checkin) | Q(last_checkin__isnull=True),
            id=self.id).update(
                next_checkin=self.get_next_scheduled_checkin(
                    next_checkin_base),
                status=MonitorStatus.ERROR,
                last_checkin=last_checkin,
            ))
        if not affected:
            return False

        event_manager = EventManager(
            {
                "logentry": {
                    "message": "Monitor failure: %s" % (self.name, )
                },
                "contexts": {
                    "monitor": {
                        "id": six.text_type(self.guid)
                    }
                },
            },
            project=Project(id=self.project_id),
        )
        event_manager.normalize()
        data = event_manager.get_data()
        helper = ClientApiHelper(project_id=self.project_id)
        helper.insert_data_to_database(data)
        monitor_failed.send(monitor=self, sender=type(self))
        return True
Beispiel #2
0
    def mark_failed(self, last_checkin=None):
        from sentry.coreapi import ClientApiHelper
        from sentry.event_manager import EventManager
        from sentry.models import Project
        from sentry.signals import monitor_failed

        if last_checkin is None:
            next_checkin_base = timezone.now()
            last_checkin = self.last_checkin
        else:
            next_checkin_base = last_checkin

        affected = type(self).objects.filter(
            id=self.id,
            last_checkin=self.last_checkin,
        ).update(
            next_checkin=self.get_next_scheduled_checkin(next_checkin_base),
            status=MonitorStatus.ERROR,
            last_checkin=last_checkin,
        )
        if not affected:
            return False

        event_manager = EventManager(
            {
                'logentry': {
                    'message': 'Monitor failure: %s' % (self.name, ),
                },
                'contexts': {
                    'monitor': {
                        'id': six.text_type(self.guid),
                    },
                },
            },
            project=Project(id=self.project_id),
        )
        event_manager.normalize()
        data = event_manager.get_data()
        helper = ClientApiHelper(project_id=self.project_id)
        helper.insert_data_to_database(data)
        monitor_failed.send(monitor=self, sender=type(self))
        return True
Beispiel #3
0
    def mark_failed(self, last_checkin=None):
        from sentry.coreapi import ClientApiHelper
        from sentry.event_manager import EventManager
        from sentry.models import Project
        from sentry.signals import monitor_failed

        if last_checkin is None:
            next_checkin_base = timezone.now()
            last_checkin = self.last_checkin or timezone.now()
        else:
            next_checkin_base = last_checkin

        affected = type(self).objects.filter(
            Q(last_checkin__lte=last_checkin) | Q(last_checkin__isnull=True),
            id=self.id,
        ).update(
            next_checkin=self.get_next_scheduled_checkin(next_checkin_base),
            status=MonitorStatus.ERROR,
            last_checkin=last_checkin,
        )
        if not affected:
            return False

        event_manager = EventManager(
            {
                'logentry': {
                    'message': 'Monitor failure: %s' % (self.name,),
                },
                'contexts': {
                    'monitor': {
                        'id': six.text_type(self.guid),
                    },
                },
            },
            project=Project(id=self.project_id),
        )
        event_manager.normalize()
        data = event_manager.get_data()
        helper = ClientApiHelper(project_id=self.project_id)
        helper.insert_data_to_database(data)
        monitor_failed.send(monitor=self, sender=type(self))
        return True
Beispiel #4
0
    def mark_failed(self, last_checkin=None, reason=MonitorFailure.UNKNOWN):
        from sentry.coreapi import insert_data_to_database_legacy
        from sentry.event_manager import EventManager
        from sentry.models import Project
        from sentry.signals import monitor_failed

        if last_checkin is None:
            next_checkin_base = timezone.now()
            last_checkin = self.last_checkin or timezone.now()
        else:
            next_checkin_base = last_checkin

        affected = (type(self).objects.filter(
            Q(last_checkin__lte=last_checkin) | Q(last_checkin__isnull=True),
            id=self.id).update(
                next_checkin=self.get_next_scheduled_checkin(
                    next_checkin_base),
                status=MonitorStatus.ERROR,
                last_checkin=last_checkin,
            ))
        if not affected:
            return False

        event_manager = EventManager(
            {
                "logentry": {
                    "message": "Monitor failure: %s (%s)" % (self.name, reason)
                },
                "contexts": {
                    "monitor": get_monitor_context(self)
                },
                "fingerprint": ["monitor",
                                six.text_type(self.guid), reason],
            },
            project=Project(id=self.project_id),
        )
        event_manager.normalize()
        data = event_manager.get_data()
        insert_data_to_database_legacy(data)
        monitor_failed.send(monitor=self, sender=type(self))
        return True