Compare commits

..

No commits in common. "main" and "v0.1.0" have entirely different histories.
main ... v0.1.0

11 changed files with 281 additions and 1766 deletions

View File

@ -1,7 +1,7 @@
## ##
# Compile application # Compile application
## ##
FROM docker.io/library/golang:alpine AS build-env FROM golang:alpine AS build-env
WORKDIR /app WORKDIR /app
COPY . . COPY . .
# ge dependencies # ge dependencies

View File

@ -1,59 +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 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 Normal file
View File

@ -0,0 +1,58 @@
# 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`

View File

@ -1,9 +0,0 @@
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"

View File

@ -1 +0,0 @@
../../../../README.adoc

18
go.mod
View File

@ -1,16 +1,12 @@
module codeberg.org/Mediathek/oven-exporter module dev.sum7.eu/genofire/oven-exporter
go 1.16 go 1.16
require ( require (
github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/knadh/koanf v1.4.2
github.com/knadh/koanf v1.5.0 github.com/prometheus/client_golang v1.10.0
github.com/pelletier/go-toml v1.9.5 // indirect go.uber.org/multierr v1.5.0 // indirect
github.com/prometheus/client_golang v1.17.0 go.uber.org/zap v1.13.0
github.com/prometheus/client_model v0.5.0 // indirect golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
github.com/prometheus/common v0.45.0 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // 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
) )

1776
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -1,63 +0,0 @@
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")
}

View File

@ -1,57 +0,0 @@
// 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())
}

View File

@ -16,7 +16,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap" "go.uber.org/zap"
"codeberg.org/Mediathek/oven-exporter/api" "dev.sum7.eu/genofire/oven-exporter/api"
) )
var configExtParser = map[string]koanf.Parser{ var configExtParser = map[string]koanf.Parser{

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"codeberg.org/Mediathek/oven-exporter/api" "dev.sum7.eu/genofire/oven-exporter/api"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap" "go.uber.org/zap"
) )