#!/usr/bin/perl
#
# ipfc.alert - IPFC alert script for MON (http://www.conostix.org/ipfc/)
#
# The IPFC alert script integrates mon alerts into the IPFC framework.
# 
# This script requires the perl libipfc available in the
# general distribution of IPFC.
#
# Alexandre Dulaunoy, adulau@conostix.com
#
# $Header: /cvsroot/ipfc/ipfc/src/wrapper/mon/ipfc.alert,v 1.3 2002/01/09 13:14:30 adulau Exp $
#
#    Copyright (C) 2001 Alexandre Dulaunoy, adulau@thinkingsecure.com
#    Copyright (C) 2001 Conostix S.A. Luxembourg
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

## IPFC Configuration
$agentid = 33;
$wrapperid = 0; 
$ENV{IPFCDIR} = "/opt/ipfc";
require $ENV{IPFCDIR}."/lib/libipfc.pl";

## 
use Getopt::Std;
use Text::Wrap;
use MIME::Base64;
getopts ("S:s:g:h:t:l:u");

$summary=<STDIN>;
chomp $summary;

$summary = $opt_S if (defined $opt_S);

$mailaddrs = join (',', @ARGV);

$ALERT = $opt_u ? "UPALERT" : "ALERT";

$t = localtime($opt_t);
($wday,$mon,$day,$tm) = split (/\s+/, $t);

&ipfc_init;

$monalert = "<firstline>".$ALERT." ".$opt_g."/".$opt_s.": 
".$summary."(".$wday." ".$mon." ".$day." ".$tm.")"."</firstline>\n";
$monalert .= "<alerttype>$ALERT/alerttype>\n";
$monalert .= "<group>$opt_g</group>\n";
$monalert .= "<service>$opt_s</service>\n";
$monalert .= "<timenoticed>$t</timenoticed>\n";
$monalert .= "<nextalert>$opt_l</nextalert>\n";
$monalert .= "<summary>$summary</summary>\n"; 
$monalert .=  "<members>$opt_h</members>\n";
$monalert .=  "<message format=\"base64\">";
while (<STDIN>) {$message .= $_; }
$encoded_message = encode_base64($message);
$monalert .= $encoded_message;
$monalert .= "</message>\n";

&IpfcGenMessage($monalert,$agentid,$wrapperid,"status","status","mon-alert","mon-alert");



