op5util 0.1.6 → 0.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98b7c7098263b0b79fbcc7dab53a96c1d66d9001
4
- data.tar.gz: ed48f74b4482bc6d8a3e3688d7f6a5583526e1bd
3
+ metadata.gz: 5bab4098ca55a344b20d807011731cce8c646170
4
+ data.tar.gz: 759ed9612ee285dc48648ebd54dc3bbea4dc78ec
5
5
  SHA512:
6
- metadata.gz: a4e6f2e3588cbbb251e67fe09ddfb4946d4b10715f3d6849d9d45699c7a610bae978e23f7d274c34f82e30afef19a58aa3d26d0f110fdaadaef316084e0da7e5
7
- data.tar.gz: 837f71ec446b2151ac5c68ebf5e9ee412257fb97142dde0b0946c9e27f9937740f8b203c0923a4656d936cfa75249f2b2290fdfea3e9ab2e9f2fb809bb852bed
6
+ metadata.gz: 6da7903090af03d5d2011c0014a9171f1acceb56a5f27a7304807b0f6005a1a4382e274d91fdacabb639c8849a8201a82841b06a912b2038f0a4df13c7861816
7
+ data.tar.gz: 9a0e569b092a711731955ad31b2b853f61882b90eaa6e7fa744d72b64db787403ccd21b56b879e0300d559314ae69c59c505ed27cbfb74d506afa69de24bdb8f
data/Readme.md CHANGED
@@ -1,4 +1,25 @@
1
- ## Op5util
1
+ # Op5util
2
+
3
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
4
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
5
+ **Table of Contents**
6
+
7
+ - [Introduction](#introduction)
8
+ - [Capabilities](#capabilities)
9
+ - [Screenshots, example usage](#screenshots-example-usage)
10
+ - [Add a host to op5, check host status](#add-a-host-to-op5-check-host-status)
11
+ - [Another use case](#another-use-case)
12
+ - [Installation](#installation)
13
+ - [Usage](#usage)
14
+ - [Commands, help text example](#commands-help-text-example)
15
+ - [Roadmap, TODO](#roadmap-todo)
16
+ - [Contact, bug-reports etc](#contact-bug-reports-etc)
17
+ - [Version history](#version-history)
18
+ - [How op5util may be used with ansible](#how-op5util-may-be-used-with-ansible)
19
+
20
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
21
+
22
+ ## Introduction
2
23
 
3
24
  Are you using Op5? Perhaps you do most of your work from the command-line
4
25
  and want to be able to do the most common Op5 tasks without logging in
@@ -11,8 +32,8 @@ Those two use-cases were my biggest itches when I first started to use
11
32
  saved curl commands to interact with the REST-api and soon op5util.rb
12
33
  was born.
13
34
 
14
- The design nowdays is reasonable modular so new functions can be easily
15
- added if they are needed, pull requests are happily accepted.
35
+ The design nowdays is reasonably modular so new functions can be easily
36
+ added as needed, pull requests are happily accepted.
16
37
 
17
38
  I use op5util daily in a production environment, but it comes with no
18
39
  warranties.
@@ -24,13 +45,13 @@ Currently op5util have implemented these functions:
24
45
  * Add a new host to be monitored by Op5
25
46
  * Add a existing host to more hostgroups
26
47
  * Schedule downtime for a host
48
+ * Acknowledge alarms for host/service
27
49
  * Show status summary of all services/host and summary of service per host
28
50
  * Show status summary of services for a host and list all services w. status for a host
29
51
  * Schedule forced checks of a host and the hosts services to be done now
30
52
  * List all hostgroups available, including members and service checks
31
-
32
- These are the most common vanilla administrative tasks I perform to keep
33
- the networked monitored.
53
+ * List all hosts, with optioinal detailed info
54
+ * Autocomplete template for bash/zsh is included
34
55
 
35
56
  ## Screenshots, example usage
36
57
 
@@ -42,9 +63,9 @@ Adding a host using ```op5util add -g linux_hosts wiki``` and at the same time a
42
63
  membership in the linux_hosts hostgroup for the host, so some standard service checks are
43
64
  defined.
44
65
 
45
- To avoid waiting for checks to be performed on the new host, we tell Op5 to check them
46
- now with the command ```op5util schedule wiki```, and after only a short wait we can
47
- take a look at the detailed host status with ```op5util status -l wiki```.
66
+ To avoid waiting for checks to be performed on the new host, we tell Op5 to check the new
67
+ host and it's services right away with the command ```op5util schedule wiki```, and after
68
+ only a short wait we can take a look at the detailed host status with ```op5util status -l wiki```.
48
69
 
49
70
  ![Usage example](https://raw.githubusercontent.com/np422/Op5util/master/screenshots/usecase2.png)
50
71
 
@@ -62,37 +83,37 @@ with the terminal output by op5util.
62
83
 
63
84
  Op5util is installed using ```gem install op5util```
64
85
 
65
- The export of the environment variable MONITOR is to avoid using the command-line
66
- flag ```-m monitor.ipa.hemma``` on every command, and by saving credentials in the in the .op5pass
67
- file you don't need type the -u/-p thereafter.
86
+ The export of the environment variable MONITOR and saving credentials in the in the .op5pass
87
+ file is to avoid using the command-line flags ```-m monitor.ipa.hemma -u user -p password```
88
+ on every command.
68
89
 
69
- Check the overall status with the command ```op5util status```, as one host is down we request more
70
- info to be displayed with ```op5util status -l```, and we see that the host gitlab01 is down, to
90
+ First check the overall status with the command ```op5util status```, as one host is down we request
91
+ more info to be displayed with ```op5util status -l```, and we see that the host gitlab01 is down, to
71
92
  acknowledge the alarms, ```op5util acknowledge gitlab01```.
72
93
 
73
- Once the problem is resolved and the host is up, ```op5util schedule gitlab01, because impatience,
74
- a final check with ```op5util status gitlab01```.
94
+ Once the problem is resolved and the host is up, ```op5util schedule gitlab01```, because impatience,
95
+ and a final check with ```op5util status gitlab01```.
75
96
 
76
97
  ![screenshot](https://raw.githubusercontent.com/np422/Op5util/master/screenshots/usecase1.png)
77
98
 
78
99
  ## Installation
79
100
 
80
- Install instructions intended for and tested on a fresh install of ubuntu 16.04.
101
+ Install instructions are intended for and tested on a fresh install of ubuntu 16.04.
81
102
 
82
103
  Op5util is distributed as a ruby gem, so first ruby must be installed.
83
104
 
84
- ``` shell
105
+ ```shell
85
106
  user@host:~$ sudo apt-get install -y ruby
86
107
  ```
87
108
 
88
- Use the command gem install, sudo is needed. This will automatically install op5util
89
- and the other gems that op5util depends on.
109
+ Use the command gem install to install op5util, sudo is needed. This will automatically
110
+ install op5util and the other gems that op5util depends on.
90
111
 
91
112
  ```shell
92
113
  user@host:~$ sudo gem install op5util
93
114
  ```
94
115
 
95
- Latest version is 0.1.6, you can verify that op5util is installed correctly with:
116
+ The latest version is 0.1.7, you can verify that op5util is installed correctly using:
96
117
 
97
118
  ``` shell
98
119
  user@host:~$ gem list --details op5util
@@ -108,7 +129,7 @@ op5util (0.1.6)
108
129
  A utility to do common Op5 administration from the commandline
109
130
  ```
110
131
 
111
- Rubygem homepage for op5util is available at: https://rubygems.org/gems/op5util
132
+ The rubygem homepage for op5util is available at: https://rubygems.org/gems/op5util
112
133
 
113
134
  ## Usage
114
135
 
@@ -116,9 +137,8 @@ There is no man-page, but the built in help text should do the job.
116
137
 
117
138
  If you enter the command ```op5util help``` the top-level documentation is displayed.
118
139
 
119
- IMHO git has very good command line interface and I've tried to make op5util to do user
120
- interaction in the same spirit as git.
121
-
140
+ Help for a op5util command is diplayed with ```op5util help <command>```, examples are
141
+ present below.
122
142
 
123
143
  ``` text
124
144
  NAME
@@ -139,7 +159,7 @@ SYNOPSIS
139
159
  op5util [global options] command [command options] [arguments...]
140
160
 
141
161
  VERSION
142
- 0.1.6
162
+ 0.1.7
143
163
 
144
164
  GLOBAL OPTIONS
145
165
  -f, --authfile=authfile - Authfile containing "username:password" used to authenticate with Op5
@@ -161,6 +181,7 @@ COMMANDS
161
181
  add - Add a new host to be monitored by the Op5 server
162
182
  add_hostgroups - Add host to a new hostgroup(s)
163
183
  autocomplete - Show instruction on howto setup tab autocomplete for op5util in your shell
184
+ commit - Commit any pending changes
164
185
  downtime - Schedule fixed downtime for a host
165
186
  help - Shows a list of commands or help for one command
166
187
  hosts - List all hosts, or detailed information about a single host
@@ -171,11 +192,10 @@ COMMANDS
171
192
  status - Show monitoring status, if no host is given all hosts/services are included
172
193
  ```
173
194
 
174
- ### Command usage
175
-
176
- To get information about a specific command, use ```op5util help add``` , example below.
195
+ ### Commands, help text example
177
196
 
178
- ``` textNAME
197
+ ``` text
198
+ NAME
179
199
  add - Add a new host to be monitored by the Op5 server
180
200
 
181
201
  SYNOPSIS
@@ -202,18 +222,25 @@ COMMAND OPTIONS
202
222
 
203
223
  ## Roadmap, TODO
204
224
 
205
- A lot remains, the code really should be DRY'ied up, more automated pre-release tests, more
206
- documentation and perhaps even adding some more functions, but the current version of op5util
207
- is already useful to me in my day-time job, perhaps it also could be useful to other Op5
208
- administrators?
225
+ A lot remains, the code really should be refactored and DRY'ied up, the commands probably need
226
+ some re-thinking, more automated pre-release tests, more documentation and perhaps even
227
+ adding some more functions, but the current version of op5util is already useful to me
228
+ in my day-time job, perhaps it also could be useful to other Op5 administrators?
209
229
 
210
- Please, give my repo a github star or drop me line if you find this utility useful. Feel
211
- free to leave a bug-reports or feature requests as an issue in this repo.
230
+ ## Contact, bug-reports etc
212
231
 
213
- /Niklas
232
+ Please, give my repo a github star or drop me line if you find this utility useful. You can
233
+ contact me at niklasp@<insert googles mail-service here>.com
234
+
235
+ And please feel free to leave bug-reports or feature requests as issues in this repo.
214
236
 
215
237
  ## Version history
216
238
 
239
+ ### 0.1.7
240
+
241
+ New command 'commit' that commits any pending/unsaved changes done previously, combined with
242
+ the option --no-commit on the add_host and add_hostgroup commands.
243
+
217
244
  ### 0.1.6
218
245
 
219
246
  New command 'hosts' which lists hosts, included example of ansible playbook
@@ -232,13 +259,13 @@ Gemspec filespec corrected to avoid unnecessary large .gem-files.
232
259
  Environment variable OP5AUTHFILE possible to use instead of --authfile, check permission
233
260
  of authfile and refuse to start if readable by other than owner.
234
261
 
235
- ## Example, use op5util with ansible
262
+ ## How op5util may be used with ansible
236
263
 
237
264
  Use the example below as a source of inspiration on how op5util can be used from
238
265
  an ansible playbook.
239
266
 
240
267
  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.
268
+ assign hostgroups, otherwise the default hostgroup 'linux_hosts' will be assigned.
242
269
 
243
270
  ``` yaml
244
271
  ---
data/bin/op5util CHANGED
@@ -54,6 +54,9 @@ command :add do |c|
54
54
  c.desc 'IP-address of host, resolved with DNS from hostname if not supplied'
55
55
  c.flag [:i, :ipaddr]
56
56
 
57
+ c.desc 'Don\'t commit changes upon exit'
58
+ c.switch [:n, 'no-commit'.to_sym]
59
+
57
60
  c.action do |_global_options, options, args|
58
61
  # Your command logic here
59
62
  # If you have any errors, just raise them
@@ -69,8 +72,11 @@ command :add_hostgroups do |c|
69
72
  c.desc 'Hostgroup(s) that host should be a member of'
70
73
  c.flag [:g, :hostgroups], :multiple => true
71
74
 
75
+ c.desc 'Don\'t commit changes upon exit'
76
+ c.switch [:n, 'no-commit'.to_sym]
77
+
72
78
  c.action do |_global_options, options, args|
73
- monitor.add_hostgroups(args[0], options[:hostgroups])
79
+ monitor.add_hostgroups(args[0], options[:hostgroups], options['no-commit'.to_sym])
74
80
  end
75
81
  end
76
82
 
@@ -100,7 +106,7 @@ command :status do |c|
100
106
  c.desc 'Print only a brief status information with stats summarized'
101
107
  c.switch [:s, :short]
102
108
 
103
- c.desc 'Print a summary with hosts listed and service information per hsot'
109
+ c.desc 'Print a summary with hosts listed and service information per host'
104
110
  c.switch [:l, :long]
105
111
 
106
112
  c.action do |_global_options, options, args|
@@ -121,7 +127,6 @@ command :acknowledge do |c|
121
127
 
122
128
  c.desc 'Make comment persistent after problems are resolved'
123
129
  c.switch [:p, :persistent]
124
-
125
130
  c.desc 'Print more verbose output'
126
131
  c.switch [:v, :verbose]
127
132
 
@@ -174,6 +179,13 @@ command :autocomplete do |c|
174
179
  end
175
180
  end
176
181
 
182
+ desc 'Commit any pending changes'
183
+ command :commit do |c|
184
+ c.action do
185
+ monitor.commit_op5_config
186
+ end
187
+ end
188
+
177
189
  pre do |global, _command, _options, _args|
178
190
  global[:authfile] = ENV['OP5AUTHFILE'] if !ENV['OP5AUTHFILE'].nil? && (global[:authfile] == '~/.op5pass')
179
191
  Op5util.check_auth(global) ? true : false
@@ -16,12 +16,7 @@ module Op5util
16
16
  headers: { 'Content-Type' => 'application/json' },
17
17
  body: body, basic_auth: @auth, verify: false)
18
18
  raise ApiError, "Response code: #{response.code}, Message: #{response.body}" if response.code != 201
19
- puts 'New host created'
20
-
21
- url = @base_uri + 'config/change'
22
- response = self.class.post(url, body: {}, basic_auth: @auth, verify: false)
23
- raise ApiError, "Response code: #{response.code}, Message: #{response.body}" if response.code != 200
24
- puts 'New op5-config saved'
19
+ commit_op5_config unless options['no-commit'.to_sym]
25
20
  end
26
21
 
27
22
  private
@@ -5,7 +5,7 @@ module Op5util
5
5
  class NoSuchHostError < StandardError; end
6
6
  # Foo
7
7
  class Monitor
8
- def add_hostgroups(host, hostgroups)
8
+ def add_hostgroups(host, hostgroups, no_commit_config)
9
9
  hostgroups.each do |group|
10
10
  members = get_hostgroup_members(group)
11
11
  if !members.grep(host).empty?
@@ -16,6 +16,7 @@ module Op5util
16
16
  update_hostgroup(group, members)
17
17
  end
18
18
  end
19
+ commit_op5_config unless no_commit_config
19
20
  end
20
21
 
21
22
  private
@@ -20,28 +20,28 @@ _op5util()
20
20
 
21
21
  case "${op5command}" in
22
22
  acknowledge)
23
- COMPREPLY=( $(compgen -W "-c --comment=Work_in_Progress -p --persistent --no-persistent -v --verbose --no-verbose SOME_OP5_HOST" -- ${cur}) )
23
+ COMPREPLY=( $(compgen -W "-c --comment=Work_in_Progress -p --persistent --no-persistent -v --verbose --no-verbose $(op5util hosts)" -- ${cur}) )
24
24
  ;;
25
25
  add)
26
- COMPREPLY=( $(compgen -W "-a --alias=\" -c --contactgroups=\" -g --hostgroups=\" -i --ipaddr=\" HOST_TO_ADD" -- ${cur}) )
26
+ COMPREPLY=( $(compgen -W "-a --alias=\" -c --contactgroups=\" -g --hostgroups=\" -i --ipaddr=\" HOST_TO_ADD $(op5util hostgroups)" -- ${cur}) )
27
27
  ;;
28
28
  add_hostgroups)
29
- COMPREPLY=( $(compgen -W "-g --hostgroup= SOME_OP5_HOST" -- ${cur}) )
29
+ COMPREPLY=( $(compgen -W "-g --hostgroup= $(op5util hosts)" -- ${cur}) )
30
30
  ;;
31
31
  autocomplete)
32
32
  COMPREPLY=( $(compgen -W "ENTER" -- ${cur}) )
33
33
  ;;
34
34
  downtime)
35
- COMPREPLY=( $(compgen -W "-t --time=n_hour_duration_of_downtime -w --wait=n_hours_before_downtime_start -c --comment= SOME_OP5_HOST" -- ${cur}) )
35
+ COMPREPLY=( $(compgen -W "-t --time=n_hour_duration_of_downtime -w --wait=n_hours_before_downtime_start -c --comment= $(op5util hosts)" -- ${cur}) )
36
36
  ;;
37
37
  hostgroups)
38
- COMPREPLY=( $(compgen -W "-l --long SOME_OP5_HOSTGROUP" -- ${cur}) )
38
+ COMPREPLY=( $(compgen -W "-l --long $(op5util hostgroups)" -- ${cur}) )
39
39
  ;;
40
40
  schedule)
41
- COMPREPLY=( $(compgen -W "-v --verbose SOME_OP5_HOST" -- ${cur}) )
41
+ COMPREPLY=( $(compgen -W "-v --verbose $(op5util hosts)" -- ${cur}) )
42
42
  ;;
43
43
  status)
44
- COMPREPLY=( $(compgen -W "-l --long -s --short SOME_OP5_HOST" -- ${cur}) )
44
+ COMPREPLY=( $(compgen -W "-l --long -s --short $(op5util hosts)" -- ${cur}) )
45
45
  ;;
46
46
  *)
47
47
  ;;
@@ -0,0 +1,31 @@
1
+ module Op5util
2
+ require 'resolv'
3
+ class ApiError < StandardError; end
4
+ # Foo
5
+ class Monitor
6
+ def commit_op5_config
7
+ if pending_changes.empty?
8
+ puts 'No changes to commit'
9
+ else
10
+ do_commit
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def pending_changes
17
+ url = @base_uri + 'config/change'
18
+ response = self.class.get(url, basic_auth: @auth, verify: false)
19
+ raise ApiError, "Response code: #{response.code}, Message: #{response.body}" if response.code != 200
20
+ JSON.parse!(response.body)
21
+ end
22
+
23
+ def do_commit
24
+ url = @base_uri + 'config/change'
25
+ response = self.class.post(url, body: {}, basic_auth: @auth, verify: false)
26
+ raise ApiError, "Response code: #{response.code}, Message: #{response.body}" if response.code != 200
27
+ puts 'Op5-config commited'
28
+ end
29
+
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Op5util
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  end
data/lib/op5util.rb CHANGED
@@ -11,3 +11,4 @@ require 'op5util/list_hostgroups.rb'
11
11
  require 'op5util/schedule_checks.rb'
12
12
  require 'op5util/autocomplete.rb'
13
13
  require 'op5util/list_hosts.rb'
14
+ require 'op5util/commit.rb'
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.6
4
+ version: 0.1.7
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-18 00:00:00.000000000 Z
11
+ date: 2017-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -127,6 +127,7 @@ files:
127
127
  - lib/op5util/add_hostgroups.rb
128
128
  - lib/op5util/autocomplete.rb
129
129
  - lib/op5util/check_auth.rb
130
+ - lib/op5util/commit.rb
130
131
  - lib/op5util/list_hostgroups.rb
131
132
  - lib/op5util/list_hosts.rb
132
133
  - lib/op5util/method_template.rb
@@ -163,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
164
  version: '0'
164
165
  requirements: []
165
166
  rubyforge_project:
166
- rubygems_version: 2.5.1
167
+ rubygems_version: 2.6.11
167
168
  signing_key:
168
169
  specification_version: 4
169
170
  summary: A utility to do common Op5 administration from the commandline