To all:
I am trying to implement a custom discovery template to be run on windows hosts. We have a custom application that can run multiple instances, each on a port ranging from 24022 to 24522. I need to write a custom discovery template that captures each "installed" instance and it's port, then create items and triggers to see if the application process is running. I have written the following vbs script located at "c:\Program Files\Zabbix Agent\zbxdiscover-ls.vbs" that returns the valid JSON list that a discovery process expects:
when I run this from a command prompt it returns what I would expect:
All good so far, now when I try to test this from the server side I get ZBX_UNSUPPORTED no matter what I do, even with a custom UserParameter entry (yes I restarted the agent)
I am out of ideas to get this to work, can anyone help?
I am trying to implement a custom discovery template to be run on windows hosts. We have a custom application that can run multiple instances, each on a port ranging from 24022 to 24522. I need to write a custom discovery template that captures each "installed" instance and it's port, then create items and triggers to see if the application process is running. I have written the following vbs script located at "c:\Program Files\Zabbix Agent\zbxdiscover-ls.vbs" that returns the valid JSON list that a discovery process expects:
Code:
Const HKLM = &h80000002
Const StartKey = "SYSTEM\CurrentControlSet\services"
Const SearchValue = "ImagePath"
Const MatchData = "C:\Program Files (x86)\ShotSpotter\FireDaemon\FireDaemon.exe -s"
Const Quote = """"
Set reg = GetObject("winmgmts://./root/default:StdRegProv")
Set objSortedList = CreateObject( "System.Collections.Sortedlist" )
FindKey HKLM, StartKey, SearchValue, MatchData
If objSortedList.Count Then
WScript.echo("{")
WScript.echo(" " & Quote & "data" & Quote & ":[")
For i = 0 To objSortedList.Count - 1
WScript.echo(" {")
WScript.echo(" " & Quote & "#LSNAME}" & Quote & ":" & Quote & objSortedList.GetKey(i) & Quote & ",")
WScript.echo(" " & Quote & "#LSPORT}" & Quote & ":" & Quote & objSortedList.GetByIndex(i) & Quote)
WScript.echo(" }")
WScript.echo(" ,")
Next
WScript.echo(" ]")
WScript.echo("}")
End If
Sub FindKey(root, key, value, data)
reg.EnumValues HKLM, key, names, types
If Not IsNull(names) Then
For Each name In names
If name = value Then
reg.GetStringValue HKLM, key, name, regdata
If regdata = data Then
LSInstance = Replace(key,"SYSTEM\CurrentControlSet\services\","")
If LSInstance <> "RestartLocServers" AND LSInstance <> "Watchdog" Then
'WScript.echo("found:" & LSInstance)
eKey = "HKEY_LOCAL_MACHINE\" & key & "\Parameters\Environment"
eValue = ReadMString(eKey)
If (eValue) Then
objSortedList.Add LSInstance, eValue
End If
'WScript.echo("test:" & eKey)
End If
End If
End If
Next
End If
'value not found in current key => continue search in subkeys
reg.EnumKey root, key, subkeys
If Not IsNull(subkeys) Then
For Each sk In subkeys
FindKey root, key & "\" & sk, value, data
Next
End If
End Sub
Function ReadMString (strKey)
Dim WSHShell, value
On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
vals = WSHShell.RegRead(strKey)
For i = 0 To UBound(vals)
If InStr(vals(i),"SSTTcpBindings") Then
ReadMString = Replace(vals(i),"SSTTcpBindings=0.0.0.0:","")
'WScript.echo("ReadMString:" & ReadMString)
End If
Next
End Function
Code:
c:\Program Files\Zabbix Agent>cscript //nologo c:\progra~1\zabbix~1\zbxdiscover-ls.vbs
{
"data":[
{
"#LSNAME}":"CambridgeMA",
"#LSPORT}":"24023"
}
,
{
"#LSNAME}":"ChelseaMA",
"#LSPORT}":"24024"
}
,
{
"#LSNAME}":"DetroitMI",
"#LSPORT}":"24029"
}
,
{
"#LSNAME}":"EverettMA",
"#LSPORT}":"24025"
}
,
{
"#LSNAME}":"RevereMA",
"#LSPORT}":"24026"
}
,
{
"#LSNAME}":"SomervilleMA",
"#LSPORT}":"24027"
}
,
{
"#LSNAME}":"WilmingtonDE",
"#LSPORT}":"24028"
}
,
]
}
Code:
//custom UserParameter entry [root@zabbix ~]# zabbix_get -s ssi-eastern-04 -k discovery.locserver ZBX_NOTSUPPORTED //try running the script with system.run [root@zabbix ~]# zabbix_get -s ssi-eastern-04 -k system.run[cscript //nologo c:\\progra~1\\zabbix~1\\zbxdiscover-ls.vbs] ZBX_NOTSUPPORTED //try to run with a batch file wrapper to the command zabbix_get -s ssi-eastern-04 -k system.run[c:\progra~1\zabbix~1\zbxdiscover-ls.bat] ZBX_NOTSUPPORTED
Comment