[SOLVED] Determining node status in shell

Jan 25, 2022
44
6
13
Ireland
Other than checking ping, is there a another more reliable method using Prox API to determine if a specific node is alive or dead?

I was hoping that pvecm had an option to poll specific nodes with pvecm status, but it only provides the overview. I am writing an if-fi that will determine which node the script will execute dependent on the status of the other nodes to avoid executing the same commands multiple times. I can do this with ping, but thought there must be another method that's Prox native.
 
you can use the 'pvesh' cli for example, namely you can use any api path there,
if you have a cluster you can get the status for all with:

Code:
pvesh get /cluster/status
 
you can use the 'pvesh' cli for example, namely you can use any api path there,
if you have a cluster you can get the status for all with:

Code:
pvesh get /cluster/status
Thanks Dominik

Would you know of another method of pulling the 1/0 values from the API? I can do it with this bit of code -
pvesh get /cluster/status --human-readable --noborder | awk '(NR!=1)'| awk '{printf " %s\n", $7}'|sort

but I'd prefer a one-liner that will echo 1 or 0 of an individual node when the online boolean is queried. I am in the API-Viewer now and the online boolean isn't a listed option under pvesh get /nodes/{node}/status
 
if a node is not online, you'll not be able to reach it via /nodes/{node}/status since that request is proxied to the target node
which would make the request (an expensive) ping

but you can use some json tooling(e.g. jq) for pvesh like this:

Code:
pvesh get /cluster/status --output-format json | jq '.[] | select(.name == "NODENAME") | .online'
 
  • Like
Reactions: b.miller

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!