How can I make a host status down if a certain service running on another host is critical or unknown? I tried service dependency or host dependency, but they dont seem to get the job done. Any help will be highly appreciated.
Thanks
amangb
Host - service dependency
Re: Host - service dependency
Hmmm... I'm not sure how you would accomplish this short of writing an event handler that changes the state of the host.
More importantly I don't understand *why* you would do this, maybe explain the full situation and we might be able to come up with a nicer solution to the problem
.
More importantly I don't understand *why* you would do this, maybe explain the full situation and we might be able to come up with a nicer solution to the problem
Re: Host - service dependency
I'm trying to build an interface for general users that they can go to a certain website and look if a service is down or up (they dont need to know the details nagios provides). For example, if the database service running on a database server is down, I want to make the web server status down, or the web service running on the web server down. That way users would know they cannot access the website, leaving the internal details to the system admin.
Re: Host - service dependency
How are you retrieving that information for the user website? Are you using ndo2db?
It sounds like your best bet is going to be putting this business logic into your actual user view page, that way your admins will see the true status and your customers will see whatever you want. You might also be able to achieve a more native solution with the Nagios BPI plugin though I'm not 100% sure you can do exactly that with it.
It sounds like your best bet is going to be putting this business logic into your actual user view page, that way your admins will see the true status and your customers will see whatever you want. You might also be able to achieve a more native solution with the Nagios BPI plugin though I'm not 100% sure you can do exactly that with it.
Re: Host - service dependency
thanks for your input. I think I may have found part of the solution to my problem. Nagios uses check-Host-alive command to determine if the host is up or down. If I define the host with its own check_command and create host dependency, wouldn't that work? That way if the service on that server is not running, the host will have a DOWN status. For example:
define host{
host_name Webserver
address x.x.x.x
check_command check_http
}
define host{
host_name DB
address x.x.x.x
check_command check_db
}
define hostdependency {
host_name DB
dependent_host_name Webserver
notification_failure_criteria d,u
}
I'm not sure how to make the webserver down if the DB is down though. Still need directions on that.
Thanks
define host{
host_name Webserver
address x.x.x.x
check_command check_http
}
define host{
host_name DB
address x.x.x.x
check_command check_db
}
define hostdependency {
host_name DB
dependent_host_name Webserver
notification_failure_criteria d,u
}
I'm not sure how to make the webserver down if the DB is down though. Still need directions on that.
Thanks
Re: Host - service dependency
well... it's certainly a creative way to solve the problem and you could definitely make that work if your heart is set on going that direction.
What you would probably need to do is create a new command definition for the database check and either statically assign the hostname to the host with the database or you could begin getting cosy with custom macros http://nagios.sourceforge.net/docs/3_0/macros.html. Then all you need to do is set the Host check to that new check command... you won't need a dependency at all. The only problem with this approach is that you will only be able to bind one command to the host, you could create a wrapper script that it runs in the command that performs all the necessary checks to say web-site is up or down to get around that though.
What you would probably need to do is create a new command definition for the database check and either statically assign the hostname to the host with the database or you could begin getting cosy with custom macros http://nagios.sourceforge.net/docs/3_0/macros.html. Then all you need to do is set the Host check to that new check command... you won't need a dependency at all. The only problem with this approach is that you will only be able to bind one command to the host, you could create a wrapper script that it runs in the command that performs all the necessary checks to say web-site is up or down to get around that though.
Re: Host - service dependency
I ended up writing a custom script for the hosts that have a lot of dependency in my network. I wonder if Nagios can come up with a solution for this. Because right now I wrote the scripts for a couple of servers, what if there are tens or hundreds of them. Anyway here is the solution. The first script is called check_dep which will check for one dependency for a host.
#!/bin/bash
DEPENDENT=$1
DPORT=$2
MASTER=$3
MPORT=$4
output=`/usr/local/nagios/libexec/check_tcp -H $MASTER -p $MPORT`
if [ $? -eq 0 ] ; then
output=`/usr/local/nagios/libexec/check_tcp -H $DEPENDENT -p $DPORT`
if [ $? -eq 0 ] ; then
echo "all ok" $output
exit 0
else
printf "dependent host failed"
exit 2
fi
else
echo "master host failed" $output
exit 2
fi
Then you go to your commands.cfg and define the command
define command {
command_name check_web
command_line /usr/local/nagios/custom_commands/check_dep $HOSTADDRESS$ $ARG1$ $ARG2$
}
And finally you'll go to your host defintion
define host{
host_name web
address x.x.x.x
check_command check_web!http_port!your_db_ip_or_fqdn!db_port
}
If you have more dependency, you can expand the check_dep script to check for three hosts and increasing the number of arguments. And you'll supply those hosts on the host definition of the dependent host.
I hope this helps for people who were banging their heads against the wall like me
#!/bin/bash
DEPENDENT=$1
DPORT=$2
MASTER=$3
MPORT=$4
output=`/usr/local/nagios/libexec/check_tcp -H $MASTER -p $MPORT`
if [ $? -eq 0 ] ; then
output=`/usr/local/nagios/libexec/check_tcp -H $DEPENDENT -p $DPORT`
if [ $? -eq 0 ] ; then
echo "all ok" $output
exit 0
else
printf "dependent host failed"
exit 2
fi
else
echo "master host failed" $output
exit 2
fi
Then you go to your commands.cfg and define the command
define command {
command_name check_web
command_line /usr/local/nagios/custom_commands/check_dep $HOSTADDRESS$ $ARG1$ $ARG2$
}
And finally you'll go to your host defintion
define host{
host_name web
address x.x.x.x
check_command check_web!http_port!your_db_ip_or_fqdn!db_port
}
If you have more dependency, you can expand the check_dep script to check for three hosts and increasing the number of arguments. And you'll supply those hosts on the host definition of the dependent host.
I hope this helps for people who were banging their heads against the wall like me
Re: Host - service dependency
Yours is kind of a unique scenario where you needed explicitly for a host to appear down when x number of services on x number of servers are down... it's not really a common scenario. This is actually the first instance of it I've seen where this was a real requirement that couldn't be solved with a simple work around.
I slapped my forehead re-reading this thread because I forgot about the check_multi plugin, which may have also helped you out instead of coding your own solution: http://exchange.nagios.org/directory/Pl ... ti/details. I'm glad you found a solution that works for you though and thanks for sharing it
!
I slapped my forehead re-reading this thread because I forgot about the check_multi plugin, which may have also helped you out instead of coding your own solution: http://exchange.nagios.org/directory/Pl ... ti/details. I'm glad you found a solution that works for you though and thanks for sharing it