2016-09-20 67 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的结果数据),如果你想!这将是一个更好的解决方案。