Page 1 of 2

Nagios captures only a single line output from VB script

Posted: Mon Nov 06, 2017 3:48 pm
by rifelixd
Hi Gurus,

I am quite new to scripting and Nagios. Kindly excuse if my sentence happen to make no sense. I am using currently using unlicensed version.
I need to passively capture software version from remote machines to XI server. I installed NSClient++ in the remote and sending my output to XI server via NCPA.

I tried using both WMI and VB script to pull the software versions. WMI does the job but Nagios displays only 32-bit software versions with a cut off 256 characters.
I followed the guide - https://support.nagios.com/kb/article.php?id=478 -- but only managed to change the output to 512 characters. I am not sure if this due to not licensed version.

VB script on the other hand runs with correct output on CMD but only displays a single line of information in Nagios Dashboard.

I need help to capture both 32bit and 64bit software version of my computer to be pushed passively to Nagios XI. Please help.

Code: Select all

-----------------
NSClient.ini file 
-----------------
[/settings/scheduler/schedules]
WMI Check = checkWMI "Query=Select Name,Version from Win32_Product"
VBS Check = versioncheck

[/settings/external scripts/scripts]
versioncheck = cscript.exe //T:30 //NoLogo scripts\\versioncheck.vbs

Code: Select all

----------
VB Script
----------
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")

For Each objSoftware in colSoftware
Wscript.Echo "Name= " & objSoftware.Name & ", " & "Version= " & objSoftware.Version & ", " & "Vendor= " & objSoftware.Vendor
Next
-------------------------------
Nagios XI Dashboard View
-------------------------------

Code: Select all

Service-------Status--------- Status Information
VBS Check-----Ok------------Name= Microsoft Application Error Reporting, Version= 12.0.6015.5000, Vendor= Microsoft Corporation

Code: Select all

WMI Check----Ok-------------Name=Microsoft Application Error ReportingVersion=12.0.6015.5000Name=Microsoft Access database engine 2010 (English)Version=14.0.7015.1000Name=VisualGPSVersion=4.2.105Name=MicrosoftAntimalwareVersion=3.0.8402.2Name=Microsoft Security ClientVersion=2.1.1116.0Name=Microsoft 
                                        .NETFramework 4.5Version=4.5.50709Name=WellSyncNVersion=8.2.0Name=SQL Server 2008 R2 SP2 Database Engine ServicesVersion=10.52.4000.0Name=Microsoft SQL Server 2008 R2 RsFx DriverVersion=10.52.4000.0Name=Microsoft Forefront Endpoint Prot

Re: Nagios captures only a single line output from VB script

Posted: Mon Nov 06, 2017 5:42 pm
by npolovenko
Hello, @ rifelixd. Have you tried running the VB plugin from the command line on your nagios server?Does the check return only one line of output or many?

You could try using output macro in this article:
https://assets.nagios.com/downloads/nag ... inapi.html

Also, can you upload the command definitions for check WMI and check VB scripts?

Re: Nagios captures only a single line output from VB script

Posted: Tue Nov 07, 2017 11:05 am
by rifelixd
Hi @npolovenko. Thank you for replying to my query. May i know how can I run the VB plugin from the Nagios Server? Should i be following this guide https://support.nagios.com/kb/article.php?id=528 ?

Re: Nagios captures only a single line output from VB script

Posted: Tue Nov 07, 2017 2:02 pm
by npolovenko
@rifelixd, Yes you can use this manual.
May i know how can I run the VB plugin from the Nagios Server? Should i be following this guide https://support.nagios.com/kb/article.php?id=528 ?
According to this manual, you can test the plugin by running the following command from your nagios server:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H your_windows_server_ip_address -c command
Please replace the IP address with your Windows Server ip address and command with the command name that you defined in nscclient.ini file.
Also, can you upload your check_processes.ini file here?

Re: Nagios captures only a single line output from VB script

Posted: Wed Nov 08, 2017 6:05 am
by rifelixd
npolovenko wrote:@rifelixd, Yes you can use this manual.
May i know how can I run the VB plugin from the Nagios Server? Should i be following this guide https://support.nagios.com/kb/article.php?id=528 ?
According to this manual, you can test the plugin by running the following command from your nagios server:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H your_windows_server_ip_address -c command
Please replace the IP address with your Windows Server ip address and command with the command name that you defined in nscclient.ini file.
Also, can you upload your check_processes.ini file here?
Hi @ npolovenko,
NRPE would not be used in my actual proposed environment as the the remote machines are NAT'ed behind the router IP and the XI server will be hosted on Internet space. So the idea would be only the remote machines sending updates to the XI server passively.

As of now, in my testing environment, both remote and server machines are connected to the same network so I will proceed to perform as requested. I have attached both .ini and .log file.

from XI server console
--------------------------
[root@localhost libexec]# ./check_nrpe -H 100.97.34.102 -c versioncheck
CHECK_NRPE: Socket timeout after 10 seconds.
[root@localhost libexec]# ./check_nrpe -H 100.97.34.102 -c versioncheck
CHECK_NRPE: Socket timeout after 10 seconds.

Re: Nagios captures only a single line output from VB script

Posted: Wed Nov 08, 2017 9:57 am
by mcapra
Do you know which version of NSClient++ you are using? There's some pretty substantial configuration differences between 0.3, 0.4, and 0.5.

Can you also share the complete contents of versioncheck.vbs? Assuming we're still in a place where we are not sure if it's the raw message length or the presence of newlines causing problems, you might also try modifying your VBScript to see if removing the newlines and concatenating everything into a single line at least gives you the full output on the Nagios XI side of things. My hunch is that the way the VBScript is handling newlines isn't jiving well with how NSClient++ interprets the output.

Regarding the WMI issue:
rifelixd wrote: I followed the guide - https://support.nagios.com/kb/article.php?id=478 -- but only managed to change the output to 512 characters. I am not sure if this due to not licensed version.
I don't know of any hard-cap within XI on status information beyond the one mentioned in that KB article. On the NSClient++ side of things, you might try fiddling with the payload length argument since that seems to be 512 by default, though I have absolutely no idea what the documentation I linked is getting at with the "NRPE agent" part.

Re: Nagios captures only a single line output from VB script

Posted: Wed Nov 08, 2017 12:42 pm
by npolovenko
Thanks, @mcapra.
In addition, I'd like to add that sometimes Nagios will not show multiple line output in Service status summary, but if you go to Service Details Page you should be able to see the rest of the output.
Take a look at this forum thread:
https://support.nagios.com/forum/viewto ... 53&p=40455

NRPE would not be used in my actual proposed environment as the the remote machines are NAT'ed behind the router IP and the XI server will be hosted on Internet space. So the idea would be only the remote machines sending updates to the XI server passively.
When you implement that architecture, I'd recommend using NCPA/NRDP plugin to send passive checks to XI. Here's the article on how to set one up:
https://assets.nagios.com/downloads/ncp ... gIGjfD_BwE

Re: Nagios captures only a single line output from VB script

Posted: Wed Nov 08, 2017 2:12 pm
by rifelixd
mcapra wrote:Do you know which version of NSClient++ you are using? There's some pretty substantial configuration differences between 0.3, 0.4, and 0.5. Can you also share the complete contents of versioncheck.vbs?
Hi @mcapra, I was using version 0.5.x but then WMI seems to be not working during my initial checks before testing with vb script. I later checked on one of the forum, it was told to use 0.4.x to resolve the issue. I am now using Nsclient version 0.4.1.90. I have also attached the vb script for your review.
npolovenko wrote:Thanks, @mcapra.
In addition, I'd like to add that sometimes Nagios will not show multiple line output in Service status summary, but if you go to Service Details Page you should be able to see the rest of the output.
Hi @npolovenko, I did checked into the service details page but it still shows the same single line of information. In my current setup, remote machines are sending these scripts passively to the XI server over NCPA.

Re: Nagios captures only a single line output from VB script

Posted: Thu Nov 09, 2017 11:18 am
by npolovenko
@rifelixd, I'm not a pro at basic programming. But I think you need to modify the script to save values of for each loop in array or append them to a string and only after the loop echo it all at once. That might help.

Code: Select all

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")

Dim myString
For Each objSoftware in colSoftware
myString = myString & "Name= " 
myString = myString & objSoftware.Name 
myString = myString & ", Version= " 
myString = myString & objSoftware.Version
myString = myString & ", Vendor= " 
myString = myString & objSoftware.Vendor
myString = myString & objSoftware.Vendor
myString = myString & vbCr
Next
WScript.Echo myString

Re: Nagios captures only a single line output from VB script

Posted: Fri Nov 10, 2017 1:06 pm
by rifelixd

Code: Select all

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")

Dim myString
For Each objSoftware in colSoftware
myString = myString & "Name= " 
myString = myString & objSoftware.Name 
myString = myString & ", Version= " 
myString = myString & objSoftware.Version
myString = myString & ", Vendor= " 
myString = myString & objSoftware.Vendor
myString = myString & objSoftware.Vendor
myString = myString & vbCr
Next
WScript.Echo myString
Thank you so much!!! @npolovenko. This works but characters that displaying on Dashboard are now limited to 512 words. I am currently checking on the payload length as advised by @mcapra