mirror of
https://github.com/onedr0p/exportarr.git
synced 2026-02-06 10:57:32 +00:00
* remove the branch requirement to run tests feature/support-bazarr * lint makefile feature/support-bazarr * add bazarr to readme feature/support-bazarr * also comment out release image as we only want tests to happen feature/support-bazarr * initial changes to start attempting to pull bazarr i thinnk? feature/support-bazarr * make it only run the tests, but skip release image feature/support-bazarr * add a genric makefile to build container localy, run and test feature/support-bazarr * rename build command feature/support-bazarr * add pic and grafana dashboard adjustments feature/support-bazarr * refactor metrics to just be contained within 1 class * add logic to allow csv values to params * remove some todos * make api version optional feature/support-bazarr * adjust makefile to auto kill and start feature/support-bazarr * remove now invalid test feature/support-bazarr * add a test for no api version instead feature/support-bazarr * add a test to enforce csv params moving forward feature/support-bazarr * add saml payloads for all endpoints, add test that mocks and verifies result feature/support-bazarr * Update .env.dist * Update .gitignore * Update internal/client/client.go * add a tidy task --------- Co-authored-by: Devin Buhl <onedr0p@users.noreply.github.com>
200 lines
4.9 KiB
Go
200 lines
4.9 KiB
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/onedr0p/exportarr/internal/arr/collector"
|
|
"github.com/onedr0p/exportarr/internal/arr/config"
|
|
)
|
|
|
|
func init() {
|
|
config.RegisterArrFlags(radarrCmd.PersistentFlags())
|
|
config.RegisterArrFlags(sonarrCmd.PersistentFlags())
|
|
config.RegisterArrFlags(lidarrCmd.PersistentFlags())
|
|
config.RegisterArrFlags(readarrCmd.PersistentFlags())
|
|
config.RegisterArrFlags(prowlarrCmd.PersistentFlags())
|
|
config.RegisterArrFlags(bazarrCmd.PersistentFlags())
|
|
config.RegisterProwlarrFlags(prowlarrCmd.PersistentFlags())
|
|
|
|
rootCmd.AddCommand(
|
|
radarrCmd,
|
|
sonarrCmd,
|
|
lidarrCmd,
|
|
readarrCmd,
|
|
bazarrCmd,
|
|
prowlarrCmd,
|
|
)
|
|
}
|
|
|
|
func UsageOnError(cmd *cobra.Command, err error) {
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
cmd.Usage()
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
var radarrCmd = &cobra.Command{
|
|
Use: "radarr",
|
|
Aliases: []string{"r"},
|
|
Short: "Prometheus Exporter for Radarr",
|
|
Long: "Prometheus Exporter for Radarr.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
c, err := config.LoadArrConfig(*conf, cmd.PersistentFlags())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.ApiVersion = "v3"
|
|
UsageOnError(cmd, c.Validate())
|
|
|
|
serveHttp(func(r prometheus.Registerer) {
|
|
r.MustRegister(
|
|
collector.NewRadarrCollector(c),
|
|
collector.NewQueueCollector(c),
|
|
collector.NewHistoryCollector(c),
|
|
collector.NewRootFolderCollector(c),
|
|
collector.NewSystemStatusCollector(c),
|
|
collector.NewSystemHealthCollector(c),
|
|
)
|
|
})
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var sonarrCmd = &cobra.Command{
|
|
Use: "sonarr",
|
|
Aliases: []string{"s"},
|
|
Short: "Prometheus Exporter for Sonarr",
|
|
Long: "Prometheus Exporter for Sonarr.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
c, err := config.LoadArrConfig(*conf, cmd.PersistentFlags())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.ApiVersion = "v3"
|
|
UsageOnError(cmd, c.Validate())
|
|
|
|
serveHttp(func(r prometheus.Registerer) {
|
|
r.MustRegister(
|
|
collector.NewSonarrCollector(c),
|
|
collector.NewQueueCollector(c),
|
|
collector.NewHistoryCollector(c),
|
|
collector.NewRootFolderCollector(c),
|
|
collector.NewSystemStatusCollector(c),
|
|
collector.NewSystemHealthCollector(c),
|
|
)
|
|
})
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var lidarrCmd = &cobra.Command{
|
|
Use: "lidarr",
|
|
Short: "Prometheus Exporter for Lidarr",
|
|
Long: "Prometheus Exporter for Lidarr.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
c, err := config.LoadArrConfig(*conf, cmd.PersistentFlags())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.ApiVersion = "v1"
|
|
UsageOnError(cmd, c.Validate())
|
|
|
|
serveHttp(func(r prometheus.Registerer) {
|
|
r.MustRegister(
|
|
collector.NewLidarrCollector(c),
|
|
collector.NewQueueCollector(c),
|
|
collector.NewHistoryCollector(c),
|
|
collector.NewRootFolderCollector(c),
|
|
collector.NewSystemStatusCollector(c),
|
|
collector.NewSystemHealthCollector(c),
|
|
)
|
|
})
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var readarrCmd = &cobra.Command{
|
|
Use: "readarr",
|
|
Aliases: []string{"b"},
|
|
Short: "Prometheus Exporter for Readarr",
|
|
Long: "Prometheus Exporter for Readarr.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
c, err := config.LoadArrConfig(*conf, cmd.PersistentFlags())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.ApiVersion = "v1"
|
|
UsageOnError(cmd, c.Validate())
|
|
|
|
serveHttp(func(r prometheus.Registerer) {
|
|
r.MustRegister(
|
|
collector.NewReadarrCollector(c),
|
|
collector.NewQueueCollector(c),
|
|
collector.NewHistoryCollector(c),
|
|
collector.NewRootFolderCollector(c),
|
|
collector.NewSystemStatusCollector(c),
|
|
collector.NewSystemHealthCollector(c),
|
|
)
|
|
})
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var bazarrCmd = &cobra.Command{
|
|
Use: "bazarr",
|
|
Aliases: []string{"b"},
|
|
Short: "Prometheus Exporter for Bazarr",
|
|
Long: "Prometheus Exporter for Bazarr.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
c, err := config.LoadArrConfig(*conf, cmd.PersistentFlags())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.ApiVersion = ""
|
|
UsageOnError(cmd, c.Validate())
|
|
|
|
serveHttp(func(r prometheus.Registerer) {
|
|
r.MustRegister(
|
|
collector.NewBazarrCollector(c),
|
|
)
|
|
})
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var prowlarrCmd = &cobra.Command{
|
|
Use: "prowlarr",
|
|
Aliases: []string{"p"},
|
|
Short: "Prometheus Exporter for Prowlarr",
|
|
Long: "Prometheus Exporter for Prowlarr.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
c, err := config.LoadArrConfig(*conf, cmd.PersistentFlags())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.ApiVersion = "v1"
|
|
c.LoadProwlarrConfig(cmd.PersistentFlags())
|
|
if err := c.Prowlarr.Validate(); err != nil {
|
|
return err
|
|
}
|
|
UsageOnError(cmd, c.Validate())
|
|
UsageOnError(cmd, c.Prowlarr.Validate())
|
|
|
|
serveHttp(func(r prometheus.Registerer) {
|
|
r.MustRegister(
|
|
collector.NewProwlarrCollector(c),
|
|
collector.NewHistoryCollector(c),
|
|
collector.NewSystemStatusCollector(c),
|
|
collector.NewSystemHealthCollector(c,
|
|
collector.NewUnavailableIndexerEmitter(c.URL)),
|
|
)
|
|
})
|
|
return nil
|
|
},
|
|
}
|