Guide de l'utilisateur Sun Remote System Control (RSC)

Annexe C Création d'un script permettant d'envoyer un message d'alerte ou un événement RSC

Vous pouvez imbriquer la sous-commande send_event de la commande rscadm dans un script ou un fichier de commandes pour enregistrer un événement RSC ou envoyer une alerte lorsque certaines conditions se présentent. Utilisez l'option -c pour envoyer une alerte.

Cette annexe contient l'exemple d'un fichier de script Perl de nom dmon.pl qui envoie une alerte RSC lorsqu'une partition de disque donnée dépasse un pourcentage donné de sa capacité. Pour utiliser correctement ce script, soumettez une entrée séparée à l'utilitaire crontab pour chacune des partitions de disque que vous voulez surveiller.

#!/usr/bin/perl

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


@notify_cmd = `/usr/platform/sun4u/sbin/rscadm';


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";
         $nofify_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);