circonus 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,38 +6,46 @@
6
6
  require 'circonusutil'
7
7
 
8
8
  host = nil
9
- cu = CirconusUtil.new() { |opts,options|
9
+ @cu = CirconusUtil.new() { |opts,options|
10
10
  options[:brokers] = []
11
11
  options[:hostname] = nil
12
12
  options[:url] = nil
13
- options[:tags] = ['application:http']
13
+ options[:tags] = ['application:http','source:manual']
14
14
  opts.banner = "Usage: #{File.basename($0)}\n"
15
- opts.on( '--tags TAGLIST',"Apply comma separated list of tags (default: empty list)" ) { |t| options[:tags] += options[:tags] + t.split(/,/) }
15
+ opts.on( '--tags TAGLIST',"Apply comma separated list of tags (default: empty list)" ) { |t| options[:tags] += t.split(/,/) }
16
16
  opts.on( '--brokers BROKER',"Comma separated list of broker names to use" ) { |t| options[:brokers] = t.split(',') }
17
17
  opts.on( '--hostname HOSTNAME',"Hostname to add" ) { |t| options[:hostname] = t }
18
+ opts.on( '--contactgroups CONTACTGROUPS',"Comma separated list of contact groups to send alerts to" ) { |t| options[:contactgroups] = t }
18
19
  opts.on( '--url URL',"URL to test" ) { |t| options[:url] = t }
19
20
  }
20
- if cu.options[:brokers].empty?
21
+ if @cu.options[:brokers].empty?
21
22
  puts "Missing brokers list"
22
23
  exit -1
23
24
  end
24
- if cu.options[:hostname].empty?
25
+ if @cu.options[:hostname].empty?
25
26
  puts "Missing hostname"
26
27
  exit -1
27
28
  end
28
- if cu.options[:url].empty?
29
+ if @cu.options[:url].empty?
29
30
  puts "Missing url"
30
31
  exit -1
31
32
  end
33
+ if @cu.options[:contactgroups].empty?
34
+ puts "Missing contact group(s)"
35
+ exit -1
36
+ end
37
+ @cu.options[:tags].sort!.uniq!
38
+ @cu.options[:contactgroups] = @cu.options[:contactgroups].split(',').sort.uniq
39
+ @cu.options[:brokers].sort!.uniq!
32
40
 
33
41
  def do_update_check_bundle(cu,data)
34
- search_check_bundle = cu.circonus.list_check_bundle({'display_name' => data['display_name']})
42
+ search_check_bundle = @cu.circonus.list_check_bundle({'display_name' => data['display_name']})
35
43
  existing = false
36
44
  if search_check_bundle.any? # already exists...
37
45
  existing = true
38
- r = cu.circonus.update_check_bundle(search_check_bundle.first['_cid'],data)
46
+ r = @cu.circonus.update_check_bundle(search_check_bundle.first['_cid'],data)
39
47
  else
40
- r = cu.circonus.add_check_bundle(data)
48
+ r = @cu.circonus.add_check_bundle(data)
41
49
  end
42
50
  if not r.nil? then
43
51
  pp r
@@ -45,11 +53,10 @@ def do_update_check_bundle(cu,data)
45
53
  end
46
54
  end
47
55
 
48
- brokerids = []
49
- cu.options[:brokers].each do |broker|
50
- circonus_brokers = cu.circonus.list_broker({'_name'=>broker})
51
- id = circonus_brokers.map { |m| m['_cid'] }.first
52
- brokerids << id
56
+ brokers = {}
57
+ @cu.options[:brokers].each do |broker|
58
+ circonus_brokers = @cu.circonus.list_broker({'_name'=>broker})
59
+ brokers[broker] = circonus_brokers.map { |m| m['_cid'] }.first
53
60
  end
54
61
 
55
62
  bundle_stub = {
@@ -81,21 +88,129 @@ bundle_stub = {
81
88
  }
82
89
 
83
90
  bundle = bundle_stub.clone
84
- bundle['brokers'] = brokerids
85
- bundle['target'] = cu.options[:hostname]
86
- bundle['tags'] = cu.options[:tags]
87
- bundle['display_name'] = "#{cu.options[:hostname]} http"
88
- bundle['config']['url'] = cu.options[:url]
89
- bundle['config']['header_Host'] = cu.options[:hostname]
90
-
91
- search_bundles = cu.circonus.search_check_bundle(bundle['display_name'],'display_name')
91
+ bundle['brokers'] = brokers.values.sort
92
+ bundle['target'] = @cu.options[:hostname]
93
+ bundle['tags'] = @cu.options[:tags]
94
+ bundle['display_name'] = "#{@cu.options[:hostname]} http"
95
+ bundle['config']['url'] = @cu.options[:url]
96
+ bundle['config']['header_Host'] = @cu.options[:hostname]
97
+ search_bundles = @cu.circonus.search_check_bundle(bundle['display_name'],'display_name')
92
98
  if search_bundles.any? # already exists...
93
- r = cu.circonus.update_check_bundle(search_bundles.first['_cid'],bundle)
99
+ r = @cu.circonus.update_check_bundle(search_bundles.first['_cid'],bundle)
94
100
  else
95
- r = cu.circonus.add_check_bundle(bundle)
101
+ r = @cu.circonus.add_check_bundle(bundle)
96
102
  end
97
103
  if not r.nil? then
98
104
  print "Success\n"
99
105
  #pp r
100
106
  end
107
+ checkids = r["_checks"]
108
+
109
+ def mib_add_datapoint!(graph,metric_name,datapoint={})
110
+ init_datapoint = {
111
+ 'color'=>nil,
112
+ "axis"=>'l',
113
+ "stack"=>nil,
114
+ "hidden"=>false,
115
+ "derive"=>"gauge",
116
+ "metric_name"=>metric_name,
117
+ "metric_type"=>"numeric"
118
+ }
119
+ new_datapoint = init_datapoint.merge(datapoint)
120
+ graph['datapoints'] << new_datapoint
121
+ new_datapoint
122
+ end
123
+
124
+ # Add a graph to the monitoring bundle
125
+ def mib_add_graph!(title,options={})
126
+ init_graph = {
127
+ 'title'=>title,
128
+ 'tags'=>[],
129
+ 'style'=>'line',
130
+ 'composites'=>[],
131
+ 'datapoints'=>[],
132
+ 'guides'=>[]
133
+ }
134
+ new_graph = init_graph.merge(options)
135
+ new_graph
136
+ end
137
+
138
+ puts "Adding graphs"
139
+ graph = mib_add_graph!("#{@cu.options[:hostname]} http latency",{'style'=>'line','tags'=>@cu.options[:tags],'min_left_y'=>0})
140
+
141
+ checkids.each do |cid|
142
+ dpcid = cid.split('/').last.to_i
143
+ %w{ tt_connect tt_firstbyte duration }.each do |metric|
144
+ mib_add_datapoint!(graph,metric,{'name'=>"metric cid:#{dpcid}",'legend_formula'=>'=round(VAL,3)','data_formula'=>'=VAL/1000.0','check_id'=>dpcid})
145
+ end
146
+ end
147
+ #pp graph
148
+ r = @cu.circonus.add_graph(graph)
149
+ if not r.nil? then
150
+ print "Success\n"
151
+ else
152
+ puts "add_graph results: #{r.inspect}"
153
+ end
154
+
155
+ def mib_add_rule_set!(metric_name,rule_set={})
156
+ contactgroupids = []
157
+ @cu.options[:contactgroups].each do |cgname|
158
+ r = @cu.circonus.list_contact_group({'name'=>cgname})
159
+ contactgroupids += r.map { |m| m['_cid'] }
160
+ end
161
+ init_rule_set = {
162
+ 'metric_name' => metric_name,
163
+ 'metric_type' => 'numeric',
164
+ 'contact_groups' => {
165
+ '1'=>contactgroupids,
166
+ '2'=>contactgroupids,
167
+ '3'=>contactgroupids,
168
+ '4'=>contactgroupids,
169
+ '5'=>contactgroupids
170
+ },
171
+ 'rules'=>[],
172
+ 'derive'=>nil # can be either counter or nil (nil means you want a gauge)
173
+ }
174
+ new_rule_set = init_rule_set.merge(rule_set)
175
+ new_rule_set
176
+ end
177
+
178
+ # Add a rule to the given rule_set
179
+ def mib_add_rule!(rule_set,rule={})
180
+ init_rule = {
181
+ 'criteria'=>'max value',
182
+ 'severity'=>5,
183
+ 'value'=>3000,
184
+ 'wait'=>300
185
+ }
186
+ new_rule = init_rule.merge(rule)
187
+ rule_set['rules'] << new_rule
188
+ new_rule
189
+ end
190
+
191
+ puts "Adding rule sets"
192
+ ######## http latency alert #########
193
+ checkids.each do |cid|
194
+ rcid = cid.split('/').last.to_i
195
+ rs = mib_add_rule_set!('duration',{'check'=>rcid})
196
+ mib_add_rule!(rs,{ "criteria"=>"on absence", "severity"=>1, "value"=>180 })
197
+ mib_add_rule!(rs,{ "criteria"=>"max value", "severity"=>1, "value"=>5000 })
198
+ mib_add_rule!(rs,{ "criteria"=>"max value", "severity"=>2, "value"=>4000 })
199
+ #pp rs
200
+ r = @cu.circonus.add_rule_set(rs)
201
+ if not r.nil? then
202
+ print "Success\n"
203
+ end
204
+ ######## http status code alert #########
205
+ rs = mib_add_rule_set!('code',{'metric_type'=>'text','check'=>rcid})
206
+ mib_add_rule!(rs,{ "criteria"=>"does not contain", "severity"=>2, "value"=>'^[23]\\d\\d$' })
207
+ #pp rs
208
+ r = @cu.circonus.add_rule_set(rs)
209
+ if not r.nil? then
210
+ print "Success\n"
211
+ end
212
+ end
213
+
214
+
215
+
101
216
 
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'circonusutil'
3
+ cu = CirconusUtil.new
4
+ cu.circonus.list_broker.each do |b|
5
+ printf("%-40s %s\n",b['_name'],b['_details'].first['ipaddress'])
6
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require 'circonusutil'
3
+ cu = CirconusUtil.new
4
+ cu.circonus.list_contact_group.each do |b|
5
+ printf("%-40s\n",b['name'])
6
+ end
7
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circonus
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-20 00:00:00.000000000 Z
12
+ date: 2014-08-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -73,8 +73,10 @@ extra_rdoc_files: []
73
73
  files:
74
74
  - lib/circonusutil.rb
75
75
  - lib/circonus.rb
76
+ - bin/circonus-list-brokers
76
77
  - bin/circonus-add-http-check
77
78
  - bin/circonus-delete-host
79
+ - bin/circonus-list-contactgroups
78
80
  - bin/circonus-add-composite
79
81
  - bin/circonus-list-tags
80
82
  - bin/circonus-list-checkbundle