'Script to check the status of a DOMAIN controller and report to Nagios 'requires DCDIAG.EXE 'Author: Felipe Ferreira 'Version: 3.0 'For now just check all tests and report critical if one fails. 'If need to check just specific tests edit cmd variable and remove all checks vars. 'TODO: 'Get from args what to check, update status to 2 and also build the cmd line 'loop thru args and with a select update tests status to 2 Dim verbose : verbose = 0 '----------NAGIOS VARs Const intOK = 0 Const intWarning = 1 Const intCritical = 2 Const intError = 3 Dim cmd dim hostname 'State of Checks ( OK, or CRITICAL) Dim services : services = "CRITICAL" Dim replications : replications = "CRITICAL" Dim advertising : advertising = "CRITICAL" Dim fsmocheck : smocheck = "CRITICAL" Dim ridmanager : ridmanager = "CRITICAL" Dim machineaccount : machineaccount = "CRITICAL" '@@@@@@@@@@ MAIN CALLS @@@@@@@@@@@@@@ 'CMD Options are: dcdiag /test:services /test:replications /test:advertising /test:fsmocheck /test:ridmanager /test:machineaccount cmd = "dcdiag /test:services /test:replications /test:advertising /test:fsmocheck /test:ridmanager /test:machineaccount" call getname() call exec(cmd) call printout() '@@@@@@@@@@ FUNCTIONS @@@@@@@@@@@@@@@ function exec(strCmd) dim objShell : Set objShell = WScript.CreateObject("WScript.Shell") call pt( strCmd ) Dim objExecObject,lineout Set objExecObject = objShell.Exec(strCmd) Do While Not objExecObject.StdOut.AtEndOfStream lineout=LCASE(objExecObject.StdOut.ReadLine()) 'Each line output is sent to parse function to check for keywords and update status call parse(lineout) loop if err.number = 0 and objExecObject.Status = 1 then call pt("done") elseif (err.number <> 0 ) then wscript.echo("Error " & err.Description & " " & Err.number) end if end function function parse(txtp) 'Parse output of dcdiag command and change state of checks if instr(txtp,"passed test") then txtp = Replace(txtp,".","") pt "PASSED " & txtp txtp = Replace(txtp,"passed test","") txtp = Replace(txtp,hostname,"") txtp = trim(txtp) Select Case txtp case "services" services = "OK" case "replications" replications = "OK" case "advertising" advertising = "OK" case "fsmocheck" fsmocheck = "OK" case "advertising" advertising = "OK" case "ridmanager" ridmanager = "OK" case "machineaccount" machineaccount = "OK" end select elseif instr(txtp,"failed test") then txtp = Replace(txtp,".","") pt "FAIL " & txtp txtp = Replace(txtp,"failed test","") txtp = Replace(txtp,hostname,"") txtp = trim(txtp) Select Case txtp case "services" services = "CRITICAL" case "replications" replications = "CRITICAL" case "advertising" advertising = "CRITICAL" case "fsmocheck" fsmocheck = "CRITICAL" case "advertising" advertising = "CRITICAL" case "ridmanager" ridmanager = "CRITICAL" case "machineaccount" machineaccount = "CRITICAL" end select end if end function function printout() 'outputs result dim msg1,msg msg = "Services: " & services & " Replications: " & replications & " Advertising: " & advertising & " Fsmocheck: " &_ fsmocheck & " Ridmanager: " & ridmanager & " Machineaccount: " & machineaccount if instr(msg,"CRITICAL") then msg1 = "CRITICAL - " wscript.echo msg1 & msg wscript.quit(intCritical) else msg1 = "OK - " wscript.echo msg1 & msg wscript.quit(intOK) end if end function function getname() 'get NAME OF LOCAL PC dim objShell2 : Set objShell2 = WScript.CreateObject("WScript.Shell") Dim objExecObject2 Set objExecObject2 = objShell2.Exec("cmd /c hostname") Do While Not objExecObject2.StdOut.AtEndOfStream hostname = LCASE(objExecObject2.StdOut.ReadLine()) 'gets %userdomain% loop hostname=trim(hostname) pt hostname end function Function help() wscript.echo "checkdc.vbs - Nagios NRPE Plugin for Active Directory Health Check" & vbcrlf & _ "Version 3.0, By Felipe Ferreira www.felipeferreira.net" & vbcrlf & _ "Usage:" & vbcrlf & _ "checkdc.vbs " & vbcrlf & _ " :services, replications, advertising, fsmocheck, ridmanager, machineaccount" & vbcrlf & vbcrlf & _ "Checks domain controller functionality by using dcdiag tool from" & vbcrlf & _ "Windows Support Tools. Following dcdiag tests are performed" end function Function pt(msgTxt) 'Prints msg on screen only if Verbose is set if Verbose = 1 then wscript.echo msgTXT end if end Function