Merge branch 'yaml' into 'master'
yaml config See merge request sum7/ejabberd-metrics!4
This commit is contained in:
commit
1a3782ce97
|
@ -114,3 +114,4 @@ venv
|
|||
|
||||
# config
|
||||
config.json
|
||||
config.yml
|
||||
|
|
15
config.py
15
config.py
|
@ -1,20 +1,23 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
import sys
|
||||
from os import environ
|
||||
from pathlib import Path
|
||||
|
||||
from ruamel.yaml import YAML
|
||||
from ruamel.yaml.parser import ParserError
|
||||
from ruamel.yaml.scanner import ScannerError
|
||||
|
||||
|
||||
class Config:
|
||||
def __init__(self):
|
||||
# class variables
|
||||
self.content = None
|
||||
self.conf_file = Path('/etc/ejabberd-metrics.conf')
|
||||
self.conf_file = Path('/etc/ejabberd-metrics.yml')
|
||||
|
||||
# dev config overwrite
|
||||
if environ.get('ejabberd_metrics_dev'):
|
||||
self.conf_file = Path('config.json')
|
||||
self.conf_file = Path('config.yml')
|
||||
|
||||
# read config file
|
||||
self._read()
|
||||
|
@ -23,13 +26,13 @@ class Config:
|
|||
"""init the config object with this method"""
|
||||
self._check()
|
||||
|
||||
# open and load json content from config
|
||||
# open file as an iostream
|
||||
with open(self.conf_file, 'r', encoding='utf-8') as f:
|
||||
try:
|
||||
self.content = json.load(f)
|
||||
self.content = YAML(typ='safe').load(f)
|
||||
|
||||
# catch json decoding errors
|
||||
except json.JSONDecodeError as err:
|
||||
except (ParserError, ScannerError) as err:
|
||||
print(err, file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"url": "http://[::1]:5280/api",
|
||||
"login": {
|
||||
"user": "metric-user",
|
||||
"server": "chat.sum7.eu",
|
||||
"password": "password"
|
||||
},
|
||||
"api": "rest",
|
||||
|
||||
"--comment": "influxdb",
|
||||
"influxdb_host": "localhost",
|
||||
"influxdb_port": 8086,
|
||||
"influxdb_db": "ejabberd",
|
||||
|
||||
"--comment": "prometheus",
|
||||
"prometheus_port": 8080,
|
||||
"prometheus_refresh": 10
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
# endpoint url
|
||||
url: "http://[::1]:5280/api"
|
||||
|
||||
# user credentials to the endpoint url
|
||||
login:
|
||||
user: "metric-user"
|
||||
server: "chat.sum7.eu"
|
||||
password: "password"
|
||||
|
||||
# muc subdomain
|
||||
# default : "conference"
|
||||
muc_host: "chat"
|
||||
|
||||
# api configuration
|
||||
# default : rpc
|
||||
api: "rest"
|
||||
|
||||
# influx db configuration
|
||||
influxdb_host: "localhost"
|
||||
influxdb_port: 8086
|
||||
influxdb_db: "example"
|
||||
|
||||
# prometheus configuration
|
||||
prometheus_port: 8080
|
||||
prometheus_refresh: 10
|
Loading…
Reference in New Issue