php开发nagios插件的方法
来源{
Nagios的插件介绍
http://os.51cto.com/art/201103/249956.htm
Nagios插件开发指导
http://cuiyingfeng.blog.51cto.com/43841/618190
通过自己编写的插件来使用 Nagios
http://www.ibm.com/developerworks/cn/aix/library/au-nagios/index.html
}
demo如下
<?php /** * php开发nagios插件的demo * 功能: 检测mysql的版本号 */ $result=""; $con = mysql_connect("1.2.3.4:3306","user","pass"); if (!$con) { //连接失败 echo "CRITICAL - Could not connect: ".mysql_error()."\n"; exit(2); } $info_str="mysql 连接成功\n"; mysql_select_db("test", $con); mysql_query("set names 'utf8'"); $sql="SHOW VARIABLES"; $dbResult=mysql_query($sql,$con); while ( $row = mysql_fetch_array($dbResult) ) { if ($row[0]=="version") { $result.=$row[0]."=".$row[1].";"; } } echo "OK - 'sql=".$sql."' then show version succeed | ".$result."\n"; exit(0); ?>