MiqUtilities

Installation

 $ bundle install 

Usage

require 'miq_utilities'

Dependencies

  1. bundler ~> 1.16
  2. rake ~> 10.0
  3. rbvmomi ~> 1.11.3
  4. tiny_tds ~> 2.1.0
  5. winrm ~> 2.2.3
  6. slack-notifier ~> 2.3.2
  7. rest-client ~> 1.8.0 x64-mingw32
  8. json ~> 2.0.4

Class Summary

Sql Server (SqlClass)

Used to manage Sql Server queries. This Class utilises the tiny_tds Ruby Gem (version => 2.1.0).

Class Method Summary

initialize

Create a connection to the client

Parameters


user ¦ String ¦ Username

password ¦ String ¦ Password

host ¦ String ¦ The host name to connect to

port ¦ String ¦ The port to use (default 1433)

database ¦ String ¦ The database name to connect to

azure ¦ Boolean ¦ Set to true when connecting to Azure

Method usage

“equire ‘miq_utilities’ sql = SqlClass.new(user, pwrd, host, 1433, db, azure)

get_client

Returns the client to utilise the tiny_tds functionality

Method usage

“lient = sql.get_client()

run_sql_query

Runs the specified SQL query against the client the class was instantiated for.

Parameters


sql ¦ String ¦ Sql Query to be run

Method usage

“uery = ‘SELECT * FROM tbl_users’ out = sql.run_sql_query(query) out.each {|user| puts “User Details: #{user}”}

close_connection

closes the connection to the client.

Method usage

“ql.close_connection()

Logging (LoggingClass)

This Class is used to handle the logging for ManageIQ and an IDE.

Class Method Summary

initialize

Instantiate the class using the name of the class/method/instantiator.

Parameters


name ¦ String ¦ The name of the class/method/instantiator

Method usage

“equire ‘miq_utilities’ logger = LoggingClass.new(‘example_method_name’)

log

Log to the $evm object i.e. automation.log.

Parameters


level ¦ String ¦ The level of info/warning/error message ¦ String ¦ The message to write logtoscreenonly ¦ Boolean ¦ Only log to screen notify ¦ Boolean ¦ Process message through the notify process

Method usage

“ogger.log(‘info’,‘This is a test message!’)

“r to process through the Notify class we would use the follwoing:

“ogger.log(‘warn’, ‘This is a warning message’, false, true)

“OTE: When “NOTE” is passed as the level, the notify class turns this into an INFO on-screen message.

VmWare (VmwareClass)

This Class is used to handle some of the heavily used VMWare utilities. This Class utilises the rbvmomi Ruby Gem (version => 1.11.3).

Class Method Summary

initialize

Assign the host name.

Parameters


hostName ¦ String ¦ The name of the host to be used

Method usage

“mware = VmwareClass.new(‘MyHostName’)

get_vsphere_connection

Returns the client connection.

Parameters


user ¦ String ¦ The name of the host to be used password ¦ String ¦ The users password

Method usage

“sphereconn = vmware.get_vsphere_connection(user,pwd)

retrieve_data_centre

Returns the datacentre based on the connection and datacentre name.

Parameters


vsphereconn ¦ object ¦ The return of “get_vsphere_connection” dcname ¦ String ¦ The name of the datacentre

Method usage

“vmdc = vmware.retrieve_data_centre(vsphereconn,‘MyDatacentre’)

Run Powershell (WinrmClass)

This Class is used to run PowerShell scripts. This Class utilises the winrm Ruby Gem (version => 2.2.3).

Class Method Summary

initialize

Run a specified PowerShell script.

Parameters


ps_script ¦ String ¦ The script to run host ¦ String ¦ The name of the host to connect to user ¦ String ¦ The user to connect with password ¦ String ¦ The users password

Method usage

“ Name = ‘Aaron’ ps1 = “C:\Powershell\RunHelloWorld.ps1 -name #Name” winrm_run(ps1,host,user,pwrd)

Notification (NotificationClass)

This Class is used to notify users and log messages accordingly. This Class utilises the slack-notifier Ruby Gem (version => 2.3.2).

Class Method Summary

notify

Initiate the process.

Parameters


event_level ¦ String ¦ info, warn, error event_message ¦ String ¦ The message to be used email_to ¦ String ¦ Who to send an email to email_from ¦ String ¦ Sent from which email address signature ¦ String ¦ Who the emails from webhookURL ¦ String ¦ The webhook to be used

Method usage

“ require ‘miq_utilities’ logger = LoggingClass.new(‘Test NotificationCLass’) logger.log(‘error’, ‘An error occured!’, false, true)

Levels (event_level)

Level
INFO
WARN
ERROR
NOTE

send_email

Sends an email to the specified user using the $evm.execute MIQ method

Parameters


message ¦ String ¦ The message to be used subject ¦ String ¦ The Subject to be used to_email ¦ String ¦ Recipient email from_email ¦ String ¦ Sender email signature ¦ String ¦ Who the emails from

Method usage

“slt require ‘miq_utilities’ notify = NotificationCLass.new notify.send_email(‘This is an Email.’, ‘Test’, ‘[email protected]’, ‘[email protected]’, ‘DevOps’)

send_slack_message

Sends a Slcak message

Parameters


message ¦ String ¦ The message to be used webhookURL ¦ String ¦ The webhook to be used

Method usage

“slt require ‘miq_utilities’ notify = NotificationCLass.new notify.send_slack_message(‘This a Slack post!’, ‘https://hooks.slack.com/services/token’)

on_screen_message

onscreen_message - Sends an on-screen notification_

Parameters


level ¦ String v info, warn, error message ¦ String ¦ The message to be used subject ¦ String ¦ The Subject to be used

Method usage

“slt require ‘miq_utilities’ notify = NotificationCLass.new notify.on_screen_message(‘info’, ‘This is an on-screen notification’, ‘Test’)