Skip to content

Commit

Permalink
Stash api fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Igorshp committed Jan 14, 2015
1 parent 7601d73 commit ac527d4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
9 changes: 3 additions & 6 deletions definitions/silence_check.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
define :sensu_silence_check, :action => :create, :payload => {} do
define :sensu_silence_check, :action => :create, :expire => -1, :payload => {} do

if params[:client].nil?
params[:client] = node.name
end

if params[:action] == :create or params[:action] == :silence
# add a timestamp and owner to the payload
# when we look at the stash later, these bits helps us know how old a stash is and how it got there
merged_payload = params[:payload].merge({'timestamp' => Time.now.to_i, 'owner' => 'chef'})

sensu_api_stash "silence/#{params[:client]}/#{params[:name]}" do
api_uri params[:api_uri]
payload merged_payload
expire params[:expire]
payload params[:payload]
action :create
end
end
Expand Down
9 changes: 3 additions & 6 deletions definitions/silence_client.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
define :sensu_silence_client, :action => :create, :payload => {} do
define :sensu_silence_client, :action => :create, :expire => -1, :payload => {} do
if params[:action] == :create or params[:action] == :silence
# add a timestamp and owner to the payload
# when we look at the stash later, these bits helps us know how old a stash is and how it got there
merged_payload = params[:payload].merge({'timestamp' => Time.now.to_i, 'owner' => 'chef'})

sensu_api_stash "silence/#{params[:name]}" do
api_uri params[:api_uri]
payload merged_payload
expire params[:expire]
payload params[:payload]
action :create
end
end
Expand Down
7 changes: 6 additions & 1 deletion providers/api_stash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ def load_current_resource
action :create do
api = Sensu::API::Stash.new(new_resource.api_uri)
unless new_resource.payload == @current_resource.payload
if api.post("/stashes/#{new_resource.name}", new_resource.payload)
# add path, timestamp and owner to the payload
# when we look at the stash later, these bits helps us know how old a stash is and how it got there
# allow to overwrite payload completely
payload = {'path' => new_resource.name, 'expire' => new_resource.expire, 'content' => { 'timestamp' => Time.now.to_i, 'owner' => 'chef'}}
merged_payload = payload.merge(new_resource.payload)
if api.post("/stashes", merged_payload)
new_resource.updated_by_last_action(true)
end
end
Expand Down
1 change: 1 addition & 0 deletions resources/api_stash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

attribute :api_uri, :kind_of => String, :required => true
attribute :payload, :kind_of => [Hash, FalseClass], :default => Hash.new
attribute :expire, :kind_of => Integer, :default => -1

def initialize(*args)
super
Expand Down

0 comments on commit ac527d4

Please sign in to comment.