Skip to content

Commit 58181e7

Browse files
committed
feat: add checkmk custom agent
1 parent b5539af commit 58181e7

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

config/ns-checkmk-agent.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_PACKAGE_ns-checkmk-agent=y
2+
CONFIG_PACKAGE_socat=y

packages/ns-checkmk-agent/Makefile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#
2+
# Copyright (C) 2026 Nethesis S.r.l.
3+
# SPDX-License-Identifier: GPL-2.0-only
4+
#
5+
6+
include $(TOPDIR)/rules.mk
7+
8+
PKG_NAME:=ns-checkmk-agent
9+
PKG_VERSION:=0.0.1
10+
PKG_RELEASE:=1
11+
12+
PKG_BUILD_DIR:=$(BUILD_DIR)/ns-checkmk-agent-$(PKG_VERSION)
13+
14+
PKG_MAINTAINER:=Giacomo Sanchietti <giacomo.sanchietti@nethesis.it>
15+
PKG_LICENSE:=GPL-3.0-only
16+
17+
include $(INCLUDE_DIR)/package.mk
18+
19+
define Package/ns-checkmk-agent
20+
SECTION:=base
21+
CATEGORY:=NethSecurity
22+
TITLE:=Check_MK monitoring agent
23+
URL:=https://github.com/Checkmk/checkmk
24+
DEPENDS:=+socat
25+
PKGARCH:=all
26+
endef
27+
28+
define Package/ns-checkmk-agent/description
29+
Check_MK monitoring agent for NethSecurity with custom plugins
30+
endef
31+
32+
# Base URLs for downloads
33+
CHECKMK_AGENT_URL:=https://raw.githubusercontent.com/Checkmk/checkmk/master/agents/check_mk_agent.openwrt
34+
PLUGIN_BASE_URL:=https://raw.githubusercontent.com/Coverup20/checkmk-tools/refs/heads/main/script-check-nsec8/full
35+
36+
# List of plugin files to download (add more as needed)
37+
PLUGIN_FILES:=check_dhcp_leases.sh check_dns_resolution.sh check_firewall_connections.sh check_firewall_rules.sh check_firewall_traffic.sh check_martian_packets.sh check_opkg_packages.sh check_ovpn_host2net.sh check_root_access.sh check_uptime.sh check_vpn_tunnels.sh check_wan_status.sh
38+
39+
define Build/Prepare
40+
mkdir -p $(PKG_BUILD_DIR)/plugins
41+
42+
# Download main Check_MK agent
43+
wget -O $(PKG_BUILD_DIR)/check_mk_agent $(CHECKMK_AGENT_URL)
44+
45+
# Download plugin files using shell script loop
46+
for plugin in $(PLUGIN_FILES); do \
47+
echo "Downloading plugin: $$plugin"; \
48+
wget -O $(PKG_BUILD_DIR)/plugins/$$plugin $(PLUGIN_BASE_URL)/$$plugin || \
49+
echo "Warning: Failed to download $$plugin"; \
50+
done
51+
endef
52+
53+
define Build/Compile
54+
endef
55+
56+
define Package/ns-checkmk-agent/install
57+
$(INSTALL_DIR) $(1)/usr/bin
58+
$(INSTALL_DIR) $(1)/etc/init.d
59+
$(INSTALL_DIR) $(1)/usr/lib/check_mk_agent/plugins
60+
61+
$(INSTALL_BIN) $(PKG_BUILD_DIR)/check_mk_agent $(1)/usr/bin/check_mk_agent
62+
$(INSTALL_BIN) ./files/check_mk_agent.init $(1)/etc/init.d/check_mk_agent
63+
64+
# Install plugin files
65+
if [ -d $(PKG_BUILD_DIR)/plugins ]; then \
66+
for plugin in $(PKG_BUILD_DIR)/plugins/*; do \
67+
[ -f "$$plugin" ] && $(INSTALL_BIN) $$plugin $(1)/usr/lib/check_mk_agent/plugins/; \
68+
done; \
69+
fi
70+
endef
71+
72+
$(eval $(call BuildPackage,ns-checkmk-agent))
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# ns-checkmk-agent
2+
3+
Check_MK monitoring agent integration for NethSecurity.
4+
5+
## Description
6+
7+
This package provides the Check_MK agent for monitoring NethSecurity firewalls. It includes:
8+
9+
- Main Check_MK agent from the official Checkmk repository
10+
- Custom plugins for NethSecurity-specific monitoring
11+
- Procd-managed service using socat to listen on TCP port 6556
12+
13+
## Features
14+
15+
- Automatic start on boot (START=98)
16+
- Respawn on failure
17+
- TCP listener on port 6556 using socat
18+
- Plugin support at `/usr/lib/check_mk_agent/plugins/`
19+
20+
## Adding More Plugins
21+
22+
To add additional plugin files from the [checkmk-tools repository](https://github.com/Coverup20/checkmk-tools/tree/main/script-check-nsec8/full):
23+
24+
1. Browse the plugin directory on GitHub to find available plugins
25+
2. Add the plugin name to the `PLUGIN_FILES` variable in the Makefile:
26+
27+
```makefile
28+
PLUGIN_FILES:=nethsecurity openvpn ipsec mwan3 certificates <new_plugin_name>
29+
```
30+
31+
3. The plugin will be automatically downloaded and installed to `/usr/lib/check_mk_agent/plugins/` during the build
32+
33+
## Testing
34+
35+
After installation on a NethSecurity firewall:
36+
37+
```bash
38+
# Test agent locally
39+
/usr/bin/check_mk_agent
40+
41+
# Test via network from monitoring server
42+
echo "" | nc <firewall-ip> 6556
43+
44+
# Check service status
45+
/etc/init.d/check_mk_agent status
46+
47+
# Start/stop service
48+
/etc/init.d/check_mk_agent start
49+
/etc/init.d/check_mk_agent stop
50+
```
51+
52+
## Configuration
53+
54+
The service is configured via procd and requires no additional configuration files. To enable/disable the service:
55+
56+
```bash
57+
/etc/init.d/check_mk_agent enable
58+
/etc/init.d/check_mk_agent disable
59+
```
60+
61+
## Dependencies
62+
63+
- socat: Used to expose the agent via TCP socket
64+
65+
## Firewall Rules
66+
67+
Remember to allow incoming connections on TCP port 6556 from your Check_MK monitoring server.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh /etc/rc.common
2+
START=98
3+
STOP=10
4+
USE_PROCD=1
5+
6+
PROG=/usr/bin/check_mk_agent
7+
8+
start_service() {
9+
procd_open_instance
10+
procd_set_param respawn
11+
procd_set_param command socat TCP-LISTEN:6556,reuseaddr,fork,keepalive EXEC:$PROG
12+
procd_set_param stdout 1
13+
procd_set_param stderr 1
14+
procd_close_instance
15+
}
16+
17+
stop_service() {
18+
killall socat >/dev/null 2>&1 || true
19+
}

0 commit comments

Comments
 (0)