You are here

Custom Plugin Check Heartbeat in Linux

6 posts / 0 new
Last post
gergv83
gergv83's picture
Custom Plugin Check Heartbeat in Linux

Hi Guys, 

I create a hand made plugin to monitoring an HA service that is running in my linux environment, basically if I execute the plugin in the linux servers works fine but when I upload it to OpsView libexec directory and then I configure it from the console to monitor a linux server it assume always the following output: WARNING. I think the problem is related that OpsView server runs the script locally and evaluate the status of the service,

I have tried to use parameters like -H %HOSTADDRESS% but still not working, I will appreciate any help cause I'm completly newbie on this.

Thanks in advance.

### BEGIN OPSVIEW INFO

 

# Macros: HOSTNAME,SERVICEDESC ### END OPSVIEW INFO   OK=0 WARNING=1 CRITICAL=2   status=`/etc/init.d/heartbeat status`  if echo "$status" | grep -q running; then    echo "Service HA is running"    exit $OK   elif echo "$status" | grep -a stopped; then    echo "Service HA is stopped"    exit $CRITICAL else   echo "Service HA could not be find"   exit $WARNING fi  
smarsh
smarsh's picture
Re: Custom Plugin Check Heartbeat in Linux

Hi,

Sounds like you want to run this script locally, but on a remote server?

You can do this easily by using NRPE. Simply install the Opsview agent on your HA servers, copy your custom script to libexec on those HA servers, then on the agent - create a .cfg file in "/usr/local/nagios/etc/nrpe_local/" - i have mine called 'overrides.cfg'. This is where you create the commands you want to allow Opsview to run remotely, i.e. your HA script:

check_command[check_HA]=/usr/local/nagios/libexec/check_HA $ARG1$

Let me break this down:

  • [...] - In the square brackets, add a name you want to call this command - i.e. check_HA.
  • =/usr/local - This is the full path to your HA script.
  • $ARG1$ - Leave this in, if your script takes arguements.

Now you have your command, check it works locally. cd to /usr/local/nagios/libexec and run a command such as:

./check_nrpe -H localhost -c check_HA

What we are doing here, is connecting to the NRPE agent on localhost (-H ...) and running the command (-c) 'check_HA' which should invoke your script, and return a value. If this works - then great, your almost there - if not, check the logs and also ensure TCP 5666 is allowed via iptables.

Finally, create a new service check in your Opsview GUI using:

  • Plugin: check_nrpe
  • Arguments: -H $HOSTADDRESS$ -c check_HA

And then apply it to your HA server(s) and you should now be getting results!

Hope this helps,

Sam

gergv83
gergv83's picture
Re: Custom Plugin Check Heartbeat in Linux

Hi Sam,

Thanks for your feedback, I configure the settings that you mention but I'm facing a strang behaviour. 

For example if I ran the script using ./check_HA and Heartbeat service is not running then it displays the correct message "Service HA is running" but if I did the same using ./check_nrpe -H 127.0.0.1 -c check_HA the output message is: "Service HA could not be found"

Have you got any clue that what could be happen?

Thank you!

 

 

smarsh
smarsh's picture
Re: Custom Plugin Check Heartbeat in Linux

Linux permissions - i suspect the nagios user cant run the script. You may need to run it as sudo and add a new line in /etc/sudoers.

gergv83
gergv83's picture
Re: Custom Plugin Check Heartbeat in Linux

Sam,

I think is not related with permissions because I have added nagios user and nagios group to the script using:

chown nagios check_HA

chgrp nagios check_HA

chmod 755 check_HA

any other possible idea?.

 

Thank you again. 

 

smarsh
smarsh's picture
Re: Custom Plugin Check Heartbeat in Linux

Apologies, I might not have phrased it the best.

The nagios user can execute your script. 

But can the nagios user do the command in your script? I.e. can nagios run "Service HA status"? I suspect not.

What you need to do is allow the nagios user to run that command above; i.e. add a line in /etc/sudoers allowing nagios to run 'service HA status' and then run the script/command in the script as 'sudo service..'. That should do it.

Best,

Sam