Why this TCP Listening Ports not display in check_MK?

This is using the agent plugins method to check for the TCP port listening, for example, to check for all Oracle listening tcp/ip ports.

This is follows the the following URL,
(https://lanbugs.de/howtos/monitoring-check_mk/check_mk-eigener-agent-check/)

On monitoring server, I create the following python script, name it - my_tcp_listener:

#!/usr/bin/env python

def inventory_my_tcp_listener(info):

for l in info:

service_identify = “%s/%s” % (l[0], l[3].split(":")[-1])

yield service_identify, None

def check_my_tcp_listener(item, params, info):

proto, port = item.split("/")

message = (2, “CRIT service not listen”)

for l in info:

if proto in l[0] and port in l[3].split(":")[-1]:

message = (0, “OK service listen”)

return message

check_info[“my_tcp_listener”] = {

“inventory_function” : inventory_my_tcp_listener,

“check_function” : check_my_tcp_listener,

“service_description” : “ORACLE Listener %s”,

}

Put this script in /omd/sites/SIN/local/share/check_mk/checks folder

On normal Monitored Test servers, create the following bash script, name it my_tcp_listener.sh,

#!/bin/bash

echo “<<<my_tcp_listener>>>”

netstat -tlpen sed 1,2d grep –w “1522\ 1523\ 1524\ 1526\ 1528\ 1529\ 1530\ 1531\ 1534”

Put this script in /usr/lib/check_mk_agent/plugins/ folder

I can see the required Services show on the checkmk portal.

However, our oracle db servers are running check_MK agent in the context of “nagios” account.

The difference is, instead of default “/usr/lib/check_mk_agent/plugins/” folder, it use “/home/nagios/plugins” folder.

The check_mk_agent is installed in /home/nagios/bin/ folder. I typed “./check_mk_agent | grep Directory”, and found that the plugins directory is located at “/home/nagios/plugins”

I copied the my_tcp_listener.sh to the given directory, chown nagios:nagios, and then chmod 755 this script. However, this doesn’t work.

I even edit my_tcp_listener.sh to,

#!/bin/bash

echo “<<<my_tcp_listener>>>”

sudo netstat -tlpen sed 1,2d grep –w “1522\ 1523\ 1524\ 1526\ 1528\ 1529\ 1530\ 1531\ 1534”

But, still the tcp ports not displayed in check_MK portal.

@Soohow.cheng, could you please format your post: Just put <code> and </code> around your code snippets or indent all code by 4 characters for the same effect. Else the code is formatted as regular text (left justified) which is fatal for Python scripts. Thank you.

Why don’t you use the [Check connecting to a TCP port] rule ?
but yeah format it first and then we’ll take a look

Yes, please consider using the active check check_tcp.

Also you may want to use the already existing plugin called netstat.{linux,aix,solaris}. You find more information about the plugin here: https://checkmk.com/cms_check_netstat.html

PS: Instead of <code>...</code> you can use three backticks (`) at the beginning and at the end of your code block example. I find this way more convenient (markdown) and easier/faster to type.

Hi, please see the python script

#!/usr/bin/env python
def inventory_my_tcp_listener(info):
   for l in info:
      service_identify = “%s/%s” % (l[0], l[3].split(":")[-1])
      yield service_identify, None
def check_my_tcp_listener(item, params, info):
   proto, port = item.split("/")
   message = (2, “CRIT service not listen”)
   for l in info:
      if proto in l[0] and port in l[3].split(":")[-1]:
          message = (0, “OK service listen”)
      return message
check_info[“my_tcp_listener”] = {
    “inventory_function” : inventory_my_tcp_listener,
    “check_function” : check_my_tcp_listener,
    “service_description” : “ORACLE Listener %s”,
}

image

Can you please also post what the output of your bash script is? The python part looks ok at first glance.

#!/bin/bash

echo “<<<my_tcp_listener>>>”

netstat -tlpen sed 1,2d grep –w “1522\ 1523\ 1524\ 1526\ 1528\ 1529\ 1530\ 1531\ 1534”

If this is really your script then you are missing pipes between the commands netstat, sed and grep.
But even then your sed looks strange, you might want to try awk instead. And instead of netstat you could try the new default ss.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.