#!/usr/local/groundwork/bin/perl --
#
# hpov_eventhandler.pl v1.0 - 07/21/2006 
#
# HP Openview Event Handler
# Copyright 2006 GroundWork Open Source Solutions, Inc. (“GroundWork”)  
# All rights reserved. Use is subject to GroundWork commercial license terms.
#
# Revision History
# 21-Jul-2006 Peter Loh
#
#

use strict;
use Time::Local;
use Time::HiRes;
my $debug = 1;
my $debuglog = ">> /usr/local/groundwork/nagios/eventhandlers/hpov.log";
my $hpov_cmd = "/opt/OV/bin/OpC/opcmsg";
my ($lastcheck,$host,$service,$status,$statustext);
my $type  = $ARGV[0];		# host or service type
$lastcheck = $ARGV[1];
$host = $ARGV[2];
$status = $ARGV[3];
$statustext = $ARGV[4];
$service = $ARGV[5];
my $hpovstatus = undef;

if ($debug) {
	open(FP, $debuglog) ;
	print FP "---------------------------------------------------------------------\n " ;
	print FP `date`." Host: $host\n Svcdesc: $service\n Lastcheck: $lastcheck\n Status: $status\n Statustext: $statustext\n" ;
}

my $cmdstring = $hpov_cmd;
if ($host !~ /\.Cadence\.COM$/i) {
	$host .= ".Cadence.COM";
}
$cmdstring .= " node=$host";
$cmdstring .= " application=gto_gwmon";
if ($type eq "service") {
	$cmdstring .= " object=$service";
	if ($status eq "OK") {
		$hpovstatus = "normal";
	} elsif ($status eq "WARNING") {
		$hpovstatus = "warning";
	} elsif ($status eq "CRITICAL") {
		$hpovstatus = "critical";
	} elsif ($status eq "UNKNOWN") {
		$hpovstatus = "minor";
	} else {
		$hpovstatus = "minor";
	}
} else {
	$cmdstring .= " object=HOST_ALERT";
	if ($status eq "UP") {
		$hpovstatus = "normal";
	} elsif ($status eq "DOWN") {
		$hpovstatus = "critical";
	} elsif ($status eq "UNREACHABLE") {
		$hpovstatus = "major";
	} elsif ($status eq "UNKNOWN") {
		$hpovstatus = "minor";
	} else {
		$hpovstatus = "minor";
	}
}
$cmdstring .= " msg_text=\"$statustext\"";
$cmdstring .= " severity=$hpovstatus";
$cmdstring .= " msg_grp=GWMP";
my @lines = `$cmdstring`;
if ($debug) {
	print FP "Command string = \"$cmdstring\"\n " ;
	print FP "Command Results = @lines\n" ;
	close FP;
}

__END__


