lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

get-sensorhistory : Index was outside of bounds of the array. #223

Closed solipsist01 closed 3 years ago

solipsist01 commented 3 years ago

Hi, @Lordmilko

It seems that version 0.9.16 introduced a new bug in the parsing in get-sensorhistory The error is however diffrent from the error we had in https://github.com/lordmilko/PrtgAPI/issues/218 I've tried to gather info as complete as possible. if you need anything, i'll provide :)

The following code now generates an error:

$sensors = get-sensor -probe $probe -type vmwaredatastoreextern
$datastorehistory = $sensors | get-sensorhistory -count 12 -EndDate (Get-Date).AddYears(-1) -average 2678400 -Verbose

VERBOSE: Get-SensorHistory: Synchronously executing request https://someprtg/api/historicdata.xml?id=51483&edate=2021-06-04-11-31-08&sdate=2020-06-04-11-28-54&avg=2678400&sortby=-datetime&coun
t=500&username=redacted&passhash=redacted

get-sensorhistory : Index was outside the bounds of the array.
At line:1 char:32
+ ...  $sensors | get-sensorhistory -count 12 -EndDate (Get-Date).AddYears( ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-SensorHistory], IndexOutOfRangeException
    + FullyQualifiedErrorId : System.IndexOutOfRangeException,PrtgAPI.PowerShell.Cmdlets.GetSensorHistory

PS C:\Windows\system32> get-module prtgapi

ModuleType Version    Name                                ExportedCommands                                                                                                                           
---------- -------    ----                                ----------------                                                                                                                           
Binary     0.9.16     prtgapi                             {Add-Device, Add-Group, Add-NotificationTrigger, Add-Sensor...}                                                                            

PS C:\Windows\system32> $error[0].Exception.StackTrace
   at PrtgAPI.Utilities.ConvertUtilities.ToDynamicDouble(String str, Nullable`1 raw)
   at PrtgAPI.PowerShell.SensorHistoryFormatter.GetChannelValue(ChannelHistoryRecord channel)
   at PrtgAPI.PowerShell.SensorHistoryFormatter.CreateObject(SensorHistoryRecord date)
   at PrtgAPI.PowerShell.SensorHistoryFormatter.<Init>d__10.MoveNext()
   at PrtgAPI.PowerShell.SensorHistoryFormatter.<Format>d__9.MoveNext()
   at System.Linq.Enumerable.<TakeIterator>d__25`1.MoveNext()
   at PrtgAPI.PowerShell.Base.PrtgProgressCmdlet.WriteList[T](IEnumerable`1 sendToPipeline)
   at PrtgAPI.PowerShell.Cmdlets.GetSensorHistory.ProcessSensorHistory()
   at PrtgAPI.PowerShell.Base.PrtgCmdlet.ExecuteWithCoreState(Action action)
   at System.Management.Automation.CommandProcessor.ProcessRecord()

PS C:\Windows\system32> get-culture

(get-culture).numberformat

LCID             Name             DisplayName                                                                                                                                                        
----             ----             -----------                                                                                                                                                        
1043             nl-NL            Dutch (Netherlands)                                                                                                                                                

CurrencyDecimalDigits    : 2
CurrencyDecimalSeparator : ,
IsReadOnly               : False
CurrencyGroupSizes       : {3}
NumberGroupSizes         : {3}
PercentGroupSizes        : {3}
CurrencyGroupSeparator   : .
CurrencySymbol           : €
NaNSymbol                : NaN
CurrencyNegativePattern  : 12
NumberNegativePattern    : 1
PercentPositivePattern   : 0
PercentNegativePattern   : 0
NegativeInfinitySymbol   : -Infinity
NegativeSign             : -
NumberDecimalDigits      : 2
NumberDecimalSeparator   : ,
NumberGroupSeparator     : .
CurrencyPositivePattern  : 2
PositiveInfinitySymbol   : Infinity
PositiveSign             : +
PercentDecimalDigits     : 2
PercentDecimalSeparator  : ,
PercentGroupSeparator    : .
PercentSymbol            : %
PerMilleSymbol           : ‰
NativeDigits             : {0, 1, 2, 3...}
DigitSubstitution        : None

RAW XML Output from PRTG: from url: https://someprtg/api/historicdata.xml?id=51483&edate=2021-06-04-11-31-08&sdate=2020-06-04-11-28-54&avg=2678400&sortby=-datetime&coun t=500&username=redacted&passhash=redacted


<?xml version="1.0" encoding="UTF-8"?>
  <histdata totalcount="11" listend="1">
   <prtg-version>21.2.67.1562</prtg-version>
   <item>
    <datetime>04/13/2021 02:00:00 AM - 02:00:00 AM</datetime>
    <datetime_raw>44330.0000000000</datetime_raw>
    <value channel="Free Space" channelid="2">82,3240949494904 %</value>
    <value_raw channel="Free Space" channelid="2">82.3241</value_raw>
    <value channel="Free Bytes" channelid="3">240.212.948.933 Byte</value>
    <value_raw channel="Free Bytes" channelid="3">240212948932.6976</value_raw>
    <value channel="Total Provisioned" channelid="4">18,99902962963 %</value>
    <value_raw channel="Total Provisioned" channelid="4">18.9990</value_raw>
    <value channel="Uncommitted Bytes" channelid="5">3.860.859.122 Byte</value>
    <value_raw channel="Uncommitted Bytes" channelid="5">3860859122.1470</value_raw>
    <value channel="Available Capacity" channelid="6">291.789.340.672 Byte</value>
    <value_raw channel="Available Capacity" channelid="6">291789340672.0000</value_raw>
    <value channel="Accessible (Yes)" channelid="7">100 %</value>
    <value_raw channel="Accessible (Yes)" channelid="7">4294972751</value_raw>
    <value channel="Downtime" channelid="-4">0 %</value>
    <value_raw channel="Downtime" channelid="-4">0.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>03/13/2021 01:00:00 AM - 02:00:00 AM</datetime>
    <datetime_raw>44299.0000000000</datetime_raw>
    <value channel="Free Space" channelid="2">82,7615973589999 %</value>
    <value_raw channel="Free Space" channelid="2">82.7616</value_raw>
    <value channel="Free Bytes" channelid="3">241.489.240.071 Byte</value>
    <value_raw channel="Free Bytes" channelid="3">241489240071.3339</value_raw>
    <value channel="Total Provisioned" channelid="4">18,9993961504032 %</value>
    <value_raw channel="Total Provisioned" channelid="4">18.9994</value_raw>
    <value channel="Uncommitted Bytes" channelid="5">5.138.220.187 Byte</value>
    <value_raw channel="Uncommitted Bytes" channelid="5">5138220186.8138</value_raw>
    <value channel="Available Capacity" channelid="6">291.789.340.672 Byte</value>
    <value_raw channel="Available Capacity" channelid="6">291789340672.0000</value_raw>
    <value channel="Accessible (Yes)" channelid="7">100 %</value>
    <value_raw channel="Accessible (Yes)" channelid="7">4294972764</value_raw>
    <value channel="Downtime" channelid="-4">0 %</value>
    <value_raw channel="Downtime" channelid="-4">0.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>02/10/2021 01:00:00 AM - 01:00:00 AM</datetime>
    <datetime_raw>44268.0000000000</datetime_raw>
    <value channel="Free Space" channelid="2">82,5293095024627 %</value>
    <value_raw channel="Free Space" channelid="2">82.5293</value_raw>
    <value channel="Free Bytes" channelid="3">240.811.757.871 Byte</value>
    <value_raw channel="Free Bytes" channelid="3">240811757870.9314</value_raw>
    <value channel="Total Provisioned" channelid="4">19,0000038099501 %</value>
    <value_raw channel="Total Provisioned" channelid="4">19.0000</value_raw>
    <value channel="Uncommitted Bytes" channelid="5">4.462.569.158 Byte</value>
    <value_raw channel="Uncommitted Bytes" channelid="5">4462569157.8698</value_raw>
    <value channel="Available Capacity" channelid="6">291.789.340.672 Byte</value>
    <value_raw channel="Available Capacity" channelid="6">291789340672.0000</value_raw>
    <value channel="Accessible (Yes)" channelid="7">100 %</value>
    <value_raw channel="Accessible (Yes)" channelid="7">4294972758</value_raw>
    <value channel="Downtime" channelid="-4">0 %</value>
    <value_raw channel="Downtime" channelid="-4">0.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>01/10/2021 01:00:00 AM - 01:00:00 AM</datetime>
    <datetime_raw>44237.0000000000</datetime_raw>
    <value channel="Free Space" channelid="2">82,2239999999924 %</value>
    <value_raw channel="Free Space" channelid="2">82.2240</value_raw>
    <value channel="Free Bytes" channelid="3">239.921.528.832 Byte</value>
    <value_raw channel="Free Bytes" channelid="3">239921528832.0000</value_raw>
    <value channel="Total Provisioned" channelid="4">19 %</value>
    <value_raw channel="Total Provisioned" channelid="4">19.0000</value_raw>
    <value channel="Uncommitted Bytes" channelid="5">3.572.501.921 Byte</value>
    <value_raw channel="Uncommitted Bytes" channelid="5">3572501921.0000</value_raw>
    <value channel="Available Capacity" channelid="6">291.789.340.672 Byte</value>
    <value_raw channel="Available Capacity" channelid="6">291789340672.0000</value_raw>
    <value channel="Accessible (Yes)" channelid="7">100 %</value>
    <value_raw channel="Accessible (Yes)" channelid="7">4294972746</value_raw>
    <value channel="Downtime" channelid="-4">0 %</value>
    <value_raw channel="Downtime" channelid="-4">0.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>12/10/2020 01:00:00 AM - 01:00:00 AM</datetime>
    <datetime_raw>44206.0000000000</datetime_raw>
    <value channel="Free Space" channelid="2">82,2248305505398 %</value>
    <value_raw channel="Free Space" channelid="2">82.2248</value_raw>
    <value channel="Free Bytes" channelid="3">239.923.270.150 Byte</value>
    <value_raw channel="Free Bytes" channelid="3">239923270149.5451</value_raw>
    <value channel="Total Provisioned" channelid="4">18,9991699007231 %</value>
    <value_raw channel="Total Provisioned" channelid="4">18.9992</value_raw>
    <value channel="Uncommitted Bytes" channelid="5">3.572.501.921 Byte</value>
    <value_raw channel="Uncommitted Bytes" channelid="5">3572501921.0000</value_raw>
    <value channel="Available Capacity" channelid="6">291.789.340.672 Byte</value>
    <value_raw channel="Available Capacity" channelid="6">291789340672.0000</value_raw>
    <value channel="Accessible (Yes)" channelid="7">100 %</value>
    <value_raw channel="Accessible (Yes)" channelid="7">4294972728</value_raw>
    <value channel="Downtime" channelid="-4">0 %</value>
    <value_raw channel="Downtime" channelid="-4">0.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>11/09/2020 01:00:00 AM - 01:00:00 AM</datetime>
    <datetime_raw>44175.0000000000</datetime_raw>
    <value channel="Free Space" channelid="2">82,2249999999963 %</value>
    <value_raw channel="Free Space" channelid="2">82.2250</value_raw>
    <value channel="Free Bytes" channelid="3">239.924.460.743 Byte</value>
    <value_raw channel="Free Bytes" channelid="3">239924460742.9065</value_raw>
    <value channel="Total Provisioned" channelid="4">18,9990000000004 %</value>
    <value_raw channel="Total Provisioned" channelid="4">18.9990</value_raw>
    <value channel="Uncommitted Bytes" channelid="5">3.572.501.959 Byte</value>
    <value_raw channel="Uncommitted Bytes" channelid="5">3572501959.1799</value_raw>
    <value channel="Available Capacity" channelid="6">291.789.340.672 Byte</value>
    <value_raw channel="Available Capacity" channelid="6">291789340672.0000</value_raw>
    <value channel="Accessible (Yes)" channelid="7">100 %</value>
    <value_raw channel="Accessible (Yes)" channelid="7">4294972744</value_raw>
    <value channel="Downtime" channelid="-4">0 %</value>
    <value_raw channel="Downtime" channelid="-4">0.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>10/09/2020 02:00:00 AM - 01:00:00 AM</datetime>
    <datetime_raw>44144.0000000000</datetime_raw>
    <value channel="Free Space" channelid="2">82,2232721275537 %</value>
    <value_raw channel="Free Space" channelid="2">82.2233</value_raw>
    <value channel="Free Bytes" channelid="3">239.919.239.028 Byte</value>
    <value_raw channel="Free Bytes" channelid="3">239919239027.9389</value_raw>
    <value channel="Total Provisioned" channelid="4">19,0007278724541 %</value>
    <value_raw channel="Total Provisioned" channelid="4">19.0007</value_raw>
    <value channel="Uncommitted Bytes" channelid="5">3.572.501.966 Byte</value>
    <value_raw channel="Uncommitted Bytes" channelid="5">3572501966.3917</value_raw>
    <value channel="Available Capacity" channelid="6">291.789.340.672 Byte</value>
    <value_raw channel="Available Capacity" channelid="6">291789340672.0000</value_raw>
    <value channel="Accessible (Yes)" channelid="7">100 %</value>
    <value_raw channel="Accessible (Yes)" channelid="7">4294986486</value_raw>
    <value channel="Downtime" channelid="-4">0 %</value>
    <value_raw channel="Downtime" channelid="-4">0.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>09/08/2020 02:00:00 AM - 02:00:00 AM</datetime>
    <datetime_raw>44113.0000000000</datetime_raw>
    <value channel="Free Space" channelid="2">82,2229999999982 %</value>
    <value_raw channel="Free Space" channelid="2">82.2230</value_raw>
    <value channel="Free Bytes" channelid="3">239.918.383.104 Byte</value>
    <value_raw channel="Free Bytes" channelid="3">239918383104.0000</value_raw>
    <value channel="Total Provisioned" channelid="4">19,0009999999932 %</value>
    <value_raw channel="Total Provisioned" channelid="4">19.0010</value_raw>
    <value channel="Uncommitted Bytes" channelid="5">3.572.501.966 Byte</value>
    <value_raw channel="Uncommitted Bytes" channelid="5">3572501966.0000</value_raw>
    <value channel="Available Capacity" channelid="6">291.789.340.672 Byte</value>
    <value_raw channel="Available Capacity" channelid="6">291789340672.0000</value_raw>
    <value channel="Accessible (Yes)" channelid="7">100 %</value>
    <value_raw channel="Accessible (Yes)" channelid="7">4294989019</value_raw>
    <value channel="Downtime" channelid="-4">0 %</value>
    <value_raw channel="Downtime" channelid="-4">0.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>08/08/2020 02:00:00 AM - 02:00:00 AM</datetime>
    <datetime_raw>44082.0000000000</datetime_raw>
    <value channel="Free Space" channelid="2"/>
    <value channel="Free Bytes" channelid="3"/>
    <value channel="Total Provisioned" channelid="4"/>
    <value channel="Uncommitted Bytes" channelid="5"/>
    <value channel="Available Capacity" channelid="6"/>
    <value channel="Accessible (Yes)" channelid="7"/>
    <value channel="Downtime" channelid="-4"/>
    <coverage>0 %</coverage>
    <coverage_raw>0000000000</coverage_raw>
   </item>
   <item>
    <datetime>07/08/2020 02:00:00 AM - 02:00:00 AM</datetime>
    <datetime_raw>44051.0000000000</datetime_raw>
    <value channel="Free Space" channelid="2"/>
    <value channel="Free Bytes" channelid="3"/>
    <value channel="Total Provisioned" channelid="4"/>
    <value channel="Uncommitted Bytes" channelid="5"/>
    <value channel="Available Capacity" channelid="6"/>
    <value channel="Accessible (Yes)" channelid="7"/>
    <value channel="Downtime" channelid="-4"/>
    <coverage>0 %</coverage>
    <coverage_raw>0000000000</coverage_raw>
   </item>
   <item>
    <datetime>06/07/2020 02:00:00 AM - 02:00:00 AM</datetime>
    <datetime_raw>44020.0000000000</datetime_raw>
    <value channel="Free Space" channelid="2"/>
    <value channel="Free Bytes" channelid="3"/>
    <value channel="Total Provisioned" channelid="4"/>
    <value channel="Uncommitted Bytes" channelid="5"/>
    <value channel="Available Capacity" channelid="6"/>
    <value channel="Accessible (Yes)" channelid="7"/>
    <value channel="Downtime" channelid="-4"/>
    <coverage>0 %</coverage>
    <coverage_raw>0000000000</coverage_raw>
   </item>
  </histdata>
lordmilko commented 3 years ago

Hi @solipsist01,

I can confirm this is a bug; I would say this is a bug that has always been there and wasn't specifically introduced in one version or another.

I have pushed a new build which should hopefully resolve this issue. Can you please try it out via the manual installation instructions?

Thanks for all your patience with this; there have been at least three incidents where separate people that have experienced issues with this feature; with each new issue that pops up I add several new unit tests to cover those edge cases; there are only so many edge cases you can have, so at some point there will finally be no more issues! Right? :P In any case, the crazy value combinations your PRTG server spits out are really helping to solidify this feature.

Regards, lordmilko

solipsist01 commented 3 years ago

Hi @lordmilko

I already tested the new build. The bug has vanished ;) Thank you !

Perhaps we now have reached the point of no more issues, indeed ! :) I will keep testing the feature, as the script runs every month to generate new reports, and we keep adding more and more.

At some point, perfection will be reality indeed :)