#!/usr/bin/perl
#
#  bin/boot.saint
#
#  Execute a bootparam WHOAMI request and report the results.
#
$running_under_saint = 1;
require 'config/paths.pl';
require 'perl/misc.pl';
require 'perl/fix_hostname.pl';

print "BEGIN\n";
die "usage: $0 client server" unless ($#ARGV == 1 || $#ARGV == 2);

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

# fields for saint...
$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; &saint_print;
		$target = $client; &saint_print;
	}
	if (/client_name:\s+(\S+)/) {
		$client = &fix_hostname($1, $server);
		$service_output = "client $client"; 
		$target = $client; &saint_print;
	}
	if (/router_addr:\s+(\S+)/) {
		$service_output = "router $1"; 
		$target = $client; &saint_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";
	}
	&saint_print();
}
