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['update_every'])
40 self.priority = int(config['priority'])
41 self.retries = int(config['retries'])
42 self.retries_left = self.retries
44 def create_timetable(self, freq=None):
46 Create service timetable.
49 timetable = {'last': 1466370091.3767564,
55 freq = self.update_every
57 self.timetable = {'last': now,
58 'next': now - (now % freq) + freq,
62 def error(msg, exception=""):
64 exception = " " + str(exception).replace("\n"," ")
65 sys.stderr.write(str(msg)+exception+"\n")
73 self.error("Service " + str(self.__name__) + "doesn't implement check() function")
81 self.error("Service " + str(self.__name__) + "doesn't implement create() function?")
89 self.error("Service " + str(self.__name__) + "doesn't implement update() function")