fix: add validation for state_descr in sensor readings
Added validation to ensure state_descr: - Is not empty when present (min: 1 character) - Has reasonable length limit (max: 255 characters) - Prevents storing invalid/malformed state descriptions This prevents invalid state sensor readings from being stored. Fixes Medium Bug #16 from reliability audit.
This commit is contained in:
parent
a230f1bfb5
commit
ba79c6da6b
1 changed files with 6 additions and 0 deletions
|
|
@ -41,6 +41,12 @@ defmodule Towerops.Snmp.SensorReading do
|
|||
|> cast(attrs, [:sensor_id, :value, :status, :state_descr, :checked_at])
|
||||
|> validate_required([:sensor_id, :status, :checked_at])
|
||||
|> validate_inclusion(:status, ["ok", "warning", "critical", "error"])
|
||||
|> validate_state_descr()
|
||||
|> foreign_key_constraint(:sensor_id)
|
||||
end
|
||||
|
||||
# Validate state_descr when present - ensure it's not empty and has reasonable length
|
||||
defp validate_state_descr(changeset) do
|
||||
validate_length(changeset, :state_descr, min: 1, max: 255)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue