Hi,

I did a sql query and i have to, in the Microsoft power shell. I need that PRTG can read the result of my query. That's my script:

invoke-sqlcmd -query "select campo from DB..tabla where campo = 10" -ServerInstance "192.168.1.1\instancia" -Username user -Password prtg | format-wide

Ande result is:

9899

I need that the PRTG reed that.


Article Comments

If you have a working powershell script that returns a numerical value and you want to read/use that value with PRTG. There are two API Formats that you can use, regardless of scripting language:

The "XML" output, as exemplified here(output):

            <prtg>
            <result>
            <channel>First channel</channel>
            <value>10</value>
            </result>
            <text>This is the sensors optional text</text>
            </prtg>

The "standard" format, as exemplified here(code):

Write-Host "10:This is the sensors optional text"
exit 0

For more information, see PRTG Manual: Custom Sensors

Please note that if your query provides a numerical result directly, you should also be able to use the built-in SQL v2 sensors: PRTG Manual: Microsoft SQL v2 Sensor

You can find examples for the SQL Sensors here:

Best Regards,
Luciano Lingnau [Paessler Support]


Jul, 2016 - Permalink

You actually could just create a SQL-Query script and use the SQL-Sensors to execute the script. This would be way easier then having a PowerShell executing an Invoke-SQLCMD to grab the data - you actually just add to the complexity of the sensor.

Of course - I don't know the whole scenario, but from what you wrote it seems to be a bit complex using PowerShell to execute a SQL query. I did monitoring of database table values to gain statistics and even alerts. You can do a lot using the SQL sensors that execute SQL scripts/queries.

Regards

Florian Rossmark

www.it-admins.com


Jul, 2018 - Permalink