Creating a Script


You can embed the scadm send_event command into a script to log an ALOM event or to send an alert when certain conditions occur. Use the -c option to send a custom critical alert.

This example shows a Perl script file named dmon.pl that sends an ALOM alert when a specified disk partition exceeds a specified percent of its capacity.

Note: This script is written for the Sun Fire V440 host server. Use the uname -i command to obtain the platform name for your host server and replace the SUNW,Sun-Fire-V440 string in the example.

To use this script as intended, submit a separate entry to the crontab utility for each disk partition you want to monitor.

#!/usr/bin/perl

# Disk Monitor
# USAGE: dmon <mount> <percent>
# e.g.: dmon /usr 80


@notify_cmd = `/usr/platform/SUNW,Sun-Fire-V440/sbin/scadm';


if (scalar(@ARGV) != 2)
{
print STDERR "USAGE: dmon.pl <mount_point> <percentage>\n";
print STDERR " e.g. dmon.pl /export/home 80\n\n";
exit;
}

open(DF, "df -k|");
$title = <DF>;

$found = 0;
while ($fields = <DF>)
{
chop($fields);
($fs, $size, $used, $avail, $capacity, $mount) = split(` `, $fields);
if ($ARGV[0] eq $mount)
{
$found = 1;
if ($capacity > $ARGV[1])
{
print STDERR "ALERT: \"", $mount, "\" is at ", $capacity,
" of capacity, sending notification\n";
$notify_msg = `mount point "`.$mount.'" is at `.
$capacity.' of capacity';
exec (@notify_cmd, `send_event', `-c', $nofify_msg)
|| die "ERROR: $!\n";
}
}
}

if ($found != 1)
{
print STDERR "ERROR: \"", $ARGV[0],
"\" is not a valid mount point\n\n";
}

close(DF);