Skip to content

Commit ed68376

Browse files
authored
Allow custom path (#8)
1 parent 281c0ca commit ed68376

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

netdata/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import aiohttp
77
import async_timeout
8+
from yarl import URL
89

910
from . import exceptions
1011

1112
_LOGGER = logging.getLogger(__name__)
12-
_INSTANCE = "http://{host}:{port}/api/v{api}/"
1313
_DATA_ENDPOINT = "data?chart={resource}&before=0&after=-1&options=seconds"
1414
_ALARMS_ENDPOINT = "alarms?all&format=json"
1515
_ALL_METRIC_ENDPOINT = (
@@ -22,14 +22,18 @@
2222
class Netdata(object):
2323
"""A class for handling connections with a Netdata instance."""
2424

25-
def __init__(self, host, loop, session, port=19999):
25+
def __init__(self, host, loop, session, port=19999, path=None):
2626
"""Initialize the connection to the Netdata instance."""
2727
self._loop = loop
2828
self._session = session
2929
self.host = host
3030
self.port = port
3131
self.values = self.alarms = self.metrics = None
32-
self.base_url = _INSTANCE.format(host=host, port=port, api=API_VERSION)
32+
if path is None:
33+
self.base_url = URL.build(scheme="http", host=host, port=port, path=f"/api/v{API_VERSION}/")
34+
else:
35+
self.base_url = URL.build(scheme="http", host=host, port=port, path=path)
36+
3337

3438
async def get_data(self, resource):
3539
"""Get detail for a resource from the data endpoint."""

0 commit comments

Comments
 (0)