op5util 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.md +43 -4
- data/bin/op5util +11 -0
- data/lib/op5util/list_hosts.rb +29 -0
- data/lib/op5util/version.rb +1 -1
- data/lib/op5util.rb +1 -0
- data/op5util.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98b7c7098263b0b79fbcc7dab53a96c1d66d9001
|
4
|
+
data.tar.gz: ed48f74b4482bc6d8a3e3688d7f6a5583526e1bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4e6f2e3588cbbb251e67fe09ddfb4946d4b10715f3d6849d9d45699c7a610bae978e23f7d274c34f82e30afef19a58aa3d26d0f110fdaadaef316084e0da7e5
|
7
|
+
data.tar.gz: 837f71ec446b2151ac5c68ebf5e9ee412257fb97142dde0b0946c9e27f9937740f8b203c0923a4656d936cfa75249f2b2290fdfea3e9ab2e9f2fb809bb852bed
|
data/Readme.md
CHANGED
@@ -5,7 +5,7 @@ and want to be able to do the most common Op5 tasks without logging in
|
|
5
5
|
to a web-gui?
|
6
6
|
|
7
7
|
Or you want to start monitoring the newly installed hosts with Op5
|
8
|
-
using your config management tool?
|
8
|
+
using your ansible/chef/whatever config management tool?
|
9
9
|
|
10
10
|
Those two use-cases were my biggest itches when I first started to use
|
11
11
|
saved curl commands to interact with the REST-api and soon op5util.rb
|
@@ -92,14 +92,14 @@ and the other gems that op5util depends on.
|
|
92
92
|
user@host:~$ sudo gem install op5util
|
93
93
|
```
|
94
94
|
|
95
|
-
Latest version is 0.1.
|
95
|
+
Latest version is 0.1.6, you can verify that op5util is installed correctly with:
|
96
96
|
|
97
97
|
``` shell
|
98
98
|
user@host:~$ gem list --details op5util
|
99
99
|
|
100
100
|
*** LOCAL GEMS ***
|
101
101
|
|
102
|
-
op5util (0.1.
|
102
|
+
op5util (0.1.6)
|
103
103
|
Author: Niklas Paulsson
|
104
104
|
Homepage: https://github.com/np422/Op5util
|
105
105
|
License: MIT License
|
@@ -139,7 +139,7 @@ SYNOPSIS
|
|
139
139
|
op5util [global options] command [command options] [arguments...]
|
140
140
|
|
141
141
|
VERSION
|
142
|
-
0.1.
|
142
|
+
0.1.6
|
143
143
|
|
144
144
|
GLOBAL OPTIONS
|
145
145
|
-f, --authfile=authfile - Authfile containing "username:password" used to authenticate with Op5
|
@@ -163,6 +163,7 @@ COMMANDS
|
|
163
163
|
autocomplete - Show instruction on howto setup tab autocomplete for op5util in your shell
|
164
164
|
downtime - Schedule fixed downtime for a host
|
165
165
|
help - Shows a list of commands or help for one command
|
166
|
+
hosts - List all hosts, or detailed information about a single host
|
166
167
|
hostgroups - List hostgroups, optionally with member and service info, Usage examples:
|
167
168
|
'op5util hostgroups' to list all hostgroups, 'op5util hostgroups -l linux_hosts'
|
168
169
|
to list members and services for the linux_hosts hostgroup
|
@@ -213,6 +214,11 @@ free to leave a bug-reports or feature requests as an issue in this repo.
|
|
213
214
|
|
214
215
|
## Version history
|
215
216
|
|
217
|
+
### 0.1.6
|
218
|
+
|
219
|
+
New command 'hosts' which lists hosts, included example of ansible playbook
|
220
|
+
in documentation.
|
221
|
+
|
216
222
|
### 0.1.5
|
217
223
|
|
218
224
|
Added template for shell autocomplete of op5util command (bash/zsh)
|
@@ -225,3 +231,36 @@ Gemspec filespec corrected to avoid unnecessary large .gem-files.
|
|
225
231
|
|
226
232
|
Environment variable OP5AUTHFILE possible to use instead of --authfile, check permission
|
227
233
|
of authfile and refuse to start if readable by other than owner.
|
234
|
+
|
235
|
+
## Example, use op5util with ansible
|
236
|
+
|
237
|
+
Use the example below as a source of inspiration on how op5util can be used from
|
238
|
+
an ansible playbook.
|
239
|
+
|
240
|
+
In this example the variable 'hostgroups', which should be a list, will be used to
|
241
|
+
assign hostgroups, otherwise the default hostgroup 'linux_hosts' will beassigned.
|
242
|
+
|
243
|
+
``` yaml
|
244
|
+
---
|
245
|
+
- hosts: monitoring-clients
|
246
|
+
gather_facts: false
|
247
|
+
serial: 1
|
248
|
+
vars:
|
249
|
+
op5_user: 'user'
|
250
|
+
op5_password: 'password'
|
251
|
+
op5_server: 'op5server'
|
252
|
+
tasks:
|
253
|
+
|
254
|
+
- name: Check if Op5 registration is needed
|
255
|
+
shell: op5util -u {{ op5_user }} -p {{ op5_password }} -m {{ op5_server }} hosts
|
256
|
+
register: var_op5_hosts
|
257
|
+
delegate_to: localhost
|
258
|
+
|
259
|
+
- set_fact:
|
260
|
+
op5_hosts: "{{ var_op5_hosts.stdout_lines }}"
|
261
|
+
|
262
|
+
- name: Register client with Op5 monitoring server
|
263
|
+
shell: op5util -u {{ op5_user }} -p {{ op5_password }} -m {{ op5_server }} add -g {{ hostgroups | default([ 'linux_hosts' ]) | join(' -g ') }} {{ inventory_hostname }}
|
264
|
+
delegate_to: localhost
|
265
|
+
when: inventory_hostname not in op5_hosts
|
266
|
+
```
|
data/bin/op5util
CHANGED
@@ -156,6 +156,17 @@ command :hostgroups do |c|
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
+
desc 'List all hosts, or detailed information about a single host'
|
160
|
+
arg_name 'host'
|
161
|
+
command :hosts do |c|
|
162
|
+
c.desc 'Show detailed information'
|
163
|
+
c.switch [:l, :long]
|
164
|
+
|
165
|
+
c.action do |_global_options, options, args|
|
166
|
+
monitor.list_hosts(args[0], options)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
159
170
|
desc 'Show instruction on howto setup tab autocomplete for op5util in your shell'
|
160
171
|
command :autocomplete do |c|
|
161
172
|
c.action do
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# rubocop:disable LineLength, AbcSize
|
2
|
+
# Foo
|
3
|
+
module Op5util
|
4
|
+
# Foo
|
5
|
+
class Monitor
|
6
|
+
def list_hosts(host, options)
|
7
|
+
response = self.class.get(@base_uri + 'config/host?format=json',
|
8
|
+
basic_auth: @auth, verify: false)
|
9
|
+
raise ApiError unless response.code == 200
|
10
|
+
JSON.parse!(response.body).map { |h| h['name'] }.select { |h| host.nil? ? true : h == host }.each do |h|
|
11
|
+
puts h
|
12
|
+
print_detailed_host_info(h) if options[:long]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def print_detailed_host_info(host)
|
19
|
+
response = self.class.get(@base_uri + "config/host/#{host}?format=json",
|
20
|
+
basic_auth: @auth, verify: false)
|
21
|
+
raise ApiError unless response.code == 200
|
22
|
+
host_info = JSON.parse!(response.body)
|
23
|
+
puts 'Contact-groups: ' + host_info['contact_groups'].join(',')
|
24
|
+
puts 'Host-groups: ' + host_info['hostgroups'].join(',')
|
25
|
+
puts 'Address: ' + host_info['address']
|
26
|
+
puts 'Alias: ' + host_info['alias']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/op5util/version.rb
CHANGED
data/lib/op5util.rb
CHANGED
data/op5util.gemspec
CHANGED
@@ -6,7 +6,7 @@ spec = Gem::Specification.new do |s|
|
|
6
6
|
s.author = 'Niklas Paulsson'
|
7
7
|
s.email = 'niklasp@gmail.com'
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.licenses = ['MIT
|
9
|
+
s.licenses = ['MIT']
|
10
10
|
s.homepage = 'https://github.com/np422/Op5util'
|
11
11
|
s.summary = 'A utility to do common Op5 administration from the commandline'
|
12
12
|
s.files = %w[bin/op5util lib/op5util.rb LICENSE op5util.gemspec] +
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: op5util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niklas Paulsson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/op5util/autocomplete.rb
|
129
129
|
- lib/op5util/check_auth.rb
|
130
130
|
- lib/op5util/list_hostgroups.rb
|
131
|
+
- lib/op5util/list_hosts.rb
|
131
132
|
- lib/op5util/method_template.rb
|
132
133
|
- lib/op5util/monitor.rb
|
133
134
|
- lib/op5util/schedule_checks.rb
|
@@ -139,7 +140,7 @@ files:
|
|
139
140
|
- op5util.rdoc
|
140
141
|
homepage: https://github.com/np422/Op5util
|
141
142
|
licenses:
|
142
|
-
- MIT
|
143
|
+
- MIT
|
143
144
|
metadata: {}
|
144
145
|
post_install_message:
|
145
146
|
rdoc_options:
|