miq_utilities 0.2.2.pre.WIP → 0.2.2

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
  SHA256:
3
- metadata.gz: 2d184df965af6a4f25ce41107b533b610e98943acabbd7eb1b4f32950132d69c
4
- data.tar.gz: 11a0ac88b95da23a66e840535b77b89e4c0a115504befb5d5a2470ab1622de2d
3
+ metadata.gz: b2b19bb0fcf6f8850ddd88cb84f111b7f638b2b2caa8947d2dbd8ca0d0ea4384
4
+ data.tar.gz: 0ca998eb10a330141f7b21d50d9310276c7b002d6fc2f5fe9961577406620502
5
5
  SHA512:
6
- metadata.gz: b2e790149e8b0acafee2a5ea18b8ef7cea2e207cb7d9b6c3de30e24c95e0b5192dd666a6455dbe5c6dc1de4c4ad46974b783c60ba7fbb61e85a595e7cda65aef
7
- data.tar.gz: be9bd063f97a37796fd79b542fec1ba297e8629f29efdaa96411725e1f40139d8a6ac0bfedef0965c71cf75ec2fc620e1ab9736b453e429def5c2347988958a3
6
+ metadata.gz: a1a4dafef4451c2224f9645abfb58064cf6a825449ef45f218c0806de8707bc3e41f7d4f29646b70f6324db73f05be12f22d0d78f7745217fc191ec6b7bb1eea
7
+ data.tar.gz: e5a4b01286f9d45a6e6b8bba0c26ea9d4abe1984a98170d247a39146678135cb8202b9e97f0907afbc7710649b2b1f2ba07ba5d22775211f8a63445bd4bdfd09
data/.gitignore CHANGED
@@ -1,21 +1,10 @@
1
1
  /.bundle/
2
- .bundle
3
2
  /.yardoc
4
3
  /_yardoc/
5
- .yardoc
6
4
  /coverage/
7
5
  /doc/
8
6
  /pkg/
9
7
  /spec/reports/
10
8
  /tmp/
11
- .config
12
9
  *.iml
13
10
  .idea
14
- .idea
15
- .idea/*
16
- */.idea
17
- */.idea/*
18
- **/.idea
19
- **/.idea/*
20
- $evm
21
-
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-notifier'
7
+ gem 'slack-ruby-client'
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,27 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- miq_utilities (0.2.2.pre.WIP)
4
+ miq_utilities (0.2.1)
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)
9
14
  builder (3.2.3)
15
+ concurrent-ruby (1.0.5)
10
16
  domain_name (0.5.20180417)
11
17
  unf (>= 0.0.5, < 1.0.0)
12
18
  erubis (2.7.0)
13
19
  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)
14
24
  faye-websocket (0.10.7)
15
25
  eventmachine (>= 0.12.0)
16
26
  websocket-driver (>= 0.5.1)
17
27
  ffi (1.9.23-x64-mingw32)
28
+ gli (2.17.1)
18
29
  gssapi (1.2.0)
19
30
  ffi (>= 1.0.1)
20
31
  gyoku (1.3.1)
21
32
  builder (>= 2.1.2)
33
+ hashie (3.5.7)
22
34
  http-cookie (1.0.3)
23
35
  domain_name (~> 0.5)
24
36
  httpclient (2.8.3)
37
+ i18n (1.0.1)
38
+ concurrent-ruby (~> 1.0)
25
39
  json (2.1.0)
26
40
  little-plugger (1.1.4)
27
41
  logging (2.2.2)
@@ -31,7 +45,9 @@ GEM
31
45
  mime-types-data (~> 3.2015)
32
46
  mime-types-data (3.2016.0521)
33
47
  mini_portile2 (2.3.0)
48
+ minitest (5.11.3)
34
49
  multi_json (1.13.1)
50
+ multipart-post (2.0.0)
35
51
  netrc (0.11.0)
36
52
  nokogiri (1.8.2-x64-mingw32)
37
53
  mini_portile2 (~> 2.3.0)
@@ -48,9 +64,18 @@ GEM
48
64
  mime-types (>= 1.16, < 4.0)
49
65
  netrc (~> 0.8)
50
66
  rubyntlm (0.6.2)
51
- slack-notifier (2.3.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)
52
75
  tiny_tds (2.1.1-x64-mingw32)
53
76
  trollop (2.1.2)
77
+ tzinfo (1.2.5)
78
+ thread_safe (~> 0.1)
54
79
  unf (0.1.4)
55
80
  unf_ext
56
81
  unf_ext (0.0.7.5-x64-mingw32)
@@ -79,7 +104,7 @@ DEPENDENCIES
79
104
  rake (~> 10.0)
80
105
  rbvmomi
81
106
  rest-client
82
- slack-notifier
107
+ slack-ruby-client
83
108
  tiny_tds
84
109
  winrm
85
110
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Installation
4
4
 
5
- $ bundle install
5
+ $ gem install miq_utilities
6
6
 
7
7
  ## Usage
8
8
 
@@ -15,7 +15,7 @@
15
15
  3. rbvmomi ~> 1.11.3
16
16
  4. tiny_tds ~> 2.1.0
17
17
  5. winrm ~> 2.2.3
18
- 6. slack-notifier ~> 2.3.2
18
+ 6. slack-ruby-client ~> 0.11.1
19
19
  7. rest-client ~> 1.8.0 x64-mingw32
20
20
  8. json ~> 2.0.4
21
21
 
@@ -214,7 +214,7 @@ password ¦ String ¦ The users password
214
214
 
215
215
  ## Notification (NotificationClass)
216
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).
217
+ This Class is used to notify users and log messages accordingly. This Class utilises the `slack-ruby-client` Ruby Gem (version => 0.11.1).
218
218
 
219
219
  ### Class Method Summary
220
220
 
@@ -229,8 +229,8 @@ event_level ¦ String ¦ info, warn, error
229
229
  event_message ¦ String ¦ The message to be used
230
230
  email_to ¦ String ¦ Who to send an email to
231
231
  email_from ¦ String ¦ Sent from which email address
232
- signature ¦ String ¦ Who the emails from
233
- webhookURL ¦ String ¦ The webhook to be used
232
+ from ¦ String ¦ From who
233
+ slack_channel ¦ Boolean ¦ The slcak channel to send the message to
234
234
  ```
235
235
 
236
236
  ##### Method usage
@@ -240,7 +240,7 @@ webhookURL ¦ String ¦ The webhook to be used
240
240
  logger.log('error', 'An error occured!', false, true)
241
241
  ```
242
242
 
243
- #### Levels (event_level)
243
+ #### Levels
244
244
  ```
245
245
  Level | Action
246
246
  ----------------------------------------------------------------------------------------------
@@ -260,7 +260,7 @@ message ¦ String ¦ The message to be used
260
260
  subject ¦ String ¦ The Subject to be used
261
261
  to_email ¦ String ¦ Recipient email
262
262
  from_email ¦ String ¦ Sender email
263
- signature ¦ String ¦ Who the emails from
263
+ from ¦ String ¦ Sent from
264
264
  ```
265
265
  ##### Method usage
266
266
 
@@ -275,10 +275,11 @@ signature ¦ String ¦ Who the emails from
275
275
  _Sends a Slcak message_
276
276
  ##### Parameters
277
277
  ```
278
- Name | Type | Description
278
+ Name | Type | Description
279
279
  --------------------------------------------------------------
280
- message ¦ String ¦ The message to be used
281
- webhookURL ¦ String ¦ The webhook to be used
280
+ message ¦ String ¦ The message to be used
281
+ channel ¦ String ¦ The channel in which to post the message
282
+ token ¦ String ¦ The API token used to authenticate
282
283
  ```
283
284
 
284
285
  ##### Method usage
@@ -286,7 +287,7 @@ webhookURL ¦ String ¦ The webhook to be used
286
287
  ```$xslt
287
288
  require 'miq_utilities'
288
289
  notify = NotificationCLass.new
289
- notify.send_slack_message('This a Slack post!', 'https://hooks.slack.com/services/token')
290
+ notify.send_slack_message('This a Slack post!', '#MIQ-CHANNEL', 'token-to-use')
290
291
  ```
291
292
 
292
293
  #### **on_screen_message**
@@ -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-notifier Ruby Gem (version => 2.3.2).
4
+ # This Class utilises the slack-ruby-client Ruby Gem (version => 0.11.1).
5
5
  #
6
6
  # Methods Summary:
7
7
  # > Name > Description/Params
@@ -10,37 +10,39 @@
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
- # signature - String : Who the emails from
14
- # webhookurl - String : The slcak channel to send the message to
13
+ # from - String : From who
14
+ # slack_channel - Boolean : 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
- # from_email - String : Sender email
20
- # signature - String : Who the emails from
21
19
  # to_email - String : Recipient email
20
+ # from_email - String : Sender email
21
+ # from - String : Sent from
22
22
  #
23
23
  # send_slack_message - Sends a Slcak message
24
- # message - String : The message to be used
25
- # webhookurl - String : The webhook to be used
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
26
27
  #
27
28
  # on_screen_message - Sends an on-screen notification
28
29
  # level - String : info, warn, error
29
30
  # message - String : The message to be used
30
31
  # subject - String : The Subject to be used
31
32
  # WIP
32
- require 'slack-notifier'
33
+ require 'slack-ruby-client'
33
34
 
34
35
  # notification class
35
36
  class NotificationClass
36
- def notify(event_level, event_message, email_to = nil, email_from = nil, signature = nil, webhookurl = nil)
37
+
38
+ def notify(event_level, event_message, email_to = nil, email_from = nil, from = nil, slack_channel = nil)
37
39
  case event_level.upcase
38
40
  when %w[WARN WARNING]
39
- send_email(event_message, 'Warning Identified', email_from, signature, email_to)
40
- send_slack_message(event_message, webhookurl)
41
+ send_email(event_message, 'Warning Identified', email_to, email_from, from)
42
+ send_slack_message(event_message, slack_channel)
41
43
  when %w[ERR ERROR]
42
- send_email(event_message, 'Error Identified', email_from, signature, email_to)
43
- send_slack_message(event_message, webhookurl)
44
+ send_email(event_message, 'Error Identified', email_to, email_from, from)
45
+ send_slack_message(event_message, slack_channel)
44
46
  on_screen_message(event_level, event_message)
45
47
  when 'NOTE'
46
48
  on_screen_message(event_level, event_message)
@@ -49,7 +51,7 @@ class NotificationClass
49
51
  raise("Oopps! Something went wrong trying to notify. Error:<#{err}>")
50
52
  end
51
53
 
52
- def send_email(message, subject, from_email, signature, to_email = nil)
54
+ def send_email(message, subject, to_email = nil, from_email, from)
53
55
  # Look in the current object for a VM
54
56
  vm = $evm.object['vm']
55
57
  if vm.nil?
@@ -93,7 +95,7 @@ class NotificationClass
93
95
  body = 'Hello, '
94
96
  body += message
95
97
  body += 'Thank you,'
96
- body += signature
98
+ body += from
97
99
 
98
100
  $evm.execute(:send_email, to, from_email, subject, body)
99
101
  rescue => err
@@ -101,11 +103,24 @@ class NotificationClass
101
103
  end
102
104
 
103
105
  # TBD - awaiting webhook setup
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}>")
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
109
124
  end
110
125
 
111
126
  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
12
13
  # database - String : The database name to connect to
13
14
  # 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, database, azure, port = nil)
28
+ def initialize(user, password, host, port = nil, database, azure)
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.2-WIP'
4
+ VERSION = '0.2.2'
5
5
  end
@@ -12,12 +12,10 @@
12
12
  # user - String : The user to connect with
13
13
  # password - String : The users password
14
14
  #
15
- # retrieve_data_center - returns the datacenter based on the connection and datacenter
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
16
18
  #
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
21
19
  require 'rbvmomi'
22
20
 
23
21
  # vmware wrapper class
@@ -36,10 +34,10 @@ class VmwareClass
36
34
  raise("No connection established!\nUse the \"get_vsphere_connection\" method to connect.") if @connection.nil?
37
35
  end
38
36
 
39
- def find_vm(datacenter, vmname)
37
+ def find_vm(dc, name)
40
38
  vm = {}
41
- datacenter.datastoreFolder.childEntity.collect do |datastore|
42
- vm[:instance] = datastore.vm.find { |x| x.name == vmname }
39
+ dc.datastoreFolder.childEntity.collect do |datastore|
40
+ vm[:instance] = datastore.vm.find { |x| x.name == name }
43
41
  if vm[:instance]
44
42
  vm[:datastore] = datastore.name
45
43
  break
@@ -48,10 +46,10 @@ class VmwareClass
48
46
  vm
49
47
  end
50
48
 
51
- def upg_tools(vmobj)
52
- instopts = if vmobj[:instance][:guest][:guestFamily] == 'windowsGuest'
49
+ def upg_tools(vm)
50
+ instopts = if vm[:instance][:guest][:guestFamily] == 'windowsGuest'
53
51
  '/s /v "/qn REBOOT=ReallySuppress"'
54
52
  end
55
- vmobj[:instance].UpgradeTools_Task(installerOptions: instopts).wait_for_completion
53
+ vm[:instance].UpgradeTools_Task(installerOptions: instopts).wait_for_completion
56
54
  end
57
55
  end
data/lib/miq_utilities.rb CHANGED
@@ -1,6 +1,4 @@
1
- # frozen_string_literal: true
2
1
 
3
- # Module to include resources
4
2
  module MiqUtilities
5
3
  require_relative 'miq_utilities/version'
6
4
  require_relative 'miq_utilities/infoblox.rb'
@@ -28,5 +28,4 @@ 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"
32
31
  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.2.pre.WIP
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron McCatty
@@ -108,20 +108,6 @@ 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'
125
111
  description: " This Gem was written to hold utilities commonly used within ManageIQ/Cloudforms. "
126
112
  email:
127
113
  - aaronmccatty@hotmail.co.uk
@@ -130,7 +116,6 @@ extensions: []
130
116
  extra_rdoc_files: []
131
117
  files:
132
118
  - ".gitignore"
133
- - ".rubocop.yml"
134
119
  - Gemfile
135
120
  - Gemfile.lock
136
121
  - LICENSE.txt
@@ -162,9 +147,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
147
  version: '0'
163
148
  required_rubygems_version: !ruby/object:Gem::Requirement
164
149
  requirements:
165
- - - ">"
150
+ - - ">="
166
151
  - !ruby/object:Gem::Version
167
- version: 1.3.1
152
+ version: '0'
168
153
  requirements: []
169
154
  rubyforge_project:
170
155
  rubygems_version: 2.7.6
data/.rubocop.yml DELETED
@@ -1,29 +0,0 @@
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