#
# $Id: MonAlert.pm,v 1.1 2002/03/05 23:45:13 fpmip Exp $
#

# Author : Tycho Fruru <tycho@fruru.com>

# Copyright (C) 2001 Tycho Fruru <tycho@fruru.com>
# Copyright (C) 2001 Conostix S.A. Luxembourg - Tycho Fruru <tycho@conostix.com>

# 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.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# 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.
#

package IPFC::Parse::Transport::MonAlert;

use strict;
use warnings;
use IPFC::Log;

BEGIN {
	use Exporter   ();
        our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);

        # set the version for version checking
        $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker

        @ISA         = qw(Exporter);
        @EXPORT      = qw( );
        %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
        @EXPORT_OK   = qw( );
}
our @EXPORT_OK;

sub parse($$$$) {
	shift; #current class
	my $dbh = shift;
	my $entry = shift;
	my $function_name = shift;
	my $r_sql_hash = shift;
	
	my $current_entry;
	my $index = 0;
	my $rc = 1;

	my %sql_hash = %{$r_sql_hash};

	my $mon_alert = $entry->{'mon-alert'}->[0];
	
	if (!defined($mon_alert)) {
		IPFC::Log::logger(1,"no mon-alert line in process_transport_mon_alert !");
		return 0;
	}
	
	$sql_hash{'alert_type'}=$mon_alert->{'alerttype'};
	$sql_hash{'mon_group'}=$mon_alert->{'group'};
	$sql_hash{'service'}=$mon_alert->{'service'};
	$sql_hash{'summary'}=$mon_alert->{'summary'};

	if (defined($mon_alert->{'timenoticed'})) {
		my $time_string = gmtime($mon_alert->{'timenoticed'});
		$time_string = $time_string." UTC";
		$sql_hash{'time'}=$time_string;
	}
	
	$sql_hash{'next_alert'}=$mon_alert->{'nextalert'};
	$sql_hash{'members'}=$mon_alert->{'members'};
	
	my $mon_message=decode_entry($mon_alert->{'message'}->[0]);
	
	$rc = $function_name->parse($dbh,$mon_message,\%sql_hash);

	IPFC::Log::logger(5,"return value for process_transport_mon_alert : $rc\n");
	return $rc;
}

return 1;
