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

powershell xml custom sensor

Votes:

0

Hello! I'm copy/write powershell xml script for monitoring Exchange DB Status.

$servername = "servermbx" 


$pssession = new-pssession -configurationname "Microsoft.Exchange" -connectionuri "http://$servername/Powershell" -Authentication Kerberos 
$startsession = import-pssession -session $pssession -allowclobber -WarningAction SilentlyContinue | out-null 

$dbstatus = get-mailboxdatabasecopystatus | select name,ActiveCopy
$dbcount = (Get-MailboxDatabaseCopyStatus).count 

$prtg = '<?xml version="1.0" encoding="Windows-1252" ?> 
<prtg>'
 
foreach ($db in $dbstatus) 
{ 
  $dbname = $db.Name 
  $dbstate = $db.ActiveCopy 
  $dbvalue = "10" 
  if ($dbstate -match "False") 
  { 
    $dbvalue = "1" 
   } 
    if ($dbstate -match "Active") 
   { 
    $dbvalue = "2" 
   } 
     
  
$prtg +="
    <result> 
        <channel>$dbname</channel> 
        <value>$dbvalue</value> 
        <showChart>1</showChart> 
        <showTable>1</showTable> 
        <mode>Absolute</mode>
    </result> 
" 
} 

$prtg +="<text>The number of databases: $dbcount</text> 
</prtg>" 
remove-pssession -session $pssession 
$prtg 

How i can edit this script or this:

When state of database False - sensor OK, state of database - Active - Sensor Error.

Now, in both cases state False or Active PRTG monitor say what sensor is Ok.

datebase exchange powershell xml

Created on Jan 18, 2016 7:58:09 AM

Last change on Jan 18, 2016 8:12:44 AM by  Luciano Lingnau [Paessler]



10 Replies

Votes:

0

Dear dukedizel

There are two options to set a sensor to an error status

  • Return the according XML result using the node <Error>
  • Return another value channel and use the channel limit to change the sensor state

The latter approach allows to also return monitoring values, even though the sensor is in the alarm state.

Created on Jan 18, 2016 4:04:51 PM by  Arne Seifert [Paessler Support]



Votes:

0

Could you give me example on my script? I try add <Error>2</Error> but it's not work.

Created on Jan 18, 2016 6:47:42 PM



Votes:

0

Dear dukedizel

An example output is

   <prtg>
   <error>1</error>
   <text>Your error message</text>
   </prtg>

Please find the full documentation in the API manual which is integrated into the PRTG webinterface: Setup | PRTG API, tab "Custom Sensors".

Created on Jan 19, 2016 12:34:21 PM by  Arne Seifert [Paessler Support]



Votes:

0

My sensor: <?xml version="1.0" encoding="Windows-1252" ?> <prtg> <result> <channel>Moscow VIP Users\SRVMBX250</channel> <value>2</value> <showChart>1</showChart> <showTable>1</showTable> <mode>Absolute</mode> <error>2</error> <text>Your error message</text> </result> <text>The number of databases: 3</text> </prtg>

limits do not work ... I create a new sensor but the sensor configured channel limits are not settable.

what am I doing wrong?

Created on Jan 19, 2016 1:07:18 PM



Votes:

0

Dear dukedizel

If you open the sensor channel configuration by clicking on its gauge, you should be able to enable and set the limits. Please clarify in which sense the limits are not settable.

Created on Jan 19, 2016 2:08:21 PM by  Arne Seifert [Paessler Support]



Votes:

0

I form this: <?xml version="1.0" encoding="Windows-1252" ?> <prtg> <result> <channel>Moscow VIP Users\SRVMBX250</channel> <value>2</value> <showChart>1</showChart> <showTable>1</showTable> <mode>Absolute</mode> <error>2</error> <text>Your error message</text> </result> <text>The number of databases: 3</text> </prtg>

I see this sensor in PRTG but Limits not settable automatically. Parameters <error>2</error> are not taken from the file. I have to put limits manually.

Created on Jan 20, 2016 5:23:48 AM



Votes:

0

The error limits must be defined in the XML output and are only read when the sensor created (i.e. they can't be changed after created). The following XML values have to be present:

<limitmode>1</limitode> <!-- mandatory !-->
<LimitMinError>10</LimitMinError>
<LimitMaxError>10</LimitMaxError>
<LimitMinWarning>10</LimitMinWarning>
<LimitMaxWarning>10</LimitMaxWarning>
<LimitErrorMsg>Your error message</LimitErrorMsg>
<LimitWarningMsg>Your Warning message</LimitWarningMsg>

Set the Limit tags according to your needs :) Further information can be found on
http://<your-prtg-server>/api.htm?tabid=7

Created on Jan 20, 2016 12:24:07 PM by  Stephan Linke [Paessler Support]

Last change on Jan 20, 2016 12:24:17 PM by  Stephan Linke [Paessler Support]



Votes:

0

Log:

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

    <result> 
        <channel>Moscow VIP Users\SRVMBX250</channel> 
        <value>2</value> 
        <showChart>1</showChart> 
        <showTable>1</showTable> 
        <limitmode>1</limitode>
        <LimitMinError>2</LimitMinError>
        <LimitMaxError>2</LimitMaxError>
        <LimitMinWarning>10</LimitMinWarning>
        <LimitMaxWarning>10</LimitMaxWarning>
        <LimitErrorMsg>Your error message</LimitErrorMsg>
        <LimitWarningMsg>Your Warning message</LimitWarningMsg>
    </result> 
<text>The number of databases: 3</text> 
</prtg>

Error

Error

Created on Jan 20, 2016 12:46:30 PM



Votes:

0

Whoops, typo - my bad:

<limitmode>1</limitmode>

Forgot the m in </limitmode> :)

Created on Jan 20, 2016 1:14:54 PM by  Stephan Linke [Paessler Support]



Votes:

0

Ok, thx now it's work!

Created on Jan 20, 2016 1:21:59 PM




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.