BOSWatch 3
Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG
 
Loading...
Searching...
No Matches
plugin.pluginBase.PluginBase Class Reference

Main plugin class. More...

Public Member Functions

def __init__ (self, pluginName, config)
 init preload some needed locals and then call onLoad() directly
 
def onLoad (self)
 Called by import of the plugin can be inherited.
 
def setup (self)
 Called before alarm can be inherited.
 
def fms (self, bwPacket)
 Called on FMS alarm can be inherited.
 
def pocsag (self, bwPacket)
 Called on POCSAG alarm can be inherited.
 
def zvei (self, bwPacket)
 Called on ZVEI alarm can be inherited.
 
def msg (self, bwPacket)
 Called on MSG packet can be inherited.
 
def teardown (self)
 Called after alarm can be inherited.
 
def onUnload (self)
 Called on shutdown of boswatch can be inherited.
 
def parseWildcards (self, msg)
 Return the message with parsed wildcards.
 

Data Fields

 config
 

Protected Member Functions

def _cleanup (self)
 Cleanup routine calls onUnload() directly.
 
def _run (self, bwPacket)
 start an complete running turn of an plugin.
 
def _getStatistics (self)
 Returns statistical information's from last plugin run.
 

Protected Attributes

 _pluginName
 
 _bwPacket
 
 _sumTime
 
 _cumTime
 
 _setupTime
 
 _alarmTime
 
 _teardownTime
 
 _runCount
 
 _setupErrorCount
 
 _alarmErrorCount
 
 _teardownErrorCount
 

Static Protected Attributes

list _pluginsActive = []
 

Detailed Description

Main plugin class.

Constructor & Destructor Documentation

◆ __init__()

def plugin.pluginBase.PluginBase.__init__ (   self,
  pluginName,
  config 
)

init preload some needed locals and then call onLoad() directly

Reimplemented in plugin.divera.BoswatchPlugin, plugin.http.BoswatchPlugin, plugin.mysql.BoswatchPlugin, plugin.telegram.BoswatchPlugin, and plugin.template_plugin.BoswatchPlugin.

31 def __init__(self, pluginName, config):
32 r"""!init preload some needed locals and then call onLoad() directly"""
33 self._pluginName = pluginName
34 self.config = config
35 self._pluginsActive.append(self)
36
37 # to save the packet while alarm is running for other functions
38 self._bwPacket = None
39
40 # for time counting
41 self._sumTime = 0
42 self._cumTime = 0
43 self._setupTime = 0
44 self._alarmTime = 0
45 self._teardownTime = 0
46
47 # for statistics
48 self._runCount = 0
49 self._setupErrorCount = 0
50 self._alarmErrorCount = 0
51 self._teardownErrorCount = 0
52
53 logging.debug("[%s] onLoad()", pluginName)
54 self.onLoad()
55

Member Function Documentation

◆ _cleanup()

def plugin.pluginBase.PluginBase._cleanup (   self)
protected

Cleanup routine calls onUnload() directly.

56 def _cleanup(self):
57 r"""!Cleanup routine calls onUnload() directly"""
58 logging.debug("[%s] onUnload()", self._pluginName)
59 self._pluginsActive.remove(self)
60 self.onUnload()
61

◆ _run()

def plugin.pluginBase.PluginBase._run (   self,
  bwPacket 
)
protected

start an complete running turn of an plugin.

Calls setup(), alarm() and teardown() in this order. The alarm() method serves the BOSWatch packet to the plugin.

Parameters
bwPacketA BOSWatch packet instance
62 def _run(self, bwPacket):
63 r"""!start an complete running turn of an plugin.
64 Calls setup(), alarm() and teardown() in this order.
65 The alarm() method serves the BOSWatch packet to the plugin.
66
67 @param bwPacket: A BOSWatch packet instance"""
68 self._runCount += 1
69 logging.debug("[%s] run #%d", self._pluginName, self._runCount)
70
71 self._bwPacket = bwPacket
72
73 tmpTime = time.time()
74 try:
75 logging.debug("[%s] setup()", self._pluginName)
76 self.setup()
77 except:
78 self._setupErrorCount += 1
79 logging.exception("[%s] error in setup()", self._pluginName)
80
81 self._setupTime = time.time() - tmpTime
82 tmpTime = time.time()
83 try:
84
85 if bwPacket.get("mode") == "fms":
86 logging.debug("[%s] fms()", self._pluginName)
87 self.fms(bwPacket)
88 if bwPacket.get("mode") == "pocsag":
89 logging.debug("[%s] pocsag()", self._pluginName)
90 self.pocsag(bwPacket)
91 if bwPacket.get("mode") == "zvei":
92 logging.debug("[%s] zvei()", self._pluginName)
93 self.zvei(bwPacket)
94 if bwPacket.get("mode") == "msg":
95 logging.debug("[%s] msg()", self._pluginName)
96 self.msg(bwPacket)
97 except:
98 self._alarmErrorCount += 1
99 logging.exception("[%s] alarm error", self._pluginName)
100
101 self._alarmTime = time.time() - tmpTime
102 tmpTime = time.time()
103 try:
104 logging.debug("[%s] teardown()", self._pluginName)
105 self.teardown()
106 except:
107 self._teardownErrorCount += 1
108 logging.exception("[%s] error in teardown()", self._pluginName)
109
110 self._teardownTime = time.time() - tmpTime
111 self._sumTime = self._setupTime + self._alarmTime + self._teardownTime
112 self._cumTime += self._sumTime
113
114 self._bwPacket = None
115
116 logging.debug("[%s] took %0.3f seconds", self._pluginName, self._sumTime)
117 # logging.debug("- setup: %0.2f sec.", self._setupTime)
118 # logging.debug("- alarm: %0.2f sec.", self._alarmTime)
119 # logging.debug("- teardown: %0.2f sec.", self._teardownTime)
120
121 return None
122

◆ _getStatistics()

def plugin.pluginBase.PluginBase._getStatistics (   self)
protected

Returns statistical information's from last plugin run.

    @return Statistics as pyton dict
123 def _getStatistics(self):
124 r"""!Returns statistical information's from last plugin run
125
126 @return Statistics as pyton dict"""
127 stats = {"type": "plugin",
128 "runCount": self._runCount,
129 "sumTime": self._sumTime,
130 "cumTime": self._cumTime,
131 "setupTime": self._setupTime,
132 "alarmTime": self._alarmTime,
133 "teardownTime": self._teardownTime,
134 "setupErrorCount": self._setupErrorCount,
135 "alarmErrorCount": self._alarmErrorCount,
136 "teardownErrorCount": self._teardownErrorCount}
137 return stats
138

◆ onLoad()

def plugin.pluginBase.PluginBase.onLoad (   self)

Called by import of the plugin can be inherited.

Reimplemented in plugin.mysql.BoswatchPlugin, plugin.telegram.BoswatchPlugin, and plugin.template_plugin.BoswatchPlugin.

139 def onLoad(self):
140 r"""!Called by import of the plugin
141 can be inherited"""
142 pass
143

◆ setup()

def plugin.pluginBase.PluginBase.setup (   self)

Called before alarm can be inherited.

Reimplemented in plugin.mysql.BoswatchPlugin, and plugin.template_plugin.BoswatchPlugin.

144 def setup(self):
145 r"""!Called before alarm
146 can be inherited"""
147 pass
148

◆ fms()

def plugin.pluginBase.PluginBase.fms (   self,
  bwPacket 
)

Called on FMS alarm can be inherited.

Parameters
bwPacketbwPacket instance

Reimplemented in plugin.divera.BoswatchPlugin, plugin.http.BoswatchPlugin, plugin.mysql.BoswatchPlugin, plugin.telegram.BoswatchPlugin, and plugin.template_plugin.BoswatchPlugin.

149 def fms(self, bwPacket):
150 r"""!Called on FMS alarm
151 can be inherited
152
153 @param bwPacket: bwPacket instance"""
154 logging.warning("ZVEI not implemented in %s", self._pluginName)
155

◆ pocsag()

def plugin.pluginBase.PluginBase.pocsag (   self,
  bwPacket 
)

Called on POCSAG alarm can be inherited.

Parameters
bwPacketbwPacket instance

Reimplemented in plugin.divera.BoswatchPlugin, plugin.http.BoswatchPlugin, plugin.mysql.BoswatchPlugin, plugin.telegram.BoswatchPlugin, and plugin.template_plugin.BoswatchPlugin.

156 def pocsag(self, bwPacket):
157 r"""!Called on POCSAG alarm
158 can be inherited
159
160 @param bwPacket: bwPacket instance"""
161 logging.warning("POCSAG not implemented in %s", self._pluginName)
162

◆ zvei()

def plugin.pluginBase.PluginBase.zvei (   self,
  bwPacket 
)

Called on ZVEI alarm can be inherited.

Parameters
bwPacketbwPacket instance

Reimplemented in plugin.divera.BoswatchPlugin, plugin.http.BoswatchPlugin, plugin.mysql.BoswatchPlugin, plugin.telegram.BoswatchPlugin, and plugin.template_plugin.BoswatchPlugin.

163 def zvei(self, bwPacket):
164 r"""!Called on ZVEI alarm
165 can be inherited
166
167 @param bwPacket: bwPacket instance"""
168 logging.warning("ZVEI not implemented in %s", self._pluginName)
169

◆ msg()

def plugin.pluginBase.PluginBase.msg (   self,
  bwPacket 
)

Called on MSG packet can be inherited.

Parameters
bwPacketbwPacket instance

Reimplemented in plugin.divera.BoswatchPlugin, plugin.http.BoswatchPlugin, plugin.mysql.BoswatchPlugin, plugin.telegram.BoswatchPlugin, and plugin.template_plugin.BoswatchPlugin.

170 def msg(self, bwPacket):
171 r"""!Called on MSG packet
172 can be inherited
173
174 @param bwPacket: bwPacket instance"""
175 logging.warning("MSG not implemented in %s", self._pluginName)
176

◆ teardown()

def plugin.pluginBase.PluginBase.teardown (   self)

Called after alarm can be inherited.

Reimplemented in plugin.mysql.BoswatchPlugin, and plugin.template_plugin.BoswatchPlugin.

177 def teardown(self):
178 r"""!Called after alarm
179 can be inherited"""
180 pass
181

◆ onUnload()

def plugin.pluginBase.PluginBase.onUnload (   self)

Called on shutdown of boswatch can be inherited.

Reimplemented in plugin.mysql.BoswatchPlugin, and plugin.template_plugin.BoswatchPlugin.

182 def onUnload(self):
183 r"""!Called on shutdown of boswatch
184 can be inherited"""
185 pass
186

◆ parseWildcards()

def plugin.pluginBase.PluginBase.parseWildcards (   self,
  msg 
)

Return the message with parsed wildcards.

187 def parseWildcards(self, msg):
188 r"""!Return the message with parsed wildcards"""
189 if self._bwPacket is None:
190 logging.warning("wildcard replacing not allowed - no bwPacket set")
191 return msg
192 return wildcard.replaceWildcards(msg, self._bwPacket)

Field Documentation

◆ _pluginsActive

list plugin.pluginBase.PluginBase._pluginsActive = []
staticprotected

◆ _pluginName

plugin.pluginBase.PluginBase._pluginName
protected

◆ config

plugin.pluginBase.PluginBase.config

◆ _bwPacket

plugin.pluginBase.PluginBase._bwPacket
protected

◆ _sumTime

plugin.pluginBase.PluginBase._sumTime
protected

◆ _cumTime

plugin.pluginBase.PluginBase._cumTime
protected

◆ _setupTime

plugin.pluginBase.PluginBase._setupTime
protected

◆ _alarmTime

plugin.pluginBase.PluginBase._alarmTime
protected

◆ _teardownTime

plugin.pluginBase.PluginBase._teardownTime
protected

◆ _runCount

plugin.pluginBase.PluginBase._runCount
protected

◆ _setupErrorCount

plugin.pluginBase.PluginBase._setupErrorCount
protected

◆ _alarmErrorCount

plugin.pluginBase.PluginBase._alarmErrorCount
protected

◆ _teardownErrorCount

plugin.pluginBase.PluginBase._teardownErrorCount
protected