Monitoring HP Raid Array on Ubuntu Server

I wanted to monitor our HP server raid array on Ubuntu 12.04.  I  am sure that there is a good way of setting this up with Nagios or SMNP – however, I thought I would write a little bash script which emails me if any of the hard drives in the raid array fail.  I assume that you have already installed the HP Proliant Support Pack perhaps using these instructions.

To send an email from command line you will also need mailx.  This is a virtual package on Ubuntu and I tend to install bsd-mailx.  To install it run:

sudo apt-get install bsd-mailx

It will also install Postfix (if this isn’t already setup).  When configuring Postfix, I selected “Internet Site” and entered the hostname of the server.

Here is the bash script that I wrote.  The indentation seems to have got lost but you should be able to recreate it.

#!/bin/bash

# Email settings
email_recipient=”your.email@somewhere.com”

# Current datetime in YYYY-MM-DD_HH-MM-SS
date=`date +”%Y-%m-%d_%H-%M-%S”`

# Make sure the log directory exists.
/bin/mkdir -p /root/harddrive_check/log

log_filename=”/root/harddrive_check/log/$date.log”

hostname=`hostname`

if hpacucli ctrl all show config | grep -q “Failed”; then

echo -e “Harddrive Check Run: `date`” > $log_filename

echo -e “\nUsing Command: hpacucli ctrl all show config” >> $log_filename

hpacucli ctrl all show config >> $log_filename

email_subject=”Harddrive Failed On $hostname”

/usr/bin/mailx -s “$email_subject” “$email_recipient” < $log_filename

fi

I then setup a cronjob on the server.

crontab -e

Adding the line:

0 * * * * /root/harddrive_check.sh

I hope this is helpful to someone.  Let me know if you know a better way of doing this. Thanks for reading.

How to install imapsync on Ubuntu 12.04

Imapsync is a really useful script from syncing imap mail boxes.  I used it when migrating from Zimbra to Google Mail.  I wanted to install imapsync from source on my Ubuntu server but found the instructions a little ridiculous.  The start of the instructions are:

Go into the directory imapsync-x.xx and read the INSTALL file.
You’re already reading the INSTALL file.

Here is what I did it:

1) Download the source from github and extract it.

2) Install a few dependences:

aptitude install libmail-imapclient-perl libdigest-md5-file-perl libterm-readkey-perl libio-socket-ssl-perl libdigest-hmac-perl makepasswd

3) In the source folder run:

make -n install

make install

You should then have a working imapsync.  To test it try:

imapsync -version

Boot partition full of old kernels

I started getting an error message every time I booted into Ubuntu.  “‘The volume “boot” has only ….. bytes disk space remaining.”.   This is caused by old Linux kernels filling up the boot partition on the hard drive.  For most users, you don’t need to keep old kernels and therefore you can remove them to free up some space.   For simplicity sake – it did this using the Synaptic Package Manager.  Here is how:

1) First, you need to find the current kernel that you are was using – so that you don’t remove it!  Open a terminal and type:

uname -a

Linux toshiba 3.5.0-23-generic #35-Ubuntu SMP Thu Jan 24 13:05:29 UTC 2013 i686 i686 i686 GNU/Linux

2) From the output, I was using 3.5.0-23-generic.  Therefore, I could remove all other kernels with version numbers lower than this.   There are three packages that make up the kernel:

  • linux-header-x-x-x-x-generic
  • linux-image-x-x-x-x-generic
  • linux-image-extra-x-x-x-x-generic

Using Synaptic Package Manager search for linux-header, then linux-image and select  the ones with a lower version number than your current kernel.  Mark each package for removal.  The linux-image-extra will automatically be removed when you remove a linux-image.

Then apply the changes and reboot your machine.

p.s. – it strikes me that it would be really good if Ubuntu could automatically do this.  Perhaps this could be built into the automatic update tool.

 

Magento PDF Invoices not appearing…

…is that another bug with Magento? Surely not. Here is the apache error log:

Declaration of Zend_Pdf_FileParserDataSource_File::__construct() must be compatible with Zend_Pdf_FileParserDataSource::__construct() in /var/www/lib/Zend/Pdf/FileParserDataSource/File.php on line 41

The solution is to change the constructor function of lib/Zend/Pdf/FileParserDataSource.php

abstract public function __construct();

to

abstract public function __construct($filePath);

Again – this bug has been around since 2010. It’s 2012…

Magento php extensions 0 must be loaded

I’ve just been installing Magento (which for some reason is a real pain!). I got a really random error message when trying to setup the database. I get an error message just saying:

"php extensions 0 must be loaded"

You need to edit app/code/core/Mage/Install/etc/config.xml changing:

&lt;extensions&gt;
&lt;pdo_mysql/&gt;
&lt;/extensions&gt;

to this:

&lt;extensions&gt;
&lt;pdo_mysql&gt;

Given that this bug has been around since for about 3 years – surely Magento can fix it?

Installing HP Proliant Support Pack (PSP) on Ubuntu 12.04

It took me a while to find the PSP for Ubuntu. It turns out that HP have renamed the old Proliant Support Pack to Management Component Pack.

We use HP ProLiant DL380 G6 servers and want to monitor the raid without using HP Insight software. You can either download the .deb files from the HP website:

However, it is much more convenient to add the HP Repository. Add the following to /etc/apt/sources.list:

deb http://downloads.linux.hp.com/SDR/downloads/MCP/ubuntu precise/current non-free

Download and add the repo keys to the system. The URL keeps changing and so there are a few choices before. The top on is the most likely to be the correct one.

wget http://downloads.linux.hpe.com/SDR/downloads/MCP/GPG-KEY-mcp
apt-key add GPG-KEY-mcp

or

wget http://downloads.linux.hp.com/SDR/downloads/MCP/GPG-KEY-mcp
apt-key add GPG-KEY-mcp

or

wget http://downloads.linux.hp.com/SDR/downloads/MCP/GPG-KEY-MCP
apt-key add GPG-KEY-MCP

Update apt-get:

apt-get update

If you want to monitor raid array then install hpacucli

apt-get install hpacucli

A basic report showing the status of your raid arrays is:

hpacucli ctrl all show config

An example output is:

Smart Array P410i in Slot 0 (Embedded)    (sn: 50123456789ABCDE)

   array A (SAS, Unused Space: 0  MB)

      logicaldrive 1 (273.4 GB, RAID 1+0, OK)

      physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS, 146 GB, OK)
      physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS, 146 GB, OK)
      physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SAS, 146 GB, OK)
      physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 146 GB, OK)

   array B (SATA, Unused Space: 0  MB)

      logicaldrive 2 (1.8 TB, RAID 1+0, OK)

      physicaldrive 2I:1:5 (port 2I:box 1:bay 5, SATA, 1 TB, OK)
      physicaldrive 2I:1:6 (port 2I:box 1:bay 6, SATA, 1 TB, OK)
      physicaldrive 2I:1:7 (port 2I:box 1:bay 7, SATA, 1 TB, OK)
      physicaldrive 2I:1:8 (port 2I:box 1:bay 8, SATA, 1 TB, OK)

   SEP (Vendor ID PMCSIERA, Model  SRC 8x6G) 250 (WWID: 50123456789ABCED)

Enjoy.

How to connect Ubuntu Client to Synology VPN server using PPTP

We have a Synology Rackstation NAS and it comes with a VPN server. I decided to try and work out how to connect my Ubuntu laptop to the Synology VPN server and route my network through that. It took me sometime to get the settings right, so I have put together a guide in the hope that it helps someone else.

Step 1 – Install the server
I installed the VPN server. You can find instruction on how to do this on the Synology website.

Step 2 – Configure the VPN server
I configured the VPN server settings as follows:

Step 3 – Setup configure the Ubuntu client
Now using the network manager and select VPN Connections -> Configure VPN…

Then click the add button:

Select PPTP and click create:

Don’t need to change the IPV4 settings – they should look like this:

You should name the connection, then enter the VPN server IP address or domain name. You will also need to add your username and password exactly the same as on the Synology server. Note: Don’t put anything in the NT Domain field. This isn’t required and will stop the client authenticating. Other how to suggest that you do this – it isn’t required for Synology.

Final Tweaks
You can then tweak the advanced settings to make sure the client runs as securely as possible. Here are the settings that I used:

Enable Your VPN Connection
To enable your the VPN connection you should click on the Network Manager -> VPN Connections -> Select your VPN connection. You will know that the VPN connection is working when the network icon has a little padlock. You don’t need to reboot your computer to make this connection work.

If you have problems then I recommend tailing the /var/log/syslog to debug.

tail -f /var/log/syslog

I hope this helps. Let me know if you have any feedback.

How to route all your network traffic through an SSH Tunnel

I’ve recently been visiting China and have been caught out by their Firewall.  This hasn’t be too bad but Google Mail and Google Drive is really slow or intermittent.  Also you can’t access YouTube or the BBC IPlayer.   The final straw for me was for some reason they have blocked the Ubuntu Dropbox repository – so you can’t install Dropbox either.

I don’t have VPN account but we do have some servers.  Therefore, I decided to route all the network traffic through one of our server.

I tried various options and final settled on sshuttle because I needed to route everything and not just Firefox. Sshuttle is a transparent proxy server that forwards over a SSH connection and sets up a proxy by running Python scripts on the remote server.  I’m assuming your are running Ubuntu on both the client and the remote server.  You will need administrative privileges on the client.

sudo apt-get install sshuttle

To route all traffic through sshuttle (except DNS):

sshuttle -r username@sshserver:port 0/0

You will then need to enter your password on your client and then the password for the remote machine.  To help debug run sshuttle in verbose mode with the -v flag.  The -r flag is  the remote host (and username).   The port 0/0 is short for 0.0.0.0/0 that represents the subnets to route over the VPN.  The usage of 0/0 routes all the traffic except DNS requests to the remote server.  If you need to tunnel your DNS too then add the -H flag.

The project website is https://www.stunnel.org/index.html

Happy Tunnelling.

smbfs stops working after upgrading from ubuntu 12.04 to 12.10

Just has another little problem while upgrading from Ubuntu 12.04 to Ubuntu 12.10.  It seems that smbfs no longers works in Ubuntu 12.10.  Once again, why don’t the developers make a webpage or a popup application which tells you these changes?  It would save hours of time for lots of users.

Anyhow, here is how I converted my fstab to work.  Before it looked like this:

//server/share /mnt/server/share smbfs iocharset=utf8,credentials=/path/to/.smbcredentials,uid=1000,gid=1000

Afterwards, I changed smbfs -> cifs and remove the gid.

//server/share /mnt/server/share cifs iocharset=utf8,credentials=/path/to/.smbcredentials,uid=1000 0 0

If you have problems then tail the /var/log/kern.log

tail -f /var/log/kern.log

Great. Back up an running again.