-
Notifications
You must be signed in to change notification settings - Fork 829
Add Zabbix agent rules #15128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
israel-villar
wants to merge
3
commits into
ComplianceAsCode:master
Choose a base branch
from
israel-villar:feat/zabbix-agent-rules
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Zabbix agent rules #15128
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| name: zabbix | ||
| packages: | ||
| - zabbix-agent | ||
| rules: | ||
| - package_zabbix_agent_installed | ||
| - service_zabbix_agent_enabled | ||
| - zabbix_agent_server_configured | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'Zabbix Agent' | ||
|
|
||
| description: |- | ||
| Zabbix is a network monitoring solution used to monitor the | ||
| status and performance of servers. This section discusses how to | ||
| configure the Zabbix agent for best effect. |
20 changes: 20 additions & 0 deletions
20
linux_os/guide/services/zabbix/package_zabbix_agent_installed/rule.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'Ensure Zabbix Agent Is Installed' | ||
|
|
||
| description: |- | ||
| {{{ describe_package_install(package="zabbix-agent") }}} | ||
|
|
||
| rationale: |- | ||
| The zabbix-agent package provides the Zabbix monitoring agent, which | ||
| reports system status and performance metrics to a central Zabbix | ||
| monitoring server. | ||
|
|
||
| severity: medium | ||
|
|
||
| {{{ complete_ocil_entry_package_installed("zabbix-agent") }}} | ||
|
|
||
| template: | ||
| name: package_installed | ||
| vars: | ||
| pkgname: zabbix-agent |
25 changes: 25 additions & 0 deletions
25
linux_os/guide/services/zabbix/service_zabbix_agent_enabled/rule.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'Ensure Zabbix Agent Is Enabled' | ||
|
|
||
| description: |- | ||
| {{{ describe_service_enable(service="zabbix-agent") }}} | ||
|
|
||
| rationale: |- | ||
| If the Zabbix agent is not running, the server cannot be monitored, | ||
| delaying detection of outages or performance issues. | ||
|
|
||
| severity: medium | ||
|
|
||
| ocil_clause: 'the zabbix-agent process is not running' | ||
|
|
||
| ocil: |- | ||
| {{{ ocil_service_enabled(service="zabbix-agent") }}} | ||
|
|
||
| fixtext: '{{{ fixtext_service_enabled(service="zabbix-agent") }}}' | ||
|
|
||
| template: | ||
| name: service_enabled | ||
| vars: | ||
| servicename: zabbix-agent | ||
| packagename: zabbix-agent |
55 changes: 55 additions & 0 deletions
55
linux_os/guide/services/zabbix/zabbix_agent_server_configured/oval/shared.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <def-group> | ||
| <definition class="compliance" id="{{{ rule_id }}}" version="1"> | ||
| {{{ oval_metadata("Zabbix agent should report to a designated server, not the packaged default", rule_title=rule_title) }}} | ||
| <criteria operator="AND"> | ||
| <criterion test_ref="test_zabbix_server_set" comment="Server directive is configured" /> | ||
| <criterion test_ref="test_zabbix_server_not_default" comment="Server directive is not left at 127.0.0.1" /> | ||
| <criterion test_ref="test_zabbix_serveractive_set" comment="ServerActive directive is configured" /> | ||
| <criterion test_ref="test_zabbix_serveractive_not_default" comment="ServerActive directive is not left at 127.0.0.1" /> | ||
| </criteria> | ||
| </definition> | ||
|
|
||
| <ind:textfilecontent54_test id="test_zabbix_server_set" version="1" | ||
| check="all" check_existence="at_least_one_exists" | ||
| comment="Server directive is present in zabbix_agentd.conf"> | ||
| <ind:object object_ref="object_zabbix_server_set"/> | ||
| </ind:textfilecontent54_test> | ||
| <ind:textfilecontent54_object id="object_zabbix_server_set" version="1"> | ||
| <ind:filepath>/etc/zabbix/zabbix_agentd.conf</ind:filepath> | ||
| <ind:pattern operation="pattern match">^Server=\S+</ind:pattern> | ||
| <ind:instance datatype="int">1</ind:instance> | ||
| </ind:textfilecontent54_object> | ||
|
|
||
| <ind:textfilecontent54_test id="test_zabbix_server_not_default" version="1" | ||
| check="all" check_existence="none_exist" | ||
| comment="Server directive is not left at 127.0.0.1"> | ||
| <ind:object object_ref="object_zabbix_server_not_default"/> | ||
| </ind:textfilecontent54_test> | ||
| <ind:textfilecontent54_object id="object_zabbix_server_not_default" version="1"> | ||
| <ind:filepath>/etc/zabbix/zabbix_agentd.conf</ind:filepath> | ||
| <ind:pattern operation="pattern match">^Server=127\.0\.0\.1\s*$</ind:pattern> | ||
| <ind:instance datatype="int">1</ind:instance> | ||
| </ind:textfilecontent54_object> | ||
|
|
||
| <ind:textfilecontent54_test id="test_zabbix_serveractive_set" version="1" | ||
| check="all" check_existence="at_least_one_exists" | ||
| comment="ServerActive directive is present in zabbix_agentd.conf"> | ||
| <ind:object object_ref="object_zabbix_serveractive_set"/> | ||
| </ind:textfilecontent54_test> | ||
| <ind:textfilecontent54_object id="object_zabbix_serveractive_set" version="1"> | ||
| <ind:filepath>/etc/zabbix/zabbix_agentd.conf</ind:filepath> | ||
| <ind:pattern operation="pattern match">^ServerActive=\S+</ind:pattern> | ||
| <ind:instance datatype="int">1</ind:instance> | ||
| </ind:textfilecontent54_object> | ||
|
|
||
| <ind:textfilecontent54_test id="test_zabbix_serveractive_not_default" version="1" | ||
| check="all" check_existence="none_exist" | ||
| comment="ServerActive directive is not left at 127.0.0.1"> | ||
| <ind:object object_ref="object_zabbix_serveractive_not_default"/> | ||
| </ind:textfilecontent54_test> | ||
| <ind:textfilecontent54_object id="object_zabbix_serveractive_not_default" version="1"> | ||
| <ind:filepath>/etc/zabbix/zabbix_agentd.conf</ind:filepath> | ||
| <ind:pattern operation="pattern match">^ServerActive=127\.0\.0\.1\s*$</ind:pattern> | ||
| <ind:instance datatype="int">1</ind:instance> | ||
| </ind:textfilecontent54_object> | ||
| </def-group> |
39 changes: 39 additions & 0 deletions
39
linux_os/guide/services/zabbix/zabbix_agent_server_configured/rule.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'Ensure Zabbix Agent Reports To A Designated Server' | ||
|
|
||
| description: |- | ||
| The Zabbix agent must be configured to report to the Zabbix server | ||
| corresponding to the network segment the host is on, by editing | ||
| <tt>Server</tt> and <tt>ServerActive</tt> in | ||
| <tt>/etc/zabbix/zabbix_agentd.conf</tt>: | ||
| <pre>Server=<zabbix_server_address> | ||
| ServerActive=<zabbix_server_address></pre> | ||
|
|
||
| rationale: |- | ||
| Leaving the agent at its packaged default (<tt>127.0.0.1</tt>) means it | ||
| is not actually reporting to any monitoring server, defeating the | ||
| purpose of having it installed. | ||
|
|
||
| severity: medium | ||
|
|
||
| warnings: | ||
| - general: |- | ||
| This rule doesn't come with a remediation; the correct Zabbix server | ||
| address depends on the network segment the host is on and needs to | ||
| be set by the administrator. | ||
|
|
||
| ocil_clause: 'Server or ServerActive is missing or left at the packaged default' | ||
|
|
||
| ocil: |- | ||
| Run the following command: | ||
| <pre># grep -E '^(Server|ServerActive)=' /etc/zabbix/zabbix_agentd.conf</pre> | ||
| Both <tt>Server</tt> and <tt>ServerActive</tt> should be present and set | ||
| to the Zabbix server address for this network segment, not left at the | ||
| packaged default of <tt>127.0.0.1</tt>. | ||
|
|
||
| fixtext: |- | ||
| Edit <tt>/etc/zabbix/zabbix_agentd.conf</tt> and set <tt>Server</tt> and | ||
| <tt>ServerActive</tt> to the Zabbix server address for this network | ||
| segment. Restart the service: | ||
| <pre># systemctl restart zabbix-agent.service</pre> |
11 changes: 11 additions & 0 deletions
11
linux_os/guide/services/zabbix/zabbix_agent_server_configured/tests/both_configured.pass.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/bash | ||
| # packages = zabbix-agent | ||
| # platform = multi_platform_debian | ||
|
|
||
| # Both Server and ServerActive point to a real monitoring server instead of | ||
| # the packaged 127.0.0.1 default. Expected result: PASS. | ||
| mkdir -p /etc/zabbix | ||
| cat > /etc/zabbix/zabbix_agentd.conf <<EOF | ||
| Server=192.168.1.10 | ||
| ServerActive=192.168.1.10 | ||
| EOF |
12 changes: 12 additions & 0 deletions
12
linux_os/guide/services/zabbix/zabbix_agent_server_configured/tests/default_values.fail.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
| # packages = zabbix-agent | ||
| # platform = multi_platform_debian | ||
| # remediation = none | ||
|
|
||
| # Both directives are left at the packaged default of 127.0.0.1, so the | ||
| # agent isn't actually reporting to any server. Expected result: FAIL. | ||
| mkdir -p /etc/zabbix | ||
| cat > /etc/zabbix/zabbix_agentd.conf <<EOF | ||
| Server=127.0.0.1 | ||
| ServerActive=127.0.0.1 | ||
| EOF |
9 changes: 9 additions & 0 deletions
9
..._os/guide/services/zabbix/zabbix_agent_server_configured/tests/directives_missing.fail.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/bin/bash | ||
| # packages = zabbix-agent | ||
| # platform = multi_platform_debian | ||
| # remediation = none | ||
|
|
||
| # Neither Server nor ServerActive is present in the config file at all. | ||
| # Expected result: FAIL. | ||
| mkdir -p /etc/zabbix | ||
| echo "# no Server/ServerActive directives" > /etc/zabbix/zabbix_agentd.conf |
12 changes: 12 additions & 0 deletions
12
linux_os/guide/services/zabbix/zabbix_agent_server_configured/tests/server_default.fail.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
| # packages = zabbix-agent | ||
| # platform = multi_platform_debian | ||
| # remediation = none | ||
|
|
||
| # ServerActive is configured, but Server is still left at the packaged | ||
| # 127.0.0.1 default. Expected result: FAIL. | ||
| mkdir -p /etc/zabbix | ||
| cat > /etc/zabbix/zabbix_agentd.conf <<EOF | ||
| Server=127.0.0.1 | ||
| ServerActive=192.168.1.10 | ||
| EOF |
12 changes: 12 additions & 0 deletions
12
...s/guide/services/zabbix/zabbix_agent_server_configured/tests/serveractive_default.fail.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
| # packages = zabbix-agent | ||
| # platform = multi_platform_debian | ||
| # remediation = none | ||
|
|
||
| # Server is configured, but ServerActive is still left at the packaged | ||
| # 127.0.0.1 default. Expected result: FAIL. | ||
| mkdir -p /etc/zabbix | ||
| cat > /etc/zabbix/zabbix_agentd.conf <<EOF | ||
| Server=192.168.1.10 | ||
| ServerActive=127.0.0.1 | ||
| EOF |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refer to #15128 (comment) please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
▎ Thanks for the review, @macko1. Here are the exact official Zabbix sources for the decisions in this PR:
▎
▎ Server / ServerActive directive names and semantics — Zabbix agent (UNIX) configuration parameter reference:
▎ https://www.zabbix.com/documentation/current/en/manual/appendix/config/zabbix_agentd
▎ This confirms Server governs passive checks (mandatory unless StartAgents=0) and ServerActive governs active checks, which is why the check requires both to be set.
▎
▎ The 127.0.0.1 "packaged default" — the official upstream Zabbix source repository ships zabbix_agentd.conf with these two directives uncommented and set to 127.0.0.1:
▎ https://github.com/zabbix/zabbix/blob/master/conf/zabbix_agentd.conf#L132-L200
▎ (see ### Option: Server and ### Option: ServerActive — the parameter reference page itself documents no default, but this reference template is the file that ships as-is in the zabbix-agent package, which is why an unmodified install ends up with both directives pointing at 127.0.0.1.)
▎
▎ Passive vs. active checks concept, explaining why both directives are relevant to a correctly-configured agent:
▎ https://www.zabbix.com/documentation/current/en/manual/concepts/agent
▎
▎ I've also pushed a commit adding expected-result comments to each test scenario per your second request (587f3a8).