Skip to content

Commit

Permalink
safe-for-work mode, more incident metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
smithclay committed Jul 29, 2015
1 parent 1640643 commit 0461eaf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions Gemfile
@@ -1,5 +1,6 @@
source "https://rubygems.org"

gem 'blasphemy'
gem 'faker'
gem 'httparty'
gem 'slop'
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -2,9 +2,12 @@ GEM
remote: https://rubygems.org/
specs:
blasphemy (0.2.0)
faker (1.4.3)
i18n (~> 0.5)
httparty (0.9.0)
multi_json (~> 1.0)
multi_xml
i18n (0.7.0)
multi_json (1.3.5)
multi_xml (0.5.1)
slop (3.5.0)
Expand All @@ -14,5 +17,6 @@ PLATFORMS

DEPENDENCIES
blasphemy
faker
httparty
slop
4 changes: 3 additions & 1 deletion bin/samuel-incident
Expand Up @@ -10,6 +10,7 @@ opts = Slop.parse(help: true) do
on :s, :service=, 'service guid'
on :d, :domain=, 'host'
on :n, :number=, 'number of incidents', as: Integer
on :safe=, 'safe for work', as: Integer
end

if opts[:service].nil?
Expand All @@ -19,8 +20,9 @@ end

options_hash = opts.to_hash
number_of_times = options_hash[:number] || 1
safe_for_work = options_hash[:safe] == 1 || true

event_creator = EventCreator.new(options_hash[:host] || 'https://events.pagerduty.com/', options_hash[:service])
event_creator = EventCreator.new(options_hash[:host] || 'https://events.pagerduty.com/', options_hash[:service], safe_for_work)
puts "Creating #{number_of_times} incident(s)..."
for i in 0...number_of_times
puts event_creator.post
Expand Down
17 changes: 11 additions & 6 deletions lib/generator.rb
@@ -1,6 +1,7 @@
require 'blasphemy'
require 'httparty'
require 'json'
require 'faker'

class EventCreator
include HTTParty
Expand All @@ -10,26 +11,30 @@ class EventCreator

attr_accessor :service_key, :base_uri

def initialize(host, service)
def initialize(host, service, safe_for_work)
@service_key = service
@base_uri = host
@sfw = safe_for_work
end

def generate_event
bacon = Faker::BaconIpsum.new
hacker = Faker::Hacker
sam = Faker::SamuelLIpsum.new
{ :service_key => @service_key,
:event_type => 'trigger',
:description => bacon.sentence,
:description => hacker.say_something_smart,
:contexts => [
{
'href' => 'https://www.youtube.com/watch?v=oUltheRpJNw',
'type' => 'image',
'src' => 'http://www.placecage.com/gif/300/180'
'href' => 'http://www.pagerduty.com',
'type' => 'link',
'text' => 'Incident Report'
}
],
:details => {
:quote => sam.paragraph
:mac_address => Faker::Internet.mac_address,
:ip_addr => Faker::Internet.ip_v4_address,
:quote => @sfw ? bacon.paragraph : sam.paragraph
}
}.to_json
end
Expand Down

0 comments on commit 0461eaf

Please sign in to comment.