1 # Description: base for netdata python.d plugins
2 # Author: Pawel Krupa (paulfantom)
8 class BaseService(object):
10 Prototype of Service class.
11 Implemented basic functionality to run jobs by `python.d.plugin`
13 def __init__(self, configuration=None, name=None):
15 This needs to be initialized in child classes
16 :param configuration: dict
20 if configuration is None:
21 self.error("BaseService: no configuration parameters supplied. Cannot create Service.")
24 self._extract_base_config(configuration)
26 self.create_timetable()
29 def _extract_base_config(self, config):
31 Get basic parameters to run service
33 config = {'update_every':1,
38 self.update_every = int(config['update_every'])
39 self.priority = int(config['priority'])
40 self.retries = int(config['retries'])
41 self.retries_left = self.retries
43 def create_timetable(self, freq=None):
45 Create service timetable.
48 timetable = {'last': 1466370091.3767564,
54 freq = self.update_every
56 self.timetable = {'last': now,
57 'next': now - (now % freq) + freq,
61 def error(msg, exception=""):
63 exception = " " + str(exception).replace("\n"," ")
64 sys.stderr.write(str(msg)+exception+"\n")
72 self.error("Service " + str(self.__name__) + "doesn't implement check() function")
80 self.error("Service " + str(self.__name__) + "doesn't implement create() function?")
88 self.error("Service " + str(self.__name__) + "doesn't implement update() function")