What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Powershell sensor script to gather to gather data from SAJ solar inverter

Votes:

0

Your Vote:

Up

Down

hello, I decided to write and share with you a script for downloading data from the SAJ inverter and presenting the data in PRTG. The original inverter tracking software is very limited and as I have PRTG instance at home on my ESX, I decided to use it for these purposes. Technically this is a advanced server which generates xml. It generates 35 channels. All data came from csv which is loaded from device interface. All you need to change ip to your.

function Get-Data {
   param(
     [string]$DeviceIP
   ) 
 
	[int]$LocalDevicePort = "80"
    $url = "http://"+ $deviceIP +"/status/status.php"
    $test = test-netconnection -ComputerName $deviceIP -Port $LocalDevicePort
    if ($test) {
        $method = "GET"
        $WebResponse = Invoke-WebRequest -Uri $url -Method $method
        $Content = $WebResponse.Content
        Return $content
        } else {
        Write-Output "host not responding"
        }#end if
    }

function Get-Table {
   param(
     [string]$DataString
   ) 

$statusfieldnames = @('Statistics', 'Total_Generated', 'Total_Running Time', 'Today_Generated', 'Today_Running_Time', 'PV1_Voltage', 'PV1_Current', 'PV2_Voltage', 'PV2_Current', 'PV3_Voltage', 'PV3_Current', 'PV1_StrCurr1', 'PV1_StrCurr2', 'PV1_StrCurr3', 'PV1_StrCurr4', 'PV2_StrCurr1', 'PV2_StrCurr2', 'PV2_StrCurr3', 'PV2_StrCurr4', 'PV3_StrCurr1', 'PV3_StrCurr2', 'PV3_StrCurr3', 'PV3_StrCurr4', 'Grid-connected_Power', 'Grid-connected_Frequency', 'Line1_Voltage', 'Line1_Current', 'Line2_Voltage', 'Line2_Current', 'Line3_Voltage', 'Line3_Current', 'Bus_Voltage', 'Device_Temperature', 'CO2emission_Reduction', 'Other_Status')
$unitsfieldnames  = @(        'na',             'kWh',                  'h',             'kWh',                  'h',           'V',           'A',           'V',           'A',           'V',           'A',            'V',            'A',            'A',            'A',            'A',            'A',            'A',            'A',            'A',            'A',            'A',            'A',                    'W',                       'Hz',             'V',             'A',             'V',             'A',             'V',             'A',           'V',                  'C',                    'Kg',           'na')
$divisorfields    = @(         '1',             '100',                 '10',             '100',                 '10',          '10',         '100',          '10',         '100',           '1',           '1',            '1',            '1',            '1',            '1',            '1',            '1',            '1',            '1',            '1',            '1',            '1',            '1',                    '1',                      '100',            '10',           '100',            '10',           '100',            '10',           '100',          '10',                 '10',                    '10',            '1')


$ValueArray = $DataString.split(',')

if (($statusfieldnames.count) -eq ($ValueArray.count)) {$max = $statusfieldnames.count}
$result = for ($i = 0; $i -lt $max; $i++) {
    [PSCustomObject]@{
        channel = $statusfieldnames[$i]
        value   = ([string]([double]($ValueArray[$i]) / [int]($divisorfields[$i]) )).replace(',','.')       
        unit    = $unitsfieldnames[$i]
        }
    }
Return $result
}

function Get-XML {
   param(
   $Table
   ) 

$prtg = '<?xml version="1.0" encoding="Windows-1252" ?> 
<prtg>'

#$prtg = '<prtg>'

foreach ($row in $Table) { 
    $channel = $row.channel
    $value = $row.value
    $unit = $row.unit
    
    if ($value.Contains('.')) {$float = 1} else {$float = 0}
    if ($channel) {
        $prtg +="
            <result> 
                <channel>$channel</channel>
                <value>$value</value>
                <unit>Custom</unit>
                <customUnit>$unit</customUnit>
                <float>$float</float>
            </result>"
        }
    } 

$prtg +="</prtg>" 
return $prtg 
}

$IP = "[PUT YOUR IP HERE]"
$data  = Get-Data  -DeviceIP   $IP
$table = Get-Table -DataString $data 
[xml]$xml = New-Object System.Xml.XmlDocument
[xml]$xml = Get-XML -Table $table

$xml.InnerXml

custom-sensor inverter powershell prtg saj

Created on Oct 26, 2020 8:55:45 PM by  solonka (0) 1

Last change on Oct 27, 2020 6:07:31 AM by  Marijan Horsky [Paessler Support]



1 Reply

Votes:

0

Your Vote:

Up

Down

Hello,

Thank you very much for sharing your script with the community. We greatly appreciate your initiative which contributes to make PRTG better.

Kind regards.

Created on Oct 27, 2020 7:03:03 AM by  Florian Lesage [Paessler Support]

Last change on Oct 27, 2020 7:03:19 AM by  Florian Lesage [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.