I first thought it was a permission issue as the spreadsheet was on a external sharepoint website. So I changed the NSClient service to be run as an account with access to the file, still didn't work. Have now copied it to the NSClient++ directory to rule out any permission issues.c:\program files\NSClient++\scripts\CheckOracle.vbs(25, 1) Microsoft Excel: Microsoft Excel cannot access the file 'c:\program files\NSClient++\Scripts\oracle.xlsx'. There are several possible reasons:
The file name or path does not exist.
The file is being used by another program.
The workbook you are trying to save has the same name as a currently open workbook.
The script works fine if run manually on the host but not when run with the check_nrpe command.
Code: Select all
'Get target data from command line
Set ObjArgs = WScript.Arguments
TargetData = ObjArgs(0)
'Target variables
'Free Desks
'No Desks
'Laptops
'Desktops
'iMac's
'Macbooks
'WinXP
'Win7
'Set filepath
TargetFile = "c:\program files\NSClient++\Scripts\oracle.xlsx"
'Set target by input box (Debug Purposes)
'TargetData = inputbox("What would you like to know?")
'Create the XL object to work with
Set xl = CreateObject("Excel.application")
'Open the XL spreadsheeet
Set objWorkBook = xl.Application.Workbooks.Open (TargetFile,1,True)
Set objWorkSheet = xl.ActiveWorkbook.WorkSheets("Counts")
xl.Application.Visible=False
'Pull the data from the counts sheet
FreeDesks = objWorkSheet.Range("B1").text
NoDesks = objWorkSheet.Range("B2").text
Laptops = objWorkSheet.Range("B3").text
Desktops = objWorkSheet.Range("B4").text
iMacs = objWorkSheet.Range("B5").text
Macbooks = objWorkSheet.Range("B6").text
WinXP = objWorkSheet.Range("B7").text
Win7 = objWorkSheet.Range("B8").text
'Shut it down and output results
xl.Application.quit
Set xl = Nothing
'Output all results in msgbox (Debug purposes)
'Msgbox("Free desks: " & FreeDesks & VbCrlf & "No Desks: " & NoDesks & VbCrlf & "Laptops: " & Laptops & VbCrlf & "Desktops: " & Desktops & VbCrlf & "iMac's " & iMacs & VbCrlf & "Macbooks: " & Macbooks & VbCrlf & "Windows XP: " & WinXP & VbCrlf & "Windows 7: " & Win7)
'Output result of query
If TargetData = "Free Desks" Then
Result = FreeDesks & ", desks free"
ElseIf TargetData = "No Desks" Then
Result = NoDesks & ", No desks"
ElseIf TargetData = "Laptops" Then
Result = Laptops & ", laptops"
ElseIf TargetData = "Desktops" Then
Result = Desktops & ", desktops"
ElseIf TargetData = "iMac's" Then
Result = iMacs & ", iMac's"
ElseIf TargetData = "Macbooks" Then
Result = Macbooks & ", Macbooks"
ElseIf TargetData = "WinXP" Then
Result = WinXP & ", Windows XP Machines"
ElseIf TargetData = "Win7" Then
Result = Win7 & ", Windows 7 Machines"
Else
Result = "Error!"
End If
WScript.Echo Result