Created
November 10, 2011 07:40
-
-
Save hedgehog/1354369 to your computer and use it in GitHub Desktop.
Papertrail webhook test client - POSTs JSON to a log processing webhook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby -w | |
# See http://help.papertrailapp.com/kb/how-it-works/web-hooks | |
require 'yajl' | |
require 'faraday' | |
class PapertrailWebhookRequest | |
def self.connection | |
Faraday::Connection.new | |
end | |
def self.run | |
results = { | |
"payload" => { | |
"saved_search" => { | |
:name => "Test search", | |
:html_search_url => "https://papertrailapp.com/events" | |
}, | |
"events" => [ | |
{ "program" => "postfix/smtpd", | |
"display_received_at" => "May 06 12:28:00", | |
"source_ip" => "1.2.3.4", | |
"source_name" => "somehost1", | |
"received_at" => "2011-07-06T12:28:00-07:00", | |
"message" => "NOQUEUE: reject: RCPT from 112-104-145-149.adsl.dynamic.seed.net.tw[112.104.145.149]: 554 5.7.1 <[email protected]>: Relay access denied; from=<[email protected]>", | |
"facility" => "User", | |
"severity" => "Notice", | |
"source_id" => 27223, | |
"id" => 3241602919305216, | |
"hostname" => "somehost1" }, | |
{ "program" => "production.log", | |
"display_received_at" => "May 06 12:28:30", | |
"source_ip" => "4.5.6.7", | |
"source_name" => "somehost4", | |
"received_at" => "2011-07-06T12:28:30-07:00", | |
"message" => "Completed in 50ms (View: 2, DB: 22) | 200 OK [https://adomain.com/path]", | |
"facility" => "User", | |
"severity" => "Notice", | |
"source_id" => 38281, | |
"id" => 3241602919305299, | |
"hostname" => "somehost4" }········· | |
], | |
"max_id" => 3241602919300000, | |
"min_id" => 3241602919310000 | |
},······ | |
} | |
···· | |
r = connection.post do |req| | |
req.url 'http://mydomain/path/to/webhook' | |
req.body = { | |
:payload => Yajl::Encoder.encode(results['payload']) | |
} | |
end | |
end | |
end | |
r = PapertrailWebhookRequest.run | |
puts "Response:\n#{r.body}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment