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

Description of the Plugin. More...

Public Member Functions

def __init__ (self, config)
 Do not change anything here!
 
def onLoad (self)
 Called by import of the plugin Remove if not implemented.
 
def setup (self)
 Called before alarm Remove if not implemented.
 
def fms (self, bwPacket)
 Called on FMS alarm.
 
def pocsag (self, bwPacket)
 Called on POCSAG alarm.
 
def zvei (self, bwPacket)
 Called on ZVEI alarm.
 
def msg (self, bwPacket)
 Called on MSG packet.
 
def teardown (self)
 Called after alarm Remove if not implemented.
 
def onUnload (self)
 Called by destruction of the plugin Remove if not implemented.
 
- Public Member Functions inherited from plugin.pluginBase.PluginBase
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

 sqlInserts
 
 connection
 
 cursor
 
- Data Fields inherited from plugin.pluginBase.PluginBase
 config
 

Additional Inherited Members

- Protected Member Functions inherited from plugin.pluginBase.PluginBase
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 inherited from plugin.pluginBase.PluginBase
 _pluginName
 
 _bwPacket
 
 _sumTime
 
 _cumTime
 
 _setupTime
 
 _alarmTime
 
 _teardownTime
 
 _runCount
 
 _setupErrorCount
 
 _alarmErrorCount
 
 _teardownErrorCount
 
- Static Protected Attributes inherited from plugin.pluginBase.PluginBase
list _pluginsActive = []
 

Detailed Description

Description of the Plugin.

Constructor & Destructor Documentation

◆ __init__()

def plugin.mysql.BoswatchPlugin.__init__ (   self,
  config 
)

Do not change anything here!

Reimplemented from plugin.pluginBase.PluginBase.

33 def __init__(self, config):
34 r"""!Do not change anything here!"""
35 super().__init__(__name__, config) # you can access the config class on 'self.config'
36

Member Function Documentation

◆ onLoad()

def plugin.mysql.BoswatchPlugin.onLoad (   self)

Called by import of the plugin Remove if not implemented.

Reimplemented from plugin.pluginBase.PluginBase.

37 def onLoad(self):
38 r"""!Called by import of the plugin
39 Remove if not implemented"""
40 self.sqlInserts = {
41 "pocsag": "INSERT INTO boswatch (packetTimestamp, packetMode, pocsag_ric, pocsag_subric, pocsag_subricText, pocsag_message, pocsag_bitrate, serverName, serverVersion, serverBuildDate, serverBranch, clientName, clientIP, clientVersion, clientBuildDate, clientBranch, inputSource, frequency) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
42 "zvei": "INSERT INTO boswatch (packetTimestamp, packetMode, zvei_tone, serverName, serverVersion, serverBuildDate, serverBranch, clientName, clientIP, clientVersion, clientBuildDate, clientBranch, inputSource, frequency) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
43 "fms": "INSERT INTO boswatch (packetTimestamp, packetMode, fms_fms, fms_service, fms_country, fms_location, fms_vehicle, fms_status, fms_direction, fms_directionText, fms_tacticalInfo, serverName, serverVersion, serverBuildDate, serverBranch, clientName, clientIP, clientVersion, clientBuildDate, clientBranch, inputSource, frequency) VALUE (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
44 "msg": "INSERT INTO boswatch (packetTimestamp, packetMode, serverName, serverVersion, serverBuildDate, serverBranch, clientName, clientIP, clientVersion, clientBuildDate, clientBranch, inputSource, frequency) VALUE (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
45 }
46
47 self.connection = mysql.connector.connect(
48 host=self.config.get("host"),
49 user=self.config.get("user"),
50 password=self.config.get("password"),
51 database=self.config.get("database"),
52 )
53
54 self.cursor = self.connection.cursor()
55 self.cursor.execute("SHOW TABLES LIKE 'boswatch'")
56
57 if self.cursor.fetchone() is None:
58 with open('init_db.sql') as f:
59 for stmnt in f.read().split(';'):
60 self.cursor.execute(stmnt)
61 self.connection.commit()
62
63 self.cursor.close()
64

◆ setup()

def plugin.mysql.BoswatchPlugin.setup (   self)

Called before alarm Remove if not implemented.

Reimplemented from plugin.pluginBase.PluginBase.

65 def setup(self):
66 r"""!Called before alarm
67 Remove if not implemented"""
68 try:
69 self.connection.ping(reconnect=True, attempts=3, delay=2)
70 except mysql.connector.Error:
71 logging.warning("Connection was down, trying to reconnect...")
72 self.onLoad()
73
74 self.cursor = self.connection.cursor()
75

◆ fms()

def plugin.mysql.BoswatchPlugin.fms (   self,
  bwPacket 
)

Called on FMS alarm.

    @param bwPacket: bwPacket instance
    Remove if not implemented

Reimplemented from plugin.pluginBase.PluginBase.

76 def fms(self, bwPacket):
77 r"""!Called on FMS alarm
78
79 @param bwPacket: bwPacket instance
80 Remove if not implemented"""
81 val = (
82 datetime.fromtimestamp(float(bwPacket.get("timestamp"))),
83 bwPacket.get("mode"),
84 bwPacket.get("fms"),
85 bwPacket.get("service"),
86 bwPacket.get("country"),
87 bwPacket.get("location"),
88 bwPacket.get("vehicle"),
89 bwPacket.get("status"),
90 bwPacket.get("direction"),
91 bwPacket.get("directionText"),
92 bwPacket.get("tacticalInfo"),
93 bwPacket.get("serverName"),
94 bwPacket.get("serverVersion"),
95 bwPacket.get("serverBuildDate"),
96 bwPacket.get("serverBranch"),
97 bwPacket.get("clientName"),
98 bwPacket.get("clientIP"),
99 bwPacket.get("clientVersion"),
100 bwPacket.get("clientBuildDate"),
101 bwPacket.get("clientBranch"),
102 bwPacket.get("inputSource"),
103 bwPacket.get("frequency")
104 )
105 self.cursor.execute(self.sqlInserts.get("fms"), val)
106

◆ pocsag()

def plugin.mysql.BoswatchPlugin.pocsag (   self,
  bwPacket 
)

Called on POCSAG alarm.

    @param bwPacket: bwPacket instance
    Remove if not implemented

Reimplemented from plugin.pluginBase.PluginBase.

107 def pocsag(self, bwPacket):
108 r"""!Called on POCSAG alarm
109
110 @param bwPacket: bwPacket instance
111 Remove if not implemented"""
112 val = (
113 datetime.fromtimestamp(float(bwPacket.get("timestamp"))),
114 bwPacket.get("mode"),
115 bwPacket.get("ric"),
116 bwPacket.get("subric"),
117 bwPacket.get("subricText"),
118 bwPacket.get("message"),
119 bwPacket.get("bitrate"),
120 bwPacket.get("serverName"),
121 bwPacket.get("serverVersion"),
122 bwPacket.get("serverBuildDate"),
123 bwPacket.get("serverBranch"),
124 bwPacket.get("clientName"),
125 bwPacket.get("clientIP"),
126 bwPacket.get("clientVersion"),
127 bwPacket.get("clientBuildDate"),
128 bwPacket.get("clientBranch"),
129 bwPacket.get("inputSource"),
130 bwPacket.get("frequency")
131 )
132 self.cursor.execute(self.sqlInserts.get("pocsag"), val)
133

◆ zvei()

def plugin.mysql.BoswatchPlugin.zvei (   self,
  bwPacket 
)

Called on ZVEI alarm.

    @param bwPacket: bwPacket instance
    Remove if not implemented

Reimplemented from plugin.pluginBase.PluginBase.

134 def zvei(self, bwPacket):
135 r"""!Called on ZVEI alarm
136
137 @param bwPacket: bwPacket instance
138 Remove if not implemented"""
139 val = (
140 datetime.fromtimestamp(float(bwPacket.get("timestamp"))),
141 bwPacket.get("mode"),
142 bwPacket.get("tone"),
143 bwPacket.get("serverName"),
144 bwPacket.get("serverVersion"),
145 bwPacket.get("serverBuildDate"),
146 bwPacket.get("serverBranch"),
147 bwPacket.get("clientName"),
148 bwPacket.get("clientIP"),
149 bwPacket.get("clientVersion"),
150 bwPacket.get("clientBuildDate"),
151 bwPacket.get("clientBranch"),
152 bwPacket.get("inputSource"),
153 bwPacket.get("frequency")
154 )
155 self.cursor.execute(self.sqlInserts.get("pocsag"), val)
156

◆ msg()

def plugin.mysql.BoswatchPlugin.msg (   self,
  bwPacket 
)

Called on MSG packet.

    @param bwPacket: bwPacket instance
    Remove if not implemented

Reimplemented from plugin.pluginBase.PluginBase.

157 def msg(self, bwPacket):
158 r"""!Called on MSG packet
159
160 @param bwPacket: bwPacket instance
161 Remove if not implemented"""
162 val = (
163 datetime.fromtimestamp(float(bwPacket.get("timestamp"))),
164 bwPacket.get("mode"),
165 bwPacket.get("serverName"),
166 bwPacket.get("serverVersion"),
167 bwPacket.get("serverBuildDate"),
168 bwPacket.get("serverBranch"),
169 bwPacket.get("clientName"),
170 bwPacket.get("clientIP"),
171 bwPacket.get("clientVersion"),
172 bwPacket.get("clientBuildDate"),
173 bwPacket.get("clientBranch"),
174 bwPacket.get("inputSource"),
175 bwPacket.get("frequency")
176 )
177 self.cursor.execute(self.sqlInserts.get("msg"), val)
178

◆ teardown()

def plugin.mysql.BoswatchPlugin.teardown (   self)

Called after alarm Remove if not implemented.

Reimplemented from plugin.pluginBase.PluginBase.

179 def teardown(self):
180 r"""!Called after alarm
181 Remove if not implemented"""
182 self.connection.commit()
183 self.cursor.close()
184

◆ onUnload()

def plugin.mysql.BoswatchPlugin.onUnload (   self)

Called by destruction of the plugin Remove if not implemented.

Reimplemented from plugin.pluginBase.PluginBase.

185 def onUnload(self):
186 r"""!Called by destruction of the plugin
187 Remove if not implemented"""
188 self.connection.close()

Field Documentation

◆ sqlInserts

plugin.mysql.BoswatchPlugin.sqlInserts

◆ connection

plugin.mysql.BoswatchPlugin.connection

◆ cursor

plugin.mysql.BoswatchPlugin.cursor