Page 1 of 1 1
Topic Options
#77236 - 2003-10-24 07:32 PM Server available script
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77237 - 2003-10-24 11:17 PM Re: Server available script
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77238 - 2003-10-27 01:58 PM Re: Server available script
Kdyer Offline
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 ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77239 - 2003-10-27 02:13 PM Re: Server available script
Radimus Moderator Offline
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.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#77240 - 2003-10-27 02:14 PM Re: Server available script
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77241 - 2003-10-28 05:14 AM Re: Server available script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Kent,

Just an FYI that you may want to be careful if you're filling the registry with entries.
(not sure if you are or not), just saying you don't want to fill it without some type of cleanup
routine in place as well.

You could expand on this with stuff like NET VIEW and/or ADSI/WMI just like those programs that
cost money do. I guess you just need to define specifically what all it is you're interested in
monitoring/controlling. Then taking the time to write the script.

Registry Storage Space
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/registry_storage_space.asp

Understanding and Configuring Registry Size Limit (RSL)
Microsoft Knowledge Base Article - 124594
http://support.microsoft.com/default.aspx?scid=124594

Registry structure
http://www.microsoft.com/windows2000/en/server/help/default.asp?url=/windows2000/en/server/help/sag_ntregconcepts_mply.htm

Top
#77242 - 2003-10-28 07:12 AM Re: Server available script
Kdyer Offline
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. [Wink]

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77243 - 2003-10-28 10:06 AM Re: Server available script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
relays only on ping...
some other stuff should be checker.
known services, default shares, registry...
_________________________
!

download KiXnet

Top
#77244 - 2003-10-28 11:13 AM Re: Server available script
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
You could also look at Servers Alive. This is realy a poor mans WhatsUp! It can be found at Woodstone's site.
_________________________
Kind regards,

Top
#77245 - 2003-10-28 01:56 PM Re: Server available script
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77246 - 2003-10-28 02:52 PM Re: Server available script
Kdyer Offline
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 ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77247 - 2003-10-28 02:54 PM Re: Server available script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
SRVAVAIL(")

should error out...
_________________________
!

download KiXnet

Top
#77248 - 2003-10-28 03:37 PM Re: Server available script
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
Kent,

Didn't you have look at the possibilities of the standard package for $99,-? Lots of addons are possible, even ssh checks and a lot of alert methods and ways to schedule a check or corresponding alert!

Yes, i'm a satisfied user of Servers Alive, and i think it can't be easily beaten for only $99 or even $179...

PS. Another option is HP Openview: $195,000

[ 28. October 2003, 15:40: Message edited by: Schuliebug ]
_________________________
Kind regards,

Top
#77249 - 2003-10-28 04:33 PM Re: Server available script
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77250 - 2003-10-28 07:23 PM Re: Server available script
Kdyer Offline
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 ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#77251 - 2003-10-28 07:35 PM Re: Server available script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Next improvement request:

INI file contains list of default services to be monitored on each server, ptentially be overridden by server-specific list.
_________________________
There are two types of vessels, submarines and targets.

Top
#77252 - 2003-10-28 07:42 PM Re: Server available script
Richard H. Administrator Offline
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 Offline
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. [Eek!]

Ouch.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.069 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org