#!/usr/bin/perl5.8.4
#  This software was derived from SATAN 1.1.1 by Dan Farmer and Wietse Venema
#  (http://www.porcupine.org/satan).
#
#
#  Execute a bootparam WHOAMI request and report the results.
#
$running_under_sara = 1;
require 'config/paths.pl';
require 'perl/misc.pl';
require 'perl/fix_hostname.pl';

die "usage: $0 client server" unless ($#ARGV == 1);

$target = $client = $ARGV[0];
$server = $ARGV[1];

# fields for sara...
$severity="x";
$status="a";
$service = "boot";

open(BOOT, "$BOOT $client $server|");

while (<BOOT>) {
	chop;
	if (/domain_name:\s+(\S+)/) {
		$service_output = "domain $1"; 
		$target = $server; &sara_print;
		$target = $client; &sara_print;
	}
	if (/client_name:\s+(\S+)/) {
		$client = &fix_hostname($1, $server);
		$service_output = "client $client"; 
		$target = $client; &sara_print;
	}
	if (/router_addr:\s+(\S+)/) {
		$service_output = "router $1"; 
		$target = $client; &sara_print;
	}
}
close(BOOT);

# print something out if nothing has happened so far...
# if rpcinfo returns !0, then flag it; else, nothing interesting showed up.
if ($service_output eq "") {
	$severity="";
	if ($?) {
		$text="boot error #$?";
	} else {
		$text="No boot output of interest";
	}
	&sara_print();
}
