add api default values + rename host to url

This commit is contained in:
Geno 2021-07-28 14:50:33 +02:00
parent 4425e3323f
commit 2b504289ea
5 changed files with 33 additions and 6 deletions

View File

@ -5,13 +5,15 @@ import "encoding/base64"
// A Client for the API // A Client for the API
type Client struct { type Client struct {
Token string `toml:"token"` Token string `toml:"token"`
Host string `toml:"host"` URL string `toml:"url"`
DefaultVHost string `toml:"default_vhost"`
DefaultApp string `toml:"default_app"`
} }
// New Client from host and token // New Client from host and token
func New(host, token string) *Client { func New(url, token string) *Client {
c := &Client{ c := &Client{
Host: host, URL: url,
} }
c.SetToken(token) c.SetToken(token)
return c return c

View File

@ -12,7 +12,7 @@ func (c *Client) Request(url string, value interface{}) error {
netClient := &http.Client{ netClient := &http.Client{
Timeout: time.Second * 20, 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 { if err != nil {
return err return err
} }

View File

@ -16,6 +16,7 @@ type ResponseList struct {
Data []string `json:"response,omitempty"` Data []string `json:"response,omitempty"`
} }
// RequestListVHosts to get list of vhosts
func (c *Client) RequestListVHosts() (*ResponseList, error) { func (c *Client) RequestListVHosts() (*ResponseList, error) {
req := ResponseList{} req := ResponseList{}
url := fmt.Sprintf(URLRequestListVHost) url := fmt.Sprintf(URLRequestListVHost)
@ -25,6 +26,7 @@ func (c *Client) RequestListVHosts() (*ResponseList, error) {
return &req, nil return &req, nil
} }
// RequestListApps to get list of apps on given vhost
func (c *Client) RequestListApps(vhost string) (*ResponseList, error) { func (c *Client) RequestListApps(vhost string) (*ResponseList, error) {
req := ResponseList{} req := ResponseList{}
url := fmt.Sprintf(URLRequestListApp, vhost) url := fmt.Sprintf(URLRequestListApp, vhost)
@ -34,6 +36,12 @@ func (c *Client) RequestListApps(vhost string) (*ResponseList, error) {
return &req, nil 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) { func (c *Client) RequestListStreams(vhost, app string) (*ResponseList, error) {
req := ResponseList{} req := ResponseList{}
url := fmt.Sprintf(URLRequestListStream, vhost, app) url := fmt.Sprintf(URLRequestListStream, vhost, app)
@ -42,3 +50,8 @@ func (c *Client) RequestListStreams(vhost, app string) (*ResponseList, error) {
} }
return &req, nil 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)
}

View File

@ -1,6 +1,6 @@
listen = ":8080" listen = ":8080"
[api] [api]
host = "http://1.2.3.4:8081" url = "http://1.2.3.4:8081"
token = "ome-access-token" token = "ome-access-token"

View File

@ -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