New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

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

Free PRTG
Download >>

 

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

 

Top Tags


View all Tags


PowerShell-Exchange-DAG Problem

Votes:

0

Your Vote:

Up

Down

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 ausfhrbaren Programms erkannt. šberprfen 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é

dag exchange powershell

Created on Sep 17, 2014 3:29:33 PM by  Rene Kertscher (0) 1

Last change on Sep 18, 2014 8:34:38 PM by  Stephan Linke [Paessler Support]



3 Replies

Votes:

0

Your Vote:

Up

Down

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

Created on Sep 18, 2014 8:35:18 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

..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

Created on Sep 18, 2014 8:59:51 PM by  Rene Kertscher (0) 1



Votes:

0

Your Vote:

Up

Down

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>" 

Created on Sep 19, 2014 10:19:25 AM by  Stephan Linke [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.