'################################################################################## ' Script that reads a specified registry value/data on a Neverfail cluster node and ' uses Zabbix_sender to populate the data into Zabbix. ' Copyright (C) 2010 Carlos R. Tronco ' ' This program is free software: you can redistribute it and/or modify ' it under the terms of the GNU General Public License as published by ' the Free Software Foundation, either version 3 of the License, or ' (at your option) any later version. ' ' This program is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' GNU General Public License for more details. ' ' You should have received a copy of the GNU General Public License ' along with this program. If not, see . ' '############################################################################## ' Feb 2010 - Carlos Tronco - cars at LosTroncos dot org */ Option Explicit 'On Error Resume Next Dim WshShell, oExec 'Generate Debug Output const DebugOut=False 'Full Path to the Reg.exe util Dim REGEXE REGEXE = "C:\Windows\system32\Reg.exe" ' Full path to the zabbix_sender prog DIM ZBXSEND ZBXSend="C:\program files\zabbix\Zabbix_sender.exe" 'ZbxServer is the hostname of the Zabbix Server DIM ZBXSERVER ZBXServer="zabbix.crtcotp.com" 'ZbxClient is the name opf this client relative to Zabbix DIM ZBXCLIENT 'The Zabbix Key DIM ZBXKey ZbxKey = WScript.Arguments(0) ' The Registry Key where the value we want is located ex: HKLM\software\fred Dim RegKey RegKey = Wscript.Arguments(1) ' The actual Value we want to get under RegKey DIM RegValue RegValue = WScript.arguments(2) 'Ex zbx send cmd line = C:\temp\Zabbix_sender -z"zabbix01" -s"mailserver01" -k"nf_cluster[file_sync_status]" -o "/Synchronized" '######################################################### ' Hex to Dec routine liberally lifted from ' http://www.sonofsofaman.com/hobbies/code/hextodec.asp '######################################################### Function HexToDec(strHex) dim lngResult dim intIndex dim strDigit dim intDigit dim intValue lngResult = 0 for intIndex = len(strHex) to 1 step -1 strDigit = mid(strHex, intIndex, 1) intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1 if intDigit >= 0 then intValue = intDigit * (16 ^ (len(strHex)-intIndex)) lngResult = lngResult + intValue else lngResult = 0 intIndex = 0 ' stop the loop end if next HexToDec = lngResult End Function '######################################################### Function GetRegValue(RegKey,RegValue) DIM CommandLine,WshShell, oExec DIM TmpAry,HexValue,TmpHexValue DIM strValue,ValueType,Result,IDX Err.Clear 'Build our Command line to get the registry value, CHR(34) is double quote CommandLine = REGEXE & " query " & chr(34)& RegKey & chr(34)& " /v " & chr(34) & RegValue & chr(34) If (DebugOut) Then WScript.Echo "CommandLine=[" & CommandLine & "]" Set WshShell = CreateObject("WScript.Shell") 'Execute the command Should look something like 'Set oExec = WshShell.Exec("REG Query HKLM\software\crtcorp\Product_A /z /v ""Reg_Dword Example""") Set oExec = WshShell.Exec(CommandLine) If DebugOut then WScript.Echo "RC=" & Err.Number 'Skip two header lines to get to the one we really want oExec.StdOut.SkipLine oExec.StdOut.SkipLine 'Get the line of output we do want and trim the leading and trailing spaces. Result = Trim(oExec.StdOut.ReadLine) If DebugOut then Wscript.Echo "Initial Result is [" & Result & "]" 'Cut off the RegValue at the front so we can try to figure out what kind of value this is Result = Trim(Right(Result,Len(Result)-Len(RegValue))) If DebugOut then Wscript.Echo "Result is [" & Result & "]" ' Now let's split the string into parts. TmpAry(0) should be the "Type" of value TmpAry=split(Result," " ) Valuetype=TmpAry(0) strValue= Trim(Right(Result,Len(Result)-Len(ValueType))) TmpHexValue = TmpAry(Ubound(Tmpary)) HexValue = Right(TmpHexValue,Len(TmpHexValue)-2) If DebugOut then WScript.Echo "0" & TmpAry(0) WScript.Echo "Last " & TmpAry(Ubound(Tmpary)) End If Select Case ValueType Case "REG_DWORD" If DebugOut then WScript.ECho "Reg DWORD" GetRegValue = HexToDec(HexValue) Case "REG_QWORD" If DebugOut then WScript.ECho "Reg QWORD" GetRegValue = HexToDec(HexValue) Case "REG_SZ" If DebugOut then WScript.ECho "Reg SZ" GetRegValue = strValue Case "REG_MULTI_SZ" If DebugOut then WScript.ECho "Reg Multi SZ" GetRegValue = strValue Case "REG_EXPAND_SZ" If DebugOut then WScript.Echo "Expand SZ" GetRegValue = strValue Case "REG_DWORD_BIG_ENDIAN" If DebugOut then WScript.ECho "Reg DWORD BIG ENDIAN" If Len(HexValue) < 8 then If DebugOut Then WScript.Echo "Padding" WScript.Echo "String" & string(8-Len(HexValue),"0") End If HexValue=string(8-Len(HexValue),"0") & HexValue If DebugOut Then WScript.Echo "New Hex Val = " & HexValue end If 'Temporary variable for shuffled HexValue DIM TMPHex for IDX=4 to 1 Step -1 TMPHex = TMPHEX & Mid(HexValue,(IDx-1)*2+1,2) If DebugOut Then Wscript.Echo "Mid(" & HexValue & "," & (IDX-1)*2+1 & "," & 2& ")" WScript.Echo Mid(HexValue,(IDX-1)*2+1,2) WScript.Echo "TMPHex=0x" & TmpHex End If Next GetRegValue= HexToDec(TmpHex) End Select End Function '#################################################################################### Function Zabbix_Send(ZabbixKey,Value) Dim WshShell, oExec, CommandLine Set WshShell = CreateObject("WScript.Shell") 'Execute the command Should look something like 'Set oExec = WshShell.Exec("REG Query HKLM\software\crtcorp\Product_A /z /v ""Reg_Dword Example""") CommandLine = ZBXSend & " -vv -z""" & ZBXServer & """ -s""" & ZBXClient & """ -k""" & ZabbixKey & """ -o """ & Value & """" WScript.Echo "Commandline is [" & CommandLine & "]" Set oExec = WshShell.Exec(CommandLine) 'Ex zbx send cmd line = C:\temp\Zabbix_sender -z"zabbix01" -s"mailserver01" -k"nf_cluster[file_sync_status]" -o "/Synchronized" End Function Set WshShell = WSCript.CreateObject("WScript.Shell") ZBXClient = WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%") Zabbix_Send ZBXKey, GetRegValue(RegKey,RegValue)