@cryptotaxi247 / netdata-1 / commits / d98457d5d

Use bundled YAML parser for unbound plugin.

This also tidies up the auto-configuration support so it's a bit more robust and provides sane defaults if the specified Unbound configuration is bogus.

Austin S. Hemmelgarn committed May 2, 2018 at 08:46 UTC d98457d5df96b04b65e5cbe4247001ee5bfe6900
1 file changed +14 -11
python.d/unbound.chart.py
+14 -11
@@ -3,9 +3,9 @@
3 # Author: Austin S. Hemmelgarn (Ferroin)
4
5 import os
6 -import yaml
6
7 from bases.FrameworkServices.SocketService import SocketService
8 +from bases.loaders import YamlOrderedLoader
9
10 PRECISION = 1000
11
@@ -94,7 +94,7 @@ class Service(SocketService):
94 self.port = 8935
95 SocketService.__init__(self, configuration, name)
96 self.ext = self.configuration.get('extended', None)
97 - self.ubconf = self.configuration.get('ubconf', '/etc/unbound/unbound.conf')
97 + self.ubconf = self.configuration.get('ubconf', None)
98 self.order = ORDER
99 self.definitions = CHARTS
100 if self.ext:
@@ -117,25 +117,28 @@ class Service(SocketService):
117 self.definitions[key]['options'][4] = self.host
118
119 def _auto_config(self):
120 - if os.access(self.ubconf, os.R_OK):
121 - with open(self.ubconf, 'r') as ubconf:
122 - try:
123 - conf = yaml.load(ubconf)
124 - except yaml.YAMLError:
125 - conf = dict()
120 + if self.ubconf and os.access(self.ubconf, os.R_OK):
121 + conf = YamlOrderedLoader.load_config_from_file(self.ubconf)[0]
122 if self.ext is None:
123 if 'extended-statistics' in conf['server'].keys():
124 self.ext = conf['server']['extended-statistics']
125 if 'remote-control' in conf.keys():
126 if conf['remote-control'].get('control-use-cert', False):
127 if not self.key:
132 - self.key = conf['remote-control'].get('control-key-file', '/etc/unbound/unbound_control.key')
128 + self.key = conf['remote-control'].get('control-key-file')
129 if not self.cert:
134 - self.cert = conf['remote-control'].get('control-cert-file', '/etc/unbound/unbound_control.pem')
135 - self.port = conf['remote-control'].get('control-port', 8953)
130 + self.cert = conf['remote-control'].get('control-cert-file')
131 + if not self.port:
132 + self.port = conf['remote-control'].get('control-port')
133 else:
134 if not self.unix_socket:
135 self.unix_socket = conf['remote-control'].get('control-interface')
136 + if not self.key:
137 + self.key = '/etc/unbound/unbound_control.key'
138 + if not self.cert:
139 + self.cert = '/etc/unbound/unbound_control.pem'
140 + if not self.port:
141 + self.port = 8953
142
143 def check(self):
144 # We need to check that auth works, otherwise there's no point.