Ad Widget

Collapse

Windows Hosts : Hardware monitoring with OHM

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • captainmac40
    Junior Member
    • Jul 2015
    • 5

    #1

    Windows Hosts : Hardware monitoring with OHM

    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

    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
    His UserParameter line on zabbix agent conf file :
    Code:
    UserParameter=ohm_disco,powershell.exe -Noprofile -ExecutionPolicy Bypass -file c:\zabbix-agent\conf\externalscripts\ohm_disco.ps1
    The second one is for getting the data of an sensor precisely :

    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
    His UserParameter line on zabbix agent conf file :
    Code:
    UserParameter=ohm_capteur[*],powershell.exe -Noprofile -ExecutionPolicy Bypass -file c:\zabbix-agent\conf\externalscripts\ohm_get.ps1 $1
    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 !
    Attached Files
    Last edited by captainmac40; 13-07-2015, 14:16. Reason: Adding files
  • NoOneIsPerfect
    Member
    • Feb 2015
    • 37

    #2
    Thanks and please upload your Zabbix template for auto-discovery.

    Comment

    • captainmac40
      Junior Member
      • Jul 2015
      • 5

      #3
      Template

      As you request , here is the template with auto-discovery , item for the sensors and an simple graph.
      Enjoy and please feedback...
      Attached Files

      Comment

      • NoOneIsPerfect
        Member
        • Feb 2015
        • 37

        #4
        Once again thanks!

        Comment

        • ApolloDS
          Junior Member
          • Dec 2010
          • 11

          #5
          Thank you!

          Thank you very much for this great Template, works very good.
          So now I can monitor temp of my gaming pc

          Comment

          • schuhbie
            Junior Member
            • Aug 2015
            • 1

            #6
            I know this is a very old thread but since it was helpful for me I'll post a quick improvement. My system was having collisions with the temporary files being made by the powershell scripts so I removed the need for them.

            ohm_disco:
            Code:
            #Create the data array
            $sensorData = @()
            Get-WmiObject -Namespace "Root\OpenHardwareMonitor" -Query "SELECT * FROM Sensor" | ForEach-Object {
                #Make a human readable name for Zabbix
                $blah = $_.Identifier -match '(\w+)/(\d+)$'
                $itemPropertyName = (Get-Culture).TextInfo.ToTitleCase($Matches[1])
                $itemPropertyIndex = $Matches[2]
                #Create the object and populate its properites
                $properties = @{'{#ID_WMI}'=$_.Identifier;'{#NAME_WMI}'=$_.Name + " " + $itemPropertyName + " " + $itemPropertyIndex}
                $object = New-Object –TypeName PSObject –Prop $properties
                #Add the object to the array
                $sensorData += ($object)
            }
            #Wrap the resulting array into another object as property 'data'
            $properties = @{'data'=$sensorData}
            $object = New-Object -TypeName PSObject -Prop $properties
            #Output to the console to be picked up by Zabbix
            write-host($object | convertto-json)
            ohm_get
            Code:
            #grab the ident parameter that was passed in (by the Zabbix agent)
            param([string]$ident)
            $request = "SELECT * FROM Sensor WHERE Identifier=" + "'" + $ident + "'"
            #Request the data (only need the first result) and write it out to the console for the zabbix agent
            $sensorValues = Get-WmiObject -Namespace "Root\OpenHardwareMonitor" -Query $request
            write-host($sensorValues[0].value)

            Comment

            • zvio
              Junior Member
              • Jan 2021
              • 2

              #7
              Since my colleagues were very helpful to me, I wanted to return the favor by sharing the updated version of the solution.

              There was an issue in Zabbix 6.4 where the template import wasn’t working properly, and the values weren’t displaying correctly. I’ve fixed these issues and will walk you through the steps to get everything working smoothly.

              I struggled a bit while writing this, so I’ve included everything in a zipped file to make it easier for you to follow along.

              Enjoy and extend vibe)
              Attached Files

              Comment


              • Kres
                Kres commented
                Editing a comment
                Hi,
                zvio followed your instructions but I get this error:

                Invalid discovery rule value: cannot parse as a valid JSON object: invalid object format, expected opening character '{' or '[' at: 'Cannot run a document in the middle of a pipeline: C:\Windows\system32\Get-WmiObject.
                At C:\Program Files\Zabbix Agent 2\externalscripts\ohm_disco.ps1

                Zabbix 6.4.10.
                WIN 10
                OHM 0.9.6

                This is from Zabbix agent2 conf:

                # Open HardwareMonitor Discovery
                UserParameter=ohm_disco,powershell.exe -Noprofile -ExecutionPolicy Bypass -file "C:\Program Files\Zabbix Agent 2\externalscripts\ohm_disco.ps1"
                UserParameter=ohm_capteur[*],powershell.exe -Noprofile -ExecutionPolicy Bypass -file "C:\Program Files\Zabbix Agent 2\externalscripts\ohm_get.ps1"

                Any suggestions

                Thx in advance

              • Kres
                Kres commented
                Editing a comment
                I forgot mentioned that i tried with LibreHardwareMonitor so that is the issue. Is it possible to modify scripts for LibreHardwareMonitor ?

              • zvio
                zvio commented
                Editing a comment
                The whole script that our friend created is based on OHM, so if your app produces a different output, it definitely won't work. Try to push manually scripts and see what output you will get, and compare what you have in OHM.
                UserParameter=ohm_disco,powershell.exe -Noprofile -ExecutionPolicy Bypass -file "C:\Program Files\Zabbix Agent 2\externalscripts\ohm_disco.ps1"
                Last edited by zvio; 13-04-2025, 01:05.
            • zvio
              Junior Member
              • Jan 2021
              • 2

              #8
              Additional fix.
              After reviewing several samples, I discovered that WMI was returning two values instead of one and it was detected as a string, not a Numeric value.
              Further investigation revealed that two instances of the Open Hardware Monitor process were running simultaneously, resulting in duplicate WMI entries.
              Ensure that only a single OHM instance is running to avoid conflicting WMI values. Once that's done, the issue should be resolved.

              Comment

              • xpech
                Junior Member
                • Nov 2025
                • 1

                #9
                Thx a lot!
                Maybe this addition to the template would be helpful. My agent kept sending floats using ',' character, even after locale changes.
                Attached Files

                Comment

                Working...