KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Check mount status of exchange 2003 mailbox database
Goto page 1, 2  Next
 
Post new topic   Reply to topic    KS-Soft Forum Index -> Library
View previous topic :: View next topic  
Author Message
ldean



Joined: 14 Nov 2008
Posts: 17

PostPosted: Fri Nov 14, 2008 3:18 pm    Post subject: Check mount status of exchange 2003 mailbox database Reply with quote

This vbs script can be used in conjunction with the external program test from host monitor to check the mount status of an exchange 2003 mailbox database. Save the file somewhere on the RMA server.

in HM, set up the test as follows (substitute things in []'s for your environment):
Code:

Method      = ExternalPrg
;--- Common properties ---
;DestFolder = Root\
RMAgent     = [AGENTNAME]
Title       = MailboxDB Mount Status
Comment     = cscript
RelatedURL  =
CmntPattern = %path%
ScheduleMode= OneTestPerDay
ScheduleTime= 05:10:00
Alerts      = Send Email
ReverseAlert= No
UnknownIsBad= Yes
WarningIsBad= Yes
UseCommonLog= Yes
PrivateLog  = C:\Program Files\HostMonitor7\Logs\mailboxmount.htm
PrivLogMode = Full
CommLogMode = Default
SyncCounters= Yes
SyncAlerts  = No
DependsOn   = list
MasterTest-Alive = Ping: 4.2.2.2
;--- Test specific properties ---
CommandLine = cscript c:\store.vbs status [SERVERNAME] "[STORAGEGROUP]" "[MAILBOX STORE]"
Condition   = MoreThan
ErrorLevel  = 0
WindowMode  = hide

for example, for command line, you may have:
CommandLine = cscript c:\store.vbs status server2003 "First Storage Group" "Mailbox Store (SERVER2003)"

Here is the VBS script:

Code:
' Name: Store.VBS
' Purpose: To Mount, Dismount, or Delete a Mailbox Store (MDB) on Exchange Server
'
'Written by Leon Funnell
'email me at leon_funnell(At)hotmail(d0t)com
'17/02/2005
'modified by LDean -- ldean[at]quikteks[dot]com
'11/10/2008

quot = chr(34)

Set iServer = CreateObject ("CDOEXM.ExchangeServer")
Set iMDB = CreateObject ("CDOEXM.MailboxStoreDB")

' check command line
GetArgs strMode,strComputerName,strSGName,strMDBName,CorrectSyntax
If CorrectSyntax Then
BindMailboxStore strComputerName,strSGName,strMDBName
Select Case strMode
Case "mount"
wscript.echo "Mounting Database " & strMDBName & " in Storage Group " & strSGName & " on " & strComputerName
iMDB.mount
Case "dismount"
wscript.echo "Dismounting Database " & strMDBName & " in Storage Group " & strSGName & " on " & strComputerName
iMDB.dismount
Case "delete"
wscript.echo "Deleting Database " & strMDBName & " in Storage Group " & strSGName & " on " & strComputerName
iMDB.DataSource.delete
Case "status"
dim sStoreStatus
If iMDB.Status = 0 Then
  wscript.quit(0)
 ElseIf iMDB.Status = 1 Then
  wscript.quit(1)
 ElseIf iMDB.Status = 2 Then
  wscript.quit(2)
 ElseIf iMDB.Status = 3 Then
  wscript.quit(3)
 Else
  wscript.quit(4)
 End If
End Select

' Cleanup
Set iServer = Nothing
Set iMDB = Nothing
Else
DisplayHelp
wscript.quit
End If

Sub BindMailboxStore (strComputerName,strSGName,strMDBName)
' Bind to the Exchange Server
iServer.DataSource.Open strComputerName

' Build the first part of the URL to the MailboxStoreDB
strTemp = "LDAP://" & iServer.DirectoryServer & "/" & "cn=" & strMDBName & ","

' Set variant array to the ExchangeServer.StorageGroups
arrStGroup = iServer.StorageGroups

' Look in the StorageGroups array if the StorageGroup with strSGName exists
If strSGName = "" Then
' Add last part to the URL to the MailboxStoreDB
strMDBUrl = strTemp & iServer.StorageGroups(0)
Else
For i = 0 To UBound(arrStGroup)
If InStr(1, UCase(arrStGroup(i)), UCase(strSGName)) <> 0 Then
strMDBUrl = arrStGroup(i)
End If
Next
If strMDBUrl <> "" Then
' Add last part to the URL to the MailboxStoreDB
strMDBUrl = strTemp & strMDBUrl
End If
End If
' Bind to the MailboxStoreDB
iMDB.DataSource.Open strMDBUrl ', , , adCreateOverwrite
End Sub


Sub GetArgs(strMode,strComputerName,strSGName,strMDBName,CorrectSyntax)
Set Args = WScript.Arguments
If args.count = 4 Then
CorrectSyntax = True
strMode = args(0)
strComputerName = args(1)
strSGName = args(2)
strMDBName = args(3)
Else
CorrectSyntax = False
End If
Select Case lcase(strMode)
Case "mount","dismount","delete"
CorrectSyntax = True
Case "/?","/help","?","help"
CorrectSyntax = False
End Select
End Sub


Sub DisplayHelp
wscript.echo "Mounts, Dismounts, or Deletes a Mailbox Store on an Exchange 2000/2003 server"
wscript.echo ""
wscript.echo "cscript Store.vbs /? or /Help ----------------------------------- Displays this help screen"
wscript.echo "cscript Store.vbs Mount Servername StorageGroupName MDBName ----- Mounts Database"
wscript.echo "cscript Store.vbs Dismount Servername StorageGroupName MDBName -- Dismounts Database"
wscript.echo "cscript Store.vbs Delete Servername StorageGroupName MDBName ---- Deletes Database"
wscript.echo "cscript store.vbs status Servername StorageGroupName MDBName ---- Checks status of database"
wscript.echo ""
wscript.echo ""
wscript.echo "Example:"
wscript.echo ""
wscript.echo "cscript Store.vbs Mount SERVER1 "&quot&"First Storage Group"&quot&" "&quot&"Mailbox Store (SERVER1)"&quot
wscript.echo ""
End Sub


I use this test to run every morning at 5:10am (right after the mailbox maint. finishes, so that if the mailbox store was too big, and got dismounted, I'll know). This will only work if the information store service is started.
The script could also be used to remount or dismount the store if needed as an alert action. The script was originally written by someone else, but I modified it to add in the status check. If the store is mounted, it will return 0, if it is dismounted it will return 1, if it is mountING, it will return 2, and if it is dismountING, it will return 3. The alerts can be set up accordingly.

Let me know if there are questions.
Back to top
View user's profile Send private message
esirignano



Joined: 23 Mar 2010
Posts: 7

PostPosted: Tue Mar 23, 2010 11:43 am    Post subject: Reply with quote

This works great! Have you found anything to monitor Exchange 2007? I understand cdoexm is no longer supported. I'm trying to find something usable in the Exchange Management Shell but nothing yet.
Back to top
View user's profile Send private message
meppyman



Joined: 06 Sep 2009
Posts: 118
Location: Melbourne

PostPosted: Wed Jul 21, 2010 4:10 pm    Post subject: Reply with quote

Not sure when but this script stopped working for me on Exchange 2003. If I run the script locally it works fine, but running it via HM it keeps saying that the response was 0 even when it isn't.

Is there a problem with the way scripts are run by HM that is missing the correct exit code?
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12063
Location: USA

PostPosted: Thu Jul 22, 2010 10:07 am    Post subject: Reply with quote

Quote:
Is there a problem with the way scripts are run by HM that is missing the correct exit code?

Problem? I do not see any problem in our code and we did not change code used for External test for many years.
Do you use External test method and start script using command line like
cscript c:\store.vbs status server2003 "First Storage Group" "Mailbox Store (SERVER2003)"?
What Windows do you use? Service Pack?
Script is performed by HostMonitor? RMA? HostMonitor/RMA started as service? application? Using admin account?
HostMonitor/RMA version?

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
meppyman



Joined: 06 Sep 2009
Posts: 118
Location: Melbourne

PostPosted: Thu Jul 22, 2010 4:58 pm    Post subject: Reply with quote

I am wondering if this ever worked now as I have found a fair bit on the net to say if you call with cscript it will not get wscript errorlevel codes returned properly. There are code snippets on the web that detail how to fix this. I will test one out and post what works. There might be other factors that influence it but this seems like the same problem.

Tried using RMA and local and the service accounts have no problems with any other test, the code runs it just returns '0' no matter what.

Here is one article on the problem...

http://my.opera.com/Lee_Harvey/blog/2007/06/03/returning-an-errorlevel-from-wsh-vbscripts

I obviously never tested it properly or some other factor on my system has affected this.
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12063
Location: USA

PostPosted: Fri Jul 23, 2010 11:07 am    Post subject: Reply with quote

External test and wscript.quit(errorcode) works just fine on our systems.
If you answer to my question, we will try to investigate the problem.

On the other hand... what is the reason to use External test if you have VB script that can be easily modified to fit Shell Script requirements? Shell Script tests can return test status and reply value to HostMonitor.
http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#chkShell

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
meppyman



Joined: 06 Sep 2009
Posts: 118
Location: Melbourne

PostPosted: Sun Jul 25, 2010 5:16 am    Post subject: Reply with quote

Do you use External test method and start script using command line like
cscript c:\store.vbs status server2003 "First Storage Group" "Mailbox Store (SERVER2003)"?

Yes

What Windows do you use? Service Pack?
HM on Windows SBS 2003 R2 and RMA on SBS 2003 both SP 2

Script is performed by HostMonitor? RMA?
Both

HostMonitor/RMA started as service? application?
Service

Using admin account?
HM uses Local System, RMA uses an account that belongs to the Administrators group

HostMonitor/RMA version?
8.64/Active 4.05
Back to top
View user's profile Send private message
meppyman



Joined: 06 Sep 2009
Posts: 118
Location: Melbourne

PostPosted: Sun Jul 25, 2010 5:37 am    Post subject: Reply with quote

KS-Soft wrote:

On the other hand... what is the reason to use External test if you have VB script that can be easily modified to fit Shell Script requirements? Shell Script tests can return test status and reply value to HostMonitor.
http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#chkShell


Basically because I had a look at that page in the help file/manual and couldn't really work out which I should be using and why. Maybe a table that explains the differences and why you use one method over the other for us non programming types?

Also I just followed the above, it worked for them so assumed it would be ok for me too.
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12063
Location: USA

PostPosted: Mon Jul 26, 2010 11:54 am    Post subject: Reply with quote

Ok, we tested HostMontior 8.64 on Windows 2003 R2 - everything works correctly.
Are you sure your script should return non-zero value? You may try simple script like
wscript.quit(3)
to see if HostMonitor works correctly.

Quote:
Maybe a table that explains the differences and why you use one method over the other for us non programming types?

There is no table. Major difference - Shell Script can send to HostMonitor status and reply while External test can return just single number.
Quote from the manual
====================
Shell Script method combines the versatility of "External" and convenience of "Active Script" method. Both "External" and "Shell Script" test methods execute specified commands as new processes. Due to this nature it is possible to use any programming tool for test creation. E.g. you may use Visual Basic script, Java script, create real executable file using C++ compiler or use simple BAT file or shell script. On the other hand this test method allows passing of any valid Status and Reply values back to HostMonitor. Just like "Active Script" (formerly "Script") test method.
====================

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
meppyman



Joined: 06 Sep 2009
Posts: 118
Location: Melbourne

PostPosted: Mon Jul 26, 2010 4:31 pm    Post subject: Reply with quote

Yes it definitely should be exiting with a non zero. If I run the script locally and add an echo "3" for example to just before the wscript.quit(3) I can see it should be giving a non zero.

Testing just a vbs file that has only wscript.quit(3) works fine.

I am adding echo and sleep commands to the code to try and see what is happening.

I know there is no table, I was suggesting that a table would be really useful to your user base.
Back to top
View user's profile Send private message
meppyman



Joined: 06 Sep 2009
Posts: 118
Location: Melbourne

PostPosted: Mon Jul 26, 2010 4:57 pm    Post subject: Reply with quote

OK so I put an On Error Resume Next statement and then reported the error details:

Code:
Error number: -2147418113

Access is denied.

Facility: Win32
ID no: c0070005
Microsoft CDO for Exchange Management



Maybe a permissions issue, but by turning on error resume it does actually run correctly which is interesting. If I run it manually it gives no error.
Back to top
View user's profile Send private message
meppyman



Joined: 06 Sep 2009
Posts: 118
Location: Melbourne

PostPosted: Mon Jul 26, 2010 5:19 pm    Post subject: Reply with quote

OK I think I have resolved the issue. The service account used by HM and the RMA needs to be delegated as an Administrator for the Exchange server. I did this and no more errors.
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12063
Location: USA

PostPosted: Tue Jul 27, 2010 6:44 am    Post subject: Reply with quote

Great

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
meppyman



Joined: 06 Sep 2009
Posts: 118
Location: Melbourne

PostPosted: Tue Jul 27, 2010 5:02 pm    Post subject: Reply with quote

Hmmm I might have spoken too soon. Had a store go down at a remote site (active RMA) and the script did not work. I had to add "on error resume next" and I get an error code even when the store is mounted so it is still not working properly.

The account is an Exchange Administrator and has the following rights:

Log on as a service
Log on as a batch job
Administrator

I also logged on to the server as that account and the script works as expected, but from HM it doesn't (exact same command copied and pasted). I even made the user a member of the domain admins group and still no dice. I cannot see any difference between the one that works on the HM server and one that doesn't work on the remote server.

The only difference between the accounts is that one is mail enabled and the other is not. But the fact I can log on locally as the service account and run the script fine shows this is not really the issue here.
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12063
Location: USA

PostPosted: Wed Jul 28, 2010 3:57 pm    Post subject: Reply with quote

As I understand this is 2nd test item, it is performed by Active RMA (while 1st test performed by HostMonitor)?
Active RMA started as service? What account do you use to run agent?

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Library All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index