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