circonus 3.4.3 → 3.4.5
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.
- data/bin/circonus-add-http-check +101 -0
- metadata +2 -2
- data/examples/add_http_check.rb +0 -88
@@ -0,0 +1,101 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Add an HTTP site check
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'circonusutil'
|
7
|
+
|
8
|
+
host = nil
|
9
|
+
cu = CirconusUtil.new() { |opts,options|
|
10
|
+
options[:brokers] = []
|
11
|
+
options[:hostname] = nil
|
12
|
+
options[:url] = nil
|
13
|
+
options[:tags] = ['application:http']
|
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(/,/) }
|
16
|
+
opts.on( '--brokers BROKER',"Comma separated list of broker names to use" ) { |t| options[:brokers] = t.split(',') }
|
17
|
+
opts.on( '--hostname HOSTNAME',"Hostname to add" ) { |t| options[:hostname] = t }
|
18
|
+
opts.on( '--url URL',"URL to test" ) { |t| options[:url] = t }
|
19
|
+
}
|
20
|
+
if cu.options[:brokers].empty?
|
21
|
+
puts "Missing brokers list"
|
22
|
+
exit -1
|
23
|
+
end
|
24
|
+
if cu.options[:hostname].empty?
|
25
|
+
puts "Missing hostname"
|
26
|
+
exit -1
|
27
|
+
end
|
28
|
+
if cu.options[:url].empty?
|
29
|
+
puts "Missing url"
|
30
|
+
exit -1
|
31
|
+
end
|
32
|
+
|
33
|
+
def do_update_check_bundle(cu,data)
|
34
|
+
search_check_bundle = cu.circonus.list_check_bundle({'display_name' => data['display_name']})
|
35
|
+
existing = false
|
36
|
+
if search_check_bundle.any? # already exists...
|
37
|
+
existing = true
|
38
|
+
r = cu.circonus.update_check_bundle(search_check_bundle.first['_cid'],data)
|
39
|
+
else
|
40
|
+
r = cu.circonus.add_check_bundle(data)
|
41
|
+
end
|
42
|
+
if not r.nil? then
|
43
|
+
pp r
|
44
|
+
print "Success (#{existing ? 'updating' : 'adding'} #{data['display_name']})\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
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
|
53
|
+
end
|
54
|
+
|
55
|
+
bundle_stub = {
|
56
|
+
"brokers"=>[ ],
|
57
|
+
"display_name"=>nil,
|
58
|
+
"period"=>60,
|
59
|
+
"target"=>nil,
|
60
|
+
"timeout"=>10,
|
61
|
+
"type"=>"http",
|
62
|
+
"tags"=>[],
|
63
|
+
"metrics"=> [
|
64
|
+
{"name"=>"body_match", "type"=>"text"},
|
65
|
+
{"name"=>"bytes", "type"=>"numeric"},
|
66
|
+
{"name"=>"code", "type"=>"text"},
|
67
|
+
{"name"=>"duration", "type"=>"numeric"},
|
68
|
+
{"name"=>"truncated", "type"=>"numeric"},
|
69
|
+
{"name"=>"tt_connect", "type"=>"numeric"},
|
70
|
+
{"name"=>"tt_firstbyte", "type"=>"numeric"}
|
71
|
+
],
|
72
|
+
"config" => {
|
73
|
+
"url"=>nil,
|
74
|
+
"http_version"=>"1.1",
|
75
|
+
"header_Host"=>nil,
|
76
|
+
"read_limit"=>"1048576",
|
77
|
+
"method"=>"GET",
|
78
|
+
"code"=>"^200$",
|
79
|
+
"redirects"=>"0"
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
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')
|
92
|
+
if search_bundles.any? # already exists...
|
93
|
+
r = cu.circonus.update_check_bundle(search_bundles.first['_cid'],bundle)
|
94
|
+
else
|
95
|
+
r = cu.circonus.add_check_bundle(bundle)
|
96
|
+
end
|
97
|
+
if not r.nil? then
|
98
|
+
print "Success\n"
|
99
|
+
#pp r
|
100
|
+
end
|
101
|
+
|
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.4.
|
4
|
+
version: 3.4.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -72,6 +72,7 @@ extra_rdoc_files: []
|
|
72
72
|
files:
|
73
73
|
- lib/circonusutil.rb
|
74
74
|
- lib/circonus.rb
|
75
|
+
- bin/circonus-add-http-check
|
75
76
|
- bin/circonus-delete-host
|
76
77
|
- bin/circonus-add-composite
|
77
78
|
- bin/circonus-list-tags
|
@@ -86,7 +87,6 @@ files:
|
|
86
87
|
- examples/util.rb
|
87
88
|
- examples/cache_copy.rb
|
88
89
|
- examples/graph_data.rb
|
89
|
-
- examples/add_http_check.rb
|
90
90
|
- examples/add_apache_node.rb
|
91
91
|
homepage: https://github.com/venturaville/circonus-api
|
92
92
|
licenses:
|
data/examples/add_http_check.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# Add an HTTP site check
|
4
|
-
#
|
5
|
-
|
6
|
-
require 'rubygems'
|
7
|
-
require 'optparse'
|
8
|
-
require 'circonus'
|
9
|
-
require "#{ENV['HOME']}/.circonus.rb"
|
10
|
-
@c = Circonus.new(@apitoken,@appname,@agent)
|
11
|
-
|
12
|
-
options = {}
|
13
|
-
options[:multi] = false
|
14
|
-
OptionParser.new { |opts|
|
15
|
-
opts.banner = "Usage: #{File.basename($0)} [-h] [-m] sitename URL"
|
16
|
-
opts.on( '-h', '--help', "This usage menu") do
|
17
|
-
puts opts
|
18
|
-
print "sitename = The site's hostname\n"
|
19
|
-
print "URL = The actual url to check on the site\n"
|
20
|
-
exit
|
21
|
-
end
|
22
|
-
opts.on( '-m','--multi',"Use multiple circonus brokers" ) do
|
23
|
-
options[:multi] = true
|
24
|
-
end
|
25
|
-
}.parse!
|
26
|
-
|
27
|
-
|
28
|
-
def usage()
|
29
|
-
print <<EOF
|
30
|
-
Usage: add_http_check.rb sitename URL
|
31
|
-
-h,--help This usage menu
|
32
|
-
-m,--multi Use multiple circonus brokers
|
33
|
-
EOF
|
34
|
-
end
|
35
|
-
|
36
|
-
sitename = ARGV[0]
|
37
|
-
url = ARGV[1]
|
38
|
-
|
39
|
-
circonus_brokers = @c.search_broker("circonus",'_type')
|
40
|
-
circonus_brokers = circonus_brokers.select {|a| a['_name'] != 'HTTPTrap'} # filter out http trap broker...
|
41
|
-
agentids = circonus_brokers.map { |m| m['_cid'] }
|
42
|
-
agentids = agentids[0,1] unless options[:multi]
|
43
|
-
|
44
|
-
bundle_stub = {
|
45
|
-
"brokers"=>[ ],
|
46
|
-
"display_name"=>nil,
|
47
|
-
"period"=>60,
|
48
|
-
"target"=>nil,
|
49
|
-
"timeout"=>10,
|
50
|
-
"type"=>"http",
|
51
|
-
"metrics"=> [
|
52
|
-
{"name"=>"body_match", "type"=>"text"},
|
53
|
-
{"name"=>"bytes", "type"=>"numeric"},
|
54
|
-
{"name"=>"code", "type"=>"text"},
|
55
|
-
{"name"=>"duration", "type"=>"numeric"},
|
56
|
-
{"name"=>"truncated", "type"=>"numeric"},
|
57
|
-
{"name"=>"tt_connect", "type"=>"numeric"},
|
58
|
-
{"name"=>"tt_firstbyte", "type"=>"numeric"}
|
59
|
-
],
|
60
|
-
"config" => {
|
61
|
-
"url"=>nil,
|
62
|
-
"http_version"=>"1.1",
|
63
|
-
"header_Host"=>nil,
|
64
|
-
"read_limit"=>"1048576",
|
65
|
-
"method"=>"GET",
|
66
|
-
"code"=>"^200$",
|
67
|
-
"redirects"=>"0"
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
bundle = bundle_stub.clone
|
72
|
-
bundle['brokers'] = agentids
|
73
|
-
bundle['target'] = sitename
|
74
|
-
bundle['display_name'] = "#{sitename} http"
|
75
|
-
bundle['config']['url'] = url
|
76
|
-
bundle['config']['header_Host'] = sitename
|
77
|
-
|
78
|
-
search_bundles = @c.search_check_bundle(bundle['display_name'],'display_name')
|
79
|
-
if search_bundles.any? # already exists...
|
80
|
-
r = @c.update_check_bundle(search_bundles.first['_cid'],bundle)
|
81
|
-
else
|
82
|
-
r = @c.add_check_bundle(bundle)
|
83
|
-
end
|
84
|
-
if not r.nil? then
|
85
|
-
print "Success\n"
|
86
|
-
#pp r
|
87
|
-
end
|
88
|
-
|