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
19 if configuration is None:
20 self.error("BaseService: no configuration parameters supplied. Cannot create Service.")
23 self._extract_base_config(configuration)
25 self.create_timetable()
26 self.execution_name = ""
28 def _extract_base_config(self, config):
30 Get basic parameters to run service
32 config = {'update_every':1,
37 self.update_every = int(config['update_every'])
38 self.priority = int(config['priority'])
39 self.retries = int(config['retries'])
40 self.retries_left = self.retries
42 def create_timetable(self, freq=None):
44 Create service timetable.
47 timetable = {'last': 1466370091.3767564,
53 freq = self.update_every
55 self.timetable = {'last': now,
56 'next': now - (now % freq) + freq,
60 def error(msg, exception=""):
62 exception = " " + str(exception).replace("\n"," ")
63 sys.stderr.write(str(msg)+exception+"\n")
71 self.error("Service " + str(self.__name__) + "doesn't implement check() function")
79 self.error("Service " + str(self.__name__) + "doesn't implement create() function?")
87 self.error("Service " + str(self.__name__) + "doesn't implement update() function")