Test Windows Updates

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
KHeitz
Posts: 14
Joined: Thu Jan 27, 2011 8:02 am

Test Windows Updates

Post by KHeitz »

Hi,
We use Host Monitor 8.82.
Is there the possibility of a test to check the Windows Updates?
The test will show the number of critical Updates from the Microsoft site, have not yet been installed.

Thank you for your help
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Test Windows Updates

Post by KS-Soft Europe »

You may use Shell Script test method and custom made script.
E.g. script may look like the following:
'============================================================================
Option Explicit

const statusAlive = "scriptRes:Host is alive:"
const statusDead = "scriptRes:No answer:"
const statusUnknown = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"

dim updateSession, updateSearcher, searchResult
dim objInstallationBehavior
dim i, cnt

Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()

Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software'")

cnt = 0
FOR i = 0 to searchResult.Updates.Count-1
Set objInstallationBehavior = searchResult.Updates.Item(i).InstallationBehavior
IF objInstallationBehavior.Impact=2 then
cnt = cnt+1 'high impact updates
ELSE
'WScript.StdOut.WriteLine searchResult.Updates.Item(i).Title & ", Impact: " & objInstallationBehavior.Impact
END IF
NEXT
if cnt>0 then
WScript.StdOut.Write statusBad & searchResult.Updates.Count & " critical updates found!"
else
WScript.StdOut.Write statusOk 'No new critical updates found
End If
'============================================================================
'Start cmd: cmd /c cscript /B /E:VBScript %Script% %Params%
'============================================================================

Please note: Script execution may take much time. You should set higher Timeout for script execution.
KHeitz
Posts: 14
Joined: Thu Jan 27, 2011 8:02 am

Post by KHeitz »

Hi, many thanks for the quick response.

how do I now install the script exactly?
the script must be stored on the server, I would like to monitor?
Or copy to my host monitor server?

Do I need a new test script?
there must be the only path to the specified script file, or more parameters so that the test works

Thank you for your help
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Test Windows Updates

Post by KS-Soft Europe »

how do I now install the script exactly?
the script must be stored on the server, I would like to monitor?
Or copy to my host monitor server?

This script is designed for ShellScript test method :http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell

You should create new ShellScript test (menu Test->New->Shell Script Test -> Script Manager)

Script Manager is used to store and test scripts.
Please check the manual or visit our web site for more information:
http://www.ks-soft.net/hostmon.eng/mfra ... m#shellmng
Do I need a new test script?
Sure, see above.
here must be the only path to the specified script file, or more parameters so that the test works
This script does not require any parameters.
You should use Start cmd in Script Manager like: cmd /c cscript /B /E:VBScript %Script% %Params%
KHeitz
Posts: 14
Joined: Thu Jan 27, 2011 8:02 am

Post by KHeitz »

Hi,

thanks for the helpful response.
I have the script now has the script manager added with the parameters.
If I now lets try the most popular script I get the following error message.
Agent error: no Response from agent within specified timeout.
time out is second to 600.


Thank you for your help
KS-Soft
Posts: 12821
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Have you tried to start script on the same system from command line?

Regards
Alex
KHeitz
Posts: 14
Joined: Thu Jan 27, 2011 8:02 am

Post by KHeitz »

Hi,

The test wokrs now fine.
One more question for this test:

How can I make the following query?

0 updates => display "No important windows updates"
1 update => display "one important windowns Update
more then one => display "xx important windows updates available "

Because in the German language, there are several variations of the word important

1 = wichtiges
more then one = wichtige

Thank you for your help
KS-Soft
Posts: 12821
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

How can I make the following query?
0 updates => display "No important windows updates"
1 update => display "one important windowns Update
more then one => display "xx important windows updates available "
You may change script in any way you want
E.g.

Code: Select all

if cnt>1 then 
  WScript.StdOut.Write statusBad & searchResult.Updates.Count & "text1" 
elseif cnt=1 then 
  WScript.StdOut.Write statusBad & searchResult.Updates.Count & "text2" 
else 
  WScript.StdOut.Write statusOk "text3" 
End If 
Regards
Alex
KHeitz
Posts: 14
Joined: Thu Jan 27, 2011 8:02 am

Post by KHeitz »

hi,

many thanks for the helpful response.
I knew the parameters elseif not.

At the momment I have the problem when ther is a server with no critical updates I always get the message:

error: script returns no results

But I can not find the error.
Any idea where I assumed something wrong?

My script now looks like this.

-------------------------------------------------------------------------------------
Option Explicit

const statusAlive = "scriptRes:Host is alive:"
const statusDead = "scriptRes:No answer:"
const statusUnknown = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"

dim updateSession, updateSearcher, searchResult
dim objInstallationBehavior
dim i, cnt

Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()

Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software'")

cnt = 0
FOR i = 0 to searchResult.Updates.Count-1
Set objInstallationBehavior = searchResult.Updates.Item(i).InstallationBehavior
IF objInstallationBehavior.Impact=2 then
cnt = cnt+1 'high impact updates
ELSE
'WScript.StdOut.WriteLine searchResult.Updates.Item(i).Title & ", Impact: " & objInstallationBehavior.Impact
END IF
NEXT
cnt>1 then
WScript.StdOut.Write statusOk & searchResult.Updates.Count & " wichtiges Windows-Updates steht zur Installation bereit"
elseif cnt=1 then
WScript.StdOut.Write statusOk & searchResult.Updates.Count & " wichtige Windows-Update stehen zur Installation bereit"
else
WScript.StdOut.Write statusbad & " Keine wichtigen Windows-Updates stehen zur Instalaltion bereit "
End If
-------------------------------------------------------------------------------------


Thank you for your help
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

ShellScript returns "error: script returns no results" error when there is an error in script.
I think you missed If statement here:
If cnt>1 then
WScript.StdOut.Write statusOk & searchResult.Updates.Count & " wichtiges Windows-Updates steht zur Installation bereit"
elseif cnt=1 then
WScript.StdOut.Write statusOk & searchResult.Updates.Count & " wichtige Windows-Update stehen zur Installation bereit"
else
WScript.StdOut.Write statusbad & " Keine wichtigen Windows-Updates stehen zur Instalaltion bereit "
End If
xcentric
Posts: 176
Joined: Sat Oct 23, 2010 4:30 pm

Post by xcentric »

THis is a great addition to my shell scripts. Thank you.

I was wondering if you have one agent in a network with multiple servers, how do you specify the server name in each test you want to create?

Ultimately you would want one update test per server.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

I have modified script. Now it should retrieve updates count from another system.
Script can accept one parameter - name (or IP) of remote machine.

Code: Select all

Option Explicit
On Error Resume Next

const statusAlive = "scriptRes:Host is alive:"
const statusDead = "scriptRes:No answer:"
const statusUnknown = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"

dim updateSession, updateSearcher, searchResult, objArgs
dim objInstallationBehavior
dim i, cnt


Set objArgs = WScript.Arguments

if objArgs.count = 0  then 
Set updateSession = CreateObject("Microsoft.Update.Session")
else
Set updateSession = CreateObject("Microsoft.Update.Session",objArgs(0))
end if

if Err.Number <> 0  then   
    WScript.StdOut.Write statusUnknown & Err.Description
    WScript.Quit
end if

Set updateSearcher = updateSession.CreateupdateSearcher()

Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software'")

cnt = 0
FOR i = 0 to searchResult.Updates.Count-1
Set objInstallationBehavior = searchResult.Updates.Item(i).InstallationBehavior
IF objInstallationBehavior.Impact=2 then
cnt = cnt+1 'high impact updates
ELSE
'WScript.StdOut.WriteLine searchResult.Updates.Item(i).Title & ", Impact: " & objInstallationBehavior.Impact
END IF
NEXT
If cnt>1 then
WScript.StdOut.Write statusOk & searchResult.Updates.Count & " wichtiges Windows-Updates steht zur Installation bereit"
elseif cnt=1 then
WScript.StdOut.Write statusOk & searchResult.Updates.Count & " wichtige Windows-Update stehen zur Installation bereit"
else
WScript.StdOut.Write statusbad & " Keine wichtigen Windows-Updates stehen zur Instalaltion bereit "
End If 
Please note: user account, under wich script is started, should have administrator privileges on remote machine.
MichaelF
Posts: 5
Joined: Tue Feb 15, 2011 2:47 am

Post by MichaelF »

Hi,

this is my first test in hostmoni with shell script.
I have Hostmoni Version 8.68.

In the Script Manager i create a new script an copied the Script.

Now what do i have to enter under Hint and Prams?

On start cmd i enter cmd /c cscript /B /C:windowsupdate.vbs %Script% %Params%

When ein Test the Script Hostmoni says Error: unable to start script.

Can you help me?
KS-Soft
Posts: 12821
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

cmd /c cscript /B /C:windowsupdate.vbs %Script% %Params%
This does not look correctly.
1) I think cscript utility does not support such /C parameter
2) If you stored script in external file (windowsupdate.vbs) then you don't need to use %Script% variable. If you stored script using Script Manager then you need to use %Script% variable but then windowsupdate.vbs has no sense.

As you may see VB script example uses the following command
cmd /c cscript /B /E:VBScript %Script% %Params%
Why don't you use the same command?
Now what do i have to enter under Hint and Prams?
Quote fro the manual
=================
Hint
List of script parameters (if any). This parameter is optional however we recommend to use it. It will be displayed in the Test Properties dialog as a reminder - which parameters should be specified for the script. E.g. "Process: %CPU usage (average)" script has 2 parameters: <process_name> and <maximum threshold (%)>
=================
So you may use this field for any information useful for you.

Parameter?
As Tom said script can accept one parameter - name (or IP) of remote machine.

Regards
Alex
xcentric
Posts: 176
Joined: Sat Oct 23, 2010 4:30 pm

Post by xcentric »

I am having a tough time with a modification. On windows 2003 the script provided here in this forum will check for "High Priority" and "Software, Optional" updates. I would like it to check only for "High Priority".

I found the following script on the internet that checks "High Priority" updates only but I am having difficulty merging the two scripts together to make it work.

Code: Select all

' check this category for 'High Priority' updates
category = "UpdateClassification"
highpriority = ",Security Updates,Update Rollups,Critical Updates,"

' create instance of update.searcher (offline)
Set objSearcher = CreateObject("Microsoft.Update.Searcher")
objSearcher.Online = 1

' find and fetch collection of updates
Set objResults = objSearcher.Search("Type='Software' and IsInstalled=0")
Set colUpdates = objResults.Updates

count = 0
titles = ""
For i = 0 to colUpdates.Count - 1
' check categories
Set colCategories = colUpdates.Item(i).Categories
For c = 0 to colCategories.Count - 1
If colCategories.item(c).Type = category _
And InStr(highPriority, "," & colCategories.item(c).Name & ",") > 0 Then
count = count + 1
titles = titles & vbCRLF & colUpdates.Item(i).Title
End If
Next
Next

If count > 0 Then
Wscript.Echo count & " pending updates:" & titles
Wscript.Quit 2
Else
Wscript.Echo "No pending updates"
Wscript.Quit 0
End If
I believe I am close to getting this to work but I am stuck so far woth this.

Code: Select all

const statusAlive = "scriptRes:Host is alive:" 
const statusDead = "scriptRes:No answer:" 
const statusUnknown = "scriptRes:Unknown:" 
const statusNotResolved = "scriptRes:Unknown host:" 
const statusOk = "scriptRes:Ok:" 
const statusBad = "scriptRes:Bad:" 
const statusBadContents = "scriptRes:Bad contents:"

' check this category for 'High Priority' updates
category = "UpdateClassification"
highpriority = ",Security Updates,Update Rollups,Critical Updates,"

' create instance of update.searcher (offline)
Set objSearcher = CreateObject("Microsoft.Update.Searcher")
objSearcher.Online = 1

' find and fetch collection of updates
Set objResults = objSearcher.Search("Type='Software' and IsInstalled=0")
Set colUpdates = objResults.Updates

count = 0
titles = ""
For i = 0 to colUpdates.Count - 1
' check categories
Set colCategories = colUpdates.Item(i).Categories
For c = 0 to colCategories.Count - 1
If colCategories.item(c).Type = category _
And InStr(highPriority, "," & colCategories.item(c).Name & ",") > 0 Then
count = count + 1
titles = titles & vbCRLF & colUpdates.Item(i).Title
End If
Next
Next

if count > 0 then 
WScript.StdOut.Write statusBad & colupdates.Updates.Count & " critical updates found!" 
else 
WScript.StdOut.Write statusOk 'No new critical updates found 
End If 




'If count > 0 Then
'Wscript.Echo count & " pending updates:" & titles
'Wscript.Quit 2
'Else
'Wscript.Echo "No pending updates"
'Wscript.Quit 0
'End If
[/quote]
Post Reply