Here is a Puppet script which automatically install the Zabbix agent on the Puppet agents.
class system::zabbix {
# Install the required packages
package { "zabbix": ensure => installed }
package { "zabbix-agent": ensure => installed }
# Replace the default config
exec { "Remove the original zabbix agent config":
command => "rm /etc/zabbix/zabbix_agentd.conf",
onlyif => "grep -c 'Hostname=Zabbix server' /etc/zabbix/zabbix_agentd.conf",
}->
file { "/etc/zabbix/zabbix_agentd.conf":
source => "puppet:///modules/system/etc/zabbix/zabbix_agentd.conf",
owner => "root",
group => "root",
mode => "644",
ensure => "present",
replace => false, # Only create this file if it doesn't exist
}->
file_line { "Update ois zabbix agent config":
line => "Hostname=$hostname",
path => "/etc/zabbix/zabbix_agentd.conf",
match => "^Hostname=.*$",
ensure => present, # Restart the Zabbix agent if updated
notify => Service["zabbix-agent"],
}
# Enable the port for zabbix agent
firewall { '202 allow communication with zabbix server':
port => [10050],
proto => tcp,
action => accept,
}
# Start the zabbix agent
service { 'zabbix-agent':
ensure => 'running',
enable => true,
require => Package["zabbix-agent"],
}
}
Done =)
Reference:
