From 72350184d8411415cf8cb2d598f355bc5306d56c Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 30 Aug 2011 12:18:58 -0400 Subject: [PATCH 1/3] CC-2694: Create command line program for viewing/dumping log files -initial commit --- utils/airtime-log.php | 113 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 utils/airtime-log.php diff --git a/utils/airtime-log.php b/utils/airtime-log.php new file mode 100644 index 000000000..daa471f57 --- /dev/null +++ b/utils/airtime-log.php @@ -0,0 +1,113 @@ + "/var/log/airtime/media-monitor/media-monitor.log", + "show-recorder" => "/var/log/airtime/show-recorder/show-recorder.log", + "playout" => "/var/log/airtime/pypo/pypo.log", + "web" => "/var/log/airtime/zendphp.log"); + +function printUsage($opts, $userMsg) +{ + $msg = $opts->getUsageMessage(); + echo $userMsg; + echo PHP_EOL."Usage: airtime-log [options]"; + echo substr($msg, strpos($msg, "\n")).PHP_EOL; +} + +function isKeyValid($key){ + global $log_files; + return array_key_exists($key, $log_files); +} + +function viewSpecificLog($key){ + global $log_files; + + if (isKeyValid($key)){ + echo "Viewing $key log\n"; + pcntl_exec(exec("which less"), array($log_files[$key])); + pcntl_wait($status); + } +} + +function dumpAllLogs(){ + $dateStr = gmdate("Y-m-d-H-i-s"); + $filename = __DIR__."/airtime-log-all-$dateStr.tgz"; + echo "Creating Airtime logs tgz file at $filename"; + $command = "tar cfz $filename /var/log/airtime 2>/dev/null"; + exec($command); +} + +function dumpSpecificLog($key){ + global $log_files; + + if (isKeyValid($key)){ + $dateStr = gmdate("Y-m-d-H-i-s"); + $filename = __DIR__."/airtime-log-$key-$dateStr.tgz"; + echo "Creating Airtime logs tgz file at $filename"; + $dir = dirname($log_files[$key]); + $command = "tar cfz $filename $dir 2>/dev/null"; + exec($command); + } +} + +function tailAllLogs(){ + global $log_files; + echo "Tail all Airtime logs"; + pcntl_exec(exec("which multitail"), $log_files); + pcntl_wait($status); +} + +function tailSpecificLog($key){ + global $log_files; + + if (isKeyValid($key)){ + echo "Tail $key log"; + pcntl_exec(exec("which tail"), array("-F", $log_files[$key])); + pcntl_wait($status); + } +} + +try { + $opts = new Zend_Console_Getopt( + array( + 'view|v-s' => "Display log file\n" + ."\t\tmediamonitor|playout|recorder|web (ALL by default)", + 'dump|d-s' => "Collect all log files and compress into a tarball\n" + ."\t\tmediamonitor|playout|recorder|web (ALL by default)", + 'tail|t-s' => "View any new entries appended to log files in real-time\n" + ."\t\tmediamonitor|playout|recorder|web (ALL by default)" + ) + ); + $opts->parse(); +} +catch (Zend_Console_Getopt_Exception $e) { + print $e->getMessage() .PHP_EOL; + printUsage($opts, ""); + exit(1); +} + +if (isset($opts->v)){ + if ($opts->v === true){ + echo "Please choose a specific log to view"; + } else { + viewSpecificLog($opts->v); + } +} else if (isset($opts->d)){ + if ($opts->d === true){ + dumpAllLogs(); + } else { + dumpSpecificLog($opts->d); + } +} else if (isset($opts->t)){ + if ($opts->t === true){ + tailAllLogs(); + } else { + tailSpecificLog($opts->t); + } +} + +echo PHP_EOL; + From 58f64b97aeba8c4da5025465b59320c807bdc214 Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 30 Aug 2011 12:28:37 -0400 Subject: [PATCH 2/3] CC-2694: Create command line program for viewing/dumping log files -Better error messages. --- utils/airtime-log.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/utils/airtime-log.php b/utils/airtime-log.php index daa471f57..c61087b23 100644 --- a/utils/airtime-log.php +++ b/utils/airtime-log.php @@ -5,14 +5,17 @@ require_once('Zend/Loader/Autoloader.php'); $autoloader = Zend_Loader_Autoloader::getInstance(); $log_files = array("media-monitor" => "/var/log/airtime/media-monitor/media-monitor.log", - "show-recorder" => "/var/log/airtime/show-recorder/show-recorder.log", + "recorder" => "/var/log/airtime/show-recorder/show-recorder.log", "playout" => "/var/log/airtime/pypo/pypo.log", "web" => "/var/log/airtime/zendphp.log"); -function printUsage($opts, $userMsg) +function printUsage($userMsg = "") { + global $opts; + $msg = $opts->getUsageMessage(); - echo $userMsg; + if (strlen($userMsg)>0) + echo $userMsg; echo PHP_EOL."Usage: airtime-log [options]"; echo substr($msg, strpos($msg, "\n")).PHP_EOL; } @@ -29,7 +32,7 @@ function viewSpecificLog($key){ echo "Viewing $key log\n"; pcntl_exec(exec("which less"), array($log_files[$key])); pcntl_wait($status); - } + } else printUsage(); } function dumpAllLogs(){ @@ -50,7 +53,7 @@ function dumpSpecificLog($key){ $dir = dirname($log_files[$key]); $command = "tar cfz $filename $dir 2>/dev/null"; exec($command); - } + } else printUsage(); } function tailAllLogs(){ @@ -67,31 +70,31 @@ function tailSpecificLog($key){ echo "Tail $key log"; pcntl_exec(exec("which tail"), array("-F", $log_files[$key])); pcntl_wait($status); - } + } else printUsage(); } try { $opts = new Zend_Console_Getopt( array( - 'view|v-s' => "Display log file\n" - ."\t\tmediamonitor|playout|recorder|web (ALL by default)", + 'view|v=s' => "Display log file\n" + ."\t\tmedia-monitor|playout|recorder|web (ALL by default)", 'dump|d-s' => "Collect all log files and compress into a tarball\n" - ."\t\tmediamonitor|playout|recorder|web (ALL by default)", + ."\t\tmedia-monitor|playout|recorder|web (ALL by default)", 'tail|t-s' => "View any new entries appended to log files in real-time\n" - ."\t\tmediamonitor|playout|recorder|web (ALL by default)" + ."\t\tmedia-monitor|playout|recorder|web (ALL by default)" ) ); $opts->parse(); } catch (Zend_Console_Getopt_Exception $e) { print $e->getMessage() .PHP_EOL; - printUsage($opts, ""); + printUsage(); exit(1); } if (isset($opts->v)){ if ($opts->v === true){ - echo "Please choose a specific log to view"; + //Should never get here. Zend_Console_Getopt requires v to provide a string parameter. } else { viewSpecificLog($opts->v); } From 9c6b722722f8ce9c93480bc5cc9ca2857fb779b2 Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 30 Aug 2011 12:38:04 -0400 Subject: [PATCH 3/3] CC-2694: Create command line program for viewing/dumping log files -check if each subsystem is actually installed on the machine. --- utils/airtime-log.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/utils/airtime-log.php b/utils/airtime-log.php index c61087b23..062beed74 100644 --- a/utils/airtime-log.php +++ b/utils/airtime-log.php @@ -9,6 +9,8 @@ $log_files = array("media-monitor" => "/var/log/airtime/media-monitor/media-moni "playout" => "/var/log/airtime/pypo/pypo.log", "web" => "/var/log/airtime/zendphp.log"); +array_filter($log_files, "file_exists"); + function printUsage($userMsg = "") { global $opts; @@ -74,14 +76,15 @@ function tailSpecificLog($key){ } try { + $keys = implode("|", array_keys($log_files)); $opts = new Zend_Console_Getopt( array( 'view|v=s' => "Display log file\n" - ."\t\tmedia-monitor|playout|recorder|web (ALL by default)", + ."\t\t$keys (ALL by default)", 'dump|d-s' => "Collect all log files and compress into a tarball\n" - ."\t\tmedia-monitor|playout|recorder|web (ALL by default)", + ."\t\t$keys (ALL by default)", 'tail|t-s' => "View any new entries appended to log files in real-time\n" - ."\t\tmedia-monitor|playout|recorder|web (ALL by default)" + ."\t\t$keys (ALL by default)" ) ); $opts->parse();