Пример #1
0
def database_notification_for_team(team=None):
    """
    Notifies teams of database usage.
    if threshold_database_notification <= 0, the notification is disabled.
    """
    LOG.info("sending database notification for team %s" % team)
    threshold_database_notification = Configuration.get_by_name_as_int(
        "threshold_database_notification", default=0)
    # if threshold_database_notification
    if threshold_database_notification <= 0:
        LOG.warning("database notification is disabled")
        return

    databases = Database.objects.filter(team=team,
                                        is_in_quarantine=False,
                                        subscribe_to_email_events=True)
    msgs = []
    for database in databases:
        used = database.used_size_in_mb
        capacity = database.total_size_in_mb
        try:
            percent_usage = (used / capacity) * 100
        except ZeroDivisionError:
            # database has no total size
            percent_usage = 0.0
        msg = "database %s => usage: %.2f | threshold: %.2f" % (
            database, percent_usage, threshold_database_notification)
        LOG.info(msg)
        msgs.append(msg)

        if not team.email:
            msgs.append(
                "team %s has no email set and therefore no database usage notification will been sent"
                % team)
        else:
            if percent_usage >= threshold_database_notification:
                LOG.info("Sending database notification...")
                context = {}
                context['database'] = database.name
                context['team'] = team
                context['measure_unity'] = "MB"
                context['used'] = used
                context['capacity'] = capacity
                context['percent'] = "%.2f" % percent_usage
                context['environment'] = database.environment.name
                email_notifications.database_usage(context=context)

    return msgs
Пример #2
0
def database_notification_for_team(team=None):
	"""
    Notifies teams of database usage.
    if threshold_database_notification <= 0, the notification is disabled.
    """
	from logical.models import Database

	LOG.info("sending database notification for team %s" % team)
	threshold_database_notification = Configuration.get_by_name_as_int("threshold_database_notification", default=0)
	# if threshold_database_notification
	if threshold_database_notification <= 0:
		LOG.warning("database notification is disabled")
		return

	databases = Database.objects.filter(team=team)
	msgs = []
	for database in databases:
		used = database.used_size_in_mb
		capacity = database.total_size_in_mb
		try:
			percent_usage = (used / capacity) * 100
		except ZeroDivisionError:
			#database has no total size
			percent_usage = 0.0
		msg = "database %s => usage: %.2f | threshold: %.2f" % (
			database, percent_usage, threshold_database_notification)
		LOG.info(msg)
		msgs.append(msg)

		if not team.email:
			msgs.append("team %s has no email set and therefore no database usage notification will been sent" % team)
		else:
			if percent_usage >= threshold_database_notification:
				LOG.info("Sending database notification...")
				context = {}
				context['database'] = database.name
				context['team'] = team
				context['measure_unity'] = "MB"
				context['used'] = used
				context['capacity'] = capacity
				context['percent'] = "%.2f" % percent_usage
				context['environment'] = database.environment.name
				email_notifications.database_usage(context=context)

	return msgs