Thursday, June 27, 2013

A practical use for Raspberry Pi

There are hundreds of Raspberry Pi projects online, each one interesting. I purchased my rpi a while ago in hopes it would replace my bedroom HTPC...unfortunately they're just not great at handling large media libraries. I did however find a very practical use for it when preparing for a family holiday.

We had rented an apartment at Noosa for the week and I knew whilst the accommodation was very nice, they only offered basic pay-tv. So I installed the latest openelec image using this guide:

http://squirrelhosting.co.uk/hosting-blog/hosting-blog-info.php?id=9

I took the rpi and a spare external HDD with me loaded up with must watch holiday movies. For anyone interested the reason I chose openelec over raspbmc was because I tested both quite thoroughly and OpenElec dealt with displaying thumbnails much better (smoother) than raspbmc in XBMC's default confluence interface.

When we booked I asked what type of TVs they have in the living/bedroom and was delighted to find out they were relatively new Samsung models so the CEC function worked great. So I didn't even need to take a remote with me!

Here's what it looked like:



Australian Radio Plugins for XBMC

My wife was using the ABC website to listen to Triple J on our HTPC. I did a little research and realised writing a plugin to do this within XBMC was pretty straight forward. While I was at it I wrote one to listen to RRR too.

EDIT: I've just created and uploaded a plugin for Double J. Thanks everyone for the feedback and suggestions.

Double J Plugin - Download here
Triple J Plugin - Download here
RRR Plugin - Download here


As Zan has written in the comments section,  to add these plugins to the home screen (as displayed below) perform the following:

System -> Settings
Appearance -> Skin Settings
Add-on Shortcuts
Home Page Music Submenu
Addon 1 Triple J
Addon 2 Three Triple R


It looks like this:



Scripting LUN path count and device info

During a recent project I cut hundreds of LUNs to present to a few Solaris 10 servers. I wanted a way to check the total number of LUNs for each server, and that each LUN was properly dual pathed. To do this, I wrote the following shell script. It will list out the LUN device path and number of paths, comma seperated, and the total number of LUNs at the end.

Remember if you're running this on a machine which has hundreds of LUNs presented to it, you're best directing the output to a file to prevent the screen buffer refresh slowing down the return rate of your results.

#!/bin/ksh

a=0
print "Device_Path,Path_Count"

# probe for LUNS
luxadm probe|grep Logical|
while
     read CRAP DEV_PATH
do

     # increment LUN count
     let a+=1

     # print device path
     print -n "${DEV_PATH:##Path:},"

     # check we have dual paths on each LUN
     pathCount=`luxadm display ${DEV_PATH:##Path:}|grep State|wc -l|tr -d ' '`

     if [ $pathCount -lt 2 ]; then
          errorMessage=" - WARNING: LUN does not contain redundant path"
     fi

     # check for path status other than online
     offlinePath=`luxadm display ${DEV_PATH:##Path:}|grep State|grep -v ONLINE`

     if [ -z $offlinePath ]; then
          offlinePath=""
     else
           errorMessage="$errorMessage - WARNING: 1 or more paths detected as NOT ONLINE"
     fi

     # print number of paths and path error if an offline path was found
     print "$pathCount $errorMessage"

done

# print number of LUNS discovered
echo "$a LUNS presented."

Monitoring Solaris zpools with HP OMW


Recently, we've had a few degraded zpools go unnoticed. They went unnoticed because our HP agents weren't monitoring their state (seems fair enough). After having a poke around what logs were available natively (not much) I broached the subject with our Tools Admin. He's always happy to help, so we knocked up the following perl script that gets executed every 15 minutes and reports in the event a zpool is in any state other than ONLINE.

use strict;

sub get_zp_list {
     my $pool_names = `zpool list -H -o name`;
     if ($pool_names eq "no pools available\n") {
          return $pool_names;
     }
     my @pool_names = split("\n",$pool_names);
     return @pool_names;
}

sub get_zp_health {
     my $pool_name = shift;
     my $result = `zpool list -H -o health $pool_name`;
     chomp $result;
     return $result;
}


#START PROCESS>>>

if ( ! -f "/sbin/zpool") {
     $ConsoleMessage->Severity("Minor");
     $ConsoleMessage->Application("zfspool");
     $ConsoleMessage->MsgText("zpools not supported in this sun release");
     $ConsoleMessage->Send();
     exit 1;
}

zpcheck();

sub zpcheck {
     my @zpools = get_zp_list();
     if ($zpools[0] eq "no pools available\n") {
          $ConsoleMessage->Severity("Minor");
          $ConsoleMessage->Application("zfspool");
          $ConsoleMessage->MsgText("no pools defined!");
          $ConsoleMessage->Send();
          return 0;
     }

     foreach my $pool (@zpools) {
          my $health = get_zp_health($pool);
          if ( $health eq "ONLINE" ) {
               # do nothing
          } else {
               $health = "unknown" if (!$health);
               # alarm in HP OMW
               $ConsoleMessage->Severity("Major");
               $ConsoleMessage->Application("zfspool");
               $ConsoleMessage->Object("$pool");
               $ConsoleMessage->MsgText("DNP- Problem with zpool $pool detected, status is $health");
               $ConsoleMessage->Send();
          }
     }
}

Launch SSH connections like RDP

I'm a sysadmin for a living, primarily dealing with UNIX and Windows servers.  Seeing as there's an everyday requirement to cross between these two platforms I've tried many solutions to better manage the connection process. I don't like any of them, and I'd much prefer to just launch a connection to a server when needed, do what's required, then exit.

To achieve this I'll use mstsc /v server_name to connect via RDP to a Windows Server, or Putty to connect to a UNIX or Linux server. Establishing Putty connections take too long so I sought for a shortcut similar to mstsc from the run dialog box, here's a quick and easy solution:

1) Modify your PATH variable
* Right click Computer and select Properties
* Select Advanced System Settings on the left pane
* Click the Advanced tab
* Click Environment Variables
* Select Path from System  Variables and click Edit
* At the end of the Variable value field add ;Your_Path_To_Putty
* Click OK and close the system properties window

2) Add a putty shortcut
* Browse to your putty path
* Right Click > New > Shortcut
* Enter the path to putty followed by -ssh (eg. C:\Putty\putty.exe -ssh)
* Click Next
* Enter a shortcut name of ssh and click Finish
* Right click your new shortcut and select Properties
* Select the Shortcut tab
* Change the Run dropdown box to reflect Maximized

Now bring up the run dialog box and type ssh server_name. If you followed along, Windows should launch a putty SSH session to your server.