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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2238911c5afe3bc64b77cf5678044f81a15b3bab44da036c3b6efda38fe7b50
4
- data.tar.gz: 615876043211d98d49c2e0898284cbd900b13929155862a9d25c8ec20402737c
3
+ metadata.gz: 2d184df965af6a4f25ce41107b533b610e98943acabbd7eb1b4f32950132d69c
4
+ data.tar.gz: 11a0ac88b95da23a66e840535b77b89e4c0a115504befb5d5a2470ab1622de2d
5
5
  SHA512:
6
- metadata.gz: b48663b05141985b94313a9996a33562048fb7b0b20ab655ce7e418b63a4848f5f5d032d8673f70c0946d7952a145996c49322889a8efc3bad8271ee6438ad83
7
- data.tar.gz: 4bab43cdb2338c9ef1abeab52dd429ab762542627c1f0f65599387c7f04dd6a215609b8efccdd5c07d84473ab9cd472556b6946a0d2b7809cea18c3d2f23c347
6
+ metadata.gz: b2e790149e8b0acafee2a5ea18b8ef7cea2e207cb7d9b6c3de30e24c95e0b5192dd666a6455dbe5c6dc1de4c4ad46974b783c60ba7fbb61e85a595e7cda65aef
7
+ data.tar.gz: be9bd063f97a37796fd79b542fec1ba297e8629f29efdaa96411725e1f40139d8a6ac0bfedef0965c71cf75ec2fc620e1ab9736b453e429def5c2347988958a3
data/.gitignore CHANGED
@@ -1,10 +1,21 @@
1
1
  /.bundle/
2
+ .bundle
2
3
  /.yardoc
3
4
  /_yardoc/
5
+ .yardoc
4
6
  /coverage/
5
7
  /doc/
6
8
  /pkg/
7
9
  /spec/reports/
8
10
  /tmp/
11
+ .config
9
12
  *.iml
10
13
  .idea
14
+ .idea
15
+ .idea/*
16
+ */.idea
17
+ */.idea/*
18
+ **/.idea
19
+ **/.idea/*
20
+ $evm
21
+
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-ruby-client'
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.1)
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-ruby-client (0.11.1)
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-ruby-client
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
- $ gem install miq_utilities
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-ruby-client ~> 0.11.1
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
- Name | Type | Description
33
- ---- | ---- | ----
34
- user | String | Username
35
- password | String | Password
36
- host | String | The host name to connect to
37
- port | String | The port to use, default 1433
38
- database | String | The database name to connect to
39
- azure | Boolean | Set to true when connecting to Azure
40
-
41
- ##### Method usage
42
- ```
43
- require 'miq_utilities'
44
- sql = SqlClass.new(user, pwrd, host, 1433, db, azure)
45
- ```
46
-
47
- #### **get_client**
48
-
49
- _Returns the client to utilise the `tiny_tds` functionality_
50
-
51
- ##### Method usage
52
- ```
53
- client = sql.get_client()
54
- ```
55
-
56
- #### **run_sql_query**
57
-
58
- _Runs the specified SQL query against the client the class was instantiated for._
59
- Name | Type | Description
60
- ---- | ---- | ----
61
- sql | String | Sql query to be run
62
-
63
- ##### Method usage
64
- ```
65
- query = 'SELECT * FROM tbl_users'
66
- out = sql.run_sql_query(query)
67
- out.each {|user| puts "User Details: #{user}"}
68
- ```
69
-
70
- #### **close_connection**
71
-
72
- _closes the connection to the client._
73
-
74
- ##### Method usage
75
- ```
76
- sql.close_connection()
77
- ```
78
-
79
- ## Logging (LoggingClass)
80
-
81
- This Class is used to handle the logging for ManageIQ and an IDE.
82
-
83
- ### Class Method Summary
84
-
85
- #### **initialize**
86
-
87
- _Instantiate the class using the name of the class/method/instantiator._
88
- Name | Type | Description
89
- ---- | ---- | ----
90
- name | String | The name of the class/method/instantiator
91
-
92
- ##### Method usage
93
- ```
94
- require 'miq_utilities'
95
- logger = LoggingClass.new('example_method_name')
96
- ```
97
-
98
- #### **log**
99
-
100
- _Log to the `$evm` object i.e. automation.log._
101
- Name | Type | Description
102
- ---- | ---- | ----
103
- level | String | The level of info/warning/error (no action is taken regardless of level)
104
- message | String | The message to write
105
- logtoscreenonly | Boolean | Only log to screen
106
- notify | Boolean | Process message through the notify process
107
-
108
- ##### Method usage
109
- ```
110
- logger.log('info','This is a test message!')
111
- ```
112
- or to process through the Notify class we would use the follwoing:
113
- ```
114
- logger.log('warn', 'This is a warning message', false, true)
115
- ```
116
- NOTE: When "NOTE" is passed as the level, the notify class turns this into an INFO on-screen message.
117
-
118
- ## VmWare (VmwareClass)
119
-
120
- This Class is used to handle some of the heavily used VMWare utilities. This Class utilises the `rbvmomi` Ruby Gem (version => 1.11.3).
121
-
122
- ### Class Method Summary
123
-
124
- #### **initialize**
125
-
126
- _Assign the host name._
127
- Name | Type | Description
128
- ---- | ---- | ----
129
- hostName | String | The name of the host to be used
130
-
131
- ##### Method usage
132
- ```
133
- vmware = VmwareClass.new('MyHostName')
134
- ```
135
-
136
- #### **get_vsphere_connection**
137
-
138
- _Returns the client connection._
139
- Name | Type | Description
140
- ---- | ---- | ----
141
- user | String | The user to connect with
142
- password | String | The users password
143
-
144
- ##### Method usage
145
- ```
146
- vsphereconn = vmware.get_vsphere_connection(user,pwd)
147
- ```
148
-
149
- #### **retrieve_data_centre**
150
-
151
- _Returns the datacentre based on the connection and datacentre name._
152
- Name | Type | Description
153
- ---- | ---- | ----
154
- vsphereconn | object | The return of "get_vsphere_connection"
155
- dcname | String | The name of the datacentre
156
-
157
- ##### Method usage
158
- ```
159
- vmdc = vmware.retrieve_data_centre(vsphereconn,'MyDatacentre')
160
- ```
161
-
162
- ## Run Powershell (WinrmClass)
163
-
164
- This Class is used to run PowerShell scripts. This Class utilises the `winrm` Ruby Gem (version => 2.2.3).
165
-
166
- ### Class Method Summary
167
-
168
- #### **initialize**
169
-
170
- _Run a specified PowerShell script._
171
- Name | Type | Description
172
- ---- | ---- | ----
173
- ps_script | String | The name of the script to run (including path to the file)
174
- host | String | The name of the host to connect to
175
- user | String | The user to connect with
176
- password | String | The users password
177
-
178
- ##### Method usage
179
- ```
180
- Name = 'Aaron'
181
- ps1 = "C:\\Powershell\\RunHelloWorld.ps1 -name #{Name}"
182
- winrm_run(ps1,host,user,pwrd)
183
- ```
184
-
185
- ## Notification (NotificationClass)
186
-
187
- This Class is used to notify users and log messages accordingly. This Class utilises the `slack-ruby-client` Ruby Gem (version => 0.11.1).
188
-
189
- ### Class Method Summary
190
-
191
- #### **notify**
192
-
193
- _Initiate the process._
194
- Name | Type | Description
195
- ---- | ---- | ----
196
- event_level | String | info, warn, error
197
- event_message | String | The message to be used
198
- email_to | String | Who to send an email to
199
- email_from | String | Sent from which email address
200
- from | String | From who
201
- slack_channel | Boolean | The slcak channel to send the message to
202
-
203
-
204
- ##### Method usage
205
- ```
206
- require 'miq_utilities'
207
- logger = LoggingClass.new('Test NotificationCLass')
208
- logger.log('error', 'An error occured!', false, true)
209
- ```
210
-
211
- #### Levels
212
- Level | Action
213
- ---- | ---- | ----
214
- INFO | Logs to the $evm log
215
- WARN | Logs to the $evm log, sends an Email and a Slack message
216
- ERROR | Logs to the $evm log, sends an Email, a Slack message and an on-screen notification
217
- NOTE | Sends and on-screen notification (As an info message)
218
-
219
-
220
- #### **send_email**
221
- _Sends an email to the specified user using the **$evm.execute** MIQ method_
222
- Name | Type | Description
223
- ---- | ---- | ----
224
- message | String | The message to be used
225
- subject | String | The Subject to be used
226
- to_email | String | Recipient email
227
- from_email | String | Sender email
228
- from | String | Sent from
229
-
230
- ##### Method usage
231
-
232
- ```$xslt
233
- require 'miq_utilities'
234
- notify = NotificationCLass.new
235
- notify.send_email('This is an Email.', 'Test', 'aaron@mycompany.com', 'miq@mycompany.com', 'DevOps')
236
- ```
237
-
238
- #### **send_slack_message**
239
-
240
- _Sends a Slcak message_
241
- Name | Type | Description
242
- ---- | ---- | ----
243
- message | String | The message to be used
244
- channel | String | The channel in which to post the message
245
- token | String | The API token used to authenticate
246
-
247
- ##### Method usage
248
-
249
- ```$xslt
250
- require 'miq_utilities'
251
- notify = NotificationCLass.new
252
- notify.send_slack_message('This a Slack post!', '#MIQ-CHANNEL', 'token-to-use')
253
- ```
254
-
255
- #### **on_screen_message**
256
- _on_screen_message - Sends an on-screen notification_
257
- Name | Type | Description
258
- ---- | ---- | ----
259
- level | String | info, warn, error
260
- message | String | The message to be used
261
- subject | String | The Subject to be used
262
-
263
- ##### Method usage
264
-
265
- ```$xslt
266
- require 'miq_utilities'
267
- notify = NotificationCLass.new
268
- notify.on_screen_message('info', 'This is an on-screen notification', 'Test')
269
- ```
270
-
271
- ## Contributing
272
-
273
- Currently not in a public repo, but you have the source to change at your will.
274
-
275
- ## License
276
-
277
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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,4 +1,6 @@
1
+ # frozen_string_literal: true
1
2
 
3
+ # Module to include resources
2
4
  module MiqUtilities
3
5
  require_relative 'miq_utilities/version'
4
6
  require_relative 'miq_utilities/infoblox.rb'
@@ -133,4 +133,4 @@ class InfobloxClass
133
133
  end
134
134
  response
135
135
  end
136
- end
136
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # .SYNOPSIS
4
- # This Class utilises the slack-ruby-client Ruby Gem (version => 0.11.1).
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
- # from - String : From who
14
- # slack_channel - Boolean : The slcak channel to send the message to
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
- # from - String : Sent from
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 - String : The message to be used
25
- # channel - String : The channel in which to post the message
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-ruby-client'
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', email_to, email_from, from)
42
- send_slack_message(event_message, slack_channel)
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', email_to, email_from, from)
45
- send_slack_message(event_message, slack_channel)
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, from_email, from)
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 += from
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, channel, token = nil)
107
- # https://github.com/slack-ruby/slack-ruby-client - install required
108
- if token.nil?
109
- Slack.configure do |config|
110
- config.token = ENV['SLACK_API_TOKEN']
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)
@@ -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, database, azure)
28
+ def initialize(user, password, host, database, azure, port = nil)
29
29
  # Logging
30
30
  @logger = LoggingClass.new('SQL')
31
31
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiqUtilities
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2-WIP'
5
5
  end
@@ -12,10 +12,12 @@
12
12
  # user - String : The user to connect with
13
13
  # password - String : The users password
14
14
  #
15
- # get_data_center - returns the datacenter based on the connection and datacenter
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(dc, name)
39
+ def find_vm(datacenter, vmname)
38
40
  vm = {}
39
- dc.datastoreFolder.childEntity.collect do |datastore|
40
- vm[:instance] = datastore.vm.find { |x| x.name == 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(vm)
50
- instopts = if vm[:instance][:guest][:guestFamily] == 'windowsGuest'
51
+ def upg_tools(vmobj)
52
+ instopts = if vmobj[:instance][:guest][:guestFamily] == 'windowsGuest'
51
53
  '/s /v "/qn REBOOT=ReallySuppress"'
52
54
  end
53
- vm[:instance].UpgradeTools_Task(installerOptions: instopts).wait_for_completion
55
+ vmobj[:instance].UpgradeTools_Task(installerOptions: instopts).wait_for_completion
54
56
  end
55
57
  end
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "winrm", "~> 2.2"
29
29
  spec.add_development_dependency "rest-client", "~>1.8"
30
30
  spec.add_development_dependency "json", "~> 2.0"
31
+ spec.add_development_dependency "slack-notifier", "~> 2.3"
31
32
  end
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.1
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: '0'
167
+ version: 1.3.1
153
168
  requirements: []
154
169
  rubyforge_project:
155
170
  rubygems_version: 2.7.6