'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' NAME: check_mqstatuschannel.vbs ' VERSION: 1.0 ' AUTHOR: Vinícius Campelo ' Alcides Lopes ' Rennan Vasconcelos ' Arthur Vasconcelos ' COMMENT: This script checks the current state channel and returning: ' OK -> RUNNING ' CRITICAL -> STOP or INATIVE ' WARNNING -> OTHERS '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '----------------------------------------------Block variable declarations------------------------------------------------------------------ Option explicit Dim objArgs 'Object with arguments Dim objShell 'Shell Object Dim objResposta 'Object with the command response Dim objRespostaCanal 'Object with the response of the command that verifies that the channel exists Dim objRespostaQM 'Object with the response of the command that checks whether the QM there Dim Comando 'String with the command to be executed in CMD Dim StringResposta 'String with the status of the channel Dim StringRespCanal 'String with the response that the channel was not found Dim StringRespostaQM 'String with the status of QM Dim RegResposta 'Regular Expression object filtering the channel status '---------------------------------------------Block regular expression to filter status------------------------------------------------------- Set RegResposta = New RegExp With RegResposta .Pattern = ".*STATUS\(([A-Z]+)\).*" .IgnoreCase = False .Global = False End With '----------------------------------------------Block catches the arguments---------------------------------------------------------------------- Set objArgs = WScript.Arguments '----------------------------------------------Block validation of the arguments---------------------------------------------------------------- If objArgs.Count < 2 Then Wscript.StdOut.WriteLine "CHECK_MQ STATUS CHANNEL Usage" Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "check_mqstatuschannel.vbs $Arg1 $Arg2" Wscript.StdOut.WriteLine "Arg1 = Queue Manager" Wscript.StdOut.WriteLine "Arg2 = Channel Name" Wscript.StdOut.WriteLine "" WScript.Quit(0) End if '----------------------------------------------Block checks------------------------------------------------------------------------------------- Set objShell = CreateObject("WScript.Shell") '########################################## The Queue Manager exist? ########################################################################### Comando = "cmd.exe /c dspmq -m " & objArgs(0) Set objRespostaQM = objShell.Exec(Comando) If objRespostaQM.StdOut.ReadLine() = "" Then Wscript.StdOut.WriteLine "UNKNOWN - The Queue Manager not exist!" WScript.Quit(3) End if '########################################## The Channel exist? ################################################################################# Comando = "cmd.exe /c echo dis CHANNEL(" & objArgs(1) & ") | runmqsc " & objArgs(0) & " | find ""AMQ8147"" " Set objRespostaCanal = objShell.Exec(Comando) StringRespCanal = objRespostaCanal.StdOut.ReadLine() If Left(StringRespCanal,7) = "AMQ8147" Then Wscript.StdOut.WriteLine "UNKNOWN - The Channel not exist!" WScript.Quit(3) End if '########################################## Checking the Channel status ######################################################################## Comando = "cmd.exe /c echo display CHSTATUS(" & objArgs(1) & ") | runmqsc " & objArgs(0) & " | find "" STATUS"" " Set objResposta = objShell.Exec(Comando) '---------------------------------------------Block granting the status value in the variable--------------------------------------------------- Do StringResposta = RegResposta.Replace(objResposta.StdOut.ReadLine(),"$1") Loop While Not objResposta.Stdout.atEndOfStream '======== If the Channel is in the Inactive state the answer will be empty. Monitoring heading alerts will be considered CRITICAL ============== if StringResposta = "" Then StringResposta = "STOPPED" End if '---------------------------------------------Block return the alert level---------------------------------------------------------------------- Select Case StringResposta Case "RUNNING" Wscript.StdOut.WriteLine "OK - Channel " & objArgs(1) & " of the queue manager " & objArgs(0) & " is running." WScript.Quit(0) Case "STOPPED" Wscript.StdOut.WriteLine "CRITICAL - Channel " & objArgs(1) & " of the queue manager " & objArgs(0) & " is stop/inactive." WScript.Quit(2) Case Else Wscript.StdOut.WriteLine "WARNING - Channel " & objArgs(1) & " of the queue manager " & objArgs(0) & " is trying to connect." WScript.Quit(1) End Select