Active Scripts and WMI

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).
megasound

not working for me

Post by megasound »

sorry but its not working for me

if i run the sctipt on my hostmonitor box it goes OK
if i run it remotely via an active agent the test is looping. so every second the script is started with NO results : it returns with :

Code: Select all

ERROR: Script return no rusults
also with in the script manager , when i do the Lets try option (with the correct parameter offcourse) it displays :

Code: Select all

[22:01:04] Agent: Mailserver is going to execute "Defrag" script ...
[22:01:04] Script started, no results received
so what am i doing wrong over here ???
please help !!!![/code]
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

As you may see, script is trying to start "c:\windows\system32\defrag.exe" in order to receive result. You may receive "Script return no rusults" when there is no "defrag.exe" in c:\windows\system32 folder or there is no "c:\windows\system32" at all. Probably, Windows is installed into another folder on remote machine, not into "C:\Windows\". So, you should verify that and adjust the script.

Regards,
Max
megasound

yes defrag.exe is here....

Post by megasound »

yess defrag.exe is here

C:\WINDOWS\system32\defrag.exe

btw this is a windows x64 R2 2003 machine with the firewall switched off
so that could not be the problem....

if i run the script locally it goes OK
but remote it won't

this is my script ;

Code: Select all

@echo off 
%1 - volume to check 

c:\windows\system32\defrag.exe %1 /a /v | find "You do not need to defragment this volume" > NUL 
IF ERRORLEVEL 1 ( 
   echo ScriptRes:Bad:You should defragment this volume 
) ELSE ( 
   echo ScriptRes:Ok:Ok
)
m
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Do you mean, the test is performed by RMA and RMA is running on x64 machine? In this case you may try to change the path to C:\WINDOWS\SysWOW64\defrag.exe

Regards,
Max
megasound

still not working

Post by megasound »

there is NO defrag.exe in that directory only in c:\windows\system32

the strange thing is that the test is flipping
every second the test is started without any results...so the test count increases very fast

i hope some one can help me to make a stable test to see if the harddisk is fragmented

thanks in advance and for all the help
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Re: still not working

Post by KS-Soft Europe »

megasound wrote:there is NO defrag.exe in that directory only in c:\windows\system32
Ok, please, revert script back to use c:\windows\system32\ folder.

So, the test is performed by RMA? What account do you use to start RMA?
We recommend to start RMA service under admin account. You may specify certain account for RMA service using standard Windows "Services" applet. For passive RMA you should find "KS Remote Monitoring Agent" service in "Services" window and provide account into "LogOn" tab. For active RMA you should look for "KS Active Remote Monitoring Agent" service.
megasound wrote:the strange thing is that the test is flipping
every second the test is started without any results...so the test count increases very fast
Strange. We cannot reproduce such a behavior. What time interval is set for this test?

Regards,
Max
User avatar
greyhat64
Posts: 246
Joined: Fri Mar 14, 2008 9:10 am
Location: USA

Post by greyhat64 »

To pick up on an earlier theme in this thread, there is a way to do this via WMI query (found on MS TechNet here):
This would produce the results you desire and avoid the 'defrag.exe - file not found' issue altogether, at least until you need to find it to perform the actual defrag. :wink:

The meat of the script (without all the extra 'report' data) found below still needs to be converted to usable AHM code:

Code: Select all

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume")

For Each objVolume in colVolumes
    errResult = objVolume.DefragAnalysis(blnRecommended, objReport)
    If errResult = 0 Then
        Wscript.Echo "Volume name: " & objVolume.Name
        If blnRecommended Then
           Wscript.Echo "You should defragment this volume."
        Else
           Wscript.Echo "You do not need to defragment this volume."
        End If
    Else
        Wscript.Echo objVolume.Name & " could not be analyzed."
        Wscript.Echo "Error number " & errResult & " occurred."
        Wscript.Echo
    End If
Next
If one of you guys wants to take this on, go for it, and please post the working code. Otherwise I'll do this when I get time and post accordingly.
Last edited by greyhat64 on Tue Feb 17, 2009 1:16 pm, edited 2 times in total.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Thank you for your point.
Actually, script adjusted to be used with "Active Script" test method was already posted in this thread earlier. I can post it again:

Code: Select all

Option Explicit

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

'---- entry point ----
FUNCTION performtest()
    dim strComputer, objWMIServicem, colVolumes, objVolume, objWMIService, blnRecommended, objReport, errResult
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colVolumes = objWMIService.ExecQuery("select * from Win32_Volume where Name = 'C:\\'")
    For Each objVolume in colVolumes
        errResult = objVolume.DefragAnalysis(blnRecommended, objReport)
        If errResult = 0 Then
            If blnRecommended Then
               performtest=statusBad & "You need to Defrag "& objVolume.Name
            Else
              performtest=statusOk
            End If
         Else
            performtest=statusBad & " Analyze Error!"
         End If
   Next
END FUNCTION
Script check drive C:\, so to check another drive you have to change C:\\ to D:\\ or so in script body.

Regards,
Max
User avatar
greyhat64
Posts: 246
Joined: Fri Mar 14, 2008 9:10 am
Location: USA

Post by greyhat64 »

NOTES: A few things to look for
  • If a volume is in the process of being defragged (a status you could also test for) you should skip testing. Otherwise, if your action is to launch a defrag, you could end up scheduling an unnecessary defrag or call defrag redundantly, which I think is not allowed.
  • You will also need to monitor for defrag failures, such as 'not enough available disk space'.
  • Finally, in rare instances (usually also low disk space related) you may get into a situation where it will execute a defrag with no apparent change, causing your test to go into a perpetual loop. This will need to be monitored as well.
Personally I would modify this to look at all volumes - that way you don't have to know how many volumes exist and the script survives any server configuration changes unscathed. Otherwise your required to go back through all your tests to add/subtract one because of volume changes - totally unnecessary if you ask me.

If you have a large number of servers to monitor you can appreciate this. The only downside is that you loose a little bit in granularity if you need to report per volume, but I would report this at a server level, not server-volume level.

You could then pass the volumes that need defragging in the reply field, which you could parse within your alert action script.

Maybe you could also compare the current reply using one of the 'Previous Reply' variables to see if progress is being made or if you are in a 'stuck status' situation (like one of the above mentioned situations), and take the appropriate action.

Just some thoughts . . . :roll:
Last edited by greyhat64 on Tue Feb 17, 2009 1:50 pm, edited 1 time in total.
megasound

Thanks for all the help so far

Post by megasound »

Thanks for all the help so far...
but still not working !!! i only whant to see if the C:\ is fragmented or not and if fragmented give me a BAD status or a warning. thats it.....

what i did is :
-set the windows 2003 server (with active agent) service to logon as administrator. so the ks managmenmt service has ALL the rights.
i also looked in the log_bad.txt but nothing is over there.
-Firewall shut off
-no users attachted only the administrator user
-no other software runing (so no virusscanner) on it

as far as the flipping issue see please : VIDEO0001.mp4 - 1.20MB
i do not understand the flipping problem...if i do this locally on a windowsxp machine it goes OK

when i use the above script posted by ks-soft europe i get this error..
Error in script:
Error number :-2147217392
Source :
Description :
Text :
Line :18
Column :4

for the good order : if i goto the windows 2003 server and run it in a dos box it goes well
see:

Code: Select all

C:\WINDOWS\system32>defrag c: /a | find "You should defragment this volume"
You should defragment this volume.
so i hope all questions are answered...if not please mail me at megasound1@gmail.com
User avatar
greyhat64
Posts: 246
Joined: Fri Mar 14, 2008 9:10 am
Location: USA

Post by greyhat64 »

I found this info on another forum.
According to Microsoft's documentation this is a WMI Class Not Found Error. Unusual, but fixable.
In order to fix this you can try the following steps (these are gathered together from related MS articles - KB820847 & KB827260):

According to Microsoft, use the following command sequence(s):
Solution#1: wmiadap /f, then restart the wmi-service..

If that doesn't work:
Solution#2: wmiadap /clearadap, then wmiadap /resyncperf, and reboot.

I haven't run into this, let us know if this resolves it.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Re: Thanks for all the help so far

Post by KS-Soft Europe »

megasound wrote:as far as the flipping issue see please : VIDEO0001.mp4 - 1.20MB
Sorry, cannot watch this movie with any player and codecs I have.
megasound wrote:when i use the above script posted by ks-soft europe i get this error..
Error in script:
Error number :-2147217392
This script will not work on XP because there is no Win32_Volume WMI class on XP. Actually, it was mentioned at this thread earlier. It will work on Windows 2003. Could you try it on Windows 2003? Are we talking about Windows 2003?

Regards,
Max
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

greyhat64 wrote:Solution#1: wmiadap /f, then restart the wmi-service..

If that doesn't work:
Solution#2: wmiadap /clearadap, then wmiadap /resyncperf, and reboot.
This will not help on XP. Win32_Volume WMI class is developed for server platform only: http://msdn.microsoft.com/en-us/library/aa394515.aspx

Anyway, thank you for supporting me. :-)

Regards,
Max
megasound

yess talking abount 2003

Post by megasound »

yes we are talking about windows 2003 server problem
hostmonitor itself runs on a windows xp machine

you can watch the movie with vlc player , its taken from my mobile phone.

thanks in advance
m
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Re: yess talking abount 2003

Post by KS-Soft Europe »

megasound wrote:yes we are talking about windows 2003 server problem
hostmonitor itself runs on a windows xp machine
So, have you tried to perform this script using RMA on Windows 2003 server?

Regards,
Max
Post Reply