PrtgAPI
PrtgAPI copied to clipboard
startIndex cannot be larger than length of string.
Describe the bug
When running the script I am getting the error somewhere in the middle,
get-sensorhistory : startIndex cannot be larger than length of string.
Parameter name: startIndex
At C:\Powershell_Scripts\Postgres\Eurogate\history_new.ps1:27 char:114
+ ... lyContinue |get-sensorhistory -Enddate $Enddate -Startdate $Startdate ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-SensorHistory], ArgumentOutOfRangeException
+ FullyQualifiedErrorId : System.ArgumentOutOfRangeException,PrtgAPI.PowerShell.Cmdlets.GetSensorHistory
any Idea why=
Steps to reproduce
`$Enddate='2022-03-18 12:00:00'
$Startdate='2022-03-18 23:59:59'
#------------Get Data SNMP Traffic-----------------------------------
get-sensor -tag tableau -type snmptraffic,snmpdiskfree,snmpcpu,ping -status up -ErrorAction SilentlyContinue |get-sensorhistory -Enddate $Enddate -Startdate $Startdate | Select-Object -Property DateTime,SensorId,'TrafficIn(volume)','TrafficIn(speed)','TrafficOut(volume)','TrafficOut(speed)',FreeSpace,Total,PacketLoss | Export-csv -Path C:\Powershell_Scripts\Postgres\Eurogate\data\export.csv -Delimiter ";" -NoTypeInformation
What is the output of 'Get-PrtgClient -Diagnostic'?
PSVersion : 5.1.17763.2268
PSEdition : Desktop
OS : Microsoft Windows Server 2019 Standard
PrtgAPIVersion : 0.9.17
Culture : de-DE
CLRVersion : .NET Framework 4.8 (528049)
PrtgVersion : 21.3.70.1629
PrtgLanguage : english.lng
Additional context
No response
Hi @cyberoner1,
After reproducing the error can you please provide the output of $error[0].Exception.StackTrace
sorry for the late reply.. here is the output:
$error[0].Exception.StackTrace
at System.String.Substring(Int32 startIndex, Int32 length)
at PrtgAPI.Utilities.ConvertUtilities.TryRoundDecimal(String str, Double raw, Func2 toDecimal, String numDecStr, String strDecStr, Double& result) 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.<Format>d__10.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()
Thanks @cyberoner1,
Can you also do the following:
First do
Set-PrtgClient -LogLevel Response
then invite Get-SensorHistory
again, specifying the -Verbose
parameter
get-sensor -tag tableau -type snmptraffic,snmpdiskfree,snmpcpu,ping -status up -ErrorAction SilentlyContinue |get-sensorhistory -Enddate $Enddate -Startdate $Startdate -Verbose
assuming it still crashes can you please provide a copy of the response that is emitted
Hi @cyberoner1,
Just following up on this, are you able to advise?
Hi @lordmilko, I've actually had this same issue for a long time and just happened to see this open issue now. It happens on maybe 3 or 4 sensors out of around 300, with which ones fail changing week to week (I guess as underlying data changes). I've attached all the same output requested with a failing sensor. Hopefully this helps.
Commands: $current_date = Get-Date $sensor = Get-Sensor -Id 60010 $sensor | Get-SensorHistory -StartDate $current_date -EndDate $current_date.AddDays(-2) -Average 3600 -Verbose
Hi @squintfox,
Thanks for providing these logs. I have pushed a commit which I believe should contain a fix for this issue. Are you able to test PrtgAPI 0.9.18-preview.5 by following the manual installation instructions and advise whether the issue is now resolved?
@lordmilko it looks like it's working great. Thank you.