#!/usr/bin/perl
#
#  bin/rpc.saint
#
#  Does an "rpcinfo -p" on a machine, tries to determine anything interesting
# running there.
#
#  TODO -- verify args
#
# version 1, Mon Mar 20 21:05:44 1995, last mod by wietse
#
require 'config/paths.pl';
require 'perl/misc.pl';

print "BEGIN\n";
die "usage: $0 target" unless ($#ARGV <= 1);

# fields for saint...
$severity="x";
$status="a";

$target = $ARGV[0];

open(RPC, "$RPCINFO -p $target|");

while (<RPC>) {
	chop;
	($prog, $vers, $proto, $port, $name) = split;
	if ($name eq "rexd" || $prog == 100017)		{ $rexd = 1; }
	if ($name eq "arm")				{ $arm = 1; }
	if ($name eq "bootparam" || $prog == 100026)	{ $bootparamd = 1; }
	if ($name eq "ypserv" || $prog == 100004)	{ $ypserv = 1; }
	if ($name eq "ypbind" || $prog == 100007)	{ $ypbind = 1; }
	if ($name eq "walld" || $prog == 100008)	{ $walld = 1; }
	if ($name eq "selection_svc" || $prog == 100015){ $s_svc = 1; }
	if ($name eq "nfs" || $prog == 100003)		{ $nfs = 1; }
	if ($name eq "nfsd")				{ $nfsd = 1; }
	if ($name eq "mountd" || $prog == 100005)	{ $mountd = 1; }
	if ($name eq "rusersd" || $prog == 100002)	{ $rusersd = 1; }
	if ($name eq "netinfobind" || $prog == 200100001){ $netinfobind = 1; }
	if ($name eq "admind" || $prog == 100087)	{ $admind = 1; }
        if ($name eq "status" || $prog == 100024)       { $statd = 1; }
	if ($prog == 100083)				{ $ttdbserverd = 1; }
        if ($name eq "rstatd" || $prog == 100001)       { $rstatd = 1; }
	if ($prog == 100068)				{ $cmsd = 1; }
	if ($name eq "sadmind" || $prog == 100232)	{ $sadmind = 1; }
	if ($name eq "amd" || $prog == 300019)		{ $amd = 1; }
	if ($name eq "sgi_fam" || $prog == 391002)	{ $sgifam = 1; }
	if ($name eq "nisd" || $prog == 100300)		{ $nisd = 1; }
	if ($prog == 100249)				{ $snmpxdmid = 1; }
	if ($name =~ /espd/ || $prog == 391029)		{ $espd = 1; }
	if ($prog == 100009)				{ $yppasswdd = 1; }
	if ($prog == 100235)				{ $cachefsd = 1; }
}
close(RPC);

if ($rexd) {
	$service = "rexd"; $text = "runs rexd"; &saint_print;
}
if ($arm) {
	$service = "arm"; $text = "runs arm"; &saint_print;
}
if ($bootparamd) {
	$service = "bootparam"; $text = "runs bootparam"; &saint_print;
}
if ($ypserv) {
	$service = "ypserv"; $text = "is a NIS server"; &saint_print;
}
if ($ypbind) {
	$service = "ypbind"; $text = "is a NIS client"; &saint_print;
}
if ($walld) {
	$service = "walld"; $text = "runs walld"; &saint_print;
}
if ($rusersd) {
	$service = "rusersd"; $text = "runs rusersd"; &saint_print;
}
if ($nfs) {
	$service = "nfs"; $text = "runs NFS"; &saint_print;
}
if ($nfsd) {
	$service = "nfsd"; $text = "runs nfsd"; &saint_print;
}
if ($mountd) {
	$service = "mountd"; $text = "runs NFS"; &saint_print;
	$service = "mountd"; $text = "runs mountd"; &saint_print;
}
if ($s_svc) {
	$service = "selection_svc"; $text = "runs selection_svc"; &saint_print;
}
if ($admind) {
	$service = "admind"; $text = "runs admind"; &saint_print;
}
if ($statd) {
        $service = "statd"; $text = "runs statd"; &saint_print;
}
if ($ttdbserverd) {
	$service = "ttdbserverd"; $text = "runs tooltalk"; &saint_print;
}
if ($rstatd) {
        $service = "rstatd"; $text = "runs rstatd"; &saint_print;
}
if ($cmsd) {
	$service = "cmsd"; $text = "runs cmsd"; &saint_print;
}
if ($sadmind) {
	$service = "sadmind"; $text = "runs sadmind"; &saint_print;
}
if ($amd) {
	$service = "amd"; $text = "runs amd"; &saint_print;
}
if ($sgifam) {
	$service = "sgifam"; $text = "runs sgifam"; &saint_print;
}
if ($nisd) {
	$service = "nisd"; $text = "runs nisd"; &saint_print;
}
if ($snmpxdmid) {
	$service = "snmpxdmid"; $text = "runs snmpxdmid"; &saint_print;
}
if ($espd) {
	$service = "espd"; $text = "runs espd"; &saint_print();
}
if ($yppasswdd) {
	$service = "yppasswdd"; $text = "runs yppasswdd"; &saint_print();
}
if ($cachefsd) {
	$service = "cachefsd"; $text = "runs cachefsd"; &saint_print;
}

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