miq_utilities 0.2.1 → 0.2.2.pre.WIP
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -0
- data/.rubocop.yml +29 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +3 -28
- data/README.md +308 -277
- data/lib/miq_utilities.rb +2 -0
- data/lib/miq_utilities/infoblox.rb +1 -1
- data/lib/miq_utilities/notification.rb +20 -35
- data/lib/miq_utilities/sql.rb +2 -2
- data/lib/miq_utilities/version.rb +1 -1
- data/lib/miq_utilities/vmware.rb +11 -9
- data/miq_utilities.gemspec +1 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d184df965af6a4f25ce41107b533b610e98943acabbd7eb1b4f32950132d69c
|
4
|
+
data.tar.gz: 11a0ac88b95da23a66e840535b77b89e4c0a115504befb5d5a2470ab1622de2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2e790149e8b0acafee2a5ea18b8ef7cea2e207cb7d9b6c3de30e24c95e0b5192dd666a6455dbe5c6dc1de4c4ad46974b783c60ba7fbb61e85a595e7cda65aef
|
7
|
+
data.tar.gz: be9bd063f97a37796fd79b542fec1ba297e8629f29efdaa96411725e1f40139d8a6ac0bfedef0965c71cf75ec2fc620e1ab9736b453e429def5c2347988958a3
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.4
|
3
|
+
Exclude:
|
4
|
+
- vendor/**/*
|
5
|
+
- Guardfile
|
6
|
+
|
7
|
+
ClassLength:
|
8
|
+
Enabled: false
|
9
|
+
CyclomaticComplexity:
|
10
|
+
Enabled: false
|
11
|
+
GlobalVars:
|
12
|
+
AllowedVariables:
|
13
|
+
- $evm
|
14
|
+
LineLength:
|
15
|
+
Enabled: false
|
16
|
+
MethodLength:
|
17
|
+
Enabled: false
|
18
|
+
Metrics/AbcSize:
|
19
|
+
Enabled: false
|
20
|
+
Metrics/LineLength:
|
21
|
+
Enabled: false
|
22
|
+
Metrics/ModuleLength:
|
23
|
+
Enabled: false
|
24
|
+
Metrics/PerceivedComplexity:
|
25
|
+
Enabled: false
|
26
|
+
Metrics/ParameterLists:
|
27
|
+
Enabled: false
|
28
|
+
Style/RescueStandardError:
|
29
|
+
Enabled: false
|
data/Gemfile
CHANGED
@@ -4,11 +4,11 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in miq_utilities.gemspec
|
6
6
|
gemspec
|
7
|
-
gem 'slack-
|
7
|
+
gem 'slack-notifier'
|
8
8
|
gem 'eventmachine'
|
9
9
|
gem 'faye-websocket'
|
10
10
|
gem 'rbvmomi'
|
11
11
|
gem 'tiny_tds'
|
12
12
|
gem 'winrm'
|
13
13
|
gem 'rest-client'
|
14
|
-
gem 'json'
|
14
|
+
gem 'json'
|
data/Gemfile.lock
CHANGED
@@ -1,41 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
miq_utilities (0.2.
|
4
|
+
miq_utilities (0.2.2.pre.WIP)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activesupport (5.2.0)
|
10
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
-
i18n (>= 0.7, < 2)
|
12
|
-
minitest (~> 5.1)
|
13
|
-
tzinfo (~> 1.1)
|
14
9
|
builder (3.2.3)
|
15
|
-
concurrent-ruby (1.0.5)
|
16
10
|
domain_name (0.5.20180417)
|
17
11
|
unf (>= 0.0.5, < 1.0.0)
|
18
12
|
erubis (2.7.0)
|
19
13
|
eventmachine (1.2.6-x64-mingw32)
|
20
|
-
faraday (0.15.0)
|
21
|
-
multipart-post (>= 1.2, < 3)
|
22
|
-
faraday_middleware (0.12.2)
|
23
|
-
faraday (>= 0.7.4, < 1.0)
|
24
14
|
faye-websocket (0.10.7)
|
25
15
|
eventmachine (>= 0.12.0)
|
26
16
|
websocket-driver (>= 0.5.1)
|
27
17
|
ffi (1.9.23-x64-mingw32)
|
28
|
-
gli (2.17.1)
|
29
18
|
gssapi (1.2.0)
|
30
19
|
ffi (>= 1.0.1)
|
31
20
|
gyoku (1.3.1)
|
32
21
|
builder (>= 2.1.2)
|
33
|
-
hashie (3.5.7)
|
34
22
|
http-cookie (1.0.3)
|
35
23
|
domain_name (~> 0.5)
|
36
24
|
httpclient (2.8.3)
|
37
|
-
i18n (1.0.1)
|
38
|
-
concurrent-ruby (~> 1.0)
|
39
25
|
json (2.1.0)
|
40
26
|
little-plugger (1.1.4)
|
41
27
|
logging (2.2.2)
|
@@ -45,9 +31,7 @@ GEM
|
|
45
31
|
mime-types-data (~> 3.2015)
|
46
32
|
mime-types-data (3.2016.0521)
|
47
33
|
mini_portile2 (2.3.0)
|
48
|
-
minitest (5.11.3)
|
49
34
|
multi_json (1.13.1)
|
50
|
-
multipart-post (2.0.0)
|
51
35
|
netrc (0.11.0)
|
52
36
|
nokogiri (1.8.2-x64-mingw32)
|
53
37
|
mini_portile2 (~> 2.3.0)
|
@@ -64,18 +48,9 @@ GEM
|
|
64
48
|
mime-types (>= 1.16, < 4.0)
|
65
49
|
netrc (~> 0.8)
|
66
50
|
rubyntlm (0.6.2)
|
67
|
-
slack-
|
68
|
-
activesupport
|
69
|
-
faraday (>= 0.9)
|
70
|
-
faraday_middleware
|
71
|
-
gli
|
72
|
-
hashie
|
73
|
-
websocket-driver
|
74
|
-
thread_safe (0.3.6)
|
51
|
+
slack-notifier (2.3.2)
|
75
52
|
tiny_tds (2.1.1-x64-mingw32)
|
76
53
|
trollop (2.1.2)
|
77
|
-
tzinfo (1.2.5)
|
78
|
-
thread_safe (~> 0.1)
|
79
54
|
unf (0.1.4)
|
80
55
|
unf_ext
|
81
56
|
unf_ext (0.0.7.5-x64-mingw32)
|
@@ -104,7 +79,7 @@ DEPENDENCIES
|
|
104
79
|
rake (~> 10.0)
|
105
80
|
rbvmomi
|
106
81
|
rest-client
|
107
|
-
slack-
|
82
|
+
slack-notifier
|
108
83
|
tiny_tds
|
109
84
|
winrm
|
110
85
|
|
data/README.md
CHANGED
@@ -1,277 +1,308 @@
|
|
1
|
-
# MiqUtilities
|
2
|
-
|
3
|
-
## Installation
|
4
|
-
|
5
|
-
$
|
6
|
-
|
7
|
-
## Usage
|
8
|
-
|
9
|
-
require 'miq_utilities'
|
10
|
-
|
11
|
-
## Dependencies
|
12
|
-
|
13
|
-
1. bundler ~> 1.16
|
14
|
-
2. rake ~> 10.0
|
15
|
-
3. rbvmomi ~> 1.11.3
|
16
|
-
4. tiny_tds ~> 2.1.0
|
17
|
-
5. winrm ~> 2.2.3
|
18
|
-
6. slack-
|
19
|
-
7. rest-client ~> 1.8.0 x64-mingw32
|
20
|
-
8. json ~> 2.0.4
|
21
|
-
|
22
|
-
# Class Summary
|
23
|
-
## Sql Server (SqlClass)
|
24
|
-
|
25
|
-
Used to manage Sql Server queries. This Class utilises the `tiny_tds` Ruby Gem (version => 2.1.0).
|
26
|
-
|
27
|
-
### Class Method Summary
|
28
|
-
|
29
|
-
#### **initialize**
|
30
|
-
|
31
|
-
_Create a connection to the client_
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
```
|
55
|
-
|
56
|
-
#### **
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
```
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
#### **
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
```
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
```
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
```
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
Name
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
1
|
+
# MiqUtilities
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
$ bundle install
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
require 'miq_utilities'
|
10
|
+
|
11
|
+
## Dependencies
|
12
|
+
|
13
|
+
1. bundler ~> 1.16
|
14
|
+
2. rake ~> 10.0
|
15
|
+
3. rbvmomi ~> 1.11.3
|
16
|
+
4. tiny_tds ~> 2.1.0
|
17
|
+
5. winrm ~> 2.2.3
|
18
|
+
6. slack-notifier ~> 2.3.2
|
19
|
+
7. rest-client ~> 1.8.0 x64-mingw32
|
20
|
+
8. json ~> 2.0.4
|
21
|
+
|
22
|
+
# Class Summary
|
23
|
+
## Sql Server (SqlClass)
|
24
|
+
|
25
|
+
Used to manage Sql Server queries. This Class utilises the `tiny_tds` Ruby Gem (version => 2.1.0).
|
26
|
+
|
27
|
+
### Class Method Summary
|
28
|
+
|
29
|
+
#### **initialize**
|
30
|
+
|
31
|
+
_Create a connection to the client_
|
32
|
+
|
33
|
+
##### Parameters
|
34
|
+
```
|
35
|
+
Name | Type | Description
|
36
|
+
-----------------------------------------------------
|
37
|
+
user ¦ String ¦ Username
|
38
|
+
|
39
|
+
password ¦ String ¦ Password
|
40
|
+
|
41
|
+
host ¦ String ¦ The host name to connect to
|
42
|
+
|
43
|
+
port ¦ String ¦ The port to use (default 1433)
|
44
|
+
|
45
|
+
database ¦ String ¦ The database name to connect to
|
46
|
+
|
47
|
+
azure ¦ Boolean ¦ Set to true when connecting to Azure
|
48
|
+
|
49
|
+
```
|
50
|
+
##### Method usage
|
51
|
+
```
|
52
|
+
require 'miq_utilities'
|
53
|
+
sql = SqlClass.new(user, pwrd, host, 1433, db, azure)
|
54
|
+
```
|
55
|
+
|
56
|
+
#### **get_client**
|
57
|
+
|
58
|
+
_Returns the client to utilise the `tiny_tds` functionality_
|
59
|
+
|
60
|
+
##### Method usage
|
61
|
+
```
|
62
|
+
client = sql.get_client()
|
63
|
+
```
|
64
|
+
|
65
|
+
#### **run_sql_query**
|
66
|
+
|
67
|
+
_Runs the specified SQL query against the client the class was instantiated for._
|
68
|
+
|
69
|
+
##### Parameters
|
70
|
+
```
|
71
|
+
Name | Type | Description
|
72
|
+
--------------------------------------
|
73
|
+
sql ¦ String ¦ Sql Query to be run
|
74
|
+
```
|
75
|
+
|
76
|
+
##### Method usage
|
77
|
+
```
|
78
|
+
query = 'SELECT * FROM tbl_users'
|
79
|
+
out = sql.run_sql_query(query)
|
80
|
+
out.each {|user| puts "User Details: #{user}"}
|
81
|
+
```
|
82
|
+
|
83
|
+
#### **close_connection**
|
84
|
+
|
85
|
+
_closes the connection to the client._
|
86
|
+
|
87
|
+
##### Method usage
|
88
|
+
```
|
89
|
+
sql.close_connection()
|
90
|
+
```
|
91
|
+
|
92
|
+
## Logging (LoggingClass)
|
93
|
+
|
94
|
+
This Class is used to handle the logging for ManageIQ and an IDE.
|
95
|
+
|
96
|
+
### Class Method Summary
|
97
|
+
|
98
|
+
#### **initialize**
|
99
|
+
|
100
|
+
_Instantiate the class using the name of the class/method/instantiator._
|
101
|
+
|
102
|
+
##### Parameters
|
103
|
+
```
|
104
|
+
Name | Type | Description
|
105
|
+
------------------------------------------------------------
|
106
|
+
name ¦ String ¦ The name of the class/method/instantiator
|
107
|
+
```
|
108
|
+
|
109
|
+
##### Method usage
|
110
|
+
```
|
111
|
+
require 'miq_utilities'
|
112
|
+
logger = LoggingClass.new('example_method_name')
|
113
|
+
```
|
114
|
+
|
115
|
+
#### **log**
|
116
|
+
|
117
|
+
_Log to the `$evm` object i.e. automation.log._
|
118
|
+
##### Parameters
|
119
|
+
```
|
120
|
+
Name | Type | Description
|
121
|
+
----------------------------------------------------------------------
|
122
|
+
level ¦ String ¦ The level of info/warning/error
|
123
|
+
message ¦ String ¦ The message to write
|
124
|
+
logtoscreenonly ¦ Boolean ¦ Only log to screen
|
125
|
+
notify ¦ Boolean ¦ Process message through the notify process
|
126
|
+
```
|
127
|
+
|
128
|
+
##### Method usage
|
129
|
+
```
|
130
|
+
logger.log('info','This is a test message!')
|
131
|
+
```
|
132
|
+
or to process through the Notify class we would use the follwoing:
|
133
|
+
```
|
134
|
+
logger.log('warn', 'This is a warning message', false, true)
|
135
|
+
```
|
136
|
+
NOTE: When "NOTE" is passed as the level, the notify class turns this into an INFO on-screen message.
|
137
|
+
|
138
|
+
## VmWare (VmwareClass)
|
139
|
+
|
140
|
+
This Class is used to handle some of the heavily used VMWare utilities. This Class utilises the `rbvmomi` Ruby Gem (version => 1.11.3).
|
141
|
+
|
142
|
+
### Class Method Summary
|
143
|
+
|
144
|
+
#### **initialize**
|
145
|
+
|
146
|
+
_Assign the host name._
|
147
|
+
##### Parameters
|
148
|
+
```
|
149
|
+
Name | Type | Description
|
150
|
+
------------------------------------------------------
|
151
|
+
hostName ¦ String ¦ The name of the host to be used
|
152
|
+
```
|
153
|
+
|
154
|
+
##### Method usage
|
155
|
+
```
|
156
|
+
vmware = VmwareClass.new('MyHostName')
|
157
|
+
```
|
158
|
+
|
159
|
+
#### **get_vsphere_connection**
|
160
|
+
_Returns the client connection._
|
161
|
+
##### Parameters
|
162
|
+
```
|
163
|
+
Name | Type | Description
|
164
|
+
------------------------------------------------------
|
165
|
+
user ¦ String ¦ The name of the host to be used
|
166
|
+
password ¦ String ¦ The users password
|
167
|
+
```
|
168
|
+
|
169
|
+
##### Method usage
|
170
|
+
```
|
171
|
+
vsphereconn = vmware.get_vsphere_connection(user,pwd)
|
172
|
+
```
|
173
|
+
|
174
|
+
#### **retrieve_data_centre**
|
175
|
+
|
176
|
+
_Returns the datacentre based on the connection and datacentre name._
|
177
|
+
##### Parameters
|
178
|
+
```
|
179
|
+
Name | Type | Description
|
180
|
+
---------------------------------------------------------------
|
181
|
+
vsphereconn ¦ object ¦ The return of "get_vsphere_connection"
|
182
|
+
dcname ¦ String ¦ The name of the datacentre
|
183
|
+
```
|
184
|
+
|
185
|
+
##### Method usage
|
186
|
+
```
|
187
|
+
vmdc = vmware.retrieve_data_centre(vsphereconn,'MyDatacentre')
|
188
|
+
```
|
189
|
+
|
190
|
+
## Run Powershell (WinrmClass)
|
191
|
+
|
192
|
+
This Class is used to run PowerShell scripts. This Class utilises the `winrm` Ruby Gem (version => 2.2.3).
|
193
|
+
|
194
|
+
### Class Method Summary
|
195
|
+
|
196
|
+
#### **initialize**
|
197
|
+
|
198
|
+
_Run a specified PowerShell script._
|
199
|
+
##### Parameters
|
200
|
+
```
|
201
|
+
Name | Type | Description
|
202
|
+
---------------------------------------------------------
|
203
|
+
ps_script ¦ String ¦ The script to run
|
204
|
+
host ¦ String ¦ The name of the host to connect to
|
205
|
+
user ¦ String ¦ The user to connect with
|
206
|
+
password ¦ String ¦ The users password
|
207
|
+
```
|
208
|
+
##### Method usage
|
209
|
+
```
|
210
|
+
Name = 'Aaron'
|
211
|
+
ps1 = "C:\\Powershell\\RunHelloWorld.ps1 -name #{Name}"
|
212
|
+
winrm_run(ps1,host,user,pwrd)
|
213
|
+
```
|
214
|
+
|
215
|
+
## Notification (NotificationClass)
|
216
|
+
|
217
|
+
This Class is used to notify users and log messages accordingly. This Class utilises the slack-notifier Ruby Gem (version => 2.3.2).
|
218
|
+
|
219
|
+
### Class Method Summary
|
220
|
+
|
221
|
+
#### **notify**
|
222
|
+
|
223
|
+
_Initiate the process._
|
224
|
+
##### Parameters
|
225
|
+
```
|
226
|
+
Name | Type | Description
|
227
|
+
---------------------------------------------------------------
|
228
|
+
event_level ¦ String ¦ info, warn, error
|
229
|
+
event_message ¦ String ¦ The message to be used
|
230
|
+
email_to ¦ String ¦ Who to send an email to
|
231
|
+
email_from ¦ String ¦ Sent from which email address
|
232
|
+
signature ¦ String ¦ Who the emails from
|
233
|
+
webhookURL ¦ String ¦ The webhook to be used
|
234
|
+
```
|
235
|
+
|
236
|
+
##### Method usage
|
237
|
+
```
|
238
|
+
require 'miq_utilities'
|
239
|
+
logger = LoggingClass.new('Test NotificationCLass')
|
240
|
+
logger.log('error', 'An error occured!', false, true)
|
241
|
+
```
|
242
|
+
|
243
|
+
#### Levels (event_level)
|
244
|
+
```
|
245
|
+
Level | Action
|
246
|
+
----------------------------------------------------------------------------------------------
|
247
|
+
INFO | Logs to the $evm log
|
248
|
+
WARN | Logs to the $evm log, sends an Email and a Slack message
|
249
|
+
ERROR | Logs to the $evm log, sends an Email, a Slack message and an on-screen notification
|
250
|
+
NOTE | Sends an on-screen notification (As an info message)
|
251
|
+
```
|
252
|
+
|
253
|
+
#### **send_email**
|
254
|
+
_Sends an email to the specified user using the **$evm.execute** MIQ method_
|
255
|
+
##### Parameters
|
256
|
+
```
|
257
|
+
Name | Type | Description
|
258
|
+
---------------------------------------------
|
259
|
+
message ¦ String ¦ The message to be used
|
260
|
+
subject ¦ String ¦ The Subject to be used
|
261
|
+
to_email ¦ String ¦ Recipient email
|
262
|
+
from_email ¦ String ¦ Sender email
|
263
|
+
signature ¦ String ¦ Who the emails from
|
264
|
+
```
|
265
|
+
##### Method usage
|
266
|
+
|
267
|
+
```$xslt
|
268
|
+
require 'miq_utilities'
|
269
|
+
notify = NotificationCLass.new
|
270
|
+
notify.send_email('This is an Email.', 'Test', 'aaron@mycompany.com', 'miq@mycompany.com', 'DevOps')
|
271
|
+
```
|
272
|
+
|
273
|
+
#### **send_slack_message**
|
274
|
+
|
275
|
+
_Sends a Slcak message_
|
276
|
+
##### Parameters
|
277
|
+
```
|
278
|
+
Name | Type | Description
|
279
|
+
--------------------------------------------------------------
|
280
|
+
message ¦ String ¦ The message to be used
|
281
|
+
webhookURL ¦ String ¦ The webhook to be used
|
282
|
+
```
|
283
|
+
|
284
|
+
##### Method usage
|
285
|
+
|
286
|
+
```$xslt
|
287
|
+
require 'miq_utilities'
|
288
|
+
notify = NotificationCLass.new
|
289
|
+
notify.send_slack_message('This a Slack post!', 'https://hooks.slack.com/services/token')
|
290
|
+
```
|
291
|
+
|
292
|
+
#### **on_screen_message**
|
293
|
+
_on_screen_message - Sends an on-screen notification_
|
294
|
+
##### Parameters
|
295
|
+
```
|
296
|
+
Name | Type | Description
|
297
|
+
--------------------------------------------
|
298
|
+
level ¦ String v info, warn, error
|
299
|
+
message ¦ String ¦ The message to be used
|
300
|
+
subject ¦ String ¦ The Subject to be used
|
301
|
+
```
|
302
|
+
##### Method usage
|
303
|
+
|
304
|
+
```$xslt
|
305
|
+
require 'miq_utilities'
|
306
|
+
notify = NotificationCLass.new
|
307
|
+
notify.on_screen_message('info', 'This is an on-screen notification', 'Test')
|
308
|
+
```
|
data/lib/miq_utilities.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# .SYNOPSIS
|
4
|
-
# This Class utilises the slack-
|
4
|
+
# This Class utilises the slack-notifier Ruby Gem (version => 2.3.2).
|
5
5
|
#
|
6
6
|
# Methods Summary:
|
7
7
|
# > Name > Description/Params
|
@@ -10,39 +10,37 @@
|
|
10
10
|
# event_message - String : The message to be used
|
11
11
|
# email_to - String : Who to send an email to
|
12
12
|
# email_from - String : Sent from which email address
|
13
|
-
#
|
14
|
-
#
|
13
|
+
# signature - String : Who the emails from
|
14
|
+
# webhookurl - String : The slcak channel to send the message to
|
15
15
|
#
|
16
16
|
# send_email - Sends an email to the specified user
|
17
17
|
# message - String : The message to be used
|
18
18
|
# subject - String : The Subject to be used
|
19
|
-
# to_email - String : Recipient email
|
20
19
|
# from_email - String : Sender email
|
21
|
-
#
|
20
|
+
# signature - String : Who the emails from
|
21
|
+
# to_email - String : Recipient email
|
22
22
|
#
|
23
23
|
# send_slack_message - Sends a Slcak message
|
24
|
-
# message
|
25
|
-
#
|
26
|
-
# token - String : The API token used to authenticate
|
24
|
+
# message - String : The message to be used
|
25
|
+
# webhookurl - String : The webhook to be used
|
27
26
|
#
|
28
27
|
# on_screen_message - Sends an on-screen notification
|
29
28
|
# level - String : info, warn, error
|
30
29
|
# message - String : The message to be used
|
31
30
|
# subject - String : The Subject to be used
|
32
31
|
# WIP
|
33
|
-
require 'slack-
|
32
|
+
require 'slack-notifier'
|
34
33
|
|
35
34
|
# notification class
|
36
35
|
class NotificationClass
|
37
|
-
|
38
|
-
def notify(event_level, event_message, email_to = nil, email_from = nil, from = nil, slack_channel = nil)
|
36
|
+
def notify(event_level, event_message, email_to = nil, email_from = nil, signature = nil, webhookurl = nil)
|
39
37
|
case event_level.upcase
|
40
38
|
when %w[WARN WARNING]
|
41
|
-
send_email(event_message, 'Warning Identified',
|
42
|
-
send_slack_message(event_message,
|
39
|
+
send_email(event_message, 'Warning Identified', email_from, signature, email_to)
|
40
|
+
send_slack_message(event_message, webhookurl)
|
43
41
|
when %w[ERR ERROR]
|
44
|
-
send_email(event_message, 'Error Identified',
|
45
|
-
send_slack_message(event_message,
|
42
|
+
send_email(event_message, 'Error Identified', email_from, signature, email_to)
|
43
|
+
send_slack_message(event_message, webhookurl)
|
46
44
|
on_screen_message(event_level, event_message)
|
47
45
|
when 'NOTE'
|
48
46
|
on_screen_message(event_level, event_message)
|
@@ -51,7 +49,7 @@ class NotificationClass
|
|
51
49
|
raise("Oopps! Something went wrong trying to notify. Error:<#{err}>")
|
52
50
|
end
|
53
51
|
|
54
|
-
def send_email(message, subject, to_email = nil
|
52
|
+
def send_email(message, subject, from_email, signature, to_email = nil)
|
55
53
|
# Look in the current object for a VM
|
56
54
|
vm = $evm.object['vm']
|
57
55
|
if vm.nil?
|
@@ -95,7 +93,7 @@ class NotificationClass
|
|
95
93
|
body = 'Hello, '
|
96
94
|
body += message
|
97
95
|
body += 'Thank you,'
|
98
|
-
body +=
|
96
|
+
body += signature
|
99
97
|
|
100
98
|
$evm.execute(:send_email, to, from_email, subject, body)
|
101
99
|
rescue => err
|
@@ -103,24 +101,11 @@ class NotificationClass
|
|
103
101
|
end
|
104
102
|
|
105
103
|
# TBD - awaiting webhook setup
|
106
|
-
def send_slack_message(message,
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
raise 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
|
112
|
-
end
|
113
|
-
else
|
114
|
-
config.token = token
|
115
|
-
end
|
116
|
-
|
117
|
-
begin
|
118
|
-
client = Slack::Web::Client.new
|
119
|
-
client.auth_test
|
120
|
-
client.chat_postMessage(channel: channel, text: message, as_user: true)
|
121
|
-
rescue => err
|
122
|
-
raise("Oopps! Something went wrong trying to send a Slack notification. Error:<#{err}>")
|
123
|
-
end
|
104
|
+
def send_slack_message(message, webhookurl)
|
105
|
+
notifier = Slack::Notifier.new webhookurl
|
106
|
+
notifier.ping message
|
107
|
+
rescue => err
|
108
|
+
raise("Oopps! Something went wrong trying to send a Slack notification. Error:<#{err}>")
|
124
109
|
end
|
125
110
|
|
126
111
|
def on_screen_message(level, message, subject = nil)
|
data/lib/miq_utilities/sql.rb
CHANGED
@@ -9,9 +9,9 @@
|
|
9
9
|
# user - String : Username
|
10
10
|
# password - String : Password
|
11
11
|
# host - String : The host name to connect to
|
12
|
-
# port - String : The port to use, default (nil) 1433
|
13
12
|
# database - String : The database name to connect to
|
14
13
|
# azure - Boolean : Set to true when connecting to Azure
|
14
|
+
# port - String : The port to use, default (nil) 1433
|
15
15
|
#
|
16
16
|
# get_client - returns the client to utilise the tiny_tds functionality
|
17
17
|
#
|
@@ -25,7 +25,7 @@ require 'tiny_tds'
|
|
25
25
|
# Sql class
|
26
26
|
class SqlClass
|
27
27
|
# Initialize Class
|
28
|
-
def initialize(user, password, host, port = nil
|
28
|
+
def initialize(user, password, host, database, azure, port = nil)
|
29
29
|
# Logging
|
30
30
|
@logger = LoggingClass.new('SQL')
|
31
31
|
|
data/lib/miq_utilities/vmware.rb
CHANGED
@@ -12,10 +12,12 @@
|
|
12
12
|
# user - String : The user to connect with
|
13
13
|
# password - String : The users password
|
14
14
|
#
|
15
|
-
#
|
16
|
-
# vsphereconn - connection : The return of "get_vsphere_connection"
|
17
|
-
# dcname - String : The name of the datacenter
|
15
|
+
# retrieve_data_center - returns the datacenter based on the connection and datacenter
|
18
16
|
#
|
17
|
+
#
|
18
|
+
# find_vm - Get the VM details from vmware
|
19
|
+
# datacenter - String : datacenter name returned from retrieve_data_center
|
20
|
+
# vmname - String : The vmname
|
19
21
|
require 'rbvmomi'
|
20
22
|
|
21
23
|
# vmware wrapper class
|
@@ -34,10 +36,10 @@ class VmwareClass
|
|
34
36
|
raise("No connection established!\nUse the \"get_vsphere_connection\" method to connect.") if @connection.nil?
|
35
37
|
end
|
36
38
|
|
37
|
-
def find_vm(
|
39
|
+
def find_vm(datacenter, vmname)
|
38
40
|
vm = {}
|
39
|
-
|
40
|
-
vm[:instance] = datastore.vm.find { |x| x.name ==
|
41
|
+
datacenter.datastoreFolder.childEntity.collect do |datastore|
|
42
|
+
vm[:instance] = datastore.vm.find { |x| x.name == vmname }
|
41
43
|
if vm[:instance]
|
42
44
|
vm[:datastore] = datastore.name
|
43
45
|
break
|
@@ -46,10 +48,10 @@ class VmwareClass
|
|
46
48
|
vm
|
47
49
|
end
|
48
50
|
|
49
|
-
def upg_tools(
|
50
|
-
instopts = if
|
51
|
+
def upg_tools(vmobj)
|
52
|
+
instopts = if vmobj[:instance][:guest][:guestFamily] == 'windowsGuest'
|
51
53
|
'/s /v "/qn REBOOT=ReallySuppress"'
|
52
54
|
end
|
53
|
-
|
55
|
+
vmobj[:instance].UpgradeTools_Task(installerOptions: instopts).wait_for_completion
|
54
56
|
end
|
55
57
|
end
|
data/miq_utilities.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miq_utilities
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2.pre.WIP
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron McCatty
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '2.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: slack-notifier
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.3'
|
111
125
|
description: " This Gem was written to hold utilities commonly used within ManageIQ/Cloudforms. "
|
112
126
|
email:
|
113
127
|
- aaronmccatty@hotmail.co.uk
|
@@ -116,6 +130,7 @@ extensions: []
|
|
116
130
|
extra_rdoc_files: []
|
117
131
|
files:
|
118
132
|
- ".gitignore"
|
133
|
+
- ".rubocop.yml"
|
119
134
|
- Gemfile
|
120
135
|
- Gemfile.lock
|
121
136
|
- LICENSE.txt
|
@@ -147,9 +162,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
162
|
version: '0'
|
148
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
164
|
requirements:
|
150
|
-
- - "
|
165
|
+
- - ">"
|
151
166
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
167
|
+
version: 1.3.1
|
153
168
|
requirements: []
|
154
169
|
rubyforge_project:
|
155
170
|
rubygems_version: 2.7.6
|