#!/usr/bin/perl -w

=head1 NAME

be_the_one.pl - updates the timestamp of an object in the ADSI domain and the FRS-test-file.

=head1 SYNOPSIS

./be_the_one.pl

=head1 DESCRIPTION

Updates the timestamp of an object in the ADSI domain and the FRS-test-file.

Normal DCs:

FRS-File:  F<c:\winnt\SYSVOL\sysvol\sap.corp\scripts\frs.tst>
AD-Object: F<LDAP://CN=MsdsMonCmp,OU=MSDS,OU=Resources,DC=sap,DC=corp>

Computers starting with C<saproot>:

FRS-File:  F<c:\winnt\SYSVOL\sysvol\corp\scripts\frs.tst>
AD-Object: F<LDAP://CN=MSDSMONCMP,OU=MSDS,DC=corp>

=head1 CONFIGURATION

The script contains hard coded paths for the frs-test-file and the object.

=head1 AUTHOR

(c) 2003 Hannes Schulz <mail@hannes-schulz.de>

=cut

use Win32::OLE;

# Find out if we're special (saproot0, saproot1)
my $special = ($ENV{COMPUTERNAME} =~ /^saproot/i)?1:0;

# Set the paths of things to update

$obj = $special?
   "LDAP://CN=MSDSMONCMP,OU=MSDS,DC=corp":
   "LDAP://CN=MsdsMonCmp,OU=MSDS,OU=Resources,DC=sap,DC=corp";
$file = $special?
   'c:\winnt\SYSVOL\sysvol\corp\scripts\frs.tst':
   'c:\winnt\SYSVOL\sysvol\sap.corp\scripts\frs.tst';

$desc = "DO NOT DELETE!!! Object used for AD replication monitoring only";

# update time string
$tm = scalar time;

# change description of object
$userobj = Win32::OLE->GetObject($obj) or do{
	print "Could not get Oject!\n";
	exit 2; # Nagios Critical
};
$userobj->{Description} = "$desc\n$tm";
$userobj->SetInfo;

# update the file...
open(FRS,">".$file) or die "Could not open frs-test-file: $!\n";
print FRS $tm;
close FRS;

exit(0)    # Nagios: OK
