Files
links/nginxmon/forms.py
T
2026-04-01 21:33:07 +11:00

59 lines
1.6 KiB
Python

from django import forms
from .models import NginxSettings, NginxAlertProfile
class NginxSettingsForm(forms.ModelForm):
class Meta:
model = NginxSettings
fields = [
'namespace',
'pod_label',
'container',
'fetch_interval_seconds',
'log_file_path',
'enabled',
'excluded_ips',
'auto_ban_enabled',
'auto_ban_threshold',
'auto_ban_window_hours',
]
widgets = {
'excluded_ips': forms.Textarea(attrs={
'rows': 4,
'placeholder': '192.168.1.218\n192.168.1.x\n192.168.1.0/24',
'class': 'font-mono text-xs',
}),
}
class NginxAlertProfileForm(forms.ModelForm):
class Meta:
model = NginxAlertProfile
fields = [
'name',
'alert_window_seconds',
'alert_max_requests',
'alert_max_error_rate',
'alert_min_requests',
'telegram_bot_token',
'telegram_chat_id',
'enabled',
]
widgets = {
'telegram_bot_token': forms.PasswordInput(render_value=True),
}
help_texts = {
'alert_max_error_rate': 'Value between 0 and 1, e.g. 0.6 = 60% errors.',
}
class PasteLogsForm(forms.Form):
log_text = forms.CharField(
widget=forms.Textarea(attrs={
'rows': 10,
'placeholder': 'Paste raw nginx ingress log lines here…',
'class': 'font-mono text-xs',
}),
label='Raw log lines',
)