def alert_detail(self, request): from freenasUI.system.models import Alert from freenasUI.system.alert import alert_node, alertPlugins dismisseds = [a.message_id for a in Alert.objects.filter(node=alert_node(), dismiss=True)] alerts = alertPlugins.get_alerts() return render(request, "freeadmin/alert_status.html", { 'alerts': alerts, 'dismisseds': dismisseds, })
def get_alerts(self): """ Temporary workaround to get alerts from legacy UI code """ rv = [] for alert in alertPlugins.get_alerts(): if alert.getDismiss(): continue rv.append(f'{alert.getLevel()} - {alert.getMessage()}') return '\n'.join(rv)
def alert_status(self, request): from freenasUI.system.models import Alert from freenasUI.system.alert import alert_node, alertPlugins dismisseds = [ a.message_id for a in Alert.objects.filter(node=alert_node()) ] alerts = alertPlugins.get_alerts() current = 'OK' for alert in alerts: # Skip dismissed alerts if alert.getId() in dismisseds: continue status = alert.getLevel() if ((status == 'WARN' and current == 'OK') or status == 'CRIT' and current in ('OK', 'WARN')): current = status return HttpResponse(current)