Enhanced Security Measures in Place:   To ensure a safer experience, we’ve implemented additional, temporary security measures for all users.

host inventory - Disk Space XQL - bytes conversion not possible because of string - to_number?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

host inventory - Disk Space XQL - bytes conversion not possible because of string - to_number?

L4 Transporter

Hello dear community, 

 

how can we get this use case running? I need to know which disk is running lower than 5 GB. 

In my case I have a conversion problem, because the field free_space is a string. How can I convert it to a number, so I can divide it to GB?

 

config case_sensitive = false
|dataset = host_inventory
| arrayexpand disks
| alter disks = json_extract(disks, "$.name"), free_space = json_extract(disks, "$.free_space"), size = json_extract(disks, "$.size")

//| alter free_space_KB = divide(free_space, 1024) // convert bytes to KB
//| alter free_space_MB = divide(free_space_KB, 1024) // convert KB to MB
//| alter free_space_GB = divide(free_space_MB, 1024) // convert MB to GB
//|alter total_upload_GB_rounded = round(free_space_GB)
//| filter applications contains $Software

| fields host_name, disks , free_space, size, ip_addresses
| sort desc free_space

 

I have also seen, that the fields are all strings and I cannot do any calculations <>. 

 

 

BR

 

Rob

 

1 accepted solution

Accepted Solutions

L2 Linker

Rob,

 

You can use the to_integer() function available in XQL to convert a string to an integer.

 

config case_sensitive = false
| dataset = host_inventory
| arrayexpand disks
| alter disks = json_extract(disks, "$.name"), free_space = to_integer(json_extract(disks, "$.free_space")), size = json_extract(disks, "$.size")
| alter free_space_KB = divide(free_space, 1024) // convert bytes to KB
| alter free_space_MB = divide(free_space_KB, 1024) // convert KB to MB
| alter free_space_GB = divide(free_space_MB, 1024) // convert MB to GB
| filter free_space_GB < 5

 

Hope this helps!

 

Tyler

View solution in original post

2 REPLIES 2

L2 Linker

Rob,

 

You can use the to_integer() function available in XQL to convert a string to an integer.

 

config case_sensitive = false
| dataset = host_inventory
| arrayexpand disks
| alter disks = json_extract(disks, "$.name"), free_space = to_integer(json_extract(disks, "$.free_space")), size = json_extract(disks, "$.size")
| alter free_space_KB = divide(free_space, 1024) // convert bytes to KB
| alter free_space_MB = divide(free_space_KB, 1024) // convert KB to MB
| alter free_space_GB = divide(free_space_MB, 1024) // convert MB to GB
| filter free_space_GB < 5

 

Hope this helps!

 

Tyler

Thank you tyler! I took the wrong datatype :/.

 

BR

 

Rob

  • 1 accepted solution
  • 1582 Views
  • 2 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!