Skip to content

Fix agent registration #204

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
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions attributes/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@
default['zabbix']['agent']['snmp_port'] = '161'

default['zabbix']['agent']['user_parameter'] = []
default['zabbix']['agent']['server_search'] = 'recipe:zabbix\\:\\:server'
2 changes: 2 additions & 0 deletions attributes/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
default['zabbix']['web']['password'] = 'zabbix'
default['zabbix']['web']['install_method'] = 'apache'
default['zabbix']['web']['fqdn'] = node['fqdn']
default['zabbix']['web']['api']['uri'] = '/api_jasonrpc.php'
default['zabbix']['web']['api']['scheme'] = 'http'
default['zabbix']['web']['aliases'] = ['zabbix']
default['zabbix']['web']['port'] = 80

Expand Down
25 changes: 21 additions & 4 deletions providers/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
Chef::Application.fatal! "Could not find host #{new_resource.hostname}"
end

# Get,create and assign groups
if new_resource.groups.empty?
group_names = new_resource.parameters[:groupNames]
else
Expand All @@ -157,12 +158,28 @@
}
}
group = connection.query(get_desired_groups_request).first
if group.nil?
Chef::Application.fatal! "Could not find group '#{desired_group}'"
if group.nil? && new_resource.create_missing_groups
Chef::Log.info "Creating group #{desired_group}"
make_groups_request = {
:method => 'hostgroup.create',
:params => {
:name => desired_group
}
}
result = connection.query(make_groups_request)
# And now fetch the newly made group to be sure it worked
# and for later use
group = connection.query(get_desired_groups_request).first
Chef::Log.error('Error creating groups, see Chef errors') if result.nil? || group.nil?
elsif group
Chef::Log.info "Group #{desired_group} already exists"
else
Chef::Application.fatal! "Could not find group, #{desired_group}, for this host and \"create_missing_groups\" is False (or unset)"
end
acc << group
end

# Get/assign templates
if new_resource.templates.empty?
template_names = new_resource.parameters[:templates]
else
Expand All @@ -173,11 +190,11 @@
:method => 'template.get',
:params => {
:filter => {
:host => desired_template
:name => desired_template
}
}
}
template = connection.query(get_desired_templates_request)
template = connection.query(get_desired_templates_request).first
acc << template
end

Expand Down
4 changes: 2 additions & 2 deletions recipes/agent_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#

if !Chef::Config[:solo]
zabbix_server = search(:node, 'recipe:zabbix\\:\\:server').first
zabbix_server = search(:node, node['zabbix']['agent']['server_search']).first
else
if node['zabbix']['web']['fqdn']
zabbix_server = node
Expand All @@ -18,7 +18,7 @@
end

connection_info = {
:url => "http://#{zabbix_server['zabbix']['web']['fqdn']}/api_jsonrpc.php",
:url => "#{zabbix_server['zabbix']['web']['api']['scheme']}://#{zabbix_server['zabbix']['web']['fqdn']}#{zabbix_server['zabbix']['web']['api']['uri']}",
:user => zabbix_server['zabbix']['web']['login'],
:password => zabbix_server['zabbix']['web']['password']
}
Expand Down