添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
谦和的菠萝  ·  [solved] Self ...·  1 周前    · 
腼腆的烈马  ·  [Anaconda]——Linux下cond ...·  1 周前    · 
逆袭的可乐  ·  Project History — ...·  1 周前    · 
完美的抽屉  ·  The Remote Work ...·  3 月前    · 
奋斗的香蕉  ·  Processmaker ...·  6 月前    · 
霸气的佛珠  ·  Job Search·  7 月前    · 

Hi, i tried to build my own check_mk plugin that checks if a port is open.
My .py content:

from .agent_based_api.v1 import *
def discover_port_check(section):
    yield Service()
def check_port_check(section):
    for line in section:
        if "10298" in line:
            yield Result(state=State.CRIT, summary="Port 10298 open")
            return
        else:
            yield Result(state=State.OK, summary=f"No open relevant Port found")
register.check_plugin(
    name="port_check",
    service_name="Port Check",
    discovery_function=discover_port_check,
    check_function=check_port_check,

my service content on the monitored server:

#!/bin/sh
echo '<<<port_check>>>'
sudo lsof -i:10298

I wondered why the service always says "Item not found in monitoring data
", because the port given is open and the command gives an output which contains the string mentioned. Thats why i tried to debug and i found out the “section” in the python script is an empty list always, so no matter what the service gives out on check_mk_agent ran locally on the monitored server, there is nothing coming through. Weird, because i followed the doc step by step and named the python and the service file identical (except for the .py extension)

Im running CheckMK ver. 2.0.0p6.

Indeed, please post the output of the lsof command. For me it’s empty as well, but that’s normal since I don’t have anything listning on this port (you may run into troubble once you get it working and the port is closed since you’ll have no monitoring data again).

If you do get output from the lsof command, run this on your CheckMK server as the CheckMK site user:

cmk -d <target server>

In this output see if you have the port_check section and if it contains the desired output from the lsof command.

no. this port is custom opened at my server. thats why it gives output. the output looks like this:

COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd       605 root    3u  IPv4  12532      0t0  TCP *:10298 (LISTEN)
sshd       605 root    4u  IPv6  12546      0t0  TCP *:10298 (LISTEN)
              

Ok, so then I’m assuming you run the agent over ssh, right? If you run it using xinetd or systemd it should run using root privileges anyway.

So in that case, make sure your monitoring user on the monitored systems has the right sudo privileges. It should be able to run the plugin without having to enter a password.

On the monitored system, su to the monitoring user and run

sudo /usr/lib/check_mk_agent/plugins/port_check

(assuming port_check is the name of your plugin). That should give you the correct output, without having to provide a password. If not, that’s most likely your issue.

Oh and indeed make sure it is in the right location and has is executable.