Checkmk 2.4.0p37 常用 CLI 命令与工具详解

Checkmk 2.4.0p37 常用 CLI 命令与工具详解:omd 全命令树与站点生命周期、cmk 服务发现/检查/配置重载、check_mk_agent、mkp 扩展包与 Livestatus 查询,Ubuntu 22.04 逐命令实测。

CheckmkCheckmk监控2026/10/20

Checkmk 2.4.0p37 常用 CLI 命令与工具详解

目标:系统梳理 Checkmk Raw 2.4.0p37 的命令行工具体系——omd 站点管理全命令树、cmk 监控引擎命令、被监控端 check_mk_agent、MKP 扩展包管理 mkp,以及 Livestatus 查询接口。所有命令与回显均在 Ubuntu 22.04 实测环境中逐条执行采集,可直接照抄复现。

一、环境信息

项目值
操作系统Ubuntu 22.04(x86_64)
Checkmk 版本Raw Edition 2.4.0p37(OMD - Open Monitoring Distribution Version 2.4.0p37.cre)
站点实例mysite(omd 多实例框架创建)
站点目录/omd/sites/mysite
站点用户mysite(omd create 自动创建)
已纳管主机localhost(自监控,22 个服务)
内置检查插件数2091 个(cmk -L 实测统计)
版本取证日期2026-10-20

命令身份约定(重要):omd 管理命令以 root 执行;cmk/mkp/unixcat 等站点内命令必须以站点用户身份执行,两种切换方式:

su - mysite        # 方式一:su 切换站点用户(实测可用)
omd su mysite      # 方式二:omd 自带的站点 shell(交互式使用)

⚠️ 注意:omd su mysite -c "命令" 的 -c 传参方式在部分环境不可靠(实测无输出),脚本中建议统一用 su - mysite -c "命令"。

二、工具概览

Checkmk 的 CLI 由四层工具组成:

工具所属层职责
omd站点管理多站点全生命周期:创建、启停、配置、备份、升级、删除
cmk监控引擎服务发现、检查执行、主机信息、配置编译与核心重载
check_mk_agent被监控端采集本机信息输出给服务端(TCP 6556)
mkp扩展包MKP 扩展包(检查插件/配置包)的打包、安装、启停
cmk-passwd站点管理修改 Web 用户密码(omd create 输出中的官方提示命令)
unixcat查询接口向 Livestatus Unix socket 发送查询(站点用户工具)

三、前置条件

  1. 已完成 Checkmk Raw 安装与站点创建(omd create),站点处于 running 状态。
  2. root 权限(omd 管理命令需要)。
  3. 站点内已至少纳管一台主机(本篇以自监控的 localhost 为例演示 cmk 命令)。

四、omd 命令详解(站点管理全命令树)

4.1 omd help 全命令树

omd help 输出全部管理命令(实测原文):

Manage multiple monitoring sites comfortably with OMD. The Open Monitoring Distribution.
Usage (called as root):

 omd help                               Show general help
 omd setversion VERSION                 Sets the default version of OMD which will be used by new sites
 omd version    [SITE]                  Show version of OMD
 omd versions                           List installed OMD versions
 omd sites                              Show list of sites
 omd create     SITE                    Create a new site (-u UID, -g GID)
 omd init       SITE                    Populate site directory with default files and enable the site
 omd rm         SITE                    Remove a site (and its data)
 omd disable    SITE                    Disable a site (stop it, unmount tmpfs, remove Apache hook)
 omd enable     SITE                    Enable a site (reenable a formerly disabled site)
 omd update-apache-config SITE                    Update the system apache config of a site (and reload apache)
 omd mv         SITE NEWNAME            Rename a site
 omd cp         SITE NEWNAME            Make a copy of a site
 omd update     SITE                    Update site to other version of OMD
 omd start      [SITE] [SERVICE]        Start services of one or all sites. This command reports one of the following exit codes.
 * 0: All services started successfully.
 * 1: The command failed to start any service.
 * 2: When targeting a single site, this indicates that one or more services failed to start. When targeting multiple sites, this indicates that an unspecific error occurred.
 omd stop       [SITE] [SERVICE]        Stop services of site(s) and terminate processes owned by the site user
 omd restart    [SITE] [SERVICE]        Restart services of site(s)
 omd reload     [SITE] [SERVICE]        Reload services of site(s)
 omd status     [SITE] [SERVICE]        Show status of services of site(s)
 omd config     SITE ...                Show and set site configuration parameters.

Usage:
 omd config [site]                      interactive mode
 omd config [site] show                 show configuration settings
 omd config [site] set VAR VAL          set specific setting VAR to VAL
 omd diff       SITE ([RELBASE])        Shows differences compared to the original version files
 omd su         SITE                    Run a shell as a site-user
 omd umount     [SITE]                  Umount ramdisk volumes of site(s)
 omd backup     SITE [SITE] [-|ARCHIVE_PATH] Create a backup tarball of a site, writing it to a file or stdout
 omd restore    [SITE] handler=[-|ARCHIVE_PATH] Restores the backup of a site to an existing site or creates a new site
 omd cleanup                            Uninstall all Check_MK versions that are not used by any site.

General Options:
 -V <version>                    set specific version, useful in combination with update/create
 -f, --force                     use force mode, useful in combination with update
 omd COMMAND -h, --help          show available options of COMMAND

要点解读:[SITE] [SERVICE] 表示 start/stop/restart/status 都支持只操作单个服务(如只重启 apache);omd COMMAND -h 可查看每个子命令的专属选项。

4.2 版本与站点查询

omd version
omd versions
omd sites

实测回显:

$ omd version
OMD - Open Monitoring Distribution Version 2.4.0p37.cre
$ omd versions
2.4.0p37.cre (default)
$ omd sites
mysite           2.4.0p37.cre     default version

4.3 创建站点(omd create)

omd create --admin-password q1w2e3r4 mysite

实测回显:

Adding /opt/omd/sites/mysite/tmp to /etc/fstab.
Creating temporary filesystem /omd/sites/mysite/tmp...Generating configuration for core (type nagios)...
Precompiling host checks...OK
Executing post-create script "01_create-sample-config.py"...OK
Executing post-create script "02_cmk-compute-api-spec"...OK
Executing post-create script "03_message-broker-certs"...OK
Updating core configuration...
Adding /opt/omd/sites/mysite/tmp to /etc/fstab.
Skipping Apache restart.
Created new site mysite with version 2.4.0p37.cre.

  The site can be started with omd start mysite.
  The default web UI is available at http://cmk-server.ubuntu.local/mysite/

  The admin user for the web applications is cmkadmin with password: q1w2e3r4
  For command line administration of the site, log in with 'omd su mysite'.
  After logging in, you can change the password for cmkadmin with 'cmk-passwd cmkadmin'.

要点:不传 --admin-password 时会生成随机密码并在输出中打印一次;cmkadmin 是 Web 管理员,automation 用户供 REST API/自动化调用。

omd create -h 可查专属选项(实测节选):

Possible options for this command:
 -u,--uid        ARG  create site user with UID ARG
 -g,--gid        ARG  create site group with GID ARG
 --admin-password ARG  set initial password instead of generating one
 --reuse              do not create a site user, reuse existing one
 -n,--no-init         leave new site directory empty (a later omd init does this
 -A,--no-autostart      set AUTOSTART to off (useful for test sites)
 --apache-reload      Issue a reload of the system apache instead of a restart
 --no-tmpfs           set TMPFS to off
 -t,--tmpfs-size ARG  specify the maximum size of the tmpfs (defaults to 50% of RAM), examples: 500M, 20G, 60%

4.4 启动/状态/停止/重启

全站启动(实测回显):

omd start mysite
Starting agent-receiver...OK
Starting mkeventd...OK
Starting rrdcached...OK
Starting redis...OK
Starting npcd...OK
Starting automation-helper...OK
Starting ui-job-scheduler...OK
Starting nagios...OK
Starting apache...OK
Starting crontab...OK

全站状态(omd status mysite 实测回显):

agent-receiver:     running
mkeventd:           running
rrdcached:          running
redis:              running
npcd:               running
automation-helper:  running
ui-job-scheduler:   running
nagios:             running
apache:             running
crontab:            running
---------------------------
Overall state:      running

单服务状态与重启(实测回显):

omd status mysite apache
apache:             running
---------------------------
Overall state:      running
omd restart mysite
Stopping crontab...OK
Stopping redis...killing ...OK
Stopping rrdcached...OK
Starting agent-receiver...OK
Starting mkeventd...OK
Starting rrdcached...OK
Starting redis...OK
Starting nagios...OK
Starting apache...OK
Starting crontab...OK

⚠️ 注意:实测中 stop/restart 偶发出现 Stopping apache...failed、still running after 20 secs! 等残停现象(进程退出慢),重跑一次 omd stop 再 omd start 即可恢复;omd status 看到个别服务 running 而 Overall 显示 partially running 时同理。

4.5 站点配置(omd config)

查看配置(omd config mysite show 实测节选):

ADMIN_MAIL:
AGENT_RECEIVER: on
AGENT_RECEIVER_PORT: 8000
APACHE_MODE: own
APACHE_TCP_ADDR: 127.0.0.1
APACHE_TCP_PORT: 5000
AUTOMATION_HELPER: on
AUTOSTART: on
CORE: nagios
LIVESTATUS_TCP: off
MKEVENTD: on
MULTISITE_COOKIE_AUTH: on
PIGGYBACK_HUB: off
PNP4NAGIOS: on
RABBITMQ_PORT: 5672
TMPFS: on
参数默认值说明
COREnagios(Raw 版固定)监控内核类型
APACHE_MODEown站点自带 Apache(监听 5000),系统 Apache 反向代理
APACHE_TCP_ADDR/PORT127.0.0.1 / 5000站点 Apache 监听地址与端口
AUTOSTARTon开机/启动时自动拉起站点
LIVESTATUS_TCPoffLivestatus TCP 6557 对外查询开关
TMPFSon站点临时目录用内存盘

修改配置(实测):

omd config mysite set LIVESTATUS_TCP on

站点完全停止时静默修改成功(无输出);站点运行中修改会报错(实测回显):

Cannot change config variables while site is running.

⚠️ 注意:改 LIVESTATUS_TCP、CORE 等核心项的标准流程是 omd stop 站点 → omd config 站点 set 参数 值 → omd start 站点。stop 必须等全部服务退出(status 显示 stopped)再执行 set。

4.6 备份与恢复(backup/restore)

omd backup mysite /tmp/mysite-backup.tar.gz
ls -lh /tmp/mysite-backup.tar.gz

实测回显(站点数据较少时备份包约 1.7MB):

-rw-r--r-- 1 root root 1.7M Oct 19 22:17 /tmp/mysite-backup.tar.gz

恢复:omd restore mysite /tmp/mysite-backup.tar.gz(恢复到已存在站点)或 omd restore handler=/tmp/mysite-backup.tar.gz(恢复为新站点,站点名按交互提示输入)。

4.7 多站点与多版本

  • omd cp mysite site2:克隆站点做测试(先 stop 源站点)。
  • omd mv mysite newname:重命名站点。
  • omd update -V 2.5.0p16 mysite:把站点升级到另一已安装版本(配合 omd setversion)。
  • omd disable/enable mysite:临时下线/恢复站点(不删数据)。
  • omd cleanup:清理没有任何站点使用的旧版本。

删除站点(实测在卸载篇演示):

omd rm mysite

五、cmk 命令详解(监控引擎)

5.1 cmk --help 速查

cmk --help 的 WAYS TO CALL 部分(实测原文节选):

WAYS TO CALL:
 cmk  --automation [COMMAND...]          Internal helper to invoke Check_MK
                                         actions
 cmk  --check [HOST [IPADDRESS]]         Check all services on the given HOST
 cmk  --check-discovery HOSTNAME         Check for not yet monitored services
 cmk  --cleanup-piggyback                Cleanup outdated piggyback files
 cmk  --create-diagnostics-dump          Create diagnostics dump
 cmk  --flush [HOST1 HOST2...]           Flush all data of some or all hosts
 cmk  --inventorize-marked-hosts         Run inventory for hosts which
                                         previously had no tree data
 cmk  --list-tag [TAG1 TAG2...]          List hosts having certain tags
 cmk  --localize [COMMAND]               Do localization operations
 cmk  --notify [MODE]                    Used to send notifications from core
 cmk  --snmpget [OID [HOST1 HOST2...]]   Fetch single OID from one or multiple
                                         hosts
 cmk  --snmptranslate HOST               Do snmptranslate on walk
 cmk  --snmpwalk [HOST1 HOST2...]        Do snmpwalk on one or more hosts
 cmk  --update-dns-cache                 Update IP address lookup cache
 cmk  -D, --dump [H1 H2...]              Dump info about all or some hosts
 cmk  -d, --dump-agent HOSTNAME|ADDRESS  Show raw information from agent
 cmk  -h, --help                         Print this help
 cmk  -I, --discover [[-I] HOST1 HOST2...]Find new services
 cmk  -i, --inventory [HOST1 HOST2...]   Do a HW/SW Inventory on some or all
                                         hosts
 cmk  -L, --list-checks                  List all available Check_MK checks
 cmk  -l, --list-hosts [G1 G2...]        Print list of all hosts or members of
                                         host groups
 cmk  -m, --browse-man                   Open interactive manpage browser
 cmk  -M, --man [CHECKTYPE]              Show manpage for check CHECKTYPE
 cmk  -N, --nagios-config [HOST1 HOST2...]Output Nagios configuration
 cmk  -O, --reload [[HostA, HostB]]      Create core config + core reload
 cmk  -P, --package [COMMAND]            DEPRECATED: Do package operations
 cmk  -R, --restart [[HostA, HostB]]     Create core config + core restart
 cmk  -U, --update                       Create core config
 cmk  -V, --version                      Print the version of Check_MK

OPTIONS:
   --debug             Let most Python exceptions raise through
   --fake-dns IP       Fake IP addresses of all hosts to be IP. This prevents
                       DNS lookups.
   --profile           Enable profiling mode
   -v, --verbose       Enable verbose output (Use twice for more)

💡 说明:-P, --package 已标注 DEPRECATED,扩展包管理统一用独立命令 mkp(见第七节)。

5.2 版本、主机列表与插件清单

cmk -V
cmk -l
cmk -L | wc -l
cmk -L | head -5

实测回显:

$ cmk -V
This is Check_MK version 2.4.0p37 CRE
$ cmk -l
localhost
$ cmk -L | wc -l
2091
$ cmk -L | head -5
3par_capacity                               agent     HPE 3PAR: Capacity
3par_cpgs                                   agent     HPE 3PAR: CPGs
3par_cpgs_usage                             agent     HPE 3PAR: CPGs Usage
3par_hosts                                  agent     HPE 3PAR: Hosts
3par_ports                                  agent     HPE 3PAR: Ports

5.3 cmk -d:查看 agent 原始数据

cmk -d localhost 输出 agent 报告的原始数据(实测节选,中间检查段落数百行):

<<<check_mk>>>
Version: 2.4.0p37
AgentOS: linux
Hostname: cmk-server.ubuntu.local
AgentDirectory: /etc/check_mk
DataDirectory: /var/lib/check_mk_agent
SpoolDirectory: /var/lib/check_mk_agent/spool
PluginsDirectory: /usr/lib/check_mk_agent/plugins
LocalDirectory: /usr/lib/check_mk_agent/local
OSType: linux
OSName: Ubuntu
OSVersion: 22.04
OSPlatform: ubuntu
FailedPythonReason:
SSHClient:
<<<checkmk_agent_plugins_lnx:sep(0)>>>
pluginsdir /usr/lib/check_mk_agent/plugins
localdir /usr/lib/check_mk_agent/local
<<<nfsmounts_v2:sep(0)>>>
<<<cifsmounts>>>
<<<mounts>>>
<<<ps_lnx>>>
[time]
1792447191
[processes]

尾部还有站点自监控信息(实测节选):

<<<omd_info:sep(59)>>>
[versions]
version;number;edition;demo
2.4.0p37.cre;2.4.0p37;cre;0
[sites]
site;used_version;autostart
mysite;2.4.0p37.cre;1

cmk -d 是排查「某服务为什么不出数」的第一手段:有对应段落说明 agent 采集正常,问题在检查插件解析;无段落则先查 agent 与网络(6556)。

5.4 cmk -I:服务发现

cmk -I localhost          # 静默模式:无新服务时无输出
cmk -v -I localhost       # 冗长模式:输出发现过程

cmk -v -I localhost 实测回显:

Get piggybacked data
+ ANALYSE DISCOVERED HOST LABELS
SUCCESS - Found no new host labels
+ ANALYSE DISCOVERED SERVICES
+ EXECUTING DISCOVERY PLUGINS (24)
SUCCESS - Found no new services

💡 说明:-I 只发现新服务,不自动激活到监控核心。发现后需要 cmk -O 重载(见 5.9),或在 Web 界面激活变更。

5.5 cmk --check:单主机执行检查

干跑模式(结果不送核心,实测回显):

cmk --check -n localhost
[agent] Success, [piggyback] Success (but no data found for this host), execution time 0.3 sec | execution_time=0.270 user_time=0.010 system_time=0.000 children_user_time=0.000 children_system_time=0.000 cmk_time_agent=0.270

带 -v 逐服务查看检查结果(实测节选):

cmk -v --check localhost
 checkmk_agent_plugins: ok
 check_mk: ok
 lnx_if: ok
[agent] Success, [piggyback] Success (but no data found for this host), execution time 0.3 sec | execution_time=0.270 user_time=0.000 system_time=0.010 children_user_time=0.000 children_system_time=0.000 cmk_time_agent=0.250

⚠️ 注意:选项顺序有讲究。cmk --check localhost -n 会报错 ValueError: invalid host address: '-n'(-n 被当成了 IP 参数,实测踩坑),必须写 cmk --check -n localhost。

5.6 cmk -D:查看主机配置详情

cmk -D localhost 实测节选(服务清单按检查类型展开,全部服务共 22 项):

localhost
Addresses:              127.0.0.1
Tags:                   [address_family:ip-v4-only], [agent:cmk-agent], [checkmk-agent:checkmk-agent], [criticality:prod], [ip-v4:ip-v4], [networking:lan], [piggyback:auto-piggyback], [site:mysite], [snmp_ds:no-snmp], [tcp:tcp]
Host groups:            check_mk
Contact groups:         check-mk-notify, all
Agent mode:             Normal Checkmk agent, or special agent if configured
Type of agent:
  TCP: 127.0.0.1:6556
  Process piggyback data from /omd/sites/mysite/tmp/check_mk/piggyback/localhost
Services:
  checktype           item                      params        description
  ------------------- ------------------------- ------------  ----------------------
  cpu_utilization_os  None                      {}            CPU utilization
  checkmk_agent       None                      {'agent_version': ('ignore', {}), ...}  Check_MK Agent
  diskstat            SUMMARY                   {}            Disk IO SUMMARY
  lnx_if              2                         {'errors': {'both': ('perc', (0.01, 0.1))}, ...}  Interface 2
  mem_used            None                      {'levels': (150.0, 200.0)}  Memory
  mkeventd_status     mysite                    {}            OMD mysite Event Console

5.7 cmk -M:查看检查插件手册

cmk -M cpu_utilization_os

实测回显(节选):

 cpu_utilization_os       Cpu Utilization OS
 Distribution:            Official part of Checkmk
 License:                 GPLv2
 Supported Agents:        Linux

 This  check measures the  CPU utilization during the  last check cycle. Levels
 can be set on the total utilization.

 DISCOVERY
 One service is created.

交互式手册浏览用 cmk -m。

5.8 cmk -i:硬件/软件清单

cmk -v -i localhost

实测回显:

+ CREATE INVENTORY OR STATUS DATA TREE
+ MAY UPDATE INVENTORY TREE
SUCCESS - Found 46 inventory entries, Found 15 status entries

清单数据在 Web 界面主机详情的 Hardware/Software Inventory 页查看,也可通过 REST API 导出。

5.9 cmk -U / -O / -R:配置编译与核心控制

cmk -U        # 只编译核心配置,不重载
cmk -O        # 编译配置 + 核心重载(平滑,不中断监控)
cmk -R        # 编译配置 + 核心重启(完全重启核心进程)

实测回显:

$ cmk -U
Precompiling host checks...OK
Validating Nagios configuration...OK
$ cmk -O
Validating Nagios configuration...OK
Reloading monitoring core...OK

⚠️ 注意:实测中若有其他激活操作进行中(如 Web 界面/REST API 刚触发过激活),会报 Configuration Error: Other restart currently in progress. Aborting.,等几秒重跑即可。这三个命令只处理「非 WATO 托管」的直接改动生效;Web 界面/REST API 的变更仍需走激活流程。

六、check_mk_agent(被监控端)

被监控端只需要装一个包(DEB/RPM 在监控端站点目录内自带):

dpkg -i /omd/sites/mysite/share/check_mk/agents/check-mk-agent_2.4.0p37-1_all.deb

实测回显:

Deployed xinetd
Starting xinetd
 * Starting internet superserver xinetd
   ...done.

⚠️ 注意:在有 systemd 的真机上,安装包会同时注册并启用 systemd 服务单元实现开机自启;在无 systemd 的最小化环境则如上输出,agent 经 xinetd 托管,效果等价。

验证安装与监听:

dpkg -l check-mk-agent | tail -1
ss -ltn | grep 6556

实测回显:

ii  check-mk-agent 2.4.0p37-1   all          Checkmk Agent for Linux
LISTEN 0      64                 *:6556             *:*

agent 包没有 --version 选项:直接执行 check_mk_agent 会输出完整采集数据(版本在首部 Version: 字段,实测如下):

<<<check_mk>>>
Version: 2.4.0p37
AgentOS: linux

agent 扩展点(被监控端目录,来自 cmk -d 输出的真实路径):

目录/机制路径用途
插件目录/usr/lib/check_mk_agent/plugins官方/自定义采集插件,输出 <<<段落>>>
local 检查/usr/lib/check_mk_agent/local本地脚本,输出即监控服务(最简单的自定义方式)
spool 目录/var/lib/check_mk_agent/spool定时任务缓存输出文件
配置目录/etc/check_mkagent 配置(如 logwatch 规则)

七、mkp 扩展包管理

mkp -h 实测回显(子命令全集):

usage: mkp [-h] [--debug] [--verbose]
           {find,inspect,template,package,show,show-all,files,list,add,remove,release,enable,disable,disable-outdated,update-active}
           ...

Command line interface for the Checkmk Extension Packages

options:
  -h, --help            show this help message and exit
  --debug, -d
  --verbose, -v         Be more verbose

available commands:
  {find,inspect,template,package,show,show-all,files,list,add,remove,release,enable,disable,disable-outdated,update-active}
    find                Show information about local files
    inspect             Show manifest of an MKP file
    template            Create a template of a package manifest
    package             Create an .mkp file from the provided manifest. You
                        can use the `template` command to create a manifest
                        template.
    show                Show manifest of a stored package
    show-all            Show all manifests
    files               Show all files beloning to a package
    list                Show a table of all known files, including the
                        deployment state
    add                 Add an MKP to the collection of managed MKPs
    remove              Remove a package from the site

常用操作(均在站点用户下执行):

mkp list                    # 列出已安装包及部署状态
mkp add /path/to/pkg.mkp    # 安装 MKP 包
mkp enable <包名> <版本>     # 启用
mkp disable <包名> <版本>    # 停用
mkp remove <包名> <版本>     # 卸载
mkp template                # 生成打包清单模板
mkp package manifest文件     # 按 manifest 打出 .mkp 包

mkp list 实测回显(未装任何扩展包时的空表):

Name Version Title Author Req. Version Until Version Files State
---- ------- ----- ------ ------------ ------------- ----- -----

八、Livestatus 查询(unixcat)

Livestatus 是 Checkmk 的实时状态查询接口(Unix socket),Web 界面数据即来源于此。socket 位于站点 tmp/run/live:

su - mysite -c "printf 'GET hosts\nColumns: name state hard_state num_services services\n\n' | unixcat ~/tmp/run/live"

实测回显(localhost 共 22 个服务,state 0 即全部正常):

localhost;0;0;22;Uptime,TCP Connections,Site mysite statistics,Process mysite rrdcached,Process mysite redis-server,Process mysite event console,Process mysite automation helpers,Process mysite apache,Process mysite agent receiver,OMD mysite status,OMD mysite performance,OMD mysite disk usage,OMD mysite apache,OMD mysite Event Console,Memory,Interface 2,Disk IO SUMMARY,Check_MK HW/SW Inventory,Check_MK Discovery,Check_MK Agent,Check_MK,CPU utilization

💡 技术拓展:查询监控状态的接口不止 Livestatus 一种。常见对比——

方式原理适用场景
Livestatus(unixcat/socket)站点本地 Unix socket 直查核心状态表脚本巡检、本地集成,零配置
Livestatus TCP(6557)同协议走 TCP,需 omd config 开启跨机对接(外部看板/网关)
REST APIHTTP+JSON,完整 CRUD自动化平台对接、主机纳管批量操作

本机脚本巡检优先 Livestatus(无认证开销),跨系统集成用 REST API。

九、注意事项

  1. 身份即权限:omd 管理命令要 root;站点内命令(cmk/mkp/unixcat)必须站点用户,直接用 root 执行 cmk 会读到错误的环境变量集。
  2. 改配置三层生效链:agent 数据(cmk -d 确认)→ 发现/规则(cmk -I 或 Web)→ 核心生效(cmk -O 或 Web 激活)。只做前两层不出新服务。
  3. -P 已废弃:老资料里的 cmk -P 打包操作统一换成 mkp。
  4. 选项顺序:cmk --check 的 -n 要放在主机名前面(见 5.5 实测报错)。
  5. omd config set 前置条件:站点须完全停止,否则报 Cannot change config variables while site is running.。

十、常见问题

Q1:omd su mysite -c "cmd" 没有输出

实测该传参方式在部分环境失效。脚本里改用 su - mysite -c "cmd",交互场景用 omd su mysite。

Q2:cmk -O 报 Other restart currently in progress. Aborting.

有并发的激活/重载在进行(Web 界面或 REST API 触发过)。等待数秒重跑即可;持续报错时 omd restart 站点 重建核心进程。

Q3:cmk -I 执行完 Web 上没有新服务

发现 ≠ 激活。命令行发现后需要 cmk -O 让核心加载新配置;若改动是在 Web/REST API 做的,则走各自的「激活变更」流程。

Q4:omd stop 后个别服务仍 running(partially running)

进程退出慢导致残停,重跑 omd stop 直到 status 显示 stopped(必要时确认站点用户进程已全部退出),再执行后续操作。

Q5:check_mk_agent 有没有版本参数

没有 --version 选项,直接执行 check_mk_agent 从输出首部 Version: 字段读版本,或 dpkg -l check-mk-agent 查包版本(实测均为 2.4.0p37)。

十一、参考链接