Archives par mot-clé : nagios

Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!

Si vous utilisez nagios et que vous êtes confrontés a cette erreur lorsque vous souhaitez effectuer une opération a partir de l’interface web de nagios, cela est du aux droits du fichier. Si on regarde d’un peu plus près:

/usr/local/nagios/var/rw# ls -l
total 0
prw-rw---- 1 nagios nagios 0 11 sept. 14:32 nagios.cmd

On constate que le fichier ne peut être manipulé que pas l’utilisateur nagios. Or lorsque l’on utilise l’interface web, c’est l’utilisateur www-data qui est utilisé. Il faut donc mettre a jours les droits sur le fichier. Le problème c’est que ce fichier est recréé a chaque démarrage de nagios. On modifie donc le fichier /etc/init.d/nagios de façon a changer les droits sur le fichier lors de sa création:

[...]

case "$1" in

        start)
                echo -n "Starting nagios:"
                $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
                if [ $? -eq 0 ]; then
                        su - $NagiosUser -c "touch $NagiosVarDir/nagios.log $NagiosRetentionFile"
                        rm -f $NagiosCommandFile
                        touch $NagiosRunFile
                        chown $NagiosUser:$NagiosGroup $NagiosRunFile
                        $NagiosBin -d $NagiosCfgFile
                        if [ -d $NagiosLockDir ]; then touch $NagiosLockDir/$NagiosLockFile; fi

                        # added by bux
                        chmod 770 $NagiosCommandFile
                        chown nagios:www-data $NagiosCommandFile
                        # end added by bux

                        echo " done."
                        exit 0
                else
                        echo "CONFIG ERROR!  Start aborted.  Check your Nagios configuration."
                        exit 1
                fi
                ;;


[...]

Et voilà !

If you have this error when you use webUI of nagios, you have to modify rights of this file

/usr/local/nagios/var/rw# ls -l
total 0
prw-rw---- 1 nagios nagios 0 11 sept. 14:32 nagios.cmd

Web interface execute this file with ‘www-data’ user. So we have to edit permissions of this file. But, nagios.cmd is created by nagios when he start. So we have to edit the init script of nagios:

[...]

case "$1" in

        start)
                echo -n "Starting nagios:"
                $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
                if [ $? -eq 0 ]; then
                        su - $NagiosUser -c "touch $NagiosVarDir/nagios.log $NagiosRetentionFile"
                        rm -f $NagiosCommandFile
                        touch $NagiosRunFile
                        chown $NagiosUser:$NagiosGroup $NagiosRunFile
                        $NagiosBin -d $NagiosCfgFile
                        if [ -d $NagiosLockDir ]; then touch $NagiosLockDir/$NagiosLockFile; fi

                        # added by bux
                        chmod 770 $NagiosCommandFile
                        chown nagios:www-data $NagiosCommandFile
                        # end added by bux

                        echo " done."
                        exit 0
                else
                        echo "CONFIG ERROR!  Start aborted.  Check your Nagios configuration."
                        exit 1
                fi
                ;;


[...]

Et woilà !