From 2b504289ea663cf3e49805b8b5086d964f577694 Mon Sep 17 00:00:00 2001 From: Geno Date: Wed, 28 Jul 2021 14:50:33 +0200 Subject: [PATCH] add api default values + rename host to url --- api/client.go | 10 ++++++---- api/request.go | 2 +- api/response_lists.go | 13 +++++++++++++ config_example.toml | 2 +- contrib/oven-exporter.service | 12 ++++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 contrib/oven-exporter.service diff --git a/api/client.go b/api/client.go index c9d6995..147b9bc 100644 --- a/api/client.go +++ b/api/client.go @@ -4,14 +4,16 @@ import "encoding/base64" // A Client for the API type Client struct { - Token string `toml:"token"` - Host string `toml:"host"` + Token string `toml:"token"` + URL string `toml:"url"` + DefaultVHost string `toml:"default_vhost"` + DefaultApp string `toml:"default_app"` } // New Client from host and token -func New(host, token string) *Client { +func New(url, token string) *Client { c := &Client{ - Host: host, + URL: url, } c.SetToken(token) return c diff --git a/api/request.go b/api/request.go index bcbd839..b1a0c77 100644 --- a/api/request.go +++ b/api/request.go @@ -12,7 +12,7 @@ func (c *Client) Request(url string, value interface{}) error { netClient := &http.Client{ Timeout: time.Second * 20, } - req, err := http.NewRequest(http.MethodGet, c.Host+url, nil) + req, err := http.NewRequest(http.MethodGet, c.URL+url, nil) if err != nil { return err } diff --git a/api/response_lists.go b/api/response_lists.go index 1cce419..75f23a7 100644 --- a/api/response_lists.go +++ b/api/response_lists.go @@ -16,6 +16,7 @@ type ResponseList struct { Data []string `json:"response,omitempty"` } +// RequestListVHosts to get list of vhosts func (c *Client) RequestListVHosts() (*ResponseList, error) { req := ResponseList{} url := fmt.Sprintf(URLRequestListVHost) @@ -25,6 +26,7 @@ func (c *Client) RequestListVHosts() (*ResponseList, error) { return &req, nil } +// RequestListApps to get list of apps on given vhost func (c *Client) RequestListApps(vhost string) (*ResponseList, error) { req := ResponseList{} url := fmt.Sprintf(URLRequestListApp, vhost) @@ -34,6 +36,12 @@ func (c *Client) RequestListApps(vhost string) (*ResponseList, error) { return &req, nil } +// RequestDefaultListApps to get list of apps on default vhost +func (c *Client) RequestDefaultListApps() (*ResponseList, error) { + return c.RequestListApps(c.DefaultVHost) +} + +// RequestDefaultListStreams to get list of streams on given vhost and app func (c *Client) RequestListStreams(vhost, app string) (*ResponseList, error) { req := ResponseList{} url := fmt.Sprintf(URLRequestListStream, vhost, app) @@ -42,3 +50,8 @@ func (c *Client) RequestListStreams(vhost, app string) (*ResponseList, error) { } return &req, nil } + +// RequestDefaultListStreams to get list of streams on default vhost and app +func (c *Client) RequestDefaultListStreams() (*ResponseList, error) { + return c.RequestListStreams(c.DefaultVHost, c.DefaultApp) +} diff --git a/config_example.toml b/config_example.toml index 36620ae..4bc9f5f 100644 --- a/config_example.toml +++ b/config_example.toml @@ -1,6 +1,6 @@ listen = ":8080" [api] -host = "http://1.2.3.4:8081" +url = "http://1.2.3.4:8081" token = "ome-access-token" diff --git a/contrib/oven-exporter.service b/contrib/oven-exporter.service new file mode 100644 index 0000000..e965848 --- /dev/null +++ b/contrib/oven-exporter.service @@ -0,0 +1,12 @@ +[Unit] +Description = Prometheus exporter for OvenMediaEngine + +[Service] +Type=simple +ExecStart=/usr/local/bin/oven-exporter -c /etc/ovenmediaengine/exporter.conf +Restart=always +RestartSec=5s +Environment=PATH=/usr/bin:/usr/local/bin + +[Install] +WantedBy=multi-user.target