可以通过创建 监控项 来限制 agent 端的检查。 黑名单、白名单或白名单/黑名单的组合。
为此,请使用两个 agent 的组合。 configuration 参数:
AllowKey=<pattern>
- 允许哪些检查;<pattern> 是 使用通配符(*)表达式指定DenyKey=<pattern>
- 禁止哪些检查;<pattern> 是 使用通配符(*)表达式指定注意:
因此,若要允许远程命令,请指定 AllowKey=system.run[<command>,*] 对于每个允许的命令,* 表示 wait 和 nowait 模式。也可以指定 AllowKey=system.run[*] 允许使用 wait 和 nowait 模式的全部命令的参数。若要禁止特定的远程命令,请添加带有 system.run[] 的 DenyKey 参数。 在 AllowKey=system.run[*] 参数之前的命令。
例如:
黑名单可能不是一个好的选择,因为新的 Zabbix version 可能会引入新的键, 而这些键并未在现有配置中明确限制。这可能导致安全漏洞。
AllowKey
参数白名单特定检查,使用 DenyKey=*
拒绝其他检查例如:
# 允许读取日志:
AllowKey=vfs.file.*[/var/log/*]
# 允许 localtime 检查
AllowKey=system.localtime[*]
# 拒绝所有其他键
DenyKey=*
^
转义空格。例如:
# 允许运行 test.bat,无论是否带有参数
AllowKey=system.run["C:\Program^ Files\Zabbix^ Agent^ 2\scripts\test.bat*"]
测试方法:
PS C:\Program Files\Zabbix Agent 2> .\zabbix_get.exe -s 127.0.0.1 -k system.run["C:\Program^ Files\Zabbix^ Agent^ 2\scripts\test.bat caret"]
此配置允许执行脚本,无论是否传递参数(例如 caret
),并确保即使脚本路径中包含空格,也允许执行 system.run
。
模式 | 描述 | 匹配 | 不匹配 |
---|---|---|---|
* | 匹配所有可能的键(无论是否带有参数)。 | 任意 | 无 |
vfs.file.contents | 匹配 vfs.file.contents 且不带参数。 |
vfs.file.contents | vfs.file.contents[/etc/passwd] |
vfs.file.contents[] | 匹配 vfs.file.contents 且带空参数。 |
vfs.file.contents[] | vfs.file.contents |
vfs.file.contents[*] | 匹配 vfs.file.contents 且带任意参数;不会匹配不带方括号的 vfs.file.contents 。 |
vfs.file.contents[] vfs.file.contents[/path/to/file] |
vfs.file.contents |
vfs.file.contents[/etc/passwd,*] | 匹配 vfs.file.contents 且第一个参数匹配 /etc/passwd ,其余参数可以是任意值(包括空值)。 |
vfs.file.contents[/etc/passwd,] vfs.file.contents[/etc/passwd,utf8] |
vfs.file.contents[/etc/passwd] vfs.file.contents[/var/log/zabbix_server.log] vfs.file.contents[] |
vfs.file.contents[*passwd*] | 匹配 vfs.file.contents 且第一个参数匹配 *passwd* ,没有其他参数。 |
vfs.file.contents[/etc/passwd] | vfs.file.contents[/etc/passwd,] vfs.file.contents[/etc/passwd, utf8] |
vfs.file.contents[*passwd*,*] | 匹配 vfs.file.contents 且第一个参数匹配 *passwd* ,后续参数可以是任意值(包括空值)。 |
vfs.file.contents[/etc/passwd,] vfs.file.contents[/etc/passwd, utf8] |
vfs.file.contents[/etc/passwd] vfs.file.contents[/tmp/test] |
vfs.file.contents[/var/log/zabbix_server.log,*,abc] | 匹配 vfs.file.contents 且第一个参数匹配 /var/log/zabbix\_server.log ,第三个参数匹配 abc ,第二个参数可以是任意值(包括空值)。 |
vfs.file.contents[/var/log/zabbix_server.log,,abc] vfs.file.contents[/var/log/zabbix_server.log,utf8,abc] |
vfs.file.contents[/var/log/zabbix_server.log,,abc,def] |
vfs.file.contents[/etc/passwd,utf8] | 匹配 vfs.file.contents 且第一个参数匹配 /etc/passwd ,第二个参数匹配 utf8 ,没有其他参数。 |
vfs.file.contents[/etc/passwd,utf8] | vfs.file.contents[/etc/passwd,] vfs.file.contents[/etc/passwd,utf16] |
vfs.file.* | 匹配以 vfs.file. 开头且不带任何参数的所有键。 |
vfs.file.contents vfs.file.size |
vfs.file.contents[] vfs.file.size[/var/log/zabbix_server.log] |
vfs.file.*[*] | 匹配以 vfs.file. 开头且带有任意参数的所有键。 |
vfs.file.size.bytes[] vfs.file.size[/var/log/zabbix_server.log, utf8] |
vfs.file.size.bytes |
vfs.*.contents | 匹配以 vfs. 开头并以 .contents 结尾且不带任何参数的所有键。 |
vfs.mount.point.file.contents vfs..contents |
vfs.contents |
一个假设的脚本如 'myscript.sh' 可以通过 一个主机 在 Zabbix agent 上以多种方式执行:
1. 作为被动或主动检查中的一个 监控项 键值,例如:
在此情况下,用户可以在 system.run[] 中添加 "wait"、"nowait" 或省略第二个参数以使用其默认值。
2. 作为一个全局脚本(由前端或 API 中的用户发起)。
用户在 告警 → 脚本 中配置此脚本,设置 "执行于:Zabbix agent" 并将 "myscript.sh" 填入脚本的 "命令" 输入框。从前端或 API 调用时,Zabbix 服务器将发送至 agent:
在此情况下,用户无法控制 "wait"/"nowait" 参数。
3. 作为来自动作的远程命令。Zabbix server 发送至 agent:
在此情况下,用户同样无法控制 "wait"/"nowait" 参数。
这意味着如果我们设置 AllowKey 如下:
那么
要允许所有上述变体,您可以添加:
到 agent/agent2 参数中。