Inverse of output from check_tcp


#1

I’m running the latest version of Nagios and plugins and I’m pretty new at running it.

I would like to use check_tcp to check the availability of a TCP port on a server. But there is a catch. When I get a “connection refused” respose, I would like to signify that it is UP, and when I get a “TCP OK” response, that that it is DOWN. I have it setup monitoring the port, but is there a way to “inverse” or “reverse” the results of check_tcp?


#2

I think you can achieve that with the **-r **flag…

./check_tcp --help
...
 -r, --refuse=ok|warn|crit
    Accept tcp refusals with states ok, warn, crit (default: crit)

HTH

/S


#3

I tried that command, and it doesn’t quite do what I need. That will make it reespond with a “TCP OK” status should it receive a connection refused status. Then when it actually goes down, it will still generate a “TCP OK” status because the port is now available. So I would never get notified that anything changed.

I need it to take a status of “connection refused” as being “UP” and when it transitions to “TCP OK” as being “DOWN”. Basically if the port is available (i.e. TCP OK), then I have an application down and not responding. That’s what I’m trying to monitor.


#4

It sounds like you would need to write a script to check that kind of behavior. I have seen many people write their own scripts as Nagios plugins before, but it doesn’t seem like an easy task unless you know a decent amount of perl or bash.


#5

Actually I just found a solution. It appears that Nagios comes with a “negate” command to reverse the output of other plugins. This solved my issue.

Thanks!