﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
  <channel>
    <title>jStudios</title>
    <description>This is Pure Idiocracy</description>
    <link>http://blog.jstudios.us/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 2.5.0.6</generator>
    <language>en-GB</language>
    <blogChannel:blogRoll>http://blog.jstudios.us/opml.axd</blogChannel:blogRoll>
    <dc:creator>techpilot007</dc:creator>
    <dc:title>jStudios</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <item>
      <title>Documenting Specs of Existing Windows Servers</title>
      <description>&lt;p&gt;Every month we receive a bill from our Sister Company for the hosting of our servers. When we receive the bill we usually just check our records to see that the specs we have documented match what we are being billed for. This tedious task falls to our Director of Infrastructure.&lt;/p&gt;
&lt;p&gt;Since I started 7 months ago he has seen the power or scripting on Windows from the rough scripts I wrote in vbScript to gather IIS, HTTP information about our existing environment and the power of scripts being used to monitor our systems. So you can see where I am going with this. He asked on a Thursday afternoon if it were possible and if I had time to write him a script that would go out to our Windows servers and gather the specs that we incur charges for (CPU cores, Memory in GB, HDD in GB).&lt;/p&gt;
&lt;p&gt;As with all the scripts I write I take a look at what others have already done so that I don't recreate the wheel. I happened to find one script that would look at a single server and dump it's information in an excel file. The first thing I didn't like about this script was how the server information in the spreadsheet was placed vertically in the file meaning that column A was the field headings and column B was the server information. So I set about modifying the script to display the information in a horizontal fashion.&lt;/p&gt;
&lt;p&gt;The second thing that bothered me about this script was that it only worked for one server that you had to manually set in the script before you ran it. Manually editing the script every time it ran to get information on a different server was not something I could tolerate so how could anyone else. So I set about hacking apart some old scripts that I had created when I started 7 months ago. The result was a script that could read a text file filled with server names and reach out to them placing their information in the excel file. The text file looked like this:&lt;/p&gt;
&lt;pre class="brush: plain;"&gt;WindowsServer01
WindowsServer02
WindowsServer03&lt;/pre&gt;
&lt;p&gt;At this point I decided I would customize what I was looking for. The script I originally started with was grabbing the bios information. Frankly for what we need to know the Bios information was unnecessary along with a few other specs. I then came to realize that the hard disk information was not in this script. Luckily I had another script that I could use code from to accomplish this task (a vbScript that I wrote to grab HDD info for Nagios).&lt;/p&gt;
&lt;p&gt;After all of that I thought I was done since it was working on every box I tried it on. So I sent it on to the Director. I had finished the script by noon on the Monday following his initial request. The first time he ran it he received an error. I was stumped at first but then came to realize that he didn't have access to one of the servers in his list. As with anything you find broken it's best to fix it when you find so you don't forget about it. I wanted the script to continue to execute for the rest of the servers in the list with only making note in the table that it was unable to access/find the server. With this new requirement I set about adding two functions that try to find the server and then checks to see that it has permission to get information on that server. If either of those two functions fails then the reason for failure is listed in the spreadsheet and the script moves on to the next server.&lt;/p&gt;
&lt;p&gt;My completed script looked like this:&lt;/p&gt;
&lt;pre class="brush: vb;"&gt;Dim strCompList
Dim strComputer
Const ForReading = 1

strComputer = ""
strCompList = "WindowsServers.txt"

IF WScript.Arguments.Length &amp;gt;= 1 THEN
    strSiteList = WScript.Arguments( 0 )
END IF

Set objFSO = CreateObject("Scripting.FileSystemObject")
sCurPath = unescape(objFSO.GetAbsolutePathName(".") &amp;amp; "\")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile (sCurPath &amp;amp; strCompList, ForReading)
strText = objTextFile.ReadAll
objTextFile.Close

strFileName = year(date) &amp;amp; "-" &amp;amp; month(date) &amp;amp; "-" &amp;amp; Day(Date) &amp;amp; "_" &amp;amp; Hour(Now()) &amp;amp; Minute(Now()) &amp;amp; ".xls"

arrComputers = Split(strText, vbCrLf)

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True
objExcel.Workbooks.Add

'Name the columns
objExcel.Cells(1, 1).Value = "Name"
objExcel.Cells(1, 2).Value = "Caption"
objExcel.Cells(1, 3).Value = "Version" 
objExcel.Cells(1, 4).Value = "Serial Number" 
objExcel.Cells(1, 5).Value = "Description" 
objExcel.Cells(1, 6).Value = "Domain" 
objExcel.Cells(1, 7).Value = "Manufacturer" 
objExcel.Cells(1, 8).Value = "Model" 
objExcel.Cells(1, 9).Value = "Number Of Processors" 
objExcel.Cells(1, 10).Value = "System Type" 
objExcel.Cells(1, 11).Value = "Total Physical Memory" 
objExcel.Cells(1, 12).Value = "HDD Space"

intDataRow = 1

For Each strComputer in arrComputers

	Dim intGigs
	Dim intCapUsed
	Dim intCapSize
	Dim intCapFree
	Dim intPerCapUsed
	Dim strDeviceInfo
	Dim strAllDeviceInfo
	intGigs = 1073741824
	intCapUsed = 0
	intCapSize = 0
	intCapFree = 0
	intPerCapUsed = 0
	strDeviceInfo = ""
	strAllDeviceInfo = ""

	intDataRow = intDataRow + 1

	If Ping(strComputer) Then
		
		If Permission(strComputer) Then
			
			Set objWMIService = GetObject("winmgmts:\\" &amp;amp; strComputer &amp;amp; "\root\cimv2")
			Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
			For Each objItem in colItems
			objExcel.Cells(intDataRow, 1).Value = objItem.CSName
			objExcel.Cells(intDataRow, 2).Value = objItem.Caption
			objExcel.Cells(intDataRow, 3).Value = objItem.Version
			objExcel.Cells(intDataRow, 4).Value = objItem.SerialNumber
			objExcel.Cells(intDataRow, 5).Value = objItem.Description

			Next

			Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
			For Each objItem in colItems
			objExcel.Cells(intDataRow, 6).Value = objItem.Domain
			objExcel.Cells(intDataRow, 7).Value = objItem.Manufacturer
			objExcel.Cells(intDataRow, 8).Value = objItem.Model
			objExcel.Cells(intDataRow, 9).Value = objItem.NumberOfProcessors
			objExcel.Cells(intDataRow, 10).Value = objItem.SystemType
			objExcel.Cells(intDataRow, 11).Value = FormatNumber((objItem.TotalPhysicalMemory / intGigs),2) &amp;amp; " GB"

			Next

			Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp;amp; strComputer &amp;amp; "\root\cimv2")
			Set colDisks = objWMIService.ExecQuery("select * from Win32_LogicalDisk where DriveType='3'")
			For Each objDisk in colDisks
			intCapSize = objDisk.Size / intGigs
			intCapFree = objDisk.Freespace / intGigs
			intCapUsed = intCapSize - intCapFree
			intPerCapUsed = (intCapUsed / intCapSize) * 100
				if IsNull(intPerCapUsed) Then
					intPerCapUsed = CInt(0)
				else
					intPerCapUsed = CInt((intCapUsed / intCapSize) * 100)
				end if
				if IsNumeric(intCapSize) Then
					intCapSize = FormatNumber(intCapSize,2)
				end if
				
				if IsNumeric(intCapUsed) Then
					intCapUsed = FormatNumber(intCapUsed,2)
				end if
			strDeviceInfo = objDisk.DeviceID &amp;amp; " (Used " &amp;amp; intCapUsed &amp;amp; " GB of " &amp;amp; intCapSize &amp;amp; " GB)"

			if strAllDeviceInfo &amp;lt;&amp;gt; "" Then
				strAllDeviceInfo =  strDeviceInfo &amp;amp; ", " &amp;amp; strAllDeviceInfo
			else
				strAllDeviceInfo = strDeviceInfo
			end if
					
			Next

			objExcel.Cells(intDataRow, 12).Value = strAllDeviceInfo
		Else
			intDataColumns = 1
			objExcel.Cells(intDataRow, 1).Value = strComputer
			objExcel.Cells(intDataRow, 2).Value = "Time out or Permission Denied"
			For intDataColumns = 3 to 12
				objExcel.Cells(intDataRow, intDataColumns).Value = "N/A"
			Next
		End If
	Else
		intDataColumns = 1
		objExcel.Cells(intDataRow, 1).Value = strComputer
		objExcel.Cells(intDataRow, 2).Value = "Cannot Find Server"
		For intDataColumns = 3 to 12
			objExcel.Cells(intDataRow, intDataColumns).Value = "N/A"
		Next
	End If

Next

objExcel.Range("A1:L1").Select
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
objExcel.DefaultFilePath = sCurPath
objExcel.ActiveWorkBook.SaveAs strFileName, -4143


MsgBox "Done"

'Functions
Function Ping(Target)
Dim results

    On Error Resume Next

    Set shell = CreateObject("WScript.Shell")
    
    ' Send 1 echo request, waiting 2 seconds for result 
    Set exec = shell.Exec("ping -n 1 -w 2000 " &amp;amp; Target)
    results = LCase(exec.StdOut.ReadAll)
    
    Ping = (InStr(results, "reply from") &amp;gt; 0)
End Function

Function Permission(strServer)
Dim objWMIService
	' Err.Clear ' redundant code
	' VBScript calls the Clear method automatically whenever On Error Resume Next statement is executed
	On Error Resume Next
	Set objWMIService = GetObject("winmgmts:\\" &amp;amp; strServer &amp;amp; "\root\CIMV2")

	Select Case Err.Number
	  Case 0
		' Success
		Permission = True
	  Case 70
		' Run-time error '70': Permission denied
		Permission = False
	  Case 462
		' The remote server machine does not exist or is unavailable
		Permission = False
	  Case -2147217375
		' Unknown/undocumented runtime error (till this time)
		' The remote server machine name was assigned erroneously
		Permission = False
		'Wscript.echo "&amp;gt;&amp;gt;" &amp;amp; strServer &amp;amp; "&amp;lt;&amp;lt;", "Run-time error '-2147217375' (undocumented runtime error)", "Error # " &amp;amp; CStr(Err.Number)
	  Case Else
		' Unhandled Run-time error (till this time)
		Permission = False
		'Wscript.echo "&amp;gt;&amp;gt;" &amp;amp; strServer &amp;amp; "&amp;lt;&amp;lt;", "Unhandled Run-time error # " &amp;amp; CStr(Err.Number) &amp;amp; " " &amp;amp; Err.Description
	End Select
	Err.Clear
	On Error GoTo 0
End Function&lt;/pre&gt;</description>
      <link>http://blog.jstudios.us/post/2012/05/15/Documenting-Specs-of-Existing-Windows-Servers.aspx</link>
      <comments>http://blog.jstudios.us/post/2012/05/15/Documenting-Specs-of-Existing-Windows-Servers.aspx#comment</comments>
      <guid>http://blog.jstudios.us/post.aspx?id=f114eb10-b3bc-45e9-85ef-ea507a179fff</guid>
      <pubDate>Tue, 15 May 2012 23:56:00 -0500</pubDate>
      <category>General</category>
      <category>Windows</category>
      <dc:publisher>techpilot007</dc:publisher>
      <pingback:server>http://blog.jstudios.us/pingback.axd</pingback:server>
      <pingback:target>http://blog.jstudios.us/post.aspx?id=f114eb10-b3bc-45e9-85ef-ea507a179fff</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://blog.jstudios.us/trackback.axd?id=f114eb10-b3bc-45e9-85ef-ea507a179fff</trackback:ping>
      <wfw:comment>http://blog.jstudios.us/post/2012/05/15/Documenting-Specs-of-Existing-Windows-Servers.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.jstudios.us/syndication.axd?post=f114eb10-b3bc-45e9-85ef-ea507a179fff</wfw:commentRss>
    </item>
    <item>
      <title>Monitoring Multiple Simular Windows Services with one Script</title>
      <description>&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;One of the first things I was asked to monitor with Nagios was the running state of a few Windows services.&lt;span&gt;&amp;nbsp; &lt;/span&gt;I could use NRPE to accomplish this but I found that I also needed to monitor the status of a few different versions of Tomcat for out Business Object servers.&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The built in NRPE checks with Nagios and NSClient++ require you to use the exact name of the service when you make the call for the service&amp;rsquo;s status.&lt;span&gt;&amp;nbsp; &lt;/span&gt;The name of the Tomcat service varies with the different versions of B.O., ex. BOEXI40Tomcat, BOE120Tomcat. Because of the different names with the versions we have I liked the idea of only having one service definition in Nagios to check on the various Tomcat Services.&lt;span&gt;&amp;nbsp; &lt;/span&gt;This is where my custom wsf (vbScript) came into play.&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;WMI queries allow you to use a SELECT statement that matches on a LIKE condition.&lt;span&gt;&amp;nbsp; &lt;/span&gt;When matching with a LIKE condition you can use a variable in the value you are querying for.&lt;span&gt;&amp;nbsp; &lt;/span&gt;It&amp;rsquo;s very similar to using a LIKE query in MS SQL Server.&lt;span&gt;&amp;nbsp; &lt;/span&gt;The variable operator to use in this case would be the percent symbol &amp;lsquo;%&amp;rsquo;.&lt;span&gt;&amp;nbsp; &lt;/span&gt;This allows you to make a WMI query that looks like this:&lt;/p&gt;
&lt;pre class="brush: sql;"&gt;"SELECT * FROM Win32_Service WHERE Name Like 'BOE%Tomcat'&lt;/pre&gt;
&lt;p class="brush: vb;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;As with most of the scripts I create I like to make them flexible enough to use for more than just one purpose. With that in mind I setup the script to accept a command line variable (s:/Service_Name).&lt;/p&gt;
&lt;pre class="brush: plain;"&gt;cscript check_services.wsf /s:BOE%Tomcat&lt;/pre&gt;
&lt;p class="MsoNormal"&gt;The output from the script gives Nagios not only a string of information but also an exit status/code. The string that the script outputs uses the service states as documented by MSDN. Below are those service states and the exit status(es)/code(s) that I've associated with them.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;"Start Pending" Exit Status = 1&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Running" Exit Status = 0&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Stop Pending" Exit Status = 1&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Stopped" Exit Status = 2&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Pause Pending" Exit Status = 1&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Paused" Exit Status = 2&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Continue Pending" Exit Status = 1&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Unknown" Exit Status =3&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The output also included performance data for Nagios so we can use our graphing tool to visualize the stability of the service. (Graphing seems to be easier on the eyes for many) An example of the output produced by the script is:&lt;/p&gt;
&lt;pre class="brush: plain;"&gt;Service: BOEXI40Tomcat : Running | service_running=2;1;0&lt;/pre&gt;
&lt;p class="MsoNormal"&gt;The complete script is below. As with every script I've created I'm sure there are better ways of accomplishing the same task but this is what I came up with.&lt;/p&gt;
&lt;pre class="brush: vb;"&gt;'
'***********************************************************************
' "check_service.wsf"
' Checks for service status on a Windows platform.
'************************************************************************
' Copyright (c) 2012 Jeremy McEachron (techpilot007)
' All rights reserved.
'
' Redistribution and use in source and binary forms, with or without
' modification, are permitted provided that the following conditions
' are met:
' 1. Redistributions of source code must retain the above copyright
'    notice, this list of conditions and the following disclaimer.
' 2. Redistributions in binary form must reproduce the above copyright
'    notice, this list of conditions and the following disclaimer in the
'    documentation and/or other materials provided with the distribution.
'
' THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
' ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
' ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
' FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
' DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
' OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
' HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
' LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
' OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
' SUCH DAMAGE.
'

&amp;lt;job&amp;gt;
&amp;lt;runtime&amp;gt;
  &amp;lt;description&amp;gt;

check_services (nrpe_nt-plugin) 1.5
This nrpe_nt plugin come with ABSOLUTELY NO WARRANTY. You may redistribute
copies of the plugins under the terms of the GNU General Public License.

  &amp;lt;/description&amp;gt;
    &amp;lt;named
      name="h"
      helpstring="Help"
      type="simple"
      required="false" 
    /&amp;gt;
  /&amp;gt;

  &amp;lt;example&amp;gt;
         
  You need to provide a string for this plugin.
         	
  This script checks the current status of a specified service. If using a wildcard character 
  for the name of your service then you need to use the percent symbol (%).
    
  Usage: command[check_services]=c:\Windows\system32\cscript.exe //nologo //T:60 check_services.wsf "$ARG1$"
  cscript check_services.wsf /s:explorer

  &amp;lt;/example&amp;gt;

&amp;lt;/runtime&amp;gt;

&amp;lt;script language="VBScript"&amp;gt;


'*******************************************************************
' Help
'*******************************************************************
If Wscript.Arguments.Named.Exists("h") Then
      Wscript.Echo "Plugin help screen:"
      Wscript.Arguments.ShowUsage()
      Wscript.Quit(3)
End If

'*******************************************************************
' Main
'*******************************************************************


Dim OutputCode, objWMIService, colItems, ComputerName, strOutput, ServiceFound

' Default to an UNKNOWN error
OutputCode = 3

' Have we found this service yet?
ServiceFound = 0

args = WScript.Arguments.Count

If args &amp;lt; 1 Then
   WScript.Echo "Usage:  check_services.vbs [service name]"
   WScript.Echo ""
   WScript.Echo "Note:  The service name is the name listed in the properties of the"
   WScript.Echo "       service and is case sensitive."
   WScript.Echo ""
   WScript.Quit( OutputCode )
End If

'*******************************************************************
' load args
'*******************************************************************
Set colNamedArguments = WScript.Arguments.Named
intServiceName = colNamedArguments.Item("s")

ComputerName = "."

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp;amp; ComputerName &amp;amp; "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name Like '" &amp;amp; intServiceName &amp;amp; "'",,48) 
	
' Attempt to enumerate the IIS sites.  However, if IIS is not installed on this
' host, it will give us a runtime error with GetObject.  Skip the error if we
' get it with 'On Error Resume Next', and then we can trap the problem below
Err.Clear

' Work our way through the list of sites and find the one we're looking at, if 
' possible.  I'm sure there is a better way to do this.
For Each objItem in colItems
         ServiceFound = 1
         strOutput = "Service: " &amp;amp; objItem.Name
         '
		 ' Services States, per MSDN
		 ' 
		 ' "Start Pending"
		 ' "Running"
		 ' "Stop Pending"
		 ' "Stopped"
		 ' "Pause Pending"
		 ' "Paused"
		 ' "Continue Pending"
		 ' "Unknown"

         Select Case objItem.State
            Case "Start Pending"
               strOutput = strOutput &amp;amp; " : Start Pending | service_running=1;1;0"
               OutputCode = 1
            Case "Running"
               strOutput = strOutput &amp;amp; " : Running | service_running=2;1;0"
               OutputCode = 0
            Case "Stop Pending"
               strOutput = strOutput &amp;amp; " : Stop Pending | service_running=1;1;0"
               OutputCode = 1
            Case "Stopped"
               strOutput = strOutput &amp;amp; " : Stopped | service_running=0;1;0"
               OutputCode = 2
            Case "Pause Pending"
               strOutput = strOutput &amp;amp; " : Pause Pending | service_running=1;1;0"
               OutputCode = 1
            Case "Paused"
               strOutput = strOutput &amp;amp; " : Paused | service_running=0;1;0"
               OutputCode = 2
            Case "Continue Pending"
               strOutput = strOutput &amp;amp; " : Continue Pending | service_running=1;1;0"
               OutputCode = 1
            Case else
                    strOutput = strOutput &amp;amp; " : UNKNOWN STATE " &amp;amp; objItem.State &amp;amp; " | service_running=0;1;0"
         End Select
Next

' If we didn't find a Service, error out
If ServiceFound &amp;lt;&amp;gt; 1 Then
   strOutput = "UNKNOWN: Service " &amp;amp; intServiceName &amp;amp; " not found | service_running=0;1;0"
   OutputCode = 3
End If

WScript.Echo strOutput
WScript.Quit( OutputCode )
'*******************************************************************
&amp;lt;/script&amp;gt;
&amp;lt;/job&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
      <link>http://blog.jstudios.us/post/2012/05/08/Monitoring-Multiple-Simular-Windows-Services-with-one-Script.aspx</link>
      <comments>http://blog.jstudios.us/post/2012/05/08/Monitoring-Multiple-Simular-Windows-Services-with-one-Script.aspx#comment</comments>
      <guid>http://blog.jstudios.us/post.aspx?id=8e119216-2a94-4f1b-95e8-9c796e23209b</guid>
      <pubDate>Tue, 08 May 2012 16:44:00 -0500</pubDate>
      <category>Monitoring</category>
      <category>Nagios</category>
      <category>SQL</category>
      <category>Windows</category>
      <dc:publisher>techpilot007</dc:publisher>
      <pingback:server>http://blog.jstudios.us/pingback.axd</pingback:server>
      <pingback:target>http://blog.jstudios.us/post.aspx?id=8e119216-2a94-4f1b-95e8-9c796e23209b</pingback:target>
      <slash:comments>23</slash:comments>
      <trackback:ping>http://blog.jstudios.us/trackback.axd?id=8e119216-2a94-4f1b-95e8-9c796e23209b</trackback:ping>
      <wfw:comment>http://blog.jstudios.us/post/2012/05/08/Monitoring-Multiple-Simular-Windows-Services-with-one-Script.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.jstudios.us/syndication.axd?post=8e119216-2a94-4f1b-95e8-9c796e23209b</wfw:commentRss>
    </item>
    <item>
      <title>Monitoring B.O. Web Intelligence Servers</title>
      <description>&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-family: Tahoma; font-size: small;"&gt;A few months ago we started to have some issues where we would find that one or more Web Intelligence (Webi server) servers in Business Objects on a physical Windows server would stop. I was asked to come up with a way to monitor the number of Webi&amp;rsquo;s on the physical server using Nagios.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;Because not all of our machines are running the same version of Powershell I decided to go with vbScript in a wsf.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;I call the wsf using Nagios and NSClient++. The script allows for the input of a few command line arguments (/s:Name_of_Process, /w:Warning_Level, /c:Critical_Level). An example of the command to call the script is:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre class="brush: plain;"&gt;cscript check_BOWebiProcess.wsf /s:explorer /w:1 /c:0&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-family: Tahoma; font-size: small;"&gt;In the NSC.ini file I added this line.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre class="brush: plain;"&gt;check_BOWebiProcess=cscript.exe //nologo //T:60 check_BOWebiProcess.wsf "$ARG1$" "$ARG2$" "$ARG3$"&lt;/pre&gt;
&lt;p&gt;&lt;span style="font-family: Tahoma; font-size: small;"&gt;I've included the script below. Let me know what you think, leave your thoughts in the comments section below.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre class="brush: vb;"&gt;'
'***********************************************************************
' "check_BOWebiProcess.wsf"
' Checks for service status on a Windows platform.
'************************************************************************
' Copyright (c) 2012 Jeremy McEachron (techpilot007)
' All rights reserved.
'
' Redistribution and use in source and binary forms, with or without
' modification, are permitted provided that the following conditions
' are met:
' 1. Redistributions of source code must retain the above copyright
'    notice, this list of conditions and the following disclaimer.
' 2. Redistributions in binary form must reproduce the above copyright
'    notice, this list of conditions and the following disclaimer in the
'    documentation and/or other materials provided with the distribution.
'
' THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
' ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
' ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
' FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
' DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
' OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
' HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
' LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
' OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
' SUCH DAMAGE.
'

&amp;lt;job&amp;gt;
&amp;lt;runtime&amp;gt;
  &amp;lt;description&amp;gt;

check_services (nrpe_nt-plugin) 1.5
This nrpe_nt plugin come with ABSOLUTELY NO WARRANTY. You may redistribute
copies of the plugins under the terms of the GNU General Public License.

  &amp;lt;/description&amp;gt;
    &amp;lt;named
      name="h"
      helpstring="Help"
      type="simple"
      required="false" 
    /&amp;gt;
  /&amp;gt;

  &amp;lt;example&amp;gt;
         
  You need to provide a string for this plugin.
         	
  This script checks the current status of a specified service. If using a wildcard character 
  for the name of your service then you need to use the percent symbol (%).
  
  w = Number of processes to trigger warning state
  c = Number of processes to trigger critical state

  Usage: command[check_BOWebiProcess]=c:\Windows\system32\cscript.exe //nologo //T:60 check_BOWebiProcess.wsf "$ARG1$" "$ARG2$" "$ARG3$"
  cscript check_BOWebiProcess.wsf /s:explorer /w:1 /c:0

  &amp;lt;/example&amp;gt;

&amp;lt;/runtime&amp;gt;

&amp;lt;script language="VBScript"&amp;gt;


'*******************************************************************
' Help
'*******************************************************************
If Wscript.Arguments.Named.Exists("h") Then
      Wscript.Echo "Plugin help screen:"
      Wscript.Arguments.ShowUsage()
      Wscript.Quit(3)
End If

'*******************************************************************
' Main
'*******************************************************************


Dim OutputCode, objWMIService, colItems, ComputerName, strOutput, ServiceFound

' Default to an UNKNOWN error
OutputCode = 3

' Have we found this site yet?
ServiceFound = 0

args = WScript.Arguments.Count

If args &amp;lt; 1 Then
   WScript.Echo "Usage:  check_services.vbs [service name]"
   WScript.Echo ""
   WScript.Echo "Note:  The service name is the name listed in the properties of the"
   WScript.Echo "       service, NOT the virtual host name or IIS site number,"
   WScript.Echo "       and is case sensitive."
   WScript.Echo ""
   WScript.Quit( OutputCode )
End If

'*******************************************************************
' load args
'*******************************************************************
Set colNamedArguments = WScript.Arguments.Named
strServiceName = colNamedArguments.Item("s")
intWarningLevel = CInt(colNamedArguments.Item("w"))
intCriticalLevel = cInt(colNamedArguments.Item("c"))

ComputerName = "."

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp;amp; ComputerName &amp;amp; "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name Like '" &amp;amp; strServiceName &amp;amp; "'")
	
Err.Clear


'output code 0 = OK
'output code 1 = Warning
'output code 2 = Critical
'output code 2 = Unknown

intProcesses = colItems.Count
intIndex = 0
intstatus = 0

' Gather info on each matching process.
For Each objItem in colItems
        ServiceFound = 1
	intIndex = intIndex + 1

	strProcessInfo = objItem.Name &amp;amp; "(" &amp;amp; intIndex &amp;amp; ")" &amp;amp; " ProcessID: " &amp;amp; objItem.ProcessId &amp;amp; " Memory: " &amp;amp; (objItem.WorkingSetSize / 1024) &amp;amp; " KB"
	strProcessPerfInfo = " '" &amp;amp; objItem.Name &amp;amp; "(" &amp;amp; intIndex &amp;amp; ") Memory KB'=" &amp;amp; (objItem.WorkingSetSize / 1024) &amp;amp; "KB"

	'WSCript.Echo objItem.Name &amp;amp; "(" &amp;amp; intIndex &amp;amp; ") " &amp;amp; objItem.ProcessId &amp;amp; " " &amp;amp; (objItem.WorkingSetSize / 1024) &amp;amp; " K"
        
	if strAllProcessInfo &amp;lt;&amp;gt; "" Then
  	        strAllProcessInfo =  strProcessInfo &amp;amp; ", " &amp;amp; vbCRLF &amp;amp; strAllProcessInfo
		strAllProcessPerfInfo =  strProcessPerfInfo &amp;amp; strAllProcessPerfInfo
	else
  	    	strAllProcessInfo = strProcessInfo
		strAllProcessPerfInfo = strProcessPerfInfo
	end if

Next

if intProcesses &amp;lt;= intCriticalLevel Then	
	   intstatus = 2
	   strResultError = "The number of processes is at or below the Critical Level of " &amp;amp; intCriticalLevel &amp;amp; " processes."	
ElseIf intProcesses &amp;lt;= intWarningLevel Then
           intstatus = 1
           strResultWarning = "The number of processes is at or below the Warning Level of " &amp;amp; intWarningLevel &amp;amp; " processes."
end if

Select Case intstatus
  Case 0 wscript.echo "Number of processes is good. Process(es) checked: " &amp;amp; vbCRLF &amp;amp; strAllProcessInfo &amp;amp; "|" &amp;amp; strAllProcessPerfInfo
         wscript.quit(0)
  Case 1 wscript.echo strResultWarning &amp;amp; "|" &amp;amp; strAllProcessPerfInfo
         wscript.quit(1)
  Case 2 wscript.echo strResultError &amp;amp; "|" &amp;amp; strAllProcessPerfInfo
         wscript.quit(2)
  Case else wscript.echo " Unknown result |" &amp;amp; strAllProcessPerfInfo
         wscript.quit(3)
End Select

'*******************************************************************
&amp;lt;/script&amp;gt;
&amp;lt;/job&amp;gt;&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&amp;nbsp;&lt;/p&gt;</description>
      <link>http://blog.jstudios.us/post/2012/04/28/Monitoring-BO-Web-Intelligence-Servers.aspx</link>
      <comments>http://blog.jstudios.us/post/2012/04/28/Monitoring-BO-Web-Intelligence-Servers.aspx#comment</comments>
      <guid>http://blog.jstudios.us/post.aspx?id=f4b4ed54-6b81-4397-bd46-1fb7a4615464</guid>
      <pubDate>Sat, 28 Apr 2012 13:33:00 -0500</pubDate>
      <category>Monitoring</category>
      <category>Nagios</category>
      <category>Windows</category>
      <dc:publisher>techpilot007</dc:publisher>
      <pingback:server>http://blog.jstudios.us/pingback.axd</pingback:server>
      <pingback:target>http://blog.jstudios.us/post.aspx?id=f4b4ed54-6b81-4397-bd46-1fb7a4615464</pingback:target>
      <slash:comments>33</slash:comments>
      <trackback:ping>http://blog.jstudios.us/trackback.axd?id=f4b4ed54-6b81-4397-bd46-1fb7a4615464</trackback:ping>
      <wfw:comment>http://blog.jstudios.us/post/2012/04/28/Monitoring-BO-Web-Intelligence-Servers.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.jstudios.us/syndication.axd?post=f4b4ed54-6b81-4397-bd46-1fb7a4615464</wfw:commentRss>
    </item>
  </channel>
</rss>