How can I use Longview to check the kernels my Linodes are running?
Linode
Linode Staff
I'm looking for any simple export options for Longview. In this case, I'm looking to make a report showing all version of the Linux kernel are in use on our account. Longview shows this information but I have to click each VM individually. Thanks!
1 Reply
rl0nergan
Linode Staff
The first thing you'll want to do is obtain the API key for each of your Longview clients. The easiest way to do this is via the Linode API and some jq magic to get a list the API keys. The commands below should return an array containing the Longview API key for each of your Longview clients. It will then loop over each Longview API key and return the hostname and kernel the associate Linode is running.
TOKEN=<InsertLinodeAPITokenHere>
# Gets all the Longview API tokens and stores them in an array
a=($(curl -sH "Authorization: Bearer $TOKEN" \
https://api.linode.com/v4/longview/clients \
| jq -r '.data[].api_key'))
# Loops through that array to return the hostname and kernel of each client
for i in "${a[@]}"
do curl -sX POST https://longview.linode.com/fetch \
-F "api_key=$i" \
-F "api_action=getLatestValue" \
-F 'keys=["SysInfo.*"]' | jq '.[0].DATA.SysInfo.hostname, .[0].DATA.SysInfo.kernel'
done