Hello everybody, my first cookbook is about getting hardware datas on windows host. I make 2 powershell scripts (I spent a lot of time for making this lol) which is getting the "hardware" datas from a software called "OpenHardwareMonitor" using windows's WMI.
You can find this software here : http://openhardwaremonitor.org/downloads/
I post here for an feedback on other installations and , of course, fixing and improvements are welcome !
The first one is for doing the auto discovery of sensors (linked with an LLD rule on zabbix server)
ohm_disco.ps1
His UserParameter line on zabbix agent conf file :
The second one is for getting the data of an sensor precisely :
ohm_get.ps1
His UserParameter line on zabbix agent conf file :
That's all for the moment , I make an .bat for agent's auto installation but it's not working again perfectly...
Sorry for my English , I'm French lol
Have a Nice Day !
You can find this software here : http://openhardwaremonitor.org/downloads/
I post here for an feedback on other installations and , of course, fixing and improvements are welcome !
The first one is for doing the auto discovery of sensors (linked with an LLD rule on zabbix server)
ohm_disco.ps1
Code:
$strFileName=".\sensors.dat"
$strFileName2=".\sensortmp.dat"
If (Test-Path $strFileName){
del $strFileName
}
If (Test-Path $strFileName2){
del $strFileName2
}
$cle = '{"{#ID_WMI}":"'
$valeur = '","{#NAME_WMI}":"'
$fermeture = '"},'
$bcl = 1
ADD-content -path $strFileName -value '{"data":['
Get-WmiObject -Namespace "Root\OpenHardwareMonitor" -Query "SELECT * FROM Sensor" | ForEach-Object {
$clecomplete = $cle + $_.Identifier + $valeur + $_.Name + $fermeture
ADD-content -path $strFileName -value $clecomplete
$bcl = $bcl +1
}
(get-content $strFileName -totalcount $bcl)[-1] | foreach-object {$_ -replace "},","}" | add-content $strFileName}
$bcl = $bcl - 2
$fichier = get-content $strFileName
$fichier[0..$bcl] > $strFileName2
$bcl = $bcl + 2
$fichier[$bcl] >> $strFileName2
move $strFileName2 $strFileName -Force
']}' >> $strFileName
Get-Content $strFileName
Code:
UserParameter=ohm_disco,powershell.exe -Noprofile -ExecutionPolicy Bypass -file c:\zabbix-agent\conf\externalscripts\ohm_disco.ps1
ohm_get.ps1
Code:
param([string]$ident)
$strFileName=".\sensors.tmp"
If (Test-Path $strFileName){
del $strFileName
}
$cle = '{"{#ID_WMI}":"'
$valeur = '","value":"'
$fermeture = '"}]}'
$request = "SELECT * FROM Sensor WHERE Identifier=" + "'" + $ident + "'"
Get-WmiObject -Namespace "Root\OpenHardwareMonitor" -Query $request | ForEach-Object {
$clecomplete = $_.value -replace ',','.'
ADD-content -path $strFileName -value $clecomplete
}
Get-content -path $strFileName
Code:
UserParameter=ohm_capteur[*],powershell.exe -Noprofile -ExecutionPolicy Bypass -file c:\zabbix-agent\conf\externalscripts\ohm_get.ps1 $1
Sorry for my English , I'm French lol

Have a Nice Day !
Comment