Page 1 of 2

Breaking the results in status information

Posted: Sat Dec 02, 2017 9:59 am
by rifelixd
https://support.nagios.com/forum/viewto ... 07#p237307

Hi @mcapra, @mcapra,
I am following up from the previous thread. The link is attached above.
Is there a way I can do for a more presentable display on the received results of my software version.

As of now it appears in a single line.

Code: Select all

Name= Service Pack 2 for SQL Server 2008 R2 (KB2630458) (64-bit), Version= 10.52.4000.0, Publisher= Microsoft Corporation Name= GDR 4042 for SQL Server 2008 R2 (KB3045313) (64-bit), Version= 10.52.4042.0, Publisher= Microsoft Corporation Name= System Center Endpoint Protection, Version= 4.10.209.0, Publisher= Microsoft Corporation Name= Microsoft SQL Server 2008 R2 (64-bit), Version= , Publisher= Microsoft Corporation Name= Microsoft SQL Server 2008 R2 (64-bit), Version= , Publisher= Microsoft Corporation
Is that possible me to display as below?

Code: Select all

Name= Service Pack 2 for SQL Server 2008 R2 (KB2630458) (64-bit), Version= 10.52.4000.0, Publisher= Microsoft Corporation 
Name= GDR 4042 for SQL Server 2008 R2 (KB3045313) (64-bit), Version= 10.52.4042.0, Publisher= Microsoft Corporation 
Name= System Center Endpoint Protection, Version= 4.10.209.0, Publisher= Microsoft Corporation 
Name= Microsoft SQL Server 2008 R2 (64-bit), Version= , Publisher= Microsoft Corporation 
Name= Microsoft SQL Server 2008 R2 (64-bit), Version= , Publisher= Microsoft Corporation
I am reattaching the initial working vb script from the previous thread.

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: Breaking the results in status information

Posted: Mon Dec 04, 2017 10:24 am
by mcapra
You could try using vbCrLf instead of vbCr:

Code: Select all

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=Impersonate}!\\" _
& strComputer & "\root\cimv2")
objWMIService.Security_.ImpersonationLevel = 3
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 & vbCrLf
Next
WScript.Echo myString
But that won't guarantee a multi-line output in the Nagios Core web interface. There's 3 layers of "difference" that need to be dealt with: VBScript, NSClient++, and Nagios Core's web interface. Hopefully a different VBScript new-line is all that is required.

Re: Breaking the results in status information

Posted: Mon Dec 04, 2017 12:12 pm
by kyang
Thanks @mcapra!

Re: Breaking the results in status information

Posted: Mon Dec 04, 2017 3:49 pm
by rifelixd
mcapra wrote:You could try using vbCrLf instead of vbCr
Hi @mcapra,
I missed to mention that I did tried vbCrLf previously but end up it shows a single line entry i.e as below:

Code: Select all

Name= Service Pack 2 for SQL Server 2008 R2 (KB2630458) (64-bit), Version= 10.52.4000.0, Publisher= Microsoft Corporation 
All information shows only if I use vbCr. :(

Re: Breaking the results in status information

Posted: Mon Dec 04, 2017 5:27 pm
by dwhitfield
Did you try vbNewLine? What version of VB is this?

Re: Breaking the results in status information

Posted: Wed Dec 06, 2017 10:57 am
by rifelixd
dwhitfield wrote:Did you try vbNewLine? What version of VB is this?
Hi @dwhitfield,

I have tried vbCrLf as well vbNewLine but the results shows a single string with a single entry of Name, Version and Publisher. When I apply run this vb from my cmd, the results shows fine but on Nagios, only vbCr pulls the entire information. The other 2 commands displays a single entry only.

I am not sure which version is this. The code is attached at the top of this thread.

Re: Breaking the results in status information

Posted: Wed Dec 06, 2017 11:03 am
by rifelixd
Hi Experts,

I am not sure if this should be reason for not allowing full text to displayed IF break command like vbCr or vbNewLine is applied in my script.
https://assets.nagios.com/downloads/nag ... viceoutput

I am seeing macros to be applied. If yes, could you please teach me how this can be applied in my environment?

Re: Breaking the results in status information

Posted: Wed Dec 06, 2017 5:16 pm
by npolovenko
@rifelixd, Please try to run the following version. I added <br> sign to the end of each loop. And since Nagios is using PHP for the front end, there's a chance that it might render the "special tag".

Code: Select all

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=Impersonate}!\\" _
& strComputer & "\root\cimv2")
objWMIService.Security_.ImpersonationLevel = 3
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
myString = myString & "\n" 
Next
WScript.Echo myString

Re: Breaking the results in status information

Posted: Thu Dec 07, 2017 9:31 am
by rifelixd
npolovenko wrote:@rifelixd, Please try to run the following version. I added <br> sign to the end of each loop. And since Nagios is using PHP for the front end, there's a chance that it might render the "special tag".
Hi @npolovenko,
Thank you for your suggestion. I have tried as advised but there the results appears same as I use vbCrLf.

Re: Breaking the results in status information

Posted: Thu Dec 07, 2017 4:34 pm
by npolovenko
@rifelixd , I think you're looking at the quick service overview. I'm pretty sure it's limited to one line only. But, if you actually click on the service hyperlink you'll see all lines. The following code worked for us, each entry was on a new line.

Code: Select all

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=Impersonate}!\\" _
& strComputer & "\root\cimv2")
objWMIService.Security_.ImpersonationLevel = 3
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 & vbCrLf
Next
WScript.Echo myString