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 custom sensor wrong value

Votes:

0

Hi, i hope someone can help me... I'm working for now 2 weeks on a sensor, that shows me how old a backup is. The result from the PowerShell script is:

            <prtg>
            <result>
            <channel>Backup Job 1</channel>
            <value>21</value>
            </result>
            <result>
            <channel>Backup Job 2</channel>
            <value>248</value>
            </result>
            <result>
            <channel>Backup Job 3</channel>
            <value>18</value>
            </result>
            </prtg>

The scipt worked verry well, but when i create a custom XML sensor the values are wrong. In this case:

Backup Job 1 = 84
Backup Job 2 = 384	
Backup Job 3 = 194

The code is very simple: 

$BackupJob1 = "Backup Job 1"
$LastBackup1 = (Get-ChildItem 'backups:\Backup Job 1').LastWriteTime | Sort-Object LastWriteTime | Select-Object -Last 1
$BackupAge1 =  (Get-Date) - $LastBackupJonas | Select-Object -Property Days | Format-Wide | Out-String
$BackupAge1 = $BackupAge1.Trim()
$BackupAge1 = $BackupAge1.ToDecimal($null)

The integer that comes out of the Sript is right, but PRTG shows a different one... I don't know why and i can't see a scheme on it.

I hope some one can help me, I'm despairing.

Greetings from Germany

backup custom-sensor failure powershell prtg sensor value

Created on Sep 27, 2019 4:36:48 PM

Last change on Sep 30, 2019 4:05:13 AM by  Sven Roggenhofer [Paessler Technical Support]



Best Answer

Accepted Answer

Votes:

1

After a lot of Troubleshooting and logging i found the Problem in PowerShell itself. When i run the script in ISE the sort function works fine. When i run the script direktly, like PRTG does, the sort function don't include all objects. This is why the script gave out a wrong value. I think the sort function had a Problem with the pipelining…

I wrote a new script without integrating the sort funktion in the pipeline and now it works.

Thanks for the food for thought, Mr. Mikulik.

I hope i could help someone with this entry.

Greetings from Germany

Created on Oct 14, 2019 6:02:27 AM

Last change on Oct 14, 2019 1:00:45 PM by  Erhard Mikulik [Paessler Support]



3 Replies

Votes:

0

Hi there,

I'll send you an email shortly about sending us logs from the sensor itself.

Kind regards,

Erhard

Created on Sep 30, 2019 12:24:33 PM by  Erhard Mikulik [Paessler Support]



Accepted Answer

Votes:

1

After a lot of Troubleshooting and logging i found the Problem in PowerShell itself. When i run the script in ISE the sort function works fine. When i run the script direktly, like PRTG does, the sort function don't include all objects. This is why the script gave out a wrong value. I think the sort function had a Problem with the pipelining…

I wrote a new script without integrating the sort funktion in the pipeline and now it works.

Thanks for the food for thought, Mr. Mikulik.

I hope i could help someone with this entry.

Greetings from Germany

Created on Oct 14, 2019 6:02:27 AM

Last change on Oct 14, 2019 1:00:45 PM by  Erhard Mikulik [Paessler Support]



Votes:

0

Thanks for sharing the outcome, Mr. Hagendorf :)

Created on Oct 14, 2019 8:04:56 AM by  Erhard Mikulik [Paessler Support]




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.