noms-client 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/TODO +4 -0
- data/bin/noms +155 -6
- data/lib/noms/client/version.rb +1 -1
- data/lib/noms/cmdb.rb +1 -0
- data/lib/noms/nagui.rb +89 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e24aa514edf837a8d6d263ffe707e86aefcc76f
|
4
|
+
data.tar.gz: 09e54474d3b41a4a257fa1cf98a248ad16b66cd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6707f63d16653725c7d9e00be5421e282db4a7195a932bd793643021f70ef8da14a04d698bcd940c1fc41ffa3d11613ec24180bb54b59e357ccb9970fb7bc1e
|
7
|
+
data.tar.gz: 35bf1ffa2984e3f338927060d46f1021b8c2b21b09d8656f70cd965468c920800aaf4752995cc3435f9cc7679767781d3f224a1cd32aac131946042e3c0f523f
|
data/TODO
CHANGED
@@ -6,3 +6,7 @@
|
|
6
6
|
* Complex requests for NCC API
|
7
7
|
* Factor almost all of CLI into interface library (in particular,
|
8
8
|
waitfor)
|
9
|
+
|
10
|
+
* need a way for the docs/help/usage to be additive from library.
|
11
|
+
i.e. library has new functions, docs/help/usage for how to use
|
12
|
+
them, should be displayed in noms --help
|
data/bin/noms
CHANGED
@@ -59,6 +59,12 @@
|
|
59
59
|
# cloud name - Describe named cloud
|
60
60
|
# ncc - Describe NCC API endpoint
|
61
61
|
# cmdb - Describe system fields
|
62
|
+
# nagios subcommand
|
63
|
+
# show type name - Show information for named type [hostgroup,host,service]
|
64
|
+
# detail host - Show object detail for named host
|
65
|
+
# query type [condition [...]] - Query for object by type [hostgroup,host,service]
|
66
|
+
# check <host> [<service>] - Run service check for host (or host check) synchronously
|
67
|
+
#
|
62
68
|
# Options:
|
63
69
|
# --names - Just print entity names, equivalent to
|
64
70
|
# --fields name --noheader --nofeedback --nolabel
|
@@ -180,6 +186,7 @@ require 'csv'
|
|
180
186
|
require 'noms/client/version'
|
181
187
|
require 'ncc/client'
|
182
188
|
require 'noms/cmdb'
|
189
|
+
require 'noms/nagui'
|
183
190
|
|
184
191
|
$VERSION = NOMS::Client::VERSION
|
185
192
|
$me = 'noms'
|
@@ -189,6 +196,8 @@ $opt = Optconfig.new('noms', {
|
|
189
196
|
'url' => 'http://noms/ncc_api/v2' },
|
190
197
|
'cmdb=s%' => {
|
191
198
|
'url' => 'http://cmdb/cmdb_api/v1' },
|
199
|
+
'nagui=s%' => {
|
200
|
+
'url' => 'http://nagios/nagui/nagios_live.cgi' },
|
192
201
|
'fields=s' => '',
|
193
202
|
'mock=s' => nil,
|
194
203
|
'format=s' => 'text',
|
@@ -201,6 +210,50 @@ $opt = Optconfig.new('noms', {
|
|
201
210
|
'default-environment' => 'production',
|
202
211
|
'default-cloud' => 'ec2',
|
203
212
|
'format-field=s%' => {
|
213
|
+
'hostgroup' => {
|
214
|
+
'fields' => [
|
215
|
+
'name','num_hosts', 'num_services'
|
216
|
+
],
|
217
|
+
'length' => {
|
218
|
+
'name' => 20,
|
219
|
+
'members' => 36,
|
220
|
+
'num_hosts' => 5,
|
221
|
+
'num_services' => 5
|
222
|
+
}
|
223
|
+
},
|
224
|
+
'host' => {
|
225
|
+
'fields' => [
|
226
|
+
'name','state', 'plugin_output'
|
227
|
+
],
|
228
|
+
'length' => {
|
229
|
+
'name' => 36,
|
230
|
+
'state' => 5,
|
231
|
+
'plugin_output' => 36
|
232
|
+
}
|
233
|
+
},
|
234
|
+
'nagcheck' => {
|
235
|
+
'fields' => [
|
236
|
+
'host_name','address','service_description','state', 'plugin_output'
|
237
|
+
],
|
238
|
+
'length' => {
|
239
|
+
'host_name' => 36,
|
240
|
+
'address' => 16,
|
241
|
+
'service_description' => 20,
|
242
|
+
'state' => 5,
|
243
|
+
'plugin_output' => 36
|
244
|
+
}
|
245
|
+
},
|
246
|
+
'service' => {
|
247
|
+
'fields' => [
|
248
|
+
'host_name','description','state', 'plugin_output'
|
249
|
+
],
|
250
|
+
'length' => {
|
251
|
+
'host_name' => 36,
|
252
|
+
'description' => 20,
|
253
|
+
'state' => 5,
|
254
|
+
'plugin_output' => 36
|
255
|
+
}
|
256
|
+
},
|
204
257
|
'svcinst' => {
|
205
258
|
'fields' => [
|
206
259
|
'name', 'type', 'note'
|
@@ -255,6 +308,7 @@ $opt = Optconfig.new('noms', {
|
|
255
308
|
if $opt['mock']
|
256
309
|
NCC::Client.mock! $opt['mock']
|
257
310
|
NOMS::CMDB.mock! $opt['mock']
|
311
|
+
NOMS::Nagui.mock! $opt['mock']
|
258
312
|
end
|
259
313
|
|
260
314
|
case $opt['format']
|
@@ -278,6 +332,7 @@ $opt['ncc']['timeout'] ||= $opt['timeout']
|
|
278
332
|
|
279
333
|
$cmdb = NOMS::CMDB.new($opt)
|
280
334
|
$ncc = NCC::Client.new($opt)
|
335
|
+
$nagui = NOMS::Nagui.new($opt)
|
281
336
|
|
282
337
|
def parse_format(fields, type)
|
283
338
|
dbg "Specified fields: #{fields.inspect}"
|
@@ -359,7 +414,7 @@ end
|
|
359
414
|
|
360
415
|
def record_formatted_output(object, type='instance', fields=nil)
|
361
416
|
fields = fmt_fields(type, fields)
|
362
|
-
all_fields = object.keys
|
417
|
+
all_fields = object.keys.sort
|
363
418
|
fields = fields & all_fields
|
364
419
|
fieldlist = parse_format($opt['fields'], type) || fields + (all_fields - fields)
|
365
420
|
case $opt['format']
|
@@ -464,19 +519,111 @@ def cmdb_show(args)
|
|
464
519
|
fqdn = args.shift
|
465
520
|
system = $cmdb.query('system', 'fqdn=' + fqdn).first
|
466
521
|
record = if ! args.empty?
|
467
|
-
|
522
|
+
system.keys.inject({}) do |h, k|
|
468
523
|
if args.include? k
|
469
524
|
h.merge({k => system[k]})
|
470
525
|
else
|
471
526
|
h
|
472
527
|
end
|
473
528
|
end
|
474
|
-
|
475
|
-
|
476
|
-
|
529
|
+
else
|
530
|
+
system
|
531
|
+
end
|
477
532
|
record
|
478
533
|
end
|
479
534
|
|
535
|
+
def nagcheck(args)
|
536
|
+
host = args.shift
|
537
|
+
if args.empty?
|
538
|
+
$nagui.nagcheck_host(host)
|
539
|
+
else
|
540
|
+
service=args.shift
|
541
|
+
$nagui.nagcheck_service(host,service)
|
542
|
+
end
|
543
|
+
end
|
544
|
+
|
545
|
+
def nagios(args)
|
546
|
+
cmd = args.shift
|
547
|
+
case cmd
|
548
|
+
when 'query'
|
549
|
+
type = args.shift
|
550
|
+
if $opt['names']
|
551
|
+
if type == 'service'
|
552
|
+
$opt['fields'] = ['host_name','description']
|
553
|
+
else
|
554
|
+
$opt['fields'] = [$nagui.default_query_key(type)] if $opt['names']
|
555
|
+
end
|
556
|
+
end
|
557
|
+
output = $nagui.query(type,args)
|
558
|
+
if type == 'hostgroup'
|
559
|
+
output.each do |item|
|
560
|
+
item.delete('members')
|
561
|
+
end
|
562
|
+
end
|
563
|
+
formatted_output(output, type)
|
564
|
+
when 'detail'
|
565
|
+
host = args.shift
|
566
|
+
record_formatted_output($nagui.host(host), 'host')
|
567
|
+
when 'show'
|
568
|
+
type = args.shift
|
569
|
+
key = args.shift
|
570
|
+
$opt['feedback'] = false
|
571
|
+
case type
|
572
|
+
when 'host'
|
573
|
+
output = $nagui.host(key)
|
574
|
+
dbg("show host: #{output.inspect}")
|
575
|
+
if output != nil
|
576
|
+
data = [{
|
577
|
+
'host_name' => output['name'],
|
578
|
+
'description' => '',
|
579
|
+
'state' => output['state'],
|
580
|
+
'plugin_output' => output['plugin_output']
|
581
|
+
}]
|
582
|
+
output['services_with_info'].each do |svc|
|
583
|
+
data << {
|
584
|
+
'host_name' => '',
|
585
|
+
'description' => svc[0],
|
586
|
+
'state' => svc[1],
|
587
|
+
'plugin_output' => svc[3]
|
588
|
+
}
|
589
|
+
end
|
590
|
+
formatted_output(data,'service')
|
591
|
+
end
|
592
|
+
when 'hostgroup'
|
593
|
+
output = $nagui.hostgroup(key)
|
594
|
+
dbg("show hostgroup: #{output.inspect}")
|
595
|
+
if output != nil
|
596
|
+
data = [{
|
597
|
+
'name' => output['name'],
|
598
|
+
'members' => "#{output['num_hosts']} hosts #{output['num_services']} services",
|
599
|
+
'num_hosts' => output['num_hosts'],
|
600
|
+
'num_services' => output['num_services']
|
601
|
+
}]
|
602
|
+
output['members_with_state'].each do |host|
|
603
|
+
data << {
|
604
|
+
'members' => host[0],
|
605
|
+
'state' => host[1]
|
606
|
+
}
|
607
|
+
end
|
608
|
+
formatted_output(data,type,['name','members','state'])
|
609
|
+
end
|
610
|
+
|
611
|
+
when 'service'
|
612
|
+
service = args.shift
|
613
|
+
output = $nagui.service(key,service)
|
614
|
+
dbg("show service: #{output.inspect}")
|
615
|
+
record_formatted_output(output,type)
|
616
|
+
else
|
617
|
+
data = nil
|
618
|
+
end
|
619
|
+
when 'check'
|
620
|
+
record_formatted_output(nagcheck(args),'nagcheck')
|
621
|
+
else
|
622
|
+
$stderr.puts "Unknown nagios command '#{cmd}'"
|
623
|
+
Process.exit(2)
|
624
|
+
end
|
625
|
+
end
|
626
|
+
|
480
627
|
def cmdb(args)
|
481
628
|
$opt['fields'] = ['fqdn'] if $opt['names']
|
482
629
|
cmd = args.shift
|
@@ -686,10 +833,12 @@ def dispatch_command(argv)
|
|
686
833
|
outs svcinst argv
|
687
834
|
when 'environment', 'env'
|
688
835
|
outs env argv
|
689
|
-
when 'instance'
|
836
|
+
when 'instance', 'inst'
|
690
837
|
outs instance argv
|
691
838
|
when 'waitfor'
|
692
839
|
waitfor argv
|
840
|
+
when 'nagios', 'nag'
|
841
|
+
outs nagios argv
|
693
842
|
when nil
|
694
843
|
$stderr.puts "Usage:\n noms --help\n noms {desc|cmdb|instance|waitfor|...} [arg]"
|
695
844
|
Process.exit(1)
|
data/lib/noms/client/version.rb
CHANGED
data/lib/noms/cmdb.rb
CHANGED
@@ -100,6 +100,7 @@ class NOMS::CMDB < NOMS::HttpClient
|
|
100
100
|
end
|
101
101
|
|
102
102
|
# CMDB API bug means use this endpoint to create
|
103
|
+
# TODO needs update as this bug is no longer present
|
103
104
|
def create_service(env, service, attrs)
|
104
105
|
attrs[:name] = service
|
105
106
|
attrs[:environment_name] = env
|
data/lib/noms/nagui.rb
CHANGED
@@ -23,28 +23,110 @@ class NOMS
|
|
23
23
|
end
|
24
24
|
|
25
25
|
class NOMS::Nagui < NOMS::HttpClient
|
26
|
+
|
27
|
+
@@validtypes =['hosts','services','hostgroups','servicegroups','contacts','commands',
|
28
|
+
'downtimes','timeperiods','status','contactgroups']
|
29
|
+
|
26
30
|
def dbg(msg)
|
27
31
|
if @opt.has_key? 'debug' and @opt['debug'] > 2
|
28
32
|
puts "DBG(#{self.class}): #{msg}"
|
29
33
|
end
|
30
34
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
|
36
|
+
# def initialize(opt)
|
37
|
+
# @opt = opt
|
38
|
+
# self.dbg "Initialized with options: #{opt.inspect}"
|
39
|
+
# end
|
35
40
|
|
36
41
|
def config_key
|
37
42
|
'nagui'
|
38
43
|
end
|
39
44
|
|
40
|
-
def
|
41
|
-
|
45
|
+
def make_plural(str)
|
46
|
+
"#{str}s"
|
47
|
+
end
|
48
|
+
|
49
|
+
def default_query_key(type)
|
50
|
+
case type
|
51
|
+
when 'host'
|
52
|
+
'name'
|
53
|
+
when 'service'
|
54
|
+
'description'
|
55
|
+
when 'hostgroup'
|
56
|
+
'name'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def make_lql(type,queries)
|
61
|
+
if !queries.kind_of?(Array)
|
62
|
+
queries=[queries]
|
63
|
+
end
|
64
|
+
lql='GET '
|
65
|
+
lql << make_plural(type)
|
66
|
+
queries.each do |q|
|
67
|
+
query = /(\w+)([!~>=<]+)(.*)/.match(q)
|
68
|
+
if query == nil
|
69
|
+
lql << "|Filter: #{default_query_key(type)} ~~ #{q}"
|
70
|
+
else
|
71
|
+
lql << "|Filter: #{query[1]} #{query[2]} #{query[3]}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
lql
|
75
|
+
end
|
76
|
+
|
77
|
+
def query(type,queries)
|
78
|
+
unless @@validtypes.include? make_plural(type)
|
79
|
+
puts "#{type} is not a valid type"
|
80
|
+
Process.exit(1)
|
81
|
+
end
|
82
|
+
query_string = make_lql(type,queries)
|
83
|
+
results = do_request(:GET => '/nagui/nagios_live.cgi', :query => URI.encode("query=#{query_string}"))
|
84
|
+
end
|
85
|
+
def hostgroup(name)
|
86
|
+
results = do_request(:GET => '/nagui/nagios_live.cgi', :query => URI.encode("query=GET hostgroups|Filter: name = #{name}"))
|
87
|
+
if results.kind_of?(Array) && results.length > 0
|
88
|
+
results[0]
|
89
|
+
else
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
def service(host,description)
|
94
|
+
results = do_request(:GET => '/nagui/nagios_live.cgi', :query => URI.encode("query=GET services|Filter: host_name = #{host}|Filter: description = #{description}"))
|
95
|
+
if results.kind_of?(Array) && results.length > 0
|
96
|
+
results[0]
|
97
|
+
else
|
98
|
+
nil
|
99
|
+
end
|
100
|
+
end
|
101
|
+
def servicegroup(name)
|
102
|
+
results = do_request(:GET => '/nagui/nagios_live.cgi', :query => URI.encode("query=GET hosts|Filter: name = #{name}"))
|
103
|
+
if results.kind_of?(Array) && results.length > 0
|
104
|
+
results[0]
|
105
|
+
else
|
106
|
+
nil
|
107
|
+
end
|
108
|
+
end
|
109
|
+
def host(hostname)
|
110
|
+
results = do_request(:GET => '/nagui/nagios_live.cgi', :query => URI.encode("query=GET hosts|Filter: name = #{hostname}"))
|
42
111
|
if results.kind_of?(Array) && results.length > 0
|
43
112
|
results[0]
|
44
113
|
else
|
45
114
|
nil
|
46
115
|
end
|
47
116
|
end
|
117
|
+
|
118
|
+
def nagcheck_host(host)
|
119
|
+
url = "/nagcheck/host/#{host}"
|
120
|
+
dbg("nagcheck url= #{url}")
|
121
|
+
nagcheck=do_request(:GET => url, :query => "report=true")
|
122
|
+
end
|
123
|
+
|
124
|
+
def nagcheck_service(host,service)
|
125
|
+
url = "/nagcheck/service/#{host}/#{service}"
|
126
|
+
dbg("nagcheck url= #{url}")
|
127
|
+
nagcheck=do_request(:GET => url, :query => "report=true")
|
128
|
+
end
|
129
|
+
|
48
130
|
def check_host_online(host)
|
49
131
|
@opt['host_up_command'] = 'check-host-alive' unless @opt.has_key?('host_up_command')
|
50
132
|
nagcheck=do_request(:GET => "/nagcheck/command/#{host}/#{@opt['host_up_command']}")
|
@@ -54,4 +136,5 @@ class NOMS::Nagui < NOMS::HttpClient
|
|
54
136
|
false
|
55
137
|
end
|
56
138
|
end
|
139
|
+
|
57
140
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noms-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Brinkley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|