Skip to content

Instantly share code, notes, and snippets.

View julianeon's full-sized avatar

Julian Martinez julianeon

View GitHub Profile
@julianeon
julianeon / pd-create-service.rb
Created April 4, 2014 22:14
Use this to create services through the API.
require 'json'
subdomain="CHANGE_THIS"
api_key="CHANGE_THIS"
endpoint="https://CHANGE_THIS.pagerduty.com/api/v1/services"
service_name="CHANGE_THIS"
key_service="CHANGE_THIS"
about="CHANGE_THIS."
escalation_policy="CHANGE_THIS"
@julianeon
julianeon / pd-create-users-csv.rb
Last active August 29, 2015 13:58
A script to import multiple users to your account at once, as long as they follow the formatting given below for the CSV file.
require 'json'
#csv needs to be in this format
#role,name,email_address
#with real-looking values:
#user,Aaron,aaronexample@gmail.com
#to add more fields, see the API, then add them to your csv file and add fields below in user_json
#the four variables below need to be changed; nothing else
usercsv="CHANGE_THIS"
@julianeon
julianeon / pd_gmail_cleared_integration.rb
Last active August 29, 2015 13:58
Check your Gmail inbox for CLEARED emails, then go to PagerDuty and clear any incidents with a matching subject line. Please note that this script will require some customization and probably cannot be used 'as is.'
require 'rubygems'
require 'gmail'
require 'curb'
require 'json'
#credentials to login to PagerDuty and resolve incidents
subdomain="CHANGE_THIS"
api_token="CHANGE_THIS"
user_id_resolver = "CHANGE_THIS"
@julianeon
julianeon / pd-create-nagios-incident.rb
Created April 16, 2014 00:10
Nagios incident-creating script. Work in progress.
require 'json'
subdomain="change_this"
api_key="change_this"
endpoint="https://events.pagerduty.com/generic/2010-04-15/create_event.json"
service_id="change_this"
service_access_key="change_this"
incident_key="change_this"
subject="change_this"
@julianeon
julianeon / csv_rearranger.rb
Created April 25, 2014 19:15
A very simple short script to rearrange unsorted csv files. Please note that sorting by fields could also be accomplished, as can printing the csv file with a different field order.
filename="CHANGE_THIS.txt"
lines=File.readlines(filename)
puts lines.sort
file_rewrite=File.open(filename,"w")
file_rewrite.puts lines.sort
require 'json'
#where to print your file output to
filename="CHANGE_THIS.txt"
subdomain="CHANGE_THIS"
service_id="CHANGE_THIS"
api_key="CHANGE_THIS"
endpoint="https://#{subdomain}.pagerduty.com/api/v1/incidents/"
@julianeon
julianeon / pd-get-incident-id.rb
Created April 30, 2014 17:24
Returns the information from a single incident.
require 'json'
incident_id="CHANGE_THIS"
subdomain="CHANGE_THIS"
api_key="CHANGE_THIS"
endpoint="https://#{subdomain}.pagerduty.com/api/v1/incidents/#{incident_id}"
def curl_get_id(tokennum,endpoint)
@julianeon
julianeon / pd-get-alerts.rb
Last active August 29, 2015 14:00
Getting all the alerts in a date range.
require 'curb'
require 'json'
subdomain="CHANGE_THIS"
api_access_key="CHANGE_THIS"
since_date="CHANGE_THIS_EXAMPLE_2014-04-01T01:00Z"
until_date="CHANGE_THIS_EXAMPLE_2014-04-05T01:00Z"
endpoint="https://#{subdomain}.pagerduty.com/api/v1/alerts"
endpoint << "?since=#{since_date}&until=#{until_date}"
@julianeon
julianeon / nokogiri.rb
Created May 6, 2014 23:30
An example of using nokogiri for regular expression matching.
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we’re interested in...
def space_replace(word)
word = word.gsub(' ',"+")
end
term=ARGV[0]
@julianeon
julianeon / interest.rb
Created May 7, 2014 01:37
To compute interest, example script for demonstrating Ruby.
base=1000
mult=1.01
10.times do |x|
base *= mult
year = x/12
month=x%12
nice_number=base.round(0)
comma_number=nice_number.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
puts "#{comma_number} #{year} #{month}"
end