'Auto create Tickets into Unicenter Service Desk, uses Nagios + NRPE_NT to pass parameters from alarms 'Author: Felipe Ferreira Date: 24/02/2009 Version: 1.0 'BUG: Resume filed will not accept spaces 'TODO: '1-Allow username to be in arguments '2-CAll exit error if cannot create '3-Also send an email to a group 'HOwto: 'Define: nrpe.cfg to use this script 'command[create_ticket]=cscript //Nologo c:\nrpe_nt\plugins\sd.vbs $ARG1$ 'Call from nagios server: './check_nrpe -H 192.168.3.228 -t 30 -c create_ticket -a "-G HD1 -T I -C Comunicaciones.ADSL -A avdarie -P Urgente -S Resumo_del_problema ''D Descricion de la cosa toda SWAJ21312" Dim Verbose : Verbose = 0 '----------NAGIOS VARs Const intOK = 0 Const intWarning = 1 Const intCritical = 2 Const intError = 3 '-----------other vars Dim strScriptFile : strScriptFile = WScript.ScriptFullname Dim strScriptPath : strScriptPath = Left(strScriptFile, Len(strScriptFile) - Len(WScript.Scriptname)) Dim outputfile : outputfile= strScriptPath & "AutoTicket.txt" Dim ofso : Set ofso = CreateObject("Scripting.FileSystemObject") Dim outfile: Set outfile = ofso.CreateTextFile(outputfile, True) dim username : username="fferreira" 'Could be dynamic '----------ARGUMENT VALUES Dim argcountcommand Dim arg(60) Dim desc ' for special description fields (SPACE PROBLEM) GetArgs() If Wscript.Arguments.Count = 0 then help() wscript.quit(intError) else strGroup = GetOneArg("-G") strType = GetOneArg("-T") strCategory= GetOneArg("-C") strAssignee=GetOneArg("-A") strPriority=GetOneArg("-p") strSummary=GetOneArg("-S") strDescription=GetOneArg("-D") end if 'write to temp txt file, check if empty? or test empty fields outfile.writeline "%GROUP="& strGroup outfile.writeline "%TYPE="& strType outfile.writeline "%CATEGORY="& strCategory outfile.writeline "%ASSIGNEE="& strAssignee outfile.writeline "%PRIORITY="& strPriority outfile.writeline "%SUMMARY="& strSummary call GetDArg() outfile.writeline "%DESCRIPTION="& chr(34) & strDescription & chr(34) wscript.sleep 40 outfile.close 'execute the cmd with the txt file strExec = "pdm_text_cmd -t Request -u " & username & " -o NEW -f " & outputfile exec(strExec) wscript.quit '-----------------FUNCTIONS AND SUBS-------------------- function exec(Command) on error resume next dim strCmd dim objShell : Set objShell = WScript.CreateObject("WScript.Shell") strCmd = Command ptn "Executing: " & strCmd Dim objExecObject : Set objExecObject = objShell.Exec(strCmd) Do While objExecObject.Status <> 1 wscript.sleep 10000 Wscript.StdOut.Write(".") Loop if err.number = 0 and objExecObject.Status = 1 then ptn "Incidencia creada" else ptn "Error creating Incident: " & strcmd & " Error : " & err.Description end if end function Function GetArgs() 'Get ALL arguments passed to the script 'On Error Resume Next Dim f argcountcommand = WScript.Arguments.Count ptn "Arguments Debug Mode:" for f = 0 to argcountcommand - 1 arg(f)=WScript.Arguments(f) if arg(f) = "-D" then ptn "GOT - at: " & f & " - " & arg(f) desc=f end if ptn f & " - " & arg(f) next End Function 'must get array value between on - and next - Function GetOneArg(strName) On Error Resume Next Dim i for i=0 to argcountcommand - 1 if (Ucase(arg(i))=Ucase(strName)) then 'Do while arg(i) <> "-" ' ptn arg(i+1) ' i = i +1 'loop GetOneArg=arg(i+1) Exit Function end if next End Function Function GetDArg() 'Function to get the description argument passed without "" will get untill end of arguments array On Error Resume Next Dim l for l=desc to argcountcommand - 1 ptn desc & " Array Description=" & arg(l+1) strDescription= strDescription & " " & arg(l+1) next End Function Function ptn(msgTxt) 'Prints msg on screen only if Verbose is set if Verbose = 1 then wscript.echo msgTXT end if end Function