]> arthur.barton.de Git - netdata.git/blob - python.d/python_modules/base.py
handling of debug interval
[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,freq=None):
26         if freq is None:
27             freq = self.update_every
28         now = time()
29         self.timetable = {'last' : now,
30                           'next' : now - (now % freq) + freq,
31                           'freq' : freq}
32
33
34     def error(self, msg, exception=""):
35         if exception != "":
36             exception = " " + str(exception).replace("\n"," ")
37         sys.stderr.write(str(msg)+exception+"\n")
38         sys.stderr.flush()
39
40     def check(self):
41         # TODO notify about not overriden function
42         self.error("Where is your check()?")
43         return False
44
45     def create(self):
46         # TODO notify about not overriden function
47         self.error("Where is your create()?")
48         return False
49
50     def update(self):
51         # TODO notify about not overriden function
52         self.error("Where is your update()?")
53         return False