Forums  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Member List  Search  FAQ  Ticket List  Log Out

 

SCRIPT: Monitor any auto-start SERVICE not in Running State.

 
Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [Networking & Security] >> GFI Network Server Monitor >> SCRIPT: Monitor any auto-start SERVICE not in Running State. Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
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 ]
Post #: 1
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

(in reply to schnazzy)
Post #: 2
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

(in reply to schnazzy)
Post #: 3
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

(in reply to schnazzy)
Post #: 4
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 12:16:00 PM   
totalstu

 

Posts: 31
Joined: 19.May2004
From: Toronto
Status: offline
Unfortunately, for me anyway, those two ideas didn't help. I also can't install v5 as I get an unknown error and the install gets halted. V5.5 installs with no problem.

Event viewer shows eventID: 11708 which brings up no info when I click the help and support centre link.

Guess I'll just to wait for 5.5 to go live [Smile]

(in reply to schnazzy)
Post #: 5
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 ]

(in reply to schnazzy)
Post #: 6
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 1:45:00 PM   
totalstu

 

Posts: 31
Joined: 19.May2004
From: Toronto
Status: offline
Ok, this is the reply I recieved from one server:
Windows script host 5.6
Service not started: Ati hotkey poller
0

I tried another server and got this reply:
Windows script host 5.6
All Auto-Start services are in a running state
-1

Not sure if this helps or not [Smile]

Thanks for taking time trying to help me.

(in reply to schnazzy)
Post #: 7
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

(in reply to schnazzy)
Post #: 8
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 2:25:00 PM   
totalstu

 

Posts: 31
Joined: 19.May2004
From: Toronto
Status: offline
I took the new script you made, saved it, put it in the scripts/monitor folder on the computer that has NSM installed and then open command prompt and ran it. The results were as I posted.

If I then make a new monitor rule, choose vbscript, browse and select allservicestest.vbs, then enter this "ServerServices( strComputer )" without the quotes, in the VB function name field, and then click ok twice, the monitor runs and gives a runtime error: Line 27 Char 0 - Variable is undefined: 'Wscript'.

I'm thinking part of the problem is related to the issue I have where I'm not able to install v5. I'm considering formatting this computer, which I inherited when I got here. It was someone elses and god knows what they have done to this [Smile] I'm also adding more ram and figure to get this thing running smooth a formatting might be in order. I'll also get a good ghost version of this for future imaging needs.

Thanks

Stuart

(in reply to schnazzy)
Post #: 9
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

(in reply to schnazzy)
Post #: 10
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

(in reply to schnazzy)
Post #: 11
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 3:19:00 PM   
totalstu

 

Posts: 31
Joined: 19.May2004
From: Toronto
Status: offline
OK, I installed v5 on the laptop and it installed properly. Looks like I'm formatting this desktop next weekend.

I tried your original script on the laptop NSM but still have the runtime error: Line 77 Char 0 - Variable is undefined: 'strComputer'

Can I ask you to take a screen shot or something of the setup page of your vbscript from within NSM (properties of the rule, then setup)? Maybe I'm missing something [Smile]

Thanks

Stuart

(in reply to schnazzy)
Post #: 12
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.

(in reply to schnazzy)
Post #: 13
RE: SCRIPT: Monitor any auto-start SERVICE not in Runni... - 20.May2004 4:13:00 PM   
totalstu

 

Posts: 31
Joined: 19.May2004
From: Toronto
Status: offline
You sir are a genius and one hell of a nice guy [Smile]

I had the VB function name incorrect. I had included ( strComputer). Boy, do I feel like an idiot.

Thanks so much for all you help.

I look forward to seeing your exchange and/or any other scripts you, or anyone else writes. Maybe you have a script that can check memory usage, etc.

Stuart

[ May 20, 2004, 10:46 PM: Message edited by: Stuart ]

(in reply to schnazzy)
Post #: 14
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

(in reply to schnazzy)
Post #: 15
Page:   [1] 2   next >   >>
All Forums >> [Networking & Security] >> GFI Network Server Monitor >> SCRIPT: Monitor any auto-start SERVICE not in Running State. Page: [1] 2   next >   >>
Jump to:





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