CC-2750:Ability to query health status for pypo, liquidsoap, media monitor, and recorder

This commit is contained in:
martin 2011-09-12 16:18:08 -04:00
parent 0591c9d76f
commit 0546633ac7
5 changed files with 88 additions and 11 deletions

View File

@ -21,6 +21,7 @@ class ApiController extends Zend_Controller_Action
->addActionContext('remove-watched-dir', 'json')
->addActionContext('set-storage-dir', 'json')
->addActionContext('get-stream-setting', 'json')
->addActionContext('status', 'json')
->initContext();
}
@ -636,5 +637,32 @@ class ApiController extends Zend_Controller_Action
$this->view->msg = Application_Model_StreamSetting::getStreamSetting();
}
public function statusAction() {
global $CC_CONFIG;
$request = $this->getRequest();
$api_key = $request->getParam('api_key');
/*
if (!in_array($api_key, $CC_CONFIG["apiKey"]))
{
header('HTTP/1.0 401 Unauthorized');
print 'You are not allowed to access this resource.';
exit;
}
*/
$status = array(
"airtime_version"=>Application_Model_Systemstatus::GetAirtimeVersion(),
"icecast"=>Application_Model_Systemstatus::GetIcecastStatus(),
"pypo"=>Application_Model_Systemstatus::GetPypoStatus(),
"liquidsoap"=>Application_Model_Systemstatus::GetLiquidsoapStatus(),
"show-recorder"=>Application_Model_Systemstatus::GetShowRecorderStatus(),
"media-monitor"=>Application_Model_Systemstatus::GetMediaMonitorStatus()
);
$this->view->status = $status;
}
}

View File

@ -3,6 +3,47 @@
class Application_Model_Systemstatus
{
public static function GetPypoStatus(){
return array(
"process_id"=>500,
"uptime_seconds"=>3600
);
}
public static function GetLiquidsoapStatus(){
return array(
"process_id"=>500,
"uptime_seconds"=>3600
);
}
public static function GetShowRecorderStatus(){
return array(
"process_id"=>500,
"uptime_seconds"=>3600
);
}
public static function GetMediaMonitorStatus(){
return array(
"process_id"=>500,
"uptime_seconds"=>3600
);
}
public static function GetIcecastStatus(){
return array(
"process_id"=>500,
"uptime_seconds"=>3600
);
}
public static function GetAirtimeVersion(){
return AIRTIME_VERSION;
}
private function getCheckSystemResults(){
//exec("airtime-check-system", $output);

View File

@ -0,0 +1,3 @@
<?php
echo $status;

View File

@ -13,15 +13,16 @@ $PORT = 5672;
$USER = 'guest';
$PASS = 'guest';
$VHOST = '/';
$EXCHANGE = 'router';
$EXCHANGE = 'airtime-pypo';
$QUEUE = 'msgs';
$conn = new AMQPConnection($HOST, $PORT, $USER, $PASS);
$ch = $conn->channel();
$ch->access_request($VHOST, false, false, true, true);
$ch->exchange_declare($EXCHANGE, 'direct', false, false, false);
$ch->exchange_declare($EXCHANGE, 'direct', false, true);
$msg_body = implode(' ', array_slice($argv, 1));
$msg_body = json_encode(array("event_type"=>"get_status", "id"=>time()));
//$msg_body = '{"schedule":{"status":{"range":{"start":"2011-09-12 20:45:22","end":"2011-09-13 20:45:22"},"version":"1.1"},"playlists":[],"check":1,"stream_metadata":{"format":"","station_name":""}},"event_type":"update_schedule"}';
$msg = new AMQPMessage($msg_body, array('content_type' => 'text/plain'));
$ch->basic_publish($msg, $EXCHANGE);

View File

@ -79,17 +79,23 @@ class PypoFetch(Thread):
command = m['event_type']
logger.info("Handling command: " + command)
if(command == 'update_schedule'):
if command == 'update_schedule':
self.schedule_data = m['schedule']
self.process_schedule(self.schedule_data, "scheduler", False)
elif (command == 'update_stream_setting'):
elif command == 'update_stream_setting':
logger.info("Updating stream setting...")
self.regenerateLiquidsoapConf(m['setting'])
elif (command == 'cancel_current_show'):
elif command == 'cancel_current_show':
logger.info("Cancel current show command received...")
self.stop_current_show()
elif command == 'get_status':
self.get_status()
# ACK the message to take it off the queue
message.ack()
def get_status(self):
logger = logging.getLogger('fetch')
logger.debug("get_status")
def stop_current_show(self):
logger = logging.getLogger('fetch')
@ -451,26 +457,24 @@ class PypoFetch(Thread):
# Wait for messages from RabbitMQ. Timeout if we
# dont get any after POLL_INTERVAL.
self.connection.drain_events(timeout=POLL_INTERVAL)
# Hooray for globals!
schedule_data = SCHEDULE_PUSH_MSG
status = 1
except socket.timeout, se:
# We didnt get a message for a while, so poll the server
# to get an updated schedule.
status, schedule_data = self.api_client.get_schedule()
status, self.schedule_data = self.api_client.get_schedule()
except Exception, e:
"""
This Generic exception is thrown whenever the RabbitMQ
Service is stopped. In this case let's check every few
seconds to see if it has come back up
"""
logger.info("Unknown exception")
logger.info("Exception, %s", e)
return
#return based on the exception
if status == 1:
self.process_schedule(schedule_data, "scheduler", False)
self.process_schedule(self.schedule_data, "scheduler", False)
loops += 1
"""