Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/oceanbench/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ type BroadcastConfig struct {
VoltageRecoveryTimeout int // Max allowable hours for voltage recovery before failure.
RegisterOpenFish bool // True if the video should be registered with openfish for annotation.
OpenFishCaptureSource string // The capture source to register the stream to.
NotifySuppressRules string // Suppression rules for notifications.
}

func (b *BroadcastConfig) PrettyHardwareStateData() string {
Expand Down Expand Up @@ -230,6 +231,7 @@ func broadcastHandler(w http.ResponseWriter, r *http.Request) {
RegisterOpenFish: r.FormValue("register-openfish") == "register-openfish",
OpenFishCaptureSource: r.FormValue("openfish-capturesource"),
BatteryVoltagePin: r.FormValue("battery-voltage-pin"),
NotifySuppressRules: r.FormValue("notify-suppress-rules"),
},
Action: r.FormValue("action"),
ListingSecondaries: r.FormValue("list-secondaries") == "listing-secondaries",
Expand Down
2 changes: 1 addition & 1 deletion cmd/oceanbench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import (
)

const (
version = "v0.31.5"
version = "v0.32.0"
localSite = "localhost"
localDevice = "localdevice"
localEmail = "localuser@localhost"
Expand Down
4 changes: 4 additions & 0 deletions cmd/oceanbench/t/broadcast.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ <h2 class="advanced pt-5">Advanced Settings</h2>
<label for="openfish-capturesource" class="advanced w-25 text-end">OpenFish Capture Source:</label>
<input class="advanced w-50 form-control" type="input" name="openfish-capturesource" value="{{.CurrentBroadcast.OpenFishCaptureSource}}" />
</div>
<div class="d-flex align-items-center gap-1 mb-1">
<label for="notify-suppress-rules" class="advanced w-25 text-end">Notification Suppression Rules:</label>
<input class="advanced w-50 form-control" type="input" name="notify-suppress-rules" value="{{.CurrentBroadcast.NotifySuppressRules}}" />
</div>
</fieldset>
<input type="hidden" name="broadcast-id" value="{{.CurrentBroadcast.ID}}" />
<input type="hidden" name="active" value="{{.CurrentBroadcast.Active}}" />
Expand Down
1 change: 1 addition & 0 deletions cmd/oceantv/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type BroadcastConfig struct {
VoltageRecoveryTimeout int // Max allowable hours for voltage recovery before failure.
RegisterOpenFish bool // True if the video should be registered with openfish for annotation.
OpenFishCaptureSource string // The capture source to register the stream to.
NotifySuppressRules string // Suppression rules for notifications.
}

func (b *BroadcastConfig) PrettyHardwareStateData() string {
Expand Down
3 changes: 2 additions & 1 deletion cmd/oceantv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (

const (
projectID = "oceantv"
version = "v0.9.3"
version = "v0.10.0"
projectURL = "https://oceantv.appspot.com"
cronServiceAccount = "oceancron@appspot.gserviceaccount.com"
locationID = "Australia/Adelaide" // TODO: Use site location.
Expand Down Expand Up @@ -429,6 +429,7 @@ func broadcastHandler(w http.ResponseWriter, r *http.Request) {
_cfg.RegisterOpenFish = cfg.RegisterOpenFish
_cfg.OpenFishCaptureSource = cfg.OpenFishCaptureSource
_cfg.BatteryVoltagePin = cfg.BatteryVoltagePin
_cfg.NotifySuppressRules = cfg.NotifySuppressRules

// Values that are parsed into floats from their form values.
_cfg.RequiredStreamingVoltage = cfg.RequiredStreamingVoltage
Expand Down
45 changes: 43 additions & 2 deletions cmd/oceantv/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package main

import (
"context"
"encoding/json"
"errors"
"fmt"
"log"
"strings"
"time"

"github.com/ausocean/cloud/cmd/oceantv/broadcast"
Expand Down Expand Up @@ -140,10 +142,49 @@ func newBroadcastSystem(ctx context.Context, store Store, cfg *BroadcastConfig,
broadcastContext := &broadcastContext{cfg, man, store, svc, NewVidforwardService(log), bus, &revidCameraClient{}, logOutput, nil}

// Subscribe event handler that notifies on events that implement errorEvent.
// Suppress if they satisfy the notification suppression rules.
bus.subscribe(func(event event) error {
if errEvent, ok := event.(errorEvent); ok {
broadcastContext.logAndNotify(errEvent.Kind(), "error event: %s", errEvent.Error())
if _, ok := event.(errorEvent); !ok {
return nil
}

errEvent := event.(errorEvent)

// Unmarshal the notification suppression rules from the broadcast configuration.
// It is of format:
// {
// "SuppressKinds": ["broadcast-kind1" , "broadcast-kind2"],
// "SuppressContaining": ["shutdown failed", "failed to start"]
// }
suppressionRules := &struct {
SuppressKinds []string
SuppressContaining []string
}{}

// Completely empty string indicates no suppression rules.
if cfg.NotifySuppressRules != "" {
err := json.Unmarshal([]byte(cfg.NotifySuppressRules), suppressionRules)
if err != nil {
broadcastContext.logAndNotify(errEvent.Kind(), "could not unmarshal notification suppression rules: %v", err)
return nil
}
}

for _, kind := range suppressionRules.SuppressKinds {
if notify.Kind(kind) == errEvent.Kind() {
broadcastContext.log("error event: %s", errEvent.Error())
return nil
}
}

for _, cont := range suppressionRules.SuppressContaining {
if strings.Contains(errEvent.Error(), cont) {
broadcastContext.log("error event: %s", errEvent.Error())
return nil
}
}

broadcastContext.logAndNotify(errEvent.Kind(), "error event: %s", errEvent.Error())
return nil
})

Expand Down
Loading