Compare commits

..

1 Commits

Author SHA1 Message Date
Jan Zípek 7a659cc044
NTFY integration 2026-04-11 20:02:08 +02:00
2 changed files with 3 additions and 16 deletions

View File

@ -61,7 +61,7 @@ func unitToSeconds(unit string) float64 {
} }
func (s *AlertsEvaluatorService) EvaluateAlert(alert *models.AlertItem) error { func (s *AlertsEvaluatorService) EvaluateAlert(alert *models.AlertItem) error {
condition := map[string]any{} condition := map[string]interface{}{}
err := json.Unmarshal([]byte(alert.Condition), &condition) err := json.Unmarshal([]byte(alert.Condition), &condition)
if err != nil { if err != nil {
return err return err
@ -86,7 +86,7 @@ func (s *AlertsEvaluatorService) EvaluateAlert(alert *models.AlertItem) error {
sensorId = int64(sensorValueCondition.SensorId) sensorId = int64(sensorValueCondition.SensorId)
value, err := s.ctx.Services.SensorValues.GetLatestToNow(sensorValueCondition.SensorId) value, err := s.ctx.Services.SensorValues.GetLatest(sensorValueCondition.SensorId, time.Now().Unix())
if err != nil { if err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
lastValue = float64(0) lastValue = float64(0)
@ -112,7 +112,7 @@ func (s *AlertsEvaluatorService) EvaluateAlert(alert *models.AlertItem) error {
sensorId = sensorLastContactCondition.SensorId sensorId = sensorLastContactCondition.SensorId
value, err := s.ctx.Services.SensorValues.GetLatestToNow(sensorLastContactCondition.SensorId) value, err := s.ctx.Services.SensorValues.GetLatest(sensorLastContactCondition.SensorId, time.Now().Unix())
if err != nil { if err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {

View File

@ -48,19 +48,6 @@ func (s *SensorValuesService) GetLatest(sensorId int64, to int64) (*sensorValue,
return &value, nil return &value, nil
} }
func (s *SensorValuesService) GetLatestToNow(sensorId int64) (*sensorValue, error) {
var value = sensorValue{}
row := s.ctx.DB.QueryRow("SELECT timestamp, value FROM sensor_values WHERE sensor_id = ? ORDER BY timestamp DESC LIMIT 1", sensorId)
err := row.Scan(&value.Timestamp, &value.Value)
if err != nil {
return nil, err
}
return &value, nil
}
func (s *SensorValuesService) Cleanup(retentionInDays int64) error { func (s *SensorValuesService) Cleanup(retentionInDays int64) error {
if retentionInDays <= 0 { if retentionInDays <= 0 {
return fmt.Errorf("retentionInDays must be greater than 0") return fmt.Errorf("retentionInDays must be greater than 0")