]> arthur.barton.de Git - netdata.git/blob - python.d/python_modules/base.py
service inheritance
[netdata.git] / python.d / python_modules / base.py
1 # Description: base for netdata python.d plugins
2 # Author: Pawel Krupa (paulfantom)
3
4 class BaseService(object):
5     def __init__(self,configuration,update_every,priority,retries):
6         if configuration is None:
7             # use defaults
8             configuration = config
9             self.error(NAME+": no configuration supplied. using defaults.")
10
11         self._parse_base_config(configuration)
12
13     def _parse_base_config(self,config,update_every,priority,retries):
14         # parse configuration options to run this Service
15         try:
16             self.update_every = int(config['update_every'])
17         except (KeyError, ValueError):
18             self.update_every = update_every
19         try:
20             self.priority = int(config['priority'])
21         except (KeyError, ValueError):
22             self.priority = priority
23         try:
24             self.retries = int(config['retries'])
25         except (KeyError, ValueError):
26             self.retries = retries
27         self.retries_left = self.retries
28
29     def error(self, msg, exception=""):
30         if exception != "":
31             exception = " " + str(exception).replace("\n"," ")
32         sys.stderr.write(str(msg)+exception+"\n")
33         sys.stderr.flush()
34
35     def check(self):
36         # TODO notify about not overriden function
37         self.error("Where is your check()?")
38         return False
39
40     def create(self):
41         # TODO notify about not overriden function
42         self.error("Where is your create()?")
43         return False
44
45     def update(self):
46         # TODO notify about not overriden function
47         self.error("Where is your update()?")
48         return False