Ad Widget

Collapse

Convert string to number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zablab
    Junior Member
    • Jan 2022
    • 28

    #1

    Convert string to number

    I'm having a bit of an issue converting a string to a number when pulling some JSON.

    I'm not really familiar with a lot of this, so learning as I go, any help would be greatly appreciated.

    I've got the result I want, which is a number. However even with number type set to float I get the following:
    • Value of type "string" is not suitable for value type "Numeric (float)". Value "10,164.94"
    Here is an example of the JSON string I'm pulling in:

    {"Database Name":"tempdb","Logical Name":"tempdb1","File Group":"PRIMARY","File Path":"T:\\SQLData\\tempdb.mdf","File Size (MB)":"10,240.00","Est Used (MB)":"75.06","Est Free (MB)":"10,164.94","Total Pages":"1,310,720","Total Pages (MB)":"10,240.00","Used Pages":"9,608","Used Pages (MB)":"75.06","Version Store":"488","Version Store (MB)":"3.81","User Objects":"496","User Objects (MB)":"3.88","System Objects":"7,880","System Objects (MB)":"61.56","Mixed Extents":"744","Mixed Extents (MB)":"5.81"}

    I'm trying to extract various Values from this string.

    My first preprocessing step looks like: $["Est Free (MB)"]
    This gives me the value 10,164.94
    However, I get the above mentioned error.

    How would I convert this string using pre-processing into a value\number? I see an option for JavaScript to perhaps convert, but not familiar enough with it to get it working.

    With appreciation,

    Update: I eventually noticed the comma in my result, so I created a replacement for ","

    So far this is allowing me to obtain my value.
    Last edited by Zablab; 03-08-2022, 22:10.
  • dimir
    Zabbix developer
    • Apr 2011
    • 1080

    #2
    By "created a replacement" do you mean you've added a preprocessing rule that removes the comma?

    Comment


    • Zablab
      Zablab commented
      Editing a comment
      Correct, I just added a Replace step to the preprocessing rule to remove the comma, I also made some modifications to the SQL Query so we're pulling in bytes instead of MB so Zabbix has an easier time converting the Units for me.
  • dimir
    Zabbix developer
    • Apr 2011
    • 1080

    #3
    If the value is in Bytes, you can set Units to "B" in item configuration to see a friendly value in "Latest data". :-) Note, this only affects the way the value is displayed in Frontend, it does not affect the way it is stored in the database.
    Last edited by dimir; 10-08-2022, 23:55.

    Comment

    Working...