dyntool 0.0.21 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/dyntool.rb +24 -4
  2. metadata +3 -3
data/lib/dyntool.rb CHANGED
@@ -6,6 +6,7 @@ require 'json'
6
6
  require 'ipaddr'
7
7
  require 'highline/import'
8
8
  require 'yaml'
9
+ require 'time'
9
10
  ### class for loading and retrieving configuration from dyn.yml
10
11
  class LoadConfig
11
12
  def SetConfFile
@@ -43,11 +44,20 @@ class LoadConfig
43
44
  @iplabel = @conf['ips'][ip]['label']
44
45
  end
45
46
  def GetIpWeight(ip,region)
46
- @weight = @conf['ips'][ip]['weight'][region]
47
+ @weight = @conf['ips'][ip][region]['weight']
48
+ end
49
+ def GetIpTTL(ip,region)
50
+ @weight = @conf['ips'][ip][region]['ttl']
47
51
  end
48
52
  def GetContacts
49
53
  @contacts = @conf['contacts']
50
54
  end
55
+ def GetGraphite
56
+ @graphite_server = @conf['graphite_server']
57
+ end
58
+ def GetNotifyApps
59
+ @apps = @conf['notify_apps']
60
+ end
51
61
  end
52
62
  ## Getting authentication creds from users
53
63
  class Utils
@@ -99,8 +109,9 @@ class Parameters
99
109
  @sconf.SetConfFile
100
110
  @sconf.GetHandler
101
111
  end
102
- def SendEvent(user,suffix)
112
+ def SendEvent(user,suffix,key)
103
113
  @data = []
114
+ @notify_apps = []
104
115
  @flag = "false"
105
116
  @ARGV.each do |arg|
106
117
  @data << "#{arg} "
@@ -116,7 +127,14 @@ class Parameters
116
127
  end
117
128
  if @flag == "false"
118
129
  abort("You are not connected to outbrain network / cant send event to logstash, aborting...")
119
- end
130
+ end
131
+ @graphite_server = @sconf.GetGraphite
132
+ @notify_apps = @sconf.GetNotifyApps
133
+ @notify_apps.each do |app|
134
+ `curl -H "x-api-key:#{key}" -d "deployment[app_name]=#{app}" -d "deployment[description]=External DNS Change" -d "deployment[changelog]=External DNS Change" -d "deployment[user]=#{user}" https://api.newrelic.com/deployments.xml > /dev/null 2>&1`
135
+ end
136
+ @time = Time.now.to_i
137
+ `echo "events.dns.change 1 #{@time}" | nc #{@graphite_server} 2003`
120
138
  end
121
139
  # Opening Session to dyn using creds from the command line
122
140
  def OpenTheSession(customer,user,password)
@@ -621,11 +639,13 @@ class OperateDyn
621
639
  @ips.each do |ip|
622
640
  @label = @@conf.GetIpLabel(ip)
623
641
  @weight = @@conf.GetIpWeight(ip,region)
642
+ @ttl = @@conf.GetIpTTL(ip,region)
624
643
  @labels << "#{@label}"
625
644
  @weights << "#{@weight}"
645
+ @ttls << "#{@ttl}"
626
646
  end
627
647
  @labels = @labels.uniq
628
- @region_hash[@i] = { :name => "#{region}", :label => { :a_label => @labels}, :weight => { :a_weight => @weights }, :serve_count => { :a_serve_count => @ips_len }, :ttl => { :a_ttl => 60 }, :countries => @countries, :rdata => @ips_hash }
648
+ @region_hash[@i] = { :name => "#{region}", :label => { :a_label => @labels}, :weight => { :a_weight => @weights }, :serve_count => { :a_serve_count => @ips_len }, :ttl => { :a_ttl => @ttls }, :countries => @countries, :rdata => @ips_hash }
629
649
  end
630
650
  @record_data = { :name => "#{service}", :groups => [ @region_hash[1],@region_hash[2],@region_hash[3],@region_hash[4],@region_hash[5],@region_hash[6],@region_hash[7],@region_hash[8],@region_hash[9] ]}
631
651
  return(@record_data)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 21
9
- version: 0.0.21
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ariel Moskovich
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2013-09-15 00:00:00 +02:00
17
+ date: 2013-09-23 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20