1

I created check in KVM virtualized host to get list of available VM's in KVM hypervisor using below command.

$ cat /usr/local/nagios/libexec/check_kvm
#!/bin/sh
val=`virsh list --all | sed '1,2d' | sed '/^$/d'| awk '{print $2":"$3}'`
echo "VM List is" - $val
exit 0

Executing the script locally fetch the data as below.

# sh /usr/local/nagios/libexec/check_kvm

VM List is - oy06b:running .......

While, fetching the data from nagios server using nrpe, I am unable to get VM list. I am getting as below "VM List is" and $val is not showing.

/usr/local/nagios/libexec/check_nrpe -H <Host IP> -c check_kvm

VM List is -

Please advice....

Paul Jany Godwin
  • 81
  • 1
  • 1
  • 8
  • Please show what the desired output should be. Your line can simply be converted to `virsh list --all | awk 'NR>2 && NF{print $2":"$3}'` No need for sed there. virsh also has the `virsh list --all --name --state-shutoff --state-running` etc... – Valentin Bajrami Apr 08 '17 at 10:21

1 Answers1

1

Executing the tool virsh requires root privileges and this is what you are actually doing when executing it directly from the shell.

However, it is executed as nagios user when run via NRPE daemon. To fix this, you need to add sudo to command definition in nrpe.cfg:

command[check_kvm]=sudo /usr/local/nagios/libexec/check_kvm

And add nagios user to sudoers file to allow executing this command/script without asking for a password:

nagios  ALL = NOPASSWD: /usr/local/nagios/libexec/check_kvm
Khaled
  • 36,533
  • 8
  • 72
  • 99