Skip to content
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

Support Sensu Go 5.6 #1105

Merged
merged 4 commits into from May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 6 additions & 10 deletions lib/puppet/provider/sensu_ad_auth/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
auths = []

output = sensuctl_list('auth', false)
Puppet.debug("sensu auth: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl auth list')
data = []
end
data = sensuctl_list('auth', false)

auth_types = sensuctl_auth_types()
data.each do |d|
Expand All @@ -37,6 +30,9 @@ def self.instances
s['port'] = server['port']
s['insecure'] = server['insecure']
s['security'] = server['security']
s['trusted_ca_file'] = server['trusted_ca_file']
s['client_cert_file'] = server['client_cert_file']
s['client_key_file'] = server['client_key_file']
binding[s['host']] = server['binding']
group_search[s['host']] = server['group_search']
user_search[s['host']] = server['user_search']
Expand Down Expand Up @@ -82,7 +78,7 @@ def create
spec[:servers] = []
resource[:servers].each do |server|
host = server['host']
server['binding'] = resource[:server_binding][host]
server['binding'] = resource[:server_binding][host] if resource[:server_binding]
server['group_search'] = resource[:server_group_search][host]
server['user_search'] = resource[:server_user_search][host]
spec[:servers] << server
Expand All @@ -108,7 +104,7 @@ def flush
if @property_flush[:server_binding]
server['binding'] = @property_flush[:server_binding][host]
else
server['binding'] = resource[:server_binding][host]
server['binding'] = resource[:server_binding][host] if resource[:server_binding]
treydock marked this conversation as resolved.
Show resolved Hide resolved
end
if @property_flush[:server_group_search]
server['group_search'] = @property_flush[:server_group_search][host]
Expand Down
10 changes: 1 addition & 9 deletions lib/puppet/provider/sensu_asset/sensuctl.rb
Expand Up @@ -8,15 +8,7 @@
def self.instances
assets = []

output = sensuctl_list('asset')
Puppet.debug("sensu assets: #{output}")
begin
data = JSON.parse(output)
return [] if data.nil?
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl asset list')
data = []
end
data = sensuctl_list('asset')

data.each do |d|
asset = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_check/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
checks = []

output = sensuctl_list('check')
Puppet.debug("sensu checks: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl check list')
data = []
end
data = sensuctl_list('check')

data.each do |d|
check = {}
Expand Down
8 changes: 7 additions & 1 deletion lib/puppet/provider/sensu_cluster_member/sensuctl.rb
Expand Up @@ -11,7 +11,13 @@ def self.instances
output = sensuctl('cluster', 'member-list', '--format', 'json')
Puppet.debug("sensu cluster members: #{output}")
begin
data = JSON.parse(output)
j = output.split(/\n\n/)
if j.size >= 2
_json = j[1]
else
_json = j[0]
end
data = JSON.parse(_json)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl cluster member-list')
data = {'members' => []}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_cluster_role/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
cluster_roles = []

output = sensuctl_list('cluster-role', false)
Puppet.debug("sensu cluster_roles: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl cluster_role list')
data = []
end
data = sensuctl_list('cluster-role', false)

data.each do |d|
cluster_role = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_cluster_role_binding/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
bindings = []

output = sensuctl_list('cluster-role-binding', false)
Puppet.debug("sensu cluster_role_bindings: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl cluster_role list')
data = []
end
data = sensuctl_list('cluster-role-binding', false)

data.each do |d|
binding = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_entity/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
entities = []

output = sensuctl_list('entity')
Puppet.debug("sensu entities: #{output}")
treydock marked this conversation as resolved.
Show resolved Hide resolved
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl entity list')
data = []
end
data = sensuctl_list('entity')

data.each do |d|
entity = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_event/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
events = []

output = sensuctl_list('event')
Puppet.debug("sensu event: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl event list')
data = []
end
data = sensuctl_list('event')

data.each do |d|
event = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_filter/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
filters = []

output = sensuctl_list('filter')
Puppet.debug("sensu filters: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl filter list')
data = []
end
data = sensuctl_list('filter')

data.each do |d|
filter = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_handler/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
handlers = []

output = sensuctl_list('handler')
Puppet.debug("sensu handlers: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl handler list')
data = []
end
data = sensuctl_list('handler')

data.each do |d|
handler = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_hook/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
hooks = []

output = sensuctl_list('hook')
Puppet.debug("sensu hooks: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl hook list')
data = []
end
data = sensuctl_list('hook')

data.each do |d|
hook = {}
Expand Down
16 changes: 6 additions & 10 deletions lib/puppet/provider/sensu_ldap_auth/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
auths = []

output = sensuctl_list('auth', false)
Puppet.debug("sensu auth: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl auth list')
data = []
end
data = sensuctl_list('auth', false)

auth_types = sensuctl_auth_types()
data.each do |d|
Expand All @@ -37,6 +30,9 @@ def self.instances
s['port'] = server['port']
s['insecure'] = server['insecure']
s['security'] = server['security']
s['trusted_ca_file'] = server['trusted_ca_file']
s['client_cert_file'] = server['client_cert_file']
s['client_key_file'] = server['client_key_file']
binding[s['host']] = server['binding']
group_search[s['host']] = server['group_search']
user_search[s['host']] = server['user_search']
Expand Down Expand Up @@ -82,7 +78,7 @@ def create
spec[:servers] = []
resource[:servers].each do |server|
host = server['host']
server['binding'] = resource[:server_binding][host]
server['binding'] = resource[:server_binding][host] if resource[:server_binding]
server['group_search'] = resource[:server_group_search][host]
server['user_search'] = resource[:server_user_search][host]
spec[:servers] << server
Expand All @@ -108,7 +104,7 @@ def flush
if @property_flush[:server_binding]
server['binding'] = @property_flush[:server_binding][host]
else
server['binding'] = resource[:server_binding][host]
server['binding'] = resource[:server_binding][host] if resource[:server_binding]
end
if @property_flush[:server_group_search]
server['group_search'] = @property_flush[:server_group_search][host]
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_mutator/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
mutators = []

output = sensuctl_list('mutator')
Puppet.debug("sensu mutators: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl mutator list')
data = []
end
data = sensuctl_list('mutator')

data.each do |d|
mutator = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_namespace/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
namespaces = []

output = sensuctl_list('namespace', false)
Puppet.debug("sensu namespaces: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl namespace list')
data = []
end
data = sensuctl_list('namespace', false)

data.each do |d|
namespace = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_role/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
roles = []

output = sensuctl_list('role')
Puppet.debug("sensu roles: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl role list')
data = []
end
data = sensuctl_list('role')

data.each do |d|
role = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_role_binding/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
bindings = []

output = sensuctl_list('role-binding')
Puppet.debug("sensu role_bindings: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl role list')
data = []
end
data = sensuctl_list('role-binding')

data.each do |d|
binding = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_silenced/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
silencings = []

output = sensuctl_list('silenced')
Puppet.debug("sensu silencings: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl silenced list')
data = []
end
data = sensuctl_list('silenced')

data.each do |d|
silenced = {}
Expand Down
9 changes: 1 addition & 8 deletions lib/puppet/provider/sensu_user/sensuctl.rb
Expand Up @@ -8,14 +8,7 @@
def self.instances
users = []

output = sensuctl_list('user', false)
Puppet.debug("sensu users: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug('Unable to parse output from sensuctl user list')
data = []
end
data = sensuctl_list('user', false)

data.each do |d|
user = {}
Expand Down
12 changes: 11 additions & 1 deletion lib/puppet/provider/sensuctl.rb
Expand Up @@ -51,7 +51,17 @@ def self.sensuctl_list(command, namespaces = true)
end
args << '--format'
args << 'json'
sensuctl(args)
data = []
output = sensuctl(args)
Puppet.debug("sensuctl #{args.join(' ')}: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError => e
Puppet.debug("Unable to parse output from sensuctl #{args.join(' ')}")
return []
end
return [] if data.nil?
data
end

def self.sensuctl_create(type, metadata, spec, api_version = 'core/v2')
Expand Down