Sign in to follow this  
Followers 0
Pixel1191

VMware hard-drive monitoring

5 posts in this topic

Greetings,

 

I is coming to get some support. :P

I've recently had some harrowing issues with dead VMware drives that I'm looking to avoid in the future and I think AutoIT might be the way to go. But I'm new to this and, safe to say, completely out of my depth. Most I've done up to this point is some basic batching.

What I want to do is remotely execute a command on a VMware ESXi-Server to get health-information on the local drive. This can be done either via SSH, or via the VMware CLI, which I would prefer. That itself isn't much of an issue and could be done via batch relatively easily, however I want to take it a step further and have the program send an E-Mail if anything is wrong....and that's where AutoIT comes in and I reach my limit.

The command to get the imformation I need (using VMware CLI) is relatively simple and no problem, it looks something like that:

esxcli -s 192.192.192.192 -u root -p password storage core device smart get -d t10.ATA_____harddrive___________________123456789____

And it's putting out the information like this:

Parameter                     Value  Threshold  Worst
----------------------------  -----  ---------  -----
Health Status                 OK     N/A        N/A
Media Wearout Indicator       0      0          0
Write Error Count             N/A    N/A        N/A
Read Error Count              100    50         100
Power-on Hours                73     0          73
Power Cycle Count             100    0          100
Reallocated Sector Count      100    3          100
Raw Read Error Rate           100    50         100
Drive Temperature             16     0          81
Driver Rated Max Temperature  N/A    N/A        N/A
Write Sectors TOT Count       N/A    N/A        N/A
Read Sectors TOT Count        N/A    N/A        N/A
Initial Bad Block Count       N/A    N/A        N/A

Now for the purpose of this, all I'm interested in, is the Health Status.

Couple of questions regarding the execution of this thing...

1) How do I tell AutoIT to run a CMD command in a specific folder? The VMware CLI stuff has to be run from its installation folder to work, as far as I know.

2) How do I process the output to continue working with it? If it prints an OK, all is well and it should just loop the whole procedure after a given time. However, If it's anything but OK, I want it to write me an E-Mail about that, so I can react accordingly.

 

I'm a complete scrub at this stuff....a simple techie, I don't deal in code, so any help would be appreciated.

Share this post


Link to post
Share on other sites



The Run() function provides the capabilities you seek.  Firstly, it allows you to specify the "working directory" for a process (see the second parameter in the help article).  As far as "interacting" with the output, there are a couple of ways to tackle that.  One (arguabliy) more sophisticated way would be to capture the StdOut (console standard output) stream.  Look at the StdOutRead() for a good example.  You shoudl be able to manipulate the examples to get some initial working results.  Let us know your progress.
 

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Okay, so I've made some steps in the right direction.

 

Frist of: the current version of the script:

 

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

$SMTPADD="server adress"

$SUBJECT="subject line"

$body="email text"

$TO="recipient"

$from="sender"

$USERNAME="username for SMTP auth"

$PASSWORD="password for SMTP auto"

$log="log.txt"

SMART()

Func SMART()

    Local $iPID = Run(@ComSpec & " /c " & 'esxcli -s 192.192.192.192 -u root -p password storage core device smart get -d t10.ATA_____harddrive___________________12345____', "C:\Program Files (x86)\VMware\VMware vSphere CLI\bin\", @SW_HIDE, $STDOUT_CHILD)

    ProcessWaitClose($iPID)

    Local $sOutput = StdoutRead($iPID)

    Local $aArray = StringSplit(StringTrimRight(StringStripCR($sOutput), StringLen(@CRLF)), @CRLF)
    If @error Then
        Run("blat.exe -server """ & $SMTPADD & """ -s """ & $SUBJECT & """ -body """ & $BODY & """ -u """ & $USERNAME & """ -pw """ & $PASSWORD & """ -t """ & $TO & """ -f """ & $from & """ -log """& $log & """","" , @SW_HIDE)
    Else
        _ArrayDisplay($aArray)
    EndIf
EndFunc

Currently, it's still displaying the results of the command if everything is alright. While that works, it's not what I want. I want it to just rerun the whole thing again...and again, with a certain time inbetween...until something goes wrong and it sends me an email. It's okay if it ends after that, no need to loop after an error. I'll get the email and have to touch the system anyway, might as well start the script again...and I don't want it to spam, either.

 

Anyone got something on looping this?

Edited by Pixel1191

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The most basic solution would probably be to turn the entire function into a while loop that ends when it encounters an error

Func SMART()
    while 1 ;Runs the entire function forever, or until the while loop is broken.
      Local $iPID = Run(@ComSpec & " /c " & 'esxcli -s 192.192.192.192 -u root -p password storage core device smart get -d t10.ATA_____harddrive___________________12345____', "C:\Program Files (x86)\VMware\VMware vSphere CLI\bin\", @SW_HIDE, $STDOUT_CHILD)

      ProcessWaitClose($iPID)

      Local $sOutput = StdoutRead($iPID)

      Local $aArray = StringSplit(StringTrimRight(StringStripCR($sOutput), StringLen(@CRLF)), @CRLF)
      If @error Then
          Run("blat.exe -server """ & $SMTPADD & """ -s """ & $SUBJECT & """ -body """ & $BODY & """ -u """ & $USERNAME & """ -pw """ & $PASSWORD & """ -t """ & $TO & """ -f """ & $from & """ -log """& $log & """","" , @SW_HIDE)
          exitloop ;exits the while loop after sending the email, else using exit will end the script.
      Else
          _ArrayDisplay($aArray)
            Sleep(120*1000) ;each time it works it sleeps for 2 minutes then re-runs
      EndIf
     WEnd ;Ends While Loop
EndFunc

If you want to, then instead of exiting the loop after sending the email you can make it go into a sub loop that it won't return from until it has been able to run successfully again

Func SMART()
    while 1 ;Runs the entire function forever, or until the while loop is broken.
      Local $iPID = Run(@ComSpec & " /c " & 'esxcli -s 192.192.192.192 -u root -p password storage core device smart get -d t10.ATA_____harddrive___________________12345____', "C:\Program Files (x86)\VMware\VMware vSphere CLI\bin\", @SW_HIDE, $STDOUT_CHILD)

      ProcessWaitClose($iPID)

      Local $sOutput = StdoutRead($iPID)

      Local $aArray = StringSplit(StringTrimRight(StringStripCR($sOutput), StringLen(@CRLF)), @CRLF)
      If @error Then
          Run("blat.exe -server """ & $SMTPADD & """ -s """ & $SUBJECT & """ -body """ & $BODY & """ -u """ & $USERNAME & """ -pw """ & $PASSWORD & """ -t """ & $TO & """ -f """ & $from & """ -log """& $log & """","" , @SW_HIDE)
          _ErrorFoundOnHold()
      Else
          _ArrayDisplay($aArray)
            Sleep(120*1000) ;each time it works it sleeps for 2 minutes then re-runs
      EndIf
     WEnd ;Ends While Loop
EndFunc

Func _ErrorFoundOnHold()
    while 1
        Local $iPID = Run(@ComSpec & " /c " & 'esxcli -s 192.192.192.192 -u root -p password storage core device smart get -d t10.ATA_____harddrive___________________12345____', "C:\Program Files (x86)\VMware\VMware vSphere CLI\bin\", @SW_HIDE, $STDOUT_CHILD)

        ProcessWaitClose($iPID)

        Local $sOutput = StdoutRead($iPID)

        Local $aArray = StringSplit(StringTrimRight(StringStripCR($sOutput), StringLen(@CRLF)), @CRLF)
        If @error Then
           sleep(120*1000)
        Else
            exitloop ;exits loop on succesful run
        EndIf
    WEnd
EndFunc

 

Edited by Mriswith2k
1 person likes this

Share this post


Link to post
Share on other sites

Alright, that'll do it!

 

Thanks a bunch!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0