1 # -*- coding: utf-8 -*-
2 # Description: base for netdata python.d plugins
3 # Author: Pawel Krupa (paulfantom)
9 class BaseService(object):
11 Prototype of Service class.
12 Implemented basic functionality to run jobs by `python.d.plugin`
14 def __init__(self, configuration=None, name=None):
16 This needs to be initialized in child classes
17 :param configuration: dict
21 if configuration is None:
22 self.error("BaseService: no configuration parameters supplied. Cannot create Service.")
25 self._extract_base_config(configuration)
27 self.create_timetable()
30 def _extract_base_config(self, config):
32 Get basic parameters to run service
34 config = {'update_every':1,
39 self.update_every = int(config.pop('update_every'))
40 self.priority = int(config.pop('priority'))
41 self.retries = int(config.pop('retries'))
42 self.retries_left = self.retries
43 self.configuration = config
45 def create_timetable(self, freq=None):
47 Create service timetable.
50 timetable = {'last': 1466370091.3767564,
56 freq = self.update_every
58 self.timetable = {'last': now,
59 'next': now - (now % freq) + freq,
63 def error(msg, exception=""):
65 exception = " " + str(exception).replace("\n"," ")
66 sys.stderr.write(str(msg)+exception+"\n")
74 self.error("Service " + str(self.__name__) + "doesn't implement check() function")
82 self.error("Service " + str(self.__name__) + "doesn't implement create() function?")
90 self.error("Service " + str(self.__name__) + "doesn't implement update() function")