Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
|
db65d47ea9 | |
|
8c7ccf7e9f | |
|
0e4ee6fcf8 | |
|
1f47ca4ee6 | |
|
fefb874f95 | |
|
804f9a337c | |
|
8c6189b4b8 |
|
@ -1,7 +1,7 @@
|
|||
##
|
||||
# Compile application
|
||||
##
|
||||
FROM golang:alpine AS build-env
|
||||
FROM docker.io/library/golang:alpine AS build-env
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
# ge dependencies
|
|
@ -0,0 +1,59 @@
|
|||
== Oven-Exporter
|
||||
|
||||
An Prometheus Exporter for OvenMediaEngine
|
||||
|
||||
(it provides also a small API-Client for OvenMediaEngine) Be welcome to improve it.
|
||||
|
||||
=== Configure OvenMediaEngine
|
||||
|
||||
This Exporter use the REST-API of OvenMediaEngine, to setting it up, that a look in there Documentation https://airensoft.gitbook.io/ovenmediaengine/rest-api[OvenMediaEngine REST-API].
|
||||
|
||||
=== Setup Exporter
|
||||
|
||||
==== Compile
|
||||
|
||||
Install https://golang.org/doc/install[golang].
|
||||
|
||||
Run: `go install -v codeberg.org/Mediathek/oven-exporter@latest`
|
||||
|
||||
==== Configuration
|
||||
|
||||
Read comments in config_example.toml for more information.
|
||||
|
||||
Maybe a good place to store this file is: `/etc/ovenmediaengine/exporter.conf`
|
||||
|
||||
OR use env variables:
|
||||
|
||||
....
|
||||
OVEN_E_LISTEN=:8080
|
||||
OVEN_E_API__URL=http://1.2.3.4:8081
|
||||
OVEN_E_API__TOKEN=ome-access-token
|
||||
OVEN_E_API__DEFAULT_VHOST=
|
||||
OVEN_E_API__DEFAULT_APP=
|
||||
....
|
||||
|
||||
(File read could be disabled by call `oven-exporter -c ''`
|
||||
|
||||
==== Startup
|
||||
|
||||
Create a systemd.service file e.g. under `/etc/systemd/system/oven-exporter.service` with maybe a content like this:
|
||||
|
||||
[source,ini]
|
||||
----
|
||||
[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
|
||||
----
|
||||
|
||||
PS: maybe you need to adjust the binary path and configuration path.
|
||||
|
||||
Start and enable on boot: `systemctl enable --now oven-exporter.service`
|
58
README.md
58
README.md
|
@ -1,58 +0,0 @@
|
|||
# Oven-Exporter
|
||||
An Prometheus Exporter for OvenMediaEngine
|
||||
|
||||
(it provides also a small API-Client for OvenMediaEngine)
|
||||
Be welcome to improve it.
|
||||
|
||||
## Configure OvenMediaEngine
|
||||
|
||||
This Exporter use the REST-API of OvenMediaEngine,
|
||||
to setting it up, that a look in there Documentation [OvenMediaEngine REST-API](
|
||||
https://airensoft.gitbook.io/ovenmediaengine/rest-api).
|
||||
|
||||
## Setup Exporter
|
||||
|
||||
### Compile
|
||||
|
||||
Install [golang](https://golang.org/doc/install).
|
||||
|
||||
Run:
|
||||
`go install -v dev.sum7.eu/genofire/oven-exporter@latest`
|
||||
|
||||
### Configuration
|
||||
Read comments in [config_example.toml](config_example.toml) for more information.
|
||||
|
||||
Maybe a good place to store this file is: `/etc/ovenmediaengine/exporter.conf`
|
||||
|
||||
OR use env variables:
|
||||
```
|
||||
OVEN_E_LISTEN=:8080
|
||||
OVEN_E_API__URL=http://1.2.3.4:8081
|
||||
OVEN_E_API__TOKEN=ome-access-token
|
||||
OVEN_E_API__DEFAULT_VHOST=
|
||||
OVEN_E_API__DEFAULT_APP=
|
||||
```
|
||||
|
||||
(File read could be disabled by call `oven-exporter -c ''`
|
||||
|
||||
### Startup
|
||||
Create a systemd.service file e.g. under `/etc/systemd/system/oven-exporter.service` with maybe a content like this:
|
||||
|
||||
```ini
|
||||
[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
|
||||
```
|
||||
PS: maybe you need to adjust the binary path and configuration path.
|
||||
|
||||
Start and enable on boot:
|
||||
`systemctl enable --now oven-exporter.service`
|
|
@ -0,0 +1,9 @@
|
|||
name: oven-exporter
|
||||
title: Oven Exporter
|
||||
# use from git tag
|
||||
version:
|
||||
v(?<version>+({0..9}).+({0..9}).+({0..9})): $<version>
|
||||
main: latest
|
||||
|
||||
nav:
|
||||
- "modules/ROOT/nav.adoc"
|
|
@ -0,0 +1 @@
|
|||
../../../../README.adoc
|
18
go.mod
18
go.mod
|
@ -1,12 +1,16 @@
|
|||
module dev.sum7.eu/genofire/oven-exporter
|
||||
module codeberg.org/Mediathek/oven-exporter
|
||||
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/knadh/koanf v1.4.2
|
||||
github.com/prometheus/client_golang v1.10.0
|
||||
go.uber.org/multierr v1.5.0 // indirect
|
||||
go.uber.org/zap v1.13.0
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/knadh/koanf v1.5.0
|
||||
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||
github.com/prometheus/client_golang v1.17.0
|
||||
github.com/prometheus/client_model v0.5.0 // indirect
|
||||
github.com/prometheus/common v0.45.0 // indirect
|
||||
github.com/prometheus/procfs v0.12.0 // indirect
|
||||
github.com/stretchr/testify v1.8.4
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.26.0
|
||||
)
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type Policy struct {
|
||||
URLExpire int64 `json:"url_expire"`
|
||||
URLActivate int64 `json:"url_activate,omitempty"`
|
||||
StreamExpire int64 `json:"stream_expire,omitempty"`
|
||||
AllowIP string `json:"allow_ip,omitempty"`
|
||||
}
|
||||
|
||||
func (p Policy) Encode() (string, error) {
|
||||
str, err := json.Marshal(p)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return base64.RawStdEncoding.EncodeToString(str), nil
|
||||
}
|
||||
|
||||
func SignEncodedPolicy(u *url.URL, secretKey string) string {
|
||||
hasher := hmac.New(sha1.New, []byte(secretKey))
|
||||
hasher.Write([]byte(u.String()))
|
||||
return base64.RawURLEncoding.EncodeToString(hasher.Sum(nil))
|
||||
|
||||
}
|
||||
|
||||
func (p Policy) SignWithQuery(u *url.URL, secretKey, encodeQuery string) (string, error) {
|
||||
encode, err := p.Encode()
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
query := u.Query()
|
||||
query.Add(encodeQuery, encode)
|
||||
u.RawQuery = query.Encode()
|
||||
return SignEncodedPolicy(u, secretKey), nil
|
||||
}
|
||||
func (p Policy) Sign(u *url.URL, secretKey string) (string, error) {
|
||||
return p.SignWithQuery(u, secretKey, "policy")
|
||||
}
|
||||
|
||||
func (p Policy) SignURLWithQuery(u *url.URL, secretKey, encodeQuery, signatureQuery string) error {
|
||||
encode, err := p.Encode()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
query := u.Query()
|
||||
query.Add(encodeQuery, encode)
|
||||
u.RawQuery = query.Encode()
|
||||
|
||||
signature := SignEncodedPolicy(u, secretKey)
|
||||
query.Add(signatureQuery, signature)
|
||||
u.RawQuery = query.Encode()
|
||||
return nil
|
||||
}
|
||||
func (p Policy) SignURL(u *url.URL, secretKey string) error {
|
||||
return p.SignURLWithQuery(u, secretKey, "policy", "signature")
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
// https://airensoft.gitbook.io/ovenmediaengine/access-control/signedpolicy
|
||||
package helper
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const (
|
||||
examplePolicyEncode = "eyJ1cmxfZXhwaXJlIjoxMzk5NzIxNTgxfQ"
|
||||
exampleSecretKey = "1kU^b6"
|
||||
exampleURL = "ws://192.168.0.100:3333/app/stream"
|
||||
exampleSignature = "dvVdBpoxAeCPl94Kt5RoiqLI0YE"
|
||||
exampleURLWithSignatureAndPolicy = "ws://192.168.0.100/app/stream?policy=eyJ1cmxfZXhwaXJlIjoxMzk5NzIxNTgxfQ&signature=dvVdBpoxAeCPl94Kt5RoiqLI0YE"
|
||||
)
|
||||
|
||||
var (
|
||||
examplePolicy = Policy{
|
||||
URLExpire: 1399721581,
|
||||
}
|
||||
)
|
||||
|
||||
func TestPolicyEncode(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
encode, err := examplePolicy.Encode()
|
||||
assert.NoError(err)
|
||||
assert.Equal(examplePolicyEncode, encode)
|
||||
}
|
||||
|
||||
func TestPolicySign(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
u, err := url.Parse(exampleURL)
|
||||
assert.NoError(err)
|
||||
|
||||
sign, err := examplePolicy.Sign(u, exampleSecretKey)
|
||||
assert.NoError(err)
|
||||
assert.Equal(exampleSignature, sign)
|
||||
}
|
||||
|
||||
func TestPolicySignURL(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
u, err := url.Parse(exampleURL)
|
||||
assert.NoError(err)
|
||||
|
||||
err = examplePolicy.SignURL(u, exampleSecretKey)
|
||||
assert.NoError(err)
|
||||
|
||||
// drop port -> is not part of example
|
||||
u.Host = u.Hostname()
|
||||
|
||||
assert.Equal(exampleURLWithSignatureAndPolicy, u.String())
|
||||
}
|
2
main.go
2
main.go
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"dev.sum7.eu/genofire/oven-exporter/api"
|
||||
"codeberg.org/Mediathek/oven-exporter/api"
|
||||
)
|
||||
|
||||
var configExtParser = map[string]koanf.Parser{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"dev.sum7.eu/genofire/oven-exporter/api"
|
||||
"codeberg.org/Mediathek/oven-exporter/api"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue