Merge branch 'cc-5709-airtime-analyzer' into cc-5709-airtime-analyzer-saas

This commit is contained in:
Albert Santoni 2014-04-01 12:29:20 -04:00
commit a6e80e2789
9 changed files with 103 additions and 18 deletions

View file

@ -10,19 +10,18 @@ from message_listener import MessageListener
class AirtimeAnalyzerServer:
# Constants
_CONFIG_PATH = '/etc/airtime/airtime.conf'
_LOG_PATH = "/var/log/airtime/airtime_analyzer.log"
# Variables
_log_level = logging.INFO
def __init__(self, debug=False):
def __init__(self, config_path, debug=False):
# Configure logging
self.setup_logging(debug)
# Read our config file
rabbitmq_config = self.read_config_file()
rabbitmq_config = self.read_config_file(config_path)
# Start listening for RabbitMQ messages telling us about newly
# uploaded files.
@ -55,9 +54,8 @@ class AirtimeAnalyzerServer:
rootLogger.addHandler(consoleHandler)
def read_config_file(self):
def read_config_file(self, config_path):
config = ConfigParser.SafeConfigParser()
config_path = AirtimeAnalyzerServer._CONFIG_PATH
try:
config.readfp(open(config_path))
except IOError as e:

View file

@ -6,12 +6,14 @@ import os
import airtime_analyzer.airtime_analyzer as aa
VERSION = "1.0"
DEFAULT_CONFIG_PATH = '/etc/airtime/airtime.conf'
print "Airtime Analyzer " + VERSION
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--daemon", help="run as a daemon", action="store_true")
parser.add_argument("--debug", help="log full debugging output", action="store_true")
parser.add_argument("--rmq-config-file", help="specify a configuration file with RabbitMQ settings (default is /etc/airtime/airtime.conf)")
args = parser.parse_args()
'''Ensure media_monitor isn't running before we start, because it'll move newly uploaded
@ -33,10 +35,15 @@ def check_if_media_monitor_is_running():
check_if_media_monitor_is_running()
#Default config file path
config_path = DEFAULT_CONFIG_PATH
if args.rmq_config_file:
config_path = args.rmq_config_file
if args.daemon:
with daemon.DaemonContext():
analyzer = aa.AirtimeAnalyzerServer(debug=args.debug)
analyzer = aa.AirtimeAnalyzerServer(config_path=config_path, debug=args.debug)
else:
# Run without daemonizing
analyzer = aa.AirtimeAnalyzerServer(debug=args.debug)
analyzer = aa.AirtimeAnalyzerServer(config_path=config_path, debug=args.debug)

View file

@ -1,5 +1,41 @@
#! /bin/bash
path=$1
filename="${path##*/}"
curl http://localhost/rest/media -u 3188BDIMPJROQP89Z0OX: -X POST -F "file=@$path" -F "name=$filename"
post_file() {
#kill process after 30 minutes (360*5=30 minutes)
max_retry=360
retry_count=0
file_path=${1}
filename="${file_path##*/}"
#base_instance_path and airtime_conf_path are common to all saas instances
base_instance_path=/mnt/airtimepro/instances/
airtime_conf_path=/etc/airtime/airtime.conf
#maps the instance_path to the url
vhost_file=/mnt/airtimepro/system/vhost.map
#instance_path will look like 1/1384, for example
instance_path=$(echo ${file_path} | grep -Po "(?<=($base_instance_path)).*?(?=/srv)")
#post request url - http://bananas.airtime.pro/rest/media, for example
url=http://
url+=$(grep -E $instance_path $vhost_file | awk '{print $1;}')
url+=/rest/media
#path to specific instance's airtime.conf
instance_conf_path=$base_instance_path$instance_path$airtime_conf_path
api_key=$(sudo awk -F "=" '/api_key/ {print $2}' $instance_conf_path)
until curl --max-time 30 $url -u $api_key":" -X POST -F "file=@${file_path}" -F "name=${filename}"
do
retry_count=$[$retry_count+1]
if [ $retry_count -ge $max_retry ]; then
break
fi
sleep 5
done
}
post_file "${1}" &

View file

@ -0,0 +1,21 @@
#! /bin/bash
post_file() {
file_path=${1}
filename="${file_path##*/}"
#kill process after 30 minutes (360*5=30 minutes)
max_retry=10
retry_count=0
until curl --max-time 30 http://localhost/rest/media -u 3188BDIMPJROQP89Z0OX: -X POST -F "file=@${file_path}" -F "name=${filename}"
do
retry_count=$[$retry_count+1]
if [ $retry_count -ge $max_retry ]; then
break
fi
sleep 1
done
}
post_file "${1}" &