SCRIPT: Monitor any auto-start SERVICE not in Running State.
|
Logged in as: Guest
|
|
Users viewing this topic:
none
|
|
Login | |
|
SCRIPT: Monitor any auto-start SERVICE not in Running S... - 19.May2004 6:22:00 PM
|
|
|
schnazzy
Posts: 32
Joined: 2.Apr.2004
From: Seattle
Status: offline
|
We have many different W2k/W2k3 servers that have multiple services on each that we want to monitor. Most servers we monitor have 3-5 services at a minimum that we want to monitor. I wrote a simple script to monitor ALL auto-start "Automatic" services that are NOT in a "Running" state. There is an Ignore list of services that may be auto-start and not in a "Running" state that it should Ignore, such as "Performance Logs and Alerts". You only need one script per server, not multiple, and it checks ALL services in one WMI call, so in reality we are checking 15-25 services per machine with little overhead.
If you are interested please take a look. If this is not the right place to post this, please let me know. If you see an error or a better way to do this, please let me know. This code works in my environment like a champ.
' ///////////////////////////////////////////////////////////////////////////// ' This file is designed for specific use with the VBScript monitor for GFI ' Network Server Manager. ' ' ServerServies takes a computer name as an argument and will check that computer ' for all services not in a "Running" state and are set to "Auto" start. There is ' a comma delimited string (strIgnore) that can be used to specify services to ' ignore if they are not "Running" but set to "Auto" start. A good example is the ' Performance Logs and Alerts service. While the string is comma delimited there ' is no requirement for the comma except for logical seperation for the programmer. ' ' There is no warranty expressed or implied for the script or code within this file. ' Test the script and modify it for your own requirements. ' ' Use of complete or partial code is at your own risk. ' 'USAGE: The VB Function name is ServerServices 'USAGE: The Parameter1 is the servername to monitor. ' ' Copyright 2004, Alex Hertz ' Version 20040510.0 ' ' /////////////////////////////////////////////////////////////////////////////
Option Explicit Const retvalUnknown = 1
Function ServerServices( strComputer ) On Error Resume Next Dim objWMIService, colItems, strIgnore, stoppedItem ' strIgnore is a comma delimited list of "Display Names" of ' auto start services that are known to not be in a running state. ' Display names can be found via the services snap-in or the "net start" ' command in a cmd.exe window. strIgnore = "TSM StorageAgent1,"+ _ "Performance Logs and Alerts" ' Make a connection via WMI to the argumented remote computer. Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2") If( Err.Number <> 0 ) Then ServerServices = retvalUnknown EXPLANATION = "Unable to access '" & strComputer & "'" Exit Function End If
' Make a WMI query for Services (on the remote computer) that are set to ' auto start but are not in a Running state. (I.E. stopped, pending... etc.) Set colItems = objWMIService.ExecQuery("select * from Win32_Service " + _ "where State!='Running' and StartMode='Auto'",,48) ' Search the strIgnore string with auto start services that are not running. ' If a non-running auto start service is not in the strIgnore string, then ' fail and return the service name. Note that if multiple auto start services ' are not running only the first one will be listed. For Each stoppedItem in colItems If instr(strIgnore,stoppedItem.Displayname) = 0 Then ServerServices = False EXPLANATION = "Service Not Started: " & stoppedItem.Displayname Exit Function End If Next ServerServices = True EXPLANATION = "All Auto-Start services are in a Running state." End Function [ May 20, 2004, 09:53 PM: Message edited by: Alex Hertz ]
|
|
|
|
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 1:11:00 AM
|
|
|
jef
Posts: 49
Joined: 9.Feb.2004
From: Denmark
Status: offline
|
Thanks a lot Alex, this is great stuff ...:-)
/Jesper
|
|
|
|
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 10:30:00 AM
|
|
|
totalstu
Posts: 31
Joined: 19.May2004
From: Toronto
Status: offline
|
Are you guys running v5 or v5.5beta. I am running 5.5 in 60 day evaluation mode and cannot get this, or the March 9 posting someone made to monitor virtual memory, to work.
For this script I receive a runtime error: Line 77 Char 0 - Variable is undefined: 'strComputer'
I'm wondering if the problem may be related to running in eval mode and/or using the beta version.
Thanks
Stuart
|
|
|
|
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 10:53:00 AM
|
|
|
schnazzy
Posts: 32
Joined: 2.Apr.2004
From: Seattle
Status: offline
|
This is for v5.0 only. While we do have 5.5 on a test server, it didn't seem to have enough upgrades to warrant a change until the production release.
Note, that while I do not mean any offense to GFI or their programmers, GFI does react strangely in some cases with explicit usages.
Example: In my test script I have to Dim EXPLANATION since Option Explicit is set however if I do that, GFI will not read the EXPLANATION on the GFI monitor window. It will just read that the script returned TRUE or FALSE. Un-Diming EXPLANATION resolves that issue but breaks the script when running in a normal command window (for testing).
Try commenting the Option Explicit line out by putting a ' (quote) in front of the line. Otherwise put Dim strComputer on the line below the Const retvalUnknown = 1.
BTW I don't believe that you should have to define (Dim) strComputer in proper VBScript since it is being defined at the input to the function. It sure doesn't break in a command window.
Alex
|
|
|
|
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 12:56:00 PM
|
|
|
schnazzy
Posts: 32
Joined: 2.Apr.2004
From: Seattle
Status: offline
|
So good news and bad news. The good news is the code works fine as originally posted, on GFI 5.5 beta. The bad news is there must be something else not working properly on your side.
Here is a special version for you. You need to save this as allservicestest.vbs and run it from your GFI monitor server (not a remote), in a command window. Use the following command (SERVER is the name of the server you want to check): cscript allservicestest.vbs SERVER
It should respond with a -1,0,or 1. -1 is GOOD, 0 means a service isn't running, and 1 means you have a problem with your GFI server or your server you are monitoring (most likely).
Here is the modified code: ' ///////////////////////////////////////////////////////////////////////////// ' This file is designed for specific use with the VBScript using CSCRIPT. ' You must be an admin on the other SERVER. ' ' ServerServies takes a computer name as an argument and will check that computer ' for all services not in a "Running" state and are set to "Auto" start. There is ' a comma delimited string (strIgnore) that can be used to specify services to ' ignore if they are not "Running" but set to "Auto" start. A good example is the ' Performance Logs and Alerts service. While the string is comma delimited there ' is no requirement for the comma except for logical seperation for the programmer. ' ' There is no warranty expressed or implied for the script or code within this file. ' Test the script and modify it for your own requirements. ' ' Use of complete or partial code is at your own risk. ' ' Copyright 2004, Alex Hertz ' Version 20040520.0 ' ' /////////////////////////////////////////////////////////////////////////////
Option Explicit Const retvalUnknown = 1
'--DIFFERENCE------- Dim strComputer, return strComputer = Wscript.Arguments(0) return = ServerServices( strComputer ) Wscript.Echo return '--END DIFFERENCE---
Function ServerServices( strComputer ) On Error Resume Next Dim objWMIService, colItems, strIgnore, stoppedItem ' strIgnore is a comma delimited list of "Display Names" of ' auto start services that are known to not be in a running state. ' Display names can be found via the services snap-in or the "net start" ' command in a cmd.exe window. strIgnore = "TSM StorageAgent1,"+ _ "Performance Logs and Alerts" ' Make a connection via WMI to the argumented remote computer. Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2") If( Err.Number <> 0 ) Then ServerServices = retvalUnknown wscript.echo "Unable to access '" & strComputer & "'" Exit Function End If
' Make a WMI query for Services (on the remote computer) that are set to ' auto start but are not in a Running state. (I.E. stopped, pending... etc.) Set colItems = objWMIService.ExecQuery("select * from Win32_Service " + _ "where State!='Running' and StartMode='Auto'",,48) ' Search the strIgnore string with auto start services that are not running. ' If a non-running auto start service is not in the strIgnore string, then ' fail and return the service name. Note that if multiple auto start services ' are not running only the first one will be listed. For Each stoppedItem in colItems If instr(strIgnore,stoppedItem.Displayname) = 0 Then ServerServices = False wscript.echo "Service Not Started: " & stoppedItem.Displayname Exit Function End If Next ServerServices = True wscript.echo "All Auto-Start services are in a Running state." End Function [ May 20, 2004, 06:58 PM: Message edited by: Alex Hertz ]
|
|
|
|
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 2:05:00 PM
|
|
|
schnazzy
Posts: 32
Joined: 2.Apr.2004
From: Seattle
Status: offline
|
So you ran them from the server where the GFI server is running? (not a remote where you installed just the client).
Does the Service rule work from GFI for either of the two servers you tried? (make sure you do NOT put a user/pwd in the rule)
If the Service rule doesn't work, put in a username and password.
Both of the results you got are perfect. This means that the original script should work fine for you as it does for me in 5.0 and 5.5.
Let me know what the answers are to the above questions.
Alex
|
|
|
|
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 2:33:00 PM
|
|
|
schnazzy
Posts: 32
Joined: 2.Apr.2004
From: Seattle
Status: offline
|
The special script I made will not run in GFI. I would definately try GFI 5.0 or 5.5 on another server with my original script. The special script will only run via cscript in a command window.
If you, anyone, has any other "nice-to-have" scripts that may help multiple people let me know. I am working on an Exchange 2000/2003 script that is more than the basic one from GFI.
Alex
|
|
|
|
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 2:52:00 PM
|
|
|
totalstu
Posts: 31
Joined: 19.May2004
From: Toronto
Status: offline
|
Well, I'm in a thin client environment and I use one of only two desktop computers but I found a laptop so I'm going to install v5 on that and see if it works. I'll let you know.
Your Exchange script looks promising seeing how well you seem to write scripts. We are just about ready to go live with Exchange here. We have at present external email hosting.
I have almost no scripting experience though there are a few people here that do scripting. We're moving in a few months, with many projects on the go, so things are hectic but I'll see if any have some spare time.
Thanks for all your help.
Stuart
|
|
|
|
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 3:48:00 PM
|
|
|
schnazzy
Posts: 32
Joined: 2.Apr.2004
From: Seattle
Status: offline
|
The monitor should be a VBScript.
The setup should have the UNC path to the file.
The VB Function name is ServerServices.
The Parameter1 is "server" with the quotes (preferrably). server is the name of your server.
|
|
|
|
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 4:46:00 PM
|
|
|
schnazzy
Posts: 32
Joined: 2.Apr.2004
From: Seattle
Status: offline
|
No problem. Let me know if there are any other scripts for the masses.
Alex
|
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts |
|
|