Using MicroStrategy Web Services for System Reliability Checks

A standard MicroStrategy Web installation comes with MicroStrategy Web Services which exposes some basic tasks for your consumption.  While not as powerful as any of the full featured SDKs, it does have two distinct advantages: 1) It’s free! and 2) It’s easier to use and get started with than the other SDKs.

But what use can you make of it?  In my environments, utilizing Web Services is an indispensable feature.  Every morning, a simple .NET application invokes the Web Services to run a simple report.  The report is a simple query that represents the most recent data in the warehouse, and it’s executed automatically before the morning’s subscriptions are set to send out.  A lot of things are accomplished by simply running this report.  First of all, if the report comes back successful and it doesn’t contain a zero, I’ve verified that MicroStrategy Web is running as well as the Intelligence Server.  I’ve verified the Data Warehouse is up and that ETL was successful.  And in the event of a report failure or a zero coming back, I can send myself an email and automatically disable all Schedules so that bad data isn’t sent out to users.  How do you accomplish all of this magic in such a simple, compact task?  Read on and I’ll show you.

I’m a hobbyist programmer and by no means an expert.  The code I’ll share today and in the future could easily be improved upon, and I encourage you to do so and share it in the comments.  This is what I’ve done that works for me, and hopefully it’ll work for you or at least guide you in the right direction.

DISCLAIMER: I’m not a professional programmer, so please use code that I provide as a guide and not as copy-paste-run-in-production!

My language of choice for MicroStrategy Web Services is Visual Basic .NET, but the concepts are pretty universal.  Since it’s a standard web service, you can get to it from any language.

Step 1: Basic Setup

The first thing you have to do in your Visual Basic project is to add the Web Service.  The steps are different depending on which version, but I’ll show you the steps for 2010, because I think it’s the trickiest.  For other versions or languages, you can Google it.

1) In your project, click on the Project menu, and then Add Service Reference (not Add Reference, that’s the tricky part!)
2) Type in the full URL, which is http://yourserver/microstrategyws/mstrws.asmx (don’t forget, that’s /microstrategyws) and click Go.
3) It should find the web service, so give it a name (I called mine MSTR in the code below) and click OK.

You should now see a Web Reference folder on the right with the MSTR Web Service under it.  Sometimes this can take a minute to load up.

Step 2: Connecting to a Project and Running a Report

The following code was written and tested in Visual Basic 2010, but should be compatible in all versions of Visual Basic .NET.

Dim mstrws As New MSTR.MSTRWS
mstrws.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials 'Standard Authentication
Dim cInfo As New MSTR.MWSConnectInfo
cInfo.AuthMode = MSTR.EnumMWSAuthMode.MWSStandard
cInfo.Login = "USERNAME"
cInfo.Password = "PASSWORD"
cInfo.ProjectSource = "ISERVER" 'Don't be fooled that it says ProjectSource, it's ISERVER!
cInfo.ProjectName = "PROJECT" 'Case and Space sensitive
'Connect to the Project and logs in
cInfo.Session = mstrws.ConnectToProject(cInfo).Session
'Execute the report
'<ReportGUID> is the GUID of the report to execute
'<PromptAns> is an XML string for prompt answers, described in Step 3
Dim ei As MSTR.MWSExecuteInfo
ei = mstrws.ExecuteReport(cInfo, Nothing, "<ReportGUID>", "<PromptAns>",_ Nothing, Nothing, "ReportViewer", Nothing,_ Nothing)
'Read the results of the data set
Dim ds As New DataSet
ds.ReadXml(New StringReader(ei.ResultXML), XmlReadMode.Auto)
If ds.Tables(0).Rows.Count > 0 Then
    'success, put your processing code here
End If
'Disconnect
Dim sess(0) As String 'Silly hoop to jump through to cleanly disconnect
sess(0) = cInfo.Session 'since it wants an array of sessions
mstrws.Disconnect(sess)
Step 3: Answering Prompts
Prompt answers are in the form of an XML string, formatted as follows:
<rsl>
  <pa pt=5 pin=0 did=DA6B21544D1C41DC1D635A96B13A20B2 tp=10>3/17/2011</pa>
  <pa pt=5 pin=0 did=253E4AD74FBDA8E2C0BB9DA08C48ACAA tp=10>3/17/2011</pa>
  <pa pt=7 pin=0 did=338B22FC40856D84FAE294811494D2BD tp=10>
    <mi>
      <es>
        <at did=DD1245E245C035B818161EB7356B2694 tp=12/>
        <e emt=1 ei=DD1245E245C035B818161EB7356B2694:1234 art=1/>
      </es>
    </mi>
  </pa>
</rsl>
There are different types of prompts in MicroStrategy.  Two are sampled above.

Value Prompts

Pass a specific free form value.
<pa pt=5 pin=0 did=DA6B21544D1C41DC1D635A96B13A20B2 tp=10>3/17/2011</pa>
This is the simplest prompt.  The did is the Prompt GUID and “3/17/2011” is the value we are passing.

Element Prompts

Choose from a list of Attribute Elements.
<pa pt=7 pin=0 did=338B22FC40856D84FAE294811494D2BD tp=10>
    <mi>
      <es>
        <at did=DD1245E245C035B818161EB7356B2694 tp=12/>
        <e emt=1 ei=DD1245E245C035B818161EB7356B2694:1234 art=1/>
      </es>
    </mi>
  </pa>
This is the most common type of prompt.  The did in the <pa> tag is the Prompt GUID, and the did in the <at> tag is the Attribute GUID.  The <e> tag is the Attribute Element that is selected.  An element is made up of the Attribute GUID : Attribute Element.  The 1234 is the Attribute ID.

Conclusion
I added the code for answering prompts to be complete, but if you were implementing this in the use case scenario I laid out in the beginning, you wouldn’t have Prompts and you could leave that parameter of the ExecuteReport() call as null.  In your own implementation, you can simply add code that checks a field value, or even that you just didn’t get an error.

You can then use .NETs System.Net.Mail to send yourself an email in the event of a failure, and trigger a  Command Manager script if you want to take action such as disabling all schedules (I’ll post that code in a separate future post, and hopefully come back and add a link here).

The advantage of this simple implementation is that you can schedule it to run before your daily subscriptions.  If there are any points of failure along the way, you can sound the alarm before any real trouble begins.  Just be sure to put this application on a neutral, reliable server, since if you run it locally you may not get the warning if the server goes down.

You may also like...