#77236 - 2003-10-24 07:32 PM
Server available script
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
In response to - Call the in charge person Converted the Batch Script to KiXtart, and is simpler.. $srvarray ='SERVER01 SERVER02 SERVER03 SERVER04'
$srvarray =$srvarray +' SERVER05 SERVER06'
FOR EACH $i IN Split ($srvarray )
?'Checking Server: ' +$i
SHELL '%COMSPEC% /C PING -n 1 ' +$i
IF @error < >0
$rc =WRITEVALUE ('HKCU\Software\KiXtart' ,$i ,$i ,'REG_SZ' )
;Notify server is off-line
MAILER ('Offline' ,$i ,'Server is off-line' )
ELSE
IF '' < >READVALUE ('HKCU\Software\KiXtart' ,$i )
;Notify back on line
MAILER ('Online' ,$i ,'Server is online' )
$rc =DELVALUE ('HKCU\Software\KiXtart' ,$i )
ENDIF
ENDIF
NEXT
FUNCTION MAILER ($status ,$server ,$body )
BREAK ON
$mailhost = 'smtp.company.com'
$recipient = 'admin@@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 Have fun! Kent
Top
#77237 - 2003-10-24 11:17 PM
Re: Server available script
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
This version does some checking and if after 60 minutes a server is not back up, there is a page sent - this way normal server restarts don't page, but if there is a problem it can be addressed.. ;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
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 )
?'Checking Server: ' +$i
SHELL '%COMSPEC% /C PING -n 1 ' +$i
IF @error < >0
IF '' =READVALUE ('HKCU\Software\KiXtart' ,$i ) ;only do this once
$rc =WRITEVALUE ('HKCU\Software\KiXtart' ,$i ,$i +@time ,'REG_SZ' )
;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 =READVALUE ('HKCU\Software\KiXtart' ,$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 < >READVALUE ('HKCU\Software\KiXtart' ,$i +'PAGE' ) ;only do this once
$rc =WRITEVALUE ('HKCU\Software\KiXtart' ,$i +'PAGE' ,$i ,'REG_SZ' )
MAILER ('pager@@messaging.sprintpcs.com' ,'Offline' ,$i ,'Paging: Server is off-line' +@time +' ' +$amerdt )
ENDIF
ENDIF
ELSE
IF '' < >READVALUE ('HKCU\Software\KiXtart' ,$i )
;Notify back on line
MAILER ('person@@company.com' ,'Online' ,$i ,'Server is online ' +@time +' ' +$amerdt )
$rc =DELVALUE ('HKCU\Software\KiXtart' ,$i )
$rc =DELVALUE ('HKCU\Software\KiXtart' ,$i +'PAGE' )
ENDIF
ENDIF
NEXT
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 Kent
Top
#77238 - 2003-10-27 01:58 PM
Re: Server available script
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
So, no takers?WhatsUp Gold retails out about $795 (usd) a seat. Kent [ 27. October 2003, 14:00: Message edited by: kdyer ]
Top
#77239 - 2003-10-27 02:13 PM
Re: Server available script
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I use KPinger from my web site. I haven't thought about adding blat to it... but it wouldn't be too hard.
Top
#77240 - 2003-10-27 02:14 PM
Re: Server available script
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I thought about adding your ping routines.. I just threw something together last week. Kent
Top
#77242 - 2003-10-28 07:12 AM
Re: Server available script
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Doc, This is a "poor man's" What's Up Gold. It is meant to be pretty simple. The idea was to take our current BATCH script that fires off every 5 minutes to see if our group of servers is up and running. If it is not, it e-mails a group of us and creates a copy of CONIFG.NT as the marker. I was asked to expand it to not only monitor every 5 minutes, but if the server was off-line over 60 minutes, it would page. Back to my point, I wanted to take our current batch script and change it to KiX. In that process, I simplified the structure too. Kent
Top
#77245 - 2003-10-28 01:56 PM
Re: Server available script
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Servers Alive - $99/$179.. What? You think we have a ton of money? Why not homebrew a solution? Registry Keys being added should not be too big of deal as the script cleans these up when the server(s) come back up. However, a thought just popped into my mind about using an INI structure and have the individual server status written to a file rather than the registry. I am not saying my solution is ideal. I know it it needs work. Thanks! Kent
Top
#77246 - 2003-10-28 02:52 PM
Re: Server available script
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
;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 ]
Top
#77249 - 2003-10-28 04:33 PM
Re: Server available script
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Cost? I am not opposed to purchasing software. With the talent base we have here, why not build our own? If you build your own, you get more flexibility to add/remove features you want. Kent
Top
#77250 - 2003-10-28 07:23 PM
Re: Server available script
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Next rev.. This ENUMERATES an INI file to pull in the server list. ;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.3
;
;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
; Version 1.3 Changed back to a PING method
; Use a separate INI file and enumerate the data within
;
;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
;
;SRVAVAIL.INI - List of Servers to check in the following format
; [SERVERS]
; SERVER01=OK
; SERVER02=OK
; SERVER03=OK
;
;KiXtart Ver 4.02
;
;Example(s) SRVAVAIL()
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 ]
$chk =@scriptdir +'\srvavail.ini'
$srv =split (readprofilestring ($chk ,'SERVERS' ,'' ),chr (10 ))
FOR EACH $i IN $srv
IF $i < >''
$status =readprofilestring ($chk ,'SERVERS' ,$i )
;?$sectionkey+' '+$status
?'Checking Server: ' +$i
SHELL '%COMSPEC% /C PING -n 1 ' +$i
IF @error < >0
IF 'OK' =$status ;only do this once
$rc =WRITEPROFILESTRING ($chk ,'SERVERS' ,$i ,$i +@time )
;Notify server is off-line
MAILER ('recipient@@company.com' ,'Offline' ,$i ,'Server is off-line ' +@time +' ' +$amerdt )
ENDIF
$ortime =READPROFILESTRING ($chk ,'SERVERS' ,$i )
IF 0 =instr ($ortime ,'PAGE' )
$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 ) ;only do this once
$rc =WRITEPROFILESTRING ($chk ,'SERVERS' ,$i ,$i +'PAGE' )
MAILER ('pager@@messaging.sprintpcs.com' ,'Offline' ,$i ,'Paging: Server is off-line' +@time +' ' +$amerdt )
ENDIF
ENDIF
ENDIF
ELSE
IF 'OK' <>READPROFILESTRING ($chk ,'SERVERS' ,$i )
;Notify back on line
MAILER ('recipient@@company.com' ,'Online' ,$i ,'Server is online ' +@time +' ' +$amerdt )
$rc =WRITEPROFILESTRING ($chk ,'SERVERS' ,$i ,'ok' )
ENDIF
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
[ 04. November 2003, 14:38: Message edited by: kdyer ]
Top
#77252 - 2003-10-28 07:42 PM
Re: Server available script
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
One of the problem I found was processes hanging on a single machine, especially when checking for things like share availability. Have a butchers' at this thread to see how I got round it and used the INI file technique to allow anyone to view the latest status information.
Top
#77253 - 2003-10-28 07:46 PM
Re: Server available script
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Richard, I think it is amazing how much my script is starting to resemble your's. Ouch. Kent
Top
Moderator: Glenn Barnas , NTDOC , Arend_ , Jochen , Radimus , Allen , ShaneEP , Ruud van Velsen , Mart
0 registered
and 369 anonymous users online.