NSClient++ VBS Script to Read Excel file

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Malcz86
Posts: 27
Joined: Thu Mar 17, 2011 11:17 am

NSClient++ VBS Script to Read Excel file

Post by Malcz86 »

We have a excel workbook we use as a asset list and I've tried writing a script to pull count data from a cell on the spreadsheet. The idea is to have a quick dashboard on Nagios with figures from the asset list. When I run the script straight from the Nagios box using, ./check_nrpe -H 10.2.10.231 -c check_OracleIT Win7 I get the below error.
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.
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.

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
NagiosXI 2011R1.9
CentOs 5.4
32bit
VMWare Image
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NSClient++ VBS Script to Read Excel file

Post by scottwilkerson »

Make sure checkExternalScripts.dll is enabled and try changing your NSClient++ command to begin with cscript

There are some documentation here
http://nsclient.org/nscp/wiki/CheckExternalScripts
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Malcz86
Posts: 27
Joined: Thu Mar 17, 2011 11:17 am

Re: NSClient++ VBS Script to Read Excel file

Post by Malcz86 »

CheckExternalScripts is enabled and I am using CScript.exe in the command.

The error message is generated by Excel so the command is running. There's just something different to the way the script is run when launched locally from within Windows and from when its launched via the NSClient.
NagiosXI 2011R1.9
CentOs 5.4
32bit
VMWare Image
Malcz86
Posts: 27
Joined: Thu Mar 17, 2011 11:17 am

Re: NSClient++ VBS Script to Read Excel file

Post by Malcz86 »

Done a bit of digging and am starting to wonder if its something to do with "interactive services", "interactive services" are disabled in Windows 2008 server. Also found the below chat log, which mentions NSClient and "interactive services".

http://www.bitchx.com/log/nagios-f/nagi ... 010-01.php
NagiosXI 2011R1.9
CentOs 5.4
32bit
VMWare Image
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NSClient++ VBS Script to Read Excel file

Post by scottwilkerson »

For this I think it may be best to check on the NSCLient++ Forum
http://www.nsclient.org/nscp/discussion
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked