0

I am using Two VM.

First : Ubuntu 14.04.3 LTS (192.168.1.102)

Second : CentOS 7 (192.168.1.105)

On 192.168.1.102 I have Nagios Core v4.1.1, NagiosQL v3.2.0 and NRPE v2.15 are installed.

On 192.168.1.105 I have Apache Apollo and NRPE v2.15 are installed.

I already add 192.168.1.105 Host to Nagios Monitoring Server(192.168.1.102) Using NRPE Plugin using below link

http://www.tecmint.com/how-to-add-linux-host-to-nagios-monitoring-server/

I am able to check Apache Apollo service is running or not on 192.168.1.105(Nagios Monitoring Server) using below script from 192.168.1.102

#!/bin/bash

if pidof -x "apollo" >/dev/null; then
echo "Apollo MQTT is Running."
exit 0
else
echo "Apollo MQTT is Stopped."
exit 2
fi

But I want that if My Apache Apollo service is not running then I want to run this service. For this I modified the above script as below

#!/bin/bash

if pidof -x "apollo" >/dev/null; then
echo "Apollo MQTT is Running."
exit 0
else
echo "Apollo MQTT is Stopped."
servicestatus=sudo /etc/init.d/apollo-broker-service start
$servicestatus
exit 2
fi

But when i try to run this script from 192.168.1.102 Nagios using below command

/usr/local/nagios/libexec/check_nrpe -H 192.168.1.105 -c check_service_apollomqtt

then output is below

Apollo MQTT is Stopped.
Starting apollo-broker-service
Could not start apollo-broker-service

I already add the below line in my 192.168.1.105 /etc/sudoers file

nagios ALL = NOPASSWD: /usr/sbin/service
user3441151
  • 1,880
  • 6
  • 35
  • 79

1 Answers1

0

Your script is not using the service command at all.

  1. Use 'which service' and make certain it is '/usr/sbin/service'. Mine is located in a different folder.
  2. Make certain that path/command from above is set correctly in your /etc/sudoers file.
  3. Then modify your script to actually use the 'service' command, like:

$servicestatus=sudo /sbin/service apollo-broker-service start

Jim Black
  • 1,422
  • 1
  • 13
  • 26