circonus 3.4.2 → 3.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/add_nginx_node.rb +25 -40
- metadata +1 -1
data/examples/add_nginx_node.rb
CHANGED
@@ -1,19 +1,30 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Add a single nginx host to circonus
|
3
3
|
|
4
|
-
require '
|
5
|
-
require 'circonus'
|
6
|
-
require 'optparse'
|
7
|
-
require "#{ENV['HOME']}/.circonus.rb"
|
4
|
+
require 'circonusutil'
|
8
5
|
|
9
|
-
|
10
|
-
|
6
|
+
host = nil
|
7
|
+
cu = CirconusUtil.new() { |opts,options|
|
8
|
+
options[:broker] = nil
|
9
|
+
options[:tags] = ['application:nginx']
|
10
|
+
opts.banner = "Usage: #{File.basename($0)} hostname\n"
|
11
|
+
opts.on( '--tags TAGLIST',"Apply comma separated list of tags (default: empty list)" ) { |t| options[:tags] += options[:tags] + t.split(/,/) }
|
12
|
+
opts.on( '--broker BROKER',"Name of the broker to use" ) { |t| options[:broker] = t }
|
13
|
+
}
|
14
|
+
if ARGV.empty? then
|
15
|
+
puts "Missing hostname!"
|
16
|
+
exit -1
|
17
|
+
end
|
18
|
+
host = ARGV.pop
|
19
|
+
|
20
|
+
def do_update_check_bundle(cu,data)
|
21
|
+
search_check_bundle = cu.circonus.list_check_bundle({'display_name' => data['display_name']})
|
11
22
|
existing = false
|
12
23
|
if search_check_bundle.any? # already exists...
|
13
24
|
existing = true
|
14
|
-
r =
|
25
|
+
r = cu.circonus.update_check_bundle(search_check_bundle.first['_cid'],data)
|
15
26
|
else
|
16
|
-
r =
|
27
|
+
r = cu.circonus.add_check_bundle(data)
|
17
28
|
end
|
18
29
|
if not r.nil? then
|
19
30
|
pp r
|
@@ -21,39 +32,13 @@ def do_update_check_bundle(data)
|
|
21
32
|
end
|
22
33
|
end
|
23
34
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
opts.banner = "Usage: #{File.basename($0)} [-h] hostname [-t tag1,tag2,...]\n"
|
29
|
-
opts.on( '-h', '--help', "This usage menu") do
|
30
|
-
puts opts
|
31
|
-
exit
|
32
|
-
end
|
33
|
-
opts.on( '-t','--tags TAGLIST',"Apply comma separated list of tags" ) do |t|
|
34
|
-
options[:tags] += t.split(/,/)
|
35
|
-
end
|
36
|
-
}.parse!
|
37
|
-
|
38
|
-
def usage()
|
39
|
-
print <<EOF
|
40
|
-
Usage: #{File.basename($0)} hostname [-t tag1,tag2,... ]
|
41
|
-
-h,--help This usage menu
|
42
|
-
-t,--tags Comma separated list of tag names to apply (default is an empty list)
|
43
|
-
EOF
|
44
|
-
end
|
45
|
-
|
46
|
-
host = ARGV[0]
|
47
|
-
if host.nil? then
|
48
|
-
usage()
|
35
|
+
agents = cu.circonus.list_broker({'_name'=>cu.options[:broker]})
|
36
|
+
agentid = agents.select { |a| a['_name'] == cu.options[:broker] }.first['_cid']
|
37
|
+
if agentid.nil?
|
38
|
+
puts "Missing agent id!"
|
49
39
|
exit -1
|
50
40
|
end
|
51
41
|
|
52
|
-
@c = Circonus.new(@apitoken,@appname,@agent)
|
53
|
-
|
54
|
-
agents = @c.list_broker
|
55
|
-
agentid = agents.select { |a| a['_name'] == @agent }.first['_cid']
|
56
|
-
|
57
42
|
print "Adding nginx for host #{host}\n"
|
58
43
|
data = {
|
59
44
|
:agent_id => agentid,
|
@@ -63,7 +48,7 @@ data = {
|
|
63
48
|
bundle = {
|
64
49
|
"type" => "nginx",
|
65
50
|
"target" => host,
|
66
|
-
"tags" => options[:tags],
|
51
|
+
"tags" => cu.options[:tags],
|
67
52
|
"timeout" => 10,
|
68
53
|
"period" => 60,
|
69
54
|
"display_name" => "#{host} nginx",
|
@@ -83,5 +68,5 @@ bundle = {
|
|
83
68
|
}
|
84
69
|
end
|
85
70
|
|
86
|
-
do_update_check_bundle(bundle)
|
71
|
+
do_update_check_bundle(cu,bundle)
|
87
72
|
|