2

This script I have here works locally just fine:

#! /bin/bash
volts=`sudo vcgencmd measure_volts core|sed 's/volt=\([0-9\.]*\)V/\1/'`
echo -n "BCM2835 SoC Voltage is ${volts}V "
echo "| volts=$volts;1.5;1.5;0;1.5"

However if Nagios tries to get the information it only gets "BCM2835 SoC Voltage is V" as if the variable was not defined.

There are also other plugins which pull the information from files and it works. So I managend to write the information in a temp file and write it back into the variable.

#! /bin/bash
sudo vcgencmd measure_volts core|sed 's/volt=\([0-9\.]*\)V/\1/'>/tmp/volts
volts=$(</tmp/volts)
echo -n "BCM2835 SoC Voltage is ${volts}V "
echo "| volts=$volts;1.5;1.5;0;1.5"

Now I am able to see the value in Nagios, but why does this only work locally and not remotely? Is it possible to make it without a temp file?

3

The user that Nagios runs as requires sudo rights just like with your normal account. You can use a command like this to see what sudo right a user has:

 $ su - nagios -c "sudo -l"
Matching Defaults entries for nagios on this host:
    requiretty, !visiblepw, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS MAIL PS1 PS2 QTDIR USERNAME LANG
    LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME
    LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", !requiretty

User nagios may run the following commands on this host:
    (root) NOPASSWD: /etc/init.d/nagios* restart
    (root) NOPASSWD: /etc/init.d/nagios restart
    (root) NOPASSWD: /etc/init.d/nagios* reload
    (root) NOPASSWD: /etc/init.d/nagios reload
    (root) NOPASSWD: /usr/bin/nagios* -v *
    (root) NOPASSWD: /usr/bin/nagios -v *
    (root) NOPASSWD: /usr/bin/nagios* -s *
    (root) NOPASSWD: /usr/bin/nagios -s *
    (root) NOPASSWD: /etc/init.d/snmptrapd restart
    (root) NOPASSWD: /etc/init.d/centstorage restart
    (root) NOPASSWD: /etc/init.d/centstorage stop
    (root) NOPASSWD: /etc/init.d/centstorage start

Assuming that Nagios has sudo rights to run your volts command, vcgencmd measure_volts, you'll also want to make sure that the sudo rights are similar to the ones above where Nagios can run the command as root and that no password is requied (NOPASSWD). Something like this in your /etc/sudoers file should do:

nagios   ALL = NOPASSWD: /path/to/vcgencmd measure_volts core

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.