What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

prtg custom sensor SQL

Votes:

0

Hi im having trouble to run this powershell command via custom sensor ...

running it with the powershellscriptrunner.exe i get only empty results - that seems to time out

$cmd = Invoke-Sqlcmd  -ServerInstance instance  -Database  db -Query "SELECT * FROM tablexy where replicationsuccess = y/n

$result = 1

try {
      if ($cmd.value -eq "N") {
        $result=0
       $resulttxt="ok -$($cmd.value)-"
      } 
      else {
       $resulttxt="Problem -$($cmd.value)-"
       $result=2
      }
} 
catch {
    $resulttxt="Problem catch"
    $result=1
	return
}
Write-host  "<prtg><result><channel>Replication</channel><value>$result</value><showChart>1</showChart><showTable>1</showTable><LimitMinError>0</LimitMinError><LimitMaxError>0</LimitMaxError></result><Text>$resulttxt</Text></prtg>" 

result via powershellscriptrunner:

<prtg><result><channel>Replication</channel><value>2</value><showChart>1</showChart><showTable>1</showTable><LimitMinError>0</LimitMinError><LimitMaxError>0</LimitMaxError></result><Text>Problem --</Text></prtg>

result via powershell:

<prtg><result><channel>Replication</channel><value>2</value><showChart>1</showChart><showTable>1</showTable><LimitMinError>0</LimitMinError><LimitMaxError>0</LimitMaxError></result><Text>Problem --</Text></prtg>

custom-sensor invoke-sqlcmd powershell sql

Created on Mar 13, 2023 10:27:35 AM

Last change on Mar 15, 2023 7:57:04 AM by  Felix Wiesneth [Paessler Support]



Replies

Nobody has replied yet


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.