def done(self, request, form_list): data = {} for form in form_list: data.update(form.cleaned_data) # Send alert alert = Alert(sent_by = data['sent_by'], title = data['title'], details = data['details'], level = data['level'], ) if data['send_to'] == 'all': alert_userlist(alert, User.objects.all()) if data['send_to'] == 'group': alert_groups(alert, data['sent_to']) if data['send_to'] == 'user': alert.sent_to = data['sent_to'] alert.save() # Display success message and redirect to changelist: return self._model_admin.response_add(request, alert)
def done(self, request, form_list): data = {} for form in form_list: data.update(form.cleaned_data) # Send alert alert = Alert( sent_by=data['sent_by'], title=data['title'], details=data['details'], level=data['level'], ) if data['send_to'] == 'all': alert_userlist(alert, User.objects.all()) if data['send_to'] == 'group': alert_groups(alert, data['sent_to']) if data['send_to'] == 'user': alert.sent_to = data['sent_to'] alert.save() # Display success message and redirect to changelist: return self._model_admin.response_add(request, alert)
def push(request): """ data pushed by standalone python script (run by munin-limits) """ json_alerts = request.POST.get("alerts") if not json_alerts: return alerts = json.loads(json_alerts) opened_alerts = Alert.objects.filter(checked=False) for a in alerts: alert = Alert(host=a["host"], group=a["group"], category=a["category"], title=a["title"], value=a["value"], label=a["label"], atype=a["type"], arange=a["range"], ipaddr=a.get("ip", ""), extinfo=a["extinfo"]) for oa in opened_alerts: if oa == alert: oa.tick(alert) alert = None break if alert: alert.save() return HttpResponse(200, 'Good!')
def test_alert_body_change_to_null(self): u = User(username='******', password='******', email='*****@*****.**') u.save() a = Alert(user=u, body='this is a test message') a.save() a.body = '' self.assertEqual(a.body, '')
def test_alert_read_toggle_false(self): u = User(username='******', password='******', email='*****@*****.**') u.save() a = Alert(user=u, read=True) a.save() a.read = False self.assertEqual(a.read, False)
def _create_alert(self): """ Generates an Alert based on the Monitor's alert_level. Returns the saved Alert. """ title = self._get_title() alert = Alert(title=title, level=self.alert_level, alarm=self, distillery=self.last_active_distillery, doc_id=self.last_saved_doc) alert.save() return alert
def track_stories_from_session_data(self, user): story_id = self.request.session.get("wants_to_track", None) if story_id is not None: try: story = Story.objects.get(id=story_id) try: Alert.objects.get(story=story, user=user) # inform the user that he is already subscribed # to this story except Alert.DoesNotExist: new_alert = Alert(story=story, user=user) new_alert.save() except Story.DoesNotExist: pass self.request.session["wants_to_track"] = None
def testAlertCount(self): u = User(username='******', password='******', email='*****@*****.**') u.save() a = Alert(user=u) b = Alert(user=u) c = Alert(user=u) a.save() b.save() c.save() alerts_count = Alert.objects.all().count() self.assertEqual(alerts_count, 3)