;Function SRVAVAIL() 
;
;Author Kent Dyer(leptonator@hotmail.com)
;
;Contributors Lonkero and Doc for ideas
; Jens for his time-based UDFs
;
;Action Checks to see if a set of servers or machines are available
; and as needed e-mail and after 60 minutes page
;
;Syntax SRVAVAIL()
;
;Version 1.2
;
;Date 24-October-2003
;
;Date Revised 28-October-2003
;
;Remarks This is a poor-mans WhatsUP Gold, it was a re-write of
; batch script I put together about 2-1/2 years ago.
; http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=2;t=004261#000005
; "Call the in charge person"
; The idea is to check for if a server is up and running. If it is not,
; e-mail appropriate staff. If a server is off-line for over an hour
; page appropriate staff. When a server comes back on-line an e-mail is
; also generated
; Version 1.0 Original Script
; Version 1.1 Added Paging component
; Version 1.2 Changed from using the Registry to INI
; Do a check for existence of an Admin share rather than a PING
;
;Returns Nothing
;
;Dependencies
;TimeDiff
;http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000040

;SerialTime
;http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000039
;
;Mailer (added to this script as it has a fourth parameter)
;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000483
;
;KiXtart Ver 4.02
;
;Example(s) SRVAVAIL()


FUNCTION SRVAVAIL()
CLS
BREAK ON
DIM $i,$amerdt,$srvarray,$rc,$time,$tcheck,$ortime,$recipitent,$status,$server,$body

$amerdt=split(@date,'/')[1]+'/'+split(@date,'/')[2]+'/'+split(@date,'/')[0]
$srvarray='server01 server02'
$srvarray=$srvarray+' server03 server 04'

FOR EACH $i IN Split($srvarray)
$chk=@scriptdir+'srvavail.ini'
?'Checking Server: '+$i
IF 0=EXIST('\\'+$i+'\ADMIN$$')
IF 'OK'=READPROFILESTRING($chk,'SERVERS',$i) ;only do this once
$rc=WRITEPROFILESTRING($chk,'SERVERS',$i,$i+@time)
;Notify server is off-line
$amerdt=split(@date,'/')[1]+'/'+split(@date,'/')[2]+'/'+split(@date,'/')[0]
MAILER('recipient@@company.com','Offline',$i,'Server is off-line '+@time+' '+$amerdt)
ENDIF
$ortime=READPROFILESTRING($chk,'SERVERS',$i)
$time=SUBSTR($ortime,LEN($i)+1,len($ortime))
$tcheck=TIMEDIFF($time,@time)
$tcheck=split($tcheck,':')[0]
IF $tcheck > '00' ;If beyond 60 minutes, page
IF $i+'PAGE'<>READPROFILESTRING($chk,'SERVERS',$i+'PAGE') ;only do this once
$rc=WRITEPROFILESTRING($chk,'SERVERS',$i+'PAGE',$i)
MAILER('pager@@messaging.sprintpcs.com','Offline',$i,'Paging: Server is off-line'+@time+' '+$amerdt)
ENDIF
ENDIF
ELSE
IF 'ok'<>READPROFILESTRING($chk,'SERVERS',$i)
;Notify back on line
MAILER('person@@company.com','Online',$i,'Server is online '+@time+' '+$amerdt)
$rc=WRITEPROFILESTRING($chk,'SERVERS',$i,'ok')
$rc=WRITEPROFILESTRING($chk,'SERVERS',$i+'PAGE','')
ENDIF
ENDIF
NEXT
ENDFUNCTION

FUNCTION MAILER($recipient,$status,$server,$body)
$mailhost = 'smtp.company.com'
$sender = 'ServerMonitor@@company.com'
$mailline = @ldrive+'Programs\blat.exe - -to $recipient -server $mailhost -subject "$server $status" '
$mailline = $mailline+'-body "$body" -f $sender -q'
SHELL $mailline
ENDFUNCTION


[ 28. October 2003, 16:34: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's