mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
Merge branch 'develop' into feature/ISSUE-67
This commit is contained in:
commit
7cca892145
2
.github/workflows/run_pytest.yml
vendored
2
.github/workflows/run_pytest.yml
vendored
|
|
@ -8,7 +8,7 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest]
|
os: [ubuntu-latest]
|
||||||
python-version: [3.6, 3.7, 3.8, 3.9]
|
python-version: [3.7, 3.8, 3.9, 3.10.2]
|
||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ class SdrInput(InputBase):
|
||||||
sdrProc.addArgument("-p " + str(sdrConfig.get("error", default="0"))) # frequency error in ppm
|
sdrProc.addArgument("-p " + str(sdrConfig.get("error", default="0"))) # frequency error in ppm
|
||||||
sdrProc.addArgument("-l " + str(sdrConfig.get("squelch", default="1"))) # squelch
|
sdrProc.addArgument("-l " + str(sdrConfig.get("squelch", default="1"))) # squelch
|
||||||
sdrProc.addArgument("-g " + str(sdrConfig.get("gain", default="100"))) # gain
|
sdrProc.addArgument("-g " + str(sdrConfig.get("gain", default="100"))) # gain
|
||||||
|
if (sdrConfig.get("fir_size", default=None) is not None):
|
||||||
|
sdrProc.addArgument("-F " + str(sdrConfig.get("fir_size"))) # fir_size
|
||||||
sdrProc.addArgument("-M fm") # set mode to fm
|
sdrProc.addArgument("-M fm") # set mode to fm
|
||||||
sdrProc.addArgument("-E DC") # set DC filter
|
sdrProc.addArgument("-E DC") # set DC filter
|
||||||
sdrProc.addArgument("-s 22050") # bit rate of audio stream
|
sdrProc.addArgument("-s 22050") # bit rate of audio stream
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@ inputSource:
|
||||||
error: 0
|
error: 0
|
||||||
squelch: 1
|
squelch: 1
|
||||||
gain: 100
|
gain: 100
|
||||||
rtlPath: /usr/bin/rtl_fm
|
#fir_size: 0
|
||||||
|
rtlPath: /usr/local/bin/rtl_fm
|
||||||
lineIn:
|
lineIn:
|
||||||
card: 1
|
card: 1
|
||||||
device: 0
|
device: 0
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ Mit `PulseAudio` wird ein PulseAudio-Sink an Multimon-NG weitergereicht, z.B. in
|
||||||
|error|Frequenz Abweichung in ppm|0|
|
|error|Frequenz Abweichung in ppm|0|
|
||||||
|squelch|Einstellung der Rauschsperre|1|
|
|squelch|Einstellung der Rauschsperre|1|
|
||||||
|gain|Verstärkung des Eingangssignals|100|
|
|gain|Verstärkung des Eingangssignals|100|
|
||||||
|
|fir_size| niedrig leckagearmen Filter|None|
|
||||||
|rtlPath|Pfad zur rtl_fm Binary|rtl_fm|
|
|rtlPath|Pfad zur rtl_fm Binary|rtl_fm|
|
||||||
|
|
||||||
**Beispiel:**
|
**Beispiel:**
|
||||||
|
|
|
||||||
67
docu/docs/plugin/divera.md
Normal file
67
docu/docs/plugin/divera.md
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
# <center>Divera 24/7</center>
|
||||||
|
---
|
||||||
|
|
||||||
|
## Beschreibung
|
||||||
|
Mit diesem Plugin ist es möglich, HTTPS-Anfragen für Alarmierungen an Divera 24/7 zu senden.
|
||||||
|
Wildcards in den Urls werden automatisch ersetzt.
|
||||||
|
|
||||||
|
## Unterstütze Alarmtypen
|
||||||
|
- Fms
|
||||||
|
- Pocsag
|
||||||
|
- Zvei
|
||||||
|
- Msg
|
||||||
|
|
||||||
|
## Resource
|
||||||
|
`divera`
|
||||||
|
|
||||||
|
## Konfiguration
|
||||||
|
|Feld|Beschreibung|Default|
|
||||||
|
|----|------------|-------|
|
||||||
|
|accesskey|Web-API-Schlüssel von Divera24/7 ||
|
||||||
|
|priority|Sonderrechte|false|
|
||||||
|
|title| Titel der Meldung | s. Beispiel|
|
||||||
|
|message| Nachrichteninhalt| s. Beispiel|
|
||||||
|
|ric|Auszulösende RIC in Divera; Gruppen->Alarmierungs-RIC||
|
||||||
|
|vehicle|Fahrzeug-Alarmierungs-RIC||
|
||||||
|
|
||||||
|
**Beispiel:**
|
||||||
|
```yaml
|
||||||
|
- type: plugin
|
||||||
|
name: Divera Plugin
|
||||||
|
res: divera
|
||||||
|
config:
|
||||||
|
accesskey: API-Key
|
||||||
|
pocsag:
|
||||||
|
priority: false
|
||||||
|
title: "{RIC}({SRIC})\n{MSG}"
|
||||||
|
message: "{MSG}"
|
||||||
|
# RIC ist in Divera definiert
|
||||||
|
ric: Probealarm
|
||||||
|
fms:
|
||||||
|
priority: false
|
||||||
|
title: "{FMS}"
|
||||||
|
message: "{FMS}"
|
||||||
|
vehicle: MTF
|
||||||
|
zvei:
|
||||||
|
ric: Probealarm
|
||||||
|
title: "{TONE}"
|
||||||
|
message: "{TONE}"
|
||||||
|
priority: false
|
||||||
|
msg:
|
||||||
|
priority: false
|
||||||
|
title: "{MSG}"
|
||||||
|
message: "{MSG}"
|
||||||
|
# RIC ist in Divera definiert
|
||||||
|
ric: Probealarm
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
## Modul Abhängigkeiten
|
||||||
|
- keine
|
||||||
|
|
||||||
|
---
|
||||||
|
## Externe Abhängigkeiten
|
||||||
|
- asyncio
|
||||||
|
- aiohttp
|
||||||
|
- urllib
|
||||||
77
install.sh
77
install.sh
|
|
@ -37,17 +37,17 @@ function exitcodefunction {
|
||||||
module=$3
|
module=$3
|
||||||
|
|
||||||
if [ $errorcode -ne "0" ]; then
|
if [ $errorcode -ne "0" ]; then
|
||||||
echo "Action: $action on $module failed." >> $boswatchpath/install/setup_log.txt
|
echo "Action: ${action} on ${module} failed." >> ${boswatch_install_path}/setup_log.txt
|
||||||
echo "Exitcode: $errorcode" >> $boswatchpath/install/setup_log.txt
|
echo "Exitcode: ${errorcode}" >> ${boswatch_install_path}/setup_log.txt
|
||||||
echo ""
|
echo ""
|
||||||
echo "Action: $action on $module failed."
|
echo "Action: ${action} on ${module} failed."
|
||||||
echo "Exitcode: $errorcode"
|
echo "Exitcode: ${errorcode}"
|
||||||
echo ""
|
echo ""
|
||||||
echo " -> If you want to open an issue at https://github.com/BOSWatch/BW3-Core/issues"
|
echo " -> If you want to open an issue at https://github.com/BOSWatch/BW3-Core/issues"
|
||||||
echo " please post the logfile, located at $boswatchpath/install/setup_log.txt"
|
echo " please post the logfile, located at ${boswatch_install_path}/setup_log.txt"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "Action: $action on $module ok." >> $boswatchpath/install/setup_log.txt
|
echo "Action: ${action} on ${module} ok." >> ${boswatch_install_path}/setup_log.txt
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,6 +76,7 @@ echo "Caution, script does not install a webserver with PHP and MySQL"
|
||||||
echo "So you have to make up manually if you want to use MySQL support"
|
echo "So you have to make up manually if you want to use MySQL support"
|
||||||
|
|
||||||
boswatchpath=/opt/boswatch3
|
boswatchpath=/opt/boswatch3
|
||||||
|
boswatch_install_path=/opt/boswatch3_install
|
||||||
reboot=false
|
reboot=false
|
||||||
|
|
||||||
for (( i=1; i<=$#; i=$i+2 )); do
|
for (( i=1; i<=$#; i=$i+2 )); do
|
||||||
|
|
@ -83,11 +84,11 @@ for (( i=1; i<=$#; i=$i+2 )); do
|
||||||
eval arg=\$$i
|
eval arg=\$$i
|
||||||
eval arg2=\$$t
|
eval arg2=\$$t
|
||||||
|
|
||||||
case $arg in
|
case ${arg} in
|
||||||
-r|--reboot) reboot=true ;;
|
-r|--reboot) reboot=true ;;
|
||||||
|
|
||||||
-b|--branch)
|
-b|--branch)
|
||||||
case $arg2 in
|
case ${arg2} in
|
||||||
dev|develop) echo " !!! WARNING: you are using the DEV BRANCH !!! "; branch=dev ;;
|
dev|develop) echo " !!! WARNING: you are using the DEV BRANCH !!! "; branch=dev ;;
|
||||||
*) branch=master ;;
|
*) branch=master ;;
|
||||||
esac ;;
|
esac ;;
|
||||||
|
|
@ -98,8 +99,7 @@ for (( i=1; i<=$#; i=$i+2 )); do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
mkdir -p $boswatchpath
|
mkdir -p ${boswatchpath} ${boswatch_install_path}
|
||||||
mkdir -p $boswatchpath/install
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
|
@ -107,57 +107,58 @@ tput cup 13 15
|
||||||
echo "[ 1/9] [#--------]"
|
echo "[ 1/9] [#--------]"
|
||||||
tput cup 15 5
|
tput cup 15 5
|
||||||
echo "-> make an apt-get update................"
|
echo "-> make an apt-get update................"
|
||||||
apt-get update -y > $boswatchpath/install/setup_log.txt 2>&1
|
apt-get update -y > ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
|
|
||||||
tput cup 13 15
|
tput cup 13 15
|
||||||
echo "[ 2/9] [##-------]"
|
echo "[ 2/9] [##-------]"
|
||||||
tput cup 15 5
|
tput cup 15 5
|
||||||
echo "-> download GIT and other stuff.........."
|
echo "-> download GIT and other stuff.........."
|
||||||
apt-get -y install git cmake build-essential libusb-1.0 qt4-qmake qt4-default libpulse-dev libx11-dev sox >> $boswatchpath/install/setup_log.txt 2>&1
|
apt-get -y install git cmake build-essential libusb-1.0 qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qt5-default libpulse-dev libx11-dev sox >> ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
exitcodefunction $? download stuff
|
exitcodefunction $? download stuff
|
||||||
|
|
||||||
tput cup 13 15
|
tput cup 13 15
|
||||||
echo "[ 3/9] [###------]"
|
echo "[ 3/9] [###------]"
|
||||||
tput cup 15 5
|
tput cup 15 5
|
||||||
echo "-> download Python, Yaml and other stuff.."
|
echo "-> download Python, Yaml and other stuff.."
|
||||||
sudo apt-get -y install python3 python3-yaml >> $boswatchpath/install/setup_log.txt 2>&1
|
apt-get -y install python3 python3-yaml python3-pip alsa-utils>> ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
exitcodefunction $? download python
|
exitcodefunction $? download python
|
||||||
|
|
||||||
tput cup 13 15
|
tput cup 13 15
|
||||||
echo "[ 4/9] [####-----]"
|
echo "[ 4/9] [####-----]"
|
||||||
tput cup 15 5
|
tput cup 15 5
|
||||||
echo "-> download rtl_fm........................."
|
echo "-> download rtl_fm........................."
|
||||||
cd $boswatchpath/install
|
cd ${boswatch_install_path}
|
||||||
git clone --branch v0.5.4 https://github.com/osmocom/rtl-sdr.git rtl-sdr >> $boswatchpath/install/setup_log.txt 2>&1
|
git clone --branch master https://github.com/osmocom/rtl-sdr.git rtl-sdr >> ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
|
cd ${boswatch_install_path}/rtl-sdr/
|
||||||
|
git checkout 2659e2df31e592d74d6dd264a4f5ce242c6369c8
|
||||||
exitcodefunction $? git-clone rtl-sdr
|
exitcodefunction $? git-clone rtl-sdr
|
||||||
cd $boswatchpath/install/rtl-sdr/
|
|
||||||
|
|
||||||
tput cup 13 15
|
tput cup 13 15
|
||||||
echo "[ 5/9] [#####----]"
|
echo "[ 5/9] [#####----]"
|
||||||
tput cup 15 5
|
tput cup 15 5
|
||||||
echo "-> compile rtl_fm......................"
|
echo "-> compile rtl_fm......................"
|
||||||
mkdir -p build && cd build
|
mkdir -p build && cd build
|
||||||
cmake ../ -DINSTALL_UDEV_RULES=ON >> $boswatchpath/install/setup_log.txt 2>&1
|
cmake ../ -DINSTALL_UDEV_RULES=ON >> ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
exitcodefunction $? cmake rtl-sdr
|
exitcodefunction $? cmake rtl-sdr
|
||||||
|
|
||||||
make >> $boswatchpath/install/setup_log.txt 2>&1
|
make >> ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
exitcodefunction $? make rtl-sdr
|
exitcodefunction $? make rtl-sdr
|
||||||
|
|
||||||
make install >> $boswatchpath/install/setup_log.txt 2>&1
|
make install >> ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
exitcodefunction $? make-install rtl-sdr
|
exitcodefunction $? make-install rtl-sdr
|
||||||
|
|
||||||
ldconfig >> $boswatchpath/install/setup_log.txt 2>&1
|
ldconfig >> ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
exitcodefunction $? ldconfig rtl-sdr
|
exitcodefunction $? ldconfig rtl-sdr
|
||||||
|
|
||||||
tput cup 13 15
|
tput cup 13 15
|
||||||
echo "[ 6/9] [######---]"
|
echo "[ 6/9] [######---]"
|
||||||
tput cup 15 5
|
tput cup 15 5
|
||||||
echo "-> download multimon-ng................"
|
echo "-> download multimon-ng................"
|
||||||
cd $boswatchpath/install
|
cd ${boswatch_install_path}
|
||||||
git clone --branch 1.1.8 https://github.com/EliasOenal/multimon-ng.git multimonNG >> $boswatchpath/install/setup_log.txt 2>&1
|
git clone --branch 1.1.8 https://github.com/EliasOenal/multimon-ng.git multimonNG >> ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
exitcodefunction $? git-clone multimonNG
|
exitcodefunction $? git-clone multimonNG
|
||||||
|
|
||||||
cd $boswatchpath/install/multimonNG/
|
cd ${boswatch_install_path}/multimonNG/
|
||||||
|
|
||||||
tput cup 13 15
|
tput cup 13 15
|
||||||
echo "[ 7/9] [#######--]"
|
echo "[ 7/9] [#######--]"
|
||||||
|
|
@ -165,25 +166,24 @@ tput cup 15 5
|
||||||
echo "-> compile multimon-ng................."
|
echo "-> compile multimon-ng................."
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
cd build
|
cd build
|
||||||
qmake ../multimon-ng.pro >> $boswatchpath/install/setup_log.txt 2>&1
|
qmake -qt=qt5 ../multimon-ng.pro >> ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
exitcodefunction $? qmake multimonNG
|
exitcodefunction $? qmake multimonNG
|
||||||
|
|
||||||
make >> $boswatchpath/install/setup_log.txt 2>&1
|
make >> ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
exitcodefunction $? make multimonNG
|
exitcodefunction $? make multimonNG
|
||||||
|
|
||||||
make install >> $boswatchpath/install/setup_log.txt 2>&1
|
make install >> ${boswatch_install_path}/setup_log.txt 2>&1
|
||||||
exitcodefunction $? qmakeinstall multimonNG
|
exitcodefunction $? qmakeinstall multimonNG
|
||||||
|
|
||||||
tput cup 13 15
|
tput cup 13 15
|
||||||
echo "[ 8/9] [########-]"
|
echo "[ 8/9] [########-]"
|
||||||
tput cup 15 5
|
tput cup 15 5
|
||||||
echo "-> download BOSWatch3.................."
|
echo "-> download BOSWatch3.................."
|
||||||
cd $boswatchpath/
|
|
||||||
|
|
||||||
case $branch in
|
case ${branch} in
|
||||||
"dev") git clone -b develop https://github.com/BOSWatch/BW3-Core >> $boswatchpath/install/setup_log.txt 2>&1 && \
|
"dev") git clone -b develop https://github.com/BOSWatch/BW3-Core ${boswatchpath} >> ${boswatch_install_path}/setup_log.txt 2>&1 && \
|
||||||
exitcodefunction $? git-clone BW3-Core-develop ;;
|
exitcodefunction $? git-clone BW3-Core-develop ;;
|
||||||
*) git clone -b master https://github.com/BOSWatch/BW3-Core >> $boswatchpath/install/setup_log.txt 2>&1 && \
|
*) git clone -b master https://github.com/BOSWatch/BW3-Core ${boswatchpath} >> ${boswatch_install_path}/setup_log.txt 2>&1 && \
|
||||||
exitcodefunction $? git-clone BW3-Core ;;
|
exitcodefunction $? git-clone BW3-Core ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
@ -191,22 +191,22 @@ tput cup 13 15
|
||||||
echo "[9/9] [#########]"
|
echo "[9/9] [#########]"
|
||||||
tput cup 15 5
|
tput cup 15 5
|
||||||
echo "-> configure..........................."
|
echo "-> configure..........................."
|
||||||
cd $boswatchpath/
|
cd ${boswatchpath}/
|
||||||
chmod +x *
|
chmod +x *
|
||||||
echo $'# BOSWatch3 - blacklist the DVB drivers to avoid conflicts with the SDR driver\n blacklist dvb_usb_rtl28xxu \n blacklist rtl2830\n blacklist dvb_usb_v2\n blacklist dvb_core' >> /etc/modprobe.d/boswatch_blacklist_sdr.conf
|
echo $'# BOSWatch3 - blacklist the DVB drivers to avoid conflicts with the SDR driver\n blacklist dvb_usb_rtl28xxu \n blacklist rtl2830\n blacklist dvb_usb_v2\n blacklist dvb_core' >> /etc/modprobe.d/boswatch_blacklist_sdr.conf
|
||||||
|
|
||||||
tput cup 17 1
|
tput cup 17 1
|
||||||
tput rev # Schrift zur besseren lesbarkeit Revers
|
tput rev # Schrift zur besseren lesbarkeit Revers
|
||||||
echo "BOSWatch is now installed in $boswatchpath/ Installation ready!"
|
echo "BOSWatch is now installed in ${boswatchpath}/ Installation ready!"
|
||||||
tput sgr0 # Schrift wieder Normal
|
tput sgr0 # Schrift wieder Normal
|
||||||
tput cup 19 3
|
tput cup 19 3
|
||||||
echo "Watch out: to run BOSWatch3 you have to modify the server.yaml and client.yaml!"
|
echo "Watch out: to run BOSWatch3 you have to modify the server.yaml and client.yaml!"
|
||||||
echo "Do the following step to do so:"
|
echo "Do the following step to do so:"
|
||||||
echo "sudo nano $boswatchpath/config/client.yaml eg. server.yaml"
|
echo "sudo nano ${boswatchpath}/config/client.yaml eg. server.yaml"
|
||||||
echo "and modify the config as you need. This step is optional if you are upgrading an old version of BOSWatch3."
|
echo "and modify the config as you need. This step is optional if you are upgrading an old version of BOSWatch3."
|
||||||
echo "You can read the instructions on https://docs.boswatch.de/"
|
echo "You can read the instructions on https://docs.boswatch.de/"
|
||||||
tput setaf 1 # Rote Schrift
|
tput setaf 1 # Rote Schrift
|
||||||
echo "Please REBOOT bevor the first start"
|
echo "Please REBOOT before the first start"
|
||||||
tput setaf 9 # Schrift zurücksetzen
|
tput setaf 9 # Schrift zurücksetzen
|
||||||
echo "start Boswatch3 with"
|
echo "start Boswatch3 with"
|
||||||
echo "sudo python3 bw_client.py -c client.yaml and sudo python3 bw_server.py -c server.yaml"
|
echo "sudo python3 bw_client.py -c client.yaml and sudo python3 bw_server.py -c server.yaml"
|
||||||
|
|
@ -214,12 +214,9 @@ echo "sudo python3 bw_client.py -c client.yaml and sudo python3 bw_server.p
|
||||||
tput cnorm
|
tput cnorm
|
||||||
|
|
||||||
# cleanup
|
# cleanup
|
||||||
mkdir $boswatchpath/log/install -p
|
mkdir ${boswatchpath}/log/install -p
|
||||||
mv $boswatchpath/install/setup_log.txt $boswatchpath/log/install/
|
mv ${boswatch_install_path}/setup_log.txt ${boswatchpath}/log/install/
|
||||||
rm $boswatchpath/install/ -R
|
rm ${boswatch_install_path} -R
|
||||||
|
|
||||||
mv $boswatchpath/BW3-Core/* $boswatchpath/
|
|
||||||
rm $boswatchpath/BW3-Core -R
|
|
||||||
|
|
||||||
if [ $reboot = "true" ]; then
|
if [ $reboot = "true" ]; then
|
||||||
/sbin/reboot
|
/sbin/reboot
|
||||||
|
|
|
||||||
137
plugin/divera.py
Normal file
137
plugin/divera.py
Normal file
|
|
@ -0,0 +1,137 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""!
|
||||||
|
____ ____ ______ __ __ __ _____
|
||||||
|
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
|
||||||
|
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
|
||||||
|
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
|
||||||
|
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
|
||||||
|
German BOS Information Script
|
||||||
|
by Bastian Schroll
|
||||||
|
|
||||||
|
@file: divera.py
|
||||||
|
@date: 16.01.2022
|
||||||
|
@author: Lars Gremme
|
||||||
|
@description: Divera247 Plugin
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
from plugin.pluginBase import PluginBase
|
||||||
|
|
||||||
|
# ###################### #
|
||||||
|
# Custom plugin includes #
|
||||||
|
import asyncio
|
||||||
|
from aiohttp import ClientSession
|
||||||
|
import urllib
|
||||||
|
# ###################### #
|
||||||
|
|
||||||
|
logging.debug("- %s loaded", __name__)
|
||||||
|
|
||||||
|
|
||||||
|
class BoswatchPlugin(PluginBase):
|
||||||
|
"""!Description of the Plugin"""
|
||||||
|
def __init__(self, config):
|
||||||
|
"""!Do not change anything here!"""
|
||||||
|
super().__init__(__name__, config) # you can access the config class on 'self.config'
|
||||||
|
|
||||||
|
def fms(self, bwPacket):
|
||||||
|
"""!Called on FMS alarm
|
||||||
|
|
||||||
|
@param bwPacket: bwPacket instance
|
||||||
|
Remove if not implemented"""
|
||||||
|
fms_data = self.config.get("fms")
|
||||||
|
apicall = urllib.parse.urlencode({
|
||||||
|
"accesskey": self.config.get("accesskey", default=""),
|
||||||
|
"vehicle_ric": self.parseWildcards(fms_data.get("vehicle", default="")),
|
||||||
|
"status_id": bwPacket.get("status"),
|
||||||
|
"status_note": bwPacket.get("directionText"),
|
||||||
|
"title": self.parseWildcards(fms_data.get("title", default="{FMS}")),
|
||||||
|
"text": self.parseWildcards(fms_data.get("message", default="{FMS}")),
|
||||||
|
"priority": fms_data.get("priority", default="false"),
|
||||||
|
})
|
||||||
|
apipath = "/api/fms"
|
||||||
|
self._makeRequests(apipath, apicall)
|
||||||
|
|
||||||
|
def pocsag(self, bwPacket):
|
||||||
|
"""!Called on POCSAG alarm
|
||||||
|
|
||||||
|
@param bwPacket: bwPacket instance
|
||||||
|
Remove if not implemented"""
|
||||||
|
poc_data = self.config.get("pocsag")
|
||||||
|
apicall = urllib.parse.urlencode({
|
||||||
|
"accesskey": self.config.get("accesskey", default=""),
|
||||||
|
"title": self.parseWildcards(poc_data.get("title", default="{RIC}({SRIC})\n{MSG}")),
|
||||||
|
"ric": self.parseWildcards(poc_data.get("ric", default="")),
|
||||||
|
"text": self.parseWildcards(poc_data.get("message", default="{MSG}")),
|
||||||
|
"priority": poc_data.get("priority", default="false"),
|
||||||
|
})
|
||||||
|
apipath = "/api/alarm"
|
||||||
|
self._makeRequests(apipath, apicall)
|
||||||
|
|
||||||
|
def zvei(self, bwPacket):
|
||||||
|
"""!Called on ZVEI alarm
|
||||||
|
|
||||||
|
@param bwPacket: bwPacket instance
|
||||||
|
Remove if not implemented"""
|
||||||
|
zvei_data = self.config.get("zvei")
|
||||||
|
apicall = urllib.parse.urlencode({
|
||||||
|
"accesskey": self.config.get("accesskey", default=""),
|
||||||
|
"title": self.parseWildcards(zvei_data.get("title", default="{TONE}")),
|
||||||
|
"ric": self.parseWildcards(zvei_data.get("ric", default="{TONE}")),
|
||||||
|
"text": self.parseWildcards(zvei_data.get("message", default="{TONE}")),
|
||||||
|
"priority": zvei_data.get("priority", default="false"),
|
||||||
|
})
|
||||||
|
apipath = "/api/alarm"
|
||||||
|
self._makeRequests(apipath, apicall)
|
||||||
|
|
||||||
|
def msg(self, bwPacket):
|
||||||
|
"""!Called on MSG packet
|
||||||
|
|
||||||
|
@param bwPacket: bwPacket instance
|
||||||
|
Remove if not implemented"""
|
||||||
|
msg_data = self.config.get("msg")
|
||||||
|
apicall = urllib.parse.urlencode({
|
||||||
|
"accesskey": self.config.get("accesskey", default=""),
|
||||||
|
"title": self.parseWildcards(msg_data.get("title", default="{MSG}")),
|
||||||
|
"ric": self.parseWildcards(msg_data.get("ric", default="")),
|
||||||
|
"text": self.parseWildcards(msg_data.get("message", default="{MSG}")),
|
||||||
|
"priority": msg_data.get("priority", default="false"),
|
||||||
|
})
|
||||||
|
apipath = "/api/alarm"
|
||||||
|
self._makeRequests(apipath, apicall)
|
||||||
|
|
||||||
|
def _makeRequests(self, apipath, apicall):
|
||||||
|
"""Parses wildcard urls and handles asynchronus requests
|
||||||
|
|
||||||
|
@param urls: array of urls"""
|
||||||
|
url = "https://www.divera247.com"
|
||||||
|
request = url + apipath + "?" + apicall
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
future = asyncio.ensure_future(self._asyncRequests(request))
|
||||||
|
loop.run_until_complete(future)
|
||||||
|
|
||||||
|
async def _asyncRequests(self, url):
|
||||||
|
"""Handles asynchronus requests
|
||||||
|
|
||||||
|
@param urls: array of urls to send requests to"""
|
||||||
|
tasks = []
|
||||||
|
|
||||||
|
async with ClientSession() as session:
|
||||||
|
logging.debug("Generated URL: [{}]".format(url))
|
||||||
|
task = asyncio.ensure_future(self._fetch(url, session))
|
||||||
|
tasks.append(task)
|
||||||
|
|
||||||
|
responses = asyncio.gather(*tasks)
|
||||||
|
await responses
|
||||||
|
|
||||||
|
async def _fetch(self, url, session):
|
||||||
|
"""Fetches requests
|
||||||
|
|
||||||
|
@param url: url
|
||||||
|
|
||||||
|
@param session: Clientsession instance"""
|
||||||
|
logging.debug("Post URL: [{}]".format(url))
|
||||||
|
async with session.post(url) as response:
|
||||||
|
logging.info("{} returned [{}]".format(response.url, response.status))
|
||||||
|
return await response.read()
|
||||||
|
|
@ -38,7 +38,7 @@ class BoswatchPlugin(PluginBase):
|
||||||
@param bwPacket: bwPacket instance
|
@param bwPacket: bwPacket instance
|
||||||
Remove if not implemented"""
|
Remove if not implemented"""
|
||||||
urls = self.config.get("fms")
|
urls = self.config.get("fms")
|
||||||
self.makeRequests(urls)
|
self._makeRequests(urls)
|
||||||
|
|
||||||
def pocsag(self, bwPacket):
|
def pocsag(self, bwPacket):
|
||||||
"""!Called on POCSAG alarm
|
"""!Called on POCSAG alarm
|
||||||
|
|
@ -46,7 +46,7 @@ class BoswatchPlugin(PluginBase):
|
||||||
@param bwPacket: bwPacket instance
|
@param bwPacket: bwPacket instance
|
||||||
Remove if not implemented"""
|
Remove if not implemented"""
|
||||||
urls = self.config.get("pocsag")
|
urls = self.config.get("pocsag")
|
||||||
self.makeRequests(urls)
|
self._makeRequests(urls)
|
||||||
|
|
||||||
def zvei(self, bwPacket):
|
def zvei(self, bwPacket):
|
||||||
"""!Called on ZVEI alarm
|
"""!Called on ZVEI alarm
|
||||||
|
|
@ -54,7 +54,7 @@ class BoswatchPlugin(PluginBase):
|
||||||
@param bwPacket: bwPacket instance
|
@param bwPacket: bwPacket instance
|
||||||
Remove if not implemented"""
|
Remove if not implemented"""
|
||||||
urls = self.config.get("zvei")
|
urls = self.config.get("zvei")
|
||||||
self.makeRequests(urls)
|
self._makeRequests(urls)
|
||||||
|
|
||||||
def msg(self, bwPacket):
|
def msg(self, bwPacket):
|
||||||
"""!Called on MSG packet
|
"""!Called on MSG packet
|
||||||
|
|
@ -62,9 +62,9 @@ class BoswatchPlugin(PluginBase):
|
||||||
@param bwPacket: bwPacket instance
|
@param bwPacket: bwPacket instance
|
||||||
Remove if not implemented"""
|
Remove if not implemented"""
|
||||||
urls = self.config.get("msg")
|
urls = self.config.get("msg")
|
||||||
self.makeRequests(urls)
|
self._makeRequests(urls)
|
||||||
|
|
||||||
def makeRequests(self, urls):
|
def _makeRequests(self, urls):
|
||||||
"""Parses wildcard urls and handles asynchronus requests
|
"""Parses wildcard urls and handles asynchronus requests
|
||||||
|
|
||||||
@param urls: array of urls"""
|
@param urls: array of urls"""
|
||||||
|
|
@ -75,7 +75,7 @@ class BoswatchPlugin(PluginBase):
|
||||||
future = asyncio.ensure_future(self.asyncRequests(urls))
|
future = asyncio.ensure_future(self.asyncRequests(urls))
|
||||||
loop.run_until_complete(future)
|
loop.run_until_complete(future)
|
||||||
|
|
||||||
async def asyncRequests(self, urls):
|
async def _asyncRequests(self, urls):
|
||||||
"""Handles asynchronus requests
|
"""Handles asynchronus requests
|
||||||
|
|
||||||
@param urls: array of urls to send requests to"""
|
@param urls: array of urls to send requests to"""
|
||||||
|
|
@ -83,13 +83,13 @@ class BoswatchPlugin(PluginBase):
|
||||||
|
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session:
|
||||||
for url in urls:
|
for url in urls:
|
||||||
task = asyncio.ensure_future(self.fetch(url, session))
|
task = asyncio.ensure_future(self._fetch(url, session))
|
||||||
tasks.append(task)
|
tasks.append(task)
|
||||||
|
|
||||||
responses = asyncio.gather(*tasks)
|
responses = asyncio.gather(*tasks)
|
||||||
await responses
|
await responses
|
||||||
|
|
||||||
async def fetch(self, url, session):
|
async def _fetch(self, url, session):
|
||||||
"""Fetches requests
|
"""Fetches requests
|
||||||
|
|
||||||
@param url: url
|
@param url: url
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue