added simple HTTP request

if alarm send a HTTP request to an url you want
This commit is contained in:
Bastian Schroll 2015-04-04 21:47:09 +02:00
parent 7dd61db384
commit c331d14047
3 changed files with 41 additions and 9 deletions

View file

@ -10,6 +10,7 @@ Python Script to Recive and Decode German BOS Information with rtl_fm and multim
- Filtering double alarms with adjustable time
- FMS and ZVEI validation (plausibility test)
- MySQL Database Support for FMS and ZVEI
- simple HTTP request at alarm to URL you want
- All configurations in seperate File "config.ini"
- simple Web Frontend with Data Parsing

View file

@ -14,12 +14,12 @@ import subprocess
#import os
import mysql
import mysql.connector
import httplib
import argparse #for parse the args
import ConfigParser #for parse the config file
import re #Regex
def curtime(format="%Y-%m-%d %H:%M:%S"):
return time.strftime(format)
@ -126,6 +126,12 @@ try:
tableFMS = config.get("MySQL", "tableFMS")
tableZVEI = config.get("MySQL", "tableZVEI")
tablePOC = config.get("MySQL", "tablePOC")
#HTTPrequest config
useHTTPrequest = int(config.get("Module", "useHTTPrequest")) #use HTTPrequest support?
if useHTTPrequest: #only if HTTPrequest is active
url = config.get("HTTPrequest", "url")
except:
stop_script("config reading error")
exit(0)
@ -212,10 +218,18 @@ try:
fms_time_old = timestamp #save last time
if useMySQL: #only if MySQL is active
if args.verbose: print "FMS to MySQL"
cursor = connection.cursor()
cursor.execute("INSERT INTO "+tableFMS+" (time,service,country,location,vehicle,status,direction,tsi) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",(curtime(),fms_service,fms_country,fms_location,fms_vehicle,fms_status,fms_direction,fms_tsi))
cursor.close()
connection.commit()
if useHTTPrequest: #only if HTTPrequest is active
httprequest = httplib.HTTPConnection(url)
httprequest.request("HEAD", "/")
httpresponse = httprequest.getresponse()
if args.verbose: print httpresponse.status, httpresponse.reason
elif args.verbose: #Invalid error only in verbose mode
print "No valid FMS: "+fms_id
elif args.verbose: #crc error only in verbose mode
@ -238,14 +252,22 @@ try:
zvei_time_old = timestamp #save last time
if useMySQL: #only if MySQL is active
if args.verbose: print "ZVEI to MySQL"
cursor = connection.cursor()
cursor.execute("INSERT INTO "+tableZVEI+" (time,zvei) VALUES (%s,%s)",(curtime(),zvei_id))
cursor.close()
connection.commit()
if useHTTPrequest: #only if HTTPrequest is active
httprequest = httplib.HTTPConnection(url)
httprequest.request("HEAD", "/")
httpresponse = httprequest.getresponse()
if args.verbose: print httpresponse.status, httpresponse.reason
elif args.verbose: #Invalid error only in verbose mode
print "No valid ZVEI: "+zvei_id
except KeyboardInterrupt:
stop_script("Keyboard Interrupt")
stop_script("Keyboard Interrupt")
except:
stop_script("other Error")

View file

@ -3,26 +3,35 @@
########################
[FMS]
#time to ignore same alarm in a row in seconds
#time to ignore same alarm in a row (sek)
double_ignore_time = 10
[ZVEI]
#time to ignore same alarm in a row in seconds
#time to ignore same alarm in a row (sek)
double_ignore_time = 5
#can take on or off the modules (0|1)
[Module]
useMySQL = 0
#useAudiorecord = 0
#useHTTPrequest = 0
useHTTPrequest = 0
#Data for MySQL connection
[MySQL]
#Data for MySQL connection
dbserver = localhost
dbuser = root
dbpassword = root
database = boswatch
#tables in the database
tableFMS = bos_fms
tableZVEI = bos_zvei
tablePOC = bos_pocsag
tablePOC = bos_pocsag
#[Audiorecord]
#recording time (sek)
#record_time = 30
[HTTPrequest]
#url without http:// !
url = www.google.de