Script to check services, check_services.vbs
I tried developing it so the services could be passed via arguments, but
using check_nt (NC_Net) and vbscript I found it impossible when we came along
multiple arguments containing spaces, its a shame 🙁 Maybe someone out there has done it.
I know a SNMP plugin that does it and I use it, but some servers are in cluster and SNMP
checks dont work well.
Anyways here is the code ( hardcoded services are in an array)

'Script to Check Multiple Services
'Usage: check_services.cvs "service 1","service2"
'By Felipe Ferreira 12/2011 www.felipeferreira.net Version 1.0 for NAGIOS
option explicit
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim outputmsg,outputmsgstats
Dim intExit
dim strScriptFile : strScriptFile = WScript.ScriptFullname
Dim svc,blnFound,intTSvc
Dim arrServices(13)
Dim strArgs
' ######## DEBUG
Dim verbose : verbose = 1
arrServices(0)="EAE_Housekeeper"
arrServices(1)="EAE Identity Server"
arrServices(2)="EAE InfoLight Main Server"
arrServices(3)="EAE InfoLight OpData Server"
arrServices(4)="EAE Net Task Server"
arrServices(5)="MaFlow Archive Manager "
arrServices(6)="MaFlow CS-OGL Manager"
arrServices(7)="MaflowData"
arrServices(8)="MaFlow PR-EAE Manager "
arrServices(9)="MaFlow RO-EAE Server"
arrServices(10)="MaFlow RsOgl Manager"
arrServices(11)="MaFlow Task Manager"
arrServices(12)="MaFlow TsOgl Manager"
arrServices(13)="MSSQL$MAFSQL"
'@@@@@@@@@@@HANDLES THE ARGUMENTS@@@@@@@@@@@@@@@
intTSvc = 0
for each svc in arrServices
	pt "SERVICO: " & svc
	call GetServices(svc)
	if (blnFound <> 1) then
	     wscript.echo "CRITICAL - Service " &  svc & " not running"
	      wscript.quit(intCritical)
	else
	      pt "OK - Service " &  svc & " running"
		  intTSvc = intTSvc + 1
	end if
	blnFound = 0
next
if (intTSvc > 0) then
	wscript.echo  "OK - " & intTSvc & " Services running"
	wscript.quit(intOK)
end if
wscript.quit(intUnknown)
Function GetServices(strComp)
'List all running services
   dim objService
   dim objWMIService : Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!localhostrootcimv2")
   Dim colRunningServices : Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service where Name like '"& strComp & "' and State = 'Running'")
   For Each objService In colRunningServices
   'pt objService.DisplayName & " running"
	 if objService.Status = "OK" then
      blnFound=1
	 end if
   Next
end function
Function pt(strTxt)
 if (verbose = 1 ) then
	wscript.echo strTxt
 end if
end function
Tags: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *