- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
Enhanced Security Measures in Place: To ensure a safer experience, we’ve implemented additional, temporary security measures for all users.
09-21-2022 06:45 AM
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
09-21-2022 06:55 AM
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
09-21-2022 06:55 AM
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
09-21-2022 07:17 AM
Thank you tyler! I took the wrong datatype :/.
BR
Rob
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!