[英]Updating munin shoutcast monitoring plugin code from version 1 to 2
因此,我嘗試更新以下代碼來監視Icecast和Shoutcast偵聽器,因為當我升級到Shoutcast 2時,它停止工作並且作者是AWOL或至少選擇不回答。
現在,我認為我已經用正則表達式代碼解決了問題,但仍然無法正常工作。 這讓我認為代碼檢索狀態頁和新URL格式的方式也是一個問題。
無論如何,我將不勝感激,可以為您提供解決方案方面的幫助,謝謝!
源代碼: https : //github.com/munin-monitoring/contrib/blob/f444e600c9718ba249d46d3b44d6b6ebaccb0aa3/plugins/network/radio
第158行的舊正則表達式:
preg_match_all( "/.*?Stream Status: \<\/td\>\<td\>\<b\>\Stream is up at \d*? kbps with (\d*?) of \d*? listeners\<\/b\>\<\/td\>\<\/tr\>/s", $xml, $parser );
我的第一個正則表達式:
preg_match_all( "/.*?Stream Status: \<\/font\>\<\/td\>\<td>\<font class\=default\>\<b\>Stream is up at (\d*?) kbps with \<B\>(\d*?) of (\d*?) listeners/s", $xml, $parser );
問題代碼:
function getShout( $host, $port, $name ) {
$error = false;
$fp = fsockopen( $host, $port, $errno, $errstr, 10 );
if ( !$fp ) {
$error = $errstr ."(". $errno .")";
} else {
fputs( $fp, "GET / HTTP/1.0\r\n" );
fputs($fp, "User-Agent: Mozilla\r\n");
fputs( $fp, "Connection: close\r\n\r\n" );
$xml = "";
while ( !feof( $fp ) ) {
$xml .= fgets($fp, 512);
}
fclose( $fp );
if ( stristr( $xml, "HTTP/1.0 200 OK" ) == true ) {
$xml = trim( substr( $xml, 42 ) );
} else {
$error = "Bad login";
}
if ( !$error ) {
$res = array( "found" => true );
preg_match_all( "/.*?Stream Status: \<\/font\>\<\/td\>\<td>\<font class\=default\>\<b\>Stream is up at (\d*?) kbps with \<B\>(\d*?) of (\d*?) listeners/s", $xml, $parser );
$res["listeners"] = $parser[1][0];
$res["name"] = $name;
} else {
$res = $error;
}
}
return $res;
}
我從命令行運行插件得到的輸出...
岩石價值B
流行值B
值B
dnb值B
精神價值B
斷裂值B
dubstep.value B
雷鬼值B
技術價值B
環境值B
完整值0
示例廣播狀態v1狀態頁: http ://stream.radioamlo.info:8010/
樣品的Shoutcast V2狀態頁: http://91.221.151.237:8994/index.html?sid=1
更新1:我的第二個正則表達式看起來更好:
preg_match_all( "/.*?Stream Status: \<\/font\>\<\/td\>\<td>\<font class\=default\>\<b\>Stream is up at \d*? kbps with \<B\>(\d*?) of \d*?
更新#2:添加'echo $ xml;' '$ error =“錯誤登錄”之后;' 返回以下錯誤:
<html><head><title>Redirect</title></head><body>Click <a href="/index.html?sid=1">here</a> for redirect.</body></html>techno.value B
HTTP/1.1 302 Found
Content-Type:text/html;charset=utf-8
Location:index.html?sid=1
Content-Length:118
根據您所寫的內容,問題是,獲取信息的位置已更改。 您發布的錯誤消息已經告訴了新位置(在主機名之前添加主機名)。
我對fsock不太熟悉,我認為它無法處理重定向。 因此,我建議您改用cURL:只需遵循cURL手冊上的第一個示例。 然后,cURL的輸出僅替換$xml
。 記住還要將GET-Information ?sid=1
傳遞給cURL!
只需測試一下,然后您將看到有關字符串解析的更多錯誤。 如果是,請發布“ new $xml
”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.