def run(self): for HeartbeatChild in HEARTBEATS: #HeartbeatChild here is a class (a subclass of the Heartbeat class) heartbeat = HeartbeatChild() if not heartbeat.is_skipped(): # try: heartbeat.run() # except Exception, e: # self.error_messages.append(e) if not heartbeat.passed(): error_message = heartbeat.alert_failure() self.error_messages.append(error_message) #OK, now that we've run anything, let's figure out what kind of shape we're in. if self.error_messages: #Bad shape. Time for red alert. alert_message = 'Heartbeat Failure. \n' for message in self.error_messages: alert_message += "%s \n" % message local_red_alert(alert_message) else: #Everything went ok - there are no error messages. report_response = requests.post(resources.HEARTBEAT_SUCSESS_URL)
def process_exception(self, request, exception): if not settings.DEBUG and not exception.__class__ is Http404: traceback = self._get_traceback() line = self.get_most_recent_line_in_traceback_from_what_codebase(traceback) if line is None: message = "A critical error has occured in production. No further information is available." else: file, other_useful_info = self.get_useful_info_from_traceback_line(line) #Now we have the useful info. We need to tell the world. message = "A critical error has occurred in production. %s. Likely culprit: %s on or near %s" % (str(exception), file, other_useful_info) local_red_alert(message) #Raise the alarm! return None #Use default exception handling.
def process_exception(self, request, exception): if not settings.DEBUG and not exception.__class__ is Http404: traceback = self._get_traceback() line = self.get_most_recent_line_in_traceback_from_what_codebase( traceback) if line is None: message = "A critical error has occured in production. No further information is available." else: file, other_useful_info = self.get_useful_info_from_traceback_line( line) #Now we have the useful info. We need to tell the world. message = "A critical error has occurred in production. %s. Likely culprit: %s on or near %s" % ( str(exception), file, other_useful_info) local_red_alert(message) #Raise the alarm! return None #Use default exception handling.
def save(self, owner=None, *args, **kwargs): if owner: #Sometimes we pass the owner in manually. If that's the case, assign that owner as the new owner. self.owner = owner #We're having a problem with phone numbers mysteriously becoming dis-associated from their owner. This is an attempt to figure out why so that we can write a test against it. if self.id is not None: #This is already in the database - let's see what the database thinks the owner is. current = PhoneNumber.objects.get(id=self.id) if current.owner: #We want the cases where there is indeed a current owner..... if not self.owner: #But there is no new owner. #Holy shit! Why are we erasing the owner? from what_apps.meta.alerts import local_red_alert import inspect message = "Phone number has disappeared!\n Phone number %s previous belonged to %s \n\n Stack Trace:\n\n %s" % current.id, current.owner, str(inspect.stack()) local_red_alert(message) super(PhoneNumber, self).save(*args, **kwargs) self.populate_calls() return self
def save(self, owner=None, *args, **kwargs): if owner: #Sometimes we pass the owner in manually. If that's the case, assign that owner as the new owner. self.owner = owner #We're having a problem with phone numbers mysteriously becoming dis-associated from their owner. This is an attempt to figure out why so that we can write a test against it. if self.id is not None: #This is already in the database - let's see what the database thinks the owner is. current = PhoneNumber.objects.get(id=self.id) if current.owner: #We want the cases where there is indeed a current owner..... if not self.owner: #But there is no new owner. #Holy shit! Why are we erasing the owner? from what_apps.meta.alerts import local_red_alert import inspect message = "Phone number has disappeared!\n Phone number %s previous belonged to %s \n\n Stack Trace:\n\n %s" % current.id, current.owner, str( inspect.stack()) local_red_alert(message) super(PhoneNumber, self).save(*args, **kwargs) self.populate_calls() return self