Compare commits
7 Commits
e38234b736
...
fd3478600f
Author | SHA1 | Date | |
---|---|---|---|
fd3478600f | |||
4d2991ba2f | |||
5aaaf57dd4 | |||
766b19e7c2 | |||
f660a6b49a | |||
ab0c1a5c46 | |||
74a6b5f2aa |
@ -60,3 +60,12 @@ Now we can simply use the InfluxDB as data source in Grafana and configure until
|
||||
beautiful plots!
|
||||
|
||||
.. image:: monitoring_grafana.png
|
||||
|
||||
Healthchecks
|
||||
------------
|
||||
|
||||
You can configure notfellchen to give a hourly ping to a healthchecks server. If this ping is not received, you will get notified and cna check why the celery jobs are no running.
|
||||
Add the following to your `notfellchen.cfg` and adjust the URL to match your check.
|
||||
.. code::
|
||||
[monitoring]
|
||||
healthchecks_url=https://health.example.org/ping/5fa7c9b2-753a-4cb3-bcc9-f982f5bc68e8
|
||||
|
@ -12,10 +12,7 @@ Notfellchen Plattform Dokumentation
|
||||
API/index.rst
|
||||
|
||||
.. image:: rtfm.png
|
||||
:name: RTFM by Elektroll
|
||||
:scale: 50 %
|
||||
:alt: Soviet style image of workers holding a sign with a gear and a screwdriver. Below is says "Read the manual"
|
||||
:name: Ratte lesend
|
||||
:alt: Zeichnung einer lesenden Ratte
|
||||
:align: center
|
||||
|
||||
|
||||
Read the manual, Image by `Mike Powell (CC-BY) <https://elektroll.art/>`_.
|
||||
|
BIN
docs/rtfm.png
BIN
docs/rtfm.png
Binary file not shown.
Before Width: | Height: | Size: 815 KiB After Width: | Height: | Size: 485 KiB |
@ -2,7 +2,7 @@ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
|
||||
from .models import User, Language, Text, ReportComment, ReportAdoptionNotice
|
||||
from .models import User, Language, Text, ReportComment, ReportAdoptionNotice, Log
|
||||
|
||||
from .models import Animal, Species, RescueOrganization, AdoptionNotice, Location, Rule, Image, ModerationAction, \
|
||||
Comment, Report, Announcement, AdoptionNoticeStatus, User, Subscriptions
|
||||
@ -62,3 +62,4 @@ admin.site.register(Text)
|
||||
admin.site.register(Announcement)
|
||||
admin.site.register(AdoptionNoticeStatus)
|
||||
admin.site.register(Subscriptions)
|
||||
admin.site.register(Log)
|
||||
|
@ -6,7 +6,7 @@ from .models import AdoptionNotice, Animal, Image, ReportAdoptionNotice, ReportC
|
||||
Comment
|
||||
from django_registration.forms import RegistrationForm
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field
|
||||
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field, Hidden
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from notfellchen.settings import MEDIA_URL
|
||||
|
||||
@ -142,8 +142,8 @@ class CommentForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_action = "comment"
|
||||
self.helper.form_class = 'form-comments'
|
||||
self.helper.add_input(Hidden('action', 'comment'))
|
||||
self.helper.add_input(Submit('submit', _('Kommentieren'), css_class="btn2"))
|
||||
|
||||
class Meta:
|
||||
|
25
src/fellchensammlung/migrations/0009_log.py
Normal file
25
src/fellchensammlung/migrations/0009_log.py
Normal file
@ -0,0 +1,25 @@
|
||||
# Generated by Django 5.1.1 on 2024-10-10 21:00
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('fellchensammlung', '0008_alter_adoptionnoticestatus_minor_status_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Log',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('action', models.CharField(max_length=255, verbose_name='Aktion')),
|
||||
('text', models.CharField(max_length=1000, verbose_name='Log text')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Nutzer*in')),
|
||||
],
|
||||
),
|
||||
]
|
@ -141,6 +141,7 @@ class Location(models.Model):
|
||||
instance.location = location
|
||||
instance.save()
|
||||
|
||||
|
||||
class RescueOrganization(models.Model):
|
||||
def __str__(self):
|
||||
return f"{self.name}"
|
||||
@ -161,7 +162,10 @@ class RescueOrganization(models.Model):
|
||||
|
||||
name = models.CharField(max_length=200)
|
||||
trusted = models.BooleanField(default=False, verbose_name=_('Vertrauenswürdig'))
|
||||
allows_using_materials = models.CharField(max_length=200,default=ALLOW_USE_MATERIALS_CHOICE[USE_MATERIALS_NOT_ASKED], choices=ALLOW_USE_MATERIALS_CHOICE, verbose_name=_('Erlaubt Nutzung von Inhalten'))
|
||||
allows_using_materials = models.CharField(max_length=200,
|
||||
default=ALLOW_USE_MATERIALS_CHOICE[USE_MATERIALS_NOT_ASKED],
|
||||
choices=ALLOW_USE_MATERIALS_CHOICE,
|
||||
verbose_name=_('Erlaubt Nutzung von Inhalten'))
|
||||
location_string = models.CharField(max_length=200, verbose_name=_("Ort der Organisation"))
|
||||
location = models.ForeignKey(Location, on_delete=models.PROTECT, blank=True, null=True)
|
||||
instagram = models.URLField(null=True, blank=True, verbose_name=_('Instagram Profil'))
|
||||
@ -540,7 +544,6 @@ class Text(models.Model):
|
||||
return expandable_dict
|
||||
|
||||
|
||||
|
||||
class Announcement(Text):
|
||||
"""
|
||||
Class to store announcements that should be displayed for all users
|
||||
@ -640,3 +643,16 @@ class Subscriptions(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.owner} - {self.adoption_notice}"
|
||||
|
||||
|
||||
class Log(models.Model):
|
||||
"""
|
||||
Basic class that allows logging random entries for later inspection
|
||||
"""
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_("Nutzer*in"))
|
||||
action = models.CharField(max_length=255, verbose_name=_("Aktion"))
|
||||
text = models.CharField(max_length=1000, verbose_name=_("Log text"))
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"[{self.action}] - {self.user} - {self.created_at.strftime('%H:%M:%S %d-%m-%Y ')}"
|
@ -1,5 +1,6 @@
|
||||
from notfellchen.celery import app as celery_app
|
||||
from .tools.admin import clean_locations, deactivate_unchecked_adoption_notices
|
||||
from .tools.misc import healthcheck_ok
|
||||
from .models import Location, AdoptionNotice
|
||||
|
||||
|
||||
@ -17,3 +18,7 @@ def task_deactivate_unchecked():
|
||||
def add_adoption_notice_location(pk):
|
||||
instance = AdoptionNotice.objects.get(pk=pk)
|
||||
Location.add_location_to_object(instance)
|
||||
|
||||
@celery_app.task(name="tools.healthcheck")
|
||||
def task_healthcheck():
|
||||
healthcheck_ok()
|
||||
|
@ -1,4 +1,8 @@
|
||||
import datetime as datetime
|
||||
import logging
|
||||
|
||||
from notfellchen import settings
|
||||
import requests
|
||||
|
||||
|
||||
def pluralize(number, letter="e"):
|
||||
@ -23,3 +27,10 @@ def age_as_hr_string(age: datetime.timedelta) -> str:
|
||||
return f'{weeks:.0f} Woche{pluralize(weeks, "n")}'
|
||||
else:
|
||||
return f'{days:.0f} Tag{pluralize(days)}'
|
||||
|
||||
|
||||
def healthcheck_ok():
|
||||
try:
|
||||
requests.get(settings.HEALTHCHECK_URL, timeout=10)
|
||||
except requests.RequestException as e:
|
||||
logging.error("Ping to healthcheck-server failed: %s" % e)
|
||||
|
@ -14,7 +14,7 @@ from notfellchen import settings
|
||||
from fellchensammlung import logger
|
||||
from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
|
||||
User, Location, AdoptionNoticeStatus, Subscriptions, CommentNotification, BaseNotification, RescueOrganization, \
|
||||
Species
|
||||
Species, Log
|
||||
from .forms import AdoptionNoticeForm, AdoptionNoticeFormWithDateWidget, ImageForm, ReportAdoptionNoticeForm, \
|
||||
CommentForm, ReportCommentForm, AnimalForm, \
|
||||
AdoptionNoticeSearchForm, AnimalFormWithDateWidget, AdoptionNoticeFormWithDateWidgetAutoAnimal
|
||||
@ -93,6 +93,10 @@ def adoption_notice_detail(request, adoption_notice_id):
|
||||
comment_instance.user = request.user
|
||||
comment_instance.save()
|
||||
|
||||
"""Log"""
|
||||
Log.objects.create(user=request.user, action="comment",
|
||||
text=f"{request.user} hat Kommentar {comment_instance.pk} zur Vermittlung {adoption_notice_id} hinzugefügt")
|
||||
|
||||
# Auto-subscribe user to adoption notice
|
||||
subscription, created = Subscriptions.objects.get_or_create(adoption_notice=adoption_notice,
|
||||
owner=request.user)
|
||||
@ -140,6 +144,9 @@ def adoption_notice_edit(request, adoption_notice_id):
|
||||
location = Location.get_location_from_string(adoption_notice_instance.location_string)
|
||||
adoption_notice_instance.location = location
|
||||
adoption_notice_instance.save()
|
||||
|
||||
"""Log"""
|
||||
Log.objects.create(user=request.user, action="adoption_notice_edit", text=f"{request.user} hat Vermittlung {adoption_notice.pk} geändert")
|
||||
return redirect(reverse("adoption-notice-detail", args=[adoption_notice_instance.pk], ))
|
||||
else:
|
||||
form = AdoptionNoticeForm(instance=adoption_notice)
|
||||
@ -216,6 +223,10 @@ def add_adoption_notice(request):
|
||||
Animal.objects.create(owner=request.user,
|
||||
name=f"{species} {i + 1}", adoption_notice=instance, species=species, sex=sex,
|
||||
date_of_birth=date_of_birth)
|
||||
|
||||
"""Log"""
|
||||
Log.objects.create(user=request.user, action="add_adoption_notice",
|
||||
text=f"{request.user} hat Vermittlung {instance.pk} hinzugefügt")
|
||||
return redirect(reverse("adoption-notice-detail", args=[instance.pk]))
|
||||
else:
|
||||
form = AdoptionNoticeFormWithDateWidgetAutoAnimal(in_adoption_notice_creation_flow=True)
|
||||
@ -260,6 +271,11 @@ def add_photo_to_animal(request, animal_id):
|
||||
instance.save()
|
||||
|
||||
animal.photos.add(instance)
|
||||
|
||||
"""Log"""
|
||||
Log.objects.create(user=request.user, action="add_photo_to_animal",
|
||||
text=f"{request.user} hat Foto {instance.pk} zum Tier {animal.pk} hinzugefügt")
|
||||
|
||||
if "save-and-add-another" in request.POST:
|
||||
form = ImageForm(in_flow=True)
|
||||
return render(request, 'fellchensammlung/forms/form-image.html', {'form': form})
|
||||
@ -283,6 +299,9 @@ def add_photo_to_adoption_notice(request, adoption_notice_id):
|
||||
instance.owner = request.user
|
||||
instance.save()
|
||||
adoption_notice.photos.add(instance)
|
||||
"""Log"""
|
||||
Log.objects.create(user=request.user, action="add_photo_to_animal",
|
||||
text=f"{request.user} hat Foto {instance.pk} zur Vermittlung {adoption_notice.pk} hinzugefügt")
|
||||
if "save-and-add-another" in request.POST:
|
||||
form = ImageForm(in_flow=True)
|
||||
return render(request, 'fellchensammlung/forms/form-image.html', {'form': form})
|
||||
@ -309,6 +328,10 @@ def animal_edit(request, animal_id):
|
||||
|
||||
if form.is_valid():
|
||||
animal = form.save()
|
||||
|
||||
"""Log"""
|
||||
Log.objects.create(user=request.user, action="add_photo_to_animal",
|
||||
text=f"{request.user} hat Tier {animal.pk} zum Tier geändert")
|
||||
return redirect(reverse("animal-detail", args=[animal.pk], ))
|
||||
else:
|
||||
form = AnimalForm(instance=animal)
|
||||
@ -429,6 +452,7 @@ def modqueue(request):
|
||||
|
||||
@login_required
|
||||
def updatequeue(request):
|
||||
#TODO: Make sure update can only be done for instances with permission
|
||||
if request.method == "POST":
|
||||
print(request.POST.get("adoption_notice_id"))
|
||||
adoption_notice = AdoptionNotice.objects.get(id=request.POST.get("adoption_notice_id"))
|
||||
|
@ -1,8 +1,7 @@
|
||||
# <your_project>/celery.py
|
||||
|
||||
import os
|
||||
from celery import Celery
|
||||
from celery.schedules import crontab
|
||||
from notfellchen import settings
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'notfellchen.settings')
|
||||
|
||||
@ -19,7 +18,12 @@ app.conf.beat_schedule = {
|
||||
},
|
||||
'daily-deactivation': {
|
||||
'task': 'admin.deactivate_unchecked',
|
||||
'schedule': 30,
|
||||
}
|
||||
'schedule': crontab(hour=1),
|
||||
},
|
||||
}
|
||||
|
||||
if settings.HEALTHCHECKS_URL is not None and settings.HEALTHCHECKS_URL != "":
|
||||
# If a healthcheck is configured, this will send an hourly ping to the healthchecks server
|
||||
app.conf.beat_schedule['hourly-healthcheck'] = {'task': 'tools.healthcheck',
|
||||
'schedule': crontab(minute=32),
|
||||
}
|
||||
|
@ -84,6 +84,8 @@ LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
|
||||
CELERY_BROKER_URL = config.get("celery", "broker", fallback="redis://localhost:6379/0")
|
||||
CELERY_RESULT_BACKEND = config.get("celery", "backend", fallback="redis://localhost:6379/0")
|
||||
|
||||
""" MONITORING """
|
||||
HEALTHCHECKS_URL = config.get("monitoring", "healthchecks_url", fallback=None)
|
||||
|
||||
""" GEOCODING """
|
||||
GEOCODING_API_URL = config.get("geocoding", "api_url", fallback="https://nominatim.hyteck.de/search")
|
||||
|
Loading…
Reference in New Issue
Block a user