Cross vCenter VM Mobility Fling – macOS?

The VMware Cross vCenter VM Mobility – CLI was recently updated so I decided to try it out. In short, this little Java based application allows you to easily move or clone VMs between disparate vCenter environments.

The Fling is listed with the following requirements:

  • JDK 1.7 or above
  • Two vCenter instances with ESX 6.0
  • Windows : Windows Server 2003 or above
  • Linux : RHEL 7.x or above, Ubuntu 11.04 or above

There is no mention of macOS there, but I decided to give it a go any way, and it turns out that it works just fine on macOS as well!
Just make sure you have the Java JDK installed locally. When I ran it the first time, I got the following error, since the JAVA_HOME environment variable was not set.

~/Downloads/xvc-mobility-cli_1.2$ sh xvc-mobility.sh
set JAVA_HOME to continue the operation

This is very easy to fix, just run the following command in your terminal of choice, and xvc-mobility.sh should work just fine on your Mac.

export JAVA_HOME=$(/usr/libexec/java_home)

Next up is running the fling with the correct parameters (this is a clone operation, not a relocate):

~/Downloads/xvc-mobility-cli_1.2$ sh xvc-mobility.sh -svc [source-vcenter] -su [source-vcenter-username]
-dvc [destination-vcenter] -du [destination-vcenter-username]
-vms [vm-name] -dh [destination-host]
-dds [destination-datastore] -op clone -cln [destination-vm-name]
...
13:41:40.591 [main] INFO com.vmware.sdkclient.vim.Task - CloneVM_Task | State = SUCCESS | Error = null | Result = com.vmware.vc.ManagedObjectReference@d9a221a7
13:41:40.597 [main] INFO com.vmware.sdkclient.vim.Task - Monitor task end
13:41:40.597 [main] INFO com.vmware.sdkclient.vim.Task - CloneVM_Task took : 0:51:33.728
13:41:40.603 [main] INFO c.v.s.helpers.CrossVcProvHelper - Successfully cloned the vm:[destination-vm-name]

I was able to clone a VM from my lab in Bergen to my lab in Oslo, without any problems what-so-ever. Not only is that a Cross vCenter vMotion, but also a Cross Country one, awesome!

Now this is just an example, please check the official documentation for all the parameters, and what the tool expects.

Logging SSH logins to Slack

I’m using Slack to alert and log a few things in my environment, and one of the things I use it for is to alert me if someone logs on via SSH to my public facing Jumphost.

For a good walkthrough on how to set up such a host, check out Tunnel all your remote connections through ssh with a linux jumpbox by Luca Dell’Oca.

My Ubuntu 16.04 Jumphost is set up to only accept Key-Based Authentication, to secure it as much as possible, but I would still like to get instant notification if someone logs into it interactively.

How to set up SSH login notification to Slack.

  1. screenshot-2016-10-06-13-04-51First of all, we need  an Incoming WebHook in Slack in order to receive the notifications.
    You configure those from the Apps & Integration menu item. This in turn opens up the Slack App Directory, find Build on the top right and then choose Make a Custom Integration.
  2. screenshot-2016-10-06-13-08-09One your are in the Build a Custom Integration section, find (or search) Incoming WebHooks and select that.
  3. Next up, define which Slack channel should be the integration point, and click on Add Incoming WebHooks integration.
  4. Copy the Webhook URL presented on the next screen
    Note: keep this one a secret, anyone with access to this URL will be able to post to your Slack channel.
  5. On my Ubuntu 16.04 Linux jumphost I’ve created a small bash script called /etc/ssh/notify.sh. This script utilizes curl  and the WebHook URL to post information directly to Slack. The script looks like this:notify.sh
    #!/bin/sh
    url="https://hooks.slack.com/services/*********"
    channel="#messages"
    host="`hostname`"
    content="\"attachments\": [ { \"mrkdwn_in\": [\"text\", \"fallback\"], \"fallback\": \"SSH login: $USER connected to \`$host\`\", \"text\": \"SSH login to \`$host\`\", \"fields\": [ { \"title\": \"User\", \"value\": \"$USER\", \"short\": true }, { \"title\": \"IP Address\", \"value\": \"$SSH_CLIENT\", \"short\": true } ], \"color\": \"#F35A00\" } ]"
    curl -s -X POST --data-urlencode "payload={\"channel\": \"$channel\", \"mrkdwn\": true, \"username\": \"ssh-bot\", $content, \"icon_emoji\": \":computer:\"}" $url
    /bin/bash

    Replace the  the WebHook URL with your own from step 4 and which channel to post to and you should be ready to go.  This script logs the username and the IP address the connection comes from, and then posts it to the Slack WebHook with the help of curl.Note: I’ve chosen to include the WebHook name etc in the script itself, instead of via the WebHook definition on Slack, mostly since I don’t want to create a WebHook for all hosts I want logging from. With this setup, I can just change the username part of the curl command. It already logs the hostname, so this is pretty much superficial, but hey, that’s how I made it.

  6. chmod +x /etc/ssh/notify.sh to make it executable, and test it. If everything works as expected, you should see an immediate log entry in your chosen Slack channel.
  7. On order to make this script runs every time someone logs into the Jumphost, I added a ForceCommand to the end of my /etc/ssh/sshd_config file, like this:
    ForceCommand /etc/ssh/notify.sh

And that’s it. A login via SSH on the Jumphost now looks like this in my Slack channel:

screenshot-2016-10-06-13-26-10

How awesome is that? Of course, this just scratches the surface of what is possible with Slack’s Incoming WebHooks, I’m using a similar approach for logging new devices discovered in phpmyipam but that’s for another post.

Let’s get the kids some RPi’s!

rpiA friend of Mr. Jase McCarty is teaching a class in programming control systems, and is in need of a few Raspberry Pi’s.

Sadly the school can’t afford buying them outright, so if you have one laying around, that you are not using, get in touch with Jase and he’ll set you up with the details on how you can contribute! If you want to do even better, and buy some RPi’s outright and donate them to the project, check out this Amazon Wishlist!

So far 7 RPi’s have been donated by the vExpert community, which in itself is pure awesome-sauce, but I’m sure we can one up that and make sure each of the students have two RPi’s each.