这文档是我拼凑出来的,脚本也是复制其他人的。自己当时找了很久。现在在这里分享给大家,顺便鄙视下51CTO上那些同样复制别人东西,还拿出来卖豆豆的人。
一、创建脚本 找一个放脚本的目录,如:C:\zabbix\Scripts
创建脚本:MySQL-ping.vbs
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin\mysqladmin -uroot -proot ping")
If Instr(str1,"alive") > 0 Then
WScript.Echo 1
Else
WScript.Echo 0
End If
Function getCommandOutput(theCommand)
Dim objShell, objCmdExec
Set objShell = CreateObject("WScript.Shell")
Set objCmdExec = objshell.exec(thecommand)
getCommandOutput = objCmdExec.StdOut.ReadAll
end Function
创建脚本:MySQL-Status_Script.vbs
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = getCommandOutput("C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin\mysqladmin -u root -proot extended-status")
Arg = objArgs(0)
str2 = Split(str1,"|")
For i = LBound(str2) to UBound(str2)
If Trim(str2(i)) = Arg Then
WScript.Echo TRIM(str2(i+1))
Exit For
End If
next
Function getCommandOutput(theCommand)
Dim objShell, objCmdExec
Set objShell = CreateObject("WScript.Shell")
Set objCmdExec = objshell.exec(thecommand)
getCommandOutput = objCmdExec.StdOut.ReadAll
end Function
#注意,str1 = getCommandOutput此处修改命令的绝对路径,用户名与密码。
二、修改agent配置文件 修改需要被监控的mysql所在服务器上的zabbix_agent.conf UnsafeUserParameters=1 添加键值 UserParameter=mysql.status[*], cscript /nologo C:\zabbix\Scripts\MySQL-Status_Script.vbs $1 UserParameter=mysql.ping, cscript /nologo C:\zabbix\Scripts\MySQL-ping.vbs
在Server端测试是否成功 /usr/local/zabbix-server/bin/zabbix_get -s 192.168.1.1 -k mysql.ping
三、重启agentd
四、在相应主机上添加zabbix的MySQL模板