Move python_apps/airtime_analyzer/ to analyzer/
This commit is contained in:
parent
a7d06ad076
commit
2ef63e8c4e
39 changed files with 0 additions and 0 deletions
48
analyzer/tools/ftp-upload-hook.sh
Executable file
48
analyzer/tools/ftp-upload-hook.sh
Executable file
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -xv
|
||||
|
||||
post_file() {
|
||||
#kill process after 30 minutes (360*5=30 minutes)
|
||||
max_retry=5
|
||||
retry_count=0
|
||||
|
||||
file_path="${1}"
|
||||
# Give us write permissions on the file to prevent problems if the user
|
||||
# uploads a read-only file.
|
||||
chmod +w "${file_path}"
|
||||
|
||||
#We must remove commas because CURL can't upload files with commas in the name
|
||||
# http://curl.haxx.se/mail/archive-2009-07/0029.html
|
||||
stripped_file_path=${file_path//','/''}
|
||||
mv "${file_path}" "${stripped_file_path}"
|
||||
file_path="${stripped_file_path}"
|
||||
# filename="${file_path##*/}"
|
||||
|
||||
airtime_conf_path=/etc/airtime/airtime.conf
|
||||
|
||||
#instance_path will look like 1/1384, for example
|
||||
http_path=$(grep base_url ${airtime_conf_path} | awk '{print $3;}')
|
||||
http_port=$(grep base_port ${airtime_conf_path} | awk '{print $3;}')
|
||||
|
||||
#post request url - http://bananas.airtime.pro/rest/media, for example
|
||||
url=http://
|
||||
url+=$http_path
|
||||
url+=:
|
||||
url+=$http_port
|
||||
url+=/rest/media
|
||||
|
||||
api_key=$(grep api_key ${airtime_conf_path} | awk '{print $3;}')
|
||||
|
||||
# -f is needed to make curl fail if there's an HTTP error code
|
||||
# -L is needed to follow redirects! (just in case)
|
||||
until curl -fL --max-time 30 $url -u $api_key":" -X POST -F "file=@${file_path}"; do
|
||||
retry_count=$((retry_count + 1))
|
||||
if [ $retry_count -ge $max_retry ]; then
|
||||
break
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
}
|
||||
|
||||
post_file "${1}" &
|
46
analyzer/tools/message_sender.php
Normal file
46
analyzer/tools/message_sender.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?
|
||||
require_once('php-amqplib/amqp.inc');
|
||||
|
||||
//use PhpAmqpLibConnectionAMQPConnection;
|
||||
//use PhpAmqpLibMessageAMQPMessage;
|
||||
|
||||
define('HOST', '127.0.0.1');
|
||||
define('PORT', '5672');
|
||||
define('USER', 'airtime');
|
||||
define('PASS', 'QEFKX5GMKT4YNMOAL9R8');
|
||||
define('VHOST', '/airtime');//'/airtime');
|
||||
|
||||
$exchange = "airtime-uploads";
|
||||
$exchangeType = "topic";
|
||||
$queue = "airtime-uploads";
|
||||
$routingKey = ""; //"airtime.analyzer.tasks";
|
||||
|
||||
if ($argc <= 1)
|
||||
{
|
||||
echo("Usage: " . $argv[0] . " message\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
$message = $argv[1];
|
||||
|
||||
$connection = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
|
||||
if (!isset($connection))
|
||||
{
|
||||
echo "Failed to connect to the RabbitMQ server.";
|
||||
return;
|
||||
}
|
||||
|
||||
$channel = $connection->channel();
|
||||
|
||||
// declare/create the queue
|
||||
$channel->queue_declare($queue, false, true, false, false);
|
||||
|
||||
// declare/create the exchange as a topic exchange.
|
||||
$channel->exchange_declare($exchange, $exchangeType, false, true, false);
|
||||
|
||||
$msg = new AMQPMessage($message, array("content_type" => "text/plain"));
|
||||
|
||||
$channel->basic_publish($msg, $exchange, $routingKey);
|
||||
print "Sent $message ($routingKey)\n";
|
||||
$channel->close();
|
||||
$connection->close();
|
20
analyzer/tools/test-hook-script.sh
Executable file
20
analyzer/tools/test-hook-script.sh
Executable file
|
@ -0,0 +1,20 @@
|
|||
#! /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}" &
|
Loading…
Add table
Add a link
Reference in a new issue