Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-SensorHistory produces an unexpected error: Input string was not in a correct format. #123

Closed
robm82 opened this issue Dec 6, 2019 · 7 comments
Labels
bug Issues that have been confirmed to be bugs in PrtgAPI and will be fixed in a future version

Comments

@robm82
Copy link

robm82 commented Dec 6, 2019

I am trying to write a script to get disk space usage over the past 30 days, which does work but on a handful of sensors I get a weird error. I have also tried to use Get-SensorHistory -id 11079 which again produces the same error, so I know that it isn't my script, but there appears to be something wrong with the PrtgAPI PowerShell module? Below is the full output:

PS C:\> Get-SensorHistory -Id 11079
Get-SensorHistory : Input string was not in a correct format.
At line:1 char:1
+ Get-SensorHistory -Id 11079
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-SensorHistory], FormatExc
   eption
    + FullyQualifiedErrorId : System.FormatException,PrtgAPI.PowerShell.Cmdlet
   s.GetSensorHistory

Here is the output of Get-PrtgClient -Diagnostic:

PSVersion      : 5.1.18362.145
PSEdition      : Desktop
OS             : Microsoft Windows 10 Enterprise
PrtgAPIVersion : 0.9.10
Culture        : en-GB
CLRVersion     : .NET Framework 4.8 (528040)
PrtgVersion    : 19.4.54.1506
PrtgLanguage   : english.lng
@robm82 robm82 added the alleged-bug Bugs raised by people helpfully using the Bug Report template! label Dec 6, 2019
@lordmilko
Copy link
Owner

Hi @robm82,

Can you please run the following commands and provide the output

Set-PrtgClient -LogLevel Response
Get-SensorHistory -Id 11079 -Verbose
$error[0].Exception.StackTrace

Regards,
lordmilko

@robm82
Copy link
Author

robm82 commented Dec 6, 2019

Thanks for the quick response @lordmilko :). Below is the output of those commands:

Set-PrtgClient -LogLevel Response
PS C:\> Get-SensorHistory -Id 11079 -Verbose
VERBOSE: Get-SensorHistory: <?xml version="1.0" encoding="UTF-8"?>
  <histdata totalcount="12" listend="1">
   <prtg-version>19.4.54.1506</prtg-version>
   <item>
    <datetime>06/12/2019 08:07:58</datetime>
    <datetime_raw>43805.3388659144</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>06/12/2019 08:02:58</datetime>
    <datetime_raw>43805.3353939468</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>06/12/2019 07:57:58</datetime>
    <datetime_raw>43805.3319217361</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>06/12/2019 07:52:58</datetime>
    <datetime_raw>43805.3284495833</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>06/12/2019 07:47:58</datetime>
    <datetime_raw>43805.3249774653</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>06/12/2019 07:42:58</datetime>
    <datetime_raw>43805.3215054051</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>06/12/2019 07:37:58</datetime>
    <datetime_raw>43805.3180330903</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>06/12/2019 07:32:58</datetime>
    <datetime_raw>43805.3145609028</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>06/12/2019 07:27:58</datetime>
    <datetime_raw>43805.3110888889</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>06/12/2019 07:22:58</datetime>
    <datetime_raw>43805.3076167361</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
   </item>
   <item>
    <datetime>06/12/2019 07:17:58</datetime>
    <datetime_raw>43805.3041442477</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>06/12/2019 07:12:58</datetime>
    <datetime_raw>43805.3006716088</datetime_raw>
    <value channel="Free Space" channelid="0">19 %</value>
    <value_raw channel="Free Space" channelid="0">19.1276</value_raw>
    <value channel="Free Bytes" channelid="1">364,703 MByte</value>
    <value_raw channel="Free Bytes"
channelid="1">382418821120.0000</value_raw>
    <value channel="Total" channelid="2">1,906,683 MByte</value>
    <value_raw channel="Total" channelid="2">1999302324224.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
  </histdata>
Get-SensorHistory : Input string was not in a correct format.
At line:1 char:1
+ Get-SensorHistory -Id 11079 -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-SensorHistory], FormatExc
   eption
    + FullyQualifiedErrorId : System.FormatException,PrtgAPI.PowerShell.Cmdlet
   s.GetSensorHistory

PS C:\> $error[0].Exception.StackTrace
   at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
   at PrtgAPI.Utilities.ConvertUtilities.ToDouble(String s)
   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 PrtgAPI.PowerShell.Base.PrtgProgressCmdlet.WriteList[T](IEnumerable`1 sendToPipeline)
   at PrtgAPI.PowerShell.Cmdlets.GetSensorHistory.ProcessRecordEx()
   at PrtgAPI.PowerShell.Base.PrtgCmdlet.ExecuteWithCoreState(Action action)
   at System.Management.Automation.CommandProcessor.ProcessRecord()

@lordmilko lordmilko added bug Issues that have been confirmed to be bugs in PrtgAPI and will be fixed in a future version and removed alleged-bug Bugs raised by people helpfully using the Bug Report template! labels Dec 6, 2019
@lordmilko
Copy link
Owner

In an attempt to make Get-SensorHistory smarter about dealing with periods and commas that could either represent periods or thousands separators, I've inadvertently caused another issue.

While I figure out a solution to this, are you able to advise whether the command Get-SensorHistory -Id 11079 -Raw works? This will display the channel values in their raw units (e.g. bytes for something normally displayed in megabytes) and should bypass the code that is having an issue

@robm82
Copy link
Author

robm82 commented Dec 6, 2019

Yes that command does work - thanks for verifying and providing a workaround.

lordmilko added a commit that referenced this issue Dec 7, 2019
…r than 1,000,000 (#123)

-Redesigned Get-SensorHistory display value converter to be more robust at deciphering whether a value is a US or EU number format
-Added additional tests for current ConvertUtilities.ToDouble implementation
@lordmilko
Copy link
Owner

Hi @robm82,

I have now pushed a release candidate for PrtgAPI 0.9.11, which contains a fix for this issue

Are you able to potentially download the latest build and follow the manual installation steps to confirm whether the command Get-SensorHistory -Id 11079 works?

In addition, it would be helpful if you could potentially get Get-SensorHistory works on all sensors on your PRTG server, just in case there are any more corner cases my fix did not address

Get-Sensor | Get-SensorHistory

Obviously this may potentially generate some load on your system, although I managed fine on my system with over 8000 sensors. While some sensors may complain they didn't have enough monitoring data, the whole thing will stop if it runs into a channel value it does not know how to parse

Please let me know how you go

Regards,
lordmilko

@robm82
Copy link
Author

robm82 commented Dec 9, 2019

Hi @lordmilko - I have just tested Get-SensorHistory -Id 11079 and it does indeed now work. I ran Get-Sensor | Get-SensorHistory as well, and I didn't get any unusual errors and that is against nearly 7000 sensors.

Thanks again for looking into the issue so quickly.

@lordmilko
Copy link
Owner

Thanks @robm82!

Please be advised PrtgAPI 0.9.11 has now been released. To update your system wide installation simply run Update-Module PrtgAPI and reopen PowerShell

Regards,
lordmilko

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that have been confirmed to be bugs in PrtgAPI and will be fixed in a future version
Projects
None yet
Development

No branches or pull requests

2 participants