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