Hi,

i´m trying to implement a powershell-based Exchange DAG-Sensor, output is in XML-Based format...

if i´m running the script directly on the prtg-server (powershell-window..) the output will look like this:

<?xml version="1.0" encoding="Windows-1252" ?> 
<prtg> 
 <result> 
   <channel>MailboxDatabase 2013\EXC2013</channel> 
   <value>1</value> 
   <showChart>1</showChart> 
   <showTable>1</showTable> 
   <mode>Absolute</mode> 
</result> 
</prtg> 

...if the script is triggered via the sensor the output is this (logs from "Result of Sensor XYZ" on the prtg-server...)

<?xml version="1.0" encoding="Windows-1252" ?> 
<prtg> 
 <result> 
   <channel>MailboxDatabase 2013\EXC2013</channel> 
   <value>1</value> 
   <showChart>1</showChart> 
   <showTable>1</showTable> 
   <mode>Absolute</mode> 
</result> 
</prtg> 

Die Benennung "if" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skr
iptdatei oder eines ausfhrbaren Programms erkannt. šberprfen Sie die Schreibw
eise des Namens, oder ob der Pfad korrekt ist (sofern enthalten), und wiederhol
en Sie den Vorgang.
Bei Zeile:1 Zeichen:114
+ &'C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\prtg_dagm
onitor.ps1' exc2013.labcloud.local;& <<<< if %errorlevel% EQU 0 (exit $LastExit
Code)else (exit %errorlevel%)
    + CategoryInfo          : ObjectNotFound: (if:String) [], CommandNotFoundE 
   xception
    + FullyQualifiedErrorId : CommandNotFoundException

...looks like the powershell-script is running correctly...but the errorlevel-handling seems to be incorrect...

any ideas ?!? ..or ist there any config-option for the sensor to surpress the errorhandling completely ?!?

regards René


Article Comments

Do you mind posting the entire script including the script sensor configuration in PRTG? :)


Sep, 2014 - Permalink

..mhh..good idea :-) here´s my customized script (...the original is from http://www.frankysweb.de/exchange-2010-monitoring-via-prtg)

param(
[string]$servername)

#$servername = "exc2013.labcloud.local" 
$WarningPreference = "SilentlyContinue"
  
#————————————— 
$pssession = new-pssession -configurationname "Microsoft.Exchange" -connectionuri "http://$servername/Powershell" -Authentication Kerberos -WarningAction "SilentlyContinue"
$startsession = import-pssession -session $pssession -allowclobber -WarningAction SilentlyContinue | out-null 
  
$dbstatus = get-mailboxdatabasecopystatus 
$dbcount = (Get-MailboxDatabaseCopyStatus).count 
  
$prtg = ‘<?xml version="1.0" encoding="Windows-1252" ?> 
<prtg> 
‘ 
  
foreach ($db in $dbstatus) 
{ 
  $dbname = $db.Name 
  $dbstate = $db.Status 
  $dbvalue = "10" 
  if ($dbstate -match "Mounted") 
  { 
    $dbvalue = "1" 
   } 
    if ($dbstate -match "Dismounted") 
   { 
    $dbvalue = "2" 
   } 
    if ($dbstate -match "Healthy") 
   { 
    $dbvalue = "3" 
   } 
  
$prtg +=" <result> 
   <channel>$dbname</channel> 
   <value>$dbvalue</value> 
   <showChart>1</showChart> 
   <showTable>1</showTable> 
   <mode>Absolute</mode> 
</result> 
</prtg> 
" 
} 
remove-pssession -session $pssession | out-null
$prtg 

...and my sensor config in PRTG:

SensorConfig


Sep, 2014 - Permalink

Can't test it properly but it should work. You added </prtg> to the foreach of the results, breaking the XML structure :) Also I've cleaned up the if statements, consider using switch/case here: Paste at line 24, replacing everthing that follows

if ($dbstate -match "Mounted") { $dbvalue = "1" } 
if ($dbstate -match "Dismounted") { $dbvalue = "2" } 
if ($dbstate -match "Healthy") { $dbvalue = "3" } 
  
$prtg += "<result>  
   <channel>$dbname</channel> 
   <value>$dbvalue</value> 
   <showChart>1</showChart> 
   <showTable>1</showTable> 
   <mode>Absolute</mode> 
</result>" 
} 
remove-pssession -session $pssession | out-null
$prtg +="<text>Your text goes here</text>
</prtg>" 

Sep, 2014 - Permalink