LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-12-2007, 09:13 PM   #1
ajferrari
LQ Newbie
 
Registered: Nov 2005
Location: Location
Distribution: SuSE 9.3
Posts: 10

Rep: Reputation: 0
Sending Raid Array Data through postfix


I set up a server with a hardware RAID array using Ubuntu Linux.

I want the array to email me when it goes down.

The server is a dell, which comes with array management software. I can use a the command line to query the status of the array.

I imagine that I should now write a script that would query the array and send that information to a file. Then the script would send that file via postfix, sendmail or something to an SMTP server which would relay the mail to my account?

I am new to Linux, what would be the best way of going about this?

I used a tutorial to set up postfix on my Ubuntu server here.

Is this the right way to go about this? How can I send a system message through postfix?

Thanks!
 
Old 01-12-2007, 09:28 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,156

Rep: Reputation: 327Reputation: 327Reputation: 327Reputation: 327
The simple way is:

check-command | mail -s "Subject" your@email.address

If you want it to only e-mail you on a failure you'll have to redirect the output from check-command to a file (e.g. check-command > myfile) and then grep for the error condition in it, and if it is detected (by checking the return value from grep, mail you. The shell script would probably look something like:

Code:
#!/bin/sh

MAILTO=your@email.address

check-command > /tmp/somefile
if [ "$?" -ne "0" ]; then
  mail -s "ERROR: could not run check-command" $MAILTO < /dev/null
  exit
fi

grep "error string" /tmp/somefile

# grep returns 0 if the string was found
if [ "$?" -eq "0" ]; then
  # uh-oh we found an error condition
  mail -s "ERROR DETECTED!" $MAILTO < /tmp/somefile
else
  # situation normal, remove the temp file
  rm -f /tmp/somefile
fi
If you have lots of stuff to monitor it behooves you to look at something like nagios or Cacti. However, it's probably only worth setting up if you have lots of stuff (at work I monitor over 700 services on around 150 machines with Nagios).
 
Old 01-13-2007, 12:33 AM   #3
ajferrari
LQ Newbie
 
Registered: Nov 2005
Location: Location
Distribution: SuSE 9.3
Posts: 10

Original Poster
Rep: Reputation: 0
That clears up the scripting part!

My question lies a little more with mailing though. Can a *unix type server just send mail out without a domain name? I have a static IP, but no mail service through my ISP. Do I have to register a domain and setup a mail server to send mail out? Or can I just use a simple mail program?

What mail program are you using? Any recommendations for a simple setup?

I found this script using Nagios! It is a little more thorough!

Code:
#!/usr/bin/perl -w

#
# NRPE plugin for monitoring Dell servers using Dell OMSA
# and omreport tool. Expects OMSA version 4.3 or 4.4.
#
# Pauli Borodulin <pauli.borodulin@uta.fi>
# Computer Centre, University of Tampere, Finland
# 20.6.2005
#
# Version 1.1 / 5.7.2005 / pb72587
#
# Changelog
#
# 1.0   Initial version
# 1.1   Clean up version
#

use strict;
use Switch;

my $OMSADIR = "/opt/dell/srvadmin";
my $OMSADISKS = "storage adisk controller=0 -fmt ssv";
my $OMSACHASSIS = "chassis -fmt ssv";
my $TIMEOUT = 5; # script timeout in secs

# Nagios defined exit codes
my $EXIT_OK = 0;
my $EXIT_WARNING = 1;
my $EXIT_CRITICAL = 2;
my $EXIT_UNKNOWN = 3;

# Internal status codes (bitwise-safe)
my $STATUS_OK = 0;
my $STATUS_WARNING = 1;
my $STATUS_CRITICAL = 2;
my $STATUS_UNKNOWN = 4;

# Internal device type codes
my $DEVICE_UNKNOWN = 0;
my $DEVICE_DISK = 1;
my $DEVICE_CHASSIS = 2;

# # # # # # # # # # #

# check that omreport exists and it's executable
if (! -X "$OMSADIR/oma/bin/omreport") {
    print "Unknown: omreport not available\n";
    exit $EXIT_UNKNOWN;
}

my $message = "";
my @data;

eval {
    local $SIG{ALRM} = sub { die "alarm\n" };
    alarm $TIMEOUT;

    # collect drive data using omreport
    my $ompid = open(OMFH, "$OMSADIR/oma/bin/omreport $OMSADISKS |");
    if($ompid == 0) {
        print "Unknown: couldn't execute omreport\n";
        exit $EXIT_UNKNOWN;
    }

    my $line;
    my $counter = 0;
    while(1) {
        $line = readline(OMFH);
        if(!defined($line)) {
            last; # break
        } elsif(index($line, ";") == -1) {
            next;
        }

        if(index($line, "ID;Status;Name") == -1) {
            # not a header row -> it's a data row
            chomp($line);
            my @fields = split(";", $line);
            $data[$counter]{'id'} = $fields[0];
            $data[$counter]{'status'} = $fields[1];
            $data[$counter]{'state'} = $fields[3];
            $data[$counter]{'devtype'} = $DEVICE_DISK;
            $counter++;
        }

    }
    close(OMFH);

    # collect chassis data
    $ompid = open(OMFH, "$OMSADIR/oma/bin/omreport $OMSACHASSIS |");
    if($ompid == 0) {
        print "Unknown: couldn't execute omreport\n";
        exit $EXIT_UNKNOWN;
    }
    while(1) {
        $line = readline(OMFH);
        if(!defined($line)) {
            last; # last line, break
        } elsif(index($line, ";") == -1) {
            next; # line must contain ';', continue
        }

        if(index($line, "SEVERITY;COMPONENT") == -1) {
            # not the header row -> it's a data row
            chomp($line);
            my @fields = split(";", $line);
            $data[$counter]{'id'} = $fields[1];
            $data[$counter]{'status'} = $fields[0];
            $data[$counter]{'state'} = "";
            $data[$counter]{'devtype'} = $DEVICE_CHASSIS;
            $counter++;
        }

    }

    close(OMFH);

    alarm 0; # disable alarm
};

# check that we got info of at least one
if((scalar @data) < 1) {
    print "Unknown: No devices were found!\n";
    exit $EXIT_UNKNOWN;
}

my $checkstatus = 0; # overall status

# process the device data
for(my $i = 0; $i < scalar @data; $i++) {

    my $devmessage = "";
    my $devtype = $data[$i]{'devtype'};
    my $status = $data[$i]{'status'};

    if($devtype == $DEVICE_DISK) {
	# disk
        my $state = $data[$i]{'state'};
        my @ids = split(":", $data[$i]{'id'});
        my $contid = $ids[0];  # controller id
        my $driveid = $ids[1]; # disk id

	$devmessage = "[drv $driveid] $status/$state ";

    } elsif($devtype == $DEVICE_CHASSIS) {
	# chassis (power supply, temps, intrusion, fans, memory, ...)
	my $device = $data[$i]{'id'};

        $devmessage = "[$device] $status ";

    } else {
        print "Unknown: Unknown device type encountered!\n";
	exit $EXIT_UNKNOWN;
    }

    switch($status) {
        case "Ok"           { $checkstatus |= $STATUS_OK; }
        case "Non-Critical" {
	    $checkstatus |= $STATUS_WARNING;
	    $message .= $devmessage;
	}
        case "Critical"     {
	    $checkstatus |= $STATUS_CRITICAL;
	    $message .= $devmessage;
	}
        else                {
	    $checkstatus |= $STATUS_UNKNOWN;
	    $message .= $devmessage;
	}
    }
}

# check whether the script timed out
if ($@) {
    die unless $@ eq "alarm\n";
    print "Unknown: script timed out\n";
    exit $EXIT_UNKNOWN;

} else {

    # output message and exit
    switch($checkstatus) {
        case 4 {
            print "Unknown: $message\n";
            exit $EXIT_UNKNOWN;
        }
        case 2 {
            print "Critical: $message\n";
            exit $EXIT_CRITICAL;
        }
        case 1 {
            print "Warning: $message\n";
            exit $EXIT_WARNING;
        }
        case 0 {
            print "OK\n";
            exit $EXIT_OK;
        }
        else {
            print "Unknown: processing error\n";
            exit $EXIT_UNKNOWN;
        }
    }
}

# these lines should not be reached
print "Unknown: plugin control flow failed.\n";
exit $EXIT_UNKNOWN;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending Via Postfix? mpapet Linux - Networking 0 12-23-2006 04:37 PM
Raid Array wwnexc Linux - Hardware 1 09-25-2005 06:47 PM
Help accessing data on NTFS raid array Qwindelzorf Linux - Hardware 2 01-15-2005 03:34 PM
sending pointer array to function marek Programming 4 04-15-2004 05:46 PM
Postfix Sending bonkers Linux - General 0 06-07-2003 03:37 AM


All times are GMT -5. The time now is 10:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration