]> arthur.barton.de Git - netdata.git/blob - python.d/python_modules/base.py
job creator in python.d.plugin
[netdata.git] / python.d / python_modules / base.py
1 # Description: base for netdata python.d plugins
2 # Author: Pawel Krupa (paulfantom)
3
4 from time import time
5
6
7 class BaseService(object):
8     def __init__(self,configuration=None):
9         if configuration is None:
10             # use defaults
11             self.error("BaseService: no configuration parameters supplied. Cannot create Service.")
12             raise RuntimeError
13         else:
14             self._extract_base_config(configuration)
15             self._create_timetable()
16             self.execution_name = ""
17
18     def _extract_base_config(self,config):
19         self.update_every = int(config['update_every'])
20         self.priority = int(config['priority'])
21         self.retries = int(config['retries'])
22         self.retries_left = self.retries
23
24     def _create_timetable(self):
25         now = time()
26         self.timetable = {'last' : now,
27                           'next' : now - (now % self.update_every) + self.update_every,
28                           'freq' : self.update_every}
29
30
31     def error(self, msg, exception=""):
32         if exception != "":
33             exception = " " + str(exception).replace("\n"," ")
34         sys.stderr.write(str(msg)+exception+"\n")
35         sys.stderr.flush()
36
37     def check(self):
38         # TODO notify about not overriden function
39         self.error("Where is your check()?")
40         return False
41
42     def create(self):
43         # TODO notify about not overriden function
44         self.error("Where is your create()?")
45         return False
46
47     def update(self):
48         # TODO notify about not overriden function
49         self.error("Where is your update()?")
50         return False