#!/usr/bin/perl

#Copyleft 2010 Thomas GINESTET (thomas dot ginestet at cryonux dot 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 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

$nsca_host="my_nsca_server"; 
$config="/etc/nagios/send_nsca.cfg";
$send_nsca="/usr/sbin/send_nsca -c $config -H $nsca_host"; 
$result = `/usr/lib/nagios/plugins/check_grep 'label ok' -t 700 --command '/usr/local/sbin/amcheck my_amanda_config'`;
$hosts = "my_amanda_server";
$service = "backup_check_label";

if ($result =~ /OK/) { $code = 0; }
if ($result =~ /WARNING/) { $code = 1; }  
if ($result =~ /CRITICAL/) { $code = 2; }

open(SEND,"|$send_nsca") || die "Could not run $send_nsca: $!\n";
print SEND "$hosts\t$service\t$code\t$result\n";
close SEND;

