Bringing HBA SAN and LUNs together with .Net

by Jesse 11. March 2009 11:33

After writing my last post on tracing the two items together, the magical lazy comment came about to -- there has to be a better way.  Of course there is, no one in their right mind would even THINK to do this by hand time and time again.  So I went hunting for a way to pull this info into something useful, like an application of some kind.  Sure enough, there is an API out there for SSH for .net called SharpSSH and it works, with a bit of thinking.

I approached this problem with the idea being simple - if I can get the result from a console into a string, I can do whatever I want with it from there.  One of the commands does exactly that -- SshExec.RunCommand(string).  Thanks to my documentation blog post, I know everything I need to do, now to work the string values when they come back.

One of the commands I use quite frequently is more.  So my first attempts with SharpSSH was to use more because it was a sure fire way to get everything, except for one problem.  If you've ever used more at least twice, there's a condition that exists when a screen is smaller than the requested information, "pages" are created so you can read parts at a time.  This poses a serious issue since using this method, I can't control this.  I COULD have executed a space command if it held out longer than, say 5 seconds but that seemed a bit cumbersome for what I wanted.  After all, most of what I need is within 100 lines or so.  Knowing this, I decided to go with tail -1000.

First, you have to create a connection and authenticate.  SharpSSH makes this rather simple by doing the following...

SshExec exec = new SshExec(server, user, pass);
exec.Connect();
if (exec.Connected)
{ }

So far, stupid easy.  Next, you do the exec.RunCommand(string) as such...

string scsiInfo = exec.RunCommand(@"tail -1000 " + procScsiLocation);

if
(string.IsNullOrEmpty(scsiInfo))
{ }

Here, I simply ask for the /proc/scsi/<adapter> info.  Since I'm working with servers that are all the same, I made these static but this could be pulled back with a simple ls on /proc/scsi/ command and a selection could be made, probably with radio buttons.  The result of this can be ugly, but each line is terminated with a \n which makes it very predictable and easily split into a list of strings (my favorite).

List<string> scsiInfoList = new List<string>(Regex.Split(scsiInfo, "\n"));

I used Regex.Split instead of String.Split strictly based on personal preference.  With this newly created list, I can create test conditions that filter out the junk I don't want and append to a string builder what I DO what.  Feeding the result into a simple multiline textbox makes this easy to read.  From there, you can do just about everything you need to do.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Comments

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Like the description says, at my core, I'm a scientist and engineer.  I came from humble beginnings on a 486DX2 Packard Hell playing doom2 on IPX to in a small time retail shop and got into hardware (ISO layers FTW!) and it was all downhill from there.  I'm infinitely curious about almost everything and always wanting to know.

According to personality tests (real ones) I classify under "Rational" more specifically, a Fieldmarshal.  I think there's something to that.

Some of the stuff I'm currently into/researching...

Sitefinity

Ninject

Subsonic 

Currently working on ...
i did the hundred


and some extra stuff

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's, their brother, their dog, cat, ferret nor gold fish's view in anyway.  At all.  Ever.

© Copyright 2007-2009