2016-09-20 46 views
0

我想檢查mysql查詢輸出並將結果與​​我的Nagios服務檢查的一些值進行比較。
它可以是有解決這個更好的方式(如果有的話 - 請您分享:))... 現在,我想這個方法:check_mysql_health - 如何檢查非數字輸出

./check_mysql_health --username root --password MyPassw0rd --mode sql --name 'show variables like 'max_connections'' --name2 "max_connections 4096" 

PS:我的max_connections值4096

mysql -Bse "show variables like 'max_connections';" 
max_connections 4096 

輸出是:

Use of uninitialized value $value in numeric gt (>) at ./check_mysql_health line 1237. 
    Use of uninitialized value $value in numeric gt (>) at ./check_mysql_health line 1238. 
    OK - max_connections 4096: 

如果我在NAME2改變價值的東西不等於 「MAX_CONNECTIONS 4096」,像 「G1Li」 號e輸出以OK狀態返回。

./check_mysql_health --username root --password MyPassw0rd --mode sql --name 'show variables like 'max_connections'' --name2 "G1Li" 
Use of uninitialized value $value in numeric gt (>) at ./check_mysql_health 

line 1237. 
    Use of uninitialized value $value in numeric gt (>) at ./check_mysql_health line 1238. 
    OK - g1li: 
# echo $? 
0 

任何想法?

吉利

+0

可能是這樣的:'--name'顯示像'max_connections'''這樣的變量。 sql裏面的引號是終止bash字符串的,所以''''''''參數''''''''''使得max_connections等成爲完全獨立的東西。 –

回答

0

我也是新來這個,這可能幫助,

./check_mysql_health --username root --password MyPassw0rd --mode sql \ 
--name 'show 1,variables like 'max_connections'' --name2 "status max_connections 4096" 

我們正在使用這種用於Oracle。我不確定這種狀況,但是這是正確的。

或者你可以自定義添加一些更多的模式(有兩個主要部分之一是遠程/本地執行SQ​​L查詢,另一個是解析nagios/icinga的結果數據),如果你想!這將是一個更好的解決方案。