class ZabbixAgent
Public Instance Methods
deploy()
click to toggle source
# File lib/dust/recipes/zabbix_agent.rb, line 3 def deploy return unless install_zabbix # set daemon name, according zu distribution daemon = @node.uses_emerge? ? 'zabbix-agentd' : 'zabbix-agent' @node.write '/etc/zabbix/zabbix_agentd.conf', generate_zabbix_agentd_conf # restart using new configuration @node.autostart_service daemon @node.restart_service daemon if options.restart? end
status()
click to toggle source
# File lib/dust/recipes/zabbix_agent.rb, line 17 def status daemon = @node.uses_emerge? ? 'zabbix-agentd' : 'zabbix-agent' return unless @node.package_installed? daemon @node.print_service_status daemon end
Private Instance Methods
default_config()
click to toggle source
default zabbix_agentd.conf configuration options
# File lib/dust/recipes/zabbix_agent.rb, line 82 def default_config defaults = { 'StartAgents' => 5, 'DebugLevel' => 3, 'Timeout' => 30, 'Hostname' => @node['fqdn'], 'UserParameter' => [] } if @node.dir_exists?('/var/run/zabbix-agent', :quiet => true) defaults['PidFile'] ||= '/var/run/zabbix-agent/zabbix_agentd.pid' elsif @node.dir_exists?('/var/run/zabbix', :quiet => true) defaults['PidFile'] ||= '/var/run/zabbix/zabbix_agentd.pid' else defaults['PidFile'] ||= '/var/run/zabbix_agentd.pid' end if @node.dir_exists?('/var/log/zabbix-agent', :quiet => true) defaults['LogFile'] ||= '/var/log/zabbix-agent/zabbix_agentd.log' elsif @node.dir_exists?('/var/log/zabbix', :quiet => true) defaults['LogFile'] ||= '/var/log/zabbix/zabbix_agentd.log' else defaults['LogFile'] ||= '/var/log/zabbix_agentd.log' end defaults end
enable_apt()
click to toggle source
check for security patches and system updates on emerge systems
# File lib/dust/recipes/zabbix_agent.rb, line 136 def enable_apt updates = [ 'apt.updates,apt-cache search \'~U\' |wc -l' ] if @node.is_debian? @node.collect_facts updates << "debian.security,debsecan --suite #{@node['lsbdistcodename']} --only-fixed --format packages |wc -l" end updates end
enable_arcconf()
click to toggle source
monitor adaptec raid status
# File lib/dust/recipes/zabbix_agent.rb, line 128 def enable_arcconf [ 'raid.smart_warnings,/sbin/arcconf getconfig 1 pd |grep "S.M.A.R.T. warnings" | awk "{SMART += $4} END {print SMART}"', 'raid.disk_rpm,/sbin/arcconf getconfig 1 pd |grep "Power State" |grep -v "Full rpm" |wc -l', 'raid.disk_state,/sbin/arcconf getconfig 1 pd |grep "\s\sState" |grep -v "Online" |wc -l' ] end
enable_emerge()
click to toggle source
check for security patches and system updates on emerge systems
# File lib/dust/recipes/zabbix_agent.rb, line 151 def enable_emerge [ 'gentoo.security,glsa-check -t all 2>/dev/null | wc -l', 'gentoo.updates,emerge -uNDp @world | grep ebuild|wc -l', 'gentoo.portage,emerge --info| grep "Timestamp of tree" | sed -e s/\'Timestamp of tree\':// -e \'s/\n//\' | xargs -I {} date --date={} +%s |xargs -I {} expr $(date +%s) - {}', 'gentoo.config,find /etc/ -name "._cfg*" 2>/dev/null|wc -l' ] end
enable_postgres()
click to toggle source
monitor postgres database
# File lib/dust/recipes/zabbix_agent.rb, line 111 def enable_postgres [ 'psql.version,psql --version|head -n1', 'psql.server_processes,psql -U zabbix -t -c "select sum(numbackends) from pg_stat_database" postgres', 'psql.db_connections,psql -U zabbix -t -c "select count(*) from pg_stat_activity" postgres', 'psql.db_fetched,psql -U zabbix -t -c "select sum(tup_fetched) from pg_stat_database" postgres', 'psql.db_deleted,psql -U zabbix -t -c "select sum(tup_deleted) from pg_stat_database" postgres', 'psql.db_inserted,psql -U zabbix -t -c "select sum(tup_inserted) from pg_stat_database" postgres', 'psql.db_returned,psql -U zabbix -t -c "select sum(tup_returned) from pg_stat_database" postgres', 'psql.db_updated,psql -U zabbix -t -c "select sum(tup_updated) from pg_stat_database" postgres', 'psql.tx_commited,psql -U zabbix -t -c "select sum(xact_commit) from pg_stat_database" postgres', 'psql.tx_rolledback,psql -U zabbix -t -c "select sum(xact_rollback) from pg_stat_database" postgres', 'psql.blks_hit,psql -U zabbix -t -c "select sum(blks_hit) from pg_stat_database" postgres', 'psql.blks_read,psql -U zabbix -t -c "select sum(blks_read) from pg_stat_database" postgres' ] end
enable_rpm()
click to toggle source
check for security patches and system updates on emerge systems
# File lib/dust/recipes/zabbix_agent.rb, line 146 def enable_rpm [ 'centos.updates,yum check-update -q |wc -l' ] end
generate_zabbix_agentd_conf()
click to toggle source
generate zabbix_agentd.conf
# File lib/dust/recipes/zabbix_agent.rb, line 51 def generate_zabbix_agentd_conf @config = default_config.merge @config @config['UserParameter'] = Array @config['UserParameter'] # system updates @config['UserParameter'] |= enable_apt if @node.uses_apt? @config['UserParameter'] |= enable_rpm if @node.uses_rpm? @config['UserParameter'] |= enable_emerge if @node.uses_emerge? # additional monitoring (raid status and postgresql) @config['UserParameter'] |= enable_postgres if @node.package_installed? [ 'postgresql-server', 'postgresql' ], :quiet => true @config['UserParameter'] |= enable_arcconf if @node.package_installed? 'arcconf', :quiet => true zabbix_agentd_conf = '' # add normal configuration variables @config.each do |key, value| next if key == 'UserParameter' zabbix_agentd_conf << "#{key}=#{value}\n" end # add user parameters @config['UserParameter'].each do |user_parameter| zabbix_agentd_conf << "UserParameter=#{user_parameter}\n" end zabbix_agentd_conf end
install_zabbix()
click to toggle source
installs zabbix and its dependencies
# File lib/dust/recipes/zabbix_agent.rb, line 26 def install_zabbix if @node.uses_apt? # debsecan is needed for zabbix checks (security updates) return false unless @node.install_package 'zabbix-agent' return false unless @node.install_package 'debsecan' if @node.is_debian? elsif @node.uses_emerge? # glsa-check (part of gentoolkit) is needed for zabbix checks (security updates) return false unless @node.install_package 'zabbix', :env => 'USE=agent' return false unless @node.install_package 'gentoolkit' elsif @node.uses_rpm? return false unless @node.install_package 'zabbix-agent' else msg = @node.messages.add('os not supported') msg.failed return false end true end