Category Archives: Uncategorized

Accessing the Rubrik API with C# .NET using RestSharp (part 1)

As I described in a previous post, at my job we recently migrated our VM backups to Rubrik. This has been extremely successful, but it broke our previous backup monitoring application, an ASP.NET web app I developed to monitor backup jobs from our previous backup application, VRanger. This web app queried the VRanger MSSQL database directly to pull job status data, and so it was a pretty simple app. Pull data from one database, insert data into another database. No biggie. But we just replaced our backup solution with Rubrik, which is an all-in-one appliance that does not have an easily-accessible SQL database to query. What it does have, however, is a REST API.

    REST API and Swagger

Rubrik, just like Nutanix, has a pretty full-featured REST API for performing operations from other applications. Chris Wahl of Rubrik has written a couple of blog posts and given some talks about using this API in vRealize Orchestrator, and has provided some sample code in PowerShell, but so far the example code out there is pretty scant, and since what I want to do right now isn’t in vRO or PowerShell, there wasn’t any good examples to work off of. So I had to figure it out myself. Hopefully this info will be helpful to someone else.

First of all, the most useful resource for the Rubrik API is the built-in API documentation. You can access it at

https://[Rubrik URL]/swagger-ui


This documentation is invaluable for learning what functions are available, what arguments they expect, and what data they return.


I am most familiar with writing code in .NET using C#, so I started looking for libraries meant to access REST services. I quickly came upon RestSharp, which is available to install via NuGet within Visual Studio. RestSharp has a nice feature that it handles serializing and deserializing data in XML and JSON formats, which comes very handy for interacting with Rubrik. Rubrik data is passed in JSON format, and not having to worry about the conversion is pretty nice.

    Accessing Rubrik API with RestSharp

Before you can do anything else in the Rubrik API, you need to log in. You need to pass the login credentials in the body of the login request, and if successful it returns a JSON object that contains a token that needs to be passed to all subsequent API requests. Here is how I made it work:

public class LoginCreds
  public string userId { get; set; }
  public string password { get; set; }

public class LoginData
  public string status { get; set; }
  public string description { get; set; }
  public string userId { get; set; }
  public string token { get; set; }

private string Login(LoginCreds MyLogin)
  var client = new RestClient();
  client.BaseUrl = new Uri("https://[Rubrik URL]");
  var request = new RestRequest(Method.POST);

  request.RequestFormat = DataFormat.Json;
  request.Resource = "login";


  var response = client.Execute(request);
  return response.Data.token;

The Login function should return the login token, which will be reused on all subsequent API calls.

One important note is that in the client.Execute() call, you specify a data type for the RestSharp library to de-serialize the return JSON data into. Then response.Data is an object in the format you specify, in this case LoginData. For API calls that return a collection of objects, you can specify the return type as a List<>, as you will see in the next example.

Note that I’m not including any exception handling in these examples. You will definitely want to enclose in a Try{} at least the client.Execute statement and any places where you reference response.Data.

public class VM
  public string id { get; set; }
  public string managedId { get; set; }
  public string moid { get; set; }
  public string name { get; set;
  public string vCenterId { get; set; }
  public string hostName { get; set; }
  public string hostId { get; set; }
  public string clusterName { get; set; }
  public string powerStatus { get; set; }
  public string configuredSlaDomainId { get; set; }
  public string configuredSlaDomainName { get; set; }
  public string effectiveSlaDomainId { get; set; }
  public string effectiveSlaDomainName { get; set; }
  public string effectiveSlaSourceManagedId { get; set; }
  public DateTime protectionDate { get; set; }
  public string ipAddress { get; set; }
  public string toolsInstalled { get; set; }
  public string snapshotCount { get; set; }
  public string primaryClusterUuid { get; set; }
  public string isReplicationEnabled { get; set; }
  public string isArchived { get; set; }

private void GetVMs(string token)
  var client = new RestClient();
  client.BaseUrl = new Uri("https://[Rubrik URL]");
  var request = new RestRequest(Method.GET);
  request.RequestFormat = DataFormat.Json;
  request.Resource = "vm";
  string authtoken = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(token + ":"));
  request.AddHeader("Authorization", "Basic " + authtoken);
  var response = client.Execute>(request);
  if (response.ResponseStatus == ResponseStatus.Error)
    txtOutput.Text += "VM Count = " + response.Data.Count + Environment.NewLine;
    foreach (VM theVM in response.Data)
      txtOutput.Text += + " - " + theVM.configuredSlaDomainName + Environment.NewLine;

That covers it for now. I was pretty excited when I got that much working. I haven’t actually written anything that actually does anything with this API yet, but having got this far, the rest should be cake. I will show what else I actually do with the Rubrik API in the next post.

Currently drinking: Sierra Nevada Northern Hemisphere Harvest Wet Hop IPA

1 Comment

Filed under Uncategorized

Our transition to Rubrik backups


At my day job a few years ago, I wrote a web app to help with monitoring the backup jobs for our VM environment. We used a tool called VRanger (by Quest Software, previously Dell Software, previously Quest Software) to do all our VMware backups. For those unfamiliar, VRanger is pretty similar in concept to Veeam, as a dedicated vSphere backup solution. It worked pretty well for us, but one of the major shortfalls was that when scheduled backups failed for whatever reason, there wasn’t good record-keeping to let us know.

VM backup jobs would fail fairly frequently, but we only backed up each VM once per day and most of the time the change rate wasn’t very high, so if a VM didn’t get backed up for a day, it wasn’t that big of a deal. If the job failed a couple times in a row though, that was a big deal, and VRanger didn’t have a way to alert on that. So I wrote an application to keep track of it.

VRanger kept all of its data in a MSSQL database, and so it was pretty easy to query the database and get the job data, and from that render a pretty web page with the relevant data and send an alert when a VM had gone for a few cycles without successfully backing up. Piece of cake.

The problem was, VRanger kinda sucks, and we were about to get a much better VM backup solution (that’s a problem?)

    Enter Rubrik

Let’s get this out of the way right now. Rubrik is F@$kin’ sweet.

By this point we were about 85% virtual, so VM backups were really important, and physical backups were less so. We needed a new backup solution, as we had well outgrown our existing VRanger/DataDomain system, and needed something new. We checked out several solutions, including Avamar, which was frankly funny. EMC wanted to sell us their entire software suite and a half rack of DataDomain, some Isilon, and a bunch of other shit.

Then there was this new player called Rubrik. They have an appliance with a stack of disks in it, that talks to vCenter, and just handles backups. We got their SE to bring a POC box in, and within 10 minutes we had it configured, talking to vCenter, and had set up a backup job on a VM. The SE then walked us through doing a live mount of the VM we just backed up in vCenter, which took that backup, registered it as a new VM in vCenter, and powered it on, all with the storage running off of Rubrik box. The Rubrik registers itself with vCenter as an NFS datastore. From start to running VM, maybe 2 minutes tops. And then if I want to restore that new VM permanently, it’s just a storage vMotion from the Rubrik to permanent storage. So slick.

    Sorry EMC

So yea, we bought Rubrik. There’s a bunch of other reasons why we decided on it versus the other choices, but simplicity was the main theme. From creating backup SLAs, to setting up notifications, to restores, to spinning up temporary environments, Rubrik won on ease of use. Of course, migrating to Rubrik sorta broke my VM backup monitoring application, but that’s a different post.

P.S. If you want to annoy a long-time Rubrik employee, ask them about the adhesive on their bezels. Much fun to be had.

Currently drinking: Sierra Nevada Northern Hemisphere Harvest Wet Hop IPA

Leave a Comment

Filed under Uncategorized

Apparently I live in the sticks.

I took this picture in my neighborhood leaving home for work one morning.  Apparently I live in the sticks.  Yes, that is a turkey.  I see deer sometimes too.

A wild turkey.  Just hanging out in my neighborhood.  Apparently I live in the sticks.

A wild turkey. Just hanging out in my neighborhood. Apparently I live in the sticks.


Currently drinking: Terrapin Golden Ale

Leave a Comment

Filed under Uncategorized

Welcome to my blog!

Well, it’s about time that I get this thing started, eh?

You can read a bunch about me on the About Me page on here, so I’m not going to repeat myself too much.  I decided to start this blog because as a network engineer in a shop that really should have a much bigger IT staff than we do, I run into entirely too much odd stuff, and I feel that it would be a shame to not record it so that future admins and engineers can maybe learn something, or at least get a laugh.  Probably at my expense.  There is a permanent forehead-shaped indentation in the wall next to my desk.

That said, I don’t want to limit this blog to just IT.  I am a big fan of beer and other adult beverages, and every once in a while I find something that I want to share my thoughts about.  In fact, the thing that actually catalyzed this blog and made me get off my ass to make it was a beer discovery.  So that’s something I will talk about some.  That catalyzing post will be coming really soon.  It will even have a couple pictures in it!

I also plan on writing some things just because I want to.  Not IT-related, not beer-related, just Me-related.  For example, I’m rather a fan of SpaceX, and the recent Falcon 9 launch failure was pretty heartbreaking, so I might write something about that.  I’m not an aerospace guy though, so there’s no danger that this blog will go full-time space-cadet.  It’s just something I like that I may write something about.  If these side topics don’t interest you, don’t worry.  I’ll try to tag the topic-relevent posts, so you can filter out the random thoughts if you just want to get to the tech or the beer.

Anyway, enough of an introduction.  I’ve got a half a bottle of rum and a six-pack of IBC root beer, and I feel like writing.  Let’s do this!


currently drinking: Cruzan rum and IBC root beer

Leave a Comment

Filed under Uncategorized