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

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

Data Fields

 config
 

Protected Member Functions

 _cleanup (self)
 Cleanup routine calls onUnload() directly.
 
 _run (self, bwPacket)
 start an complete running turn of an plugin.
 
 _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__()

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()

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()

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
69 # --- FIX: Multicast list support ---
70 if isinstance(bwPacket, list):
71 # if we got a list of packets, we have to run each packet through the complete alarm process (Setup -> Alarm -> Teardown)
72 for single_packet in bwPacket:
73 self._run(single_packet)
74 return None
75 # ---------------------------------------------------------------------
76
77 self._runCount += 1
78 logging.debug("[%s] run #%d", self._pluginName, self._runCount)
79
80 self._bwPacket = bwPacket
81
82 tmpTime = time.time()
83 try:
84 logging.debug("[%s] setup()", self._pluginName)
85 self.setup()
86 except:
87 self._setupErrorCount += 1
88 logging.exception("[%s] error in setup()", self._pluginName)
89
90 self._setupTime = time.time() - tmpTime
91 tmpTime = time.time()
92 try:
93
94 if bwPacket.get("mode") == "fms":
95 logging.debug("[%s] fms()", self._pluginName)
96 self.fms(bwPacket)
97 if bwPacket.get("mode") == "pocsag":
98 logging.debug("[%s] pocsag()", self._pluginName)
99 self.pocsag(bwPacket)
100 if bwPacket.get("mode") == "zvei":
101 logging.debug("[%s] zvei()", self._pluginName)
102 self.zvei(bwPacket)
103 if bwPacket.get("mode") == "msg":
104 logging.debug("[%s] msg()", self._pluginName)
105 self.msg(bwPacket)
106 except:
107 self._alarmErrorCount += 1
108 logging.exception("[%s] alarm error", self._pluginName)
109
110 self._alarmTime = time.time() - tmpTime
111 tmpTime = time.time()
112 try:
113 logging.debug("[%s] teardown()", self._pluginName)
114 self.teardown()
115 except:
116 self._teardownErrorCount += 1
117 logging.exception("[%s] error in teardown()", self._pluginName)
118
119 self._teardownTime = time.time() - tmpTime
120 self._sumTime = self._setupTime + self._alarmTime + self._teardownTime
121 self._cumTime += self._sumTime
122
123 self._bwPacket = None
124
125 logging.debug("[%s] took %0.3f seconds", self._pluginName, self._sumTime)
126 # logging.debug("- setup: %0.2f sec.", self._setupTime)
127 # logging.debug("- alarm: %0.2f sec.", self._alarmTime)
128 # logging.debug("- teardown: %0.2f sec.", self._teardownTime)
129
130 return None
131

◆ _getStatistics()

plugin.pluginBase.PluginBase._getStatistics (   self)
protected

Returns statistical information's from last plugin run.

Returns
Statistics as pyton dict
132 def _getStatistics(self):
133 r"""!Returns statistical information's from last plugin run
134
135 @return Statistics as pyton dict"""
136 stats = {"type": "plugin",
137 "runCount": self._runCount,
138 "sumTime": self._sumTime,
139 "cumTime": self._cumTime,
140 "setupTime": self._setupTime,
141 "alarmTime": self._alarmTime,
142 "teardownTime": self._teardownTime,
143 "setupErrorCount": self._setupErrorCount,
144 "alarmErrorCount": self._alarmErrorCount,
145 "teardownErrorCount": self._teardownErrorCount}
146 return stats
147

◆ onLoad()

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.

148 def onLoad(self):
149 r"""!Called by import of the plugin
150 can be inherited"""
151 pass
152

◆ setup()

plugin.pluginBase.PluginBase.setup (   self)

Called before alarm can be inherited.

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

153 def setup(self):
154 r"""!Called before alarm
155 can be inherited"""
156 pass
157

◆ fms()

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.

158 def fms(self, bwPacket):
159 r"""!Called on FMS alarm
160 can be inherited
161
162 @param bwPacket: bwPacket instance"""
163 logging.warning("ZVEI not implemented in %s", self._pluginName)
164

◆ pocsag()

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.

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

◆ zvei()

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.

172 def zvei(self, bwPacket):
173 r"""!Called on ZVEI alarm
174 can be inherited
175
176 @param bwPacket: bwPacket instance"""
177 logging.warning("ZVEI not implemented in %s", self._pluginName)
178

◆ msg()

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.

179 def msg(self, bwPacket):
180 r"""!Called on MSG packet
181 can be inherited
182
183 @param bwPacket: bwPacket instance"""
184 logging.warning("MSG not implemented in %s", self._pluginName)
185

◆ teardown()

plugin.pluginBase.PluginBase.teardown (   self)

Called after alarm can be inherited.

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

186 def teardown(self):
187 r"""!Called after alarm
188 can be inherited"""
189 pass
190

◆ onUnload()

plugin.pluginBase.PluginBase.onUnload (   self)

Called on shutdown of boswatch can be inherited.

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

191 def onUnload(self):
192 r"""!Called on shutdown of boswatch
193 can be inherited"""
194 pass
195

◆ parseWildcards()

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

Return the message with parsed wildcards.

196 def parseWildcards(self, msg):
197 r"""!Return the message with parsed wildcards"""
198 if self._bwPacket is None:
199 logging.warning("wildcard replacing not allowed - no bwPacket set")
200 return msg
201 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