circonus 3.6.7 → 3.6.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/circonus-add-ssh-check +148 -0
  2. metadata +4 -2
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Add an ssh 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[:timeout] = 10 # seconds
13
+ options[:tags] = ['application:ssh','source:manual']
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] += 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( '--timeout TIMEOUT',"Host timeout" ) { |t| options[:timeout] = t.to_i }
19
+ opts.on( '--contactgroups CONTACTGROUPS',"Comma separated list of contact groups to send alerts to" ) { |t| options[:contactgroups] = t }
20
+ }
21
+ if @cu.options[:brokers].empty?
22
+ puts "Missing brokers list"
23
+ exit -1
24
+ end
25
+ if @cu.options[:hostname].empty?
26
+ puts "Missing hostname"
27
+ exit -1
28
+ end
29
+ if @cu.options[:contactgroups].empty?
30
+ puts "Missing contact group(s)"
31
+ exit -1
32
+ end
33
+ @cu.options[:tags].sort!.uniq!
34
+ @cu.options[:contactgroups] = @cu.options[:contactgroups].split(',').sort.uniq
35
+ @cu.options[:brokers].sort!.uniq!
36
+
37
+ def do_update_check_bundle(cu,data)
38
+ search_check_bundle = @cu.circonus.list_check_bundle({'display_name' => data['display_name']})
39
+ existing = false
40
+ if search_check_bundle.any? # already exists...
41
+ existing = true
42
+ r = @cu.circonus.update_check_bundle(search_check_bundle.first['_cid'],data)
43
+ else
44
+ r = @cu.circonus.add_check_bundle(data)
45
+ end
46
+ if not r.nil? then
47
+ pp r
48
+ print "Success (#{existing ? 'updating' : 'adding'} #{data['display_name']})\n"
49
+ end
50
+ end
51
+
52
+ brokers = {}
53
+ @cu.options[:brokers].each do |broker|
54
+ circonus_brokers = @cu.circonus.list_broker({'_name'=>broker})
55
+ brokers[broker] = circonus_brokers.map { |m| m['_cid'] }.first
56
+ end
57
+
58
+ bundle_stub = {
59
+ "brokers"=>[ ],
60
+ "display_name"=>nil,
61
+ "period"=>120,
62
+ "target"=>nil,
63
+ "timeout"=>15,
64
+ "type"=>"ssh2",
65
+ 'notes' => 'This check is to see if SSH is responding on a node',
66
+ "tags"=>[],
67
+ "metrics"=> [
68
+ {"name"=>"duration", "type"=>"numeric"}
69
+ ],
70
+ "config" => {
71
+ "method_crypt_cs"=>"aes128-ctr",
72
+ "method_comp_sc"=>"none",
73
+ "method_comp_cs"=>"none",
74
+ "method_hostkey"=>"ssh-dss",
75
+ 'port' => 22,
76
+ "method_crypt_sc"=>"aes128-ctr"
77
+ }
78
+ }
79
+
80
+ bundle = bundle_stub.clone
81
+ bundle['brokers'] = brokers.values.sort
82
+ bundle['target'] = @cu.options[:hostname]
83
+ bundle['tags'] = @cu.options[:tags]
84
+ bundle['display_name'] = ([@cu.options[:hostname],'ssh'] + ['ssh']).join(' ')
85
+ search_bundles = @cu.circonus.search_check_bundle(bundle['display_name'],'display_name')
86
+ if search_bundles.any? # already exists...
87
+ r = @cu.circonus.update_check_bundle(search_bundles.first['_cid'],bundle)
88
+ else
89
+ r = @cu.circonus.add_check_bundle(bundle)
90
+ end
91
+ if not r.nil? then
92
+ print "Success\n"
93
+ #pp r
94
+ end
95
+ checkids = r["_checks"]
96
+
97
+ def mib_add_rule_set!(metric_name,rule_set={})
98
+ contactgroupids = []
99
+ @cu.options[:contactgroups].each do |cgname|
100
+ r = @cu.circonus.list_contact_group({'name'=>cgname})
101
+ contactgroupids += r.map { |m| m['_cid'] }
102
+ end
103
+ init_rule_set = {
104
+ 'metric_name' => metric_name,
105
+ 'metric_type' => 'numeric',
106
+ 'contact_groups' => {
107
+ '1'=>contactgroupids,
108
+ '2'=>contactgroupids,
109
+ '3'=>contactgroupids,
110
+ '4'=>contactgroupids,
111
+ '5'=>contactgroupids
112
+ },
113
+ 'rules'=>[],
114
+ 'derive'=>nil # can be either counter or nil (nil means you want a gauge)
115
+ }
116
+ new_rule_set = init_rule_set.merge(rule_set)
117
+ new_rule_set
118
+ end
119
+
120
+ # Add a rule to the given rule_set
121
+ def mib_add_rule!(rule_set,rule={})
122
+ init_rule = {
123
+ 'criteria'=>'max value',
124
+ 'severity'=>5,
125
+ 'value'=>3000,
126
+ 'wait'=>5
127
+ }
128
+ new_rule = init_rule.merge(rule)
129
+ rule_set['rules'] << new_rule
130
+ new_rule
131
+ end
132
+
133
+ puts "Adding rule sets"
134
+ ######## ssh absence alert #########
135
+ checkids.each do |cid|
136
+ rcid = cid.split('/').last.to_i
137
+
138
+ rs = mib_add_rule_set!('duration',{'link'=>'http://docs.turner.com/display/SRE/Circonus+TCP+Check+ERP','notes'=>'This alert is a test to see if a node is actually online using the responsiveness of the ssh port. If this is alerting it means the node in the alert is likely offline'})
139
+ mib_add_rule!(rs,{"criteria"=>"on absence", "severity"=>1, "value"=>300})
140
+
141
+ r = @cu.circonus.add_rule_set(rs)
142
+ if not r.nil? then
143
+ print "Success\n"
144
+ else
145
+ print "Failure\n"
146
+ end
147
+ end
148
+
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.6.7
4
+ version: 3.6.8
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-11-17 00:00:00.000000000 Z
12
+ date: 2014-12-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -70,6 +70,7 @@ executables:
70
70
  - circonus-list-tags
71
71
  - circonus-list-brokers
72
72
  - circonus-list-contactgroups
73
+ - circonus-add-ssh-check
73
74
  extensions: []
74
75
  extra_rdoc_files: []
75
76
  files:
@@ -83,6 +84,7 @@ files:
83
84
  - bin/circonus-list-tags
84
85
  - bin/circonus-list-checkbundle
85
86
  - bin/circonus-cli
87
+ - bin/circonus-add-ssh-check
86
88
  - examples/add_dns_monitor.rb
87
89
  - examples/add_snmp_node.rb
88
90
  - examples/update_nginx_graph.rb